diff --git a/doc/samples/benchmark/half.cpp b/doc/samples/benchmark/half.cpp index 25e7ceea..4aac8187 100644 --- a/doc/samples/benchmark/half.cpp +++ b/doc/samples/benchmark/half.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Benchmark program // -// Copyright © 2005—2015 Sam Hocevar +// Copyright © 2005—2018 Sam Hocevar // // This program is free software. It comes without any warranty, to // 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) { float result[10] = { 0.0f }; - Timer timer; + lol::timer timer; /* Set up tables */ float *pf = new float[HALF_TABLE_SIZE + 1]; @@ -48,62 +48,62 @@ void bench_half(int mode) } /* Convert half to float (array) */ - timer.Get(); + timer.get(); half::convert(pf, ph, HALF_TABLE_SIZE); - result[0] += timer.Get(); + result[0] += timer.get(); /* Convert half to float (fast) */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) pf[i] = (float)ph[i]; - result[1] += timer.Get(); + result[1] += timer.get(); /* Copy float */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) pf[i] = pf[i + 1]; - result[2] += timer.Get(); + result[2] += timer.get(); /* Add a half to every float */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) pf[i] += ph[i]; - result[3] += timer.Get(); + result[3] += timer.get(); /* Copy half */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) ph[i] = ph[i + 1]; - result[4] += timer.Get(); + result[4] += timer.get(); /* Change sign of every half */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) ph[i] = -ph[i]; - result[5] += timer.Get(); + result[5] += timer.get(); /* Convert float to half (array) */ - timer.Get(); + timer.get(); half::convert(ph, pf, HALF_TABLE_SIZE); - result[6] += timer.Get(); + result[6] += timer.get(); /* Convert float to half (fast) */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) ph[i] = (half)pf[i]; - result[7] += timer.Get(); + result[7] += timer.get(); /* Convert float to half (accurate) */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) ph[i] = half::makeaccurate(pf[i]); - result[8] += timer.Get(); + result[8] += timer.get(); /* Add a float to every half */ - timer.Get(); + timer.get(); for (size_t i = 0; i < HALF_TABLE_SIZE; i++) ph[i] += pf[i]; - result[9] += timer.Get(); + result[9] += timer.get(); } delete[] pf; diff --git a/doc/samples/benchmark/real.cpp b/doc/samples/benchmark/real.cpp index 7cf8edd7..6455bdda 100644 --- a/doc/samples/benchmark/real.cpp +++ b/doc/samples/benchmark/real.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Benchmark program // -// Copyright © 2005—2015 Sam Hocevar +// Copyright © 2005—2018 Sam Hocevar // // This program is free software. It comes without any warranty, to // 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) { float result[12] = { 0.0f }; - Timer timer; + lol::timer timer; 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; - timer.Get(); + timer.get(); for (size_t i = 0; i < REAL_TABLE_SIZE; i++) { real tmp = fib1 + fib2; fib1 = fib2; fib2 = tmp; } - result[0] += timer.Get(); + result[0] += timer.get(); real fact = 1.0; - timer.Get(); + timer.get(); for (size_t i = 0; i < REAL_TABLE_SIZE; i++) fact = fact * real(1.0 + i); - result[1] += timer.Get(); + result[1] += timer.get(); real invfact = 1.0; - timer.Get(); + timer.get(); for (size_t i = 0; i < REAL_TABLE_SIZE; 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++) (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++) (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++) diff --git a/doc/samples/benchmark/trig.cpp b/doc/samples/benchmark/trig.cpp index c9eefd7c..13cf2348 100644 --- a/doc/samples/benchmark/trig.cpp +++ b/doc/samples/benchmark/trig.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Benchmark program // -// Copyright © 2005—2015 Sam Hocevar +// Copyright © 2005—2018 Sam Hocevar // // This program is free software. It comes without any warranty, to // 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) { float result[12] = { 0.0f }; - Timer timer; + lol::timer timer; /* Set up tables */ float *pf = new float[TRIG_TABLE_SIZE]; @@ -56,59 +56,59 @@ void bench_trig(int mode) } /* Sin */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) #if __GNUC__ && !__SNC__ pf2[i] = __builtin_sinf(pf[i]); #else pf2[i] = sinf(pf[i]); #endif - result[0] += timer.Get(); + result[0] += timer.get(); /* Fast sin */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN pf2[i] = f_sinf(pf[i]); #else pf2[i] = sinf(pf[i]); #endif - result[1] += timer.Get(); + result[1] += timer.get(); /* Lol sin */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) pf2[i] = lol_sin(pf[i]); - result[2] += timer.Get(); + result[2] += timer.get(); /* Cos */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) #if __GNUC__ && !__SNC__ pf2[i] = __builtin_cosf(pf[i]); #else pf2[i] = cosf(pf[i]); #endif - result[3] += timer.Get(); + result[3] += timer.get(); /* Fast cos */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN pf2[i] = f_cosf(pf[i]); #else pf2[i] = cosf(pf[i]); #endif - result[4] += timer.Get(); + result[4] += timer.get(); /* Lol cos */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) pf2[i] = lol_cos(pf[i]); - result[5] += timer.Get(); + result[5] += timer.get(); /* Sin & cos */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) { #if __GNUC__ && !__SNC__ @@ -119,10 +119,10 @@ void bench_trig(int mode) pf3[i] = cosf(pf[i]); #endif } - result[6] += timer.Get(); + result[6] += timer.get(); /* Fast sin & cos */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) { #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN @@ -133,39 +133,39 @@ void bench_trig(int mode) pf3[i] = cosf(pf[i]); #endif } - result[7] += timer.Get(); + result[7] += timer.get(); /* Lol sincos */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) lol_sincos(pf[i], &pf2[i], &pf3[i]); - result[8] += timer.Get(); + result[8] += timer.get(); /* Tan */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) #if __GNUC__ && !__SNC__ pf2[i] = __builtin_tanf(pf[i]); #else pf2[i] = tanf(pf[i]); #endif - result[9] += timer.Get(); + result[9] += timer.get(); /* Fast tan */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) #if HAVE_FASTMATH_H && !__native_client__ && !EMSCRIPTEN pf2[i] = f_tanf(pf[i]); #else pf2[i] = tanf(pf[i]); #endif - result[10] += timer.Get(); + result[10] += timer.get(); /* Lol tan */ - timer.Get(); + timer.get(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) pf2[i] = lol_tan(pf[i]); - result[11] += timer.Get(); + result[11] += timer.get(); } delete[] pf; diff --git a/doc/samples/benchmark/vector.cpp b/doc/samples/benchmark/vector.cpp index 298a7faf..54478531 100644 --- a/doc/samples/benchmark/vector.cpp +++ b/doc/samples/benchmark/vector.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Benchmark program // -// Copyright © 2005—2015 Sam Hocevar +// Copyright © 2005—2018 Sam Hocevar // // This program is free software. It comes without any warranty, to // 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) { float result[5] = { 0.0f }; - Timer timer; + lol::timer timer; /* Set up tables */ mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1]; @@ -45,34 +45,34 @@ void bench_matrix(int mode) } /* Copy matrices */ - timer.Get(); + timer.get(); for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) pm[i] = pm[i + 1]; - result[0] += timer.Get(); + result[0] += timer.get(); /* Determinant */ - timer.Get(); + timer.get(); for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) pf[i] = determinant(pm[i]); - result[1] += timer.Get(); + result[1] += timer.get(); /* Multiply matrices */ - timer.Get(); + timer.get(); for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) pm[i] *= pm[i + 1]; - result[2] += timer.Get(); + result[2] += timer.get(); /* Add matrices */ - timer.Get(); + timer.get(); for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) pm[i] += pm[i + 1]; - result[3] += timer.Get(); + result[3] += timer.get(); /* Invert matrix */ - timer.Get(); + timer.get(); for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) pm[i] = inverse(pm[i]); - result[4] += timer.Get(); + result[4] += timer.get(); } delete[] pm; diff --git a/doc/samples/btphystest.cpp b/doc/samples/btphystest.cpp index 53bfb94c..da6c1a25 100644 --- a/doc/samples/btphystest.cpp +++ b/doc/samples/btphystest.cpp @@ -2,7 +2,7 @@ // Lol Engine — BtPhys tutorial // // Copyright © 2009—2015 Benjamin “Touky” Huet -// © 2012—2015 Sam Hocevar +// © 2012—2018 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // 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++) { 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; @@ -482,15 +482,15 @@ void BtPhysTest::TickGame(float seconds) //Jump handling //if (length(PhysObj->GetPhysic()->GetLinearVelocity()) < 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 * vec3(JUMP_STRAFE, 1.f, JUMP_STRAFE) * vec3(rand(-1.f, 1.f), 1.0f, rand(-1.f, 1.f)) * PhysObj->GetPhysic()->GetMass()); - Timer = ZERO_TIME; + obj_timer = ZERO_TIME; } } diff --git a/doc/samples/sandbox/sample.cpp b/doc/samples/sandbox/sample.cpp index 780395f5..13b31a4c 100644 --- a/doc/samples/sandbox/sample.cpp +++ b/doc/samples/sandbox/sample.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Sandbox program // -// Copyright © 2005—2015 Sam Hocevar +// Copyright © 2005—2018 Sam Hocevar // // This program is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -20,7 +20,7 @@ using namespace lol; int main() { - Timer t; + timer t; bigint<128> x(17), y(23); x.print(); @@ -37,6 +37,6 @@ int main() printf("%d %d\n", (int)x, (int)y); - printf("Time: %f s\n", t.Get()); + printf("Time: %f s\n", t.get()); } diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index c2eaf4ad..25b95d95 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -63,7 +63,7 @@ private: /* Fixed framerate management */ int frame, recording; - Timer timer; + timer m_timer; float deltatime, bias, fps; #if LOL_BUILD_DEBUG float keepalive; @@ -240,7 +240,7 @@ void TickerData::GameThreadTick() } else { - data->deltatime = data->timer.Get(); + data->deltatime = data->m_timer.get(); data->bias += data->deltatime; } @@ -540,7 +540,7 @@ void Ticker::TickDraw() if (frametime > data->bias + .2f) frametime = data->bias + .2f; /* Don't go below 5 fps */ 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 (!data->recording) diff --git a/src/lol/sys/threadtypes.h b/src/lol/sys/threadtypes.h index b880dbd6..3638e8ab 100644 --- a/src/lol/sys/threadtypes.h +++ b/src/lol/sys/threadtypes.h @@ -147,9 +147,9 @@ private: int m_thread_min = 0; int m_thread_active = 0; array m_threads; - Timer m_thread_added_timer; + timer m_thread_added_timer; int m_thread_added = 0; - Timer m_thread_removed_timer; + timer m_thread_removed_timer; int m_thread_removed = 0; queue m_statusqueue; diff --git a/src/lol/sys/timer.h b/src/lol/sys/timer.h index 606ffd19..e30f932e 100644 --- a/src/lol/sys/timer.h +++ b/src/lol/sys/timer.h @@ -17,37 +17,23 @@ #include // -// The Timer class +// The timer class // --------------- // namespace lol { -class Timer +class timer { 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) { diff --git a/src/profiler.cpp b/src/profiler.cpp index 8c52347d..c27d8733 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -36,7 +36,7 @@ public: private: float history[HISTORY]; - Timer timer; + timer m_timer; float avg, max; } data[Profiler::STAT_COUNT]; @@ -47,12 +47,12 @@ data[Profiler::STAT_COUNT]; void Profiler::Start(int id) { - data[id].timer.Get(); + data[id].m_timer.get(); } 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].avg = 0.0f; diff --git a/src/sys/thread.cpp b/src/sys/thread.cpp index e9853aa2..70452a02 100644 --- a/src/sys/thread.cpp +++ b/src/sys/thread.cpp @@ -98,14 +98,14 @@ void BaseThreadManager::AdjustThreadCount(int count) //Spawn worker threads and ... m_threads << new thread(std::bind(&BaseThreadManager::BaseThreadWork, this, std::placeholders::_1)); m_thread_added++; - m_thread_added_timer.Reset(); + m_thread_added_timer.reset(); } else { //Signal worker threads for completion and ... m_jobqueue.push(new ThreadJob(ThreadJobType::THREAD_STOP)); m_thread_removed++; - m_thread_removed_timer.Reset(); + m_thread_removed_timer.reset(); } } #endif //LOL_FEATURE_THREADS @@ -130,7 +130,7 @@ void BaseThreadManager::CleanAddedThread(bool wait) break; } //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 } @@ -157,7 +157,7 @@ void BaseThreadManager::CleanRemovedThread(bool wait) break; } //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 } diff --git a/src/t/sys/thread.cpp b/src/t/sys/thread.cpp index 9e6bfbcd..c154e52f 100644 --- a/src/t/sys/thread.cpp +++ b/src/t/sys/thread.cpp @@ -39,10 +39,10 @@ lolunit_declare_fixture(thread_test) protected: virtual bool DoWork() { - Timer timer; + timer t; m_done = false; msg::info("%s: STARTED WORK\n", GetName()); - timer.Wait(2.f); + t.wait(2.f); msg::info("%s: ENDED WORK\n", GetName()); m_done = true; return true; diff --git a/src/t/sys/timer.cpp b/src/t/sys/timer.cpp index e96b33ae..94d06c00 100644 --- a/src/t/sys/timer.cpp +++ b/src/t/sys/timer.cpp @@ -32,17 +32,17 @@ lolunit_declare_fixture(timer_test) 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); } };