void rct2_loop() { int last_tick = 0; _finished = 0; do { if (SDL_GetTicks() - last_tick < 25) continue; last_tick = SDL_GetTicks(); osinterface_process_messages(); rct2_update(); osinterface_draw(); } while (!_finished); }
static void RunFixedFrame() { _uncapTick = 0; uint32 currentTick = SDL_GetTicks(); uint32 ticksElapsed = currentTick - _lastTick; if (ticksElapsed < UPDATE_TIME_MS) { SDL_Delay(UPDATE_TIME_MS - ticksElapsed); _lastTick += UPDATE_TIME_MS; } else { _lastTick = currentTick; } platform_process_messages(); rct2_update(); if (!_isWindowMinimised) { platform_draw(); } }
static void RunVariableFrame() { uint32 currentTick = SDL_GetTicks(); if (_uncapTick == 0) { _uncapTick = currentTick; sprite_position_tween_reset(); } // Limit number of updates per loop (any long pauses or debugging can make this update for a very long time) if (currentTick - _uncapTick > UPDATE_TIME_MS * 60) { _uncapTick = currentTick - UPDATE_TIME_MS - 1; } platform_process_messages(); while (_uncapTick <= currentTick && currentTick - _uncapTick > UPDATE_TIME_MS) { // Get the original position of each sprite sprite_position_tween_store_a(); // Update the game so the sprite positions update rct2_update(); // Get the next position of each sprite sprite_position_tween_store_b(); _uncapTick += UPDATE_TIME_MS; } // Tween the position of each sprite from the last position to the new position based on the time between the last // tick and the next tick. float nudge = 1 - ((float)(currentTick - _uncapTick) / UPDATE_TIME_MS); sprite_position_tween_all(nudge); platform_draw(); sprite_position_tween_restore(); }
/** * Run the main game loop until the finished flag is set at 40fps (25ms interval). */ static void openrct2_loop() { uint32 currentTick, ticksElapsed, lastTick = 0; static uint32 uncapTick = 0; static int fps = 0; static uint32 secondTick = 0; log_verbose("begin openrct2 loop"); _finished = 0; do { if (gConfigGeneral.uncap_fps && gGameSpeed <= 4) { currentTick = SDL_GetTicks(); if (uncapTick == 0) { // Reset sprite locations uncapTick = SDL_GetTicks(); openrct2_reset_object_tween_locations(); } // Limit number of updates per loop (any long pauses or debugging can make this update for a very long time) if (currentTick - uncapTick > 25 * 60) { uncapTick = currentTick - 25 - 1; } platform_process_messages(); while (uncapTick <= currentTick && currentTick - uncapTick > 25) { // Get the original position of each sprite for (uint16 i = 0; i < MAX_SPRITES; i++) { _spritelocations1[i].x = g_sprite_list[i].unknown.x; _spritelocations1[i].y = g_sprite_list[i].unknown.y; _spritelocations1[i].z = g_sprite_list[i].unknown.z; } // Update the game so the sprite positions update rct2_update(); // Get the next position of each sprite for (uint16 i = 0; i < MAX_SPRITES; i++) { _spritelocations2[i].x = g_sprite_list[i].unknown.x; _spritelocations2[i].y = g_sprite_list[i].unknown.y; _spritelocations2[i].z = g_sprite_list[i].unknown.z; } uncapTick += 25; } // Tween the position of each sprite from the last position to the new position based on the time between the last // tick and the next tick. float nudge = 1 - ((float)(currentTick - uncapTick) / 25); for (uint16 i = 0; i < MAX_SPRITES; i++) { if (!sprite_should_tween(&g_sprite_list[i])) continue; sprite_move( _spritelocations2[i].x + (sint16)((_spritelocations1[i].x - _spritelocations2[i].x) * nudge), _spritelocations2[i].y + (sint16)((_spritelocations1[i].y - _spritelocations2[i].y) * nudge), _spritelocations2[i].z + (sint16)((_spritelocations1[i].z - _spritelocations2[i].z) * nudge), &g_sprite_list[i] ); invalidate_sprite_2(&g_sprite_list[i]); } if ((SDL_GetWindowFlags(gWindow) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_HIDDEN)) == 0) { rct2_draw(); platform_draw(); } fps++; if (SDL_GetTicks() - secondTick >= 1000) { fps = 0; secondTick = SDL_GetTicks(); } // Restore the real positions of the sprites so they aren't left at the mid-tween positions for (uint16 i = 0; i < MAX_SPRITES; i++) { if (!sprite_should_tween(&g_sprite_list[i])) continue; invalidate_sprite_2(&g_sprite_list[i]); sprite_move(_spritelocations2[i].x, _spritelocations2[i].y, _spritelocations2[i].z, &g_sprite_list[i]); } network_update(); } else { uncapTick = 0; currentTick = SDL_GetTicks(); ticksElapsed = currentTick - lastTick; if (ticksElapsed < 25) { if (ticksElapsed < 15) SDL_Delay(15 - ticksElapsed); continue; } lastTick = currentTick; platform_process_messages(); rct2_update(); if ((SDL_GetWindowFlags(gWindow) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_HIDDEN)) == 0) { rct2_draw(); platform_draw(); } } } while (!_finished); }