diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/api/Animator.h | 14 | ||||
-rw-r--r-- | src/crepe/api/Camera.h | 26 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 36 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 16 | ||||
-rw-r--r-- | src/crepe/api/Texture.h | 1 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 17 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 49 | ||||
-rw-r--r-- | src/crepe/system/AnimatorSystem.cpp | 2 |
8 files changed, 60 insertions, 101 deletions
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index ede1610..42ce957 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -28,11 +28,11 @@ public: /** * \brief Constructs an Animator object that will control animations for a sprite sheet. * - * \param[in] id The unique identifier for the component, typically assigned automatically. - * \param[in] spritesheet A reference to the Sprite object which holds the sprite sheet for animation. - * \param[in] row The maximum number of rows in the sprite sheet. - * \param[in] col The maximum number of columns in the sprite sheet. - * \param[in] col__animate The specific col index of the sprite sheet to animate. This allows selecting which col to animate from multiple col in the sheet. + * \param id The unique identifier for the component, typically assigned automatically. + * \param spritesheet A reference to the Sprite object which holds the sprite sheet for animation. + * \param row The maximum number of rows in the sprite sheet. + * \param col The maximum number of columns in the sprite sheet. + * \param col__animate The specific col index of the sprite sheet to animate. This allows selecting which col to animate from multiple col in the sheet. * * This constructor sets up the Animator with the given parameters, and initializes the animation system. */ @@ -80,8 +80,10 @@ private: //int fps; private: - //! Friend class that can directly access the private members of the Animator. + //! AnimatorSystem adjust the private member parameters of Animator; friend class AnimatorSystem; + + //! SDLContext reads the Animator member var's friend class SDLContext; }; } // namespace crepe diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 7587b44..708a523 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -2,8 +2,8 @@ #include <cstdint> -#include "Component.h" #include "Color.h" +#include "Component.h" namespace crepe { @@ -31,34 +31,22 @@ public: ~Camera(); public: - /** - * \brief Background color of the camera view. - */ + //! \brief Background color of the camera view. Color bg_color; - /** - * \brief Aspect ratio height for the camera. - */ + //! \brief Aspect ratio height for the camera. double aspect_height; - /** - * \brief Aspect ratio width for the camera. - */ + //! \brief Aspect ratio width for the camera. double aspect_width; - /** - * \brief X-coordinate of the camera position. - */ + //! \brief X-coordinate of the camera position. double x; - /** - * \brief Y-coordinate of the camera position. - */ + //! \brief Y-coordinate of the camera position. double y; - /** - * \brief Zoom level of the camera view. - */ + //! \brief Zoom level of the camera view. double zoom; public: diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 51cb860..1db32d7 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -10,13 +10,6 @@ namespace crepe { -/** - * \struct Rect - * \brief Represents a rectangle area for rendering. - * - * Everything within the defined rectangle will be rendered. - * The SDLContext will translate this into the library's rectangle structure. - */ struct Rect { int w = 0; int h = 0; @@ -24,29 +17,16 @@ struct Rect { int y = 0; }; -/** - * \struct FlipSettings - * \brief Flip settings for the sprite. - * - * Defines the horizontal and vertical flip settings for a sprite, which the - * SDLContext will translate into the corresponding settings for the library. - */ struct FlipSettings { bool flip_x = false; bool flip_y = false; }; -//! Forward declaration of the SDLContext facade. class SDLContext; - -//! Forward declaration of the Animator class. class Animator; - -//! Forward declaration of the AnimatorSystem class. class AnimatorSystem; /** - * \class Sprite * \brief Represents a renderable sprite component. * * A renderable sprite that can be displayed in the game. It includes a texture, @@ -55,6 +35,9 @@ class AnimatorSystem; class Sprite : public Component { public: + + // TODO: Loek comment in github #27 will be looked another time + // about shared_ptr Texture /** * \brief Constructs a Sprite with specified parameters. * \param game_id Unique identifier for the game object this sprite belongs to. @@ -78,23 +61,30 @@ public: //! Flip settings for the sprite FlipSettings flip; //! Layer sorting level of the sprite - uint8_t sorting_in_layer; + uint8_t sorting_in_layer = 0; //! Order within the sorting layer - uint8_t order_in_layer; + uint8_t order_in_layer = 0; public: /** * \brief Gets the maximum number of instances allowed for this sprite. * \return Maximum instance count as an integer. + * + * For now is this number randomly picked. I think it will eventually be 1. */ virtual int get_instances_max() const { return 10; } private: + //! Reads the sprite_rect of sprite friend class SDLContext; + + //! Reads the all the variables plus the sprite_rect friend class Animator; + + //! Reads the all the variables plus the sprite_rect friend class AnimatorSystem; - //! Render area of the sprite + //! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator object is present in GameObject Rect sprite_rect; }; diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index 5519e5e..e6c2e05 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -32,18 +32,10 @@ void Texture::load(unique_ptr<Asset> res) { } int Texture::get_width() const{ - if (this->texture) { - return SDLContext::get_instance().get_width(*this); - } - else { - return 0; - } + if (this->texture == nullptr) return 0; + return SDLContext::get_instance().get_width(*this); } int Texture::get_height() const{ - if (this->texture) { - return SDLContext::get_instance().get_height(*this); - } - else { - return 0; - } + if (this->texture == nullptr) return 0; + return SDLContext::get_instance().get_width(*this); } diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h index 6d99a93..828518d 100644 --- a/src/crepe/api/Texture.h +++ b/src/crepe/api/Texture.h @@ -64,6 +64,7 @@ private: void load(std::unique_ptr<Asset> res); private: + //TODO make RAII //! The texture of the class from the library SDL_Texture * texture = nullptr; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 9a2d15a..cedb7b8 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -7,6 +7,7 @@ #include <cmath> #include <cstddef> #include <iostream> +#include <string> #include "../api/Sprite.h" #include "../api/Texture.h" @@ -98,13 +99,15 @@ void SDLContext::handle_events(bool & running) { */ } -void SDLContext::clear_screen() const { SDL_RenderClear(this->game_renderer); } -void SDLContext::present_screen() const { SDL_RenderPresent(this->game_renderer); } +void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer); } +void SDLContext::present_screen() { + SDL_RenderPresent(this->game_renderer); +} void SDLContext::draw(const Sprite & sprite, const Transform & transform, - const Camera & cam) const { + const Camera & cam) { - static SDL_RendererFlip render_flip + SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) | (SDL_FLIP_VERTICAL * sprite.flip.flip_y)); @@ -147,10 +150,10 @@ 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) const { - dbg_trace(); +//TODO: make this RAII +SDL_Texture * SDLContext::texture_from_path(const std::string & path) { - SDL_Surface * tmp = IMG_Load(path); + SDL_Surface * tmp = IMG_Load(path.c_str()); if (!tmp) { std::cerr << "Error surface " << IMG_GetError << std::endl; } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 3396697..80b76dd 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -3,18 +3,18 @@ #include <SDL2/SDL_keycode.h> #include <SDL2/SDL_render.h> #include <SDL2/SDL_video.h> +#include <string> #include "../api/Sprite.h" #include "../api/Transform.h" #include "api/Camera.h" -typedef SDL_Keycode CREPE_KEYCODES; - //FIXME: this needs to be removed const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; namespace crepe { +typedef SDL_Keycode CREPE_KEYCODES; class Texture; class LoopManager; @@ -35,29 +35,13 @@ public: */ static SDLContext & get_instance(); - /** - * \brief Deleted copy constructor. - */ SDLContext(const SDLContext &) = delete; - - /** - * \brief Deleted move constructor. - */ SDLContext(SDLContext &&) = delete; - - /** - * \brief Deleted copy assignment operator. - * \return Reference to the SDLContext instance. - */ SDLContext & operator=(const SDLContext &) = delete; - - /** - * \brief Deleted move assignment operator. - * \return Reference to the SDLContext instance. - */ SDLContext & operator=(SDLContext &&) = delete; private: + //! will only use handle_events friend class LoopManager; /** * \brief Handles SDL events such as window close and input. @@ -65,8 +49,8 @@ private: */ void handle_events(bool & running); - private: + //! Will only use get_ticks friend class AnimatorSystem; /** @@ -75,7 +59,6 @@ private: */ const uint64_t get_ticks() const; - private: /** * \brief Constructs an SDLContext instance. @@ -87,13 +70,13 @@ private: * \brief Destroys the SDLContext instance. * Cleans up SDL resources, including the window and renderer. */ - virtual ~SDLContext(); - - + ~SDLContext(); private: - + //! Will use the funtions: texture_from_path, get_width,get_height. friend class Texture; + + //! Will use the funtions: texture_from_path, get_width,get_height. friend class Animator; /** @@ -101,25 +84,24 @@ private: * \param path Path to the image file. * \return Pointer to the created SDL_Texture. */ - SDL_Texture * texture_from_path(const char * path) const; + SDL_Texture * texture_from_path(const std::string & path); /** * \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 & ) const ; + 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 &) const ; - + int get_height(const Texture &) const; private: - + //! Will use draw,clear_screen, present_screen, camera. friend class RenderSystem; /** @@ -129,17 +111,17 @@ private: * \param camera Reference to the Camera for view adjustments. */ void draw(const Sprite & sprite, const Transform & transform, - const Camera & camera) const; + const Camera & camera); /** * \brief Clears the screen, preparing for a new frame. */ - void clear_screen() const ; + void clear_screen(); /** * \brief Presents the rendered frame to the screen. */ - void present_screen() const ; + void present_screen(); /** * \brief Sets the current camera for rendering. @@ -148,6 +130,7 @@ private: void camera(const Camera & camera); private: + //TODO: Make this RAII //! sdl window SDL_Window * game_window = nullptr; //! renderer for the crepe engine diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index 3d6c807..4ea889a 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -3,11 +3,11 @@ #include <functional> #include <vector> -#include "ComponentManager.h" #include "facade/SDLContext.h" #include "util/log.h" #include "api/Animator.h" +#include "ComponentManager.h" #include "AnimatorSystem.h" using namespace crepe; |