Swap type names back.

This commit is contained in:
2026-03-15 00:09:57 -07:00
parent a5cff85e22
commit 64cad70b56
+24 -25
View File
@@ -288,7 +288,7 @@ static void SDLProcessMessages(game_controller_input *KeyboardController)
} }
} }
static float SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold) static F32 SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold)
{ {
F32 Result = 0.0f; F32 Result = 0.0f;
if(Value < -DeadZoneThreshold) if(Value < -DeadZoneThreshold)
@@ -299,7 +299,7 @@ static float SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold)
} }
#define DEFAULT_REFRESH_RATE 60 #define DEFAULT_REFRESH_RATE 60
static int SDLGetWindowRefreshRate(SDL_Window *Window) static S32 SDLGetWindowRefreshRate(SDL_Window *Window)
{ {
int DisplayIndex = SDL_GetWindowDisplayIndex(Window); int DisplayIndex = SDL_GetWindowDisplayIndex(Window);
SDL_DisplayMode Mode; SDL_DisplayMode Mode;
@@ -311,18 +311,17 @@ static int SDLGetWindowRefreshRate(SDL_Window *Window)
return Mode.refresh_rate; return Mode.refresh_rate;
} }
static unsigned long long SDLGetWallClock() static U64 SDLGetWallClock()
{ {
return SDL_GetPerformanceCounter(); return SDL_GetPerformanceCounter();
} }
// WARNING: Might lose lots of precision because of conversion from 64-bit to float. static F32 SDLGetSecondsElapsed(U64 Start, U64 End)
static float SDLGetSecondsElapsed(unsigned long long Start, unsigned long long End)
{ {
return (float)(End - Start) / (float)GlobalPerfCountFrequency; return (F32)(End - Start) / (F32)GlobalPerfCountFrequency;
} }
int main(int argc, char *argv[]) S32 main(S32 argc, char *argv[])
{ {
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO)) { if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO)) {
/* TODO: This didn't work . . . */ /* TODO: This didn't work . . . */
@@ -382,9 +381,9 @@ int main(int argc, char *argv[])
GlobalPerfCountFrequency = SDL_GetPerformanceFrequency(); GlobalPerfCountFrequency = SDL_GetPerformanceFrequency();
unsigned long long LastCounter; U64 LastCounter;
#if __x86_64__ || __i386__ #if __x86_64__ || __i386__
unsigned long long LastCycleCount; U64 LastCycleCount;
#endif #endif
while(GlobalRunning) { while(GlobalRunning) {
@@ -394,9 +393,9 @@ int main(int argc, char *argv[])
LastCycleCount = __rdtsc(); // NOTE: rdtsc reports clock cylces, however it is not meant for really precise profiler work as the value returned is varied. LastCycleCount = __rdtsc(); // NOTE: rdtsc reports clock cylces, however it is not meant for really precise profiler work as the value returned is varied.
#endif // Also, __rdtsc is not available on MacOS ARM; I have not checked MacOS x64. #endif // Also, __rdtsc is not available on MacOS ARM; I have not checked MacOS x64.
int MonitorRefreshHz = SDLGetWindowRefreshRate(Window); S32 MonitorRefreshHz = SDLGetWindowRefreshRate(Window);
int GameUpdateHz = MonitorRefreshHz / 2; S32 GameUpdateHz = MonitorRefreshHz / 2;
float TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz; F32 TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz;
game_controller_input *OldKeyboardController = GetController(OldInput, 0); game_controller_input *OldKeyboardController = GetController(OldInput, 0);
game_controller_input *NewKeyboardController = GetController(NewInput, 0); game_controller_input *NewKeyboardController = GetController(NewInput, 0);
@@ -417,8 +416,8 @@ int main(int argc, char *argv[])
if(ControllerHandles[ControllerIndex] != 0 && SDL_GameControllerGetAttached(ControllerHandles[ControllerIndex])) { if(ControllerHandles[ControllerIndex] != 0 && SDL_GameControllerGetAttached(ControllerHandles[ControllerIndex])) {
NewController->IsConnected = true; NewController->IsConnected = true;
short StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX); S16 StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX);
short StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY); S16 StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY);
NewController->IsAnalog = true; NewController->IsAnalog = true;
NewController->StickAverageX = SDLProcessInputStickValue((F32)StickX, CONTROLLER_LEFT_THUMB_DEADZONE); NewController->StickAverageX = SDLProcessInputStickValue((F32)StickX, CONTROLLER_LEFT_THUMB_DEADZONE);
@@ -469,8 +468,8 @@ int main(int argc, char *argv[])
} }
} }
int TargetQueueBytes = SoundOutput.LatencySampleCount * SoundOutput.BytesPerSample; S32 TargetQueueBytes = SoundOutput.LatencySampleCount * SoundOutput.BytesPerSample;
int BytesToWrite = TargetQueueBytes - SDL_GetQueuedAudioSize(1); S32 BytesToWrite = TargetQueueBytes - SDL_GetQueuedAudioSize(1);
game_sound_output_buffer SoundBuffer; game_sound_output_buffer SoundBuffer;
SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond; SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond;
SoundBuffer.SampleCount = BytesToWrite / SoundOutput.BytesPerSample; SoundBuffer.SampleCount = BytesToWrite / SoundOutput.BytesPerSample;
@@ -484,10 +483,10 @@ int main(int argc, char *argv[])
GameUpdateAndRender(&GameMemory, NewInput, &Buffer, &SoundBuffer); GameUpdateAndRender(&GameMemory, NewInput, &Buffer, &SoundBuffer);
SDLFillSoundBuffer(&SoundOutput, BytesToWrite); SDLFillSoundBuffer(&SoundOutput, BytesToWrite);
unsigned long WorkCounter = SDLGetWallClock(); U64 WorkCounter = SDLGetWallClock();
float WorkSecondsElapsed = SDLGetSecondsElapsed(LastCounter, WorkCounter); F32 WorkSecondsElapsed = SDLGetSecondsElapsed(LastCounter, WorkCounter);
float SecondsElapsedForFrame = WorkSecondsElapsed; F32 SecondsElapsedForFrame = WorkSecondsElapsed;
if(SecondsElapsedForFrame < TargetSecondsPerFrame) { if(SecondsElapsedForFrame < TargetSecondsPerFrame) {
while(SecondsElapsedForFrame < TargetSecondsPerFrame) { while(SecondsElapsedForFrame < TargetSecondsPerFrame) {
SecondsElapsedForFrame = SDLGetSecondsElapsed(LastCounter, SDLGetWallClock()); SecondsElapsedForFrame = SDLGetSecondsElapsed(LastCounter, SDLGetWallClock());
@@ -498,19 +497,19 @@ int main(int argc, char *argv[])
// TODO: Logging. // TODO: Logging.
} }
unsigned long long EndCounter = SDLGetWallClock(); U64 EndCounter = SDLGetWallClock();
SDLDisplayBufferInWindow(GlobalBackbuffer, Window, Renderer); SDLDisplayBufferInWindow(GlobalBackbuffer, Window, Renderer);
double MSPerFrame = 1000.0 * SDLGetSecondsElapsed(LastCounter, EndCounter); F64 MSPerFrame = 1000.0 * SDLGetSecondsElapsed(LastCounter, EndCounter);
double FPS = 0.0; F64 FPS = 0.0;
LastCounter = EndCounter; LastCounter = EndCounter;
#if __x86_64__ || __i386__ #if __x86_64__ || __i386__
unsigned long long EndCycleCount = __rdtsc(); U64 EndCycleCount = __rdtsc();
unsigned long long CyclesElapsed = EndCycleCount - LastCycleCount; U64 CyclesElapsed = EndCycleCount - LastCycleCount;
double MCPF = ((double)CyclesElapsed / (1000.0 * 1000.0)); F64 MCPF = ((double)CyclesElapsed / (1000.0 * 1000.0));
fprintf(stderr, "%.02f ms/f, %.02f/s, %.02f mc/f\n", MSPerFrame, FPS, MCPF); fprintf(stderr, "%.02f ms/f, %.02f/s, %.02f mc/f\n", MSPerFrame, FPS, MCPF);
LastCycleCount = EndCycleCount; LastCycleCount = EndCycleCount;
#else #else