Table of Contents
- Purpose
- Interface
- SDL_Texture* get_texture(const char* file)
- SDL_Texture* load_texture(const char* file)
- TTF_Font* get_font(const char* file, int size)
- TTF_Font* load_font(const char* file, int size)
- void add_arbitrary_asset_by_name(void* memory, deleter_fn deleter, const char* name)
- void add_arbitrary_asset(void* memory, deleter_fn deleter)
- resource_t* get_asset(const char* file)
- resourcetype_t asset_type(const char* name)
- int asset_exists(const char* name)
- int delete_by_name(const char* name)
- void clean_assets()
- Definitions
Purpose
Manages resources loaded from disk. As well as any transient data that end programmers submit to it. Generally resources submitted to the assets module should be left as they are.
Interface
SDL_Texture* get_texture(const char* file)
Searches the asset database for a previously loaded instance of file
.
If file
is loaded, get_texture
returns the found instance. If the file is not yet loaded get_texture
will call load_texture
and return the result.
returns: found or loaded texture or NULL
if the file cannot load.
SDL_Texture* load_texture(const char* file)
Load a texture from a file and store it in the asset database.
returns: loaded texture or NULL
if an error occurred.
TTF_Font* get_font(const char* file, int size)
Searches the asset database for a previously loaded instance of file
.
If file
is loaded, get_font
will return the found instance, if not, get_font
will call load_font
and return the result.
returns: found or loaded font, or NULL
if the file cannot load.
TTF_Font* load_font(const char* file, int size)
Load a font and store it in the asset database.
returns: loaded font or NULL
if an error occurred.
void add_arbitrary_asset_by_name(void* memory, deleter_fn deleter, const char* name)
Submit arbitrary memory to be managed by the asset database and assign it a asset name.
void add_arbitrary_asset(void* memory, deleter_fn deleter)
Submit arbitrary memory to be managed by the asset database.
NOTE: Memory submitted by this function is NOT retrievable, this function requires that you keep a pointer separately.
If you need to retrieve your pointer through the asset database use add_arbitrary_asset_by_name
instead
resource_t* get_asset(const char* file)
Get the raw resource_t
representation of a file.
returns: raw resource_t
representing file
, or NULL
if file
is not loaded
resourcetype_t asset_type(const char* name)
Get the type of resource an asset is loaded under.
returns: type of a loaded asset, or RESOURCETYPE_MIN if the resource does not exist.
int asset_exists(const char* name)
Check if the asset database contains an asset by name
.
returns: 1
if name
is loaded, or 0
if name
is not loaded.
int delete_by_name(const char* name)
Free and delete an asset from the asset database.
returns: 1
if the asset was freed and deleted, or 0
if the file was not loaded in the first place.
void clean_assets()
Free and delete all assets in the asset database.
Definitions
deleter_fn
void(*deleter_fn)(void* target)
Used by manually submitted asset memory to delete the objects submitted.
Will be used by calling them with the submitted memory
pointer as the first argument.
resourcetype_t
The type of resource managed by any given resource_t
.
enum resourcetype_t {
RESOURCETYPE_MIN,
RESOURCETYPE_TEXTURE,
RESOURCETYPE_FONT,
RESOURCETYPE_ARBITRARY,
RESOURCETYPE_MAX
}
resource_t
FOR MOST SITUATIONS: DO NOT USE. There are valid reasons why you might want to directly manipulate an instance of resource_t
. But in most cases, you'd rather access the managed asset. There are get_*
functions for each resourcetype_t
.
struct resource_t {
resourcetype_t type;
uintptr_t hash;
char* name;
union {
SDL_Texture* texture;
struct {
int size;
TTF_Font* font;
} font;
struct {
void* memory;
deleter_fn deleter;
} arbitrary_type;
};
}