X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=8c3be2c47229f15f6338e421383e754dc529f72b;hb=cdc3c940197937b0508a1eb7dcf44874951908b7;hp=e76026e17bfc68c3c468eedc59421fcdc08a1ff3;hpb=e0bf8eee0aec424593e68e37e35c6b6f120e4712;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index e76026e1..8c3be2c4 100644 --- a/src/events.c +++ b/src/events.c @@ -53,13 +53,42 @@ int FilterMouseMotionEvents(const Event *event) } /* skip mouse motion events without pressed button outside level editor */ - if (button_status == MB_RELEASED && game_status != GAME_MODE_EDITOR && - game_status != GAME_MODE_PLAYING) + if (button_status == MB_RELEASED && + game_status != GAME_MODE_EDITOR && game_status != GAME_MODE_PLAYING) return 0; else return 1; } +/* to prevent delay problems, skip mouse motion events if the very next + event is also a mouse motion event (and therefore effectively only + handling the last of a row of mouse motion events in the event queue) */ + +boolean SkipPressedMouseMotionEvent(const Event *event) +{ + /* nothing to do if the current event is not a mouse motion event */ + if (event->type != EVENT_MOTIONNOTIFY) + return FALSE; + + /* only skip motion events with pressed button outside level editor */ + if (button_status == MB_RELEASED || + game_status == GAME_MODE_EDITOR || game_status == GAME_MODE_PLAYING) + return FALSE; + + if (PendingEvent()) + { + Event next_event; + + PeekEvent(&next_event); + + /* if next event is also a mouse motion event, skip the current one */ + if (next_event.type == EVENT_MOTIONNOTIFY) + return TRUE; + } + + return FALSE; +} + /* this is only really needed for non-SDL targets to filter unwanted events; when using SDL with properly installed event filter, this function can be replaced with a simple "NextEvent()" call, but it doesn't hurt either */ @@ -68,9 +97,19 @@ static boolean NextValidEvent(Event *event) { while (PendingEvent()) { + boolean handle_this_event = FALSE; + NextEvent(event); if (FilterMouseMotionEvents(event)) + handle_this_event = TRUE; + +#if 1 + if (SkipPressedMouseMotionEvent(event)) + handle_this_event = FALSE; +#endif + + if (handle_this_event) return TRUE; } @@ -85,7 +124,7 @@ void EventLoop(void) { Event event; - if (NextValidEvent(&event)) + while (NextValidEvent(&event)) { switch(event.type) { @@ -112,7 +151,7 @@ void EventLoop(void) else { /* when playing, display a special mouse pointer inside the playfield */ - if (game_status == GAME_MODE_PLAYING) + if (game_status == GAME_MODE_PLAYING && !tape.pausing) { if (!playfield_cursor_set && cursor_inside_playfield && DelayReached(&playfield_cursor_delay, 1000)) @@ -283,6 +322,11 @@ void HandleButtonEvent(ButtonEvent *event) else button_status = MB_RELEASED; +#if 0 + printf("::: button %s\n", event->type == EVENT_BUTTONPRESS ? + "pressed" : "released"); +#endif + HandleButton(event->x, event->y, button_status); } @@ -298,6 +342,10 @@ void HandleMotionEvent(MotionEvent *event) motion_status = TRUE; +#if 0 + printf("::: %d, %d\n", event->x, event->y); +#endif + HandleButton(event->x, event->y, button_status); } @@ -347,6 +395,7 @@ void HandleFocusEvent(FocusChangeEvent *event) Delay(100); KeyboardAutoRepeatOffUnlessAutoplay(); } + if (old_joystick_status != -1) joystick.status = old_joystick_status; } @@ -411,36 +460,8 @@ void HandleButton(int mx, int my, int button) case GAME_MODE_PLAYING: #ifdef DEBUG - if (button == MB_RELEASED) - { - if (IN_GFX_SCREEN(mx, my)) - { - int sx = (mx - SX) / TILEX; - int sy = (my - SY) / TILEY; - int x = LEVELX(sx); - int y = LEVELY(sy); - - printf("INFO: SCREEN(%d, %d), LEVEL(%d, %d)\n", sx, sy, x, y); - - if (!IN_LEV_FIELD(x, y)) - break; - - printf(" Feld[%d][%d] == %d ('%s')\n", x,y, Feld[x][y], - element_info[Feld[x][y]].token_name); - printf(" Back[%d][%d] == %d\n", x,y, Back[x][y]); - printf(" Store[%d][%d] == %d\n", x,y, Store[x][y]); - printf(" Store2[%d][%d] == %d\n", x,y, Store2[x][y]); - printf(" StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]); - printf(" MovPos[%d][%d] == %d\n", x,y, MovPos[x][y]); - printf(" MovDir[%d][%d] == %d\n", x,y, MovDir[x][y]); - printf(" MovDelay[%d][%d] == %d\n", x,y, MovDelay[x][y]); - printf(" ChangeDelay[%d][%d] == %d\n", x,y, ChangeDelay[x][y]); - printf(" GfxElement[%d][%d] == %d\n", x,y, GfxElement[x][y]); - printf(" GfxAction[%d][%d] == %d\n", x,y, GfxAction[x][y]); - printf(" GfxFrame[%d][%d] == %d\n", x,y, GfxFrame[x][y]); - printf("\n"); - } - } + if (button == MB_PRESSED && !motion_status && IN_GFX_SCREEN(mx, my)) + DumpTile(LEVELX((mx - SX) / TILEX), LEVELY((my - SY) / TILEY)); #endif break; @@ -548,6 +569,10 @@ static void HandleKeysSpecial(Key key) { DumpBrush(); } + else if (is_string_suffix(cheat_input, ":DDB")) + { + DumpBrush_Small(); + } } } @@ -671,10 +696,13 @@ void HandleKey(Key key, int key_status) if (game_status == GAME_MODE_MAIN && key == setup.shortcut.toggle_pause) { +#if 1 + StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE); +#else if (setup.autorecord) TapeStartRecording(); -#if defined(PLATFORM_UNIX) +#if defined(NETWORK_AVALIABLE) if (options.network) SendToServer_StartPlaying(); else @@ -684,6 +712,7 @@ void HandleKey(Key key, int key_status) StopAnimation(); InitGame(); } +#endif return; } @@ -718,6 +747,7 @@ void HandleKey(Key key, int key_status) case GAME_MODE_INFO: switch(key) { + case KSYM_space: case KSYM_Return: if (game_status == GAME_MODE_MAIN) HandleMainMenu(0,0, 0,0, MB_MENU_CHOICE); @@ -764,6 +794,7 @@ void HandleKey(Key key, int key_status) case GAME_MODE_SCORES: switch(key) { + case KSYM_space: case KSYM_Return: case KSYM_Escape: game_status = GAME_MODE_MAIN; @@ -899,6 +930,11 @@ void HandleKey(Key key, int key_status) printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize); break; + case KSYM_v: + printf("::: currently using game engine version %d\n", + game.engine_version); + break; + #if 0 case KSYM_z: @@ -945,7 +981,7 @@ void HandleNoEvent() return; } -#if defined(PLATFORM_UNIX) +#if defined(NETWORK_AVALIABLE) if (options.network) HandleNetworking(); #endif