From 7dbcfe876cdd9a084d55be0c687e0642a55a8839 Mon Sep 17 00:00:00 2001 From: freezarite Date: Sat, 30 Nov 2024 15:35:03 +0100 Subject: [PATCH] Added some doxygen documentation to TextureEnumBase.h and TextureManager.h --- include/TextureEnumBase.h | 15 +++++++++++ include/TextureManager.h | 54 +++++++++++++++++++++++++++++++++++++++ src/TextureManager.cpp | 1 - 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/include/TextureEnumBase.h b/include/TextureEnumBase.h index 75c3573..e9e5d9a 100644 --- a/include/TextureEnumBase.h +++ b/include/TextureEnumBase.h @@ -1,3 +1,18 @@ +/*! + * \file Textures.h + * \brief Forward declaration of the \c Textures enum class. + * + * This file contains a forward declaration of the \c Textures enum class, which is used as a base + * class for texture identifiers in the engine. It allows developers to define their own set of texture + * types in their own implementation, providing flexibility in texture management within the engine. + * + * \details + * The \c Textures enum class is intended to be implemented by the developer within their own scope. + * This allows for customized texture entries to be defined based on the specific needs of the project. + * The base declaration ensures that the enum class can be referenced and used consistently throughout + * the engine while leaving the details of the texture identifiers up to the implementation. + */ + #pragma once enum class Textures; \ No newline at end of file diff --git a/include/TextureManager.h b/include/TextureManager.h index 5e5cd02..8789a2c 100644 --- a/include/TextureManager.h +++ b/include/TextureManager.h @@ -8,6 +8,22 @@ #include #include "TextureEnumBase.h" +/*! + * \class TextureManager + * \brief A manager for loading, caching, and drawing textures. + * + * The `TextureManager` class is responsible for handling texture loading, caching, + * and rendering in the engine. It provides functions to add, load, and draw textures + * from files, as well as manage sprite sheets. + * + * It uses two caches: one for regular textures (`texture_cache`) and one for + * map tile textures (`mapTile_texture_cache`). This allows for efficient texture reuse + * and management across different parts of the game. + * + * \note Textures are identified by an enum class `Textures` which is user-defined. + * Developers are expected to define the texture types in their own implementation. + */ + class TextureManager { public: @@ -21,12 +37,50 @@ class TextureManager } } + /*! + * \brief Adds a single texture to the cache. + * \param texture The texture identifier. + * \param filePath The file path to the texture file. + * + * This function loads the texture from the specified file and stores it in + * the `texture_cache`. If loading the texture fails, an exception is thrown. + */ void addSingleTexture(Textures texture, const char* filePath); + + /*! + * \brief Adds multiple textures to the cache. + * \param textures A map of texture identifiers and corresponding file paths. + * + * This function iterates over the provided map of textures and loads each + * texture using `addSingleTexture`. It allows developers to add several + * textures at once. + */ void addTextures(const std::map& textures); + + /*! + * \brief Loads a texture from the cache. + * \param texture The texture identifier. + * \return A pointer to the `SDL_Texture` if found, or `nullptr` if not found. + * + * This function looks up a texture in the `texture_cache` and returns the + * corresponding `SDL_Texture*`. If the texture is not found, it logs an error + * message and returns `nullptr`. + */ SDL_Texture* loadTexture(Textures texture); static std::vector splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet); static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false); + /*! + * \brief Loads a map tile texture from the file system and caches it. + * \param path The file path to the texture. + * \return A pointer to the `SDL_Texture` representing the map tile. + * + * This function checks if the map tile texture is already cached. If not, it + * loads the texture from the file system and stores it in the cache. + * + * If loading fails, an exception is thrown with a descriptive error message. + * /todo should not be usable for the developer and only be accessed by the map class + */ SDL_Texture* loadMapTileTexture(const char* path); private: diff --git a/src/TextureManager.cpp b/src/TextureManager.cpp index ff8e2fd..3b81ee3 100644 --- a/src/TextureManager.cpp +++ b/src/TextureManager.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "GameInternal.h"