X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=d9104aa1be04172a8d64bc8be39b3afd8c57fb46;hb=b2c07ef9208b06f07e8d45fdddbffd8db721a02d;hp=5f80c5debc113399c863909fe0d9ccf7086b54f1;hpb=1eb84ec23ba8db3b68f373d6077a6e923e244e35;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 5f80c5de..d9104aa1 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))) @@ -151,115 +152,63 @@ boolean NextValidEvent(Event *event) return FALSE; } -void EventLoop(void) +void HandleEvents() { - while (1) + Event event; + unsigned int event_frame_delay = 0; + unsigned int event_frame_delay_value = GAME_FRAME_DELAY; + + ResetDelayCounter(&event_frame_delay); + + while (NextValidEvent(&event)) { - if (PendingEvent()) /* got event */ + switch (event.type) { - Event event; + case EVENT_BUTTONPRESS: + case EVENT_BUTTONRELEASE: + HandleButtonEvent((ButtonEvent *) &event); + break; - while (NextValidEvent(&event)) - { - switch (event.type) - { - case EVENT_BUTTONPRESS: - case EVENT_BUTTONRELEASE: - HandleButtonEvent((ButtonEvent *) &event); - break; - - case EVENT_MOTIONNOTIFY: - HandleMotionEvent((MotionEvent *) &event); - break; + case EVENT_MOTIONNOTIFY: + HandleMotionEvent((MotionEvent *) &event); + break; #if defined(TARGET_SDL2) - case SDL_WINDOWEVENT: - HandleWindowEvent((WindowEvent *) &event); - break; - - case EVENT_FINGERPRESS: - case EVENT_FINGERRELEASE: - case EVENT_FINGERMOTION: - HandleFingerEvent((FingerEvent *) &event); - break; - - case EVENT_TEXTINPUT: - HandleTextEvent((TextEvent *) &event); - break; - - case SDL_APP_WILLENTERBACKGROUND: - case SDL_APP_DIDENTERBACKGROUND: - case SDL_APP_WILLENTERFOREGROUND: - case SDL_APP_DIDENTERFOREGROUND: - HandlePauseResumeEvent((PauseResumeEvent *) &event); - break; -#endif - - case EVENT_KEYPRESS: - case EVENT_KEYRELEASE: - HandleKeyEvent((KeyEvent *) &event); - break; - - default: - HandleOtherEvents(&event); - break; - } - } - } - else - { - if (effectiveGameStatus() == GAME_MODE_TITLE) - { - /* when showing title screens, hide mouse pointer (if not moved) */ - - if (gfx.cursor_mode != CURSOR_NONE && - DelayReached(&special_cursor_delay, special_cursor_delay_value)) - { - SetMouseCursor(CURSOR_NONE); - } - } - else if (game_status == GAME_MODE_PLAYING && (!tape.pausing || - tape.single_step)) - { - /* when playing, display a special mouse pointer inside the playfield */ + case SDL_WINDOWEVENT: + HandleWindowEvent((WindowEvent *) &event); + break; - if (gfx.cursor_mode != CURSOR_PLAYFIELD && - cursor_inside_playfield && - DelayReached(&special_cursor_delay, special_cursor_delay_value)) - { - SetMouseCursor(CURSOR_PLAYFIELD); - } - } - else if (gfx.cursor_mode != CURSOR_DEFAULT) - { - SetMouseCursor(CURSOR_DEFAULT); - } + case EVENT_FINGERPRESS: + case EVENT_FINGERRELEASE: + case EVENT_FINGERMOTION: + HandleFingerEvent((FingerEvent *) &event); + break; - /* this is set after all pending events have been processed */ - cursor_mode_last = gfx.cursor_mode; - } + case EVENT_TEXTINPUT: + HandleTextEvent((TextEvent *) &event); + break; - /* also execute after pending events have been processed before */ - HandleNoEvent(); + case SDL_APP_WILLENTERBACKGROUND: + case SDL_APP_DIDENTERBACKGROUND: + case SDL_APP_WILLENTERFOREGROUND: + case SDL_APP_DIDENTERFOREGROUND: + HandlePauseResumeEvent((PauseResumeEvent *) &event); + break; +#endif - /* don't use all CPU time when idle; the main loop while playing - has its own synchronization and is CPU friendly, too */ + case EVENT_KEYPRESS: + case EVENT_KEYRELEASE: + HandleKeyEvent((KeyEvent *) &event); + break; - if (game_status == GAME_MODE_PLAYING) - { - HandleGameActions(); - } - else - { - if (!PendingEvent()) /* delay only if no pending events */ - Delay(10); + default: + HandleOtherEvents(&event); + break; } - /* refresh window contents from drawing buffer, if needed */ - BackToFront(); - - if (game_status == GAME_MODE_QUIT) - return; + // do not handle events for longer than standard frame delay period + if (DelayReached(&event_frame_delay, event_frame_delay_value)) + break; } } @@ -305,6 +254,71 @@ void HandleOtherEvents(Event *event) } } +void HandleMouseCursor() +{ + if (game_status == GAME_MODE_TITLE) + { + /* when showing title screens, hide mouse pointer (if not moved) */ + + if (gfx.cursor_mode != CURSOR_NONE && + DelayReached(&special_cursor_delay, special_cursor_delay_value)) + { + SetMouseCursor(CURSOR_NONE); + } + } + else if (game_status == GAME_MODE_PLAYING && (!tape.pausing || + tape.single_step)) + { + /* when playing, display a special mouse pointer inside the playfield */ + + if (gfx.cursor_mode != CURSOR_PLAYFIELD && + cursor_inside_playfield && + DelayReached(&special_cursor_delay, special_cursor_delay_value)) + { + SetMouseCursor(CURSOR_PLAYFIELD); + } + } + else if (gfx.cursor_mode != CURSOR_DEFAULT) + { + SetMouseCursor(CURSOR_DEFAULT); + } + + /* this is set after all pending events have been processed */ + cursor_mode_last = gfx.cursor_mode; +} + +void EventLoop(void) +{ + unsigned int sync_frame_delay = 0; + unsigned int sync_frame_delay_value = GAME_FRAME_DELAY; + + while (1) + { + if (PendingEvent()) + HandleEvents(); + else + HandleMouseCursor(); + + /* also execute after pending events have been processed before */ + 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 == GAME_MODE_PLAYING) + HandleGameActions(); + + /* 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; + } +} + void ClearEventQueue() { while (PendingEvent()) @@ -1567,7 +1581,8 @@ void HandleKey(Key key, int key_status) default: if (key == KSYM_Escape) { - game_status = GAME_MODE_MAIN; + SetGameStatus(GAME_MODE_MAIN); + DrawMainMenu(); return;