Files
punchie-engine/include/AssetManager.h
T
2022-10-02 02:16:28 +01:00

64 lines
1.5 KiB
C

#ifndef ASSET_MANAGER_H
#define ASSET_MANAGER_H
#include "Renderer.h"
#include "SDL_mixer.h"
#include "SDL_render.h"
#include "SDL_ttf.h"
#include "reusable_ids.h"
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif // !__cplusplus
typedef enum {
ASSET_TYPE_IMAGE,
ASSET_TYPE_AUDIO_FX,
ASSET_TYPE_MUSIC,
ASSET_TYPE_FONT,
ASSET_TYPE_COUNT
} AssetType;
typedef struct asset_manager AssetManager;
/**
* Attempts to allocate an AssetManager object on the heap.
*
* Returns the pointer to the object when it succeeds, or NULL if it fails.
*/
AssetManager *create_asset_manager();
/**
* Attempts to load an asset to the manager from a file path.
*
* Returns the AssetID on success or an INVALID_ID in the case of failure.
*/
AssetID load_asset_to_manager(AssetManager *am, const char *path,
AssetType type, Renderer *renderer);
/**
* Removes an asset from the manager using its ID.
*
* Does nothing if the ID is not valid.
*/
void remove_asset_from_manager(AssetManager *am, AssetID *id_ptr);
SDL_Texture *get_texture(AssetManager *am, AssetID id);
TTF_Font *get_font(AssetManager *am, AssetID id);
Mix_Chunk *get_audio_chunk(AssetManager *am, AssetID id);
Mix_Music *get_music(AssetManager *am, AssetID id);
/**
* Frees the memory allocated to the AssetManager object and performs the
* necessary cleanup to free all memory that were allocated to the loaded
* assets.
*/
void destroy_asset_manager(AssetManager **am);
#ifdef __cplusplus
}
#endif // !__cplusplus
#endif // !ASSET_MANAGER_H