/*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
*\r
-* This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\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
+* 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
+* 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
+* Author: Robert Nagy, ronag89@gmail.com\r
*/\r
+\r
#pragma once\r
\r
+#define NOMINMAX\r
+\r
#include <windows.h>\r
+#include <Mmsystem.h>\r
\r
namespace caspar {\r
\r
{\r
public:\r
high_prec_timer()\r
+ : time_(0)\r
{\r
- QueryPerformanceFrequency(&freq_);\r
- QueryPerformanceCounter(&time_);\r
}\r
\r
// Author: Ryan M. Geiss\r
// http://www.geisswerks.com/ryan/FAQS/timing.html\r
void tick(double interval)\r
{ \r
- LARGE_INTEGER t;\r
- QueryPerformanceCounter(&t);\r
+ auto t = ::timeGetTime();\r
\r
- if (time_.QuadPart != 0)\r
+ if (time_ != 0)\r
{\r
- int ticks_to_wait = static_cast<int>(static_cast<double>(freq_.QuadPart) * interval);\r
- int done = 0;\r
+ auto ticks_to_wait = static_cast<DWORD>(interval*1000.0);\r
+ bool 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
+ { \r
+ auto ticks_passed = t - time_;\r
+ auto ticks_left = ticks_to_wait - ticks_passed;\r
\r
- if (t.QuadPart < time_.QuadPart) // time wrap\r
+ if (t < time_) // time wrap\r
done = 1;\r
if (ticks_passed >= ticks_to_wait)\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 > 2)\r
Sleep(1);\r
else \r
for (int i = 0; i < 10; ++i) \r
Sleep(0); // causes thread to give up its timeslice\r
}\r
+\r
+ t = ::timeGetTime();\r
}\r
while (!done); \r
}\r
time_ = t;\r
} \r
private: \r
- LARGE_INTEGER freq_;\r
- LARGE_INTEGER time_;\r
+ DWORD time_;\r
};\r
\r
\r