X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=4c71dca04ece48c1d1e0b436656b51234f4c5c90;hb=5d3436c34268fb35d378a39d9d825def453afbec;hp=42277b02e6c1947d5e0176b11657638aa68a7e49;hpb=f6bcc10ce7b517f04eb5cddf01c9ec29ee729b7e;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 42277b02..4c71dca0 100644 --- a/src/events.c +++ b/src/events.c @@ -19,6 +19,7 @@ #include "editor.h" #include "files.h" #include "tape.h" +#include "cartoons.h" #include "network.h" @@ -66,7 +67,7 @@ static int FilterEventsExt(const Event *event) /* do no reset mouse cursor before all pending events have been processed */ if (gfx.cursor_mode == cursor_mode_last && - ((effectiveGameStatus() == GAME_MODE_TITLE && + ((game_status == GAME_MODE_TITLE && gfx.cursor_mode == CURSOR_NONE) || (game_status == GAME_MODE_PLAYING && gfx.cursor_mode == CURSOR_PLAYFIELD))) @@ -153,12 +154,20 @@ boolean NextValidEvent(Event *event) void EventLoop(void) { + static unsigned int sync_frame_delay = 0; + unsigned int sync_frame_delay_value = GAME_FRAME_DELAY; + while (1) { if (PendingEvent()) /* got event */ { + // use separate frame delay counter to not reset main delay counter + unsigned int sync_frame_delay2 = 0; + unsigned int sync_frame_delay_value2 = sync_frame_delay_value; Event event; + ResetDelayCounter(&sync_frame_delay2); + while (NextValidEvent(&event)) { switch (event.type) @@ -204,11 +213,16 @@ void EventLoop(void) HandleOtherEvents(&event); break; } + + // do not handle events for longer than standard frame delay period + if (DelayReached(&sync_frame_delay2, sync_frame_delay_value2)) + break; } } - else + + // always handle non-event game actions for every game frame interval { - if (effectiveGameStatus() == GAME_MODE_TITLE) + if (game_status == GAME_MODE_TITLE) { /* when showing title screens, hide mouse pointer (if not moved) */ @@ -218,7 +232,8 @@ void EventLoop(void) SetMouseCursor(CURSOR_NONE); } } - else if (game_status == GAME_MODE_PLAYING && !tape.pausing) + else if (game_status == GAME_MODE_PLAYING && (!tape.pausing || + tape.single_step)) { /* when playing, display a special mouse pointer inside the playfield */ @@ -245,18 +260,14 @@ void EventLoop(void) has its own synchronization and is CPU friendly, too */ if (game_status == GAME_MODE_PLAYING) - { HandleGameActions(); - } - else - { - if (!PendingEvent()) /* delay only if no pending events */ - Delay(10); - } /* refresh window contents from drawing buffer, if needed */ BackToFront(); + if (game_status != GAME_MODE_PLAYING) + WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value); + if (game_status == GAME_MODE_QUIT) return; } @@ -407,9 +418,6 @@ void HandleButtonEvent(ButtonEvent *event) void HandleMotionEvent(MotionEvent *event) { - if (!PointerInWindow(window)) - return; /* window and pointer are on different screens */ - if (button_status == MB_RELEASED && game_status != GAME_MODE_EDITOR) return; @@ -1554,28 +1562,6 @@ void HandleKey(Key key, int key_status) } break; -#if 0 - case KSYM_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; -#endif - case KSYM_v: printf("::: currently using game engine version %d\n", game.engine_version); @@ -1591,7 +1577,8 @@ void HandleKey(Key key, int key_status) default: if (key == KSYM_Escape) { - game_status = GAME_MODE_MAIN; + SetGameStatus(GAME_MODE_MAIN); + DrawMainMenu(); return;