Core/Clock: Restart now returns the elapsed time in milliseconds

This commit is contained in:
Jérôme Leclercq 2018-02-07 15:02:44 +01:00
parent b855dcb17e
commit fb3eb9443e
6 changed files with 20 additions and 12 deletions

View File

@ -59,6 +59,7 @@ Nazara Engine:
- Fix LuaClass not working correctly when Lua stack wasn't empty
- Add RigidBody2D simulation control (via EnableSimulation and IsSimulationEnabled), which allows to disable physics and collisions at will.
- ⚠️ LuaInstance no longer load all lua libraries on construction, this is done in the new LoadLibraries method which allows you to excludes some libraries
- Clock::Restart now returns the elapsed microseconds since construction or last Restart call
Nazara Development Kit:
- Added ImageWidget (#139)

View File

@ -107,8 +107,7 @@ namespace Ndk
if (m_shouldQuit)
return false;
m_updateTime = m_updateClock.GetSeconds();
m_updateClock.Restart();
m_updateTime = m_updateClock.Restart() / 1'000'000.f;
for (World& world : m_worlds)
world.Update(m_updateTime);

View File

@ -325,9 +325,7 @@ int main()
while (application.Run())
{
Nz::UInt64 elapsedUS = updateClock.GetMicroseconds();
// On relance l'horloge
updateClock.Restart();
Nz::UInt64 elapsedUS = updateClock.Restart() / 1'000'000;
// Mise à jour (Caméra)
const Nz::UInt64 updateRate = 1000000 / 60; // 60 fois par seconde

View File

@ -32,7 +32,7 @@ namespace Nz
bool IsPaused() const;
void Pause();
void Restart();
UInt64 Restart();
void Unpause();
Clock& operator=(const Clock& clock) = default;
@ -46,7 +46,7 @@ namespace Nz
bool m_paused;
};
typedef UInt64 (*ClockFunction)();
using ClockFunction = UInt64 (*)();
extern NAZARA_CORE_API ClockFunction GetElapsedMicroseconds;
extern NAZARA_CORE_API ClockFunction GetElapsedMilliseconds;

View File

@ -67,7 +67,7 @@ namespace Nz
*/
float Clock::GetSeconds() const
{
return GetMicroseconds()/1000000.f;
return GetMicroseconds()/1'000'000.f;
}
/*!
@ -132,15 +132,26 @@ namespace Nz
/*!
* \brief Restart the clock
* \return Microseconds elapsed
*
* Restarts the clock, putting it's time counter back to zero (as if the clock got constructed).
* It also compute the elapsed microseconds since the last Restart() call without any time loss (a problem that the combination of GetElapsedMicroseconds and Restart have).
*/
void Clock::Restart()
UInt64 Clock::Restart()
{
NazaraLock(m_mutex);
Nz::UInt64 now = GetElapsedMicroseconds();
Nz::UInt64 elapsedTime = m_elapsedTime;
if (!m_paused)
elapsedTime += (now - m_refTime);
m_elapsedTime = 0;
m_refTime = GetElapsedMicroseconds();
m_refTime = now;
m_paused = false;
return elapsedTime;
}
/*!

View File

@ -51,9 +51,8 @@ SCENARIO("EventHandler", "[PLATFORM][EVENTHANDLER][INTERACTIVE][.]")
while (app.Run())
{
window.Display();
float elapsedTime = elapsedTimeClock.GetSeconds();
elapsedTimeClock.Restart();
float elapsedTime = elapsedTimeClock.Restart() / 1'000'000;
if (!fsm.Update(elapsedTime))
{
NazaraError("Failed to update state machine.");