@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Benchmark program | // Lol Engine — Benchmark program | ||||
// | // | ||||
// Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2005—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// This program is free software. It comes without any warranty, to | // This program is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -26,7 +26,7 @@ static size_t const HALF_RUNS = 50; | |||||
void bench_half(int mode) | void bench_half(int mode) | ||||
{ | { | ||||
float result[10] = { 0.0f }; | float result[10] = { 0.0f }; | ||||
Timer timer; | |||||
lol::timer timer; | |||||
/* Set up tables */ | /* Set up tables */ | ||||
float *pf = new float[HALF_TABLE_SIZE + 1]; | float *pf = new float[HALF_TABLE_SIZE + 1]; | ||||
@@ -48,62 +48,62 @@ void bench_half(int mode) | |||||
} | } | ||||
/* Convert half to float (array) */ | /* Convert half to float (array) */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
half::convert(pf, ph, HALF_TABLE_SIZE); | half::convert(pf, ph, HALF_TABLE_SIZE); | ||||
result[0] += timer.Get(); | |||||
result[0] += timer.get(); | |||||
/* Convert half to float (fast) */ | /* Convert half to float (fast) */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
pf[i] = (float)ph[i]; | pf[i] = (float)ph[i]; | ||||
result[1] += timer.Get(); | |||||
result[1] += timer.get(); | |||||
/* Copy float */ | /* Copy float */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
pf[i] = pf[i + 1]; | pf[i] = pf[i + 1]; | ||||
result[2] += timer.Get(); | |||||
result[2] += timer.get(); | |||||
/* Add a half to every float */ | /* Add a half to every float */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
pf[i] += ph[i]; | pf[i] += ph[i]; | ||||
result[3] += timer.Get(); | |||||
result[3] += timer.get(); | |||||
/* Copy half */ | /* Copy half */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
ph[i] = ph[i + 1]; | ph[i] = ph[i + 1]; | ||||
result[4] += timer.Get(); | |||||
result[4] += timer.get(); | |||||
/* Change sign of every half */ | /* Change sign of every half */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
ph[i] = -ph[i]; | ph[i] = -ph[i]; | ||||
result[5] += timer.Get(); | |||||
result[5] += timer.get(); | |||||
/* Convert float to half (array) */ | /* Convert float to half (array) */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
half::convert(ph, pf, HALF_TABLE_SIZE); | half::convert(ph, pf, HALF_TABLE_SIZE); | ||||
result[6] += timer.Get(); | |||||
result[6] += timer.get(); | |||||
/* Convert float to half (fast) */ | /* Convert float to half (fast) */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
ph[i] = (half)pf[i]; | ph[i] = (half)pf[i]; | ||||
result[7] += timer.Get(); | |||||
result[7] += timer.get(); | |||||
/* Convert float to half (accurate) */ | /* Convert float to half (accurate) */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
ph[i] = half::makeaccurate(pf[i]); | ph[i] = half::makeaccurate(pf[i]); | ||||
result[8] += timer.Get(); | |||||
result[8] += timer.get(); | |||||
/* Add a float to every half */ | /* Add a float to every half */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | for (size_t i = 0; i < HALF_TABLE_SIZE; i++) | ||||
ph[i] += pf[i]; | ph[i] += pf[i]; | ||||
result[9] += timer.Get(); | |||||
result[9] += timer.get(); | |||||
} | } | ||||
delete[] pf; | delete[] pf; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Benchmark program | // Lol Engine — Benchmark program | ||||
// | // | ||||
// Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2005—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// This program is free software. It comes without any warranty, to | // This program is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -26,7 +26,7 @@ static size_t const REAL_RUNS = 50; | |||||
void bench_real(int mode) | void bench_real(int mode) | ||||
{ | { | ||||
float result[12] = { 0.0f }; | float result[12] = { 0.0f }; | ||||
Timer timer; | |||||
lol::timer timer; | |||||
for (size_t run = 0; run < REAL_RUNS; run++) | for (size_t run = 0; run < REAL_RUNS; run++) | ||||
{ | { | ||||
@@ -37,36 +37,36 @@ void bench_real(int mode) | |||||
} | } | ||||
real fib1 = 1.0, fib2 = 1.0; | real fib1 = 1.0, fib2 = 1.0; | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | ||||
{ | { | ||||
real tmp = fib1 + fib2; | real tmp = fib1 + fib2; | ||||
fib1 = fib2; | fib1 = fib2; | ||||
fib2 = tmp; | fib2 = tmp; | ||||
} | } | ||||
result[0] += timer.Get(); | |||||
result[0] += timer.get(); | |||||
real fact = 1.0; | real fact = 1.0; | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | ||||
fact = fact * real(1.0 + i); | fact = fact * real(1.0 + i); | ||||
result[1] += timer.Get(); | |||||
result[1] += timer.get(); | |||||
real invfact = 1.0; | real invfact = 1.0; | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | for (size_t i = 0; i < REAL_TABLE_SIZE; i++) | ||||
invfact = invfact / real(1.0 + i); | invfact = invfact / real(1.0 + i); | ||||
result[2] += timer.Get(); | |||||
result[2] += timer.get(); | |||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) | for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) | ||||
(void)sin(real(0.01 * i)); | (void)sin(real(0.01 * i)); | ||||
result[3] += timer.Get() * 128; | |||||
result[3] += timer.get() * 128; | |||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) | for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) | ||||
(void)exp((real)(int)(i - REAL_TABLE_SIZE / 256)); | (void)exp((real)(int)(i - REAL_TABLE_SIZE / 256)); | ||||
result[4] += timer.Get() * 128; | |||||
result[4] += timer.get() * 128; | |||||
} | } | ||||
for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) | for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Benchmark program | // Lol Engine — Benchmark program | ||||
// | // | ||||
// Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2005—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// This program is free software. It comes without any warranty, to | // This program is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -30,7 +30,7 @@ static size_t const TRIG_RUNS = 50; | |||||
void bench_trig(int mode) | void bench_trig(int mode) | ||||
{ | { | ||||
float result[12] = { 0.0f }; | float result[12] = { 0.0f }; | ||||
Timer timer; | |||||
lol::timer timer; | |||||
/* Set up tables */ | /* Set up tables */ | ||||
float *pf = new float[TRIG_TABLE_SIZE]; | float *pf = new float[TRIG_TABLE_SIZE]; | ||||
@@ -56,59 +56,59 @@ void bench_trig(int mode) | |||||
} | } | ||||
/* Sin */ | /* Sin */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
#if __GNUC__ && !__SNC__ | #if __GNUC__ && !__SNC__ | ||||
pf2[i] = __builtin_sinf(pf[i]); | pf2[i] = __builtin_sinf(pf[i]); | ||||
#else | #else | ||||
pf2[i] = sinf(pf[i]); | pf2[i] = sinf(pf[i]); | ||||
#endif | #endif | ||||
result[0] += timer.Get(); | |||||
result[0] += timer.get(); | |||||
/* Fast sin */ | /* Fast sin */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
#if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | ||||
pf2[i] = f_sinf(pf[i]); | pf2[i] = f_sinf(pf[i]); | ||||
#else | #else | ||||
pf2[i] = sinf(pf[i]); | pf2[i] = sinf(pf[i]); | ||||
#endif | #endif | ||||
result[1] += timer.Get(); | |||||
result[1] += timer.get(); | |||||
/* Lol sin */ | /* Lol sin */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
pf2[i] = lol_sin(pf[i]); | pf2[i] = lol_sin(pf[i]); | ||||
result[2] += timer.Get(); | |||||
result[2] += timer.get(); | |||||
/* Cos */ | /* Cos */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
#if __GNUC__ && !__SNC__ | #if __GNUC__ && !__SNC__ | ||||
pf2[i] = __builtin_cosf(pf[i]); | pf2[i] = __builtin_cosf(pf[i]); | ||||
#else | #else | ||||
pf2[i] = cosf(pf[i]); | pf2[i] = cosf(pf[i]); | ||||
#endif | #endif | ||||
result[3] += timer.Get(); | |||||
result[3] += timer.get(); | |||||
/* Fast cos */ | /* Fast cos */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
#if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | ||||
pf2[i] = f_cosf(pf[i]); | pf2[i] = f_cosf(pf[i]); | ||||
#else | #else | ||||
pf2[i] = cosf(pf[i]); | pf2[i] = cosf(pf[i]); | ||||
#endif | #endif | ||||
result[4] += timer.Get(); | |||||
result[4] += timer.get(); | |||||
/* Lol cos */ | /* Lol cos */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
pf2[i] = lol_cos(pf[i]); | pf2[i] = lol_cos(pf[i]); | ||||
result[5] += timer.Get(); | |||||
result[5] += timer.get(); | |||||
/* Sin & cos */ | /* Sin & cos */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
{ | { | ||||
#if __GNUC__ && !__SNC__ | #if __GNUC__ && !__SNC__ | ||||
@@ -119,10 +119,10 @@ void bench_trig(int mode) | |||||
pf3[i] = cosf(pf[i]); | pf3[i] = cosf(pf[i]); | ||||
#endif | #endif | ||||
} | } | ||||
result[6] += timer.Get(); | |||||
result[6] += timer.get(); | |||||
/* Fast sin & cos */ | /* Fast sin & cos */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
{ | { | ||||
#if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | ||||
@@ -133,39 +133,39 @@ void bench_trig(int mode) | |||||
pf3[i] = cosf(pf[i]); | pf3[i] = cosf(pf[i]); | ||||
#endif | #endif | ||||
} | } | ||||
result[7] += timer.Get(); | |||||
result[7] += timer.get(); | |||||
/* Lol sincos */ | /* Lol sincos */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
lol_sincos(pf[i], &pf2[i], &pf3[i]); | lol_sincos(pf[i], &pf2[i], &pf3[i]); | ||||
result[8] += timer.Get(); | |||||
result[8] += timer.get(); | |||||
/* Tan */ | /* Tan */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
#if __GNUC__ && !__SNC__ | #if __GNUC__ && !__SNC__ | ||||
pf2[i] = __builtin_tanf(pf[i]); | pf2[i] = __builtin_tanf(pf[i]); | ||||
#else | #else | ||||
pf2[i] = tanf(pf[i]); | pf2[i] = tanf(pf[i]); | ||||
#endif | #endif | ||||
result[9] += timer.Get(); | |||||
result[9] += timer.get(); | |||||
/* Fast tan */ | /* Fast tan */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
#if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN | ||||
pf2[i] = f_tanf(pf[i]); | pf2[i] = f_tanf(pf[i]); | ||||
#else | #else | ||||
pf2[i] = tanf(pf[i]); | pf2[i] = tanf(pf[i]); | ||||
#endif | #endif | ||||
result[10] += timer.Get(); | |||||
result[10] += timer.get(); | |||||
/* Lol tan */ | /* Lol tan */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) | ||||
pf2[i] = lol_tan(pf[i]); | pf2[i] = lol_tan(pf[i]); | ||||
result[11] += timer.Get(); | |||||
result[11] += timer.get(); | |||||
} | } | ||||
delete[] pf; | delete[] pf; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Benchmark program | // Lol Engine — Benchmark program | ||||
// | // | ||||
// Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2005—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// This program is free software. It comes without any warranty, to | // This program is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -26,7 +26,7 @@ static size_t const MATRIX_RUNS = 100; | |||||
void bench_matrix(int mode) | void bench_matrix(int mode) | ||||
{ | { | ||||
float result[5] = { 0.0f }; | float result[5] = { 0.0f }; | ||||
Timer timer; | |||||
lol::timer timer; | |||||
/* Set up tables */ | /* Set up tables */ | ||||
mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1]; | mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1]; | ||||
@@ -45,34 +45,34 @@ void bench_matrix(int mode) | |||||
} | } | ||||
/* Copy matrices */ | /* Copy matrices */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | ||||
pm[i] = pm[i + 1]; | pm[i] = pm[i + 1]; | ||||
result[0] += timer.Get(); | |||||
result[0] += timer.get(); | |||||
/* Determinant */ | /* Determinant */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | ||||
pf[i] = determinant(pm[i]); | pf[i] = determinant(pm[i]); | ||||
result[1] += timer.Get(); | |||||
result[1] += timer.get(); | |||||
/* Multiply matrices */ | /* Multiply matrices */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | ||||
pm[i] *= pm[i + 1]; | pm[i] *= pm[i + 1]; | ||||
result[2] += timer.Get(); | |||||
result[2] += timer.get(); | |||||
/* Add matrices */ | /* Add matrices */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | ||||
pm[i] += pm[i + 1]; | pm[i] += pm[i + 1]; | ||||
result[3] += timer.Get(); | |||||
result[3] += timer.get(); | |||||
/* Invert matrix */ | /* Invert matrix */ | ||||
timer.Get(); | |||||
timer.get(); | |||||
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) | ||||
pm[i] = inverse(pm[i]); | pm[i] = inverse(pm[i]); | ||||
result[4] += timer.Get(); | |||||
result[4] += timer.get(); | |||||
} | } | ||||
delete[] pm; | delete[] pm; | ||||
@@ -2,7 +2,7 @@ | |||||
// Lol Engine — BtPhys tutorial | // Lol Engine — BtPhys tutorial | ||||
// | // | ||||
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// © 2012—2015 Sam Hocevar <sam@hocevar.net> | |||||
// © 2012—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -449,7 +449,7 @@ void BtPhysTest::TickGame(float seconds) | |||||
for (int i = 0; i < m_physobj_list.count(); i++) | for (int i = 0; i < m_physobj_list.count(); i++) | ||||
{ | { | ||||
PhysicsObject* PhysObj = m_physobj_list[i].m1; | PhysicsObject* PhysObj = m_physobj_list[i].m1; | ||||
float &Timer = m_physobj_list[i].m2; | |||||
float &obj_timer = m_physobj_list[i].m2; | |||||
vec3 obj_loc = PhysObj->GetPhysic()->GetTransform()[3].xyz; | vec3 obj_loc = PhysObj->GetPhysic()->GetTransform()[3].xyz; | ||||
@@ -482,15 +482,15 @@ void BtPhysTest::TickGame(float seconds) | |||||
//Jump handling | //Jump handling | ||||
//if (length(PhysObj->GetPhysic()->GetLinearVelocity()) < ZERO_SPEED) | //if (length(PhysObj->GetPhysic()->GetLinearVelocity()) < ZERO_SPEED) | ||||
if (lol::abs(PhysObj->GetPhysic()->GetLinearVelocity().y) < ZERO_SPEED) | if (lol::abs(PhysObj->GetPhysic()->GetLinearVelocity().y) < ZERO_SPEED) | ||||
Timer -= seconds; | |||||
obj_timer -= seconds; | |||||
if (Timer < .0f) | |||||
if (obj_timer < .0f) | |||||
{ | { | ||||
PhysObj->GetPhysic()->AddImpulse(JUMP_HEIGHT * | PhysObj->GetPhysic()->AddImpulse(JUMP_HEIGHT * | ||||
vec3(JUMP_STRAFE, 1.f, JUMP_STRAFE) * | vec3(JUMP_STRAFE, 1.f, JUMP_STRAFE) * | ||||
vec3(rand(-1.f, 1.f), 1.0f, rand(-1.f, 1.f)) * | vec3(rand(-1.f, 1.f), 1.0f, rand(-1.f, 1.f)) * | ||||
PhysObj->GetPhysic()->GetMass()); | PhysObj->GetPhysic()->GetMass()); | ||||
Timer = ZERO_TIME; | |||||
obj_timer = ZERO_TIME; | |||||
} | } | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Sandbox program | // Lol Engine — Sandbox program | ||||
// | // | ||||
// Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2005—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// This program is free software. It comes without any warranty, to | // This program is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -20,7 +20,7 @@ using namespace lol; | |||||
int main() | int main() | ||||
{ | { | ||||
Timer t; | |||||
timer t; | |||||
bigint<128> x(17), y(23); | bigint<128> x(17), y(23); | ||||
x.print(); | x.print(); | ||||
@@ -37,6 +37,6 @@ int main() | |||||
printf("%d %d\n", (int)x, (int)y); | printf("%d %d\n", (int)x, (int)y); | ||||
printf("Time: %f s\n", t.Get()); | |||||
printf("Time: %f s\n", t.get()); | |||||
} | } | ||||
@@ -63,7 +63,7 @@ private: | |||||
/* Fixed framerate management */ | /* Fixed framerate management */ | ||||
int frame, recording; | int frame, recording; | ||||
Timer timer; | |||||
timer m_timer; | |||||
float deltatime, bias, fps; | float deltatime, bias, fps; | ||||
#if LOL_BUILD_DEBUG | #if LOL_BUILD_DEBUG | ||||
float keepalive; | float keepalive; | ||||
@@ -240,7 +240,7 @@ void TickerData::GameThreadTick() | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
data->deltatime = data->timer.Get(); | |||||
data->deltatime = data->m_timer.get(); | |||||
data->bias += data->deltatime; | data->bias += data->deltatime; | ||||
} | } | ||||
@@ -540,7 +540,7 @@ void Ticker::TickDraw() | |||||
if (frametime > data->bias + .2f) | if (frametime > data->bias + .2f) | ||||
frametime = data->bias + .2f; /* Don't go below 5 fps */ | frametime = data->bias + .2f; /* Don't go below 5 fps */ | ||||
if (frametime > data->bias) | if (frametime > data->bias) | ||||
data->timer.Wait(frametime - data->bias); | |||||
data->m_timer.wait(frametime - data->bias); | |||||
/* If recording, do not try to compensate for lag. */ | /* If recording, do not try to compensate for lag. */ | ||||
if (!data->recording) | if (!data->recording) | ||||
@@ -147,9 +147,9 @@ private: | |||||
int m_thread_min = 0; | int m_thread_min = 0; | ||||
int m_thread_active = 0; | int m_thread_active = 0; | ||||
array<thread*> m_threads; | array<thread*> m_threads; | ||||
Timer m_thread_added_timer; | |||||
timer m_thread_added_timer; | |||||
int m_thread_added = 0; | int m_thread_added = 0; | ||||
Timer m_thread_removed_timer; | |||||
timer m_thread_removed_timer; | |||||
int m_thread_removed = 0; | int m_thread_removed = 0; | ||||
queue<ThreadStatus> m_statusqueue; | queue<ThreadStatus> m_statusqueue; | ||||
@@ -17,37 +17,23 @@ | |||||
#include <thread> | #include <thread> | ||||
// | // | ||||
// The Timer class | |||||
// The timer class | |||||
// --------------- | // --------------- | ||||
// | // | ||||
namespace lol | namespace lol | ||||
{ | { | ||||
class Timer | |||||
class timer | |||||
{ | { | ||||
public: | public: | ||||
Timer() | |||||
{ | |||||
(void)get_seconds(true); | |||||
} | |||||
void Reset() | |||||
{ | |||||
(void)get_seconds(true); | |||||
} | |||||
inline timer() { (void)get_seconds(true); } | |||||
float Get() | |||||
{ | |||||
return get_seconds(true); | |||||
} | |||||
float Poll() | |||||
{ | |||||
return get_seconds(false); | |||||
} | |||||
inline void reset() { (void)get_seconds(true); } | |||||
inline float get() { return get_seconds(true); } | |||||
inline float poll() { return get_seconds(false); } | |||||
void Wait(float seconds) | |||||
void wait(float seconds) | |||||
{ | { | ||||
if (seconds > 0.0f) | if (seconds > 0.0f) | ||||
{ | { | ||||
@@ -36,7 +36,7 @@ public: | |||||
private: | private: | ||||
float history[HISTORY]; | float history[HISTORY]; | ||||
Timer timer; | |||||
timer m_timer; | |||||
float avg, max; | float avg, max; | ||||
} | } | ||||
data[Profiler::STAT_COUNT]; | data[Profiler::STAT_COUNT]; | ||||
@@ -47,12 +47,12 @@ data[Profiler::STAT_COUNT]; | |||||
void Profiler::Start(int id) | void Profiler::Start(int id) | ||||
{ | { | ||||
data[id].timer.Get(); | |||||
data[id].m_timer.get(); | |||||
} | } | ||||
void Profiler::Stop(int id) | void Profiler::Stop(int id) | ||||
{ | { | ||||
float seconds = data[id].timer.Get(); | |||||
float seconds = data[id].m_timer.get(); | |||||
data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds; | data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds; | ||||
data[id].avg = 0.0f; | data[id].avg = 0.0f; | ||||
@@ -98,14 +98,14 @@ void BaseThreadManager::AdjustThreadCount(int count) | |||||
//Spawn worker threads and ... | //Spawn worker threads and ... | ||||
m_threads << new thread(std::bind(&BaseThreadManager::BaseThreadWork, this, std::placeholders::_1)); | m_threads << new thread(std::bind(&BaseThreadManager::BaseThreadWork, this, std::placeholders::_1)); | ||||
m_thread_added++; | m_thread_added++; | ||||
m_thread_added_timer.Reset(); | |||||
m_thread_added_timer.reset(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
//Signal worker threads for completion and ... | //Signal worker threads for completion and ... | ||||
m_jobqueue.push(new ThreadJob(ThreadJobType::THREAD_STOP)); | m_jobqueue.push(new ThreadJob(ThreadJobType::THREAD_STOP)); | ||||
m_thread_removed++; | m_thread_removed++; | ||||
m_thread_removed_timer.Reset(); | |||||
m_thread_removed_timer.reset(); | |||||
} | } | ||||
} | } | ||||
#endif //LOL_FEATURE_THREADS | #endif //LOL_FEATURE_THREADS | ||||
@@ -130,7 +130,7 @@ void BaseThreadManager::CleanAddedThread(bool wait) | |||||
break; | break; | ||||
} | } | ||||
//Assert if spawning took too much time | //Assert if spawning took too much time | ||||
//ASSERT(!(m_thread_added > 0 && m_thread_added_timer.Poll() > 5.f)); | |||||
//ASSERT(!(m_thread_added > 0 && m_thread_added_timer.poll() > 5.f)); | |||||
#endif //LOL_FEATURE_THREADS | #endif //LOL_FEATURE_THREADS | ||||
} | } | ||||
@@ -157,7 +157,7 @@ void BaseThreadManager::CleanRemovedThread(bool wait) | |||||
break; | break; | ||||
} | } | ||||
//Assert if stopping took too much time | //Assert if stopping took too much time | ||||
//ASSERT(!(m_thread_removed > 0 && m_thread_removed_timer.Poll() > 5.f)); | |||||
//ASSERT(!(m_thread_removed > 0 && m_thread_removed_timer.poll() > 5.f)); | |||||
#endif //LOL_FEATURE_THREADS | #endif //LOL_FEATURE_THREADS | ||||
} | } | ||||
@@ -39,10 +39,10 @@ lolunit_declare_fixture(thread_test) | |||||
protected: | protected: | ||||
virtual bool DoWork() | virtual bool DoWork() | ||||
{ | { | ||||
Timer timer; | |||||
timer t; | |||||
m_done = false; | m_done = false; | ||||
msg::info("%s: STARTED WORK\n", GetName()); | msg::info("%s: STARTED WORK\n", GetName()); | ||||
timer.Wait(2.f); | |||||
t.wait(2.f); | |||||
msg::info("%s: ENDED WORK\n", GetName()); | msg::info("%s: ENDED WORK\n", GetName()); | ||||
m_done = true; | m_done = true; | ||||
return true; | return true; | ||||
@@ -32,17 +32,17 @@ lolunit_declare_fixture(timer_test) | |||||
lolunit_declare_test(timers) | lolunit_declare_test(timers) | ||||
{ | { | ||||
Timer timer0, timer1; | |||||
timer t0, t1; | |||||
timer0.Wait(1.5); | |||||
t0.wait(1.5); | |||||
float t0 = timer1.Poll(); | |||||
float t1 = timer1.Get(); | |||||
lolunit_assert_doubles_equal(t0, t1, 1e-5); | |||||
lolunit_assert_doubles_equal(1.5, t1, 1e-3); | |||||
float s0 = t1.poll(); | |||||
float s1 = t1.get(); | |||||
lolunit_assert_doubles_equal(s0, s1, 1e-5); | |||||
lolunit_assert_doubles_equal(1.5, s1, 1e-3); | |||||
timer1.Wait(1.5); | |||||
lolunit_assert_doubles_equal(3.0, timer0.Get(), 1e-3); | |||||
t1.wait(1.5); | |||||
lolunit_assert_doubles_equal(3.0, t0.get(), 1e-3); | |||||
} | } | ||||
}; | }; | ||||