printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter());
#endif
-#if 1
- WaitUntilDelayReached(&anim_sync_frame_delay, anim_sync_frame_delay_value);
+ // global animations now synchronized with frame delay of screen update
anim_sync_frame++;
-#else
- if (DelayReached(&anim_sync_frame_delay, anim_sync_frame_delay_value))
- anim_sync_frame++;
-#endif
for (i = 0; i < NUM_GAME_MODES; i++)
HandleGlobalAnim(ANIM_CONTINUE, i);
void EventLoop(void)
{
- unsigned int sync_frame_delay = 0;
- unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
-
while (1)
{
if (PendingEvent())
if (game_status == GAME_MODE_PLAYING)
HandleGameActions();
- /* refresh window contents from drawing buffer, if needed */
+ /* always copy backbuffer to visible screen for every video frame */
BackToFront();
- if (game_status != GAME_MODE_PLAYING)
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
+ /* reset video frame delay to default (may change again while playing) */
+ SetVideoFrameDelay(GAME_FRAME_DELAY);
if (game_status == GAME_MODE_QUIT)
return;
void DrawRelocateScreen(int old_x, int old_y, int x, int y, int move_dir,
boolean center_screen, boolean quick_relocation)
{
+ unsigned int frame_delay_value_old = GetVideoFrameDelay();
boolean ffwd_delay = (tape.playing && tape.fast_forward);
boolean no_delay = (tape.warp_forward);
int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
+ SetVideoFrameDelay(wait_delay_value);
+
while (scroll_x != new_scroll_x || scroll_y != new_scroll_y)
{
int dx = 0, dy = 0;
/* scroll in two steps of half tile size to make things smoother */
BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
- Delay(wait_delay_value);
/* scroll second step to align at full tile size */
- BackToFront();
- Delay(wait_delay_value);
+ BlitScreenToBitmap(window);
}
DrawAllPlayers();
BackToFront();
- Delay(wait_delay_value);
+
+ SetVideoFrameDelay(frame_delay_value_old);
}
void RelocatePlayer(int jx, int jy, int el_player_raw)
DrawPlayer(player);
- BackToFront();
- Delay(wait_delay_value);
+ BackToFront_WithFrameDelay(wait_delay_value);
}
DrawPlayer(player); /* needed here only to cleanup last field */
void GameActions()
{
+#if 0
static unsigned int game_frame_delay = 0;
+#endif
unsigned int game_frame_delay_value;
byte *recorded_player_action;
byte summarized_player_action = 0;
if (tape.playing && tape.warp_forward && !tape.pausing)
game_frame_delay_value = 0;
+ SetVideoFrameDelay(game_frame_delay_value);
+
+#if 0
#if 0
/* ---------- main game synchronization point ---------- */
/* ---------- main game synchronization point ---------- */
WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
+#endif
#endif
if (network_playing && !network_player_action_received)
AdvanceFrameAndPlayerCounters(player->index_nr);
DrawAllPlayers();
- BackToFront();
+ BackToFront_WithFrameDelay(0);
}
player->move_delay_value = original_move_delay_value;
SDL_SetRenderTarget(sdl_renderer, NULL);
SDL_RenderCopy(sdl_renderer, sdl_texture_target, NULL, NULL);
}
+#endif
- // show render target buffer on screen
- SDL_RenderPresent(sdl_renderer);
+ // global synchronization point of the game to align video frame delay
+ WaitUntilDelayReached(&video.frame_delay, video.frame_delay_value);
+#if defined(TARGET_SDL2)
+ // show render target buffer on screen
+ SDL_RenderPresent(sdl_renderer);
#else // TARGET_SDL
if (rect)
SDL_UpdateRects(screen, 1, rect);
while (time_current < time_post_delay)
{
- // do not wait longer than 10 ms at a time to be able to ...
- Delay(MIN(10, time_post_delay - time_current));
-
- // ... continue drawing global animations during post delay
+ // updating the screen contains waiting for frame delay (non-busy)
UpdateScreen(NULL);
time_current = SDL_GetTicks();
video.window_scaling_available = WINDOW_SCALING_STATUS;
+ video.frame_delay = 0;
+ video.frame_delay_value = GAME_FRAME_DELAY;
+
SDLInitVideoBuffer(fullscreen);
video.initialized = TRUE;
return SDLSetVideoMode(fullscreen);
}
+void SetVideoFrameDelay(unsigned int frame_delay_value)
+{
+ video.frame_delay_value = frame_delay_value;
+}
+
+unsigned int GetVideoFrameDelay()
+{
+ return video.frame_delay_value;
+}
+
boolean ChangeVideoModeIfNeeded(boolean fullscreen)
{
if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
char *window_scaling_quality;
int screen_rendering_mode;
+ unsigned int frame_delay;
+ unsigned int frame_delay_value;
+
boolean initialized;
};
void KeyboardAutoRepeatOn(void);
void KeyboardAutoRepeatOff(void);
boolean SetVideoMode(boolean);
+void SetVideoFrameDelay(unsigned int);
+unsigned int GetVideoFrameDelay();
boolean ChangeVideoModeIfNeeded(boolean);
Bitmap *LoadImage(char *);
static TreeInfo *level_number = NULL;
static TreeInfo *level_number_current = NULL;
-static unsigned int sync_frame_delay = 0;
-static unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
-
static struct
{
int value;
DoAnimation();
BackToFront();
-
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
}
return key;
DoAnimation();
BackToFront();
-
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
}
/* write new key bindings back to player setup */
DoAnimation();
BackToFront();
-
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
}
/* calibrated center position (joystick should now be centered) */
NextEvent(&event);
HandleOtherEvents(&event);
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
+ BackToFront();
}
}
static struct GadgetInfo *tool_gadget[NUM_TOOL_BUTTONS];
static int request_gadget_id = -1;
-static unsigned int sync_frame_delay = 0;
-static unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
-
static char *print_if_not_empty(int element)
{
static char *s = NULL;
#endif
}
+void BackToFront_WithFrameDelay(unsigned int frame_delay_value)
+{
+ unsigned int frame_delay_value_old = GetVideoFrameDelay();
+
+ SetVideoFrameDelay(frame_delay_value);
+
+ BackToFront();
+
+ SetVideoFrameDelay(frame_delay_value_old);
+}
+
static void FadeCrossSaveBackbuffer()
{
BlitBitmap(backbuffer, bitmap_db_cross, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
DoAnimation();
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
+ BackToFront();
}
}
}
BackToFront();
-
- WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
}
return result;
void BlitScreenToBitmap_RND(Bitmap *);
void BlitScreenToBitmap(Bitmap *);
void BackToFront();
+void BackToFront_WithFrameDelay(unsigned int);
void FadeIn(int);
void FadeOut(int);