This allows simulation and other actions, such as camera movements, to
use different time steps. Now camera will move the same speed
regardless of the simulation time (eg. very low fps scenarios).
Furthermore, the maximum time step value is always respected and won't
be exceeded even though user adjusts the simulation speed to higher.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
int last_framecount = 0, last_step_count = 0;
unsigned long old_ticks, ticks = 0, last_frame_tick = 0;
unsigned long step_count = 0;
int last_framecount = 0, last_step_count = 0;
unsigned long old_ticks, ticks = 0, last_frame_tick = 0;
unsigned long step_count = 0;
- double time = 0, last_fps = 0, time_scale = 1, last_sps = 0;
+ double last_fps = 0, time_scale = 1, last_sps = 0;
+ double step_time = 0, true_time = 0;
list_for_each_entry_from(pl2, &planet->list, list) {
struct planet *ptmp;
if (!gravitize_planets(pl1, pl2,
list_for_each_entry_from(pl2, &planet->list, list) {
struct planet *ptmp;
if (!gravitize_planets(pl1, pl2,
continue;
ptmp = list_to_planet(pl2->list.prev);
continue;
ptmp = list_to_planet(pl2->list.prev);
- move_planet(pl1, time * time_scale);
+ move_planet(pl1, step_time);
- move_camera(&camera, time);
+ move_camera(&camera, true_time);
- if (poll_events(&screen, &camera, &time_scale, time))
+ if (poll_events(&screen, &camera, &time_scale, true_time))
return;
old_ticks = ticks;
ticks = gettime();
return;
old_ticks = ticks;
ticks = gettime();
- time = (ticks - old_ticks) / (1000.0 * 1000.0) ;
- time = MIN(time, 0.02);
+ true_time = (ticks - old_ticks) / (1000.0 * 1000.0) ;
+ step_time = true_time * time_scale;
+ step_time = MIN(step_time, 0.02);