From 165ba90102ebb5d1b612498ba3271a8cb02dc08f Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 31 Mar 2026 16:25:40 -0700 Subject: [PATCH] Probably should not fetch screen refresh rate in the loop, for now. --- handmade.c | 2 +- sdl_handmade.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/handmade.c b/handmade.c index 5dcd69a..e57d85d 100644 --- a/handmade.c +++ b/handmade.c @@ -11,7 +11,7 @@ static void GameOutputSound(game_state *GameState, S16 ToneVolume, *SampleOut; S32 WavePeriod, SampleIndex; - ToneVolume = 8000; + ToneVolume = 0; WavePeriod = SoundBuffer->SamplesPerSecond / ToneHz; SampleOut = SoundBuffer->Samples; diff --git a/sdl_handmade.c b/sdl_handmade.c index bc4a181..7e6b62b 100644 --- a/sdl_handmade.c +++ b/sdl_handmade.c @@ -805,11 +805,18 @@ S32 main(S32 argc, char *argv[]) game_input Input[2]; game_input *NewInput, *OldInput; sdl_game_code Game; + F32 TargetSecondsPerFrame; + S32 MonitorRefreshHz, GameUpdateHz; U64 LastCounter; #if __x86_64__ || __i386__ U64 LastCycleCount; #endif + + MonitorRefreshHz = SDLGetWindowRefreshRate(Window); + GameUpdateHz = MonitorRefreshHz; + TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz; + NewInput = &Input[0]; OldInput = &Input[1]; memset(&Input, 0, sizeof(Input)); @@ -820,8 +827,6 @@ S32 main(S32 argc, char *argv[]) while(GlobalRunning) { thread_context Context; - S32 MonitorRefreshHz, GameUpdateHz; - F32 TargetSecondsPerFrame; U32 NewDLLWriteTime, ButtonIndex, ControllerIndex, SDLMouseButtons; game_controller_input *OldKeyboardController, @@ -849,10 +854,6 @@ S32 main(S32 argc, char *argv[]) LastCycleCount = __rdtsc(); #endif - MonitorRefreshHz = SDLGetWindowRefreshRate(Window); - GameUpdateHz = MonitorRefreshHz; - TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz; - NewDLLWriteTime = GetLastWriteTime(SDLState.DLLPath); if(NewDLLWriteTime > Game.DLLLastWriteTime) { SDLUnloadGameCode(&Game); @@ -1074,10 +1075,11 @@ S32 main(S32 argc, char *argv[]) SDLPlaybackInput(&SDLState, NewInput); } - if(Game.UpdateAndRender) + if(Game.UpdateAndRender) { Game.UpdateAndRender(&Context, &GameMemory, NewInput, &Buffer, &SoundBuffer); + } SDLFillSoundBuffer(&SoundOutput, BytesToWrite);