Path: blob/master/samples/wp8/OcvRotatingCube/PhoneXamlDirect3DApp1/PhoneXamlDirect3DApp1Comp/BasicTimer.h
16350 views
#pragma once12#include <wrl.h>34// Helper class for basic timing.5ref class BasicTimer sealed6{7public:8// Initializes internal timer values.9BasicTimer()10{11if (!QueryPerformanceFrequency(&m_frequency))12{13throw ref new Platform::FailureException();14}15Reset();16}1718// Reset the timer to initial values.19void Reset()20{21Update();22m_startTime = m_currentTime;23m_total = 0.0f;24m_delta = 1.0f / 60.0f;25}2627// Update the timer's internal values.28void Update()29{30if (!QueryPerformanceCounter(&m_currentTime))31{32throw ref new Platform::FailureException();33}3435m_total = static_cast<float>(36static_cast<double>(m_currentTime.QuadPart - m_startTime.QuadPart) /37static_cast<double>(m_frequency.QuadPart)38);3940if (m_lastTime.QuadPart == m_startTime.QuadPart)41{42// If the timer was just reset, report a time delta equivalent to 60Hz frame time.43m_delta = 1.0f / 60.0f;44}45else46{47m_delta = static_cast<float>(48static_cast<double>(m_currentTime.QuadPart - m_lastTime.QuadPart) /49static_cast<double>(m_frequency.QuadPart)50);51}5253m_lastTime = m_currentTime;54}5556// Duration in seconds between the last call to Reset() and the last call to Update().57property float Total58{59float get() { return m_total; }60}6162// Duration in seconds between the previous two calls to Update().63property float Delta64{65float get() { return m_delta; }66}6768private:69LARGE_INTEGER m_frequency;70LARGE_INTEGER m_currentTime;71LARGE_INTEGER m_startTime;72LARGE_INTEGER m_lastTime;73float m_total;74float m_delta;75};767778