Re: Performance problem after saving game
Reply #4 –
Well, old code looks like that:
uint32 last_ms = dr_time();
last_frame_ms[last_frame_idx] = last_ms;
last_frame_idx = (last_frame_idx+1) % 32;
if(last_frame_ms[last_frame_idx]<last_ms) {
realFPS = (32000u) / (last_ms-last_frame_ms[last_frame_idx]);
}
else {
realFPS = umgebung_t::fps;
simloops = 60;
}
if(last_frame_ms[last_frame_idx]<last_ms) { this probably was meant to refer to previous frame, but due to last_frame_idx = (last_frame_idx+1) % 32; in previous line actually refers to first recorded and still remaining frame. As frames are not updated during save, this frame refers to really ancient time (like 20 seconds in past), resulting in 0 FPS. As RealFPS is related with refreshing of last_frame_ms, game takes hard time to redo it and as result lags for quite a time.
Probably, this would still be good, as long as saving routine (or other long-blockers) would reset entire last_frame_ms table. Map enlarger do so
// make timer loop invalid
for( int i=0; i<32; i++ ) {
last_frame_ms[i] = 0x7FFFFFFFu;
last_step_nr[i] = 0xFFFFFFFFu;
}
last_frame_idx = 0;
for a reason (?)
Your reset_timer() is indeed required, but unfortunately, it doesn't fix the bug