Add sound loading from rres file
Also, fixes mistake in raw data size when loading from RRES filescene_man
parent
4ede1abcc1
commit
d660b4e5a5
|
@ -93,8 +93,9 @@ Texture2D* add_texture_rres(Assets_t* assets, const char* name, const char* file
|
||||||
Texture2D* out_tex = NULL;
|
Texture2D* out_tex = NULL;
|
||||||
if (chunk.info.baseSize > 0)
|
if (chunk.info.baseSize > 0)
|
||||||
{
|
{
|
||||||
|
uint32_t sz = chunk.info.baseSize - sizeof(int) - (chunk.data.propCount*sizeof(int));
|
||||||
//Expect RAW type of png extension
|
//Expect RAW type of png extension
|
||||||
Image image = LoadImageFromMemory(GetFileExtension(filename), chunk.data.raw, chunk.info.baseSize);
|
Image image = LoadImageFromMemory(GetFileExtension(filename), chunk.data.raw, sz);
|
||||||
Texture2D tex = LoadTextureFromImage(image);
|
Texture2D tex = LoadTextureFromImage(image);
|
||||||
UnloadImage(image);
|
UnloadImage(image);
|
||||||
|
|
||||||
|
@ -108,6 +109,32 @@ Texture2D* add_texture_rres(Assets_t* assets, const char* name, const char* file
|
||||||
return out_tex;
|
return out_tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sound* add_sound_rres(Assets_t* assets, const char* name, const char* filename, const RresFileInfo_t* rres_file)
|
||||||
|
{
|
||||||
|
uint8_t snd_idx = n_loaded[2];
|
||||||
|
assert(snd_idx < MAX_SOUNDS);
|
||||||
|
|
||||||
|
int res_id = rresGetResourceId(rres_file->dir, filename);
|
||||||
|
rresResourceChunk chunk = rresLoadResourceChunk(rres_file->fname, res_id);
|
||||||
|
|
||||||
|
Sound* out_snd = NULL;
|
||||||
|
if (chunk.info.baseSize > 0)
|
||||||
|
{
|
||||||
|
uint32_t sz = chunk.info.baseSize - sizeof(int) - (chunk.data.propCount*sizeof(int));
|
||||||
|
Wave wave = LoadWaveFromMemory(GetFileExtension(filename), chunk.data.raw, sz);
|
||||||
|
Sound snd = LoadSoundFromWave(wave);
|
||||||
|
UnloadWave(wave);
|
||||||
|
|
||||||
|
sfx[snd_idx].sound = snd;
|
||||||
|
strncpy(sfx[snd_idx].name, name, MAX_NAME_LEN);
|
||||||
|
sc_map_put_s64(&assets->m_sounds, sfx[snd_idx].name, snd_idx);
|
||||||
|
n_loaded[2]++;
|
||||||
|
out_snd = &sfx[snd_idx].sound;
|
||||||
|
}
|
||||||
|
rresUnloadResourceChunk(chunk);
|
||||||
|
return out_snd;
|
||||||
|
}
|
||||||
|
|
||||||
Sprite_t* add_sprite(Assets_t* assets, const char* name, Texture2D* texture)
|
Sprite_t* add_sprite(Assets_t* assets, const char* name, Texture2D* texture)
|
||||||
{
|
{
|
||||||
uint8_t spr_idx = n_loaded[1];
|
uint8_t spr_idx = n_loaded[1];
|
||||||
|
@ -364,7 +391,8 @@ LevelPack_t* add_level_pack_rres(Assets_t* assets, const char* name, const char*
|
||||||
LevelPack_t* pack = NULL;
|
LevelPack_t* pack = NULL;
|
||||||
if (chunk.info.baseSize > 0 && strcmp(".lpk", (const char*)(chunk.data.props + 1)) == 0)
|
if (chunk.info.baseSize > 0 && strcmp(".lpk", (const char*)(chunk.data.props + 1)) == 0)
|
||||||
{
|
{
|
||||||
pack = add_level_pack_zst(assets, name, chunk.data.raw, chunk.info.baseSize);
|
uint32_t sz = chunk.info.baseSize - sizeof(int) - (chunk.data.propCount*sizeof(int));
|
||||||
|
pack = add_level_pack_zst(assets, name, chunk.data.raw, sz);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,7 @@ LevelPack_t* uncompress_level_pack(Assets_t* assets, const char* name, const cha
|
||||||
// Rres version
|
// Rres version
|
||||||
Texture2D* add_texture_rres(Assets_t* assets, const char* name, const char* filename, const RresFileInfo_t* rres_file);
|
Texture2D* add_texture_rres(Assets_t* assets, const char* name, const char* filename, const RresFileInfo_t* rres_file);
|
||||||
LevelPack_t* add_level_pack_rres(Assets_t* assets, const char* name, const char* filename, const RresFileInfo_t* rres_file);
|
LevelPack_t* add_level_pack_rres(Assets_t* assets, const char* name, const char* filename, const RresFileInfo_t* rres_file);
|
||||||
|
Sound* add_sound_rres(Assets_t* assets, const char* name, const char* filename, const RresFileInfo_t* rres_file);
|
||||||
|
|
||||||
Sprite_t* add_sprite(Assets_t* assets, const char* name, Texture2D* texture);
|
Sprite_t* add_sprite(Assets_t* assets, const char* name, Texture2D* texture);
|
||||||
EmitterConfig_t* add_emitter_conf(Assets_t* assets, const char* name);
|
EmitterConfig_t* add_emitter_conf(Assets_t* assets, const char* name);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
void init_engine(GameEngine_t* engine)
|
void init_engine(GameEngine_t* engine)
|
||||||
{
|
{
|
||||||
|
InitAudioDevice();
|
||||||
sc_queue_init(&engine->key_buffer);
|
sc_queue_init(&engine->key_buffer);
|
||||||
engine->sfx_list.n_sfx = N_SFX;
|
engine->sfx_list.n_sfx = N_SFX;
|
||||||
memset(engine->sfx_list.sfx, 0, engine->sfx_list.n_sfx * sizeof(SFX_t));
|
memset(engine->sfx_list.sfx, 0, engine->sfx_list.n_sfx * sizeof(SFX_t));
|
||||||
|
@ -15,6 +16,7 @@ void deinit_engine(GameEngine_t* engine)
|
||||||
term_assets(&engine->assets);
|
term_assets(&engine->assets);
|
||||||
free_memory_pools();
|
free_memory_pools();
|
||||||
sc_queue_term(&engine->key_buffer);
|
sc_queue_term(&engine->key_buffer);
|
||||||
|
CloseAudioDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_inputs(GameEngine_t* engine, Scene_t* scene)
|
void process_inputs(GameEngine_t* engine, Scene_t* scene)
|
||||||
|
|
7
main.c
7
main.c
|
@ -36,6 +36,12 @@ int main(void)
|
||||||
#endif
|
#endif
|
||||||
init_item_creation(&engine.assets);
|
init_item_creation(&engine.assets);
|
||||||
|
|
||||||
|
load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX);
|
||||||
|
load_sfx(&engine, "snd_land", PLAYER_LAND_SFX);
|
||||||
|
load_sfx(&engine, "snd_wdrop", WATER_IN_SFX);
|
||||||
|
load_sfx(&engine, "snd_bland", BOULDER_LAND_SFX);
|
||||||
|
load_sfx(&engine, "snd_bubble", BUBBLE_SFX);
|
||||||
|
|
||||||
LevelScene_t sandbox_scene;
|
LevelScene_t sandbox_scene;
|
||||||
sandbox_scene.scene.engine = &engine;
|
sandbox_scene.scene.engine = &engine;
|
||||||
init_sandbox_scene(&sandbox_scene);
|
init_sandbox_scene(&sandbox_scene);
|
||||||
|
@ -82,6 +88,7 @@ int main(void)
|
||||||
update_entity_manager(&curr_scene->ent_manager);
|
update_entity_manager(&curr_scene->ent_manager);
|
||||||
// This is needed to advance time delta
|
// This is needed to advance time delta
|
||||||
render_scene(curr_scene);
|
render_scene(curr_scene);
|
||||||
|
update_sfx_list(&engine);
|
||||||
|
|
||||||
if (curr_scene->state != SCENE_PLAYING)
|
if (curr_scene->state != SCENE_PLAYING)
|
||||||
{
|
{
|
||||||
|
|
|
@ -230,6 +230,7 @@ typedef enum AssetInfoType
|
||||||
TEXTURE_INFO,
|
TEXTURE_INFO,
|
||||||
SPRITE_INFO,
|
SPRITE_INFO,
|
||||||
LEVELPACK_INFO,
|
LEVELPACK_INFO,
|
||||||
|
SOUND_INFO,
|
||||||
INVALID_INFO
|
INVALID_INFO
|
||||||
}AssetInfoType_t;
|
}AssetInfoType_t;
|
||||||
|
|
||||||
|
@ -250,7 +251,7 @@ int main(void)
|
||||||
.reserved = 0 // <reserved>
|
.reserved = 0 // <reserved>
|
||||||
};
|
};
|
||||||
|
|
||||||
#define STARTING_CHUNKS 8
|
#define STARTING_CHUNKS 64
|
||||||
// Central Directory
|
// Central Directory
|
||||||
rresCentralDir central = {
|
rresCentralDir central = {
|
||||||
.count = 0,
|
.count = 0,
|
||||||
|
@ -307,6 +308,10 @@ int main(void)
|
||||||
{
|
{
|
||||||
info_type = LEVELPACK_INFO;
|
info_type = LEVELPACK_INFO;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(tmp, "Sound") == 0)
|
||||||
|
{
|
||||||
|
info_type = SOUND_INFO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info_type = INVALID_INFO;
|
info_type = INVALID_INFO;
|
||||||
|
@ -337,6 +342,21 @@ int main(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SOUND_INFO:
|
||||||
|
{
|
||||||
|
// ---- OGG Sound
|
||||||
|
if (
|
||||||
|
addRawData(
|
||||||
|
&header, info_str,
|
||||||
|
rresFile, ".ogg",
|
||||||
|
central.entries + central.count
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
central.count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case LEVELPACK_INFO:
|
case LEVELPACK_INFO:
|
||||||
{
|
{
|
||||||
// ---- Compressed Level Data
|
// ---- Compressed Level Data
|
||||||
|
|
|
@ -32,7 +32,6 @@ int main(void)
|
||||||
{
|
{
|
||||||
InitWindow(1280, 640, "raylib");
|
InitWindow(1280, 640, "raylib");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
InitAudioDevice();
|
|
||||||
init_engine(&engine);
|
init_engine(&engine);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -57,6 +57,21 @@ static bool parse_emitter_info(char* emitter_info_str, EmitterConfig_t* conf)
|
||||||
return data_count == 8;
|
return data_count == 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline AssetInfoType_t get_asset_type(const char* str)
|
||||||
|
{
|
||||||
|
if (strcmp(str, "Texture") == 0) return TEXTURE_INFO;
|
||||||
|
|
||||||
|
if (strcmp(str, "Sprite") == 0) return SPRITE_INFO;
|
||||||
|
|
||||||
|
if (strcmp(str, "Sound") == 0) return SOUND_INFO;
|
||||||
|
|
||||||
|
if (strcmp(str, "Emitter") == 0) return EMITTER_INFO;
|
||||||
|
|
||||||
|
if (strcmp(str, "LevelPack") == 0) return LEVELPACK_INFO;
|
||||||
|
|
||||||
|
return INVALID_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
bool load_from_rres(const char* file, Assets_t* assets)
|
bool load_from_rres(const char* file, Assets_t* assets)
|
||||||
{
|
{
|
||||||
RresFileInfo_t rres_file;
|
RresFileInfo_t rres_file;
|
||||||
|
@ -91,22 +106,7 @@ bool load_from_rres(const char* file, Assets_t* assets)
|
||||||
if (tmp[0] == '-')
|
if (tmp[0] == '-')
|
||||||
{
|
{
|
||||||
tmp++;
|
tmp++;
|
||||||
if (strcmp(tmp, "Texture") == 0)
|
info_type = get_asset_type(tmp);
|
||||||
{
|
|
||||||
info_type = TEXTURE_INFO;
|
|
||||||
}
|
|
||||||
else if (strcmp(tmp, "Sprite") == 0)
|
|
||||||
{
|
|
||||||
info_type = SPRITE_INFO;
|
|
||||||
}
|
|
||||||
else if (strcmp(tmp, "LevelPack") == 0)
|
|
||||||
{
|
|
||||||
info_type = LEVELPACK_INFO;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
info_type = INVALID_INFO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -141,6 +141,16 @@ bool load_from_rres(const char* file, Assets_t* assets)
|
||||||
printf("Added level pack %s as %s\n", info_str, name);
|
printf("Added level pack %s as %s\n", info_str, name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SOUND_INFO:
|
||||||
|
{
|
||||||
|
if (add_sound_rres(assets, name, info_str, &rres_file) == NULL)
|
||||||
|
{
|
||||||
|
printf("Unable to add sound at line %lu\n", line_num);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("Added sound %s as %s\n", info_str, name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SPRITE_INFO:
|
case SPRITE_INFO:
|
||||||
{
|
{
|
||||||
SpriteInfo_t spr_info = {0};
|
SpriteInfo_t spr_info = {0};
|
||||||
|
@ -201,30 +211,7 @@ bool load_from_infofile(const char* file, Assets_t* assets)
|
||||||
if (tmp[0] == '-')
|
if (tmp[0] == '-')
|
||||||
{
|
{
|
||||||
tmp++;
|
tmp++;
|
||||||
if (strcmp(tmp, "Texture") == 0)
|
info_type = get_asset_type(tmp);
|
||||||
{
|
|
||||||
info_type = TEXTURE_INFO;
|
|
||||||
}
|
|
||||||
else if (strcmp(tmp, "Sprite") == 0)
|
|
||||||
{
|
|
||||||
info_type = SPRITE_INFO;
|
|
||||||
}
|
|
||||||
else if (strcmp(tmp, "Sound") == 0)
|
|
||||||
{
|
|
||||||
info_type = SOUND_INFO;
|
|
||||||
}
|
|
||||||
else if (strcmp(tmp, "Emitter") == 0)
|
|
||||||
{
|
|
||||||
info_type = EMITTER_INFO;
|
|
||||||
}
|
|
||||||
else if (strcmp(tmp, "LevelPack") == 0)
|
|
||||||
{
|
|
||||||
info_type = LEVELPACK_INFO;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
info_type = INVALID_INFO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue