forked from 0ad/0ad
timer.cpp: start FPS value = 60 => faster convergence
timer.h: TIMER uses debug_out main/input: moved game_ticks to input.cpp (only used if input.cpp is included) This was SVN commit r1653.
This commit is contained in:
parent
f7e82dbc16
commit
2077d4fd1d
@ -79,7 +79,7 @@ state = INIT;
|
||||
|
||||
static FILE* f;
|
||||
|
||||
extern u32 game_ticks;
|
||||
u32 game_ticks;
|
||||
|
||||
static u32 time_adjust = 0;
|
||||
static u32 next_event_time;
|
||||
|
@ -112,13 +112,13 @@ int fps;
|
||||
|
||||
void calc_fps()
|
||||
{
|
||||
static double avg_fps = 30.0;
|
||||
static double avg_fps = 60.0;
|
||||
double cur_fps = avg_fps;
|
||||
|
||||
// get elapsed time [s] since last update
|
||||
static double last_t;
|
||||
const double t = get_time();
|
||||
ONCE(last_t = t - 33e-3); // first call: 30 FPS
|
||||
ONCE(last_t = t - 1.0/60.0); // first call: 60 FPS
|
||||
const double dt = t - last_t;
|
||||
|
||||
// (in case timer resolution is low): count frames until
|
||||
@ -229,5 +229,7 @@ void calc_fps()
|
||||
const double difference = fabs(avg_fps-fps);
|
||||
const double threshold = fminf(5.f, 0.05f*fps);
|
||||
if(difference > threshold)
|
||||
fps = (int)avg_fps;
|
||||
fps = (int)(avg_fps + 0.99);
|
||||
// C float -> int rounds down; we want to round up to
|
||||
// hit vsync-locked framerates exactly.
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include "sysdep/debug.h" // debug_out
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -67,7 +69,7 @@ public:
|
||||
else if(dt > 1e-3)
|
||||
scale = 1e3, unit = 'm';
|
||||
|
||||
printf("TIMER %s: %g %cs\n", name.c_str(), dt*scale, unit);
|
||||
debug_out("TIMER %s: %g %cs\n", name.c_str(), dt*scale, unit);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -84,8 +84,6 @@ extern int conInputHandler(const SDL_Event* ev);
|
||||
|
||||
// Globals
|
||||
|
||||
u32 game_ticks;
|
||||
|
||||
bool keys[SDLK_LAST];
|
||||
bool mouseButtons[5];
|
||||
int mouse_x=50, mouse_y=50;
|
||||
@ -961,6 +959,7 @@ static void Shutdown()
|
||||
vfs_shutdown();
|
||||
|
||||
h_mgr_shutdown();
|
||||
mem_shutdown();
|
||||
}
|
||||
|
||||
static void Init(int argc, char* argv[])
|
||||
|
Loading…
Reference in New Issue
Block a user