Hello, I am working on porting my game to a fixed rate logic
model. It’s an R-Type style 2D game. I already have a
very playable game with all sorts of SDL goodiess and
effects, but it plays like crapola due to d-time style
sprite position interpolation.
What I am presenting here is two paragraphs of pseudo-code,
the first of which is my d-time model, and the second is
what I have so far in my Fixed Rate Logic model, but I
really don’t know what to do next, so I’d appreciate any
input from anyone! Including you, Mr. Olofson – you seem
to really have this topic down to a science!
I have rendered the following pseudo-code from my actual C++
source.
while(true)
{
check_keys_and_adjust_player_velocity();
/// sprite movement is based on d-time
/// so game runs fine at any framerate
advance_sprites_based_on_dtime();
if(create_new_enemy_timer.has_completed())
{
add_new_enemy();
create_new_enemy_timer.reset();
create_new_enemy_timer.start();
}
// Throttle framerate at 50 fps
// so it doesn’t bog down game logic
// and so it doesn’t cause game to hog
// all of CPU
if(screen.framerate() < 50)
{
screen.clear(BLACK);
background_picture.draw(screen);
sprite_manager.draw_all_sprites(screen);
weapon_and_shield_panel.draw(screen);
Game::mouse.draw(screen);
screen.update();
}
}
So I’m taking this model and trying to make a Fixed Rate
Logic model. This is all I can think of so far:
Uint32 logic_frequency = 100; // 100 Hz
// 1/100th of a second per logic frame
Timer logic_frame_period_timer;
logic_frame_period_timer.set(1 / logic_frequency);
logic_frame_period_timer.start();
while(true)
{
if(logic_frame_period_timer.is_done())
{
advance_game_logic_by_one_frame();
logic_frame_period_timer.reset();
logic_frame_period_timer.start();
}
/// ??? how do I incorporate the game render frame
/// routine???
///
/// ??? what if the game render framerate drops below
/// 30 fps???
}
Should I do my interpolation of sprite coordinates between
logic_frames based on the number of render_frames that
occur between one logic frame?
Or should I interpolate the coordinates based on the average
render_framerate in comparison to the number of
rendered_frames so far in one game logic cycle? If that
makes any sense?
Kindly Appreciated,
Paul Lowe