too tired to think

This commit is contained in:
Erris
2026-01-31 10:27:40 +01:00
parent 5a25ab5f5f
commit 7b4950dda0
20 changed files with 160 additions and 92 deletions

View File

@@ -2,6 +2,7 @@
#define OPEN_ENGINE_HPP
#include "open_engine/core.hpp"
#include "open_engine/ref_scope.hpp"
#include "open_engine/application.hpp"
#include "open_engine/logging.hpp"
#include "open_engine/events/key_event.hpp"
@@ -10,6 +11,7 @@
#include "open_engine/renderer/renderer.hpp"
#include "open_engine/core/time.hpp"
#include "open_engine/input/input_system.hpp"
#include "open_engine/input/mouse_codes.hpp"
#include "open_engine/input/keycodes.hpp"
#include "open_engine/renderer/buffer.hpp"
#include "open_engine/renderer/shader.hpp"

View File

@@ -1,13 +1,14 @@
#ifndef APPLICATION_HPP
#define APPLICATION_HPP
#include "open_engine/core.hpp"
#include "open_engine/events/application_event.hpp"
#include "open_engine/imgui/imgui_layer.hpp"
#include "open_engine/window/window.hpp"
#include "open_engine/layer_stack.hpp"
#include "open_engine/layer.hpp"
int main(int argc, char **argv);
namespace OpenEngine {
class Application
{
@@ -15,8 +16,6 @@ namespace OpenEngine {
Application();
~Application();
void Run();
virtual void OnEvent(Event& event);
void QueueLayerPush(Ref<Layer> layer);
@@ -30,9 +29,11 @@ namespace OpenEngine {
inline void StopRunning() { running = false; };
private:
void Run();
bool OnWindowClose(WindowCloseEvent& event);
bool OnWindowResize(WindowResizeEvent& event);
private:
inline static Application* instance;
bool running = true;
@@ -40,6 +41,8 @@ namespace OpenEngine {
Ref<ImGuiLayer> imgui_layer;
LayerStack layer_stack;
friend int ::main(int argc, char **argv);
};
// Is defined by client

View File

@@ -3,8 +3,6 @@
#include "open_engine/instrumentor.hpp"
#include <memory>
#ifdef OE_ENABLE_ASSERTS
#include <signal.h>
#define OE_ASSERT(x, ...) { if (!(x)) { OE_ERROR("Assertion Failed: {0}", __VA_ARGS__); raise(SIGTRAP); } }
@@ -18,22 +16,4 @@
#define BIND_EVENT_FN(function) std::bind(&function, this, std::placeholders::_1)
namespace OpenEngine {
template<typename T>
using Scope = std::unique_ptr<T>;
template<typename T, typename ... Args>
constexpr Scope<T> CreateScope(Args&& ... args)
{
return std::make_unique<T>(std::forward<Args>(args)...);
}
template<typename T>
using Ref = std::shared_ptr<T>;
template<typename T, typename ... Args>
constexpr Ref<T> CreateRef(Args&& ... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
}
#endif // CORE_HPP

View File

@@ -1,7 +1,7 @@
#ifndef ENTRY_POINT_HPP
#define ENTRY_POINT_HPP
#include "open_engine/instrumentor.hpp"
#include "open_engine/core.hpp"
#include "open_engine/application.hpp"
#include "open_engine/logging.hpp"

View File

@@ -1,6 +1,10 @@
#ifndef INSTRUMENTOR_HPP
#define INSTRUMENTOR_HPP
#include "open_engine/logging.hpp"
#include <mutex>
#include <sstream>
#include <string>
#include <chrono>
#include <algorithm>
@@ -8,11 +12,15 @@
#include <thread>
namespace OpenEngine {
using FloatingPointMicroseconds = std::chrono::duration<double, std::micro>;
struct ProfileResult
{
std::string name;
long long start, end;
uint32_t thread_id;
FloatingPointMicroseconds start;
std::chrono::microseconds elapsed_time;
std::thread::id thread_id;
};
struct InstrumentationSession
@@ -30,45 +38,53 @@ namespace OpenEngine {
void BeginSession(const char* name, const std::string& filepath = "results.json")
{
std::lock_guard lock(mutex);
if (current_session) {
if (Logger::GetCoreLogger())
OE_CORE_ERROR("Instrumentor::BeginSession({}), when session {} already exists", name, current_session->name);
InternalEndSession();
}
output_stream.open(filepath);
WriteHeader();
if(output_stream.is_open()) {
current_session = new InstrumentationSession(name);
WriteHeader();
} else {
if (Logger::GetCoreLogger())
OE_CORE_ERROR("Instrumentor could not open results file: {}", filepath);
}
};
void EndSession()
{
WriteFooter();
output_stream.flush();
output_stream.close();
profile_count = 0;
std::lock_guard lock(mutex);
InternalEndSession();
};
void WriteProfile(const ProfileResult& result)
{
if (profile_count++ > 0)
output_stream << ",";
std::stringstream json;
std::string name = result.name;
std::replace(name.begin(), name.end(), '"', '\'');
output_stream << "{";
output_stream << "\"cat\":\"function\",";
output_stream << "\"dur\":" << (result.end - result.start) << ',';
output_stream << "\"name\":\"" << name << "\",";
output_stream << "\"ph\":\"X\",";
output_stream << "\"pid\":0,";
output_stream << "\"tid\":" << result.thread_id << ",";
output_stream << "\"ts\":" << result.start;
output_stream << "}";
};
json << std::setprecision(3) << std::fixed;
json << ",{";
json << "\"cat\":\"function\",";
json << "\"dur\":" << (result.elapsed_time.count()) << ',';
json << "\"name\":\"" << name << "\",";
json << "\"ph\":\"X\",";
json << "\"pid\":0,";
json << "\"tid\":" << result.thread_id << ",";
json << "\"ts\":" << result.start.count();
json << "}";
void WriteHeader()
{
output_stream << "{\"otherData\": {},\"traceEvents\":[";
};
std::lock_guard lock(mutex);
void WriteFooter()
{
output_stream << "]}";
if (current_session) {
output_stream << json.str();
output_stream.flush();
}
};
static Instrumentor& Get()
@@ -78,11 +94,32 @@ namespace OpenEngine {
};
private:
void WriteHeader()
{
output_stream << "{\"otherData\": {},\"traceEvents\":[{}";
};
void WriteFooter()
{
output_stream << "]}";
};
void InternalEndSession() {
if (current_session) {
WriteFooter();
output_stream.close();
delete current_session;
current_session = nullptr;
}
}
Instrumentor()
{
};
private:
std::mutex mutex;
InstrumentationSession* current_session = nullptr;
std::ofstream output_stream;
int profile_count = 0;
};
@@ -106,11 +143,12 @@ namespace OpenEngine {
{
auto end_timepoint = std::chrono::high_resolution_clock::now();
long long start = std::chrono::time_point_cast<std::chrono::microseconds>(start_timepoint).time_since_epoch().count();
long long end = std::chrono::time_point_cast<std::chrono::microseconds>(end_timepoint).time_since_epoch().count();
auto start = FloatingPointMicroseconds{start_timepoint.time_since_epoch()};
auto elapsed_time = std::chrono::time_point_cast<std::chrono::microseconds>(end_timepoint).time_since_epoch()
- std::chrono::time_point_cast<std::chrono::microseconds>(start_timepoint).time_since_epoch();
uint32_t thread_id = std::hash<std::thread::id>{}(std::this_thread::get_id());
Instrumentor::Get().WriteProfile({ name, start, end, thread_id });
Instrumentor::Get().WriteProfile({ name, start, elapsed_time, std::this_thread::get_id() });
stopped = true;
};

View File

@@ -1,12 +1,14 @@
#ifndef LOGGING_HPP
#define LOGGING_HPP
#include "open_engine/core.hpp"
#include "open_engine/ref_scope.hpp"
#include <spdlog/logger.h>
#include <spdlog/spdlog.h>
#include <string>
namespace OpenEngine {
spdlog::level::level_enum stringToLogLevel(std::string level_str);
int setupMultisinkLogger(const std::string &file_path);

View File

@@ -18,7 +18,7 @@ namespace OpenEngine {
void OnEvent(Event& e);
const OrthographicCamera& GetCamera() const { return camera; };
OrthographicCamera GetCamera() { return camera;};
OrthographicCamera& GetCamera() { return camera; };
float GetZoom() const { return zoom; }
void SetZoom(float level) { zoom = level; };

View File

@@ -0,0 +1,24 @@
#ifndef REF_SCOPE_HPP
#define REF_SCOPE_HPP
#include <memory>
namespace OpenEngine {
template<typename T>
using Scope = std::unique_ptr<T>;
template<typename T, typename ... Args>
constexpr Scope<T> CreateScope(Args&& ... args)
{
return std::make_unique<T>(std::forward<Args>(args)...);
}
template<typename T>
using Ref = std::shared_ptr<T>;
template<typename T, typename ... Args>
constexpr Ref<T> CreateRef(Args&& ... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
}
#endif // REF_SCOPE_HPP

View File

@@ -2,8 +2,9 @@
#define RENDER_COMMAND_HPP
#include "open_engine/core.hpp"
#include "open_engine/renderer/renderer_api.hpp"
#include "open_engine/opengl/opengl_renderer_api.hpp"
#include "open_engine/renderer/renderer_api.hpp"
#include "open_engine/ref_scope.hpp"
#include <cstdint>

View File

@@ -1,13 +1,20 @@
#ifndef RENDERER2D_HPP
#define RENDERER2D_HPP
#include "open_engine/core.hpp"
#include "open_engine/orthographic_camera.hpp"
#include "open_engine/renderer/texture.hpp"
#include "open_engine/ref_scope.hpp"
#include <glm/fwd.hpp>
namespace OpenEngine {
struct Transform
{
glm::vec3 position = {0.0f, 0.0f, 0.0f};
glm::vec3 size = {1.0f, 1.0f, 1.0f};
float rotation = 0.0f;
};
class Renderer2D
{
public:
@@ -17,10 +24,8 @@ namespace OpenEngine {
static void BeginScene(const OrthographicCamera& camera);
static void EndScene();
static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color);
static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color);
static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture);
static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture);
static void DrawQuad(const Transform& transform_data, const glm::vec4& color);
static void DrawQuad(const Transform& transform_data, const Ref<Texture2D>& texture, float tiling_factor = 1.0f);
};
}

View File

@@ -1,7 +1,7 @@
#ifndef SHADER_HPP
#define SHADER_HPP
#include <unordered_map>
#include <open_engine/ref_scope.hpp>
#include <glm/glm.hpp>
#include <string>