Browse Source

Fix mouse bug

merge-requests/2/head
Miloslav Číž 2 years ago
parent
commit
5ca8581e04
  1. 2
      TODO.txt
  2. 22
      main_sdl.c

2
TODO.txt

@ -199,6 +199,8 @@ done: @@ -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?

22
main_sdl.c

@ -163,9 +163,15 @@ void webButton(uint8_t key, uint8_t down) @@ -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) @@ -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() @@ -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[]) @@ -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[]) @@ -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[]) @@ -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

Loading…
Cancel
Save