Fix mouse bug

This commit is contained in:
Miloslav Číž 2020-10-11 19:10:20 +02:00
parent 2606355b03
commit 5ca8581e04
2 changed files with 20 additions and 4 deletions

View File

@ -199,6 +199,8 @@ done:
compilers and settings)
- High pitch noise in SDL music AGAIN!
- Add SW buttons to emscripten version so that it's playable on mobiles.
- When SDL level starts without moving the mouse, the camera sometimes rotates
wildly.
scratched:
- option for disabling wall transparency, for performance?

View File

@ -163,9 +163,15 @@ void webButton(uint8_t key, uint8_t down)
}
#endif
int8_t mouseMoved = 0; /* Whether the mouse has moved since program started,
this is needed to fix an SDL limitation. */
void SFG_getMouseOffset(int16_t *x, int16_t *y)
{
#ifndef __EMSCRIPTEN__
if (mouseMoved)
{
int mX, mY;
SDL_GetMouseState(&mX,&mY);
@ -175,6 +181,7 @@ void SFG_getMouseOffset(int16_t *x, int16_t *y)
SDL_WarpMouseInWindow(window,
SFG_SCREEN_RESOLUTION_X / 2, SFG_SCREEN_RESOLUTION_Y / 2);
}
#endif
}
@ -312,6 +319,8 @@ void mainLoopIteration()
}
else if (event.type == SDL_QUIT)
running = 0;
else if (event.type == SDL_MOUSEMOTION)
mouseMoved = 1;
}
sdlMouseButtonState = SDL_GetMouseState(NULL,NULL);
@ -428,8 +437,6 @@ int main(int argc, char *argv[])
puts("SDL: initializing SDL");
SFG_init();
window =
SDL_CreateWindow("raycasting", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SFG_SCREEN_RESOLUTION_X, SFG_SCREEN_RESOLUTION_Y,
@ -455,8 +462,6 @@ int main(int argc, char *argv[])
sdlKeyboardState = SDL_GetKeyboardState(NULL);
SDL_ShowCursor(0);
SDL_Init(SDL_INIT_AUDIO);
#if !SFG_OS_IS_MALWARE
@ -488,6 +493,15 @@ int main(int argc, char *argv[])
running = 1;
SDL_ShowCursor(0);
SFG_init();
SDL_PumpEvents();
SDL_WarpMouseInWindow(window,
SFG_SCREEN_RESOLUTION_X / 2, SFG_SCREEN_RESOLUTION_Y / 2);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(mainLoopIteration,0,1);
#else