diff --git a/CMakeLists.txt b/CMakeLists.txt index 77f8845..efc7e7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ target_compile_options( -Wall -Wextra -std=c++17 + -Ofast ) target_include_directories( BML PUBLIC inc ) diff --git a/inc/BML.h b/inc/BML.h index 2416548..175db7b 100644 --- a/inc/BML.h +++ b/inc/BML.h @@ -17,10 +17,32 @@ #include "bWindow.h" #include "bSound.h" +/** + * @brief Initializes SDL + * + */ void BML_Init(); + +/** + * @brief Closes SDL + * + */ void BML_Close(); +/** + * @brief Gets the path to the file + * + * @param const char* relative path to the file + * @return std::string absolute path to the file + */ std::string BML_GetPath(const char* path); + +/** + * @brief Gets the path to the file + * + * @param std::string path relative path to the file + * @return std::string Absolute path to the file + */ std::string BML_GetPath(std::string path); #endif diff --git a/inc/bRect.h b/inc/bRect.h index f80b9b5..fa7154a 100644 --- a/inc/bRect.h +++ b/inc/bRect.h @@ -13,14 +13,26 @@ #include #include + /** + * @brief A struct for holding a 2D point + * + */ struct bPoint { Uint32 x, y; - // Easy conversion to SDL_Point + /** + * @brief Converts to SDL_Point + * + * @return SDL_Point + */ operator SDL_Point() const; }; +/** + * @brief A struct for holding a 2D rectangle + * + */ struct bRect { Uint32 x; @@ -28,7 +40,11 @@ struct bRect { Uint32 width; Uint32 height; - // Easy conversion to SDL_Rect + /** + * @brief Converts to SDL_Rect + * + * @return SDL_Rect + */ operator SDL_Rect() const; }; diff --git a/inc/bSheet.h b/inc/bSheet.h index 5e028ea..716b61f 100644 --- a/inc/bSheet.h +++ b/inc/bSheet.h @@ -41,34 +41,82 @@ struct bAnimation { // @brief Data structure used for storing spritesheet info struct bSheet { + // @brief The path to the spritesheet std::string imagePath; + + // @brief The bTexture of the spritesheet bTexture sourceTexture; + // @brief Whether or not the sheet is animated bool animated = false; + // @brief The total width of the source texture Uint32 totalWidth; + + // @brief The total height of the source texture Uint32 totalHeight; + // @brief The total amount of sprites in the sheet Uint16 totalSprites; - Uint16 currentSprite = 0; + + // @brief The current sprite being displayed + uint16_t currentSprite = 0; + + // @brief The rectangles for each sprite std::vector sprites; - // Maybe make this like a dictionary that can be added to or something + // @brief The current animation being played as a pointer bAnimation *currentAnimation = NULL; + + // @brief All the animations in the sheet, keyed on their name std::unordered_map animations; + /** + * @brief Starts the animation with the given key + * + * @param std::string the key to check the map for + * @return True if it found the key + * @return False if it didn't find the key + */ bool startAnimation(std::string key); - // PLEASE BEE IM BEGGING YOU DO NOT USE THIS!!! + /** + * @brief Starts the animation from the given pointer, don't use this + * + * @param animation + * @return true + * @return false + */ bool startAnimation(bAnimation *animation); + /** + * @brief Updates the animation, used internally + * + * @return true + * @return false + */ bool updateAnimation(); + + /** + * @brief Stops the animation + * + * @return true + * @return false + */ bool stopAnimation(); }; -//void writeSheetToBin(const char* filePath, bSheet data); + +/** + * @brief Reads a spritesheet from a Aseprite JSON file + * + * @param filePath + * @param data + * @return true + * @return false + */ bool readSheetFromJSON(const char *filePath, bSheet &data); #endif diff --git a/inc/bTexture.h b/inc/bTexture.h index 2a8a730..d0a93c6 100644 --- a/inc/bTexture.h +++ b/inc/bTexture.h @@ -15,6 +15,8 @@ #include "bRect.h" +// TODO: Implement texture freeing and destructer for that + // @brief Data structure used for storing texture info struct bTexture { @@ -26,34 +28,84 @@ struct bTexture { }; -// @brief Class for mananging usage of textures +/** + * @brief A class for managing textures in a cache + * + */ class bTextureManager { public: + /** + * @brief Making a bTextureManager tied to the renderer + * + * @param SDL_Renderer* renderer + */ bTextureManager(SDL_Renderer *renderer); + + /** + * @brief Destroy the b Texture Manager::b Texture Manager object by clearing the cache + * + */ ~bTextureManager(); - // Load the texture either by creating a new one or grabbing it from the cache + /** + * @brief Load the texture either by creating a new one or grabbing it from the cache + * + * @param const_char* the path to the texture + * @param bRect the dimensions of the texture + */ bTexture loadTexture(const char *path, bRect dim); - // Unloads the texture, if it's not being used by anything else + /** + * @brief Unload the texture by decreasing the ref count and deleting it if it's at zero + * + * @param bTexture the texture to unload + */ void unloadTexture(bTexture texture); - // Does not delete bTextures, User still has to do that on ther own + /** + * @brief Clear the cache of textures + * + */ void clearCache(); - // Rendering the Texture either using a rect or a point + /** + * @brief Render the texture to the screen + * + * @param bTexture the texture to render + * @param bRect the destination rectangle + */ void renderTexture(bTexture &texture, bRect dest); + + /** + * @brief Render the texture to the screen + * + * @param bTexture the texture to render + * @param bPoint the destination point + */ void renderTexture(bTexture &texture, bPoint dest); private: + /** + * @brief The renderer that the textures are tied to + * + */ SDL_Renderer *_sdl_renderer; - // Cache + + /** + * @brief Cache of allocated textures + * + */ std::unordered_map _loaded_textures; + + /** + * @brief Reference counter for textures + * + */ std::unordered_map _refs; }; diff --git a/src/bRenderer.cpp b/src/bRenderer.cpp index 7a7a431..b46e768 100644 --- a/src/bRenderer.cpp +++ b/src/bRenderer.cpp @@ -9,6 +9,7 @@ bRenderer::bRenderer(SDL_Window *window, Uint32 _render_flags) { // Grabs the SDL_Window() _context = window; + _bkg_color = {255, 255, 255, 255}; _sdl_renderer = SDL_CreateRenderer(_context, -1, _render_flags);