174 lines
3.4 KiB
C
174 lines
3.4 KiB
C
enum {
|
|
MAX_NAME_LENGTH = 64,
|
|
MAX_MESH_COUNT = 128,
|
|
MAX_MATERIAL_COUNT = 128,
|
|
MAX_MUSIC_COUNT = 128,
|
|
MAX_SFX_COUNT = 128
|
|
};
|
|
|
|
typedef uint32_t handle_t;
|
|
|
|
typedef struct mesh {
|
|
char name[MAX_NAME_LENGTH];
|
|
GLuint vao, vbo, ebo;
|
|
uint16_t index_count;
|
|
handle_t material;
|
|
} mesh_t;
|
|
|
|
typedef struct material {
|
|
char name[MAX_NAME_LENGTH];
|
|
GLuint texture;
|
|
} material_t;
|
|
|
|
typedef struct wav {
|
|
char name[MAX_NAME_LENGTH];
|
|
uint32_t byte_count;
|
|
uint32_t sample_rate;
|
|
float volume;
|
|
float* data;
|
|
} wav_t;
|
|
|
|
typedef struct asset_mgr {
|
|
struct {
|
|
hash_t hash;
|
|
size_t count;
|
|
mesh_t data[MAX_MESH_COUNT];
|
|
} meshes;
|
|
|
|
struct {
|
|
hash_t hash;
|
|
size_t count;
|
|
material_t data[MAX_MATERIAL_COUNT];
|
|
} materials;
|
|
|
|
struct {
|
|
hash_t hash;
|
|
size_t count;
|
|
wav_t data[MAX_MUSIC_COUNT];
|
|
} music;
|
|
|
|
struct {
|
|
hash_t hash;
|
|
size_t count;
|
|
wav_t data[MAX_SFX_COUNT];
|
|
} sfx;
|
|
} asset_mgr_t;
|
|
|
|
void
|
|
asset_mgr_startup(void)
|
|
{
|
|
g_asset_mgr->meshes.hash = hash_create(NEAREST_PRIME_256, sizeof(handle_t));
|
|
g_asset_mgr->materials.hash = hash_create(NEAREST_PRIME_256, sizeof(handle_t));
|
|
g_asset_mgr->music.hash = hash_create(NEAREST_PRIME_256, sizeof(handle_t));
|
|
g_asset_mgr->sfx.hash = hash_create(NEAREST_PRIME_256, sizeof(handle_t));
|
|
}
|
|
|
|
void
|
|
insert_mesh(mesh_t mesh)
|
|
{
|
|
handle_t handle = g_asset_mgr->meshes.count;
|
|
|
|
g_asset_mgr->meshes.data[handle] = mesh;
|
|
hash_add(&g_asset_mgr->meshes.hash, HASH_CSTR(mesh.name), &handle);
|
|
|
|
g_asset_mgr->meshes.count++;
|
|
}
|
|
|
|
void
|
|
insert_material(material_t material)
|
|
{
|
|
handle_t handle = g_asset_mgr->materials.count;
|
|
|
|
g_asset_mgr->materials.data[handle] = material;
|
|
hash_add(&g_asset_mgr->materials.hash, HASH_CSTR(material.name), &handle);
|
|
|
|
g_asset_mgr->materials.count++;
|
|
}
|
|
|
|
void
|
|
insert_music(wav_t music)
|
|
{
|
|
handle_t handle = g_asset_mgr->music.count;
|
|
|
|
g_asset_mgr->music.data[handle] = music;
|
|
hash_add(&g_asset_mgr->music.hash, HASH_CSTR(music.name), &handle);
|
|
|
|
g_asset_mgr->music.count++;
|
|
}
|
|
|
|
void
|
|
insert_sfx(wav_t sfx)
|
|
{
|
|
handle_t handle = g_asset_mgr->sfx.count;
|
|
|
|
g_asset_mgr->sfx.data[handle] = sfx;
|
|
hash_add(&g_asset_mgr->sfx.hash, HASH_CSTR(sfx.name), &handle);
|
|
|
|
g_asset_mgr->sfx.count++;
|
|
}
|
|
|
|
mesh_t*
|
|
get_mesh_by_name(const char* name)
|
|
{
|
|
handle_t* handle = (handle_t*)hash_get(g_asset_mgr->meshes.hash, HASH_CSTR(name));
|
|
|
|
mesh_t* result = &g_asset_mgr->meshes.data[*handle];
|
|
return result;
|
|
}
|
|
|
|
mesh_t*
|
|
get_mesh_by_handle(handle_t handle)
|
|
{
|
|
mesh_t* result = &g_asset_mgr->meshes.data[handle];
|
|
return result;
|
|
}
|
|
|
|
material_t*
|
|
get_material_by_name(const char* name)
|
|
{
|
|
handle_t* handle = (handle_t*)hash_get(g_asset_mgr->materials.hash, HASH_CSTR(name));
|
|
|
|
material_t* result = &g_asset_mgr->materials.data[*handle];
|
|
return result;
|
|
}
|
|
|
|
material_t*
|
|
get_material_by_handle(handle_t handle)
|
|
{
|
|
material_t* result = &g_asset_mgr->materials.data[handle];
|
|
return result;
|
|
}
|
|
|
|
wav_t*
|
|
get_music_by_name(const char* name)
|
|
{
|
|
handle_t* handle = (handle_t*)hash_get(g_asset_mgr->music.hash, HASH_CSTR(name));
|
|
|
|
wav_t* result = &g_asset_mgr->music.data[*handle];
|
|
return result;
|
|
}
|
|
|
|
wav_t*
|
|
get_music_by_handle(handle_t handle)
|
|
{
|
|
wav_t* result = &g_asset_mgr->music.data[handle];
|
|
return result;
|
|
}
|
|
|
|
wav_t*
|
|
get_sfx_by_name(const char* name)
|
|
{
|
|
handle_t* handle = (handle_t*)hash_get(g_asset_mgr->sfx.hash, HASH_CSTR(name));
|
|
|
|
wav_t* result = &g_asset_mgr->sfx.data[*handle];
|
|
return result;
|
|
}
|
|
|
|
wav_t*
|
|
get_sfx_by_handle(handle_t handle)
|
|
{
|
|
wav_t* result = &g_asset_mgr->sfx.data[handle];
|
|
return result;
|
|
}
|
|
|