Ver Fonte

Able to query how long slept for each frame

Bill Robinson há 11 anos atrás
pai
commit
8ed65a36c5
2 ficheiros alterados com 11 adições e 3 exclusões
  1. 5 0
      Core/Contents/Include/PolyCore.h
  2. 6 3
      Core/Contents/Source/PolyCore.cpp

+ 5 - 0
Core/Contents/Include/PolyCore.h

@@ -317,6 +317,10 @@ namespace Polycode {
 		long getRefreshIntervalMs() const {
 		long getRefreshIntervalMs() const {
 			return refreshInterval;
 			return refreshInterval;
 		}
 		}
+
+		long getTimeSleptMs() const {
+			return timeSleptMs;
+		}
 		
 		
 		/**
 		/**
 		* Returns the total ticks elapsed since launch.
 		* Returns the total ticks elapsed since launch.
@@ -396,6 +400,7 @@ namespace Polycode {
 		void *userPointer;
 		void *userPointer;
 		
 		
 		long refreshInterval;
 		long refreshInterval;
+		unsigned int timeSleptMs;
 		
 		
 		bool fullScreen;
 		bool fullScreen;
 		int aaLevel;
 		int aaLevel;

+ 6 - 3
Core/Contents/Source/PolyCore.cpp

@@ -241,13 +241,16 @@ namespace Polycode {
 	void Core::doSleep() {
 	void Core::doSleep() {
 		unsigned int ticks = getTicks();
 		unsigned int ticks = getTicks();
 		unsigned int ticksSinceLastFrame = ticks - lastSleepFrameTicks;
 		unsigned int ticksSinceLastFrame = ticks - lastSleepFrameTicks;
-		if(ticksSinceLastFrame <= refreshInterval)
+		int sleepTimeMs = refreshInterval - ticksSinceLastFrame;
+		if(sleepTimeMs > 0) {
 #ifdef _WINDOWS
 #ifdef _WINDOWS
-		Sleep((refreshInterval - ticksSinceLastFrame));
+			Sleep(sleepTimeMs);
 #else
 #else
-			usleep((refreshInterval - ticksSinceLastFrame) * 1000);
+			usleep(sleepTimeMs * 1000);
 #endif
 #endif
+		}
 		lastSleepFrameTicks = getTicks();
 		lastSleepFrameTicks = getTicks();
+		timeSleptMs = lastSleepFrameTicks - ticks;
 	}
 	}