Bläddra i källkod

Merge pull request #365 from dbstone/master

Fixes to the timing system
Ivan Safrin 12 år sedan
förälder
incheckning
d9d0f4bd4c

+ 4 - 1
Core/Contents/Include/PolyWinCore.h

@@ -118,7 +118,7 @@ namespace Polycode {
 		std::vector<TouchInfo> touches;
 		PolyKEY keyCode;
 		wchar_t unicodeChar;		
-		char mouseButton;	
+		char mouseButton;	
 		static const int EVENTBASE_PLATFORMEVENT = 0x300;
 		static const int INPUT_EVENT = EVENTBASE_PLATFORMEVENT+0;
 	};
@@ -272,6 +272,9 @@ public:
 		unsigned int PixelFormat;
 		PIXELFORMATDESCRIPTOR pfd;
 		
+		// frequency of the windows performance counter
+		double pcFreq;
+
 		// Tracks whether the system supports multitouch at runtime
 		bool hasMultiTouch;
 		

+ 1 - 1
Core/Contents/Source/PolyCore.cpp

@@ -242,7 +242,7 @@ namespace Polycode {
 #else
 			usleep((refreshInterval - ticksSinceLastFrame) * 1000);
 #endif
-		lastSleepFrameTicks = ticks;
+		lastSleepFrameTicks = getTicks();
 	}
 	
 	

+ 7 - 1
Core/Contents/Source/PolyWinCore.cpp

@@ -126,6 +126,10 @@ Win32Core::Win32Core(PolycodeViewBase *view, int _xRes, int _yRes, bool fullScre
 	wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
 	wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) wglGetProcAddress("wglGetSwapIntervalEXT");
 	
+	LARGE_INTEGER li;
+	QueryPerformanceFrequency(&li);
+	pcFreq = double(li.QuadPart)/1000.0;
+	
 	setVSync(vSync);
 
 	CoreServices::getInstance()->installModule(new GLSLShaderModule());	
@@ -161,7 +165,9 @@ void Win32Core::warpCursor(int x, int y) {
 }
 
 unsigned int Win32Core::getTicks() {
-	return GetTickCount();
+	LARGE_INTEGER li;
+	QueryPerformanceCounter(&li);
+	return unsigned int(li.QuadPart / pcFreq);
 }
 
 void Win32Core::Render() {