+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+* This file is part of CasparCG.\r
+*\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
#pragma once\r
\r
+#define NOMINMAX\r
+\r
#include <windows.h>\r
\r
namespace caspar {\r
\r
-class timer\r
+class high_prec_timer\r
{\r
public:\r
- timer()\r
+ high_prec_timer()\r
{\r
QueryPerformanceFrequency(&freq_);\r
QueryPerformanceCounter(&time_);\r
\r
// Author: Ryan M. Geiss\r
// http://www.geisswerks.com/ryan/FAQS/timing.html\r
- void wait(double fps)\r
+ void tick(double interval)\r
{ \r
LARGE_INTEGER t;\r
QueryPerformanceCounter(&t);\r
\r
if (time_.QuadPart != 0)\r
{\r
- int ticks_to_wait = static_cast<int>(static_cast<double>(freq_.QuadPart) / fps);\r
- int done = 0;\r
+ __int64 ticks_to_wait = static_cast<int>(static_cast<double>(freq_.QuadPart) * interval);\r
+ __int64 done = 0;\r
do\r
{\r
QueryPerformanceCounter(&t);\r
\r
- int ticks_passed = static_cast<int>(static_cast<__int64>(t.QuadPart) - static_cast<__int64>(time_.QuadPart));\r
- int ticks_left = ticks_to_wait - ticks_passed;\r
+ __int64 ticks_passed = static_cast<__int64>(t.QuadPart) - static_cast<__int64>(time_.QuadPart);\r
+ __int64 ticks_left = ticks_to_wait - ticks_passed;\r
\r
if (t.QuadPart < time_.QuadPart) // time wrap\r
done = 1;\r
// otherwise, do a few Sleep(0)'s, which just give up the timeslice,\r
// but don't really save cpu or battery, but do pass a tiny\r
// amount of time.\r
- if (ticks_left > static_cast<int>((freq_.QuadPart*2)/1000))\r
+ if (ticks_left > static_cast<__int64>((freq_.QuadPart*2)/1000))\r
Sleep(1);\r
else \r
for (int i = 0; i < 10; ++i) \r
LARGE_INTEGER time_;\r
};\r
\r
+\r
}
\ No newline at end of file