X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=9f84cc207126b5ce4d7f2d52053061fc9faa623c;hb=7d958613de0b14e460ebca1a651b73cfadf9213c;hp=85ae4d61f86c4da85ef41f9ce473d454b3918075;hpb=b9c7e4a42762c8526702726f1404d3e75dbc29f5;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 85ae4d61..9f84cc20 100644 --- a/src/events.c +++ b/src/events.c @@ -28,6 +28,23 @@ #define KEY_RELEASED FALSE #define KEY_PRESSED TRUE + +/* event filter especially needed for SDL event filtering due to + delay problems with lots of mouse motion events when mouse + button not pressed */ + +int FilterMouseMotionEvents(const Event *event) +{ + if (event->type != EVENT_MOTIONNOTIFY) + return 1; + + /* get mouse motion events without pressed button only in level editor */ + if (button_status == MB_RELEASED && game_status != LEVELED) + return 0; + else + return 1; +} + void EventLoop(void) { while(1) @@ -38,34 +55,39 @@ void EventLoop(void) NextEvent(&event); - switch(event.type) + if (FilterMouseMotionEvents(&event)) { - case EVENT_BUTTONPRESS: - case EVENT_BUTTONRELEASE: - HandleButtonEvent((ButtonEvent *) &event); - break; - - case EVENT_MOTIONNOTIFY: - HandleMotionEvent((MotionEvent *) &event); - break; - - case EVENT_KEYPRESS: - case EVENT_KEYRELEASE: - HandleKeyEvent((KeyEvent *) &event); - break; - - default: - HandleOtherEvents(&event); - break; + switch(event.type) + { + case EVENT_BUTTONPRESS: + case EVENT_BUTTONRELEASE: + HandleButtonEvent((ButtonEvent *) &event); + break; + + case EVENT_MOTIONNOTIFY: + HandleMotionEvent((MotionEvent *) &event); + break; + + case EVENT_KEYPRESS: + case EVENT_KEYRELEASE: + HandleKeyEvent((KeyEvent *) &event); + break; + + default: + HandleOtherEvents(&event); + break; + } } } - - HandleNoXEvent(); + else + HandleNoEvent(); /* don't use all CPU time when idle; the main loop while playing has its own synchronization and is CPU friendly, too */ - if (game_status != PLAYING) + if (game_status == PLAYING) + HandleGameActions(); + else { SyncDisplay(); if (!PendingEvent()) /* delay only if no pending events */ @@ -101,6 +123,14 @@ void HandleOtherEvents(Event *event) HandleClientMessageEvent((ClientMessageEvent *) event); break; +#ifdef USE_SDL_JOYSTICK + case SDL_JOYAXISMOTION: + case SDL_JOYBUTTONDOWN: + case SDL_JOYBUTTONUP: + HandleJoystickEvent(event); + break; +#endif + default: break; } @@ -176,6 +206,7 @@ void SleepWhileUnmapped() void HandleExposeEvent(ExposeEvent *event) { +#ifndef USE_SDL_LIBRARY int x = event->x, y = event->y; int width = event->width, height = event->height; @@ -209,6 +240,7 @@ void HandleExposeEvent(ExposeEvent *event) BlitBitmap(drawto, window, x,y, width,height, x,y); FlushDisplay(); +#endif } void HandleButtonEvent(ButtonEvent *event) @@ -225,17 +257,17 @@ void HandleButtonEvent(ButtonEvent *event) void HandleMotionEvent(MotionEvent *event) { - int win_x, win_y; - - if (!QueryPointer(window, &win_x, &win_y)) + if (!PointerInWindow(window)) return; /* window and pointer are on different screens */ - if (!button_status && game_status != LEVELED) +#if 1 + if (button_status == MB_RELEASED && game_status != LEVELED) return; +#endif motion_status = TRUE; - HandleButton(win_x, win_y, button_status); + HandleButton(event->x, event->y, button_status); } void HandleKeyEvent(KeyEvent *event) @@ -394,6 +426,7 @@ void HandleButton(int mx, int my, int button) void HandleKey(Key key, int key_status) { int joy = 0; + boolean anyTextGadgetActiveOrJustFinished = anyTextGadgetActive(); static struct SetupKeyboardInfo custom_key; static struct { @@ -557,7 +590,8 @@ void HandleKey(Key key, int key_status) break; case LEVELED: - HandleLevelEditorKeyInput(key); + if (!anyTextGadgetActiveOrJustFinished) + HandleLevelEditorKeyInput(key); break; case PLAYING: @@ -589,6 +623,38 @@ void HandleKey(Key key, int key_status) GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay); break; + case KEY_d: + if (options.debug) + { + options.debug = FALSE; + printf("debug mode disabled\n"); + } + else + { + options.debug = TRUE; + printf("debug mode enabled\n"); + } + break; + + case KEY_s: + if (!global.fps_slowdown) + { + global.fps_slowdown = TRUE; + global.fps_slowdown_factor = 2; + printf("fps slowdown enabled -- display only every 2nd frame\n"); + } + else if (global.fps_slowdown_factor == 2) + { + global.fps_slowdown_factor = 4; + printf("fps slowdown enabled -- display only every 4th frame\n"); + } + else + { + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; + printf("fps slowdown disabled\n"); + } + break; #if 0 case KEY_a: @@ -676,7 +742,7 @@ void HandleKey(Key key, int key_status) } } -void HandleNoXEvent() +void HandleNoEvent() { if (button_status && game_status != PLAYING) { @@ -684,15 +750,12 @@ void HandleNoXEvent() return; } -#ifndef MSDOS +#if !defined(MSDOS) && !defined(WIN32) if (options.network) HandleNetworking(); #endif HandleJoystick(); - - if (game_status == PLAYING) - HandleGameActions(); } static int HandleJoystickForAllPlayers()