Removed mouse delay.
This commit is contained in:
+23
-27
@@ -634,7 +634,7 @@ S32 main(S32 argc, char *argv[])
|
||||
|
||||
game_input *NewInput = &Input[0];
|
||||
game_input *OldInput = &Input[1];
|
||||
memset(&Input, 0, sizeof(Input));
|
||||
memset(Input, 0, sizeof(Input));
|
||||
|
||||
GlobalPerfCountFrequency = SDL_GetPerformanceFrequency();
|
||||
|
||||
@@ -658,13 +658,21 @@ S32 main(S32 argc, char *argv[])
|
||||
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? */
|
||||
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]), SDL_BUTTON_LMASK & SDLMouseButtons);
|
||||
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]), SDL_BUTTON_MMASK & SDLMouseButtons);
|
||||
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]), SDL_BUTTON_RMASK & SDLMouseButtons);
|
||||
/* WARNING: TODO: SDL_BUTTON_X1MASK and SDL_BUTTON_X2MASK cannot be on at the
|
||||
* same time for some reason. */
|
||||
/* WARNING: TODO: SDL_BUTTON_X1MASK and SDL_BUTTON_X2MASK cannot be on at the same time for some reason. */
|
||||
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]), SDL_BUTTON_X1MASK & SDLMouseButtons);
|
||||
SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]), SDL_BUTTON_X2MASK & SDLMouseButtons);
|
||||
|
||||
@@ -741,15 +749,11 @@ S32 main(S32 argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
S32 TargetQueueBytes = SoundOutput.LatencySampleCount *
|
||||
SoundOutput.BytesPerSample;
|
||||
S32 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;
|
||||
SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond;
|
||||
SoundBuffer.SampleCount = BytesToWrite / SoundOutput.BytesPerSample;
|
||||
SoundBuffer.Samples = (short *)SoundOutput.Samples;
|
||||
|
||||
thread_context Context;
|
||||
@@ -763,25 +767,19 @@ S32 main(S32 argc, char *argv[])
|
||||
Buffer.Pitch = GlobalBackbuffer.Pitch;
|
||||
|
||||
if(Game.UpdateAndRender) {
|
||||
Game.UpdateAndRender(&Context, &GameMemory,
|
||||
NewInput, &Buffer,
|
||||
&SoundBuffer);
|
||||
Game.UpdateAndRender(&Context, &GameMemory, NewInput, &Buffer, &SoundBuffer);
|
||||
}
|
||||
|
||||
SDLFillSoundBuffer(&SoundOutput, BytesToWrite);
|
||||
|
||||
U64 WorkCounter = SDLGetWallClock();
|
||||
F32 WorkSecondsElapsed =
|
||||
SDLGetSecondsElapsed(LastCounter, WorkCounter);
|
||||
F32 WorkSecondsElapsed = SDLGetSecondsElapsed(LastCounter, WorkCounter);
|
||||
|
||||
F32 SecondsElapsedForFrame = WorkSecondsElapsed;
|
||||
if(SecondsElapsedForFrame < TargetSecondsPerFrame) {
|
||||
while(SecondsElapsedForFrame < TargetSecondsPerFrame) {
|
||||
SecondsElapsedForFrame =
|
||||
SDLGetSecondsElapsed(LastCounter,
|
||||
SDLGetWallClock());
|
||||
SDL_Delay((U32)((TargetSecondsPerFrame -
|
||||
SecondsElapsedForFrame) * 1000.0));
|
||||
SecondsElapsedForFrame = SDLGetSecondsElapsed(LastCounter, SDLGetWallClock());
|
||||
SDL_Delay((U32)((TargetSecondsPerFrame - SecondsElapsedForFrame) * 1000.0));
|
||||
}
|
||||
} else {
|
||||
/* TODO: Missed frame rate! */
|
||||
@@ -790,11 +788,9 @@ S32 main(S32 argc, char *argv[])
|
||||
|
||||
U64 EndCounter = SDLGetWallClock();
|
||||
|
||||
SDLDisplayBufferInWindow(GlobalBackbuffer, Window,
|
||||
Renderer);
|
||||
SDLDisplayBufferInWindow(GlobalBackbuffer, Window, Renderer);
|
||||
|
||||
F64 MSPerFrame = 1000.0 *
|
||||
SDLGetSecondsElapsed(LastCounter, EndCounter);
|
||||
F64 MSPerFrame = 1000.0 * SDLGetSecondsElapsed(LastCounter, EndCounter);
|
||||
F64 FPS = 0.0;
|
||||
|
||||
LastCounter = EndCounter;
|
||||
@@ -808,7 +804,7 @@ S32 main(S32 argc, char *argv[])
|
||||
LastCycleCount = EndCycleCount;
|
||||
#endif
|
||||
|
||||
SWAP(game_input *, NewInput, OldInput);
|
||||
SWAP(game_input *, OldInput, NewInput);
|
||||
}
|
||||
} else {
|
||||
/* TODO: Failed to allocate Samples and Sound memory . . . */
|
||||
|
||||
Reference in New Issue
Block a user