Probably should not fetch screen refresh rate in the loop, for now.

This commit is contained in:
2026-03-31 16:25:40 -07:00
parent 4be3d0df80
commit 165ba90102
2 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ static void GameOutputSound(game_state *GameState,
S16 ToneVolume, *SampleOut; S16 ToneVolume, *SampleOut;
S32 WavePeriod, SampleIndex; S32 WavePeriod, SampleIndex;
ToneVolume = 8000; ToneVolume = 0;
WavePeriod = SoundBuffer->SamplesPerSecond / ToneHz; WavePeriod = SoundBuffer->SamplesPerSecond / ToneHz;
SampleOut = SoundBuffer->Samples; SampleOut = SoundBuffer->Samples;
+9 -7
View File
@@ -805,11 +805,18 @@ S32 main(S32 argc, char *argv[])
game_input Input[2]; game_input Input[2];
game_input *NewInput, *OldInput; game_input *NewInput, *OldInput;
sdl_game_code Game; sdl_game_code Game;
F32 TargetSecondsPerFrame;
S32 MonitorRefreshHz, GameUpdateHz;
U64 LastCounter; U64 LastCounter;
#if __x86_64__ || __i386__ #if __x86_64__ || __i386__
U64 LastCycleCount; U64 LastCycleCount;
#endif #endif
MonitorRefreshHz = SDLGetWindowRefreshRate(Window);
GameUpdateHz = MonitorRefreshHz;
TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz;
NewInput = &Input[0]; NewInput = &Input[0];
OldInput = &Input[1]; OldInput = &Input[1];
memset(&Input, 0, sizeof(Input)); memset(&Input, 0, sizeof(Input));
@@ -820,8 +827,6 @@ S32 main(S32 argc, char *argv[])
while(GlobalRunning) { while(GlobalRunning) {
thread_context Context; thread_context Context;
S32 MonitorRefreshHz, GameUpdateHz;
F32 TargetSecondsPerFrame;
U32 NewDLLWriteTime, ButtonIndex, ControllerIndex, U32 NewDLLWriteTime, ButtonIndex, ControllerIndex,
SDLMouseButtons; SDLMouseButtons;
game_controller_input *OldKeyboardController, game_controller_input *OldKeyboardController,
@@ -849,10 +854,6 @@ S32 main(S32 argc, char *argv[])
LastCycleCount = __rdtsc(); LastCycleCount = __rdtsc();
#endif #endif
MonitorRefreshHz = SDLGetWindowRefreshRate(Window);
GameUpdateHz = MonitorRefreshHz;
TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz;
NewDLLWriteTime = GetLastWriteTime(SDLState.DLLPath); NewDLLWriteTime = GetLastWriteTime(SDLState.DLLPath);
if(NewDLLWriteTime > Game.DLLLastWriteTime) { if(NewDLLWriteTime > Game.DLLLastWriteTime) {
SDLUnloadGameCode(&Game); SDLUnloadGameCode(&Game);
@@ -1074,10 +1075,11 @@ S32 main(S32 argc, char *argv[])
SDLPlaybackInput(&SDLState, NewInput); SDLPlaybackInput(&SDLState, NewInput);
} }
if(Game.UpdateAndRender) if(Game.UpdateAndRender) {
Game.UpdateAndRender(&Context, &GameMemory, Game.UpdateAndRender(&Context, &GameMemory,
NewInput, &Buffer, NewInput, &Buffer,
&SoundBuffer); &SoundBuffer);
}
SDLFillSoundBuffer(&SoundOutput, BytesToWrite); SDLFillSoundBuffer(&SoundOutput, BytesToWrite);