@@ -63,36 +63,36 @@ void DebugFps::TickGame(float deltams) | |||
#if 0 | |||
sprintf(buf, "%2.2f fps (%i)", | |||
1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
Ticker::GetFrameNum()); | |||
data->lines[0]->SetText(buf); | |||
sprintf(buf, "Game % 7.2f % 7.2f", | |||
Profiler::GetAvg(Profiler::STAT_TICK_GAME), | |||
Profiler::GetMax(Profiler::STAT_TICK_GAME)); | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME), | |||
1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME)); | |||
data->lines[1]->SetText(buf); | |||
sprintf(buf, "Draw % 7.2f % 7.2f", | |||
Profiler::GetAvg(Profiler::STAT_TICK_DRAW), | |||
Profiler::GetMax(Profiler::STAT_TICK_DRAW)); | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW), | |||
1e3f * Profiler::GetMax(Profiler::STAT_TICK_DRAW)); | |||
data->lines[2]->SetText(buf); | |||
sprintf(buf, "Blit % 7.2f % 7.2f", | |||
Profiler::GetAvg(Profiler::STAT_TICK_BLIT), | |||
Profiler::GetMax(Profiler::STAT_TICK_BLIT)); | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT), | |||
1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT)); | |||
data->lines[3]->SetText(buf); | |||
sprintf(buf, "Frame % 7.2f % 7.2f", | |||
Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
Profiler::GetMax(Profiler::STAT_TICK_FRAME)); | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME)); | |||
data->lines[4]->SetText(buf); | |||
#else | |||
sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)", | |||
Profiler::GetAvg(Profiler::STAT_TICK_GAME), | |||
Profiler::GetAvg(Profiler::STAT_TICK_DRAW), | |||
Profiler::GetAvg(Profiler::STAT_TICK_BLIT), | |||
Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME), | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW), | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT), | |||
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||
Ticker::GetFrameNum()); | |||
data->lines[0]->SetText(buf); | |||
#endif | |||
@@ -51,14 +51,14 @@ data[Profiler::STAT_COUNT]; | |||
void Profiler::Start(int id) | |||
{ | |||
data[id].timer.GetMs(); | |||
data[id].timer.Get(); | |||
} | |||
void Profiler::Stop(int id) | |||
{ | |||
float deltams = data[id].timer.GetMs(); | |||
float seconds = data[id].timer.Get(); | |||
data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams; | |||
data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds; | |||
data[id].avg = 0.0f; | |||
data[id].max = 0.0f; | |||
@@ -188,7 +188,7 @@ void *TickerData::GameThreadMain(void *p) | |||
} | |||
else | |||
{ | |||
data->deltams = data->timer.GetMs(); | |||
data->deltams = 1000.0f * data->timer.Get(); | |||
data->bias += data->deltams; | |||
} | |||
@@ -396,7 +396,7 @@ void Ticker::TickDraw() | |||
if (framems > data->bias + 200.0f) | |||
framems = data->bias + 200.0f; // Don't go below 5 fps | |||
if (framems > data->bias) | |||
data->timer.WaitMs(framems - data->bias); | |||
data->timer.Wait(1e-3f * (framems - data->bias)); | |||
/* If recording, do not try to compensate for lag. */ | |||
if (!data->recording) | |||
@@ -62,64 +62,64 @@ private: | |||
#endif | |||
} | |||
float GetOrWait(float deltams, bool update) | |||
float GetOrWait(float seconds, bool update) | |||
{ | |||
float ret, towait; | |||
float secs_elapsed, secs_towait; | |||
#if defined __linux__ || defined __native_client__ || defined __APPLE__ | |||
struct timeval tv; | |||
gettimeofday(&tv, NULL); | |||
ret = 1e-3f * (tv.tv_usec - tv0.tv_usec) | |||
+ 1e3f * (tv.tv_sec - tv0.tv_sec); | |||
secs_elapsed = 1e-6f * (tv.tv_usec - tv0.tv_usec) | |||
+ (tv.tv_sec - tv0.tv_sec); | |||
if (update) | |||
tv0 = tv; | |||
towait = deltams - ret; | |||
if (towait > 0.0f) | |||
usleep((int)(towait * 1e3f)); | |||
secs_towait = seconds - secs_elapsed; | |||
if (secs_towait > 0.0f) | |||
usleep((int)(secs_towait * 1e6f)); | |||
#elif defined _WIN32 | |||
LARGE_INTEGER cycles; | |||
QueryPerformanceCounter(&cycles); | |||
static float ms_per_cycle = GetMsPerCycle(); | |||
ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart); | |||
static float secs_per_cycle = GetSecondsPerCycle(); | |||
secs_elapsed = secs_per_cycle * (cycles.QuadPart - cycles0.QuadPart); | |||
if (update) | |||
cycles0 = cycles; | |||
towait = deltams - ret; | |||
if (towait > 5e-4f) | |||
Sleep((int)(towait + 0.5f)); | |||
secs_towait = seconds - secs_elapsed; | |||
if (secs_towait > 5e-4f) | |||
Sleep((int)(secs_towait * 1e3f + 0.5f)); | |||
#elif defined __CELLOS_LV2__ | |||
uint64_t cycles; | |||
SYS_TIMEBASE_GET(cycles); | |||
static float ms_per_cycle = GetMsPerCycle(); | |||
ret = ms_per_cycle * (cycles - cycles0); | |||
static float secs_per_cycle = GetSecondsPerCycle(); | |||
secs_elapsed = secs_per_cycle * (cycles - cycles0); | |||
if (update) | |||
cycles0 = cycles; | |||
towait = deltams - ret; | |||
if (towait > 0.0f) | |||
sys_timer_usleep((int)(towait * 1e3f)); | |||
secs_towait = seconds - secs_elapsed; | |||
if (secs_towait > 0.0f) | |||
sys_timer_usleep((int)(secs_towait * 1e6f)); | |||
#else | |||
/* The crappy SDL fallback */ | |||
Uint32 ticks = SDL_GetTicks(); | |||
ret = ticks - ticks0; | |||
secs_elapsed = 1e-3f * (ticks - ticks0); | |||
if (update) | |||
ticks0 = ticks; | |||
towait = deltams - ret; | |||
if (towait > 0.5f) | |||
SDL_Delay((int)(towait + 0.5f)); | |||
secs_towait = seconds - secs_elapsed; | |||
if (secs_towait > 5e-4f) | |||
SDL_Delay((int)(secs_towait * 1e3f + 0.5f)); | |||
#endif | |||
return ret; | |||
return secs_elapsed; | |||
} | |||
static float GetMsPerCycle() | |||
static float GetSecondsPerCycle() | |||
{ | |||
#if defined __linux__ || defined __native_client__ || defined __APPLE__ | |||
return 1.0f; | |||
return 1e-3f; | |||
#elif defined _WIN32 | |||
LARGE_INTEGER tmp; | |||
QueryPerformanceFrequency(&tmp); | |||
return 1e3f / tmp.QuadPart; | |||
return 1.f / tmp.QuadPart; | |||
#elif defined __CELLOS_LV2__ | |||
return 1e3f / sys_time_get_timebase_frequency(); | |||
return 1.f / sys_time_get_timebase_frequency(); | |||
#else | |||
return 1.0f; | |||
return 1e-3f; | |||
#endif | |||
} | |||
@@ -148,19 +148,19 @@ Timer::~Timer() | |||
delete data; | |||
} | |||
float Timer::GetMs() | |||
float Timer::Get() | |||
{ | |||
return data->GetOrWait(0.0f, true); | |||
} | |||
float Timer::PollMs() | |||
float Timer::Poll() | |||
{ | |||
return data->GetOrWait(0.0f, false); | |||
} | |||
void Timer::WaitMs(float deltams) | |||
void Timer::Wait(float seconds) | |||
{ | |||
(void)data->GetOrWait(deltams, false); | |||
(void)data->GetOrWait(seconds, false); | |||
} | |||
} /* namespace lol */ | |||
@@ -27,9 +27,9 @@ public: | |||
Timer(); | |||
~Timer(); | |||
float GetMs(); | |||
float PollMs(); | |||
void WaitMs(float deltams); | |||
float Get(); | |||
float Poll(); | |||
void Wait(float seconds); | |||
private: | |||
TimerData *data; | |||
@@ -46,69 +46,69 @@ void bench_half(int mode) | |||
} | |||
/* Copy float */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
pf[i] = pf[i + 1]; | |||
result[0] += timer.GetMs(); | |||
result[0] += timer.Get(); | |||
/* Convert half to float (array) */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
half::convert(pf, ph, HALF_TABLE_SIZE); | |||
result[1] += timer.GetMs(); | |||
result[1] += timer.Get(); | |||
/* Convert half to float (fast) */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
pf[i] = (float)ph[i]; | |||
result[2] += timer.GetMs(); | |||
result[2] += timer.Get(); | |||
/* Add a half to every float */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
pf[i] += ph[i]; | |||
result[3] += timer.GetMs(); | |||
result[3] += timer.Get(); | |||
/* Copy half */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
ph[i] = ph[i + 1]; | |||
result[4] += timer.GetMs(); | |||
result[4] += timer.Get(); | |||
/* Change sign of every half */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
ph[i] = -ph[i]; | |||
result[5] += timer.GetMs(); | |||
result[5] += timer.Get(); | |||
/* Convert float to half (array) */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
half::convert(ph, pf, HALF_TABLE_SIZE); | |||
result[6] += timer.GetMs(); | |||
result[6] += timer.Get(); | |||
/* Convert float to half (fast) */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
ph[i] = (half)pf[i]; | |||
result[7] += timer.GetMs(); | |||
result[7] += timer.Get(); | |||
/* Convert float to half (accurate) */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
ph[i] = half::makeaccurate(pf[i]); | |||
result[8] += timer.GetMs(); | |||
result[8] += timer.Get(); | |||
/* Add a float to every half */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | |||
ph[i] += pf[i]; | |||
result[9] += timer.GetMs(); | |||
result[9] += timer.Get(); | |||
} | |||
delete[] pf; | |||
delete[] ph; | |||
for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) | |||
result[i] *= 1000000.0f / (HALF_TABLE_SIZE * HALF_RUNS); | |||
result[i] *= 1e9f / (HALF_TABLE_SIZE * HALF_RUNS); | |||
Log::Info(" ns/elem\n"); | |||
Log::Info("float = float %7.3f\n", result[0]); | |||
@@ -36,40 +36,40 @@ void bench_real(int mode) | |||
} | |||
real fib1 = 1.0, fib2 = 1.0; | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | |||
{ | |||
real tmp = fib1 + fib2; | |||
fib1 = fib2; | |||
fib2 = tmp; | |||
} | |||
result[0] += timer.GetMs(); | |||
result[0] += timer.Get(); | |||
real fact = 1.0; | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | |||
fact = fact * real(1.0 + i); | |||
result[1] += timer.GetMs(); | |||
result[1] += timer.Get(); | |||
real invfact = 1.0; | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | |||
invfact = invfact / real(1.0 + i); | |||
result[2] += timer.GetMs(); | |||
result[2] += timer.Get(); | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) | |||
sin(real(0.01 * i)); | |||
result[3] += timer.GetMs() * 128; | |||
result[3] += timer.Get() * 128; | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) | |||
exp((real)(int)(i - REAL_TABLE_SIZE / 256)); | |||
result[4] += timer.GetMs() * 128; | |||
result[4] += timer.Get() * 128; | |||
} | |||
for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) | |||
result[i] *= 1000000.0f / (REAL_TABLE_SIZE * REAL_RUNS); | |||
result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS); | |||
Log::Info(" ns/elem\n"); | |||
Log::Info("real = real + real %7.3f\n", result[0]); | |||
@@ -64,59 +64,59 @@ void bench_trig(int mode) | |||
} | |||
/* Sin */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
#if defined __GNUC__ && !defined __SNC__ | |||
pf2[i] = __builtin_sinf(pf[i]); | |||
#else | |||
pf2[i] = sinf(pf[i]); | |||
#endif | |||
result[0] += timer.GetMs(); | |||
result[0] += timer.Get(); | |||
/* Fast sin */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
#if defined HAVE_FASTMATH_H && !defined __native_client__ | |||
pf2[i] = f_sinf(pf[i]); | |||
#else | |||
pf2[i] = sinf(pf[i]); | |||
#endif | |||
result[1] += timer.GetMs(); | |||
result[1] += timer.Get(); | |||
/* Lol sin */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
pf2[i] = lol_sin(pf[i]); | |||
result[2] += timer.GetMs(); | |||
result[2] += timer.Get(); | |||
/* Cos */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
#if defined __GNUC__ && !defined __SNC__ | |||
pf2[i] = __builtin_cosf(pf[i]); | |||
#else | |||
pf2[i] = cosf(pf[i]); | |||
#endif | |||
result[3] += timer.GetMs(); | |||
result[3] += timer.Get(); | |||
/* Fast cos */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
#if defined HAVE_FASTMATH_H && !defined __native_client__ | |||
pf2[i] = f_cosf(pf[i]); | |||
#else | |||
pf2[i] = cosf(pf[i]); | |||
#endif | |||
result[4] += timer.GetMs(); | |||
result[4] += timer.Get(); | |||
/* Lol cos */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
pf2[i] = lol_cos(pf[i]); | |||
result[5] += timer.GetMs(); | |||
result[5] += timer.Get(); | |||
/* Sin & cos */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
{ | |||
#if defined __GNUC__ && !defined __SNC__ | |||
@@ -127,10 +127,10 @@ void bench_trig(int mode) | |||
pf3[i] = cosf(pf[i]); | |||
#endif | |||
} | |||
result[6] += timer.GetMs(); | |||
result[6] += timer.Get(); | |||
/* Fast sin & cos */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
{ | |||
#if defined HAVE_FASTMATH_H && !defined __native_client__ | |||
@@ -141,39 +141,39 @@ void bench_trig(int mode) | |||
pf3[i] = cosf(pf[i]); | |||
#endif | |||
} | |||
result[7] += timer.GetMs(); | |||
result[7] += timer.Get(); | |||
/* Lol sincos */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
lol_sincos(pf[i], &pf2[i], &pf3[i]); | |||
result[8] += timer.GetMs(); | |||
result[8] += timer.Get(); | |||
/* Tan */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
#if defined __GNUC__ && !defined __SNC__ | |||
pf2[i] = __builtin_tanf(pf[i]); | |||
#else | |||
pf2[i] = tanf(pf[i]); | |||
#endif | |||
result[9] += timer.GetMs(); | |||
result[9] += timer.Get(); | |||
/* Fast tan */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
#if defined HAVE_FASTMATH_H && !defined __native_client__ | |||
pf2[i] = f_tanf(pf[i]); | |||
#else | |||
pf2[i] = tanf(pf[i]); | |||
#endif | |||
result[10] += timer.GetMs(); | |||
result[10] += timer.Get(); | |||
/* Lol tan */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | |||
pf2[i] = lol_tan(pf[i]); | |||
result[11] += timer.GetMs(); | |||
result[11] += timer.Get(); | |||
} | |||
delete[] pf; | |||
@@ -181,7 +181,7 @@ void bench_trig(int mode) | |||
delete[] pf3; | |||
for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) | |||
result[i] *= 1000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS); | |||
result[i] *= 1e9f / (TRIG_TABLE_SIZE * TRIG_RUNS); | |||
Log::Info(" ns/elem\n"); | |||
Log::Info("float = sinf(float) %7.3f\n", result[0]); | |||
@@ -44,41 +44,41 @@ void bench_matrix(int mode) | |||
} | |||
/* Copy matrices */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | |||
pm[i] = pm[i + 1]; | |||
result[0] += timer.GetMs(); | |||
result[0] += timer.Get(); | |||
/* Determinant */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | |||
pf[i] = determinant(pm[i]); | |||
result[1] += timer.GetMs(); | |||
result[1] += timer.Get(); | |||
/* Multiply matrices */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | |||
pm[i] *= pm[i + 1]; | |||
result[2] += timer.GetMs(); | |||
result[2] += timer.Get(); | |||
/* Add matrices */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | |||
pm[i] += pm[i + 1]; | |||
result[3] += timer.GetMs(); | |||
result[3] += timer.Get(); | |||
/* Invert matrix */ | |||
timer.GetMs(); | |||
timer.Get(); | |||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | |||
pm[i] = inverse(pm[i]); | |||
result[4] += timer.GetMs(); | |||
result[4] += timer.Get(); | |||
} | |||
delete[] pm; | |||
delete[] pf; | |||
for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) | |||
result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS); | |||
result[i] *= 1e9f / (MATRIX_TABLE_SIZE * MATRIX_RUNS); | |||
Log::Info(" ns/elem\n"); | |||
Log::Info("mat4 = mat4 %7.3f\n", result[0]); | |||