From 258164bf9a2d468bbf75dab219689ceea79591a8 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 6 Jul 2025 14:02:50 +0330 Subject: [PATCH] style: applied AAA principle --- .../engine/include/engine/base/entrypoint.hpp | 10 +-- .../engine/include/engine/camera/camera.hpp | 18 ++--- .../engine/include/engine/camera/ortho.hpp | 37 ++++----- .../engine/include/engine/camera/scene.hpp | 75 +++++++++++-------- .../include/engine/core/application.hpp | 2 +- modules/engine/include/engine/core/window.hpp | 26 ++++--- .../include/engine/debug/instrumentor.hpp | 6 +- .../engine/include/engine/debug/logger.hpp | 5 +- modules/engine/include/engine/events/char.hpp | 6 +- .../engine/include/engine/events/event.hpp | 27 ++++--- .../engine/include/engine/events/keyboard.hpp | 15 ++-- .../engine/include/engine/events/mouse.hpp | 28 ++++--- .../engine/include/engine/events/window.hpp | 16 ++-- .../include/engine/graphics/blender.hpp | 3 +- .../include/engine/graphics/buffers.hpp | 31 +++++--- .../include/engine/graphics/framebuffer.hpp | 20 +++-- .../engine/graphics/graphics_context.hpp | 14 ++-- .../engine/graphics/render_command.hpp | 5 +- .../include/engine/graphics/renderer.hpp | 29 +++---- .../graphics/renderer_programs/quad.hpp | 10 +-- .../graphics/renderer_programs/texture.hpp | 9 ++- .../renderer_programs/tinted_texture.hpp | 13 ++-- .../engine/include/engine/graphics/shader.hpp | 4 +- .../include/engine/graphics/texture.hpp | 7 +- .../include/engine/graphics/vertex_layout.hpp | 4 +- modules/engine/include/engine/input/input.hpp | 17 +++-- modules/engine/include/engine/layer/layer.hpp | 31 ++++---- .../include/engine/layer/layer_stack.hpp | 19 ++--- modules/engine/include/engine/math/random.hpp | 14 ++-- .../platform/graphics/directx/buffers.hpp | 2 +- .../graphics/directx/framebuffers.hpp | 2 +- .../platform/graphics/directx/shader.hpp | 2 +- .../graphics/directx/shared_context.hpp | 16 ++-- .../platform/graphics/opengl/buffers.hpp | 4 +- .../platform/graphics/opengl/framebuffers.hpp | 2 +- .../platform/graphics/opengl/texture.hpp | 2 +- .../graphics/opengl/vertex_layout.hpp | 2 +- .../scene/components/scriptable_entity.hpp | 6 +- .../engine/scene/components/transform.hpp | 2 +- .../engine/include/engine/scene/entity.hpp | 15 ++-- modules/engine/include/engine/scene/scene.hpp | 12 +-- modules/engine/include/engine/time/timer.hpp | 6 +- .../engine/user_interface/user_interface.hpp | 20 ++--- .../include/engine/utils/file_manager.hpp | 29 +++---- .../include/engine/utils/resource_manager.hpp | 12 +-- .../include/engine/utils/serializer.hpp | 8 +- .../include/engine/utils/stringifier.hpp | 10 +-- modules/engine/src/camera/scene.cpp | 20 ++--- modules/engine/src/core/application.cpp | 20 ++--- modules/engine/src/core/uuid.cpp | 4 +- modules/engine/src/debug/instrumentor.cpp | 3 +- modules/engine/src/debug/logger.cpp | 2 +- modules/engine/src/graphics/blender.cpp | 19 ++--- modules/engine/src/graphics/buffers.cpp | 58 ++++++-------- modules/engine/src/graphics/framebuffer.cpp | 16 ++-- .../engine/src/graphics/graphics_context.cpp | 15 ++-- .../engine/src/graphics/render_command.cpp | 18 ++--- modules/engine/src/graphics/renderer.cpp | 44 +++++------ .../src/graphics/renderer_programs/quad.cpp | 2 +- .../graphics/renderer_programs/texture.cpp | 2 +- .../renderer_programs/tinted_texture.cpp | 2 +- modules/engine/src/graphics/shader.cpp | 16 ++-- modules/engine/src/graphics/texture.cpp | 16 ++-- modules/engine/src/graphics/vertex_layout.cpp | 16 ++-- modules/engine/src/input/input.cpp | 24 +++--- modules/engine/src/layer/layer.cpp | 13 +--- modules/engine/src/layer/layer_stack.cpp | 8 +- modules/engine/src/math/random.cpp | 26 +++---- .../src/platform/graphics/directx/blender.cpp | 6 +- .../src/platform/graphics/directx/buffers.cpp | 52 ++++++------- .../graphics/directx/framebuffers.cpp | 24 +++--- .../graphics/directx/graphics_context.cpp | 22 +++--- .../graphics/directx/render_command.cpp | 8 +- .../src/platform/graphics/directx/shader.cpp | 13 ++-- .../src/platform/graphics/directx/texture.cpp | 8 +- .../graphics/directx/user_interface.cpp | 6 +- .../graphics/directx/vertex_layout.cpp | 9 +-- .../src/platform/graphics/opengl/buffers.cpp | 19 +++-- .../graphics/opengl/graphics_context.cpp | 13 ++-- .../src/platform/graphics/opengl/shader.cpp | 24 +++--- .../src/platform/graphics/opengl/texture.cpp | 22 +++--- .../graphics/opengl/user_interface.cpp | 2 +- .../graphics/opengl/vertex_layout.cpp | 9 ++- .../engine/src/platform/os/linux/l_window.cpp | 75 +++++++------------ modules/engine/src/scene/scene.cpp | 28 +++---- modules/engine/src/time/timer.cpp | 2 +- .../src/user_interface/user_interface.cpp | 8 +- modules/engine/src/utils/file_manager.cpp | 40 +++++----- modules/engine/src/utils/resource_manager.cpp | 8 +- modules/engine/src/utils/serializer.cpp | 64 ++++++++-------- modules/engine/src/utils/stringifier.cpp | 16 ++-- .../include/mirror/panel/scene_hierarchy.hpp | 1 + modules/mirror/src/editor_layer.cpp | 21 +++--- modules/mirror/src/mirror.cpp | 11 +-- modules/mirror/src/panel/asset_browser.cpp | 14 ++-- modules/mirror/src/panel/properties.cpp | 53 +++++++------ modules/mirror/src/panel/scene_hierarchy.cpp | 17 +++-- 97 files changed, 823 insertions(+), 769 deletions(-) diff --git a/modules/engine/include/engine/base/entrypoint.hpp b/modules/engine/include/engine/base/entrypoint.hpp index b2d62f4..70aabd7 100644 --- a/modules/engine/include/engine/base/entrypoint.hpp +++ b/modules/engine/include/engine/base/entrypoint.hpp @@ -2,10 +2,10 @@ #ifdef LIGHT_PLATFORM_WINDOWS - #include + #include // to be defined in client project -extern Light::Application *Light::CreateApplication(); +extern Light::Application *Light::create_application(); // #todo: use windows specific stuff int main(int argc, char *argv[]) @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) try { - application = Light::CreateApplication(); + application = Light::create_application(); lt_assert(application, "Light::Application is not intialized"); for (int i = 0; i < argc; i++) @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) #include // to be defined in client project -extern Light::Application *Light::CreateApplication(); +extern Light::Application *Light::create_application(); // #todo: use linux specific stuff int main(int argc, char *argv[]) @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) try { - application = Light::CreateApplication(); + application = Light::create_application(); lt_assert(application, "Light::Application is not intialized"); application->game_loop(); diff --git a/modules/engine/include/engine/camera/camera.hpp b/modules/engine/include/engine/camera/camera.hpp index 21da5a1..5bd2f0f 100644 --- a/modules/engine/include/engine/camera/camera.hpp +++ b/modules/engine/include/engine/camera/camera.hpp @@ -7,29 +7,29 @@ namespace Light { class Camera { -private: - glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); - -protected: - glm::mat4 m_projection; - public: Camera() = default; - inline const glm::mat4 &GetProjection() const + auto get_projection() const -> const glm::mat4 & { return m_projection; } - inline const glm::vec4 &GetBackgroundColor() const + auto get_background_color() const -> const glm::vec4 & { return m_background_color; } - inline void set_background_color(const glm::vec4 &color) + void set_background_color(const glm::vec4 &color) { m_background_color = color; } + +protected: + glm::mat4 m_projection; + +private: + glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); }; } // namespace Light diff --git a/modules/engine/include/engine/camera/ortho.hpp b/modules/engine/include/engine/camera/ortho.hpp index e61c7c5..90d37ca 100644 --- a/modules/engine/include/engine/camera/ortho.hpp +++ b/modules/engine/include/engine/camera/ortho.hpp @@ -7,18 +7,6 @@ namespace Light { class OrthographicCamera { -private: - glm::vec2 m_position; - float m_aspect_ratio; - float m_zoom_level; - - const glm::vec3 m_up; - - glm::mat4 m_projection; - glm::mat4 m_view; - - glm::vec4 m_clear_color; - public: OrthographicCamera( const glm::vec2 &position, @@ -27,28 +15,43 @@ public: const glm::vec4 &clearColor = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) ); - // CAMERA // void calculate_view(); + void calculate_projection(); void on_resize(const glm::vec2 &size); - inline const glm::mat4 &GetView() const + auto get_view() const -> const glm::mat4 & { return m_view; } - inline const glm::mat4 &GetProjection() const + + auto get_projection() const -> const glm::mat4 & { return m_projection; } - inline const glm::vec4 &GetClearColor() const + auto get_clear_color() const -> const glm::vec4 & { return m_clear_color; } - // CAMERA_CONTROLLER // void move(const glm::vec2 &position); + +private: + glm::vec2 m_position; + + float m_aspect_ratio; + + float m_zoom_level; + + const glm::vec3 m_up; + + glm::mat4 m_projection; + + glm::mat4 m_view; + + glm::vec4 m_clear_color; }; } // namespace Light diff --git a/modules/engine/include/engine/camera/scene.hpp b/modules/engine/include/engine/camera/scene.hpp index 59132f1..7f31fcf 100644 --- a/modules/engine/include/engine/camera/scene.hpp +++ b/modules/engine/include/engine/camera/scene.hpp @@ -14,26 +14,24 @@ public: Perspetcive = 1 }; - struct OrthographicSpecification // :#todo use this + struct OrthographicSpecification { float size; - float nearPlane, farPlane; + + float near_plane; + + float far_plane; }; struct PerspectiveSpecification { - float verticalFOV; - float nearPlane, farPlane; + float vertical_fov; + + float near_plane; + + float far_plane; }; -private: - OrthographicSpecification m_orthographic_specification; - PerspectiveSpecification m_perspective_specification; - float m_aspect_ratio; - - ProjectionType m_projection_type; - -public: SceneCamera(); void set_viewport_size(unsigned int width, unsigned int height); @@ -41,45 +39,62 @@ public: void set_projection_type(ProjectionType projectionType); void set_orthographic_size(float size); + void set_orthographic_far_plane(float farPlane); + void set_orthographic_near_plane(float nearPlane); void set_perspective_vertical_fov(float verticalFov); + void set_perspective_far_plane(float farPlane); + void set_perspective_near_plane(float nearPlane); - inline float get_orthographic_size() const + auto get_orthographic_size() const -> float { return m_orthographic_specification.size; } - inline float get_orthographic_far_plane() const + + auto get_orthographic_far_plane() const -> float { - return m_orthographic_specification.farPlane; - } - inline float get_orthographic_near_plane() const - { - return m_orthographic_specification.nearPlane; + return m_orthographic_specification.far_plane; } - inline float get_perspective_vertical_fov() const + auto get_orthographic_near_plane() const -> float { - return m_perspective_specification.verticalFOV; - } - inline float get_perspective_far_plane() const - { - return m_perspective_specification.farPlane; - } - inline float get_perspective_near_plane() const - { - return m_perspective_specification.nearPlane; + return m_orthographic_specification.near_plane; } - inline ProjectionType get_projection_type() const + auto get_perspective_vertical_fov() const -> float + { + return m_perspective_specification.vertical_fov; + } + + auto get_perspective_far_plane() const -> float + { + return m_perspective_specification.far_plane; + } + + auto get_perspective_near_plane() const -> float + { + return m_perspective_specification.near_plane; + } + + auto get_projection_type() const -> ProjectionType { return m_projection_type; } + private: + OrthographicSpecification m_orthographic_specification; + + PerspectiveSpecification m_perspective_specification; + + float m_aspect_ratio; + + ProjectionType m_projection_type; + void calculate_projection(); }; diff --git a/modules/engine/include/engine/core/application.hpp b/modules/engine/include/engine/core/application.hpp index 14d11cb..1f82318 100644 --- a/modules/engine/include/engine/core/application.hpp +++ b/modules/engine/include/engine/core/application.hpp @@ -48,6 +48,6 @@ private: void log_debug_data(); }; -extern Application *CreateApplication(); +extern Application *create_application(); } // namespace Light diff --git a/modules/engine/include/engine/core/window.hpp b/modules/engine/include/engine/core/window.hpp index c0fe278..3ff4832 100644 --- a/modules/engine/include/engine/core/window.hpp +++ b/modules/engine/include/engine/core/window.hpp @@ -11,7 +11,9 @@ class Event; struct WindowProperties { std::string title; + glm::uvec2 size; + bool vsync, visible; }; @@ -41,47 +43,49 @@ public: virtual void set_title(const std::string &title) = 0; - virtual void set_size(const glm::uvec2 &size, bool additive = false) = 0; // pass 0 for width or - // height for single - // dimension resizing + /** pass 0 for width or height for single dimension resizing */ + virtual void set_size(const glm::uvec2 &size, bool additive = false) = 0; - inline void close() + void close() { b_Closed = true; } + virtual void set_v_sync(bool vsync, bool toggle = false) = 0; virtual void set_visibility(bool visible, bool toggle = false) = 0; - inline GraphicsContext *GetGfxContext() const + auto get_graphics_context() const -> GraphicsContext * { return m_graphics_context.get(); } - inline const WindowProperties &GetProperties() const + auto get_properties() const -> const WindowProperties & { return m_properties; } - inline const std::string &GetTitle() const + auto get_title() const -> const std::string & { return m_properties.title; } - inline const glm::uvec2 &get_size() const + auto get_size() const -> const glm::uvec2 & { return m_properties.size; } - inline bool is_closed() const + auto is_closed() const -> bool { return b_Closed; } - inline bool is_v_sync() const + + auto is_v_sync() const -> bool { return m_properties.vsync; } - inline bool is_visible() const + + auto is_visible() const -> bool { return m_properties.visible; } diff --git a/modules/engine/include/engine/debug/instrumentor.hpp b/modules/engine/include/engine/debug/instrumentor.hpp index 5349a42..37c4fe0 100644 --- a/modules/engine/include/engine/debug/instrumentor.hpp +++ b/modules/engine/include/engine/debug/instrumentor.hpp @@ -18,16 +18,16 @@ class Instrumentor public: static Scope create(); - static inline void begin_session(const std::string &outputPath) + static void begin_session(const std::string &outputPath) { s_context->begin_session_impl(outputPath); } - static inline void end_session() + static void end_session() { s_context->end_session_impl(); } - static inline void submit_scope_profile(const ScopeProfileResult &profileResult) + static void submit_scope_profile(const ScopeProfileResult &profileResult) { s_context->submit_scope_profile_impl(profileResult); } diff --git a/modules/engine/include/engine/debug/logger.hpp b/modules/engine/include/engine/debug/logger.hpp index ba7f174..3cd6d60 100644 --- a/modules/engine/include/engine/debug/logger.hpp +++ b/modules/engine/include/engine/debug/logger.hpp @@ -30,11 +30,12 @@ class logger public: static Scope create(); - static inline Ref get_engine_logger() + static auto get_engine_logger() -> Ref { return s_context->m_engine_logger; } - static inline Ref get_file_logger() + + static auto get_file_logger() -> Ref { return s_context->m_file_logger; } diff --git a/modules/engine/include/engine/events/char.hpp b/modules/engine/include/engine/events/char.hpp index 3d6e0cc..fba8329 100644 --- a/modules/engine/include/engine/events/char.hpp +++ b/modules/engine/include/engine/events/char.hpp @@ -13,20 +13,20 @@ public: { } - inline int get_character() const + auto get_character() const -> int { return m_character; } - virtual std::string get_info_lt_log() const override + auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "CharSet: " << m_character; return ss.str(); } - event_type(SetChar); + event_category(InputEventCategory | KeyboardEventCategory); private: diff --git a/modules/engine/include/engine/events/event.hpp b/modules/engine/include/engine/events/event.hpp index 35e970b..18d2c50 100644 --- a/modules/engine/include/engine/events/event.hpp +++ b/modules/engine/include/engine/events/event.hpp @@ -36,25 +36,32 @@ enum EventCategory MouseEventCategory = bit(3), }; -#define event_type(type) \ +#define event_type(type) \ EventType get_event_type() const override \ - { \ - return ::Light::EventType::type; \ + { \ + return ::Light::EventType::type; \ } -#define event_category(eCategory) \ + +#define event_category(eCategory) \ inline bool has_category(EventCategory category) const override \ - { \ - return (eCategory) & category; \ + { \ + return (eCategory) & category; \ } class Event { public: - virtual EventType get_event_type() const = 0; - virtual std::string get_info_lt_log() const = 0; - virtual bool has_category(EventCategory category) const = 0; + Event() = default; - friend std::ostream &operator<<(std::ostream &os, const Event &e) + virtual ~Event() = default; + + virtual auto get_event_type() const -> EventType = 0; + + virtual auto get_info_lt_log() const -> std::string = 0; + + virtual auto has_category(EventCategory category) const -> bool = 0; + + friend auto operator<<(std::ostream &os, const Event &e) -> std::ostream & { return os << e.get_info_lt_log(); } diff --git a/modules/engine/include/engine/events/keyboard.hpp b/modules/engine/include/engine/events/keyboard.hpp index 30aa0cb..31b3f15 100644 --- a/modules/engine/include/engine/events/keyboard.hpp +++ b/modules/engine/include/engine/events/keyboard.hpp @@ -13,12 +13,12 @@ public: { } - inline int get_key() const + auto get_key() const -> int { return m_key; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "KeyPressed: " << m_key; @@ -40,18 +40,20 @@ public: { } - inline int get_key() const + auto get_key() const -> int { return m_key; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "KeyRepeated: " << m_key; return ss.str(); } + event_type(KeyRepeated); + event_category(InputEventCategory | KeyboardEventCategory); private: @@ -65,12 +67,12 @@ public: { } - inline int get_key() const + auto get_key() const -> int { return m_key; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "KeyReleased: " << m_key; @@ -78,6 +80,7 @@ public: } event_type(KeyReleased); + event_category(InputEventCategory | KeyboardEventCategory); private: diff --git a/modules/engine/include/engine/events/mouse.hpp b/modules/engine/include/engine/events/mouse.hpp index 29bb3f7..1e44c13 100644 --- a/modules/engine/include/engine/events/mouse.hpp +++ b/modules/engine/include/engine/events/mouse.hpp @@ -14,27 +14,30 @@ public: { } - inline const glm::vec2 &GetPosition() const + auto get_position() const -> const glm::vec2 & { return m_position; } - inline float get_x() const + auto get_x() const -> float { return m_position.x; } - inline float get_y() const + + auto get_y() const -> float { return m_position.y; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "MouseMoved: " << m_position.x << ", " << m_position.y; return ss.str(); } + event_type(MouseMoved); + event_category(InputEventCategory | MouseEventCategory); private: @@ -48,18 +51,20 @@ public: { } - inline float get_offset() const + auto get_offset() const -> float { return m_offset; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "WheelScrolled: " << m_offset; return ss.str(); } + event_type(WheelScrolled); + event_category(InputEventCategory | MouseEventCategory); private: @@ -73,18 +78,20 @@ public: { } - inline int get_button() const + auto get_button() const -> int { return m_button; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "ButtonPressed: " << m_button; return ss.str(); } + event_type(ButtonPressed); + event_category(InputEventCategory | MouseEventCategory); private: @@ -98,12 +105,12 @@ public: { } - inline int get_button() const + auto get_button() const -> int { return m_button; } - virtual std::string get_info_lt_log() const override + virtual auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "ButtonReleased: " << m_button; @@ -111,6 +118,7 @@ public: } event_type(ButtonReleased); + event_category(InputEventCategory | MouseEventCategory); private: diff --git a/modules/engine/include/engine/events/window.hpp b/modules/engine/include/engine/events/window.hpp index 29d24e4..00fe178 100644 --- a/modules/engine/include/engine/events/window.hpp +++ b/modules/engine/include/engine/events/window.hpp @@ -10,7 +10,7 @@ namespace Light { class WindowClosedEvent: public Event { public: - virtual std::string get_info_lt_log() const override + auto get_info_lt_log() const -> std::string override { return "WindowClosedEvent"; } @@ -27,12 +27,12 @@ public: { } - const glm::ivec2 &GetPosition() const + auto get_position() const -> const glm::ivec2 & { return m_position; } - virtual std::string get_info_lt_log() const override + auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "WindwoMoved: " << m_position.x << ", " << m_position.y; @@ -55,12 +55,12 @@ public: { } - const glm::uvec2 &get_size() const + auto get_size() const -> const glm::uvec2 & { return m_size; } - virtual std::string get_info_lt_log() const override + auto get_info_lt_log() const -> std::string override { std::stringstream ss; ss << "WindowResized: " << m_size.x << ", " << m_size.y; @@ -78,24 +78,26 @@ private: class WindowLostFocusEvent: public Event { public: - virtual std::string get_info_lt_log() const override + auto get_info_lt_log() const -> std::string override { return "WindowLostFocus"; } event_type(WindowLostFocus); + event_category(WindowEventCategory); }; class WindowGainFocusEvent: public Event { public: - virtual std::string get_info_lt_log() const override + auto get_info_lt_log() const -> std::string override { return "WindowGainFocus"; } event_type(WindowGainFocus); + event_category(WindowEventCategory); }; diff --git a/modules/engine/include/engine/graphics/blender.hpp b/modules/engine/include/engine/graphics/blender.hpp index 560b6dc..87df726 100644 --- a/modules/engine/include/engine/graphics/blender.hpp +++ b/modules/engine/include/engine/graphics/blender.hpp @@ -37,9 +37,10 @@ enum class BlendFactor : uint8_t class Blender { public: - static Scope create(Ref sharedContext); + static auto create(Ref sharedContext) -> Scope; virtual void enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0; + virtual void disable() = 0; protected: diff --git a/modules/engine/include/engine/graphics/buffers.hpp b/modules/engine/include/engine/graphics/buffers.hpp index d93dae2..2c47541 100644 --- a/modules/engine/include/engine/graphics/buffers.hpp +++ b/modules/engine/include/engine/graphics/buffers.hpp @@ -11,13 +11,17 @@ enum class ConstantBufferIndex ViewProjection = 0u }; -//========== CONSTANT_BUFFER ==========// class ConstantBuffer { public: - static Scope create(ConstantBufferIndex index, unsigned int size, Ref sharedContext); + static auto create( + ConstantBufferIndex index, + unsigned int size, + Ref sharedContext + ) -> Scope; + + virtual auto map() -> void * = 0; - virtual void* map() = 0; virtual void un_map() = 0; virtual void bind() = 0; @@ -26,33 +30,40 @@ protected: ConstantBuffer() = default; }; -//========== VERTEX_BUFFER ==========// class VertexBuffer { public: - static Ref create(float* vertices, unsigned int stride, unsigned int count, Ref sharedContext); + static auto create( + float *vertices, + unsigned int stride, + unsigned int count, + Ref sharedContext + ) -> Ref; virtual ~VertexBuffer() = default; - virtual void* map() = 0; + virtual auto map() -> void * = 0; + virtual void un_map() = 0; - virtual void bind() = 0; + virtual void bind() = 0; + virtual void un_bind() = 0; protected: VertexBuffer() = default; }; -//========== INDEX_BUFFER ==========// class IndexBuffer { public: - static Ref create(unsigned int* indices, unsigned int count, Ref sharedContext); + static auto create(unsigned int *indices, unsigned int count, Ref sharedContext) + -> Ref; virtual ~IndexBuffer() = default; - virtual void bind() = 0; + virtual void bind() = 0; + virtual void un_bind() = 0; protected: diff --git a/modules/engine/include/engine/graphics/framebuffer.hpp b/modules/engine/include/engine/graphics/framebuffer.hpp index 696852b..f4765fb 100644 --- a/modules/engine/include/engine/graphics/framebuffer.hpp +++ b/modules/engine/include/engine/graphics/framebuffer.hpp @@ -1,7 +1,6 @@ #pragma once #include - #include namespace Light { @@ -10,21 +9,28 @@ class SharedContext; struct FramebufferSpecification { - unsigned int width, height; + unsigned int width; + + unsigned int height; + unsigned int samples = 1; }; class Framebuffer { public: - static Ref create(const FramebufferSpecification& specification, Ref sharedContext); + static auto create( + const FramebufferSpecification &specification, + Ref sharedContext + ) -> Ref; - virtual void bind_as_target(const glm::vec4& clearColor) = 0; - virtual void bind_as_resource() = 0; + virtual void bind_as_target(const glm::vec4 &clearColor) = 0; - virtual void resize(const glm::uvec2& size) = 0; + virtual void bind_as_resource() = 0; - virtual void* GetColorAttachment() = 0; + virtual void resize(const glm::uvec2 &size) = 0; + + virtual auto get_color_attachment() -> void * = 0; protected: Framebuffer() = default; diff --git a/modules/engine/include/engine/graphics/graphics_context.hpp b/modules/engine/include/engine/graphics/graphics_context.hpp index ba0c3af..22c8a14 100644 --- a/modules/engine/include/engine/graphics/graphics_context.hpp +++ b/modules/engine/include/engine/graphics/graphics_context.hpp @@ -6,7 +6,7 @@ struct GLFWwindow; namespace Light { -class renderer; +class Renderer; class resource_manager; class SharedContext; class UserInterface; @@ -24,7 +24,7 @@ enum class GraphicsAPI class GraphicsContext { public: - static Scope create(GraphicsAPI api, GLFWwindow *windowHandle); + static auto create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope; GraphicsContext(const GraphicsContext &) = delete; @@ -34,22 +34,22 @@ public: virtual void log_debug_data() = 0; - static inline GraphicsAPI get_graphics_api() + static GraphicsAPI get_graphics_api() { return s_context->m_graphics_api; } - static inline Ref get_shared_context() + static Ref get_shared_context() { return s_context->m_shared_context; } - inline renderer *GetRenderer() + auto get_renderer() -> Renderer * { return m_renderer.get(); } - inline UserInterface *GetUserInterface() + auto get_user_interface() -> UserInterface * { return m_user_interface.get(); } @@ -66,7 +66,7 @@ private: Scope m_user_interface; - Scope m_renderer; + Scope m_renderer; }; } // namespace Light diff --git a/modules/engine/include/engine/graphics/render_command.hpp b/modules/engine/include/engine/graphics/render_command.hpp index 963fa87..fc5faba 100644 --- a/modules/engine/include/engine/graphics/render_command.hpp +++ b/modules/engine/include/engine/graphics/render_command.hpp @@ -12,11 +12,12 @@ class SharedContext; class RenderCommand { public: - static Scope create(GLFWwindow *windowHandle, Ref sharedContext); + static auto create(GLFWwindow *windowHandle, Ref sharedContext) + -> Scope; RenderCommand(const RenderCommand &) = delete; - RenderCommand &operator=(const RenderCommand &) = delete; + auto operator=(const RenderCommand &) -> RenderCommand & = delete; virtual ~RenderCommand() = default; diff --git a/modules/engine/include/engine/graphics/renderer.hpp b/modules/engine/include/engine/graphics/renderer.hpp index 16b219f..ff0be54 100644 --- a/modules/engine/include/engine/graphics/renderer.hpp +++ b/modules/engine/include/engine/graphics/renderer.hpp @@ -22,12 +22,13 @@ class SharedContext; class Camera; class WindowResizedEvent; -class renderer +class Renderer { public: - static Scope create(GLFWwindow *windowHandle, Ref sharedContext); + static auto create(GLFWwindow *windowHandle, Ref sharedContext) + -> Scope; - static inline void draw_quad( + static void draw_quad( const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint, @@ -37,20 +38,12 @@ public: s_context->draw_quad_impl(position, size, tint, texture); } - static inline void draw_quad( - const glm::vec3 &position, - const glm::vec2 &size, - const glm::vec4 &tint - ) + static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint) { s_context->draw_quad_impl(position, size, tint); } - static inline void draw_quad( - const glm::vec3 &position, - const glm::vec2 &size, - Ref texture - ) + static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, Ref texture) { s_context->draw_quad_impl(position, size, texture); } @@ -70,7 +63,7 @@ public: s_context->draw_quad_impl(transform, texture); } - static inline void begin_scene( + static void begin_scene( Camera *camera, const glm::mat4 &cameraTransform, const Ref &targetFrameBuffer = nullptr @@ -78,7 +71,8 @@ public: { s_context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer); } - static inline void end_scene() + + static void end_scene() { s_context->end_scene_impl(); } @@ -86,10 +80,11 @@ public: void on_window_resize(const WindowResizedEvent &event); void begin_frame(); + void end_frame(); private: - static renderer *s_context; + static Renderer *s_context; QuadRendererProgram m_quad_renderer; @@ -109,7 +104,7 @@ private: bool m_should_clear_backbuffer; - renderer(GLFWwindow *windowHandle, Ref sharedContext); + Renderer(GLFWwindow *windowHandle, Ref sharedContext); void draw_quad_impl( const glm::vec3 &position, diff --git a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp b/modules/engine/include/engine/graphics/renderer_programs/quad.hpp index 88fb684..51a8982 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/quad.hpp @@ -10,9 +10,7 @@ class Shader; class VertexBuffer; class IndexBuffer; class VertexLayout; - class OrthographicCamera; - class SharedContext; class QuadRendererProgram: RendererProgram @@ -26,7 +24,7 @@ public: QuadRendererProgram(unsigned int maxVertices, Ref sharedContext); - bool advance(); + auto advance() -> bool; void map() override; @@ -34,17 +32,17 @@ public: void bind() override; - inline QuadVertexData *GetMapCurrent() + auto get_map_current() -> QuadVertexData * { return m_map_current; } - inline unsigned int get_quad_count() const + auto get_quad_count() const -> unsigned int { return m_quad_count; } - inline constexpr unsigned int get_vertex_size() const + constexpr auto get_vertex_size() const -> unsigned int { return sizeof(QuadVertexData); } diff --git a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp b/modules/engine/include/engine/graphics/renderer_programs/texture.hpp index 2fdf891..e0ded45 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/texture.hpp @@ -19,12 +19,13 @@ public: struct TextureVertexData { glm::vec4 position; + glm::vec2 texcoord; }; TextureRendererProgram(unsigned int maxVertices, Ref sharedContext); - bool advance(); + auto advance() -> bool; void map() override; @@ -32,17 +33,17 @@ public: void bind() override; - inline TextureVertexData *GetMapCurrent() + auto get_map_current() -> TextureVertexData * { return m_map_current; } - inline unsigned int get_quad_count() const + auto get_quad_count() const -> unsigned int { return m_quad_count; } - inline constexpr unsigned int get_vertex_size() const + constexpr auto get_vertex_size() const -> unsigned int { return sizeof(TextureVertexData); } 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 bb15f7f..84c4152 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp @@ -10,9 +10,7 @@ class Shader; class VertexBuffer; class IndexBuffer; class VertexLayout; - class OrthographicCamera; - class SharedContext; class TintedTextureRendererProgram: RendererProgram @@ -21,30 +19,33 @@ public: struct TintedTextureVertexData { glm::vec4 position; + glm::vec4 tint; + glm::vec2 texcoord; }; TintedTextureRendererProgram(unsigned int maxVertices, Ref sharedContext); - bool advance(); + auto advance() -> bool; void map() override; + void un_map() override; void bind() override; - inline TintedTextureVertexData *GetMapCurrent() + auto get_map_current() -> TintedTextureVertexData * { return m_map_current; } - inline unsigned int get_quad_count() const + auto get_quad_count() const -> unsigned int { return m_quad_count; } - inline constexpr unsigned int get_vertex_size() const + constexpr auto get_vertex_size() const -> unsigned int { return sizeof(TintedTextureVertexData); } diff --git a/modules/engine/include/engine/graphics/shader.hpp b/modules/engine/include/engine/graphics/shader.hpp index 3b817cb..21c568e 100644 --- a/modules/engine/include/engine/graphics/shader.hpp +++ b/modules/engine/include/engine/graphics/shader.hpp @@ -19,11 +19,11 @@ public: GEOMETRY = 3 }; - static Ref create( + static auto create( BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref sharedContext - ); + ) -> Ref; virtual ~Shader() = default; diff --git a/modules/engine/include/engine/graphics/texture.hpp b/modules/engine/include/engine/graphics/texture.hpp index 68fd194..daebfbd 100644 --- a/modules/engine/include/engine/graphics/texture.hpp +++ b/modules/engine/include/engine/graphics/texture.hpp @@ -6,7 +6,6 @@ namespace Light { class SharedContext; -// #todo: improve textures class Texture { public: @@ -21,15 +20,15 @@ public: Texture(const Texture &) = delete; - Texture &operator=(const Texture &) = delete; + auto operator=(const Texture &) -> Texture & = delete; virtual ~Texture() = default; virtual void bind(unsigned int slot = 0) = 0; - virtual void *get_texture() = 0; + virtual auto get_texture() -> void * = 0; - inline const std::string &GetFilePath() const + auto GetFilePath() const -> const std::string & { return m_file_path; } diff --git a/modules/engine/include/engine/graphics/vertex_layout.hpp b/modules/engine/include/engine/graphics/vertex_layout.hpp index 1e7fa64..27fd5a1 100644 --- a/modules/engine/include/engine/graphics/vertex_layout.hpp +++ b/modules/engine/include/engine/graphics/vertex_layout.hpp @@ -33,12 +33,12 @@ enum class VertexElementType class VertexLayout { public: - static Ref create( + static auto create( Ref vertexBuffer, Ref shader, const std::vector> &elements, Ref sharedContext - ); + ) -> Ref; virtual ~VertexLayout() = default; diff --git a/modules/engine/include/engine/input/input.hpp b/modules/engine/include/engine/input/input.hpp index e68132d..7209389 100644 --- a/modules/engine/include/engine/input/input.hpp +++ b/modules/engine/include/engine/input/input.hpp @@ -11,38 +11,39 @@ class Event; class Input { public: - static Scope create(); + static auto create() -> Scope; - static inline void receive_user_interface_events(bool receive, bool toggle = false) + static void receive_user_interface_events(bool receive, bool toggle = false) { s_context->receive_user_interface_events_impl(receive, toggle); } - static inline void receive_game_events(bool receive, bool toggle = false) + static void receive_game_events(bool receive, bool toggle = false) { s_context->receieve_game_events_impl(receive, toggle); } - static inline bool get_keyboard_key(int code) + static auto get_keyboard_key(int code) -> bool { return s_context->m_keyboad_keys[code]; } - static inline bool get_mouse_button(int code) + static auto get_mouse_button(int code) -> bool { return s_context->m_mouse_buttons[code]; } - static inline const glm::vec2 &get_mouse_position(int code) + static auto get_mouse_position(int code) -> const glm::vec2 & { return s_context->m_mouse_position; } void on_event(const Event &inputEvent); - inline bool is_receiving_input_events() const + auto is_receiving_input_events() const -> bool { return m_user_interface_events; } - inline bool is_receiving_game_events() const + + auto is_receiving_game_events() const -> bool { return m_game_events; } diff --git a/modules/engine/include/engine/layer/layer.hpp b/modules/engine/include/engine/layer/layer.hpp index 953054c..d07af59 100644 --- a/modules/engine/include/engine/layer/layer.hpp +++ b/modules/engine/include/engine/layer/layer.hpp @@ -25,9 +25,10 @@ class Layer { public: Layer(const std::string &name); + virtual ~Layer() = default; - const std::string &GetName() const + auto get_name() const -> const std::string & { return m_layer_name; } @@ -43,72 +44,72 @@ public: { } - bool on_event(const Event &event); + auto on_event(const Event &event) -> bool; protected: std::string m_layer_name; - virtual bool on_mouse_moved(const MouseMovedEvent &event) + virtual auto on_mouse_moved(const MouseMovedEvent &event) -> bool { return false; } - virtual bool on_button_pressed(const ButtonPressedEvent &event) + virtual auto on_button_pressed(const ButtonPressedEvent &event) -> bool { return false; } - virtual bool on_button_released(const ButtonReleasedEvent &event) + virtual auto on_button_released(const ButtonReleasedEvent &event) -> bool { return false; } - virtual bool on_wheel_scrolled(const WheelScrolledEvent &event) + virtual auto on_wheel_scrolled(const WheelScrolledEvent &event) -> bool { return false; } - virtual bool on_key_pressed(const KeyPressedEvent &event) + virtual auto on_key_pressed(const KeyPressedEvent &event) -> bool { return false; } - virtual bool on_key_repeat(const KeyRepeatEvent &event) + virtual auto on_key_repeat(const KeyRepeatEvent &event) -> bool { return false; } - virtual bool on_key_released(const KeyReleasedEvent &event) + virtual auto on_key_released(const KeyReleasedEvent &event) -> bool { return false; } - virtual bool on_set_char(const SetCharEvent &event) + virtual auto on_set_char(const SetCharEvent &event) -> bool { return false; } - virtual bool on_window_closed(const WindowClosedEvent &event) + virtual auto on_window_closed(const WindowClosedEvent &event) -> bool { return false; } - virtual bool on_window_resized(const WindowResizedEvent &event) + virtual auto on_window_resized(const WindowResizedEvent &event) -> bool { return false; } - virtual bool on_window_moved(const WindowMovedEvent &event) + virtual auto on_window_moved(const WindowMovedEvent &event) -> bool { return false; } - virtual bool on_window_lost_focus(const WindowLostFocusEvent &event) + virtual auto on_window_lost_focus(const WindowLostFocusEvent &event) -> bool { return false; } - virtual bool on_window_gain_focus(const WindowGainFocusEvent &event) + virtual auto on_window_gain_focus(const WindowGainFocusEvent &event) -> bool { return false; } diff --git a/modules/engine/include/engine/layer/layer_stack.hpp b/modules/engine/include/engine/layer/layer_stack.hpp index 4e2ea28..71992d7 100644 --- a/modules/engine/include/engine/layer/layer_stack.hpp +++ b/modules/engine/include/engine/layer/layer_stack.hpp @@ -10,47 +10,48 @@ class Event; class LayerStack /* singleton */ { public: - static Scope create(); + static auto create() -> Scope; ~LayerStack(); // #todo: is this needed? template - static inline void emplace_layer(Args &&...args) + static void emplace_layer(Args &&...args) { s_context->attach_layer_impl(new t((args)...)); } - static inline void attach_layer(Layer *layer) + static void attach_layer(Layer *layer) { s_context->attach_layer_impl(layer); } - static inline void detach_layer(Layer *layer) + + static void detach_layer(Layer *layer) { s_context->detach_layer_impl(layer); } - inline bool is_empty() + auto is_empty() -> bool { return m_layers.empty(); } - std::vector::iterator begin() + auto begin() -> std::vector::iterator { return m_layers.begin(); } - std::vector::iterator end() + auto end() -> std::vector::iterator { return m_layers.end(); } - std::vector::reverse_iterator rbegin() + auto rbegin() -> std::vector::reverse_iterator { return m_layers.rbegin(); } - std::vector::reverse_iterator rend() + auto rend() -> std::vector::reverse_iterator { return m_layers.rend(); } diff --git a/modules/engine/include/engine/math/random.hpp b/modules/engine/include/engine/math/random.hpp index a17165b..2e870c3 100644 --- a/modules/engine/include/engine/math/random.hpp +++ b/modules/engine/include/engine/math/random.hpp @@ -7,10 +7,14 @@ #include -namespace Light { namespace Math { +namespace Light { +namespace Math { - float rand(int min, int max, int decimals = 0); - glm::vec2 rand_vec2(int min, int max, int decimals = 0); - glm::vec3 rand_vec3(int min, int max, int decimals = 0); +auto rand(int min, int max, int decimals = 0) -> float; -}} \ No newline at end of file +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 Math +} // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/buffers.hpp b/modules/engine/include/engine/platform/graphics/directx/buffers.hpp index eab79c3..c53c98c 100644 --- a/modules/engine/include/engine/platform/graphics/directx/buffers.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/buffers.hpp @@ -50,7 +50,7 @@ public: void un_bind() override; - void *map() override; + auto map() -> void * override; void un_map() override; diff --git a/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp b/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp index 80b7037..097d2a0 100644 --- a/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp @@ -17,7 +17,7 @@ public: Ref sharedContext ); - inline void *GetColorAttachment() override + auto get_color_attachment() -> void * override { return (void *)m_shader_resource_view.Get(); } diff --git a/modules/engine/include/engine/platform/graphics/directx/shader.hpp b/modules/engine/include/engine/platform/graphics/directx/shader.hpp index 3baff09..f56637f 100644 --- a/modules/engine/include/engine/platform/graphics/directx/shader.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/shader.hpp @@ -25,7 +25,7 @@ public: void un_bind() override; - inline Microsoft::WRL::ComPtr get_vertex_blob() + auto get_vertex_blob() -> Microsoft::WRL::ComPtr { return m_vertex_blob; } diff --git a/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp b/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp index 8cbeb03..9c41a31 100644 --- a/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp @@ -10,42 +10,42 @@ namespace Light { class dxSharedContext: public SharedContext { public: - inline Microsoft::WRL::ComPtr get_device() + [[nodiscard]] auto get_device() -> Microsoft::WRL::ComPtr { return m_device; } - inline Microsoft::WRL::ComPtr get_device_context() + [[nodiscard]] auto get_device_context() -> Microsoft::WRL::ComPtr { return m_deviceContext; } - inline Microsoft::WRL::ComPtr get_swap_chain() + [[nodiscard]] auto get_swap_chain() -> Microsoft::WRL::ComPtr { return m_swap_chain; } - inline Microsoft::WRL::ComPtr get_render_target_view() + [[nodiscard]] auto get_render_target_view() -> Microsoft::WRL::ComPtr { return m_render_target_view; } - inline Microsoft::WRL::ComPtr &GetDeviceRef() + [[nodiscard]] auto &GetDeviceRef() -> Microsoft::WRL::ComPtr { return m_device; } - inline Microsoft::WRL::ComPtr &GetDeviceContextRef() + [[nodiscard]] auto &GetDeviceContextRef() -> Microsoft::WRL::ComPtr { return m_deviceContext; } - inline Microsoft::WRL::ComPtr &GetSwapChainRef() + [[nodiscard]] auto &GetSwapChainRef() -> Microsoft::WRL::ComPtr { return m_swap_chain; } - inline Microsoft::WRL::ComPtr &GetRenderTargetViewRef() + [[nodiscard]] auto &GetRenderTargetViewRef() -> Microsoft::WRL::ComPtr { return m_render_target_view; } diff --git a/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp b/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp index 41d983e..f567061 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp @@ -14,7 +14,7 @@ public: void bind() override; - void *map() override; + auto map() -> void * override; void un_map() override; @@ -35,7 +35,7 @@ public: void un_bind() override; - void *map() override; + auto map() -> void * override; void un_map() override; diff --git a/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp b/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp index 4cb2f22..743bbf9 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp @@ -18,7 +18,7 @@ public: void resize(const glm::uvec2 &size) override; - inline void *GetColorAttachment() override + auto get_color_attachment() -> void * override { return (void *)m_color_attachment_id; } diff --git a/modules/engine/include/engine/platform/graphics/opengl/texture.hpp b/modules/engine/include/engine/platform/graphics/opengl/texture.hpp index a5b818a..cf7c3cd 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/texture.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/texture.hpp @@ -20,7 +20,7 @@ public: void bind(unsigned int slot = 0u) override; - void *get_texture() override; + auto get_texture() -> void * override; private: unsigned int m_texture_id; diff --git a/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp b/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp index ce0b664..4d873df 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp @@ -33,7 +33,7 @@ public: void un_bind() override; private: - glVertexElementDesc get_element_desc(VertexElementType type, unsigned int offset); + auto get_element_desc(VertexElementType type, unsigned int offset) -> glVertexElementDesc; unsigned int m_array_id; }; diff --git a/modules/engine/include/engine/scene/components/scriptable_entity.hpp b/modules/engine/include/engine/scene/components/scriptable_entity.hpp index 8da9b00..ba8d88d 100644 --- a/modules/engine/include/engine/scene/components/scriptable_entity.hpp +++ b/modules/engine/include/engine/scene/components/scriptable_entity.hpp @@ -14,15 +14,15 @@ public: virtual ~NativeScript() = default; - inline unsigned int get_uid() const + auto get_uid() const -> unsigned int { return m_unique_identifier; } template - t &GetComponent() + auto GetComponent() -> t & { - return m_entity.GetComponent(); + return m_entity.get_component(); } protected: diff --git a/modules/engine/include/engine/scene/components/transform.hpp b/modules/engine/include/engine/scene/components/transform.hpp index 64a9505..7e29dea 100644 --- a/modules/engine/include/engine/scene/components/transform.hpp +++ b/modules/engine/include/engine/scene/components/transform.hpp @@ -25,7 +25,7 @@ struct TransformComponent { } - inline glm::mat4 get_transform() const + auto get_transform() const -> glm::mat4 { return glm::translate(translation) * glm::rotate(rotation.z, glm::vec3(0.0f, 0.0f, 1.0f)) * glm::scale(scale); diff --git a/modules/engine/include/engine/scene/entity.hpp b/modules/engine/include/engine/scene/entity.hpp index d4f4dfb..57793c3 100644 --- a/modules/engine/include/engine/scene/entity.hpp +++ b/modules/engine/include/engine/scene/entity.hpp @@ -15,35 +15,35 @@ public: ~Entity(); template - inline t &AddComponent(Args &&...args) + auto add_component(Args &&...args) -> t & { return m_scene->m_registry.emplace(m_handle, std::forward(args)...); } template - inline t &GetComponent() + auto get_component() -> t & { return m_scene->m_registry.get(m_handle); } template - inline bool has_component() + auto has_component() -> bool { return m_scene->m_registry.any_of(m_handle); } template - inline void remove_component() + void remove_component() { m_scene->m_registry.remove(m_handle); } - inline uint64_t get_uuid() + auto get_uuid() -> uint64_t { - return GetComponent().uuid; + return get_component().uuid; } - inline bool is_valid() const + auto is_valid() const -> bool { return m_handle != entt::null && m_scene != nullptr; } @@ -55,6 +55,7 @@ public: private: entt::entity m_handle; + Scene *m_scene; }; diff --git a/modules/engine/include/engine/scene/scene.hpp b/modules/engine/include/engine/scene/scene.hpp index 7b8f859..7f59d45 100644 --- a/modules/engine/include/engine/scene/scene.hpp +++ b/modules/engine/include/engine/scene/scene.hpp @@ -24,25 +24,27 @@ public: void on_render(const Ref &targetFrameBuffer = nullptr); - Entity create_entity( + auto create_entity( const std::string &name, const TransformComponent &transform = TransformComponent() - ); + ) -> Entity; - Entity get_entity_by_tag(const std::string &tag); + auto get_entity_by_tag(const std::string &tag) -> Entity; private: friend class Entity; + friend class SceneSerializer; + friend class SceneHierarchyPanel; entt::registry m_registry; - Entity create_entity_with_uuid( + auto create_entity_with_uuid( const std::string &name, UUID uuid, const TransformComponent &transform = TransformComponent() - ); + ) -> Entity; }; } // namespace Light diff --git a/modules/engine/include/engine/time/timer.hpp b/modules/engine/include/engine/time/timer.hpp index 8bcd9df..df4661a 100644 --- a/modules/engine/include/engine/time/timer.hpp +++ b/modules/engine/include/engine/time/timer.hpp @@ -10,7 +10,7 @@ class Timer public: Timer(); - inline float get_elapsed_time() const + auto get_elapsed_time() const -> float { return (std::chrono::duration_cast( std::chrono::steady_clock::now() - m_start @@ -19,7 +19,7 @@ public: / 1000.; } - inline void reset() + void reset() { m_start = std::chrono::steady_clock::now(); } @@ -35,7 +35,7 @@ public: void update(); - inline float get_delta_time() const + auto get_delta_time() const -> float { return m_delta_time; } diff --git a/modules/engine/include/engine/user_interface/user_interface.hpp b/modules/engine/include/engine/user_interface/user_interface.hpp index 41b867d..5973e56 100644 --- a/modules/engine/include/engine/user_interface/user_interface.hpp +++ b/modules/engine/include/engine/user_interface/user_interface.hpp @@ -14,20 +14,21 @@ class SharedContext; class UserInterface /* singleton */ { public: - static Scope create(GLFWwindow *windowHandle, Ref sharedContext); - - UserInterface(const UserInterface &) = delete; - - UserInterface &operator=(const UserInterface &) = delete; - - virtual ~UserInterface() = default; - - void init(GLFWwindow *windowHandle, Ref sharedContext); + static auto create(GLFWwindow *windowHandle, Ref sharedContext) + -> Scope; static void dockspace_begin(); static void dockspace_end(); + UserInterface(const UserInterface &) = delete; + + auto operator=(const UserInterface &) -> UserInterface & = delete; + + virtual ~UserInterface() = default; + + void init(GLFWwindow *windowHandle, Ref sharedContext); + virtual void platform_implementation( GLFWwindow *windowHandle, Ref sharedContext @@ -47,7 +48,6 @@ private: void set_dark_theme_colors(); - ImGuiWindowFlags m_dockspace_flags; }; diff --git a/modules/engine/include/engine/utils/file_manager.hpp b/modules/engine/include/engine/utils/file_manager.hpp index d996116..1ddb6de 100644 --- a/modules/engine/include/engine/utils/file_manager.hpp +++ b/modules/engine/include/engine/utils/file_manager.hpp @@ -17,42 +17,42 @@ public: virtual void release(); - inline uint8_t *get_data() + auto get_data() -> uint8_t * { return m_data; } - inline uint32_t get_size() + auto get_size() -> uint32_t { return m_size; } - inline const std::string &get_path() + auto get_path() -> const std::string & { return m_path; } - inline const std::string &get_name() + auto get_name() -> const std::string & { return m_name; } - inline const std::string &get_extension() + auto get_extension() -> const std::string & { return m_extension; } - inline const std::string &get_name_with_extention() + auto get_name_with_extention() -> const std::string & { return m_name + '.' + m_extension; } - inline bool is_valid() const + auto is_valid() const -> bool { return !!m_data; } - inline operator bool() const + operator bool() const { return is_valid(); } @@ -95,22 +95,22 @@ public: void release() override; - inline uint32_t get_width() const + auto get_width() const -> uint32_t { return m_width; } - inline uint32_t get_height() const + auto get_height() const -> uint32_t { return m_height; } - inline uint32_t get_components() const + auto get_components() const -> uint32_t { return m_components; } - inline uint32_t get_desired_components() const + auto get_desired_components() const -> uint32_t { return m_desired_components; } @@ -128,9 +128,10 @@ private: class FileManager { public: - static BasicFileHandle read_text_file(const std::string &path); + static auto read_text_file(const std::string &path) -> BasicFileHandle; - static ImageFileHandle read_image_file(const std::string &path, int32_t desiredComponents); + static auto read_image_file(const std::string &path, int32_t desiredComponents) + -> ImageFileHandle; }; } // namespace Light diff --git a/modules/engine/include/engine/utils/resource_manager.hpp b/modules/engine/include/engine/utils/resource_manager.hpp index f03d426..61448d0 100644 --- a/modules/engine/include/engine/utils/resource_manager.hpp +++ b/modules/engine/include/engine/utils/resource_manager.hpp @@ -11,9 +11,9 @@ class SharedContext; class ResourceManager { public: - static Scope create(); + static auto create() -> Scope; - static inline void load_shader( + static void load_shader( const std::string &name, const std::string &vertexPath, const std::string &pixelPath @@ -22,7 +22,7 @@ public: s_context->load_shader_impl(name, vertexPath, pixelPath); } - static inline void load_texture( + static void load_texture( const std::string &name, const std::string &path, unsigned int desiredComponents = 4u @@ -31,17 +31,17 @@ public: s_context->load_texture_impl(name, path, desiredComponents); } - static inline void release_texture(const std::string &name) + static void release_texture(const std::string &name) { s_context->release_texture_impl(name); } - static inline Ref get_shader(const std::string &name) + static auto get_shader(const std::string &name) -> Ref { return s_context->m_shaders[name]; } - static inline Ref get_texture(const std::string &name) + static auto get_texture(const std::string &name) -> Ref { return s_context->m_textures[name]; } diff --git a/modules/engine/include/engine/utils/serializer.hpp b/modules/engine/include/engine/utils/serializer.hpp index 583afba..bcd43a0 100644 --- a/modules/engine/include/engine/utils/serializer.hpp +++ b/modules/engine/include/engine/utils/serializer.hpp @@ -12,13 +12,13 @@ class SceneSerializer public: SceneSerializer(const Ref &scene); - void serialize(const std::string &filePath); + void serialize(const std::string &file_path); - bool deserialize(const std::string &filePath); + auto deserialize(const std::string &file_path) -> bool; - void serialize_binary(const std::string &filePath); + void serialize_binary(const std::string &file_path); - bool deserialize_binary(const std::string &filePath); + auto deserialize_binary(const std::string &file_path) -> bool; private: Ref m_scene; diff --git a/modules/engine/include/engine/utils/stringifier.hpp b/modules/engine/include/engine/utils/stringifier.hpp index 13f1dea..750e139 100644 --- a/modules/engine/include/engine/utils/stringifier.hpp +++ b/modules/engine/include/engine/utils/stringifier.hpp @@ -11,15 +11,15 @@ enum class GraphicsAPI; class Stringifier { public: - static std::string glDebugMsgSeverity(unsigned int severity); + static auto glDebugMsgSeverity(unsigned int severity) -> std::string; - static std::string glDebugMsgSource(unsigned int source); + static auto glDebugMsgSource(unsigned int source) -> std::string; - static std::string glDebugMsgType(unsigned int type); + static auto glDebugMsgType(unsigned int type) -> std::string; - static std::string spdlogLevel(unsigned int level); + static auto spdlogLevel(unsigned int level) -> std::string; - static std::string graphics_api_to_string(GraphicsAPI api); + static auto graphics_api_to_string(GraphicsAPI api) -> std::string; }; } // namespace Light diff --git a/modules/engine/src/camera/scene.cpp b/modules/engine/src/camera/scene.cpp index 7cc6a81..c3cd2ed 100644 --- a/modules/engine/src/camera/scene.cpp +++ b/modules/engine/src/camera/scene.cpp @@ -32,31 +32,31 @@ void SceneCamera::set_orthographic_size(float size) void SceneCamera::set_orthographic_far_plane(float farPlane) { - m_orthographic_specification.farPlane = farPlane; + m_orthographic_specification.far_plane = farPlane; calculate_projection(); } void SceneCamera::set_orthographic_near_plane(float nearPlane) { - m_orthographic_specification.nearPlane = nearPlane; + m_orthographic_specification.near_plane = nearPlane; calculate_projection(); } void SceneCamera::set_perspective_vertical_fov(float verticalFOV) { - m_perspective_specification.verticalFOV = verticalFOV; + m_perspective_specification.vertical_fov = verticalFOV; calculate_projection(); } void SceneCamera::set_perspective_far_plane(float farPlane) { - m_perspective_specification.farPlane = farPlane; + m_perspective_specification.far_plane = farPlane; calculate_projection(); } void SceneCamera::set_perspective_near_plane(float nearPlane) { - m_perspective_specification.nearPlane = nearPlane; + m_perspective_specification.near_plane = nearPlane; calculate_projection(); } @@ -69,17 +69,17 @@ void SceneCamera::calculate_projection() m_orthographic_specification.size * 0.5f * m_aspect_ratio, -m_orthographic_specification.size * 0.5f, m_orthographic_specification.size * 0.5f, - m_orthographic_specification.farPlane, - m_orthographic_specification.nearPlane + m_orthographic_specification.far_plane, + m_orthographic_specification.near_plane ); } else // perspective { m_projection = glm::perspective( - m_perspective_specification.verticalFOV, + m_perspective_specification.vertical_fov, m_aspect_ratio, - m_perspective_specification.nearPlane, - m_perspective_specification.farPlane + m_perspective_specification.near_plane, + m_perspective_specification.far_plane ); } } diff --git a/modules/engine/src/core/application.cpp b/modules/engine/src/core/application.cpp index fa58e15..a8052bf 100644 --- a/modules/engine/src/core/application.cpp +++ b/modules/engine/src/core/application.cpp @@ -49,8 +49,8 @@ void Application::game_loop() // log debug data m_logger->log_debug_data(); - m_window->GetGfxContext()->log_debug_data(); - m_window->GetGfxContext()->GetUserInterface()->log_debug_data(); + m_window->get_graphics_context()->log_debug_data(); + m_window->get_graphics_context()->get_user_interface()->log_debug_data(); // reveal window m_window->set_visibility(true); @@ -59,7 +59,7 @@ void Application::game_loop() m_instrumentor->begin_session("Logs/ProfileResults_GameLoop.json"); /* game loop */ - DeltaTimer deltaTimer; + auto delta_timer = DeltaTimer {}; while (!m_window->is_closed()) { { @@ -67,29 +67,29 @@ void Application::game_loop() lt_profile_scope("game_loop::update"); for (auto it = m_layer_stack->begin(); it != m_layer_stack->end(); it++) - (*it)->on_update(deltaTimer.get_delta_time()); + (*it)->on_update(delta_timer.get_delta_time()); } { // render layers lt_profile_scope("game_loop::Render"); - m_window->GetGfxContext()->GetRenderer()->begin_frame(); + m_window->get_graphics_context()->get_renderer()->begin_frame(); for (auto it = m_layer_stack->begin(); it != m_layer_stack->end(); it++) (*it)->on_render(); - m_window->GetGfxContext()->GetRenderer()->end_frame(); + m_window->get_graphics_context()->get_renderer()->end_frame(); } { // render user interface lt_profile_scope("game_loop::UserInterface"); - m_window->GetGfxContext()->GetUserInterface()->begin(); + m_window->get_graphics_context()->get_user_interface()->begin(); for (auto it = m_layer_stack->begin(); it != m_layer_stack->end(); it++) (*it)->on_user_interface_update(); - m_window->GetGfxContext()->GetUserInterface()->end(); + m_window->get_graphics_context()->get_user_interface()->end(); } { @@ -99,7 +99,7 @@ void Application::game_loop() } /// update delta time - deltaTimer.update(); + delta_timer.update(); } m_instrumentor->end_session(); // ProfileResults_GameLoop // @@ -119,7 +119,7 @@ void Application::on_event(const Event &event) m_window->on_event(event); if (event.get_event_type() == EventType::WindowResized) - m_window->GetGfxContext()->GetRenderer()->on_window_resize( + m_window->get_graphics_context()->get_renderer()->on_window_resize( (const WindowResizedEvent &)event ); } diff --git a/modules/engine/src/core/uuid.cpp b/modules/engine/src/core/uuid.cpp index 2f52c10..5236c27 100644 --- a/modules/engine/src/core/uuid.cpp +++ b/modules/engine/src/core/uuid.cpp @@ -2,8 +2,8 @@ namespace Light { -std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()()); -std::uniform_int_distribution UUID::s_distribution; +auto UUID::s_engine = std::mt19937_64(std::random_device()()); +auto UUID::s_distribution = std::uniform_int_distribution {}; UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_distribution(s_engine) : uuid) { diff --git a/modules/engine/src/debug/instrumentor.cpp b/modules/engine/src/debug/instrumentor.cpp index 2034804..eae2baf 100644 --- a/modules/engine/src/debug/instrumentor.cpp +++ b/modules/engine/src/debug/instrumentor.cpp @@ -4,7 +4,7 @@ namespace Light { Instrumentor *Instrumentor::s_context = nullptr; -Scope Instrumentor::create() +auto Instrumentor::create() -> Scope { return make_scope(new Instrumentor); } @@ -69,6 +69,7 @@ InstrumentorTimer::~InstrumentorTimer() m_result.start = std::chrono::time_point_cast(m_start) .time_since_epoch() .count(); + m_result.duration = std::chrono::time_point_cast(end) .time_since_epoch() .count() diff --git a/modules/engine/src/debug/logger.cpp b/modules/engine/src/debug/logger.cpp index 98a9c69..dfb86bd 100644 --- a/modules/engine/src/debug/logger.cpp +++ b/modules/engine/src/debug/logger.cpp @@ -6,7 +6,7 @@ namespace Light { logger *logger::s_context = nullptr; -Scope logger::create() +auto logger::create() -> Scope { return make_scope(new logger()); } diff --git a/modules/engine/src/graphics/blender.cpp b/modules/engine/src/graphics/blender.cpp index a8db815..d8add76 100644 --- a/modules/engine/src/graphics/blender.cpp +++ b/modules/engine/src/graphics/blender.cpp @@ -10,22 +10,23 @@ namespace Light { -Scope Blender::create(Ref sharedContext) +auto Blender::create(Ref sharedContext) -> Scope { switch (GraphicsContext::get_graphics_api()) { case GraphicsAPI::OpenGL: return create_scope(); case GraphicsAPI::DirectX: - lt_win(return create_scope(std::static_pointer_cast(sharedContext - ));) + lt_win(return create_scope( + std::static_pointer_cast(sharedContext) + );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); } } diff --git a/modules/engine/src/graphics/buffers.cpp b/modules/engine/src/graphics/buffers.cpp index 8d42328..a633b4b 100644 --- a/modules/engine/src/graphics/buffers.cpp +++ b/modules/engine/src/graphics/buffers.cpp @@ -11,13 +11,11 @@ namespace Light { -//================================================== CONSTANT_BUFFER -//==================================================// -Scope ConstantBuffer::create( +auto ConstantBuffer::create( ConstantBufferIndex index, unsigned int size, Ref sharedContext -) +) -> Scope { switch (GraphicsContext::get_graphics_api()) { @@ -30,26 +28,22 @@ Scope ConstantBuffer::create( std::static_pointer_cast(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } -//================================================== CONSTANT_BUFFER -//==================================================// -//================================================== VERTEX_BUFFER -//==================================================// -Ref VertexBuffer::create( +auto VertexBuffer::create( float *vertices, unsigned int stride, unsigned int count, Ref sharedContext -) +) -> Ref { switch (GraphicsContext::get_graphics_api()) { @@ -63,24 +57,21 @@ Ref VertexBuffer::create( std::static_pointer_cast(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } -//================================================== VERTEX_BUFFER -//==================================================// -//======================================== INDEX_BUFFER ========================================// -Ref IndexBuffer::create( +auto IndexBuffer::create( unsigned int *indices, unsigned int count, Ref sharedContext -) +) -> Ref { switch (GraphicsContext::get_graphics_api()) { @@ -93,15 +84,14 @@ Ref IndexBuffer::create( std::dynamic_pointer_cast(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } -//======================================== INDEX_BUFFER ========================================// } // namespace Light diff --git a/modules/engine/src/graphics/framebuffer.cpp b/modules/engine/src/graphics/framebuffer.cpp index 83f72d3..11b9fee 100644 --- a/modules/engine/src/graphics/framebuffer.cpp +++ b/modules/engine/src/graphics/framebuffer.cpp @@ -10,10 +10,10 @@ namespace Light { -Ref Framebuffer::create( +auto Framebuffer::create( const FramebufferSpecification &specification, Ref sharedContext -) +) -> Ref { switch (GraphicsContext::get_graphics_api()) { @@ -25,12 +25,12 @@ Ref Framebuffer::create( std::static_pointer_cast(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } diff --git a/modules/engine/src/graphics/graphics_context.cpp b/modules/engine/src/graphics/graphics_context.cpp index 1484bca..98c0560 100644 --- a/modules/engine/src/graphics/graphics_context.cpp +++ b/modules/engine/src/graphics/graphics_context.cpp @@ -21,7 +21,7 @@ GraphicsContext::~GraphicsContext() { } -Scope GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) +auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope { // terminate 'GraphicsContext' dependent classes if (s_context) @@ -45,17 +45,18 @@ Scope GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind } // create gfx context - Scope scopeGfx; + auto scope_gfx = Scope {}; switch (api) { // opengl case GraphicsAPI::OpenGL: - scopeGfx = create_scope(windowHandle); - s_context = scopeGfx.get(); + scope_gfx = create_scope(windowHandle); + s_context = scope_gfx.get(); break; // directx case GraphicsAPI::DirectX: - lt_win(scopeGfx = create_scope(windowHandle); s_context = scopeGfx.get(); + lt_win(scope_gfx = create_scope(windowHandle); + s_context = scope_gfx.get(); break;) default @@ -69,13 +70,13 @@ Scope GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind // create 'GraphicsContext' dependent classes s_context->m_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context); - s_context->m_renderer = renderer::create(windowHandle, s_context->m_shared_context); + s_context->m_renderer = Renderer::create(windowHandle, s_context->m_shared_context); // check lt_assert(s_context->m_user_interface, "Failed to create UserInterface"); lt_assert(s_context->m_renderer, "Failed to create renderer"); - return std::move(scopeGfx); + return std::move(scope_gfx); } } // namespace Light diff --git a/modules/engine/src/graphics/render_command.cpp b/modules/engine/src/graphics/render_command.cpp index a48bdcb..57d8955 100644 --- a/modules/engine/src/graphics/render_command.cpp +++ b/modules/engine/src/graphics/render_command.cpp @@ -10,10 +10,8 @@ namespace Light { -Scope RenderCommand::create( - GLFWwindow *windowHandle, - Ref sharedContext -) +auto RenderCommand::create(GLFWwindow *windowHandle, Ref sharedContext) + -> Scope { switch (GraphicsContext::get_graphics_api()) { @@ -24,12 +22,12 @@ Scope RenderCommand::create( (std::static_pointer_cast)(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } diff --git a/modules/engine/src/graphics/renderer.cpp b/modules/engine/src/graphics/renderer.cpp index c8f3c4d..ddb752c 100644 --- a/modules/engine/src/graphics/renderer.cpp +++ b/modules/engine/src/graphics/renderer.cpp @@ -12,9 +12,9 @@ namespace Light { -renderer *renderer::s_context = nullptr; +Renderer *Renderer::s_context = nullptr; -renderer::renderer(GLFWwindow *windowHandle, Ref sharedContext) +Renderer::Renderer(GLFWwindow *windowHandle, Ref sharedContext) : m_quad_renderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext) , m_texture_renderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext) , m_tinted_texture_renderer(LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES, sharedContext) @@ -39,19 +39,19 @@ renderer::renderer(GLFWwindow *windowHandle, Ref sharedContext) m_blender->enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA); } -Scope renderer::create(GLFWwindow *windowHandle, Ref sharedContext) +auto Renderer::create(GLFWwindow *windowHandle, Ref sharedContext) -> Scope { - return make_scope(new renderer(windowHandle, sharedContext)); + return make_scope(new Renderer(windowHandle, sharedContext)); } -void renderer::on_window_resize(const WindowResizedEvent &event) +void Renderer::on_window_resize(const WindowResizedEvent &event) { m_render_command->set_viewport(0u, 0u, event.get_size().x, event.get_size().y); } //======================================== DRAW_QUAD ========================================// /* tinted textures */ -void renderer::draw_quad_impl( +void Renderer::draw_quad_impl( const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint, @@ -67,7 +67,7 @@ void renderer::draw_quad_impl( } /* tint */ -void renderer::draw_quad_impl( +void Renderer::draw_quad_impl( const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint @@ -81,7 +81,7 @@ void renderer::draw_quad_impl( } /* texture */ -void renderer::draw_quad_impl( +void Renderer::draw_quad_impl( const glm::vec3 &position, const glm::vec2 &size, Ref texture @@ -96,10 +96,10 @@ void renderer::draw_quad_impl( //======================================== DRAW_QUAD ========================================// //==================== DRAW_QUAD_TINT ====================// -void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) +void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) { // locals - QuadRendererProgram::QuadVertexData *bufferMap = m_quad_renderer.GetMapCurrent(); + QuadRendererProgram::QuadVertexData *bufferMap = m_quad_renderer.get_map_current(); // top left bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); @@ -127,14 +127,14 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) //==================== DRAW_QUAD_TINT ====================// //==================== DRAW_QUAD_TEXTURE ====================// -void renderer::draw_quad_impl(const glm::mat4 &transform, Ref texture) +void Renderer::draw_quad_impl(const glm::mat4 &transform, 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.GetMapCurrent(); + TextureRendererProgram::TextureVertexData *bufferMap = m_texture_renderer.get_map_current(); // top left bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); @@ -164,7 +164,7 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, Ref texture) } } -void renderer::draw_quad_impl( +void Renderer::draw_quad_impl( const glm::mat4 &transform, const glm::vec4 &tint, Ref texture @@ -176,7 +176,7 @@ void renderer::draw_quad_impl( // locals TintedTextureRendererProgram::TintedTextureVertexData *bufferMap = m_tinted_texture_renderer - .GetMapCurrent(); + .get_map_current(); // top left bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); @@ -212,22 +212,22 @@ void renderer::draw_quad_impl( //==================== DRAW_QUAD_TEXTURE ====================// -void renderer::begin_frame() +void Renderer::begin_frame() { } -void renderer::end_frame() +void Renderer::end_frame() { m_render_command->swap_buffers(); m_render_command->clear_back_buffer( - m_default_framebuffer_camera ? m_default_framebuffer_camera->GetBackgroundColor() : + m_default_framebuffer_camera ? m_default_framebuffer_camera->get_background_color() : glm::vec4(0.0f) ); m_default_framebuffer_camera = nullptr; } -void renderer::begin_scene_impl( +void Renderer::begin_scene_impl( Camera *camera, const glm::mat4 &cameraTransform, const Ref &targetFrameBuffer /* = nullptr */ @@ -237,7 +237,7 @@ void renderer::begin_scene_impl( m_target_framebuffer = targetFrameBuffer; if (targetFrameBuffer) - targetFrameBuffer->bind_as_target(camera->GetBackgroundColor()); + targetFrameBuffer->bind_as_target(camera->get_background_color()); else { m_default_framebuffer_camera = camera; @@ -246,7 +246,7 @@ void renderer::begin_scene_impl( // update view projection buffer glm::mat4 *map = (glm::mat4 *)m_view_projection_buffer->map(); - map[0] = camera->GetProjection() * glm::inverse(cameraTransform); + map[0] = camera->get_projection() * glm::inverse(cameraTransform); m_view_projection_buffer->un_map(); // map renderers @@ -255,7 +255,7 @@ void renderer::begin_scene_impl( m_tinted_texture_renderer.map(); } -void renderer::flush_scene() +void Renderer::flush_scene() { /* tinted texture renderer */ m_tinted_texture_renderer.un_map(); @@ -286,7 +286,7 @@ void renderer::flush_scene() m_tinted_texture_renderer.map(); } -void renderer::end_scene_impl() +void Renderer::end_scene_impl() { /* tinted texture renderer */ m_tinted_texture_renderer.un_map(); diff --git a/modules/engine/src/graphics/renderer_programs/quad.cpp b/modules/engine/src/graphics/renderer_programs/quad.cpp index 532f94b..1952cdb 100644 --- a/modules/engine/src/graphics/renderer_programs/quad.cpp +++ b/modules/engine/src/graphics/renderer_programs/quad.cpp @@ -38,7 +38,7 @@ QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref bool { m_map_current += 4; diff --git a/modules/engine/src/graphics/renderer_programs/texture.cpp b/modules/engine/src/graphics/renderer_programs/texture.cpp index bd0cda4..0f170a1 100644 --- a/modules/engine/src/graphics/renderer_programs/texture.cpp +++ b/modules/engine/src/graphics/renderer_programs/texture.cpp @@ -41,7 +41,7 @@ TextureRendererProgram::TextureRendererProgram( )); } -bool TextureRendererProgram::advance() +auto TextureRendererProgram::advance() -> bool { if (m_map_current + 4 >= m_map_end) { diff --git a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp b/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp index 2b0f018..4ea6eee 100644 --- a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp +++ b/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp @@ -43,7 +43,7 @@ TintedTextureRendererProgram::TintedTextureRendererProgram( )); } -bool TintedTextureRendererProgram::advance() +auto TintedTextureRendererProgram::advance() -> bool { m_map_current += 4; diff --git a/modules/engine/src/graphics/shader.cpp b/modules/engine/src/graphics/shader.cpp index e437a54..d5e8797 100644 --- a/modules/engine/src/graphics/shader.cpp +++ b/modules/engine/src/graphics/shader.cpp @@ -10,11 +10,11 @@ namespace Light { -Ref Shader::create( +auto Shader::create( BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref sharedContext -) +) -> Ref { // load shader source switch (GraphicsContext::get_graphics_api()) @@ -28,12 +28,12 @@ Ref Shader::create( std::static_pointer_cast(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } diff --git a/modules/engine/src/graphics/texture.cpp b/modules/engine/src/graphics/texture.cpp index 6e93e7b..05ea1ca 100644 --- a/modules/engine/src/graphics/texture.cpp +++ b/modules/engine/src/graphics/texture.cpp @@ -10,14 +10,14 @@ namespace Light { -Ref Texture::create( +auto Texture::create( unsigned int width, unsigned int height, unsigned int components, unsigned char *pixels, Ref sharedContext, const std::string &filePath -) +) -> Ref { switch (GraphicsContext::get_graphics_api()) { @@ -34,12 +34,12 @@ Ref Texture::create( filePath );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } diff --git a/modules/engine/src/graphics/vertex_layout.cpp b/modules/engine/src/graphics/vertex_layout.cpp index 7e7a7de..b283025 100644 --- a/modules/engine/src/graphics/vertex_layout.cpp +++ b/modules/engine/src/graphics/vertex_layout.cpp @@ -10,12 +10,12 @@ namespace Light { -Ref VertexLayout::create( +auto VertexLayout::create( Ref vertexBuffer, Ref shader, const std::vector> &elements, Ref sharedContext -) +) -> Ref { switch (GraphicsContext::get_graphics_api()) { @@ -28,12 +28,12 @@ Ref VertexLayout::create( std::static_pointer_cast(sharedContext) );) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - static_cast(GraphicsContext::get_graphics_api()) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + static_cast(GraphicsContext::get_graphics_api()) + ); return nullptr; } } diff --git a/modules/engine/src/input/input.cpp b/modules/engine/src/input/input.cpp index 8b936d9..ad8857b 100644 --- a/modules/engine/src/input/input.cpp +++ b/modules/engine/src/input/input.cpp @@ -10,7 +10,7 @@ namespace Light { Input *Input::s_context = nullptr; -Scope Input::create() +auto Input::create() -> Scope { return make_scope(new Input); } @@ -40,7 +40,7 @@ void Input::receive_user_interface_events_impl(bool receive, bool toggle /* = fa void Input::receieve_game_events_impl(bool receive, bool toggle /*= false*/) { - bool prev = m_game_events; + auto prev = m_game_events; m_game_events = toggle ? !m_user_interface_events : receive; if (m_game_events != prev) @@ -59,18 +59,18 @@ void Input::restart_input_state() void Input::on_event(const Event &inputEvent) { - ImGuiIO &io = ImGui::GetIO(); + auto &io = ImGui::GetIO(); switch (inputEvent.get_event_type()) { //** MOUSE_EVENTS **// case EventType::MouseMoved: { - const MouseMovedEvent &event = (const MouseMovedEvent &)inputEvent; + const auto &event = dynamic_cast(inputEvent); if (m_game_events) { - m_mouse_delta = event.GetPosition() - m_mouse_position; - m_mouse_position = event.GetPosition(); + m_mouse_delta = event.get_position() - m_mouse_position; + m_mouse_position = event.get_position(); } if (m_user_interface_events) @@ -80,7 +80,7 @@ void Input::on_event(const Event &inputEvent) } case EventType::ButtonPressed: { - const ButtonPressedEvent &event = (const ButtonPressedEvent &)inputEvent; + const auto &event = (const ButtonPressedEvent &)inputEvent; if (m_game_events) m_mouse_buttons[event.get_button()] = true; @@ -92,7 +92,7 @@ void Input::on_event(const Event &inputEvent) } case EventType::ButtonReleased: { - const ButtonReleasedEvent &event = (const ButtonReleasedEvent &)inputEvent; + const auto &event = (const ButtonReleasedEvent &)inputEvent; if (m_game_events) m_mouse_buttons[event.get_button()] = false; @@ -104,7 +104,7 @@ void Input::on_event(const Event &inputEvent) } case EventType::WheelScrolled: { - const WheelScrolledEvent &event = (const WheelScrolledEvent &)inputEvent; + const auto &event = (const WheelScrolledEvent &)inputEvent; if (m_game_events) m_mouse_wheel_delta = event.get_offset(); @@ -117,7 +117,7 @@ void Input::on_event(const Event &inputEvent) //** KEYBOARD_EVENTS **// case EventType::KeyPressed: { - const KeyPressedEvent &event = (const KeyPressedEvent &)inputEvent; + const auto &event = (const KeyPressedEvent &)inputEvent; if (m_game_events) m_keyboad_keys[event.get_key()] = true; @@ -133,7 +133,7 @@ void Input::on_event(const Event &inputEvent) } case EventType::KeyReleased: { - const KeyReleasedEvent &event = (const KeyReleasedEvent &)inputEvent; + const auto &event = (const KeyReleasedEvent &)inputEvent; if (m_game_events) m_keyboad_keys[event.get_key()] = false; @@ -147,7 +147,7 @@ void Input::on_event(const Event &inputEvent) { if (m_user_interface_events) { - const SetCharEvent &event = (const SetCharEvent &)inputEvent; + const auto &event = (const SetCharEvent &)inputEvent; io.AddInputCharacter(event.get_character()); } diff --git a/modules/engine/src/layer/layer.cpp b/modules/engine/src/layer/layer.cpp index db9a43f..96471df 100644 --- a/modules/engine/src/layer/layer.cpp +++ b/modules/engine/src/layer/layer.cpp @@ -11,34 +11,23 @@ Layer::Layer(const std::string &name): m_layer_name(name) { } -bool Layer::on_event(const Event &event) +auto Layer::on_event(const Event &event) -> bool { switch (event.get_event_type()) { - /* mouse */ - // cursor case EventType::MouseMoved: return on_mouse_moved((MouseMovedEvent &)event); - // button case EventType::ButtonPressed: return on_button_pressed((ButtonPressedEvent &)event); case EventType::ButtonReleased: return on_button_released((ButtonReleasedEvent &)event); - // wheel case EventType::WheelScrolled: return on_wheel_scrolled((WheelScrolledEvent &)event); - /* keyboard */ - // key 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); - // char case EventType::SetChar: return on_set_char((SetCharEvent &)event); - /* window */ - // termination case EventType::WindowClosed: return on_window_closed((WindowClosedEvent &)event); - // size/position case EventType::WindowResized: return on_window_resized((WindowResizedEvent &)event); case EventType::WindowMoved: return on_window_moved((WindowMovedEvent &)event); - // focus case EventType::WindowLostFocus: return on_window_lost_focus((WindowLostFocusEvent &)event); case EventType::WindowGainFocus: return on_window_gain_focus((WindowGainFocusEvent &)event); } diff --git a/modules/engine/src/layer/layer_stack.cpp b/modules/engine/src/layer/layer_stack.cpp index f9dd28e..9d85b47 100644 --- a/modules/engine/src/layer/layer_stack.cpp +++ b/modules/engine/src/layer/layer_stack.cpp @@ -9,7 +9,7 @@ namespace Light { LayerStack *LayerStack::s_context = nullptr; -Scope LayerStack::create() +auto LayerStack::create() -> Scope { return make_scope(new LayerStack()); } @@ -25,7 +25,7 @@ LayerStack::LayerStack(): m_layers {}, m_begin(), m_end() LayerStack::~LayerStack() { - for (Layer *layer : m_layers) + for (auto *layer : m_layers) delete layer; } @@ -36,7 +36,7 @@ void LayerStack::attach_layer_impl(Layer *layer) m_begin = m_layers.begin(); m_end = m_layers.end(); - lt_log(trace, "Attached [{}]", layer->GetName()); + lt_log(trace, "Attached [{}]", layer->get_name()); } void LayerStack::detach_layer_impl(Layer *layer) @@ -46,7 +46,7 @@ void LayerStack::detach_layer_impl(Layer *layer) m_begin = m_layers.begin(); m_end = m_layers.end(); - lt_log(trace, "Detached [{}]", layer->GetName()); + lt_log(trace, "Detached [{}]", layer->get_name()); } } // namespace Light diff --git a/modules/engine/src/math/random.cpp b/modules/engine/src/math/random.cpp index 7abff6f..fc14fed 100644 --- a/modules/engine/src/math/random.cpp +++ b/modules/engine/src/math/random.cpp @@ -4,38 +4,38 @@ namespace Light { namespace Math { -float rand(int min, int max, int decimals /* = 0 */) +auto rand(int min, int max, int decimals /* = 0 */) -> float { - const int dec = std::pow(10, decimals); + const auto dec = static_cast(std::pow(10, decimals)); min *= dec; max *= dec; return (min + (::rand() % (max)-min)) / (float)dec; } -glm::vec2 rand_vec2(int min, int max, int decimals /* = 0 */) +auto rand_vec2(int min, int max, int decimals /* = 0 */) -> glm::vec2 { - const int dec = std::pow(10, decimals); + const auto dec = static_cast(std::pow(10, decimals)); min *= dec; max *= dec; - float r1 = (min + (::rand() % (max)-min)) / (float)dec; - float r2 = (min + (::rand() % (max)-min)) / (float)dec; + auto r1 = (min + (::rand() % (max)-min)) / (float)dec; + auto r2 = (min + (::rand() % (max)-min)) / (float)dec; - return glm::vec2(r1, r2); + return { r1, r2 }; } -glm::vec3 rand_vec3(int min, int max, int decimals /* = 0 */) +auto rand_vec3(int min, int max, int decimals /* = 0 */) -> glm::vec3 { - const int dec = std::pow(10, decimals); + const auto dec = static_cast(std::pow(10, decimals)); min *= dec; max *= dec; - float r1 = (min + (::rand() % (max - min))) / (float)dec; - float r2 = (min + (::rand() % (max - min))) / (float)dec; - float r3 = (min + (::rand() % (max - min))) / (float)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 glm::vec3(r1, r2, r3); + return { r1, r2, r3 }; } } // namespace Math } // namespace Light diff --git a/modules/engine/src/platform/graphics/directx/blender.cpp b/modules/engine/src/platform/graphics/directx/blender.cpp index c01a6b7..7e8e53d 100644 --- a/modules/engine/src/platform/graphics/directx/blender.cpp +++ b/modules/engine/src/platform/graphics/directx/blender.cpp @@ -46,7 +46,7 @@ dxBlender::dxBlender(Ref sharedContext) m_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; // create blend state - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateBlendState(&m_desc, &m_blend_state)); } @@ -58,7 +58,7 @@ void dxBlender::enable(BlendFactor srcFactor, BlendFactor dstFactor) m_desc.RenderTarget[0].DestBlend = m_factor_map.at(dstFactor); // re-create blind state - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateBlendState(&m_desc, &m_blend_state)); // bind blend state @@ -71,7 +71,7 @@ void dxBlender::disable() m_desc.RenderTarget[0].BlendEnable = false; // re-create blind state - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateBlendState(&m_desc, &m_blend_state)); // bind blend state diff --git a/modules/engine/src/platform/graphics/directx/buffers.cpp b/modules/engine/src/platform/graphics/directx/buffers.cpp index 22a57b2..f216b35 100644 --- a/modules/engine/src/platform/graphics/directx/buffers.cpp +++ b/modules/engine/src/platform/graphics/directx/buffers.cpp @@ -15,14 +15,14 @@ dxConstantBuffer::dxConstantBuffer( , m_map {} , m_index(static_cast(index)) { - D3D11_BUFFER_DESC bDesc = {}; + auto bDesc = D3D11_BUFFER_DESC {}; bDesc.ByteWidth = size; bDesc.Usage = D3D11_USAGE_DYNAMIC; bDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateBuffer(&bDesc, nullptr, &m_buffer)); m_context->get_device_context()->VSSetConstantBuffers(m_index, 1u, m_buffer.GetAddressOf()); } @@ -32,10 +32,11 @@ void dxConstantBuffer::bind() m_context->get_device_context()->VSSetConstantBuffers(m_index, 1u, m_buffer.GetAddressOf()); } -void *dxConstantBuffer::map() +auto dxConstantBuffer::map() -> void * { m_context->get_device_context()->VSSetConstantBuffers(m_index, 1u, m_buffer.GetAddressOf()); - m_context->get_device_context()->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map); + m_context->get_device_context() + ->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map); return m_map.pData; } @@ -43,11 +44,7 @@ void dxConstantBuffer::un_map() { m_context->get_device_context()->Unmap(m_buffer.Get(), NULL); } -//======================================== CONSTANT_BUFFER -//========================================// -//================================================== VERTEX_BUFFER -//==================================================// dxVertexBuffer::dxVertexBuffer( float *vertices, unsigned int stride, @@ -60,7 +57,7 @@ dxVertexBuffer::dxVertexBuffer( , m_stride(stride) { // buffer desc - D3D11_BUFFER_DESC bDesc = {}; + auto bDesc = D3D11_BUFFER_DESC {}; bDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bDesc.Usage = D3D11_USAGE_DYNAMIC; @@ -70,7 +67,7 @@ dxVertexBuffer::dxVertexBuffer( bDesc.StructureByteStride = stride; // create buffer - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateBuffer(&bDesc, nullptr, &m_buffer)); } @@ -79,9 +76,10 @@ dxVertexBuffer::~dxVertexBuffer() un_bind(); } -void *dxVertexBuffer::map() +auto dxVertexBuffer::map() -> void * { - m_context->get_device_context()->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map); + m_context->get_device_context() + ->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map); return m_map.pData; } @@ -92,22 +90,19 @@ void dxVertexBuffer::un_map() void dxVertexBuffer::bind() { - static const unsigned int offset = 0u; + static const auto offset = unsigned int { 0u }; m_context->get_device_context() ->IASetVertexBuffers(0u, 1u, m_buffer.GetAddressOf(), &m_stride, &offset); } void dxVertexBuffer::un_bind() { - static const unsigned int offset = 0u; - static ID3D11Buffer *buffer = nullptr; + static const auto offset = unsigned int { 0u }; + static auto *buffer = (ID3D11Buffer *)(nullptr); m_context->get_device_context()->IASetVertexBuffers(0u, 1u, &buffer, &m_stride, &offset); } -//================================================== VERTEX_BUFFER -//==================================================// -//======================================== INDEX_BUFFER ========================================// dxIndexBuffer::dxIndexBuffer( unsigned int *indices, unsigned int count, @@ -117,20 +112,25 @@ dxIndexBuffer::dxIndexBuffer( , m_buffer(nullptr) { // generate indices if not provided - bool hasIndices = !!indices; + auto hasIndices = !!indices; if (!hasIndices) { // check if (count % 6 != 0) { lt_log(warn, "'indices' can only be null if count is multiple of 6"); - lt_log(warn, "Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6))); + lt_log( + warn, + "Adding {} to 'count' -> {}", + (6 - (count % 6)), + count + (6 - (count % 6)) + ); count = count + (6 - (count % 6)); } // create indices indices = new unsigned int[count]; - unsigned int offset = 0; + auto offset = 0; for (unsigned int i = 0; i < count; i += 6) { indices[i + 0] = offset + 0u; @@ -146,7 +146,7 @@ dxIndexBuffer::dxIndexBuffer( } // buffer desc - D3D11_BUFFER_DESC bDesc = {}; + auto bDesc = D3D11_BUFFER_DESC {}; bDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; bDesc.Usage = D3D11_USAGE_DEFAULT; @@ -154,11 +154,11 @@ dxIndexBuffer::dxIndexBuffer( bDesc.StructureByteStride = sizeof(unsigned int); // subresource data - D3D11_SUBRESOURCE_DATA sDesc = {}; + auto sDesc = D3D11_SUBRESOURCE_DATA {}; sDesc.pSysMem = indices; // create buffer - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateBuffer(&bDesc, &sDesc, &m_buffer)); // delete indices @@ -178,8 +178,8 @@ void dxIndexBuffer::bind() void dxIndexBuffer::un_bind() { - static const unsigned int offset = 0u; - static ID3D11Buffer *buffer = nullptr; + static const auto offset = (unsigned int) { 0u }; + static auto *buffer = (ID3D11Buffer *)(nullptr); m_context->get_device_context()->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, offset); } diff --git a/modules/engine/src/platform/graphics/directx/framebuffers.cpp b/modules/engine/src/platform/graphics/directx/framebuffers.cpp index 25b5a90..9f48e86 100644 --- a/modules/engine/src/platform/graphics/directx/framebuffers.cpp +++ b/modules/engine/src/platform/graphics/directx/framebuffers.cpp @@ -15,9 +15,9 @@ dxFramebuffer::dxFramebuffer( , m_shader_resource_view(nullptr) , m_depth_stencil_view(nullptr) { - HRESULT hr; + auto hr = HRESULT {}; - D3D11_TEXTURE2D_DESC t2dDesc = {}; + auto t2dDesc = D3D11_TEXTURE2D_DESC {}; t2dDesc.Width = specification.width; t2dDesc.Height = specification.height; t2dDesc.MipLevels = 1; @@ -31,15 +31,16 @@ dxFramebuffer::dxFramebuffer( t2dDesc.MiscFlags = NULL; dxc(m_context->get_device()->CreateTexture2D(&t2dDesc, nullptr, &m_color_attachment)); - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {}; srvDesc.Format = t2dDesc.Format; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MostDetailedMip = 0; dxc(m_context->get_device() - ->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view)); + ->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view) + ); - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {}; + auto rtvDesc = D3D11_RENDER_TARGET_VIEW_DESC {}; rtvDesc.Format = t2dDesc.Format; rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rtvDesc.Texture2D.MipSlice = 0u; @@ -60,7 +61,7 @@ void dxFramebuffer::bind_as_target(const glm::vec4 &clearColor) ->OMSetRenderTargets(1u, m_render_target_view.GetAddressOf(), nullptr); m_context->get_device_context()->ClearRenderTargetView(m_render_target_view.Get(), color); - D3D11_VIEWPORT viewport; + auto viewport = D3D11_VIEWPORT {}; viewport.TopLeftX = 0; viewport.TopLeftY = 0; @@ -85,9 +86,9 @@ void dxFramebuffer::resize(const glm::uvec2 &size) m_specification.width = std::clamp(size.x, 1u, 16384u); m_specification.height = std::clamp(size.y, 1u, 16384u); - D3D11_TEXTURE2D_DESC textureDesc; - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + auto textureDesc = D3D11_TEXTURE2D_DESC {}; + auto rtvDesc = D3D11_RENDER_TARGET_VIEW_DESC {}; + auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {}; m_color_attachment->GetDesc(&textureDesc); m_render_target_view->GetDesc(&rtvDesc); @@ -96,12 +97,13 @@ void dxFramebuffer::resize(const glm::uvec2 &size) textureDesc.Width = m_specification.width; textureDesc.Height = m_specification.height; - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateTexture2D(&textureDesc, nullptr, &m_color_attachment)); dxc(m_context->get_device() ->CreateRenderTargetView(m_color_attachment.Get(), &rtvDesc, &m_render_target_view)); dxc(m_context->get_device() - ->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view)); + ->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view) + ); } } // namespace Light diff --git a/modules/engine/src/platform/graphics/directx/graphics_context.cpp b/modules/engine/src/platform/graphics/directx/graphics_context.cpp index b10205e..188419f 100644 --- a/modules/engine/src/platform/graphics/directx/graphics_context.cpp +++ b/modules/engine/src/platform/graphics/directx/graphics_context.cpp @@ -31,10 +31,10 @@ dxGraphicsContext::dxGraphicsContext(GLFWwindow *windowHandle) void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle) { - Ref context = std::static_pointer_cast(m_shared_context); + auto context = std::static_pointer_cast(m_shared_context); // swap chain desc - DXGI_SWAP_CHAIN_DESC sd = { 0 }; + auto sd = DXGI_SWAP_CHAIN_DESC { 0 }; // buffer desc sd.BufferDesc.Width = 1u; @@ -62,7 +62,7 @@ void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle) sd.Flags = NULL; // determine device flags - UINT flags = NULL; + auto flags = UINT { NULL }; #ifdef LIGHT_DEBUG flags = D3D11_CREATE_DEVICE_DEBUG; #endif @@ -86,13 +86,13 @@ void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle) void dxGraphicsContext::setup_render_targets() { - Ref context = std::static_pointer_cast(m_shared_context); + auto context = std::static_pointer_cast(m_shared_context); // set primitive topology context->get_device_context()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // create render target view - Microsoft::WRL::ComPtr backBuffer; + auto backBuffer = Microsoft::WRL::ComPtr {}; dxc(context->get_swap_chain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer)); dxc(context->get_device() @@ -134,22 +134,22 @@ void dxGraphicsContext::setup_debug_interface() void dxGraphicsContext::log_debug_data() { - Ref context = std::static_pointer_cast(m_shared_context); + auto context = std::static_pointer_cast(m_shared_context); // locals - IDXGIDevice *DXGIDevice; - IDXGIAdapter *DXGIAdapter; - DXGI_ADAPTER_DESC DXGIAdapterDesc; + auto *DXGIDevice = (IDXGIDevice *) {}; + auto *DXGIAdapter = (IDXGIAdapter *) {}; + auto *DXGIAdapterDesc = (DXGI_ADAPTER_DESC *) {}; context->get_device()->QueryInterface(__uuidof(IDXGIDevice), (void **)&DXGIDevice); DXGIDevice->GetAdapter(&DXGIAdapter); DXGIAdapter->GetDesc(&DXGIAdapterDesc); // get the adapter's description - char DefChar = ' '; + auto DefChar = ' '; char ch[180]; WideCharToMultiByte(CP_ACP, 0, DXGIAdapterDesc.Description, -1, ch, 180, &DefChar, NULL); - std::string adapterDesc(ch); + auto adapterDesc = std::string { ch }; // release memory DXGIDevice->release(); diff --git a/modules/engine/src/platform/graphics/directx/render_command.cpp b/modules/engine/src/platform/graphics/directx/render_command.cpp index 3c36f2b..2ffa545 100644 --- a/modules/engine/src/platform/graphics/directx/render_command.cpp +++ b/modules/engine/src/platform/graphics/directx/render_command.cpp @@ -60,7 +60,7 @@ void dxRenderCommand::set_viewport( set_resolution(width, height); // create viewport - D3D11_VIEWPORT viewport; + auto viewport = D3D11_VIEWPORT {}; viewport.TopLeftX = x; viewport.TopLeftY = y; @@ -77,10 +77,10 @@ void dxRenderCommand::set_viewport( void dxRenderCommand::set_resolution(unsigned int width, unsigned int height) { - HRESULT hr; + auto hr = HRESULT {}; // remove render target - ID3D11RenderTargetView *nullViews[] = { nullptr }; + auto *nullViews[] = (ID3D11RenderTargetView *) { nullptr }; m_context->get_device_context()->OMSetRenderTargets(1u, nullViews, nullptr); m_context->GetRenderTargetViewRef().reset(); @@ -89,7 +89,7 @@ void dxRenderCommand::set_resolution(unsigned int width, unsigned int height) ->ResizeBuffers(0u, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, NULL)); // create render target - Microsoft::WRL::ComPtr backBuffer = nullptr; + auto backBuffer = Microsoft::WRL::ComPtr { nullptr }; dxc(m_context->get_swap_chain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer)); dxc(m_context->get_device()->CreateRenderTargetView( backBuffer.Get(), diff --git a/modules/engine/src/platform/graphics/directx/shader.cpp b/modules/engine/src/platform/graphics/directx/shader.cpp index 1da40f3..8dc458a 100644 --- a/modules/engine/src/platform/graphics/directx/shader.cpp +++ b/modules/engine/src/platform/graphics/directx/shader.cpp @@ -5,8 +5,8 @@ namespace Light { dxShader::dxShader( - basic_file_handle vertexFile, - basic_file_handle pixelFile, + BasicFileHandle vertexFile, + BasicFileHandle pixelFile, Ref sharedContext ) : m_context(sharedContext) @@ -14,7 +14,9 @@ dxShader::dxShader( , m_pixel_shader(nullptr) , m_vertex_blob(nullptr) { - Microsoft::WRL::ComPtr ps = nullptr, vsErr = nullptr, psErr = nullptr; + auto ps = Microsoft::WRL::ComPtr { nullptr }; + auto vsErr = Microsoft::WRL::ComPtr { nullptr }; + auto psErr = Microsoft::WRL::ComPtr { nullptr }; // compile shaders (we don't use dxc here because if d3_d_compile fails it throws a dxException // without logging the vsErr/psErr @@ -50,7 +52,7 @@ dxShader::dxShader( lt_assert(!psErr.Get(), "Pixels shader compile error: {}", (char *)psErr->GetBufferPointer()); // create shaders - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateVertexShader( m_vertex_blob->GetBufferPointer(), m_vertex_blob->GetBufferSize(), @@ -58,7 +60,8 @@ dxShader::dxShader( &m_vertex_shader )); dxc(m_context->get_device() - ->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_pixel_shader)); + ->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_pixel_shader) + ); } dxShader::~dxShader() diff --git a/modules/engine/src/platform/graphics/directx/texture.cpp b/modules/engine/src/platform/graphics/directx/texture.cpp index 5ce2e97..026febf 100644 --- a/modules/engine/src/platform/graphics/directx/texture.cpp +++ b/modules/engine/src/platform/graphics/directx/texture.cpp @@ -18,7 +18,7 @@ dxTexture::dxTexture( , m_sampler_state(nullptr) { // texture2d desc - D3D11_TEXTURE2D_DESC t2dDesc = {}; + auto t2dDesc = D3D11_TEXTURE2D_DESC {}; t2dDesc.Width = width; t2dDesc.Height = height; t2dDesc.MipLevels = 0u; @@ -37,7 +37,7 @@ dxTexture::dxTexture( t2dDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; // create texture - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateTexture2D(&t2dDesc, nullptr, &m_texture_2d)); m_context->get_device_context() ->UpdateSubresource(m_texture_2d.Get(), 0u, nullptr, pixels, width * 4u, 0u); @@ -45,7 +45,7 @@ dxTexture::dxTexture( m_texture_2d->GetDesc(&t2dDesc); // shader resource view desc - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {}; srvDesc.Format = t2dDesc.Format; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MostDetailedMip = 0u; @@ -57,7 +57,7 @@ dxTexture::dxTexture( m_context->get_device_context()->GenerateMips(m_shader_resource_view.Get()); // sampler desc - D3D11_SAMPLER_DESC sDesc = {}; + auto sDesc = D3D11_SAMPLER_DESC {}; sDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; diff --git a/modules/engine/src/platform/graphics/directx/user_interface.cpp b/modules/engine/src/platform/graphics/directx/user_interface.cpp index a02a6c7..bd030e8 100644 --- a/modules/engine/src/platform/graphics/directx/user_interface.cpp +++ b/modules/engine/src/platform/graphics/directx/user_interface.cpp @@ -16,8 +16,8 @@ void dxUserInterface::platform_implementation( Ref sharedContext ) { - ImGuiIO &io = ImGui::GetIO(); - Ref context = std::dynamic_pointer_cast(sharedContext); + auto &io = ImGui::GetIO(); + auto context = std::dynamic_pointer_cast(sharedContext); ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle)); ImGui_ImplDX11_Init(context->get_device().Get(), context->get_device_context().Get()); @@ -26,7 +26,7 @@ void dxUserInterface::platform_implementation( dxUserInterface::~dxUserInterface() { // #todo: handle this in a better way - ImGuiIO &io = ImGui::GetIO(); + auto &io = ImGui::GetIO(); if (io.IniFilename == "default_gui_layout.ini") io.IniFilename = "user_gui_layout.ini"; diff --git a/modules/engine/src/platform/graphics/directx/vertex_layout.cpp b/modules/engine/src/platform/graphics/directx/vertex_layout.cpp index 1dff7c9..081d6cc 100644 --- a/modules/engine/src/platform/graphics/directx/vertex_layout.cpp +++ b/modules/engine/src/platform/graphics/directx/vertex_layout.cpp @@ -12,8 +12,7 @@ dxVertexLayout::dxVertexLayout( : m_context(sharedContext) , m_input_layout(nullptr) { - // occupy space for input elements - std::vector inputElementsDesc; + auto inputElementsDesc = std::vector {}; inputElementsDesc.reserve(elements.size()); // extract elements desc @@ -28,11 +27,11 @@ dxVertexLayout::dxVertexLayout( 0u }); } - Ref dxpShader = std::dynamic_pointer_cast(shader); + auto dxpShader = std::dynamic_pointer_cast(shader); lt_assert(dxpShader, "Failed to cast 'Shader' to 'dxShader'"); // create input layout (vertex layout) - HRESULT hr; + auto hr = HRESULT {}; dxc(m_context->get_device()->CreateInputLayout( &inputElementsDesc[0], inputElementsDesc.size(), @@ -57,7 +56,7 @@ void dxVertexLayout::un_bind() m_context->get_device_context()->IASetInputLayout(nullptr); } -DXGI_FORMAT dxVertexLayout::get_dxgi_format(VertexElementType type) +auto dxVertexLayout::get_dxgi_format(VertexElementType type) -> DXGI_FORMAT { switch (type) { diff --git a/modules/engine/src/platform/graphics/opengl/buffers.cpp b/modules/engine/src/platform/graphics/opengl/buffers.cpp index a9cfec8..894e739 100644 --- a/modules/engine/src/platform/graphics/opengl/buffers.cpp +++ b/modules/engine/src/platform/graphics/opengl/buffers.cpp @@ -24,9 +24,9 @@ void glConstantBuffer::bind() glBindBufferBase(GL_UNIFORM_BUFFER, m_index, m_buffer_id); } -void *glConstantBuffer::map() +auto glConstantBuffer::map() -> void * { - void *map = glMapNamedBuffer(m_buffer_id, GL_WRITE_ONLY); + auto *map = glMapNamedBuffer(m_buffer_id, GL_WRITE_ONLY); return map; } @@ -59,7 +59,7 @@ void glVertexBuffer::un_bind() glBindBuffer(GL_ARRAY_BUFFER, NULL); } -void *glVertexBuffer::map() +auto glVertexBuffer::map() -> void * { return glMapNamedBuffer(m_buffer_id, GL_WRITE_ONLY); } @@ -74,21 +74,26 @@ void glVertexBuffer::un_map() glIndexBuffer::glIndexBuffer(unsigned int *indices, unsigned int count): m_buffer_id(NULL) { // generate indices if not provided - bool hasIndices = !!indices; + auto hasIndices = !!indices; if (!hasIndices) { // check if (count % 6 != 0) { lt_log(warn, "'indices' can only be null if count is multiple of 6"); - lt_log(warn, "Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6))); + lt_log( + warn, + "Adding {} to 'count' -> {}", + (6 - (count % 6)), + count + (6 - (count % 6)) + ); count = count + (6 - (count % 6)); } // create indices indices = new unsigned int[count]; - unsigned int offset = 0u; - for (unsigned int i = 0u; i < count; i += 6u) + auto offset = 0u; + for (auto i = 0u; i < count; i += 6u) { indices[i + 0] = offset + 0u; indices[i + 1] = offset + 1u; diff --git a/modules/engine/src/platform/graphics/opengl/graphics_context.cpp b/modules/engine/src/platform/graphics/opengl/graphics_context.cpp index 6094996..3ec78b6 100644 --- a/modules/engine/src/platform/graphics/opengl/graphics_context.cpp +++ b/modules/engine/src/platform/graphics/opengl/graphics_context.cpp @@ -42,7 +42,6 @@ void glGraphicsContext::log_debug_data() void glGraphicsContext::set_debug_message_callback() { // determine log level - // #todo: set filters from config.h #if defined(LIGHT_DEBUG) glEnable(GL_DEBUG_OUTPUT); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); @@ -89,22 +88,26 @@ void glGraphicsContext::set_debug_message_callback() case GL_DEBUG_SEVERITY_MEDIUM: case GL_DEBUG_SEVERITY_LOW: - lt_log(warn, + lt_log( + warn, "glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}", Stringifier::glDebugMsgSeverity(severity), Stringifier::glDebugMsgSource(source), Stringifier::glDebugMsgType(type), - id); + id + ); lt_log(warn, " {}", message); return; case GL_DEBUG_SEVERITY_NOTIFICATION: - lt_log(trace, + lt_log( + trace, "Severity: {} :: Source: {} :: Type: {} :: ID: {}", Stringifier::glDebugMsgSeverity(severity), Stringifier::glDebugMsgSource(source), Stringifier::glDebugMsgType(type), - id); + id + ); lt_log(trace, " {}", message); return; } diff --git a/modules/engine/src/platform/graphics/opengl/shader.cpp b/modules/engine/src/platform/graphics/opengl/shader.cpp index b60d65e..7735601 100644 --- a/modules/engine/src/platform/graphics/opengl/shader.cpp +++ b/modules/engine/src/platform/graphics/opengl/shader.cpp @@ -61,18 +61,18 @@ void glShader::un_bind() // // log error // if (result.GetCompilationStatus() != shaderc_compilation_status_success) // { -// lt_log(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? "vertex" : -// "pixel", file.GetPath()); lt_log(err, " {}", result.GetErrorMessage()); +// lt_log(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? +// "vertex" : "pixel", file.GetPath()); lt_log(err, " {}", result.GetErrorMessage()); // } // // return result; // } -unsigned int glShader::compile_shader(std::string source, Shader::Stage stage) +auto glShader::compile_shader(std::string source, Shader::Stage stage) -> unsigned int { // &(address of) needs an lvalue - const char *lvalue_source = source.c_str(); - unsigned int shader = glCreateShader( + const auto *lvalue_source = source.c_str(); + auto shader = glCreateShader( stage == Shader::Stage::VERTEX ? GL_VERTEX_SHADER : stage == Shader::Stage::PIXEL ? GL_FRAGMENT_SHADER : stage == Shader::Stage::GEOMETRY ? GL_GEOMETRY_SHADER : @@ -84,20 +84,22 @@ unsigned int glShader::compile_shader(std::string source, Shader::Stage stage) glCompileShader(shader); // check - int isCompiled = 0; + auto isCompiled = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled); if (isCompiled == GL_FALSE) { - int logLength = 0; + auto logLength = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); - char *errorLog = (char *)alloca(logLength); + auto *errorLog = (char *)alloca(logLength); glGetShaderInfoLog(shader, logLength, &logLength, &errorLog[0]); - lt_log(err, + lt_log( + err, "glShader::glShader: failed to compile {} shader:\n {}", stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel", - errorLog); + errorLog + ); return NULL; } @@ -105,7 +107,7 @@ unsigned int glShader::compile_shader(std::string source, Shader::Stage stage) #ifdef LIGHT_OPENGL_ENABLE_SHADER_INFO_LOG // info log { - int logLength = 0; + auto logLength = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); if (logLength) { diff --git a/modules/engine/src/platform/graphics/opengl/texture.cpp b/modules/engine/src/platform/graphics/opengl/texture.cpp index 108b4a7..b5f23bd 100644 --- a/modules/engine/src/platform/graphics/opengl/texture.cpp +++ b/modules/engine/src/platform/graphics/opengl/texture.cpp @@ -23,17 +23,17 @@ glTexture::glTexture( glTextureParameteri(m_texture_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // determine formats - unsigned int format = components == 4u ? GL_RGBA : - components == 3u ? GL_RGB : - components == 2u ? GL_RG : - components == 1u ? GL_RED : - NULL; + auto format = components == 4u ? GL_RGBA : + components == 3u ? GL_RGB : + components == 2u ? GL_RG : + components == 1u ? GL_RED : + NULL; - unsigned int internalFormat = format == GL_RGBA ? GL_RGBA8 : - format == GL_RGB ? GL_RGB8 : - format == GL_RG ? GL_RG8 : - format == GL_RED ? GL_R8 : - NULL; + auto internalFormat = format == GL_RGBA ? GL_RGBA8 : + format == GL_RGB ? GL_RGB8 : + format == GL_RG ? GL_RG8 : + format == GL_RED ? GL_R8 : + NULL; // check lt_assert(format, "Invalid number of components: {}", components); @@ -67,7 +67,7 @@ void glTexture::bind(unsigned int slot /* = 0u */) glBindTexture(GL_TEXTURE_2D, m_texture_id); } -void *glTexture::get_texture() +auto glTexture::get_texture() -> void * { return (void *)(intptr_t)m_texture_id; } diff --git a/modules/engine/src/platform/graphics/opengl/user_interface.cpp b/modules/engine/src/platform/graphics/opengl/user_interface.cpp index 538c573..243baaa 100644 --- a/modules/engine/src/platform/graphics/opengl/user_interface.cpp +++ b/modules/engine/src/platform/graphics/opengl/user_interface.cpp @@ -21,7 +21,7 @@ void glUserInterface::platform_implementation( glUserInterface::~glUserInterface() { // #todo: handle this in a better way - ImGuiIO &io = ImGui::GetIO(); + auto &io = ImGui::GetIO(); if (io.IniFilename == "default_gui_layout.ini") io.IniFilename = "user_gui_layout.ini"; diff --git a/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp b/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp index c09eb5b..03e5986 100644 --- a/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp +++ b/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp @@ -18,9 +18,9 @@ glVertexLayout::glVertexLayout( lt_assert(!elements.empty(), "'elements' is empty"); // local - std::vector elementsDesc; + auto elementsDesc = std::vector {}; elementsDesc.reserve(elements.size()); - unsigned int stride = 0u; + auto stride = 0u; // extract elements desc for (const auto &element : elements) @@ -37,7 +37,7 @@ glVertexLayout::glVertexLayout( bind(); // enable vertex attributes - unsigned int index = 0u; + auto index = 0u; for (const auto &elementDesc : elementsDesc) { glVertexAttribPointer( @@ -67,7 +67,8 @@ void glVertexLayout::un_bind() glBindVertexArray(NULL); } -glVertexElementDesc glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset) +auto glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset) + -> glVertexElementDesc { switch (type) { diff --git a/modules/engine/src/platform/os/linux/l_window.cpp b/modules/engine/src/platform/os/linux/l_window.cpp index 9cfaa76..4a17ff9 100644 --- a/modules/engine/src/platform/os/linux/l_window.cpp +++ b/modules/engine/src/platform/os/linux/l_window.cpp @@ -9,7 +9,7 @@ namespace Light { -Scope Window::create(std::function callback) +auto Window::create(std::function callback) -> Scope { return create_scope(callback); } @@ -70,7 +70,7 @@ void lWindow:: set_properties(const WindowProperties &properties, bool overrideVisibility /* = false */) { // save the visibility status and re-assign if 'overrideVisibility' is false - bool visible = overrideVisibility ? properties.visible : m_properties.visible; + auto visible = overrideVisibility ? properties.visible : m_properties.visible; m_properties = properties; m_properties.visible = visible; @@ -120,119 +120,102 @@ void lWindow::set_visibility(bool visible, bool toggle) void lWindow::bind_glfw_events() { - //============================== MOUSE_EVENTS ==============================// - /* cursor position */ glfwSetCursorPosCallback(m_handle, [](GLFWwindow *window, double xpos, double ypos) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); - MouseMovedEvent event(xpos, ypos); + auto event = MouseMovedEvent { + static_cast(xpos), + static_cast(ypos), + }; callback(event); }); - /* mouse button */ glfwSetMouseButtonCallback(m_handle, [](GLFWwindow *window, int button, int action, int mods) { std::function callback = *(std::function *) glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) { - ButtonPressedEvent event(button); + auto event = ButtonPressedEvent { button }; callback(event); } else if (action == GLFW_RELEASE) { - ButtonReleasedEvent event(button); + auto event = ButtonReleasedEvent { button }; callback(event); } }); - /* scroll */ glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double xoffset, double yoffset) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); - WheelScrolledEvent event(yoffset); + auto event = WheelScrolledEvent { static_cast(yoffset) }; callback(event); }); - //============================== MOUSE_EVENTS ==============================// - //============================== KEYBOARD_EVENTS ==============================// - /* key */ glfwSetKeyCallback( m_handle, [](GLFWwindow *window, int key, int scancode, int action, int mods) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) { - KeyPressedEvent event(key); + auto event = KeyPressedEvent { key }; callback(event); } else if (action == GLFW_RELEASE) { - KeyReleasedEvent event(key); + auto event = KeyReleasedEvent { key }; callback(event); } } ); - /* char */ + glfwSetCharCallback(m_handle, [](GLFWwindow *window, unsigned int character) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); - SetCharEvent event(character); + auto event = SetCharEvent { character }; callback(event); }); - //============================== KEYBOARD_EVENTS ==============================// - - //============================== WINDOW_EVENTS ==============================// - /* window position */ glfwSetWindowPosCallback(m_handle, [](GLFWwindow *window, int xpos, int ypos) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); - WindowMovedEvent event(xpos, ypos); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); + auto event = WindowMovedEvent { xpos, ypos }; callback(event); }); - /* window size */ glfwSetWindowSizeCallback(m_handle, [](GLFWwindow *window, int width, int height) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); - WindowResizedEvent event(width, height); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); + auto event = WindowResizedEvent { + static_cast(width), + static_cast(height), + }; callback(event); }); - /* window close */ glfwSetWindowCloseCallback(m_handle, [](GLFWwindow *window) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); - WindowClosedEvent event; + auto callback = *(std::function *)glfwGetWindowUserPointer(window); + auto event = WindowClosedEvent {}; callback(event); }); - /* window focus */ glfwSetWindowFocusCallback(m_handle, [](GLFWwindow *window, int focus) { - std::function callback = *(std::function *) - glfwGetWindowUserPointer(window); + auto callback = *(std::function *)glfwGetWindowUserPointer(window); if (focus == GLFW_TRUE) { - WindowGainFocusEvent event; + auto event = WindowGainFocusEvent {}; callback(event); } else { - WindowLostFocusEvent event; + auto event = WindowLostFocusEvent {}; callback(event); } }); - //============================== WINDOW_EVENTS ==============================// } } // namespace Light diff --git a/modules/engine/src/scene/scene.cpp b/modules/engine/src/scene/scene.cpp index 2df3822..3a8a596 100644 --- a/modules/engine/src/scene/scene.cpp +++ b/modules/engine/src/scene/scene.cpp @@ -40,8 +40,8 @@ void Scene::on_update(float deltaTime) void Scene::on_render(const Ref &targetFrameBuffer /* = nullptr */) { - Camera *sceneCamera = nullptr; - TransformComponent *sceneCameraTransform; + auto *sceneCamera = (Camera *) {}; + auto *sceneCameraTransform = (TransformComponent *) {}; /* scene camera */ { @@ -59,33 +59,33 @@ void Scene::on_render(const Ref &targetFrameBuffer /* = nullptr */) { if (sceneCamera) { - renderer::begin_scene(sceneCamera, *sceneCameraTransform, targetFrameBuffer); + Renderer::begin_scene(sceneCamera, *sceneCameraTransform, targetFrameBuffer); m_registry.group(entt::get) .each([](TransformComponent &transformComp, SpriteRendererComponent &spriteRendererComp) { - renderer::draw_quad( + Renderer::draw_quad( transformComp, spriteRendererComp.tint, spriteRendererComp.texture ); }); - renderer::end_scene(); + Renderer::end_scene(); } } } -Entity Scene::create_entity(const std::string &name, const TransformComponent &transform) +auto Scene::create_entity(const std::string &name, const TransformComponent &transform) -> Entity { return create_entity_with_uuid(name, UUID(), transform); } -Entity Scene::get_entity_by_tag(const std::string &tag) +auto Scene::get_entity_by_tag(const std::string &tag) -> Entity { // TagComponent tagComp(tag); // entt::entity entity = entt::to_entity(m_registry, tagComp); - Entity entity; + auto entity = Entity {}; m_registry.view().each([&](TagComponent &tagComp) { // if (tagComp.tag == tag) @@ -101,16 +101,16 @@ Entity Scene::get_entity_by_tag(const std::string &tag) } } -Entity Scene::create_entity_with_uuid( +auto Scene::create_entity_with_uuid( const std::string &name, UUID uuid, const TransformComponent &transform -) +) -> Entity { - Entity entity { m_registry.create(), this }; - entity.AddComponent(name); - entity.AddComponent(transform); - entity.AddComponent(uuid); + auto entity = Entity { m_registry.create(), this }; + entity.add_component(name); + entity.add_component(transform); + entity.add_component(uuid); return entity; } diff --git a/modules/engine/src/time/timer.cpp b/modules/engine/src/time/timer.cpp index 1b4015b..d611b4e 100644 --- a/modules/engine/src/time/timer.cpp +++ b/modules/engine/src/time/timer.cpp @@ -12,7 +12,7 @@ DeltaTimer::DeltaTimer(): m_previous_frame(NULL), m_delta_time(60.0f / 1000.0f) void DeltaTimer::update() { - float currentFrame = timer.get_elapsed_time(); + auto currentFrame = timer.get_elapsed_time(); m_delta_time = currentFrame - m_previous_frame; m_previous_frame = currentFrame; } diff --git a/modules/engine/src/user_interface/user_interface.cpp b/modules/engine/src/user_interface/user_interface.cpp index 936a972..2e15aab 100644 --- a/modules/engine/src/user_interface/user_interface.cpp +++ b/modules/engine/src/user_interface/user_interface.cpp @@ -18,12 +18,10 @@ namespace Light { UserInterface *UserInterface::s_context = nullptr; -Scope UserInterface::create( - GLFWwindow *windowHandle, - Ref sharedContext -) +auto UserInterface::create(GLFWwindow *windowHandle, Ref sharedContext) + -> Scope { - Scope scopeUserInterface = nullptr; + auto scopeUserInterface = Scope { nullptr }; switch (GraphicsContext::get_graphics_api()) { diff --git a/modules/engine/src/utils/file_manager.cpp b/modules/engine/src/utils/file_manager.cpp index 955f14b..5917be9 100644 --- a/modules/engine/src/utils/file_manager.cpp +++ b/modules/engine/src/utils/file_manager.cpp @@ -27,14 +27,14 @@ void BasicFileHandle::release() } -BasicFileHandle FileManager::read_text_file(const std::string &path) +auto FileManager::read_text_file(const std::string &path) -> BasicFileHandle { // parse path info - std::string name = path.substr(0, path.find('.') + -1); - std::string extension = path.substr(path.find('.') + 1); + auto name = path.substr(0, path.find('.') + -1); + auto extension = path.substr(path.find('.') + 1); // open file - std::ifstream file(path.c_str(), std::ios_base::in | std::ios_base::binary); + auto file = std::ifstream { path.c_str(), std::ios_base::in | std::ios_base::binary }; // check if (!file) @@ -46,45 +46,44 @@ BasicFileHandle FileManager::read_text_file(const std::string &path) // fetch file size file.seekg(0, std::ios::end); - uint32_t size = file.tellg(); + auto size = file.tellg(); file.seekg(0, std::ios::beg); if (!size) lt_log(warn, "Empty text file: {}", path); // read file - uint8_t *data = new uint8_t[size]; + auto *data = new uint8_t[size]; file.read(reinterpret_cast(data), size); file.close(); - return BasicFileHandle(data, size, path, name, extension); + return { data, static_cast(size), path, name, extension }; } -ImageFileHandle FileManager::read_image_file(const std::string &path, int32_t desiredComponents) +auto FileManager::read_image_file(const std::string &path, int32_t desiredComponents) + -> ImageFileHandle { // parse path info - std::string name = path.substr(0, path.find('.') + -1); - std::string extension = path.substr(path.find('.') + 1); + auto name = path.substr(0, path.find('.') + -1); + auto extension = path.substr(path.find('.') + 1); // load image - int32_t width = 0, height = 0, fetchedComponents = 0; - uint8_t *pixels = stbi_load( - path.c_str(), - &width, - &height, - &fetchedComponents, - desiredComponents - ); + auto width = 0; + auto height = 0; + auto fetchedComponents = 0; + auto *pixels = stbi_load(path.c_str(), &width, &height, &fetchedComponents, desiredComponents); // check if (!pixels) lt_log(warn, "Failed to load image file: <{}>", path); else if (fetchedComponents != desiredComponents) - lt_log(warn, + lt_log( + warn, "Mismatch of fetched/desired components: <{}> ({}/{})", name + '.' + extension, fetchedComponents, - desiredComponents); + desiredComponents + ); return ImageFileHandle( pixels, @@ -106,5 +105,4 @@ void ImageFileHandle::release() m_size = 0ull; } - } // namespace Light diff --git a/modules/engine/src/utils/resource_manager.cpp b/modules/engine/src/utils/resource_manager.cpp index 4cb2577..b9f1ba7 100644 --- a/modules/engine/src/utils/resource_manager.cpp +++ b/modules/engine/src/utils/resource_manager.cpp @@ -8,7 +8,7 @@ namespace Light { ResourceManager *ResourceManager::s_context = nullptr; -Scope ResourceManager::create() +auto ResourceManager::create() -> Scope { return make_scope(new ResourceManager()); } @@ -31,8 +31,8 @@ void ResourceManager::load_shader_impl( lt_assert(!pixelPath.empty(), "Empty 'pixelPath'"); // load files - BasicFileHandle vertexFile = FileManager::read_text_file(vertexPath); - BasicFileHandle pixelFile = FileManager::read_text_file(pixelPath); + auto vertexFile = FileManager::read_text_file(vertexPath); + auto pixelFile = FileManager::read_text_file(pixelPath); // check lt_assert(vertexFile.is_valid(), "Failed to read vertex file: {}", vertexPath); @@ -57,7 +57,7 @@ void ResourceManager::load_texture_impl( lt_assert(s_context, "Uninitliazed singleton"); // load file - ImageFileHandle imgFile = FileManager::read_image_file(path, desiredComponents); + auto imgFile = FileManager::read_image_file(path, desiredComponents); // create texture m_textures[name] = Ref(Texture::create( diff --git a/modules/engine/src/utils/serializer.cpp b/modules/engine/src/utils/serializer.cpp index 2134ded..b921688 100644 --- a/modules/engine/src/utils/serializer.cpp +++ b/modules/engine/src/utils/serializer.cpp @@ -8,16 +8,16 @@ namespace YAML { template<> struct convert { - static Node encode(const glm::vec3 &rhs) + static auto encode(const glm::vec3 &rhs) -> Node { - Node node; + auto node = Node {}; node.push_back(rhs.x); node.push_back(rhs.y); node.push_back(rhs.z); return node; } - static bool decode(const Node &node, glm::vec3 &rhs) + static auto decode(const Node &node, glm::vec3 &rhs) -> bool { if (!node.IsSequence() || node.size() != 3) return false; @@ -32,9 +32,9 @@ struct convert template<> struct convert { - static Node encode(const glm::vec4 &rhs) + static auto encode(const glm::vec4 &rhs) -> Node { - Node node; + auto node = Node {}; node.push_back(rhs.x); node.push_back(rhs.y); node.push_back(rhs.z); @@ -42,7 +42,7 @@ struct convert return node; } - static bool decode(const Node &node, glm::vec4 &rhs) + static auto decode(const Node &node, glm::vec4 &rhs) -> bool { if (!node.IsSequence() || node.size() != 4) return false; @@ -58,14 +58,14 @@ struct convert namespace Light { -static YAML::Emitter &operator<<(YAML::Emitter &out, const glm::vec3 &v) +static auto operator<<(YAML::Emitter &out, const glm::vec3 &v) -> YAML::Emitter & { out << YAML::Flow; out << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq; return out; } -static YAML::Emitter &operator<<(YAML::Emitter &out, const glm::vec4 &v) +static auto operator<<(YAML::Emitter &out, const glm::vec4 &v) -> YAML::Emitter & { out << YAML::Flow; out << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq; @@ -78,14 +78,14 @@ SceneSerializer::SceneSerializer(const Ref &scene): m_scene(scene) void SceneSerializer::serialize(const std::string &filePath) { - YAML::Emitter out; + auto out = YAML::Emitter {}; out << YAML::BeginMap; // Scene out << YAML::Key << "Scene" << YAML::Value << "Untitled"; out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq; for (auto [entityID, storage] : m_scene->m_registry.storage()) { - Entity entity = { static_cast(entityID), m_scene.get() }; + auto entity = Entity { static_cast(entityID), m_scene.get() }; if (!entity.is_valid()) return; @@ -96,53 +96,53 @@ void SceneSerializer::serialize(const std::string &filePath) std::filesystem::create_directories(filePath.substr(0ull, filePath.find_last_of('\\'))); - std::ofstream fout(filePath); + auto fout = std::ofstream { filePath }; if (!fout.is_open()) lt_log(trace, "Failed to create fout at: {}", filePath); + fout << out.c_str(); } -bool SceneSerializer::deserialize(const std::string &filePath) +auto SceneSerializer::deserialize(const std::string &filePath) -> bool { - std::ifstream stream(filePath); - std::stringstream ss; + auto stream = std::ifstream { filePath }; + auto ss = std::stringstream {}; ss << stream.rdbuf(); - YAML::Node data = YAML::Load(ss.str()); + auto data = YAML::Load(ss.str()); if (!data["Scene"]) return false; - std::string sceneName = data["Scene"].as(); + auto sceneName = data["Scene"].as(); lt_log(trace, "Deserializing scene: '{}'", sceneName); auto entities = data["Entities"]; if (entities) { /* #TEMPORARY SOLUTION# */ - std::unordered_set texturePaths; + auto texturePaths = std::unordered_set {}; /* #TEMPORARY SOLUTION# */ - for (auto entity : entities) { - uint64_t uuid = entity["entity"].as(); // #todo + auto uuid = entity["entity"].as(); // #todo - std::string name; + auto name = std::string {}; auto tagComponent = entity["TagComponent"]; if (tagComponent) name = tagComponent["Tag"].as(); lt_log(trace, "Deserialized entity '{}' : '{}'", uuid, name); - Entity deserializedEntity = m_scene->create_entity_with_uuid(name, uuid); + auto deserializedEntity = m_scene->create_entity_with_uuid(name, uuid); - TagComponent gg = deserializedEntity.GetComponent(); + auto gg = deserializedEntity.get_component(); lt_log(trace, gg.tag); auto transformComponent = entity["TransformComponent"]; if (transformComponent) { auto &entityTransforomComponent = deserializedEntity - .GetComponent(); + .get_component(); entityTransforomComponent.translation = transformComponent["Translation"] .as(); @@ -155,11 +155,11 @@ bool SceneSerializer::deserialize(const std::string &filePath) if (spriteRendererComponent) { auto &entitySpriteRendererComponent = deserializedEntity - .AddComponent(); + .add_component(); entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"].as( ); - std::string texturePath = spriteRendererComponent["Texture"].as(); + auto texturePath = spriteRendererComponent["Texture"].as(); if (!texturePaths.contains(texturePath)) { @@ -174,7 +174,7 @@ bool SceneSerializer::deserialize(const std::string &filePath) auto cameraComponent = entity["CameraComponent"]; if (cameraComponent) { - auto &entityCameraComponent = deserializedEntity.AddComponent(); + auto &entityCameraComponent = deserializedEntity.add_component(); const auto &cameraSpecifications = cameraComponent["Camera"]; entityCameraComponent.camera.set_projection_type( @@ -220,7 +220,7 @@ void SceneSerializer::serialize_binary(const std::string &filePath) lt_log(err, "NO_IMPLEMENT"); } -bool SceneSerializer::deserialize_binary(const std::string &filePath) +auto SceneSerializer::deserialize_binary(const std::string &filePath) -> bool { lt_log(err, "NO_IMPLEMENT"); return false; @@ -236,7 +236,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity) out << YAML::Key << "TagComponent"; out << YAML::BeginMap; // tag component - auto &tagComponent = entity.GetComponent().tag; + auto &tagComponent = entity.get_component().tag; out << YAML::Key << "Tag" << YAML::Value << tagComponent; out << YAML::EndMap; // tag component @@ -247,7 +247,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity) out << YAML::Key << "TransformComponent"; out << YAML::BeginMap; // transform component - auto &transformComponent = entity.GetComponent(); + auto &transformComponent = entity.get_component(); out << YAML::Key << "Translation" << YAML::Value << transformComponent.translation; out << YAML::Key << "Rotation" << YAML::Value << transformComponent.rotation; @@ -261,7 +261,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity) out << YAML::Key << "SpriteRendererComponent"; out << YAML::BeginMap; // sprite renderer component; - auto &spriteRendererComponent = entity.GetComponent(); + auto &spriteRendererComponent = entity.get_component(); out << YAML::Key << "Texture" << YAML::Value << spriteRendererComponent.texture->GetFilePath(); @@ -278,7 +278,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity) out << YAML::Key << "CameraComponent"; out << YAML::BeginMap; // camera component - auto &cameraComponent = entity.GetComponent(); + auto &cameraComponent = entity.get_component(); out << YAML::Key << "Camera" << YAML::Value; out << YAML::BeginMap; // camera @@ -297,7 +297,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity) out << YAML::Key << "ProjectionType" << YAML::Value << (int)cameraComponent.camera.get_projection_type(); out << YAML::Key << "BackgroundColor" << YAML::Value - << cameraComponent.camera.GetBackgroundColor(); + << cameraComponent.camera.get_background_color(); out << YAML::EndMap; // camera out << YAML::Key << "IsPrimary" << YAML::Value << cameraComponent.isPrimary; diff --git a/modules/engine/src/utils/stringifier.cpp b/modules/engine/src/utils/stringifier.cpp index 3da4c52..0c0abe3 100644 --- a/modules/engine/src/utils/stringifier.cpp +++ b/modules/engine/src/utils/stringifier.cpp @@ -5,8 +5,7 @@ namespace Light { -//============================== OPENGL ==============================// -std::string Stringifier::glDebugMsgSeverity(unsigned int severity) +auto Stringifier::glDebugMsgSeverity(unsigned int severity) -> std::string { switch (severity) { @@ -18,7 +17,7 @@ std::string Stringifier::glDebugMsgSeverity(unsigned int severity) } } -std::string Stringifier::glDebugMsgSource(unsigned int source) +auto Stringifier::glDebugMsgSource(unsigned int source) -> std::string { switch (source) { @@ -32,7 +31,7 @@ std::string Stringifier::glDebugMsgSource(unsigned int source) } } -std::string Stringifier::glDebugMsgType(unsigned int type) +auto Stringifier::glDebugMsgType(unsigned int type) -> std::string { switch (type) { @@ -48,10 +47,8 @@ std::string Stringifier::glDebugMsgType(unsigned int type) default: return "UNKNOWN"; } } -//============================== OPENGL ==============================// -//==================== SPDLOG ====================// -std::string Stringifier::spdlogLevel(unsigned int level) +auto Stringifier::spdlogLevel(unsigned int level) -> std::string { switch (level) { @@ -65,10 +62,8 @@ std::string Stringifier::spdlogLevel(unsigned int level) default: return "UNKNOWN"; } } -//==================== SPDLOG ====================// -//==================== GRAPHICS_API ====================// -std::string Stringifier::graphics_api_to_string(GraphicsAPI api) +auto Stringifier::graphics_api_to_string(GraphicsAPI api) -> std::string { switch (api) { @@ -80,6 +75,5 @@ std::string Stringifier::graphics_api_to_string(GraphicsAPI api) default: return "UNKNOWN"; } } -//==================== GRAPHICS_API ====================// } // namespace Light diff --git a/modules/mirror/include/mirror/panel/scene_hierarchy.hpp b/modules/mirror/include/mirror/panel/scene_hierarchy.hpp index 8664955..9f484e7 100644 --- a/modules/mirror/include/mirror/panel/scene_hierarchy.hpp +++ b/modules/mirror/include/mirror/panel/scene_hierarchy.hpp @@ -13,6 +13,7 @@ class SceneHierarchyPanel: public Panel { public: SceneHierarchyPanel(); + SceneHierarchyPanel(Ref context, Ref propertiesPanel = nullptr); void on_user_interface_update(); diff --git a/modules/mirror/src/editor_layer.cpp b/modules/mirror/src/editor_layer.cpp index 7b27a6c..d3fc14a 100644 --- a/modules/mirror/src/editor_layer.cpp +++ b/modules/mirror/src/editor_layer.cpp @@ -16,18 +16,19 @@ EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("") if (m_scene_dir.empty()) { m_camera_entity = m_scene->create_entity("Camera"); - m_camera_entity.AddComponent(SceneCamera(), true); + m_camera_entity.add_component(SceneCamera(), true); ResourceManager::load_texture("Awesomeface", "Assets/Textures/awesomeface.png"); - Entity entity = m_scene->create_entity("Awesomeface", {}); - entity.AddComponent( + + auto entity = Entity { m_scene->create_entity("Awesomeface", {}) }; + entity.add_component( ResourceManager::get_texture("Awesomeface"), glm::vec4 { 0.0f, 1.0f, 1.0f, 1.0f } ); } else { - SceneSerializer serializer(m_scene); + auto serializer = SceneSerializer { m_scene }; lt_assert(serializer.deserialize(m_scene_dir), "Failed to de-serialize: {}", m_scene_dir); // m_camera_entity = m_scene->GetEntityByTag("Game Camera"); @@ -38,7 +39,7 @@ EditorLayer::~EditorLayer() { if (!m_scene_dir.empty()) { - SceneSerializer serializer(m_scene); + auto serializer = SceneSerializer { m_scene }; serializer.serialize(m_scene_dir); } } @@ -55,7 +56,7 @@ void EditorLayer::on_update(float deltaTime) Input::get_keyboard_key(Key::W) ? 1.0f : 0.0f; - auto &cameraTranslation = m_camera_entity.GetComponent().translation; + auto &cameraTranslation = m_camera_entity.get_component().translation; cameraTranslation += glm::vec3(m_direction * m_speed * deltaTime, 0.0f); if (Input::get_keyboard_key(Key::Escape)) @@ -75,22 +76,22 @@ void EditorLayer::on_user_interface_update() if (ImGui::Begin("Game")) { Input::receive_game_events(ImGui::IsWindowFocused()); - ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + auto regionAvail = ImGui::GetContentRegionAvail(); if (m_available_content_region_prev != regionAvail) { m_framebuffer->resize({ regionAvail.x, regionAvail.y }); - auto &camera = m_camera_entity.GetComponent().camera; + auto &camera = m_camera_entity.get_component().camera; camera.set_viewport_size(regionAvail.x, regionAvail.y); m_available_content_region_prev = regionAvail; } if (GraphicsContext::get_graphics_api() == GraphicsAPI::DirectX) - ImGui::Image(m_framebuffer->GetColorAttachment(), regionAvail); + ImGui::Image(m_framebuffer->get_color_attachment(), regionAvail); else ImGui::Image( - m_framebuffer->GetColorAttachment(), + m_framebuffer->get_color_attachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0) diff --git a/modules/mirror/src/mirror.cpp b/modules/mirror/src/mirror.cpp index db38767..ffcee57 100644 --- a/modules/mirror/src/mirror.cpp +++ b/modules/mirror/src/mirror.cpp @@ -14,10 +14,11 @@ public: Mirror() { // Set window properties - Light::WindowProperties properties; - properties.title = "Mirror"; - properties.size = glm::uvec2(1280u, 720u); - properties.vsync = true; + auto properties = Light::WindowProperties { + .title = "Mirror", + .size = glm::uvec2(1280u, 720u), + .vsync = true, + }; m_window->set_properties(properties); @@ -26,7 +27,7 @@ public: } }; -Application *CreateApplication() +auto create_application() -> Application * { return new Mirror(); } diff --git a/modules/mirror/src/panel/asset_browser.cpp b/modules/mirror/src/panel/asset_browser.cpp index 8705b34..79e9d04 100644 --- a/modules/mirror/src/panel/asset_browser.cpp +++ b/modules/mirror/src/panel/asset_browser.cpp @@ -34,9 +34,9 @@ void AssetBrowserPanel::on_user_interface_update() } } - ImVec2 regionAvail = ImGui::GetContentRegionAvail(); - uint32_t cellSize = m_file_size + m_file_padding; - uint32_t columnCount = std::clamp( + auto regionAvail = ImGui::GetContentRegionAvail(); + auto cellSize = m_file_size + m_file_padding; + auto columnCount = std::clamp( static_cast(std::floor(regionAvail.x / cellSize)), 1u, 64u @@ -45,13 +45,13 @@ void AssetBrowserPanel::on_user_interface_update() if (ImGui::BeginTable("ContentBrowser", columnCount)) { m_directory_texture->bind(0u); - for (auto &dirEntry : std::filesystem::directory_iterator(m_current_directory)) + for (const auto &dirEntry : std::filesystem::directory_iterator(m_current_directory)) { const auto &path = dirEntry.path(); - std::string extension = dirEntry.path().extension().string(); + auto extension = dirEntry.path().extension().string(); // TODO: Tidy up - AssetType assetType; + auto assetType = AssetType {}; assetType = extension.empty() ? AssetType::Directory : extension == ".txt" ? AssetType::Text : @@ -102,7 +102,7 @@ void AssetBrowserPanel::on_user_interface_update() ImVec4 { 1.0f, 1.0f, 1.0f, 1.0f } )) { - SceneSerializer serializer(m_active_scene); + auto serializer = SceneSerializer { m_active_scene }; lt_log(info, "Attempting to deserialize: {}", path.string()); serializer.deserialize(path.string()); } diff --git a/modules/mirror/src/panel/properties.cpp b/modules/mirror/src/panel/properties.cpp index e6ed717..9588c2c 100644 --- a/modules/mirror/src/panel/properties.cpp +++ b/modules/mirror/src/panel/properties.cpp @@ -16,14 +16,16 @@ void PropertiesPanel::on_user_interface_update() { if (m_entity_context.has_component()) { - auto &tagComponent = m_entity_context.GetComponent(); + auto &tagComponent = m_entity_context.get_component(); - char buffer[256]; - memset(buffer, 0, sizeof(buffer)); - std::strncpy(buffer, tagComponent.tag.c_str(), sizeof(buffer)); + auto buffer = std::array {}; + memset(buffer.data(), 0, buffer.size()); + std::strncpy(buffer.data(), tagComponent.tag.c_str(), buffer.size()); - if (ImGui::InputText("##Tag", buffer, sizeof(buffer))) - tagComponent.tag = std::string(buffer); + if (ImGui::InputText("##Tag", buffer.data(), buffer.size())) + { + tagComponent.tag = buffer.data(); + } } ImGui::SameLine(); @@ -41,7 +43,7 @@ void PropertiesPanel::on_user_interface_update() ImGuiSelectableFlags_Disabled : NULL )) - m_entity_context.AddComponent( + m_entity_context.add_component( Light::ResourceManager::get_texture("awesomeface") ); @@ -52,7 +54,7 @@ void PropertiesPanel::on_user_interface_update() ImGuiSelectableFlags_Disabled : NULL )) - m_entity_context.AddComponent(); + m_entity_context.add_component(); ImGui::EndPopup(); } @@ -80,14 +82,17 @@ void PropertiesPanel::on_user_interface_update() [&](auto &cameraComponent) { auto &camera = cameraComponent.camera; - SceneCamera::ProjectionType projectionType = camera.get_projection_type(); - const char *projectionTypesString[] = { "Orthographic", "Perspective" }; + auto projectionType = camera.get_projection_type(); + auto projectionTypesString = std::array { + "Orthographic", + "Perspective", + }; if (ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType])) { for (int i = 0; i < 2; i++) { - const bool isSelected = (int)projectionType == i; + const auto isSelected = (int)projectionType == i; if (ImGui::Selectable(projectionTypesString[i], isSelected)) { projectionType = (SceneCamera::ProjectionType)i; @@ -103,7 +108,9 @@ void PropertiesPanel::on_user_interface_update() if (projectionType == SceneCamera::ProjectionType::Orthographic) { - float orthoSize, nearPlane, farPlane; + auto orthoSize = float {}; + auto nearPlane = float {}; + auto farPlane = float {}; orthoSize = camera.get_orthographic_size(); nearPlane = camera.get_orthographic_near_plane(); @@ -121,7 +128,9 @@ void PropertiesPanel::on_user_interface_update() else // perspective { - float verticalFOV, nearPlane, farPlane; + auto verticalFOV = float {}; + auto nearPlane = float {}; + auto farPlane = float {}; verticalFOV = glm::degrees(camera.get_perspective_vertical_fov()); nearPlane = camera.get_perspective_near_plane(); @@ -157,7 +166,7 @@ void PropertiesPanel::draw_vec3_control( float columnWidth /*= 100.0f*/ ) { - ImGuiIO &io = ImGui::GetIO(); + auto &io = ImGui::GetIO(); auto boldFont = io.Fonts->Fonts[0]; @@ -169,8 +178,8 @@ void PropertiesPanel::draw_vec3_control( ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2 { 0, 0 }); - float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f; - ImVec2 buttonSize = { lineHeight + 3.0f, lineHeight }; + auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f; + auto buttonSize = ImVec2 { lineHeight + 3.0f, lineHeight }; ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.1f, 0.15f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.2f, 0.2f, 1.0f)); @@ -229,16 +238,16 @@ void PropertiesPanel::draw_component( if (!entity.has_component()) return; - auto &component = entity.GetComponent(); + auto &component = entity.get_component(); - ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + auto regionAvail = ImGui::GetContentRegionAvail(); - ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth - | ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap - | ImGuiTreeNodeFlags_FramePadding; + auto flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth + | ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap + | ImGuiTreeNodeFlags_FramePadding; ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 4, 4 }); - float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f; + auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f; ImGui::Separator(); if (ImGui::TreeNodeEx((void *)typeid(ComponentType).hash_code(), flags, name.c_str())) diff --git a/modules/mirror/src/panel/scene_hierarchy.cpp b/modules/mirror/src/panel/scene_hierarchy.cpp index e744ef1..fecdfe0 100644 --- a/modules/mirror/src/panel/scene_hierarchy.cpp +++ b/modules/mirror/src/panel/scene_hierarchy.cpp @@ -28,9 +28,12 @@ void SceneHierarchyPanel::on_user_interface_update() for (auto entityID : m_context->m_registry.view()) { - Entity entity(static_cast(entityID), m_context.get()); - const std::string &tag = entity.GetComponent(); + auto entity = Entity { + static_cast(entityID), + m_context.get(), + }; + const auto &tag = entity.get_component(); draw_node(entity, tag); }; } @@ -48,10 +51,14 @@ void SceneHierarchyPanel::set_context(Ref context, Ref p void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label) { - ImGuiTreeNodeFlags flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL) - | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth; + auto flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL) + | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth; - bool expanded = ImGui::TreeNodeEx((void *)(uint64_t)(uint32_t)(entity), flags, label.c_str()); + const auto expanded = ImGui::TreeNodeEx( + (void *)(uint64_t)(uint32_t)(entity), + flags, + label.c_str() + ); if (ImGui::IsItemClicked()) {