basic-game-framework/src/corelib/assets.h

55 lines
1.2 KiB
C
Raw Normal View History

2023-04-06 13:20:08 +00:00
#ifndef _assets_h
#define _assets_h
#include <SDL2/SDL_ttf.h>
2023-04-06 13:20:08 +00:00
#ifdef __cplusplus
extern "C" {
#endif
#include "stddef.h"
#include "SDL2/SDL.h"
typedef enum resourcetype_t {
RESOURCETYPE_MIN,
RESOURCETYPE_TEXTURE,
RESOURCETYPE_FONT,
RESOURCETYPE_ARBITRARY,
2023-04-06 13:20:08 +00:00
RESOURCETYPE_MAX
} resourcetype_t;
typedef void(*deleter_t)(void* target);
2023-04-06 13:20:08 +00:00
typedef struct resource_t {
resourcetype_t type;
uintptr_t hash;
char* name;
union {
SDL_Texture* texture;
TTF_Font* font;
struct {
void* memory;
deleter_t deleter;
} arbitrary_type;
2023-04-06 13:20:08 +00:00
};
} 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);
2023-04-06 13:20:08 +00:00
extern SDL_Texture* load_texture(const char* file);
extern TTF_Font* load_font(const char* file, int size);
2023-04-06 13:20:08 +00:00
extern SDL_Texture* get_texture(const char* file);
extern TTF_Font* get_font(const char* file, int size);
2023-04-06 13:20:08 +00:00
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);
2023-04-06 13:20:08 +00:00
extern void clean_assets();
#ifdef __cplusplus
}
#endif
#endif /* _assets_h */