Removed mouse delay.

This commit is contained in:
igor
2026-04-18 01:51:10 -07:00
parent 1c1bea8a05
commit 73c9232e84
2 changed files with 25 additions and 27 deletions
+2
View File
@@ -383,6 +383,8 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *In
} }
#endif #endif
DrawRectangle(Buffer, (F32)Input->MouseX-14.0f, (F32)Input->MouseY-14.0f, (F32)(Input->MouseX)+2.0f, (F32)(Input->MouseY)+2.0f, 1.0f, 0.0f, 0.0f);
GameOutputSound(GameState, SoundBuffer, 400); GameOutputSound(GameState, SoundBuffer, 400);
} }
+23 -27
View File
@@ -634,7 +634,7 @@ S32 main(S32 argc, char *argv[])
game_input *NewInput = &Input[0]; game_input *NewInput = &Input[0];
game_input *OldInput = &Input[1]; game_input *OldInput = &Input[1];
memset(&Input, 0, sizeof(Input)); memset(Input, 0, sizeof(Input));
GlobalPerfCountFrequency = SDL_GetPerformanceFrequency(); GlobalPerfCountFrequency = SDL_GetPerformanceFrequency();
@@ -658,13 +658,21 @@ S32 main(S32 argc, char *argv[])
Game = SDLLoadGameCode(SDLState.DLLPath); Game = SDLLoadGameCode(SDLState.DLLPath);
} }
U32 SDLMouseButtons = SDL_GetMouseState(&(NewInput->MouseX), &(NewInput->MouseY)); S32 MouseX, MouseY;
SDL_GetGlobalMouseState(&MouseX, &MouseY);
S32 WindowX, WindowY;
SDL_GetWindowPosition(Window, &WindowX, &WindowY);
NewInput->MouseX = MouseX - WindowX;
NewInput->MouseY = MouseY - WindowY;
U32 SDLMouseButtons = SDL_GetMouseState(NULL, NULL);
NewInput->MouseZ = 0; /* TODO: Support mouse wheel? */ NewInput->MouseZ = 0; /* TODO: Support mouse wheel? */
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]), SDL_BUTTON_LMASK & SDLMouseButtons); SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]), SDL_BUTTON_LMASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]), SDL_BUTTON_MMASK & SDLMouseButtons); SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]), SDL_BUTTON_MMASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]), SDL_BUTTON_RMASK & SDLMouseButtons); SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]), SDL_BUTTON_RMASK & SDLMouseButtons);
/* WARNING: TODO: SDL_BUTTON_X1MASK and SDL_BUTTON_X2MASK cannot be on at the /* WARNING: TODO: SDL_BUTTON_X1MASK and SDL_BUTTON_X2MASK cannot be on at the same time for some reason. */
* same time for some reason. */
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]), SDL_BUTTON_X1MASK & SDLMouseButtons); SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]), SDL_BUTTON_X1MASK & SDLMouseButtons);
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]), SDL_BUTTON_X2MASK & SDLMouseButtons); SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]), SDL_BUTTON_X2MASK & SDLMouseButtons);
@@ -741,15 +749,11 @@ S32 main(S32 argc, char *argv[])
} }
} }
S32 TargetQueueBytes = SoundOutput.LatencySampleCount * S32 TargetQueueBytes = SoundOutput.LatencySampleCount * SoundOutput.BytesPerSample;
SoundOutput.BytesPerSample; S32 BytesToWrite = TargetQueueBytes - SDL_GetQueuedAudioSize(1);
S32 BytesToWrite =
TargetQueueBytes - SDL_GetQueuedAudioSize(1);
game_sound_output_buffer SoundBuffer; game_sound_output_buffer SoundBuffer;
SoundBuffer.SamplesPerSecond = SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond;
SoundOutput.SamplesPerSecond; SoundBuffer.SampleCount = BytesToWrite / SoundOutput.BytesPerSample;
SoundBuffer.SampleCount =
BytesToWrite / SoundOutput.BytesPerSample;
SoundBuffer.Samples = (short *)SoundOutput.Samples; SoundBuffer.Samples = (short *)SoundOutput.Samples;
thread_context Context; thread_context Context;
@@ -763,25 +767,19 @@ S32 main(S32 argc, char *argv[])
Buffer.Pitch = GlobalBackbuffer.Pitch; Buffer.Pitch = GlobalBackbuffer.Pitch;
if(Game.UpdateAndRender) { if(Game.UpdateAndRender) {
Game.UpdateAndRender(&Context, &GameMemory, Game.UpdateAndRender(&Context, &GameMemory, NewInput, &Buffer, &SoundBuffer);
NewInput, &Buffer,
&SoundBuffer);
} }
SDLFillSoundBuffer(&SoundOutput, BytesToWrite); SDLFillSoundBuffer(&SoundOutput, BytesToWrite);
U64 WorkCounter = SDLGetWallClock(); U64 WorkCounter = SDLGetWallClock();
F32 WorkSecondsElapsed = F32 WorkSecondsElapsed = SDLGetSecondsElapsed(LastCounter, WorkCounter);
SDLGetSecondsElapsed(LastCounter, WorkCounter);
F32 SecondsElapsedForFrame = WorkSecondsElapsed; F32 SecondsElapsedForFrame = WorkSecondsElapsed;
if(SecondsElapsedForFrame < TargetSecondsPerFrame) { if(SecondsElapsedForFrame < TargetSecondsPerFrame) {
while(SecondsElapsedForFrame < TargetSecondsPerFrame) { while(SecondsElapsedForFrame < TargetSecondsPerFrame) {
SecondsElapsedForFrame = SecondsElapsedForFrame = SDLGetSecondsElapsed(LastCounter, SDLGetWallClock());
SDLGetSecondsElapsed(LastCounter, SDL_Delay((U32)((TargetSecondsPerFrame - SecondsElapsedForFrame) * 1000.0));
SDLGetWallClock());
SDL_Delay((U32)((TargetSecondsPerFrame -
SecondsElapsedForFrame) * 1000.0));
} }
} else { } else {
/* TODO: Missed frame rate! */ /* TODO: Missed frame rate! */
@@ -790,11 +788,9 @@ S32 main(S32 argc, char *argv[])
U64 EndCounter = SDLGetWallClock(); U64 EndCounter = SDLGetWallClock();
SDLDisplayBufferInWindow(GlobalBackbuffer, Window, SDLDisplayBufferInWindow(GlobalBackbuffer, Window, Renderer);
Renderer);
F64 MSPerFrame = 1000.0 * F64 MSPerFrame = 1000.0 * SDLGetSecondsElapsed(LastCounter, EndCounter);
SDLGetSecondsElapsed(LastCounter, EndCounter);
F64 FPS = 0.0; F64 FPS = 0.0;
LastCounter = EndCounter; LastCounter = EndCounter;
@@ -808,7 +804,7 @@ S32 main(S32 argc, char *argv[])
LastCycleCount = EndCycleCount; LastCycleCount = EndCycleCount;
#endif #endif
SWAP(game_input *, NewInput, OldInput); SWAP(game_input *, OldInput, NewInput);
} }
} else { } else {
/* TODO: Failed to allocate Samples and Sound memory . . . */ /* TODO: Failed to allocate Samples and Sound memory . . . */