Swap type names back.
This commit is contained in:
+24
-25
@@ -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;
|
||||
if(Value < -DeadZoneThreshold)
|
||||
@@ -299,7 +299,7 @@ static float SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold)
|
||||
}
|
||||
|
||||
#define DEFAULT_REFRESH_RATE 60
|
||||
static int SDLGetWindowRefreshRate(SDL_Window *Window)
|
||||
static S32 SDLGetWindowRefreshRate(SDL_Window *Window)
|
||||
{
|
||||
int DisplayIndex = SDL_GetWindowDisplayIndex(Window);
|
||||
SDL_DisplayMode Mode;
|
||||
@@ -311,18 +311,17 @@ static int SDLGetWindowRefreshRate(SDL_Window *Window)
|
||||
return Mode.refresh_rate;
|
||||
}
|
||||
|
||||
static unsigned long long SDLGetWallClock()
|
||||
static U64 SDLGetWallClock()
|
||||
{
|
||||
return SDL_GetPerformanceCounter();
|
||||
}
|
||||
|
||||
// WARNING: Might lose lots of precision because of conversion from 64-bit to float.
|
||||
static float SDLGetSecondsElapsed(unsigned long long Start, unsigned long long End)
|
||||
static F32 SDLGetSecondsElapsed(U64 Start, U64 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)) {
|
||||
/* TODO: This didn't work . . . */
|
||||
@@ -382,9 +381,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
GlobalPerfCountFrequency = SDL_GetPerformanceFrequency();
|
||||
|
||||
unsigned long long LastCounter;
|
||||
U64 LastCounter;
|
||||
#if __x86_64__ || __i386__
|
||||
unsigned long long LastCycleCount;
|
||||
U64 LastCycleCount;
|
||||
#endif
|
||||
|
||||
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.
|
||||
#endif // Also, __rdtsc is not available on MacOS ARM; I have not checked MacOS x64.
|
||||
|
||||
int MonitorRefreshHz = SDLGetWindowRefreshRate(Window);
|
||||
int GameUpdateHz = MonitorRefreshHz / 2;
|
||||
float TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz;
|
||||
S32 MonitorRefreshHz = SDLGetWindowRefreshRate(Window);
|
||||
S32 GameUpdateHz = MonitorRefreshHz / 2;
|
||||
F32 TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz;
|
||||
|
||||
game_controller_input *OldKeyboardController = GetController(OldInput, 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])) {
|
||||
NewController->IsConnected = true;
|
||||
|
||||
short StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX);
|
||||
short StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY);
|
||||
S16 StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX);
|
||||
S16 StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY);
|
||||
|
||||
NewController->IsAnalog = true;
|
||||
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;
|
||||
int BytesToWrite = TargetQueueBytes - SDL_GetQueuedAudioSize(1);
|
||||
S32 TargetQueueBytes = SoundOutput.LatencySampleCount * SoundOutput.BytesPerSample;
|
||||
S32 BytesToWrite = TargetQueueBytes - SDL_GetQueuedAudioSize(1);
|
||||
game_sound_output_buffer SoundBuffer;
|
||||
SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond;
|
||||
SoundBuffer.SampleCount = BytesToWrite / SoundOutput.BytesPerSample;
|
||||
@@ -484,10 +483,10 @@ int main(int argc, char *argv[])
|
||||
GameUpdateAndRender(&GameMemory, NewInput, &Buffer, &SoundBuffer);
|
||||
SDLFillSoundBuffer(&SoundOutput, BytesToWrite);
|
||||
|
||||
unsigned long WorkCounter = SDLGetWallClock();
|
||||
float WorkSecondsElapsed = SDLGetSecondsElapsed(LastCounter, WorkCounter);
|
||||
U64 WorkCounter = SDLGetWallClock();
|
||||
F32 WorkSecondsElapsed = SDLGetSecondsElapsed(LastCounter, WorkCounter);
|
||||
|
||||
float SecondsElapsedForFrame = WorkSecondsElapsed;
|
||||
F32 SecondsElapsedForFrame = WorkSecondsElapsed;
|
||||
if(SecondsElapsedForFrame < TargetSecondsPerFrame) {
|
||||
while(SecondsElapsedForFrame < TargetSecondsPerFrame) {
|
||||
SecondsElapsedForFrame = SDLGetSecondsElapsed(LastCounter, SDLGetWallClock());
|
||||
@@ -498,19 +497,19 @@ int main(int argc, char *argv[])
|
||||
// TODO: Logging.
|
||||
}
|
||||
|
||||
unsigned long long EndCounter = SDLGetWallClock();
|
||||
U64 EndCounter = SDLGetWallClock();
|
||||
|
||||
SDLDisplayBufferInWindow(GlobalBackbuffer, Window, Renderer);
|
||||
|
||||
double MSPerFrame = 1000.0 * SDLGetSecondsElapsed(LastCounter, EndCounter);
|
||||
double FPS = 0.0;
|
||||
F64 MSPerFrame = 1000.0 * SDLGetSecondsElapsed(LastCounter, EndCounter);
|
||||
F64 FPS = 0.0;
|
||||
|
||||
LastCounter = EndCounter;
|
||||
|
||||
#if __x86_64__ || __i386__
|
||||
unsigned long long EndCycleCount = __rdtsc();
|
||||
unsigned long long CyclesElapsed = EndCycleCount - LastCycleCount;
|
||||
double MCPF = ((double)CyclesElapsed / (1000.0 * 1000.0));
|
||||
U64 EndCycleCount = __rdtsc();
|
||||
U64 CyclesElapsed = EndCycleCount - LastCycleCount;
|
||||
F64 MCPF = ((double)CyclesElapsed / (1000.0 * 1000.0));
|
||||
fprintf(stderr, "%.02f ms/f, %.02f/s, %.02f mc/f\n", MSPerFrame, FPS, MCPF);
|
||||
LastCycleCount = EndCycleCount;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user