From 310d8d35799f41b1f2e8683f3428da262920cd1b Mon Sep 17 00:00:00 2001 From: light7734 Date: Mon, 7 Jul 2025 15:13:05 +0330 Subject: [PATCH] refactor: fix some static analysis --- modules/engine/CMakeLists.txt | 2 - .../include/engine/core/application.hpp | 22 +++-- modules/engine/include/engine/engine.hpp | 3 - .../graphics/renderer_programs/quad.hpp | 11 +-- .../graphics/renderer_programs/texture.hpp | 13 +-- .../renderer_programs/tinted_texture.hpp | 12 +-- modules/engine/include/engine/math/random.hpp | 20 ----- .../engine/include/engine/scene/entity.hpp | 2 - modules/engine/include/engine/scene/scene.hpp | 4 - modules/engine/include/engine/time/timer.hpp | 31 ++----- modules/engine/src/camera/ortho.cpp | 12 +-- modules/engine/src/camera/scene.cpp | 34 ++++---- modules/engine/src/core/application.cpp | 14 ++-- modules/engine/src/graphics/renderer.cpp | 84 +++++++++---------- .../src/graphics/renderer_programs/quad.cpp | 29 ++++--- .../graphics/renderer_programs/texture.cpp | 26 +++--- .../renderer_programs/tinted_texture.cpp | 27 +++--- modules/engine/src/input/input.cpp | 1 + modules/engine/src/layer/layer.cpp | 37 +++++--- modules/engine/src/math/random.cpp | 41 --------- modules/engine/src/scene/entity.cpp | 3 - modules/engine/src/scene/scene.cpp | 7 -- modules/engine/src/time/timer.cpp | 11 --- .../src/user_interface/user_interface.cpp | 15 +++- modules/mirror/src/mirror.cpp | 10 +-- 25 files changed, 200 insertions(+), 271 deletions(-) delete mode 100644 modules/engine/include/engine/math/random.hpp delete mode 100644 modules/engine/src/math/random.cpp diff --git a/modules/engine/CMakeLists.txt b/modules/engine/CMakeLists.txt index 3fd11b7..70842eb 100644 --- a/modules/engine/CMakeLists.txt +++ b/modules/engine/CMakeLists.txt @@ -25,7 +25,6 @@ if(NOT WIN32) input/input.cpp layer/layer.cpp layer/layer_stack.cpp - math/random.cpp platform/graphics/opengl/blender.cpp platform/graphics/opengl/buffers.cpp platform/graphics/opengl/framebuffers.cpp @@ -70,7 +69,6 @@ else() input/input.cpp layer/layer.cpp layer/layer_stack.cpp - math/random.cpp platform/graphics/directx/blender.cpp platform/graphics/directx/buffers.cpp platform/graphics/directx/framebuffers.cpp diff --git a/modules/engine/include/engine/core/application.hpp b/modules/engine/include/engine/core/application.hpp index cda7618..2a54ef5 100644 --- a/modules/engine/include/engine/core/application.hpp +++ b/modules/engine/include/engine/core/application.hpp @@ -9,32 +9,42 @@ namespace Light { class Window; class Event; +extern Scope create_application(); + class Application { public: Application(const Application &) = delete; - Application &operator=(const Application &) = delete; + Application(Application &&) = delete; + + auto operator=(const Application &) -> Application & = delete; + + auto operator=(Application &&) -> Application & = delete; virtual ~Application(); void game_loop(); + [[nodiscard]] auto get_window() -> Window & + { + return *m_window; + } + static void quit(); protected: Application(); - Scope m_window; - private: - static Application *s_instance; - void on_event(const Event &event); void log_debug_data(); + + Scope m_window; + + static Application *s_instance; }; -extern Light::Scope create_application(); } // namespace Light diff --git a/modules/engine/include/engine/engine.hpp b/modules/engine/include/engine/engine.hpp index 4b30d32..2fd016e 100644 --- a/modules/engine/include/engine/engine.hpp +++ b/modules/engine/include/engine/engine.hpp @@ -47,9 +47,6 @@ // third party #include -// math -#include - // scene #include #include diff --git a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp b/modules/engine/include/engine/graphics/renderer_programs/quad.hpp index c1dd5df..7d96653 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/quad.hpp @@ -16,14 +16,15 @@ class SharedContext; class QuadRendererProgram: RendererProgram { public: -virtual ~QuadRendererProgram() = default; + virtual ~QuadRendererProgram() = default; struct QuadVertexData { glm::vec4 position; + glm::vec4 tint; }; - QuadRendererProgram(unsigned int maxVertices, const Ref& sharedContext); + QuadRendererProgram(unsigned int maxVertices, const Ref &sharedContext); auto advance() -> bool; @@ -35,7 +36,7 @@ virtual ~QuadRendererProgram() = default; auto get_map_current() -> QuadVertexData * { - return m_map_current; + return &m_map[m_idx]; } [[nodiscard]] auto get_quad_count() const -> unsigned int @@ -57,9 +58,9 @@ private: Ref m_vertex_layout; - QuadVertexData *m_map_current = nullptr; + std::span m_map; - QuadVertexData *m_map_end = nullptr; + size_t m_idx {}; unsigned int m_quad_count = 0u; diff --git a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp b/modules/engine/include/engine/graphics/renderer_programs/texture.hpp index e9ebedb..d12c044 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/texture.hpp @@ -16,7 +16,8 @@ class SharedContext; class TextureRendererProgram: RendererProgram { public: -virtual ~TextureRendererProgram() = default; + ~TextureRendererProgram() override = default; + struct TextureVertexData { glm::vec4 position; @@ -24,7 +25,7 @@ virtual ~TextureRendererProgram() = default; glm::vec2 texcoord; }; - TextureRendererProgram(unsigned int maxVertices, const Ref& sharedContext); + TextureRendererProgram(unsigned int maxVertices, const Ref &sharedContext); auto advance() -> bool; @@ -36,7 +37,7 @@ virtual ~TextureRendererProgram() = default; auto get_map_current() -> TextureVertexData * { - return m_map_current; + return &m_map[m_idx]; } [[nodiscard]] auto get_quad_count() const -> unsigned int @@ -58,11 +59,11 @@ private: Ref m_vertex_layout; - TextureVertexData *m_map_current = nullptr; + std::span m_map; - TextureVertexData *m_map_end = nullptr; + size_t m_idx {}; - unsigned int m_quad_count{0u}; + unsigned int m_quad_count { 0u }; unsigned int m_max_vertices; }; diff --git a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp b/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp index 2fff668..3a8a1bb 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp @@ -16,7 +16,7 @@ class SharedContext; class TintedTextureRendererProgram: RendererProgram { public: -virtual ~TintedTextureRendererProgram() = default; + virtual ~TintedTextureRendererProgram() = default; struct TintedTextureVertexData { glm::vec4 position; @@ -26,7 +26,7 @@ virtual ~TintedTextureRendererProgram() = default; glm::vec2 texcoord; }; - TintedTextureRendererProgram(unsigned int maxVertices, const Ref& sharedContext); + TintedTextureRendererProgram(unsigned int maxVertices, const Ref &sharedContext); auto advance() -> bool; @@ -38,7 +38,7 @@ virtual ~TintedTextureRendererProgram() = default; auto get_map_current() -> TintedTextureVertexData * { - return m_map_current; + return &m_map[m_idx]; } [[nodiscard]] auto get_quad_count() const -> unsigned int @@ -60,11 +60,11 @@ private: Ref m_vertex_layout; - TintedTextureVertexData *m_map_current = nullptr; + std::span m_map; - TintedTextureVertexData *m_map_end = nullptr; + size_t m_idx {}; - unsigned int m_quad_count{0u}; + unsigned int m_quad_count { 0u }; unsigned int m_max_vertices; }; diff --git a/modules/engine/include/engine/math/random.hpp b/modules/engine/include/engine/math/random.hpp deleted file mode 100644 index 20895c1..0000000 --- a/modules/engine/include/engine/math/random.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -// #todo: make proper math stuff - -// this is a temporary header file to extend the glm math -// light engine will either have it's own math library or extend upon the glm - -#include - - -namespace Light::Math { - -auto rand(int min, int max, int decimals = 0) -> float; - -auto rand_vec2(int min, int max, int decimals = 0) -> glm::vec2; - -auto rand_vec3(int min, int max, int decimals = 0) -> glm::vec3; - -} // namespace Light::Math - diff --git a/modules/engine/include/engine/scene/entity.hpp b/modules/engine/include/engine/scene/entity.hpp index 353db51..e3ba30c 100644 --- a/modules/engine/include/engine/scene/entity.hpp +++ b/modules/engine/include/engine/scene/entity.hpp @@ -12,8 +12,6 @@ class Entity public: Entity(entt::entity handle = entt::null, Scene *scene = nullptr); - ~Entity(); - template auto add_component(Args &&...args) -> t & { diff --git a/modules/engine/include/engine/scene/scene.hpp b/modules/engine/include/engine/scene/scene.hpp index 7f59d45..01dc92a 100644 --- a/modules/engine/include/engine/scene/scene.hpp +++ b/modules/engine/include/engine/scene/scene.hpp @@ -14,10 +14,6 @@ class Framebuffer; class Scene { public: - Scene(); - - ~Scene(); - void on_create(); void on_update(float deltaTime); diff --git a/modules/engine/include/engine/time/timer.hpp b/modules/engine/include/engine/time/timer.hpp index f1238c2..248307f 100644 --- a/modules/engine/include/engine/time/timer.hpp +++ b/modules/engine/include/engine/time/timer.hpp @@ -12,11 +12,12 @@ public: [[nodiscard]] auto get_elapsed_time() const -> float { - return (std::chrono::duration_cast( - std::chrono::steady_clock::now() - m_start - ) - .count()) - / 1000.; + using std::chrono::duration_cast; + using std::chrono::milliseconds; + using std::chrono::steady_clock; + + auto rep = duration_cast(steady_clock::now() - m_start).count(); + return static_cast(rep) / 1000.f; } void reset() @@ -28,24 +29,4 @@ private: std::chrono::time_point m_start; }; -class DeltaTimer -{ -public: - DeltaTimer(); - - void update(); - - [[nodiscard]] auto get_delta_time() const -> float - { - return m_delta_time; - } - -private: - Timer timer; - - float m_previous_frame; - - float m_delta_time; -}; - } // namespace Light diff --git a/modules/engine/src/camera/ortho.cpp b/modules/engine/src/camera/ortho.cpp index c72bfcc..ea2fcff 100644 --- a/modules/engine/src/camera/ortho.cpp +++ b/modules/engine/src/camera/ortho.cpp @@ -6,15 +6,15 @@ namespace Light { OrthographicCamera::OrthographicCamera( const glm::vec2 &position, - float aspectRatio, - float zoomLevel, - const glm::vec4 &clearColor /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */ + float aspect_ratio, + float zoom_level, + const glm::vec4 &clear_color /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */ ) : m_up(0.0f, 1.0f, 0.0f) , m_position(position) - , m_aspect_ratio(aspectRatio) - , m_zoom_level(zoomLevel) - , m_clear_color(clearColor) + , m_aspect_ratio(aspect_ratio) + , m_zoom_level(zoom_level) + , m_clear_color(clear_color) { } diff --git a/modules/engine/src/camera/scene.cpp b/modules/engine/src/camera/scene.cpp index 080fd09..3022ee7 100644 --- a/modules/engine/src/camera/scene.cpp +++ b/modules/engine/src/camera/scene.cpp @@ -4,23 +4,25 @@ namespace Light { SceneCamera::SceneCamera() - : m_orthographic_specification { .size=1000.0f, .near_plane=-1.0f, .far_plane=10000.0f } - , m_perspective_specification { .vertical_fov=glm::radians(45.0f), .near_plane=0.01f, .far_plane=10000.0f } + : m_orthographic_specification { .size = 1000.0f, .near_plane = -1.0f, .far_plane = 10000.0f } + , m_perspective_specification { .vertical_fov = glm::radians(45.0f), + .near_plane = 0.01f, + .far_plane = 10000.0f } , m_aspect_ratio(16.0f / 9.0f) - + { calculate_projection(); } void SceneCamera::set_viewport_size(unsigned int width, unsigned int height) { - m_aspect_ratio = width / (float)height; + m_aspect_ratio = static_cast(width) / static_cast(height); calculate_projection(); } -void SceneCamera::set_projection_type(ProjectionType projectionType) +void SceneCamera::set_projection_type(ProjectionType projection_type) { - m_projection_type = projectionType; + m_projection_type = projection_type; calculate_projection(); } @@ -30,33 +32,33 @@ void SceneCamera::set_orthographic_size(float size) calculate_projection(); } -void SceneCamera::set_orthographic_far_plane(float farPlane) +void SceneCamera::set_orthographic_far_plane(float far_plane) { - m_orthographic_specification.far_plane = farPlane; + m_orthographic_specification.far_plane = far_plane; calculate_projection(); } -void SceneCamera::set_orthographic_near_plane(float nearPlane) +void SceneCamera::set_orthographic_near_plane(float near_plane) { - m_orthographic_specification.near_plane = nearPlane; + m_orthographic_specification.near_plane = near_plane; calculate_projection(); } -void SceneCamera::set_perspective_vertical_fov(float verticalFOV) +void SceneCamera::set_perspective_vertical_fov(float vertical_fov) { - m_perspective_specification.vertical_fov = verticalFOV; + m_perspective_specification.vertical_fov = vertical_fov; calculate_projection(); } -void SceneCamera::set_perspective_far_plane(float farPlane) +void SceneCamera::set_perspective_far_plane(float far_plane) { - m_perspective_specification.far_plane = farPlane; + m_perspective_specification.far_plane = far_plane; calculate_projection(); } -void SceneCamera::set_perspective_near_plane(float nearPlane) +void SceneCamera::set_perspective_near_plane(float near_plane) { - m_perspective_specification.near_plane = nearPlane; + m_perspective_specification.near_plane = near_plane; calculate_projection(); } diff --git a/modules/engine/src/core/application.cpp b/modules/engine/src/core/application.cpp index 75dcbdf..10237af 100644 --- a/modules/engine/src/core/application.cpp +++ b/modules/engine/src/core/application.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include #include @@ -48,7 +50,7 @@ void Application::game_loop() Instrumentor::begin_session("Logs/ProfileResults_GameLoop.json"); /* game loop */ - auto delta_timer = DeltaTimer {}; + auto timer = Timer {}; while (!m_window->is_closed()) { { @@ -57,8 +59,11 @@ void Application::game_loop() for (auto &it : LayerStack::instance()) { - it->on_update(delta_timer.get_delta_time()); + it->on_update(timer.get_elapsed_time()); } + + // TODO: each layer should have their own "delta time" + timer.reset(); } { @@ -92,9 +97,6 @@ void Application::game_loop() lt_profile_scope("game_loop::Events"); m_window->poll_events(); } - - /// update delta time - delta_timer.update(); } Instrumentor::end_session(); @@ -116,7 +118,7 @@ void Application::on_event(const Event &event) if (event.get_event_type() == EventType::WindowResized) { m_window->get_graphics_context()->get_renderer()->on_window_resize( - (const WindowResizedEvent &)event + dynamic_cast(event) ); } } diff --git a/modules/engine/src/graphics/renderer.cpp b/modules/engine/src/graphics/renderer.cpp index 2991b32..bd2e64f 100644 --- a/modules/engine/src/graphics/renderer.cpp +++ b/modules/engine/src/graphics/renderer.cpp @@ -98,24 +98,24 @@ void Renderer::draw_quad_impl( //==================== DRAW_QUAD_TINT ====================// void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) { - // locals - QuadRendererProgram::QuadVertexData *bufferMap = m_quad_renderer.get_map_current(); + auto map = std::span { m_quad_renderer.get_map_current(), + 4 }; // top left - bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); - bufferMap[0].tint = tint; + map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); + map[0].tint = tint; // top right - bufferMap[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); - bufferMap[1].tint = tint; + map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); + map[1].tint = tint; // bottom right - bufferMap[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); - bufferMap[2].tint = tint; + map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); + map[2].tint = tint; // bottom left - bufferMap[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); - bufferMap[3].tint = tint; + map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); + map[3].tint = tint; // advance if (!m_quad_renderer.advance()) @@ -124,33 +124,32 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) flush_scene(); } } -//==================== DRAW_QUAD_TINT ====================// -//==================== DRAW_QUAD_TEXTURE ====================// void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref &texture) { - // #todo: implement a proper binding lt_assert(texture, "Texture passed to renderer::draw_quad_impl"); - texture->bind(); - // locals - TextureRendererProgram::TextureVertexData *bufferMap = m_texture_renderer.get_map_current(); + texture->bind(); + auto map = std::span { + m_texture_renderer.get_map_current(), + 4 + }; // top left - bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); - bufferMap[0].texcoord = { 0.0f, 0.0f }; + map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); + map[0].texcoord = { 0.0f, 0.0f }; // top right - bufferMap[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); - bufferMap[1].texcoord = { 1.0f, 0.0f }; + map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); + map[1].texcoord = { 1.0f, 0.0f }; // bottom right - bufferMap[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); - bufferMap[2].texcoord = { 1.0f, 1.0f }; + map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); + map[2].texcoord = { 1.0f, 1.0f }; // bottom left - bufferMap[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); - bufferMap[3].texcoord = { 0.0f, 1.0f }; + map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); + map[3].texcoord = { 0.0f, 1.0f }; // advance if (!m_texture_renderer.advance()) @@ -166,35 +165,34 @@ void Renderer::draw_quad_impl( const Ref &texture ) { - // #todo: implement a proper binding lt_assert(texture, "Texture passed to renderer::draw_quad_impl"); - texture->bind(); - // locals - TintedTextureRendererProgram::TintedTextureVertexData *bufferMap = m_tinted_texture_renderer - .get_map_current(); + texture->bind(); + auto map = std::span { + m_tinted_texture_renderer.get_map_current(), + 4 + }; // top left - bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); - bufferMap[0].tint = tint; - bufferMap[0].texcoord = { 0.0f, 0.0f }; + map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); + map[0].tint = tint; + map[0].texcoord = { 0.0f, 0.0f }; // top right - bufferMap[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); - bufferMap[1].tint = tint; - bufferMap[1].texcoord = { 1.0f, 0.0f }; + map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); + map[1].tint = tint; + map[1].texcoord = { 1.0f, 0.0f }; // bottom right - bufferMap[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); - bufferMap[2].tint = tint; - bufferMap[2].texcoord = { 1.0f, 1.0f }; + map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); + map[2].tint = tint; + map[2].texcoord = { 1.0f, 1.0f }; // bottom left - bufferMap[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); - bufferMap[3].tint = tint; - bufferMap[3].texcoord = { 0.0f, 1.0f }; + map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); + map[3].tint = tint; + map[3].texcoord = { 0.0f, 1.0f }; - // advance if (!m_tinted_texture_renderer.advance()) { log_wrn("Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES); @@ -202,8 +200,6 @@ void Renderer::draw_quad_impl( } } -//==================== DRAW_QUAD_TEXTURE ====================// - void Renderer::begin_frame() { } diff --git a/modules/engine/src/graphics/renderer_programs/quad.cpp b/modules/engine/src/graphics/renderer_programs/quad.cpp index 840c43e..bbd8245 100644 --- a/modules/engine/src/graphics/renderer_programs/quad.cpp +++ b/modules/engine/src/graphics/renderer_programs/quad.cpp @@ -7,12 +7,14 @@ namespace Light { -QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, const Ref& sharedContext) +QuadRendererProgram::QuadRendererProgram( + unsigned int max_vertices, + const Ref &shared_context +) : m_shader(nullptr) , m_index_buffer(nullptr) , m_vertex_layout(nullptr) - , - m_max_vertices(maxVertices) + , m_max_vertices(max_vertices) { // #todo: don't use relative path ResourceManager::load_shader( @@ -23,24 +25,23 @@ QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, const Ref( - VertexBuffer::create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext) + VertexBuffer::create(nullptr, sizeof(QuadVertexData), max_vertices, shared_context) ); m_index_buffer = Ref( - IndexBuffer::create(nullptr, (maxVertices / 4) * 6, sharedContext) + IndexBuffer::create(nullptr, (max_vertices / 4) * 6, shared_context) ); m_vertex_layout = Ref(VertexLayout::create( m_vertex_buffer, m_shader, { { "POSITION", VertexElementType::Float4 }, { "COLOR", VertexElementType::Float4 } }, - sharedContext + shared_context )); } auto QuadRendererProgram::advance() -> bool { - m_map_current += 4; - - if (m_map_current >= m_map_end) + m_idx += 4; + if (m_idx >= m_map.size()) { log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); return false; @@ -52,15 +53,19 @@ auto QuadRendererProgram::advance() -> bool void QuadRendererProgram::map() { - m_quad_count = 0u; + m_map = std::span { + static_cast(m_vertex_buffer->map()), + m_max_vertices, + }; - m_map_current = (QuadRendererProgram::QuadVertexData *)m_vertex_buffer->map(); - m_map_end = m_map_current + m_max_vertices; + m_quad_count = 0u; + m_idx = {}; } void QuadRendererProgram::un_map() { m_vertex_buffer->un_map(); + m_idx = {}; } void QuadRendererProgram::bind() diff --git a/modules/engine/src/graphics/renderer_programs/texture.cpp b/modules/engine/src/graphics/renderer_programs/texture.cpp index a123de9..0fbae15 100644 --- a/modules/engine/src/graphics/renderer_programs/texture.cpp +++ b/modules/engine/src/graphics/renderer_programs/texture.cpp @@ -8,14 +8,13 @@ namespace Light { TextureRendererProgram::TextureRendererProgram( - unsigned int maxVertices, - const Ref& sharedContext + unsigned int max_vertices, + const Ref &shared_context ) : m_shader(nullptr) , m_index_buffer(nullptr) , m_vertex_layout(nullptr) - , - m_max_vertices(maxVertices) + , m_max_vertices(max_vertices) { // #todo: don't use relative path ResourceManager::load_shader( @@ -26,38 +25,41 @@ TextureRendererProgram::TextureRendererProgram( m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_TEXTURE_SHADER"); m_vertex_buffer = Ref( - VertexBuffer::create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext) + VertexBuffer::create(nullptr, sizeof(TextureVertexData), max_vertices, shared_context) ); m_index_buffer = Ref( - IndexBuffer::create(nullptr, (maxVertices / 4) * 6, sharedContext) + IndexBuffer::create(nullptr, (max_vertices / 4) * 6, shared_context) ); m_vertex_layout = Ref(VertexLayout::create( m_vertex_buffer, m_shader, { { "POSITION", VertexElementType::Float4 }, { "TEXCOORD", VertexElementType::Float2 } }, - sharedContext + shared_context )); } auto TextureRendererProgram::advance() -> bool { - if (m_map_current + 4 >= m_map_end) + m_idx += 4; + if (m_idx >= m_map.size()) { log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); return false; } - m_map_current += 4; m_quad_count++; return true; } void TextureRendererProgram::map() { - m_quad_count = 0u; + m_map = std::span { + static_cast(m_vertex_buffer->map()), + m_max_vertices, + }; - m_map_current = (TextureRendererProgram::TextureVertexData *)m_vertex_buffer->map(); - m_map_end = m_map_current + m_max_vertices; + m_quad_count = 0u; + m_idx = {}; } void TextureRendererProgram::un_map() diff --git a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp b/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp index a1187ae..a461ccc 100644 --- a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp +++ b/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp @@ -8,14 +8,13 @@ namespace Light { TintedTextureRendererProgram::TintedTextureRendererProgram( - unsigned int maxVertices, - const Ref& sharedContext + unsigned int max_vertices, + const Ref &shared_context ) : m_shader(nullptr) , m_index_buffer(nullptr) , m_vertex_layout(nullptr) - , - m_max_vertices(maxVertices) + , m_max_vertices(max_vertices) { // #todo: don't use relative path ResourceManager::load_shader( @@ -26,10 +25,10 @@ TintedTextureRendererProgram::TintedTextureRendererProgram( m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER"); m_vertex_buffer = Ref( - VertexBuffer::create(nullptr, sizeof(TintedTextureVertexData), maxVertices, sharedContext) + VertexBuffer::create(nullptr, sizeof(TintedTextureVertexData), max_vertices, shared_context) ); m_index_buffer = Ref( - IndexBuffer::create(nullptr, (maxVertices / 4) * 6, sharedContext) + IndexBuffer::create(nullptr, (max_vertices / 4) * 6, shared_context) ); m_vertex_layout = Ref(VertexLayout::create( m_vertex_buffer, @@ -37,15 +36,14 @@ TintedTextureRendererProgram::TintedTextureRendererProgram( { { "POSITION", VertexElementType::Float4 }, { "TINT", VertexElementType::Float4 }, { "TEXCOORD", VertexElementType::Float2 } }, - sharedContext + shared_context )); } auto TintedTextureRendererProgram::advance() -> bool { - m_map_current += 4; - - if (m_map_current >= m_map_end) + m_idx += 4; + if (m_idx >= m_map.size()) { log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices); return false; @@ -57,10 +55,13 @@ auto TintedTextureRendererProgram::advance() -> bool void TintedTextureRendererProgram::map() { - m_quad_count = 0u; + m_map = std::span { + static_cast(m_vertex_buffer->map()), + m_max_vertices, + }; - m_map_current = (TintedTextureRendererProgram::TintedTextureVertexData *)m_vertex_buffer->map(); - m_map_end = m_map_current + m_max_vertices; + m_quad_count = 0u; + m_idx = {}; } void TintedTextureRendererProgram::un_map() diff --git a/modules/engine/src/input/input.cpp b/modules/engine/src/input/input.cpp index 51ab39b..4b1ac41 100644 --- a/modules/engine/src/input/input.cpp +++ b/modules/engine/src/input/input.cpp @@ -156,6 +156,7 @@ void Input::on_event(const Event &inputEvent) return; } + default: log_trc("Dropped event"); } } diff --git a/modules/engine/src/layer/layer.cpp b/modules/engine/src/layer/layer.cpp index 5251001..0c8698c 100644 --- a/modules/engine/src/layer/layer.cpp +++ b/modules/engine/src/layer/layer.cpp @@ -15,21 +15,32 @@ auto Layer::on_event(const Event &event) -> bool { switch (event.get_event_type()) { - case EventType::MouseMoved: return on_mouse_moved((MouseMovedEvent &)event); - case EventType::ButtonPressed: return on_button_pressed((ButtonPressedEvent &)event); - case EventType::ButtonReleased: return on_button_released((ButtonReleasedEvent &)event); - case EventType::WheelScrolled: return on_wheel_scrolled((WheelScrolledEvent &)event); + case EventType::MouseMoved: return on_mouse_moved(dynamic_cast(event)); + case EventType::ButtonPressed: + return on_button_pressed(dynamic_cast(event)); + case EventType::ButtonReleased: + return on_button_released(dynamic_cast(event)); + case EventType::WheelScrolled: + return on_wheel_scrolled(dynamic_cast(event)); - case EventType::KeyPressed: return on_key_pressed((KeyPressedEvent &)event); - case EventType::KeyRepeated: return on_key_repeat((KeyRepeatEvent &)event); - case EventType::KeyReleased: return on_key_released((KeyReleasedEvent &)event); - case EventType::SetChar: return on_set_char((SetCharEvent &)event); + case EventType::KeyPressed: return on_key_pressed(dynamic_cast(event)); + case EventType::KeyRepeated: return on_key_repeat(dynamic_cast(event)); + case EventType::KeyReleased: + return on_key_released(dynamic_cast(event)); + case EventType::SetChar: return on_set_char(dynamic_cast(event)); - case EventType::WindowClosed: return on_window_closed((WindowClosedEvent &)event); - case EventType::WindowResized: return on_window_resized((WindowResizedEvent &)event); - case EventType::WindowMoved: return on_window_moved((WindowMovedEvent &)event); - case EventType::WindowLostFocus: return on_window_lost_focus((WindowLostFocusEvent &)event); - case EventType::WindowGainFocus: return on_window_gain_focus((WindowGainFocusEvent &)event); + case EventType::WindowClosed: + return on_window_closed(dynamic_cast(event)); + case EventType::WindowResized: + return on_window_resized(dynamic_cast(event)); + case EventType::WindowMoved: + return on_window_moved(dynamic_cast(event)); + case EventType::WindowLostFocus: + return on_window_lost_focus(dynamic_cast(event)); + case EventType::WindowGainFocus: + return on_window_gain_focus(dynamic_cast(event)); + + default: lt_assert(false, "Invalid event: {}", event.get_info_lt_log()); } } diff --git a/modules/engine/src/math/random.cpp b/modules/engine/src/math/random.cpp deleted file mode 100644 index 8cabdc1..0000000 --- a/modules/engine/src/math/random.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - - -namespace Light::Math { - -auto rand(int min, int max, int decimals /* = 0 */) -> float -{ - const auto dec = static_cast(std::pow(10, decimals)); - min *= dec; - max *= dec; - - return (min + (::rand() % (max)-min)) / (float)dec; -} - -auto rand_vec2(int min, int max, int decimals /* = 0 */) -> glm::vec2 -{ - const auto dec = static_cast(std::pow(10, decimals)); - min *= dec; - max *= dec; - - auto r1 = (min + (::rand() % (max)-min)) / (float)dec; - auto r2 = (min + (::rand() % (max)-min)) / (float)dec; - - return { r1, r2 }; -} - -auto rand_vec3(int min, int max, int decimals /* = 0 */) -> glm::vec3 -{ - const auto dec = static_cast(std::pow(10, decimals)); - min *= dec; - max *= dec; - - auto r1 = (min + (::rand() % (max - min))) / (float)dec; - auto r2 = (min + (::rand() % (max - min))) / (float)dec; - auto r3 = (min + (::rand() % (max - min))) / (float)dec; - - return { r1, r2, r3 }; -} -} // namespace Light::Math - diff --git a/modules/engine/src/scene/entity.cpp b/modules/engine/src/scene/entity.cpp index 5920001..ba487ab 100644 --- a/modules/engine/src/scene/entity.cpp +++ b/modules/engine/src/scene/entity.cpp @@ -7,7 +7,4 @@ Entity::Entity(entt::entity handle, Scene *scene): m_handle(handle), m_scene(sce { } -Entity::~Entity() -= default; - } // namespace Light diff --git a/modules/engine/src/scene/scene.cpp b/modules/engine/src/scene/scene.cpp index 8583b1a..0fe8e24 100644 --- a/modules/engine/src/scene/scene.cpp +++ b/modules/engine/src/scene/scene.cpp @@ -6,13 +6,6 @@ namespace Light { -Scene::Scene() -{ -} - -Scene::~Scene() -= default; - void Scene::on_create() { /* native scripts */ diff --git a/modules/engine/src/time/timer.cpp b/modules/engine/src/time/timer.cpp index d611b4e..e828f98 100644 --- a/modules/engine/src/time/timer.cpp +++ b/modules/engine/src/time/timer.cpp @@ -6,15 +6,4 @@ Timer::Timer(): m_start(std::chrono::steady_clock::now()) { } -DeltaTimer::DeltaTimer(): m_previous_frame(NULL), m_delta_time(60.0f / 1000.0f) -{ -} - -void DeltaTimer::update() -{ - auto currentFrame = timer.get_elapsed_time(); - m_delta_time = currentFrame - m_previous_frame; - m_previous_frame = currentFrame; -} - } // namespace Light diff --git a/modules/engine/src/user_interface/user_interface.cpp b/modules/engine/src/user_interface/user_interface.cpp index 0b1b35f..fd2250c 100644 --- a/modules/engine/src/user_interface/user_interface.cpp +++ b/modules/engine/src/user_interface/user_interface.cpp @@ -15,6 +15,12 @@ #include #include + +inline ImGuiDockNodeFlags_ operator|(ImGuiDockNodeFlags_ a, ImGuiDockNodeFlags_ b) +{ + return static_cast(std::to_underlying(a) | std::to_underlying(b)); +} + namespace Light { UserInterface *UserInterface::s_context = nullptr; @@ -44,11 +50,13 @@ auto UserInterface::create(GLFWwindow *windowHandle, Ref sharedCo } UserInterface::UserInterface() + // NOLINTBEGIN : m_dockspace_flags( ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus ) +// NOLINTEND { lt_assert( !s_context, @@ -66,13 +74,13 @@ void UserInterface::init(GLFWwindow *windowHandle, Ref sharedCont // configure io ImGuiIO &io = ImGui::GetIO(); + // NOLINTBEGIN io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; - io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports; io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports; + // NOLINTEND // #todo: handle this in a better way if (std::filesystem::exists("user_gui_layout.ini")) @@ -117,8 +125,9 @@ void UserInterface::dockspace_begin() ImGui::DockSpace( ImGui::GetID("MyDockSpace"), ImVec2(0.0f, 0.0f), - ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground + ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground // NOLINT ); + style.WindowMinSize.x = minWinSizeX; } diff --git a/modules/mirror/src/mirror.cpp b/modules/mirror/src/mirror.cpp index 7f79399..51c55cc 100644 --- a/modules/mirror/src/mirror.cpp +++ b/modules/mirror/src/mirror.cpp @@ -8,28 +8,28 @@ namespace Light { -class Mirror: public Light::Application +class Mirror: public Application { public: Mirror() { // Set window properties - auto properties = Light::WindowProperties { + auto properties = WindowProperties { .title = "Mirror", .size = glm::uvec2(1280u, 720u), .vsync = true, }; - m_window->set_properties(properties); + get_window().set_properties(properties); // Attach the sandbox layer LayerStack::emplace_layer("MirrorLayer"); } }; -auto create_application() -> Light::Scope +auto create_application() -> Scope { - return Light::create_scope(); + return create_scope(); } } // namespace Light