Skip to content

Commit

Permalink
Beginning Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
BSBussell committed Mar 10, 2023
1 parent 07fb5ee commit 5d135ed
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 12 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ target_compile_options(
-Wall
-Wextra
-std=c++17
-Ofast
)

target_include_directories( BML PUBLIC inc )
Expand Down
22 changes: 22 additions & 0 deletions inc/BML.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 18 additions & 2 deletions inc/bRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,38 @@
#include <SDL2/SDL.h>
#include <cstdint>

/**
* @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;
Uint32 y;
Uint32 width;
Uint32 height;

// Easy conversion to SDL_Rect
/**
* @brief Converts to SDL_Rect
*
* @return SDL_Rect
*/
operator SDL_Rect() const;

};
Expand Down
56 changes: 52 additions & 4 deletions inc/bSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bRect> 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<std::string, bAnimation> 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
64 changes: 58 additions & 6 deletions inc/bTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<std::string, SDL_Texture*> _loaded_textures;

/**
* @brief Reference counter for textures
*
*/
std::unordered_map<SDL_Texture*, Uint8> _refs;

};
Expand Down
1 change: 1 addition & 0 deletions src/bRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5d135ed

Please sign in to comment.