From 50d62714136c1c7a132342c8de77962fa525ca91 Mon Sep 17 00:00:00 2001 From: doyle Date: Tue, 21 Nov 2023 22:47:54 +1100 Subject: [PATCH] fp: Use audio handles --- External/tely | 2 +- feely_pona.cpp | 23 +++++++---------------- feely_pona_game.h | 20 +++++++++++--------- project.rdbg | Bin 2519 -> 2600 bytes 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/External/tely b/External/tely index d3b03b9..f6c96fb 160000 --- a/External/tely +++ b/External/tely @@ -1 +1 @@ -Subproject commit d3b03b99ebeefe19097e07f0a04e4c614175a526 +Subproject commit f6c96fb65331e2829a43e0375cb8fc1bd0969c06 diff --git a/feely_pona.cpp b/feely_pona.cpp index 0a892a9..3859c56 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -2015,18 +2015,18 @@ static void FP_Update(TELY_OS *os, FP_Game *game, TELY_OSInput *input, TELY_Audi // haven't given the player cooldown yet, so we assign a timestamp for that if (game->play.wave_cooldown_timestamp_ms == 0) { game->play.wave_cooldown_timestamp_ms = game->play.clock_ms + FP_COOLDOWN_WAVE_TIME_MS; - TELY_Audio_Fade(audio, game->audio[FP_GameAudio_Music1], TELY_AudioEffectFade_Out, 2000 /*fade_duration_ms*/); - TELY_Audio_Play(audio, game->audio[FP_GameAudio_Music2], 1.f); - TELY_Audio_Fade(audio, game->audio[FP_GameAudio_Music2], TELY_AudioEffectFade_In, 2000 /*fade_duration_ms*/); + TELY_Audio_Fade(audio, game->bg_music1, TELY_AudioEffectFade_Out, 2000 /*fade_duration_ms*/); + game->bg_music2 = TELY_Audio_Play(audio, game->audio[FP_GameAudio_Music2], 1.f); + TELY_Audio_Fade(audio, game->bg_music2, TELY_AudioEffectFade_In, 2000 /*fade_duration_ms*/); } else { // NOTE: Check if cooldown has elapsed, the next wave can start if so if (game->play.clock_ms > game->play.wave_cooldown_timestamp_ms) { game->play.enemies_per_wave = DQN_MAX(5 * DQN_CAST(uint32_t)game->play.mob_spawners.size, DQN_CAST(uint32_t)(game->play.enemies_per_wave * 1.5)); game->play.enemies_spawned_this_wave = 0; // Important! Reset the spawn count game->play.wave_cooldown_timestamp_ms = 0; // Important! We reset the timestamp for the next wave - TELY_Audio_Fade(audio, game->audio[FP_GameAudio_Music2], TELY_AudioEffectFade_Out, 2000 /*fade_duration_ms*/); - TELY_Audio_Play(audio, game->audio[FP_GameAudio_Music1], 1.f); - TELY_Audio_Fade(audio, game->audio[FP_GameAudio_Music1], TELY_AudioEffectFade_In, 2000 /*fade_duration_ms*/); + TELY_Audio_Fade(audio, game->bg_music2, TELY_AudioEffectFade_Out, 2000 /*fade_duration_ms*/); + game->bg_music1 = TELY_Audio_Play(audio, game->audio[FP_GameAudio_Music1], 1.f); + TELY_Audio_Fade(audio, game->bg_music1, TELY_AudioEffectFade_In, 2000 /*fade_duration_ms*/); if (monkey_spawn && game->play.current_wave != 0) { // NOTE: We spawn a monkey at these wave intervals; @@ -4461,16 +4461,6 @@ void TELY_OS_DLLFrameUpdate(TELY_OS *os) // ============================================================================================= - TELY_Audio *audio = &os->audio; - - #if 1 - if (audio->playback_size == 0) { - //TELY_Audio_Play(audio, game->audio[FP_GameAudio_Music2], 1.f /*volume*/); - } - #endif - - // ============================================================================================= - if (game->play.state == FP_GameState_Play || game->play.state == FP_GameState_Tutorial) { if (TELY_OSInput_KeyWasDown(input->mouse_left) && TELY_OSInput_KeyIsDown(input->mouse_left)) { if (game->play.prev_active_entity.id) @@ -4500,6 +4490,7 @@ void TELY_OS_DLLFrameUpdate(TELY_OS *os) } } + TELY_Audio *audio = &os->audio; for (game->play.delta_s_accumulator += DQN_CAST(Dqn_f32)input->delta_s; game->play.delta_s_accumulator > FP_GAME_PHYSICS_STEP; game->play.delta_s_accumulator -= FP_GAME_PHYSICS_STEP) { diff --git a/feely_pona_game.h b/feely_pona_game.h index 2ceebb1..591cb8a 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -481,15 +481,17 @@ struct FP_Game TELY_AssetFontHandle jetbrains_mono_font; TELY_AssetFontHandle talkco_font; - TELY_AssetAudioHandle audio[FP_GameAudio_Count]; - TELY_AssetSpriteSheet atlas_sprite_sheet; - TELY_RFui rfui; - FP_GamePlay play; - Dqn_Arena *frame_arena; - uint16_t font_size; - uint16_t large_font_size; - uint16_t large_talkco_font_size; - uint16_t xlarge_talkco_font_size; + TELY_AssetAudioHandle audio[FP_GameAudio_Count]; + TELY_AudioPlaybackHandle bg_music1; + TELY_AudioPlaybackHandle bg_music2; + TELY_AssetSpriteSheet atlas_sprite_sheet; + TELY_RFui rfui; + FP_GamePlay play; + Dqn_Arena *frame_arena; + uint16_t font_size; + uint16_t large_font_size; + uint16_t large_talkco_font_size; + uint16_t xlarge_talkco_font_size; }; struct FP_GameAStarNode diff --git a/project.rdbg b/project.rdbg index f4d20426a5252b7098b7b8ddfa17196171b04e07..ee107c112d84b6aa5d20cdb1daed6f8cee361123 100644 GIT binary patch delta 358 zcmcaEyh3Dx6RRWx1B1n6K_<j@r$Y={v zGI>5TCqG0%Oi^-vQL0`tNZg7&zZj%J2gp|8DK06>ODsvwEznCgg__GEQCyM&vOHt50FxHbG8sl^kfO<%%sh-BjcSu+ znFSfaN+-W#;$Tz*im6WAZ_klhQIZO@HD_`mv)<$eCc(+xOfUX840RU0!XGs76 delta 297 zcmZ1>a$R_W6RQLR1B1!rLRQU*1+0^`**F;;fgCHY+|=CsqDsBwf`Z8ftW8`%I;k`> zCq*w~awCT>3y|vt(lhxwiwdJXNCQh!VsYwZ1r{%$a_h+wEIgApGiyz5Vb-54%A`KI zm{|}k?!e45S%pPw@=GR}$rG6Lp;~hjOEM-4GTAVi!rZ~l#09iRX0ihdCr@!nQC?z6 za&CcMvMtCa_WWXyvp{T+{Q?|C$@xX8dda$zCo-u`R$$~}w1G*n7v-eq=w%o~jb$lH zE6tp2z;=X@XYyCJO`A8fCo%$=jhz0IAF#7