Sfoglia il codice sorgente

Merge pull request #487 from wivlaro/query-time-slept

Able to query how long slept for each frame
Ivan Safrin 11 anni fa
parent
commit
6d6c1dbafa
2 ha cambiato i file con 11 aggiunte e 3 eliminazioni
  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 {
 			return refreshInterval;
 		}
+
+		long getTimeSleptMs() const {
+			return timeSleptMs;
+		}
 		
 		/**
 		* Returns the total ticks elapsed since launch.
@@ -396,6 +400,7 @@ namespace Polycode {
 		void *userPointer;
 		
 		long refreshInterval;
+		unsigned int timeSleptMs;
 		
 		bool fullScreen;
 		int aaLevel;

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

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