Esempio n. 1
0
	/*!
	* \brief Restart the clock
	* Restarts the clock, putting it's time counter back to zero (as if the clock got constructed).
	*/
	void Clock::Restart()
	{
		NazaraLock(m_mutex);

		m_elapsedTime = 0;
		m_refTime = GetElapsedMicroseconds();
		m_paused = false;
	}
		UInt64 GetElapsedMicrosecondsFirstRun()
		{
			if (ClockImplInitializeHighPrecision())
				GetElapsedMicroseconds = ClockImplGetElapsedMicroseconds;
			else
				GetElapsedMicroseconds = GetMicrosecondsLowPrecision;

			return GetElapsedMicroseconds();
		}
	/*!
	* Returns the elapsed time in microseconds
	* \return Microseconds elapsed
	*
	* \see GetMilliseconds, GetSeconds
	*/
	UInt64 Clock::GetMicroseconds() const
	{
		NazaraLock(m_mutex);

		UInt64 elapsedMicroseconds = m_elapsedTime;
		if (!m_paused)
			elapsedMicroseconds += (GetElapsedMicroseconds() - m_refTime);

		return elapsedMicroseconds;
	}
	/*!
	* \brief Unpause the clock
	*
	* Unpauses the clock, making the clock continue to measure the time
	* This has no effect if the clock is already unpaused
	*
	* \see IsPaused, Unpause
	*/
	void Clock::Unpause()
	{
		NazaraLock(m_mutex);

		if (m_paused)
		{
			m_refTime = GetElapsedMicroseconds();
			m_paused = false;
		}
	}
	/*!
	* \brief Pause the clock
	*
	* Pauses the clock, making the time retrieving functions to always return the value at the time the clock was paused
	* This has no effect if the clock is already paused
	*
	* \see IsPaused, Unpause
	*/
	void Clock::Pause()
	{
		NazaraLock(m_mutex);

		if (!m_paused)
		{
			m_elapsedTime += GetElapsedMicroseconds() - m_refTime;
			m_paused = true;
		}
	}
	/*!
	* \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).
	*/
	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 = now;
		m_paused = false;

		return elapsedTime;
	}
	/*!
	* \brief Constructs a Clock object
	*
	* \param startingValue The starting time value, in microseconds
	* \param paused The clock pause state
	*/
	Clock::Clock(UInt64 startingValue, bool paused) :
	m_elapsedTime(startingValue),
	m_refTime(GetElapsedMicroseconds()),
	m_paused(paused)
	{
	}
Esempio n. 8
0
double GetElapsedSeconds()
{
    return ((double)GetElapsedMicroseconds() / (double)Frequency.QuadPart);
}