#include "editor.h"
#include "files.h"
#include "tape.h"
+#include "cartoons.h"
#include "network.h"
/* 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)))
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)
- {
- /* 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;
}
}
}
}
+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())
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;
void HandleButton(int mx, int my, int button, int button_nr)
{
static int old_mx = 0, old_my = 0;
+ boolean button_hold = FALSE;
if (button < 0)
{
mx = old_mx;
my = old_my;
button = -button;
+ button_hold = TRUE;
}
else
{
}
#if defined(PLATFORM_ANDROID)
+ // !!! for now, do not handle gadgets when playing -- maybe fix this !!!
if (game_status != GAME_MODE_PLAYING &&
HandleGadgets(mx, my, button))
{
}
#endif
+ if (button_hold && game_status == GAME_MODE_PLAYING && tape.pausing)
+ return;
+
/* do not use scroll wheel button events for anything other than gadgets */
if (IS_WHEEL_BUTTON(button_nr))
return;
}
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);
default:
if (key == KSYM_Escape)
{
- game_status = GAME_MODE_MAIN;
+ SetGameStatus(GAME_MODE_MAIN);
+
DrawMainMenu();
return;
void HandleNoEvent()
{
- if (button_status && game_status != GAME_MODE_PLAYING)
+ // if (button_status && game_status != GAME_MODE_PLAYING)
+ if (button_status && (game_status != GAME_MODE_PLAYING || tape.pausing))
{
HandleButton(0, 0, -button_status, button_status);
}