Documented TextureHandler.h

merge-requests/1/merge
marouault 4 years ago
parent e11fbb01b4
commit db7d1e6c82

@ -1,3 +1,10 @@
/**
* \file TextureHandler.h
* \brief Define a structure, an enum and associated functions to handle textures loading, accessing and freeing
* \author Martin Rouault
* \date 16/12/2021
*/
#ifndef TEXTURE_HANDLER_INCLUDED #ifndef TEXTURE_HANDLER_INCLUDED
#define TEXTURE_HANDLER_INCLUDED #define TEXTURE_HANDLER_INCLUDED
@ -5,28 +12,52 @@
#include <stdio.h> #include <stdio.h>
#include "engine/TextureLoader.h" #include "engine/TextureLoader.h"
// List here the different texture to handle
// In the enum
// Island become TEXTURE_Island
// In file
// Island become Island.png
#define MACRO_FOR_ALL_TEXTURES(M) \ #define MACRO_FOR_ALL_TEXTURES(M) \
M(Island) \ M(Island) \
M(Bridge) \ M(Bridge) \
M(Piece) \ M(Piece) \
M(Water) M(Water)
#define MACRO_IDENTITY_COMMA(E) TEXTURE_##E, // Allow the generation of enum
#define MACRO_TEXTURE_ENUM_GEN(E) TEXTURE_##E,
/**
* \enum EnumTextures
* \brief Indexes for textures in TextureHandler
*/
typedef enum typedef enum
{ {
MACRO_FOR_ALL_TEXTURES(MACRO_IDENTITY_COMMA) MACRO_FOR_ALL_TEXTURES(MACRO_TEXTURE_ENUM_GEN)
NB_TEXTURES_DEFINED NB_TEXTURES_DEFINED ///< Contains the number of textures
} EnumTextures; } EnumTextures;
/**
* \struct TextureHandler
* \brief A struct to handle all textures
*/
typedef struct typedef struct
{ {
SDL_Texture* textures[NB_TEXTURES_DEFINED]; SDL_Texture* textures[NB_TEXTURES_DEFINED]; ///< An array of texture (indexed with EnumTextures)
} TextureHandler; } TextureHandler;
/**
* \brief Create a TextureHandler and load each texture defined in MACRO_FOR_ALL_TEXTURES in it
* \param renderer The renderer which is passed to texture when they are created
* \return ** TextureHandler filled with textures
*/
TextureHandler newTextureHandler(SDL_Renderer* renderer); TextureHandler newTextureHandler(SDL_Renderer* renderer);
/**
* @brief Free every textures in the TextureHandler
* @param textureHandler The texturehandler containing textures to free (textures array will be filled with NULL after calling this function)
*/
void freeTextureHandler(TextureHandler* textureHandler); void freeTextureHandler(TextureHandler* textureHandler);
#endif // TEXTURE_HANDLER_INCLUDED #endif // TEXTURE_HANDLER_INCLUDED
Loading…
Cancel
Save