2021-01-18 14:46:11 +00:00
|
|
|
#include "assets.h"
|
2021-05-12 17:26:41 +00:00
|
|
|
#include "raylib.h"
|
2021-05-12 17:38:11 +00:00
|
|
|
#include "gen/texgen.h"
|
2021-01-18 14:46:11 +00:00
|
|
|
|
2021-05-12 17:26:41 +00:00
|
|
|
#define ASSETS_COUNT (sizeof(assets)/sizeof(asset))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
asset_id id;
|
|
|
|
asset_kind kind;
|
|
|
|
|
|
|
|
union {
|
|
|
|
Texture2D tex;
|
|
|
|
Sound snd;
|
|
|
|
};
|
|
|
|
|
|
|
|
// NOTE(zaklaus): metadata
|
|
|
|
} asset;
|
|
|
|
|
|
|
|
#include "assets_list.c"
|
|
|
|
|
|
|
|
int32_t assets_setup(void) {
|
|
|
|
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
|
|
|
|
asset *b = &assets[i];
|
|
|
|
|
|
|
|
switch (b->kind) {
|
|
|
|
case AKIND_TEXTURE: {
|
2021-05-12 17:38:11 +00:00
|
|
|
b->tex = texgen_build_sprite(b->id);
|
2021-05-12 17:26:41 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case AKIND_SOUND: {
|
|
|
|
// TODO(zaklaus): soundgen
|
|
|
|
}break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
// TODO(zaklaus): assert
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void assets_destroy(void) {
|
|
|
|
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
|
|
|
|
switch (assets[i].kind) {
|
|
|
|
case AKIND_TEXTURE: {
|
|
|
|
UnloadTexture(assets[i].tex);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case AKIND_SOUND: {
|
|
|
|
// TODO(zaklaus): soundgen
|
|
|
|
}break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
// TODO(zaklaus): assert
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t assets_find(asset_id id) {
|
|
|
|
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
|
|
|
|
if (assets[i].id == id)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return ASSET_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
asset_kind assets_get_kind(uint16_t id) {
|
|
|
|
return assets[id].kind;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *assets_get_snd(uint16_t id) {
|
|
|
|
return (void*)&assets[id].snd;;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *assets_get_tex(uint16_t id) {
|
|
|
|
return (void*)&assets[id].tex;
|
|
|
|
}
|