diff --git a/Data/Audio/terry_hit.ogg b/Data/Audio/terry_hit.ogg new file mode 100644 index 0000000..ae49fb6 --- /dev/null +++ b/Data/Audio/terry_hit.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:047bb92b9cf80e962d915d488667ba2d1d45a5104a9137a4dbaef67868a38e5e +size 9277 diff --git a/External/tely b/External/tely index f28426b..04b0275 160000 --- a/External/tely +++ b/External/tely @@ -1 +1 @@ -Subproject commit f28426b027a5d63974ff8901459b8fb8454f39fe +Subproject commit 04b02759fa5a673b8644d87e22c611f3b92eb1e5 diff --git a/feely_pona.cpp b/feely_pona.cpp index edbeb4d..87dc7f8 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -422,12 +422,13 @@ void TELY_DLL_Init(void *user_data) FP_Game_PopParentEntity(game); } - uint16_t font_size = 18; - game->camera.scale = Dqn_V2_InitNx1(1); - game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size); - game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size); - game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size); - game->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa")); + uint16_t font_size = 18; + game->camera.scale = Dqn_V2_InitNx1(1); + game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size); + game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size); + game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size); + game->audio[FP_GameAudio_TestAudio] = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa")); + game->audio[FP_GameAudio_TerryHit] = platform->func_load_audio(assets, DQN_STRING8("Terry Hit"), DQN_STRING8("Data/Audio/terry_hit.ogg")); } void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 dir_vector) @@ -562,6 +563,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_Ga if (!entity->attack_processed && game->clock_ms >= midpoint_clock_ms) { entity->attack_box_size = entity->local_hit_box_size; + FP_EnqueueSound(game, game->audio[FP_GameAudio_TerryHit], 1.0f); // NOTE: Position the attack box switch (entity->direction) { case FP_GameDirection_Left: { @@ -1341,7 +1343,6 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input } } Dqn_Profiler_EndZone(update_zone); - } void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) @@ -1574,10 +1575,23 @@ void TELY_DLL_FrameUpdate(void *user_data) // ============================================================================================= TELY_Audio *audio = &platform->audio; - if (audio->playback_size == 0) { - TELY_Audio_Play(audio, game->test_audio, 1.f /*volume*/); + + // NOTE: Process the sound command queue + for (uint32_t i = 0; i < game->sound_command_count; i++) + { + FP_SoundCommand *sound_command = &game->sound_commands[i]; + TELY_Audio_Play(audio, sound_command->audio_handle, sound_command->volume); } + // NOTE: Clear the sound command queue for the next frame + game->sound_command_count = 0; + +#if 0 + if (audio->playback_size == 0) { + TELY_Audio_Play(audio, game->audio[FP_GameAudio_TestAudio], 1.f /*volume*/); + } +#endif + // ============================================================================================= if (TELY_Platform_InputKeyWasDown(input->mouse_left) && TELY_Platform_InputKeyIsDown(input->mouse_left)) { @@ -1693,5 +1707,5 @@ void TELY_DLL_FrameUpdate(void *user_data) } TELY_RFui_Flush(rfui, renderer, input, assets); - //TELY_Audio_MixPlaybackSamples(audio, assets); + TELY_Audio_MixPlaybackSamples(audio, assets); } diff --git a/feely_pona_game.cpp b/feely_pona_game.cpp index 1d3f9db..8dfe918 100644 --- a/feely_pona_game.cpp +++ b/feely_pona_game.cpp @@ -706,3 +706,10 @@ FP_GameFindClosestEntityResult FP_Game_FindClosestEntityWithType(FP_Game *game, return result; } +static void FP_EnqueueSound(FP_Game *game, TELY_AssetAudioHandle audio_handle, Dqn_f32 volume) +{ + DQN_ASSERT(game->sound_command_count < MAX_SOUNDS); + FP_SoundCommand *sound_command = &game->sound_commands[game->sound_command_count++]; + sound_command->audio_handle = audio_handle; + sound_command->volume = volume; +} diff --git a/feely_pona_game.h b/feely_pona_game.h index 1dad517..50b1568 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -197,6 +197,20 @@ struct FP_GameCamera Dqn_V2 scale; }; +enum FP_GameAudio +{ + FP_GameAudio_TestAudio, + FP_GameAudio_TerryHit, + FP_GameAudio_Count, +}; + +struct FP_SoundCommand +{ + TELY_AssetAudioHandle audio_handle; + float volume; +}; + +const uint32_t MAX_SOUNDS = 128; struct FP_Game { Dqn_f32 delta_s_accumulator; @@ -205,7 +219,11 @@ struct FP_Game TELY_AssetFontHandle inter_regular_font; TELY_AssetFontHandle inter_italic_font; TELY_AssetFontHandle jetbrains_mono_font; - TELY_AssetAudioHandle test_audio; + TELY_AssetAudioHandle audio[FP_GameAudio_Count]; + + FP_SoundCommand sound_commands[MAX_SOUNDS]; + uint32_t sound_command_count; + Dqn_Slice hero_sprite_anims; TELY_AssetSpriteSheet hero_sprite_sheet; Dqn_FArray parent_entity_stack;