2023-04-06 13:20:08 +00:00
|
|
|
#ifndef _assets_h
|
|
|
|
#define _assets_h
|
|
|
|
|
2023-04-20 08:10:27 +00:00
|
|
|
#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,
|
2023-04-20 08:10:27 +00:00
|
|
|
RESOURCETYPE_FONT,
|
|
|
|
RESOURCETYPE_ARBITRARY,
|
2023-04-06 13:20:08 +00:00
|
|
|
RESOURCETYPE_MAX
|
|
|
|
} resourcetype_t;
|
|
|
|
|
2023-07-15 22:38:06 +00:00
|
|
|
typedef void(*deleter_fn)(void* target);
|
2023-04-20 08:10:27 +00:00
|
|
|
|
2023-04-06 13:20:08 +00:00
|
|
|
typedef struct resource_t {
|
|
|
|
resourcetype_t type;
|
|
|
|
uintptr_t hash;
|
|
|
|
char* name;
|
|
|
|
union {
|
|
|
|
SDL_Texture* texture;
|
2023-04-20 22:25:05 +00:00
|
|
|
struct {
|
|
|
|
int size;
|
|
|
|
TTF_Font* font;
|
|
|
|
} font;
|
2023-04-20 08:10:27 +00:00
|
|
|
struct {
|
|
|
|
void* memory;
|
2023-07-15 22:38:06 +00:00
|
|
|
deleter_fn deleter;
|
2023-04-20 08:10:27 +00:00
|
|
|
} arbitrary_type;
|
2023-04-06 13:20:08 +00:00
|
|
|
};
|
|
|
|
} resource_t;
|
|
|
|
|
2023-07-15 22:38:06 +00:00
|
|
|
extern void add_arbitrary_asset(void* memory, deleter_fn deleter);
|
|
|
|
extern void add_arbitrary_asset_by_name(void* memory, deleter_fn deleter, const char* name);
|
2023-04-06 13:20:08 +00:00
|
|
|
extern SDL_Texture* load_texture(const char* file);
|
2023-04-20 08:10:27 +00:00
|
|
|
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);
|
2023-04-20 08:10:27 +00:00
|
|
|
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);
|
|
|
|
|
2023-04-20 20:55:05 +00:00
|
|
|
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 */
|