diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Animator.cpp | 6 | ||||
-rw-r--r-- | src/crepe/api/Animator.h | 58 | ||||
-rw-r--r-- | src/crepe/api/AssetManager.h | 6 | ||||
-rw-r--r-- | src/crepe/api/BoxCollider.h | 2 | ||||
-rw-r--r-- | src/crepe/api/Button.h | 6 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.h | 2 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 5 | ||||
-rw-r--r-- | src/crepe/api/EventHandler.h | 34 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 12 | ||||
-rw-r--r-- | src/crepe/api/Metadata.h | 2 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 28 | ||||
-rw-r--r-- | src/crepe/api/Scene.h | 4 | ||||
-rw-r--r-- | src/crepe/api/Script.h | 2 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 38 | ||||
-rw-r--r-- | src/crepe/api/Transform.h | 2 |
16 files changed, 89 insertions, 122 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 154135f..b8a91dc 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,10 +7,10 @@ using namespace crepe; -Animator::Animator(uint32_t id, Sprite & ss, unsigned int max_row, unsigned int max_col, - const Animator::Data & data) +Animator::Animator(game_object_id_t id, Sprite & spritesheet, unsigned int max_row, + unsigned int max_col, const Animator::Data & data) : Component(id), - spritesheet(ss), + spritesheet(spritesheet), max_rows(max_row), max_columns(max_col), data(data) { diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 23d29f6..7c850b8 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -1,10 +1,9 @@ #pragma once -#include <sys/types.h> +#include "../types.h" #include "Component.h" #include "Sprite.h" -#include "types.h" namespace crepe { @@ -21,55 +20,31 @@ class SDLContext; class Animator : public Component { public: struct Data { - //! frames per second for animation unsigned int fps = 1; - //! The current col being animated. unsigned int col = 0; - //! The current row being animated. unsigned int row = 0; - //! should the animation loop bool looping = false; - //! starting frame for cycling unsigned int cycle_start = 0; - - //! end frame for cycling (-1 --> use last frame) + //! end frame for cycling (-1 = use last frame) int cycle_end = -1; - - //! offset in pixels. - // TODO implement - unsigned int white_space = 0; }; public: - /** - * \brief Animator will repeat the animation - * - */ + //! Animator will repeat the animation void loop(); - - /** - * \brief starts the animation - * - */ + //! starts the animation void play(); - /** - * \brief pauses the animation - * - * sets the active false - * - */ + //! pauses the animation void pause(); - /** * \brief stops the animation * * sets the active on false and resets all the current rows and columns - * */ void stop(); /** @@ -81,8 +56,8 @@ public: /** * \brief set the range in the row * - * \param start of row animation - * \param end of row animation + * \param start of row animation + * \param end of row animation */ void set_cycle_range(int start, int end); /** @@ -91,11 +66,7 @@ public: * \param col animation column */ void set_anim(int col); - - /** - * \brief will go to the next animaiton of current row - * - */ + //! will go to the next animaiton of current row void next_anim(); public: @@ -103,7 +74,7 @@ public: * \brief Constructs an Animator object that will control animations for a sprite sheet. * * \param id The unique identifier for the component, typically assigned automatically. - * \param ss the reference to the spritesheet + * \param spritesheet the reference to the spritesheet * \param max_row maximum of rows inside the given spritesheet * \param max_col maximum of columns inside the given spritesheet * \param data extra animation data for more control @@ -111,25 +82,22 @@ public: * This constructor sets up the Animator with the given parameters, and initializes the * animation system. */ - Animator(game_object_id_t id, Sprite & ss, unsigned int max_row, unsigned int max_col, - const Animator::Data & data); + Animator(game_object_id_t id, Sprite & spritesheet, unsigned int max_row, + unsigned int max_col, const Animator::Data & data); ~Animator(); // dbg_trace public: //! The maximum number of columns in the sprite sheet. const unsigned int max_columns; - //! The maximum number of rows in the sprite sheet. const unsigned int max_rows; - Animator::Data data; private: //! A reference to the Sprite sheet containing. Sprite & spritesheet; - - // uses the spritesheet + //! Uses the spritesheet friend AnimatorSystem; }; + } // namespace crepe -// diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h index fee6780..3b1cc4b 100644 --- a/src/crepe/api/AssetManager.h +++ b/src/crepe/api/AssetManager.h @@ -9,7 +9,7 @@ namespace crepe { /** * \brief The AssetManager is responsible for storing and managing assets over multiple scenes. - * + * * The AssetManager ensures that assets are loaded once and can be accessed across different * scenes. It caches assets to avoid reloading them every time a scene is loaded. Assets are * retained in memory until the AssetManager is destroyed, at which point the cached assets are @@ -46,9 +46,9 @@ public: * \param reload If true, the asset will be reloaded from the file, even if it is already * cached. * \tparam T The type of asset to cache (e.g., texture, sound, etc.). - * + * * \return A shared pointer to the cached asset. - * + * * This template function caches the asset at the given file path. If the asset is already * cached and `reload` is false, the existing cached version will be returned. Otherwise, the * asset will be reloaded and added to the cache. diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h index 89e43d8..1ac4d46 100644 --- a/src/crepe/api/BoxCollider.h +++ b/src/crepe/api/BoxCollider.h @@ -8,7 +8,7 @@ namespace crepe { /** * \brief A class representing a box-shaped collider. - * + * * This class is used for collision detection with other colliders (e.g., CircleCollider). */ class BoxCollider : public Collider { diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index 26e7526..61b18d7 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -11,7 +11,7 @@ class Button : public UIObject { public: /** * \brief Constructs a Button with the specified game object ID and dimensions. - * + * * \param id The unique ID of the game object associated with this button. * \param dimensions The width and height of the UIObject * \param offset The offset relative this GameObjects Transform @@ -23,7 +23,7 @@ public: /** * \brief Indicates if the button is a toggle button (can be pressed and released). - * + * * A toggle button allows for a pressed/released state, whereas a regular button * typically only has an on-click state. */ @@ -31,7 +31,7 @@ public: // TODO: create separate toggle button class /** * \brief The callback function to be executed when the button is clicked. - * + * * This function is invoked whenever the button is clicked. It can be set to any * function that matches the signature `void()`. */ diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index b2e3df8..593c4e6 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -39,8 +39,8 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Vector2.h Vector2.hpp Color.h - Texture.h - AssetManager.h + Texture.h + AssetManager.h AssetManager.hpp Scene.h Metadata.h diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index ebd1cb2..c7bf66e 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -8,7 +8,7 @@ namespace crepe { /** * \brief A class representing a circle-shaped collider. - * + * * This class is used for collision detection with other colliders (e.g., BoxCollider). */ class CircleCollider : public Collider { diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index f1bca62..a9745c3 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -1,8 +1,10 @@ #pragma once +#include <string> + #include "../util/Log.h" + #include "types.h" -#include <string> namespace crepe { @@ -69,7 +71,6 @@ public: //! default screen size in pixels ivec2 default_size = {1280, 720}; std::string window_title = "Jetpack joyride clone"; - } window_settings; //! Asset loading options diff --git a/src/crepe/api/EventHandler.h b/src/crepe/api/EventHandler.h index 7bdd9a3..7bb501b 100644 --- a/src/crepe/api/EventHandler.h +++ b/src/crepe/api/EventHandler.h @@ -8,12 +8,12 @@ namespace crepe { /** * \brief A type alias for an event handler function. - * - * The EventHandler is a std::function that takes an EventType reference and returns a boolean value + * + * The EventHandler is a std::function that takes an EventType reference and returns a boolean value * indicating whether the event is handled. - * + * * \tparam EventType The type of event this handler will handle. - * + * * Returning \c false from an event handler results in the event being propogated to other listeners for the same event type, while returning \c true stops propogation altogether. */ template <typename EventType> @@ -22,7 +22,7 @@ using EventHandler = std::function<bool(const EventType & e)>; /** * \class IEventHandlerWrapper * \brief An abstract base class for event handler wrappers. - * + * * This class provides the interface for handling events. Derived classes must implement the * `call()` method to process events */ @@ -35,9 +35,9 @@ public: /** * \brief Executes the handler with the given event. - * + * * This method calls the `call()` method of the derived class, passing the event to the handler. - * + * * \param e The event to be processed. * \return A boolean value indicating whether the event is handled. */ @@ -46,9 +46,9 @@ public: private: /** * \brief The method responsible for handling the event. - * + * * This method is implemented by derived classes to process the event. - * + * * \param e The event to be processed. * \return A boolean value indicating whether the event is handled. */ @@ -58,11 +58,11 @@ private: /** * \class EventHandlerWrapper * \brief A wrapper for event handler functions. - * - * This class wraps an event handler function of a specific event type. It implements the - * `call()` and `get_type()` methods to allow the handler to be executed and its type to be + * + * This class wraps an event handler function of a specific event type. It implements the + * `call()` and `get_type()` methods to allow the handler to be executed and its type to be * queried. - * + * * \tparam EventType The type of event this handler will handle. */ template <typename EventType> @@ -70,9 +70,9 @@ class EventHandlerWrapper : public IEventHandlerWrapper { public: /** * \brief Constructs an EventHandlerWrapper with a given handler. - * + * * The constructor takes an event handler function and stores it in the wrapper. - * + * * \param handler The event handler function. */ explicit EventHandlerWrapper(const EventHandler<EventType> & handler); @@ -80,9 +80,9 @@ public: private: /** * \brief Calls the stored event handler with the event. - * + * * This method casts the event to the appropriate type and calls the handler. - * + * * \param e The event to be handled. * \return A boolean value indicating whether the event is handled. */ diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 4cd2bc0..ff80f49 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -10,7 +10,7 @@ class ComponentManager; /** * \brief Represents a GameObject - * + * * This class represents a GameObject. The GameObject class is only used as an interface for * the game programmer. The actual implementation is done in the ComponentManager. */ @@ -19,7 +19,7 @@ private: /** * This constructor creates a new GameObject. It creates a new Transform and Metadata * component and adds them to the ComponentManager. - * + * * \param component_manager Reference to component_manager * \param id The id of the GameObject * \param name The name of the GameObject @@ -37,20 +37,20 @@ private: public: /** * \brief Set the parent of this GameObject - * + * * This method sets the parent of this GameObject. It sets the parent in the Metadata * component of this GameObject and adds this GameObject to the children list of the parent * GameObject. - * + * * \param parent The parent GameObject */ void set_parent(const GameObject & parent); /** * \brief Add a component to the GameObject - * + * * This method adds a component to the GameObject. It forwards the arguments to the * ComponentManager. - * + * * \tparam T The type of the component * \tparam Args The types of the arguments * \param args The arguments to create the component diff --git a/src/crepe/api/Metadata.h b/src/crepe/api/Metadata.h index 235d42f..f404703 100644 --- a/src/crepe/api/Metadata.h +++ b/src/crepe/api/Metadata.h @@ -9,7 +9,7 @@ namespace crepe { /** * \brief Metadata component - * + * * This class represents the Metadata component. It stores the name, tag, parent and children * of a GameObject. */ diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index 8265ba5..40c6bf1 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -11,7 +11,7 @@ namespace crepe { /** * \brief Rigidbody class - * + * * This class is used by the physics sytem and collision system. It configures how to system * interact with the gameobject for movement and collisions. */ @@ -19,7 +19,7 @@ class Rigidbody : public Component { public: /** * \brief BodyType enum - * + * * This enum provides three bodytypes the physics sytem and collision system use. */ enum class BodyType { @@ -32,7 +32,7 @@ public: }; /** * \brief PhysicsConstraints to constrain movement - * + * * This struct configures the movement constraint for this object. If a constraint is enabled * the systems will not move the object. */ @@ -46,9 +46,9 @@ public: }; public: - /** + /** * \brief struct for Rigidbody data - * + * * This struct holds the data for the Rigidbody. */ struct Data { @@ -59,7 +59,7 @@ public: * * The `gravity_scale` controls how much gravity affects the object. It is a multiplier applied to the default * gravity force, allowing for fine-grained control over how the object responds to gravity. - * + * */ float gravity_scale = 0; @@ -108,7 +108,7 @@ public: * The `PhysicsConstraints` struct defines the constraints that restrict an object's movement * in certain directions or prevent rotation. These constraints effect only the physics system * to prevent the object from moving or rotating in specified ways. - * + * */ PhysicsConstraints constraints; @@ -128,7 +128,7 @@ public: * The `offset` defines a positional shift applied to all colliders associated with the object, relative to the object's * transform position. This allows for the colliders to be placed at a different position than the object's actual * position, without modifying the object's transform itself. - * + * */ vec2 offset; @@ -136,14 +136,14 @@ public: * \brief Defines the collision layers of a GameObject. * * The `collision_layers` specifies the layers that the GameObject will collide with. - * Each element represents a layer ID, and the GameObject will only detect + * Each element represents a layer ID, and the GameObject will only detect * collisions with other GameObjects that belong to these layers. */ std::set<int> collision_layers; }; public: - /** + /** * \param game_object_id id of the gameobject the rigibody is added to. * \param data struct to configure the rigidbody. */ @@ -152,15 +152,15 @@ public: Data data; public: - /** + /** * \brief add a linear force to the Rigidbody. - * + * * \param force Vector2 that is added to the linear force. */ void add_force_linear(const vec2 & force); - /** + /** * \brief add a angular force to the Rigidbody. - * + * * \param force Vector2 that is added to the angular force. */ void add_force_angular(float force); diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 9f1e8ce..ba9bb76 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -12,7 +12,7 @@ class ComponentManager; /** * \brief Represents a Scene - * + * * This class represents a Scene. The Scene class is only used as an interface for the game * programmer. */ @@ -41,7 +41,7 @@ public: protected: /** * \name Late references - * + * * These references are set by SceneManager immediately after calling the constructor of Scene. * * \note Scene must have a constructor without arguments so the game programmer doesn't need to diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index d1be1dc..d99ab0e 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -20,7 +20,7 @@ class ComponentManager; * This class is used as a base class for user-defined scripts that can be added to game * objects using the \c BehaviorScript component. * - * \info Additional *events* (like Unity's OnDisable and OnEnable) should be implemented as + * \note Additional *events* (like Unity's OnDisable and OnEnable) should be implemented as * member or lambda methods in derivative user script classes and registered in \c init(). * * \warning Concrete scripts are allowed do create a custom constructor, but the utility diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index ea8104c..dbf41e4 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -31,11 +31,10 @@ public: //! Sprite data that does not have to be set in the constructor struct Data { /** - * \color tint of the sprite + * \brief Sprite tint (multiplied) * - * the default value is white because of the color multiplier. - * this means that the orginal image will be shown. if color is BLACK for example - * then it turns the image black because of the Color channels being 0. + * The sprite texture's pixels are multiplied by this color before being displayed + * (including alpha channel for transparency). */ Color color = Color::WHITE; @@ -49,15 +48,15 @@ public: const int order_in_layer = 0; /** - * \size width and height of the sprite in game units - * - * - if height is filled in and not width it will multiply width by aspect_ratio. - * - if width is filled in and not height it will multiply height by aspect_ratio. - * - if neither is filled it will not show sprite because size will be zero - * - if both are filled will it use the width and height without making sure the aspect_ratio - * is correct - */ - vec2 size; + * \brief width and height of the sprite in game units + * + * - if exclusively width is specified, the height is calculated using the texture's aspect + * ratio + * - if exclusively height is specified, the width is calculated using the texture's aspect + * ratio + * - if both are specified the texture is streched to fit the specified size + */ + vec2 size = {0, 0}; //! independent sprite angle. rotating clockwise direction in degrees float angle_offset = 0; @@ -71,7 +70,6 @@ public: public: /** - * \brief Constructs a Sprite with specified parameters. * \param game_id Unique identifier for the game object this sprite belongs to. * \param texture asset of the image * \param ctx all the sprite data @@ -86,12 +84,12 @@ public: private: /** - * \aspect_ratio ratio of the img - * - * - This will multiply one of \c size variable if it is 0. - * - Will be adjusted if \c Animator component is added to an GameObject - * that is why this value cannot be const. - */ + * \brief ratio of the img + * + * - This will multiply one of \c size variable if it is 0. + * - Will be adjusted if \c Animator component is added to an GameObject that is why this + * value cannot be const. + */ float aspect_ratio; //! Reads the mask of sprite diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index 3ef0fb5..7ee6d65 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -7,7 +7,7 @@ namespace crepe { /** * \brief Transform component - * + * * This class represents the Transform component. It stores the position, rotation and scale of * a GameObject. */ |