From 968204e9d1fe68c107ea9b312751bdab73fa4369 Mon Sep 17 00:00:00 2001 From: Prince Frizzy Date: Sun, 18 May 2025 21:58:19 -0400 Subject: [PATCH] [build] Fix compile errors for Switch. --- data/dynos_bin_gfx.cpp | 8 ++++---- src/pc/configfile.c | 2 +- src/pc/game_main.c | 21 +++++++++++++++------ src/pc/game_main.h | 2 ++ src/pc/lua/utils/smlua_audio_utils.c | 4 ++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/data/dynos_bin_gfx.cpp b/data/dynos_bin_gfx.cpp index e01f85bb1..5a6690d76 100644 --- a/data/dynos_bin_gfx.cpp +++ b/data/dynos_bin_gfx.cpp @@ -23,7 +23,7 @@ static u32 sGfxCommandErrorSize = 0; #define CHECK_TOKEN_INDEX(tokenIndex, returnValue) { \ if (tokenIndex >= aNode->mTokens.Count()) { \ - PrintDataErrorGfx(" ERROR: Invalid token index: %llu, tokens count is: %d", tokenIndex, aNode->mTokens.Count()); \ + DynOS_PrintDataErrorGfx(" ERROR: Invalid token index: %llu, tokens count is: %d", tokenIndex, aNode->mTokens.Count()); \ return returnValue; \ } \ } @@ -1217,7 +1217,7 @@ template static String ConvertParam(lua_State *L, GfxData *aGfxData, u32 paramIndex, const char *typeName, const SmluaToFunc &smluaToFunc, const ReturnFunc &returnFunc) { T value = smluaToFunc(L, paramIndex); if (!gSmLuaConvertSuccess) { - PrintDataErrorGfx(" ERROR: Failed to convert parameter %u to %s", paramIndex, typeName); + DynOS_PrintDataErrorGfx(" ERROR: Failed to convert parameter %u to %s", paramIndex, typeName); return ""; } return returnFunc(value); @@ -1266,7 +1266,7 @@ static String ResolveParam(lua_State *L, GfxData *aGfxData, u32 paramIndex, char [&aGfxData] (Gfx *gfx) { return CreateRawPointerDataNode(aGfxData, gfx); } ); } - PrintDataErrorGfx(" ERROR: Unknown parameter type: '%c'", paramType); + DynOS_PrintDataErrorGfx(" ERROR: Unknown parameter type: '%c'", paramType); return ""; } @@ -1353,7 +1353,7 @@ static bool CheckGfxLength(GfxData *aGfxData, Gfx *gfx, u32 lengthToWrite) { if (lengthToWrite > 1) { u32 gfxLength = gfx_get_length(gfx); if (gfxLength < lengthToWrite) { - PrintDataErrorGfx(" ERROR: Cannot write %u commands to display list of length: %u", lengthToWrite, gfxLength); + DynOS_PrintDataErrorGfx(" ERROR: Cannot write %u commands to display list of length: %u", lengthToWrite, gfxLength); return false; } } diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 92ba34d8f..a37f55185 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -22,7 +22,7 @@ #include "game/save_file.h" #include "pc/network/network_player.h" #include "string_utils.h" -#include "pc/pc_main.h" +#include "pc/game_main.h" #define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0])) diff --git a/src/pc/game_main.c b/src/pc/game_main.c index 10b6fe793..b5ea2f93f 100644 --- a/src/pc/game_main.c +++ b/src/pc/game_main.c @@ -95,6 +95,8 @@ static u32 sDrawnFrames = 0; bool gGameInited = false; bool gGfxInited = false; +f32 gMasterVolume = 100.0f; + u8 gLuaVolumeMaster = 127; u8 gLuaVolumeLevel = 127; u8 gLuaVolumeSfx = 127; @@ -304,18 +306,25 @@ void produce_one_dummy_frame(void (*callback)(), u8 clearColorR, u8 clearColorG, static s16 sAudioBuffer[SAMPLES_HIGH * 2 * 2] = { 0 }; void buffer_audio(void) { - bool shouldMute = configMuteFocusLoss && !wm_api->has_focus(); - const f32 masterMod = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f; - set_sequence_player_volume(SEQ_PLAYER_LEVEL, shouldMute ? 0 : (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f * masterMod); - set_sequence_player_volume(SEQ_PLAYER_SFX, shouldMute ? 0 : (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f * masterMod); - set_sequence_player_volume(SEQ_PLAYER_ENV, shouldMute ? 0 : (f32)configEnvVolume / 127.0f * (f32)gLuaVolumeEnv / 127.0f * masterMod); + bool shouldMute = (configMuteFocusLoss && !wm_api->has_focus()) || (gMasterVolume == 0); + if (!shouldMute) { + set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f); + set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f); + set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * (f32)gLuaVolumeEnv / 127.0f); + } int samplesLeft = audio_api->buffered(); u32 numAudioSamples = samplesLeft < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW; for (s32 i = 0; i < 2; i++) { create_next_audio_buffer(sAudioBuffer + i * (numAudioSamples * 2), numAudioSamples); } - audio_api->play((u8 *)sAudioBuffer, 2 * numAudioSamples * 4); + + if (!shouldMute) { + for (u16 i = 0; i < ARRAY_COUNT(sAudioBuffer); i++) { + sAudioBuffer[i] *= gMasterVolume; + } + audio_api->play((u8 *)sAudioBuffer, 2 * numAudioSamples * 4); + } } void *audio_thread(UNUSED void *arg) { diff --git a/src/pc/game_main.h b/src/pc/game_main.h index 6419f07a8..38f7d42b2 100644 --- a/src/pc/game_main.h +++ b/src/pc/game_main.h @@ -14,6 +14,8 @@ extern "C" { extern bool gGameInited; extern bool gGfxInited; +extern f32 gMasterVolume; + extern u8 gLuaVolumeMaster; extern u8 gLuaVolumeLevel; extern u8 gLuaVolumeSfx; diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c index 3274b61f5..b7c329a4c 100644 --- a/src/pc/lua/utils/smlua_audio_utils.c +++ b/src/pc/lua/utils/smlua_audio_utils.c @@ -359,7 +359,7 @@ void audio_stream_stop(struct ModAudio* audio) { f32 audio_stream_get_position(struct ModAudio* audio) { if (!audio_sanity_check(audio, true, "get stream position from")) { return 0; } - u64 cursor; ma_data_source_get_cursor_in_pcm_frames(&audio->decoder, &cursor); + ma_uint64 cursor; ma_data_source_get_cursor_in_pcm_frames(&audio->decoder, &cursor); return (f32)cursor / ma_engine_get_sample_rate(&sModAudioEngine); } @@ -384,7 +384,7 @@ void audio_stream_set_looping(struct ModAudio* audio, bool looping) { void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, s64 loopEnd) { if (!audio_sanity_check(audio, true, "set stream loop points for")) { return; } - u64 length; ma_data_source_get_length_in_pcm_frames(&audio->decoder, &length); + ma_uint64 length; ma_data_source_get_length_in_pcm_frames(&audio->decoder, &length); if (loopStart < 0) loopStart += length; if (loopEnd <= 0) loopEnd += length;