diff --git a/src/corelib/assets.c b/src/corelib/assets.c index 1f41c21..ed853c1 100644 --- a/src/corelib/assets.c +++ b/src/corelib/assets.c @@ -6,6 +6,8 @@ #define NUM_ASSETS 256 +void _remove_asset(resource_t*); + resource_t g_assets[NUM_ASSETS]; resource_t* g_assets_endptr = g_assets; @@ -94,6 +96,26 @@ void _delete_referenced_asset(resource_t* res) { } } +int asset_exists(const char* name) { + return get_asset(name) != NULL; +} + +resourcetype_t asset_type(const char* name) { + resource_t* r = get_asset(name); + if(r != NULL) { + return r->type; + } else { + return RESOURCETYPE_MIN; + } +} + +int delete_by_name(const char* name) { + resource_t* r = get_asset(name); + if(r == NULL) return 0; + _remove_asset(r); + return 1; +} + void clean_assets() { for(resource_t* res = g_assets; res != g_assets_endptr; ++res) { _delete_referenced_asset(res); diff --git a/src/corelib/assets.h b/src/corelib/assets.h index c84c7b6..ee4983c 100644 --- a/src/corelib/assets.h +++ b/src/corelib/assets.h @@ -34,12 +34,17 @@ typedef struct resource_t { } resource_t; extern void add_arbitrary_asset(void* memory, deleter_t deleter); +extern void add_arbitrary_asset_by_name(void* memory, deleter_t deleter, const char* name); extern SDL_Texture* load_texture(const char* file); extern TTF_Font* load_font(const char* file, int size); extern SDL_Texture* get_texture(const char* file); extern TTF_Font* get_font(const char* file, int size); extern resource_t* get_asset(const char* file); +extern resourcetype_t asset_type(const char* name); +extern int asset_exists(const char* name); +extern int delete_by_name(const char* name); + extern void clean_assets(); #ifdef __cplusplus