Browse Source

Some windows improvements

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
43ef8e4a7d
3 changed files with 27 additions and 9 deletions
  1. 4 0
      CMakeLists.txt
  2. 2 1
      README.md
  3. 21 8
      src/anki/util/HighRezTimerWindows.cpp

+ 4 - 0
CMakeLists.txt

@@ -192,6 +192,10 @@ if(NOT MSVC)
 else()
 else()
 	ProcessorCount(PC)
 	ProcessorCount(PC)
 	add_definitions("/MP${PC}")
 	add_definitions("/MP${PC}")
+
+	if(${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
+		add_definitions("/Ox")
+	endif()
 endif()
 endif()
 
 
 # Use gold linker
 # Use gold linker

+ 2 - 1
README.md

@@ -63,6 +63,7 @@ Prerequisites:
 - Python 3.0 and up
 - Python 3.0 and up
 	- Make sure that the python executable's location is in `PATH` environment variable
 	- Make sure that the python executable's location is in `PATH` environment variable
 - Microsoft Visual Studio 2017 and up
 - Microsoft Visual Studio 2017 and up
+	- Make sure that `Windows 10 SDK (xxx) for Desktop C++ [x86 and x64]` component is installed
 
 
 To build the release version open `PowerShell` and type:
 To build the release version open `PowerShell` and type:
 
 
@@ -70,7 +71,7 @@ To build the release version open `PowerShell` and type:
 	$mkdir build
 	$mkdir build
 	$cd build
 	$cd build
 	$cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release
 	$cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release
-	$cmake --build .
+	$cmake --build . --config Release
 
 
 Alternatively, recent Visual Studio versions support building CMake projects from inside the IDE:
 Alternatively, recent Visual Studio versions support building CMake projects from inside the IDE:
 
 

+ 21 - 8
src/anki/util/HighRezTimerWindows.cpp

@@ -5,6 +5,7 @@
 
 
 #include <anki/util/HighRezTimer.h>
 #include <anki/util/HighRezTimer.h>
 #include <anki/util/Assert.h>
 #include <anki/util/Assert.h>
+#include <cstdio>
 #include <Windows.h>
 #include <Windows.h>
 
 
 namespace anki
 namespace anki
@@ -17,11 +18,18 @@ namespace
 class DummyInitTimer
 class DummyInitTimer
 {
 {
 public:
 public:
-	DWORD m_start;
+	LARGE_INTEGER m_start;
+	LARGE_INTEGER m_ticksPerSec;
 
 
 	DummyInitTimer()
 	DummyInitTimer()
 	{
 	{
-		m_start = GetTickCount();
+		if (!QueryPerformanceFrequency(&m_ticksPerSec))
+		{
+			fprintf(stderr, "QueryPerformanceFrequency() failed\n");
+			abort();
+		}
+
+		QueryPerformanceCounter(&m_start);
 	}
 	}
 };
 };
 
 
@@ -29,22 +37,27 @@ DummyInitTimer init;
 
 
 } // end namespace anonymous
 } // end namespace anonymous
 
 
-static U32 getMs()
+static U64 getMs()
 {
 {
-	DWORD now = GetTickCount();
-	return now - init.m_start;
+	LARGE_INTEGER now;
+	QueryPerformanceCounter(&now);
+
+	now.QuadPart -= init.m_start.QuadPart;
+	now.QuadPart *= 1000;
+	now.QuadPart /= init.m_ticksPerSec.QuadPart;
+
+	return now.QuadPart;
 }
 }
 
 
 void HighRezTimer::sleep(Second sec)
 void HighRezTimer::sleep(Second sec)
 {
 {
-	U32 ms = static_cast<U32>(sec * 1000.0);
-	Sleep(ms);
+	Sleep(U32(sec * 1000.0));
 }
 }
 
 
 Second HighRezTimer::getCurrentTime()
 Second HighRezTimer::getCurrentTime()
 {
 {
 	// Second(ticks) / 1000.0
 	// Second(ticks) / 1000.0
-	return static_cast<Second>(getMs()) * 0.001;
+	return Second(getMs()) * 0.001;
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki