From 9432900158e6a31815345fcf0af8d28ae34c6da9 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 8 Nov 2024 11:44:21 +0100 Subject: code style --- src/crepe/system/RenderSystem.h | 69 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'src/crepe/system/RenderSystem.h') diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 4b910a4..684776b 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -1,17 +1,78 @@ #pragma once #include "System.h" +#include "api/Camera.h" namespace crepe { +/** + * \class RenderSystem + * \brief Manages rendering operations for all game objects. + * + * RenderSystem is responsible for rendering sprites, clearing and presenting the screen, + * and managing the active camera. It functions as a singleton, providing centralized + * rendering services for the application. + */ class RenderSystem : public System { public: - static RenderSystem & get_instance(); - void update(); + /** + * \brief Gets the singleton instance of RenderSystem. + * \return Reference to the RenderSystem instance. + */ + static RenderSystem & get_instance(); + + /** + * \brief Updates the RenderSystem for the current frame. + * This method is called to perform all rendering operations for the current game frame. + */ + void update() override; + +private: + /** + * \brief Constructs a RenderSystem instance. + * Private constructor to enforce singleton pattern. + */ + RenderSystem(); + + /** + * \brief Destroys the RenderSystem instance. + */ + ~RenderSystem(); + + /** + * \brief Clears the screen in preparation for rendering. + */ + void clear_screen(); + + /** + * \brief Presents the rendered frame to the display. + */ + void present_screen(); + + /** + * \brief Updates the active camera used for rendering. + */ + void update_camera(); + + /** + * \brief Renders all active sprites to the screen. + */ + void render_sprites(); + + /** + * \todo Include color handling for sprites. + * \todo Implement particle emitter rendering with sprites. + * \todo Add text rendering using SDL_ttf for text components. + * \todo Implement a text component and a button component. + * \todo Ensure each sprite is checked for active status before rendering. + * \todo Sort all layers by order before rendering. + * \todo Consider adding text input functionality. + */ private: - RenderSystem(); - ~RenderSystem(); + //! Pointer to the current active camera for rendering + // \todo needs a better solution + Camera * curr_cam; }; } // namespace crepe -- cgit v1.2.3 From 2e0b75fc51c4ef025f6b74f7f1648d04039bb955 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 8 Nov 2024 12:16:41 +0100 Subject: fixed the includes and const settings --- src/crepe/api/Animator.cpp | 6 +++--- src/crepe/api/Animator.h | 3 ++- src/crepe/api/Camera.cpp | 9 ++++++--- src/crepe/api/Camera.h | 3 ++- src/crepe/api/Sprite.cpp | 9 ++++----- src/crepe/api/Sprite.h | 6 +++--- src/crepe/api/Texture.cpp | 2 +- src/crepe/facade/SDLContext.cpp | 12 ++++++------ src/crepe/facade/SDLContext.h | 12 ++++++------ src/crepe/system/AnimatorSystem.cpp | 9 ++++----- src/crepe/system/RenderSystem.cpp | 6 +++--- src/crepe/system/RenderSystem.h | 6 +++--- 12 files changed, 43 insertions(+), 40 deletions(-) (limited to 'src/crepe/system/RenderSystem.h') diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 3834e0b..0896bb0 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,11 +1,11 @@ +#include -#include "Animator.h" #include "Component.h" #include "api/Sprite.h" - #include "util/log.h" -#include + +#include "Animator.h" using namespace crepe; diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 3493623..ec29a7f 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -1,8 +1,9 @@ #pragma once +#include + #include "Component.h" #include "api/Sprite.h" -#include namespace crepe { class AnimatorSystem; diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index 46a56b2..d423131 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -1,14 +1,17 @@ +#include -#include "Camera.h" #include "Component.h" #include "api/Color.h" #include "util/log.h" -#include + +#include "Camera.h" using namespace crepe; -Camera::Camera(uint32_t id, const Color& color) : Component(id), bg_color(color), aspect_width(640), aspect_height(480), zoom(1), x(0),y(0){ +Camera::Camera(uint32_t id, const Color & color) + : Component(id), bg_color(color), aspect_width(640), aspect_height(480), + zoom(1), x(0), y(0) { dbg_trace(); } diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 022496d..1ff9f37 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -1,8 +1,9 @@ #pragma once +#include + #include "Component.h" #include "api/Color.h" -#include namespace crepe { diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 3db8f2b..42e1177 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -1,17 +1,16 @@ -#include #include -#include "../util/log.h" - #include "Component.h" -#include "Sprite.h" #include "Texture.h" #include "facade/SDLContext.h" +#include "../util/log.h" + +#include "Sprite.h" using namespace std; using namespace crepe; -Sprite::Sprite(game_object_id_t id, shared_ptr image, +Sprite::Sprite(game_object_id_t id, const shared_ptr image, const Color & color, const FlipSettings & flip) : Component(id), color(color), flip(flip), sprite_image(image) { dbg_trace(); diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 2e8b52a..6f83ac8 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -5,9 +5,9 @@ #include "api/Color.h" #include "api/Texture.h" - #include "Component.h" + namespace crepe { /** @@ -62,7 +62,7 @@ public: * \param color Color tint applied to the sprite. * \param flip Flip settings for horizontal and vertical orientation. */ - Sprite(game_object_id_t id, std::shared_ptr image, + Sprite(game_object_id_t id, const std::shared_ptr image, const Color & color, const FlipSettings & flip); /** @@ -72,7 +72,7 @@ public: //! Texture used for the sprite - std::shared_ptr sprite_image; + const std::shared_ptr sprite_image; //! Color tint of the sprite Color color; //! Flip settings for the sprite diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index 5519e5e..f052e4d 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -2,8 +2,8 @@ #include "../facade/SDLContext.h" #include "../util/log.h" - #include "Asset.h" + #include "Texture.h" using namespace crepe; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index bbeb3a9..9a2d15a 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -98,11 +98,11 @@ void SDLContext::handle_events(bool & running) { */ } -void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer); } -void SDLContext::present_screen() { SDL_RenderPresent(this->game_renderer); } +void SDLContext::clear_screen() const { SDL_RenderClear(this->game_renderer); } +void SDLContext::present_screen() const { SDL_RenderPresent(this->game_renderer); } void SDLContext::draw(const Sprite & sprite, const Transform & transform, - const Camera & cam) { + const Camera & cam) const { static SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) @@ -147,7 +147,7 @@ void SDLContext::camera(const Camera & cam) { const uint64_t SDLContext::get_ticks() const { return SDL_GetTicks64(); } -SDL_Texture * SDLContext::texture_from_path(const char * path) { +SDL_Texture * SDLContext::texture_from_path(const char * path) const { dbg_trace(); SDL_Surface * tmp = IMG_Load(path); @@ -165,12 +165,12 @@ SDL_Texture * SDLContext::texture_from_path(const char * path) { return created_texture; } -int SDLContext::get_width(const Texture & ctx) { +int SDLContext::get_width(const Texture & ctx) const { int w; SDL_QueryTexture(ctx.texture, NULL, NULL, &w, NULL); return w; } -int SDLContext::get_height(const Texture & ctx) { +int SDLContext::get_height(const Texture & ctx) const { int h; SDL_QueryTexture(ctx.texture, NULL, NULL, NULL, &h); return h; diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index a08d0d8..3396697 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -101,21 +101,21 @@ private: * \param path Path to the image file. * \return Pointer to the created SDL_Texture. */ - SDL_Texture * texture_from_path(const char * path); + SDL_Texture * texture_from_path(const char * path) const; /** * \brief Gets the width of a texture. * \param texture Reference to the Texture object. * \return Width of the texture as an integer. */ - int get_width(const Texture & ); + int get_width(const Texture & ) const ; /** * \brief Gets the height of a texture. * \param texture Reference to the Texture object. * \return Height of the texture as an integer. */ - int get_height(const Texture &); + int get_height(const Texture &) const ; private: @@ -129,17 +129,17 @@ private: * \param camera Reference to the Camera for view adjustments. */ void draw(const Sprite & sprite, const Transform & transform, - const Camera & camera); + const Camera & camera) const; /** * \brief Clears the screen, preparing for a new frame. */ - void clear_screen(); + void clear_screen() const ; /** * \brief Presents the rendered frame to the screen. */ - void present_screen(); + void present_screen() const ; /** * \brief Sets the current camera for rendering. diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index 052d264..3d6c807 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -1,15 +1,14 @@ +#include +#include +#include -#include "AnimatorSystem.h" #include "ComponentManager.h" #include "facade/SDLContext.h" #include "util/log.h" - #include "api/Animator.h" -#include -#include -#include +#include "AnimatorSystem.h" using namespace crepe; diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 149af68..849d810 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -20,9 +20,9 @@ RenderSystem & RenderSystem::get_instance() { return instance; } -void RenderSystem::clear_screen() { SDLContext::get_instance().clear_screen(); } +void RenderSystem::clear_screen() const { SDLContext::get_instance().clear_screen(); } -void RenderSystem::present_screen() { +void RenderSystem::present_screen() const { SDLContext::get_instance().present_screen(); } void RenderSystem::update_camera() { @@ -36,7 +36,7 @@ void RenderSystem::update_camera() { this->curr_cam = &cam; } } -void RenderSystem::render_sprites() { +void RenderSystem::render_sprites() const { ComponentManager & mgr = ComponentManager::get_instance(); diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 684776b..c5e674a 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -43,12 +43,12 @@ private: /** * \brief Clears the screen in preparation for rendering. */ - void clear_screen(); + void clear_screen() const; /** * \brief Presents the rendered frame to the display. */ - void present_screen(); + void present_screen() const; /** * \brief Updates the active camera used for rendering. @@ -58,7 +58,7 @@ private: /** * \brief Renders all active sprites to the screen. */ - void render_sprites(); + void render_sprites() const; /** * \todo Include color handling for sprites. -- cgit v1.2.3 From cb6aae1751a95a29bc04d805d9cc9135b5c54c1e Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 8 Nov 2024 12:29:55 +0100 Subject: fixed include code-style --- src/crepe/api/Animator.cpp | 4 ++-- src/crepe/api/Animator.h | 2 +- src/crepe/api/Camera.cpp | 4 ++-- src/crepe/api/Camera.h | 2 +- src/crepe/api/Sprite.cpp | 4 ++-- src/crepe/api/Sprite.h | 4 ++-- src/crepe/api/Texture.cpp | 2 +- src/crepe/system/RenderSystem.h | 4 +++- 8 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/crepe/system/RenderSystem.h') diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 0896bb0..4b4d4be 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,10 +1,10 @@ #include -#include "Component.h" -#include "api/Sprite.h" #include "util/log.h" +#include "Component.h" +#include "Sprite.h" #include "Animator.h" using namespace crepe; diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index ec29a7f..ede1610 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -3,7 +3,7 @@ #include #include "Component.h" -#include "api/Sprite.h" +#include "Sprite.h" namespace crepe { class AnimatorSystem; diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index d423131..dbbfb32 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -1,10 +1,10 @@ #include -#include "Component.h" -#include "api/Color.h" #include "util/log.h" +#include "Component.h" +#include "Color.h" #include "Camera.h" using namespace crepe; diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 1ff9f37..7587b44 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -3,7 +3,7 @@ #include #include "Component.h" -#include "api/Color.h" +#include "Color.h" namespace crepe { diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 42e1177..db96c32 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -1,10 +1,10 @@ #include -#include "Component.h" -#include "Texture.h" #include "facade/SDLContext.h" #include "../util/log.h" +#include "Component.h" +#include "Texture.h" #include "Sprite.h" using namespace std; diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 6f83ac8..51cb860 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -3,8 +3,8 @@ #include #include -#include "api/Color.h" -#include "api/Texture.h" +#include "Color.h" +#include "Texture.h" #include "Component.h" diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index f052e4d..5519e5e 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -2,8 +2,8 @@ #include "../facade/SDLContext.h" #include "../util/log.h" -#include "Asset.h" +#include "Asset.h" #include "Texture.h" using namespace crepe; diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index c5e674a..ec80a0e 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -1,8 +1,10 @@ #pragma once -#include "System.h" #include "api/Camera.h" +#include "System.h" + + namespace crepe { /** -- cgit v1.2.3