[Scummvm-cvs-logs] SF.net SVN: scummvm:[53403] scummvm/trunk/engines/sword25

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Oct 13 12:41:30 CEST 2010


Revision: 53403
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53403&view=rev
Author:   fingolfin
Date:     2010-10-13 10:41:30 +0000 (Wed, 13 Oct 2010)

Log Message:
-----------
SWORD25: Get rid of Kernel::GetMicroTicks()

Modified Paths:
--------------
    scummvm/trunk/engines/sword25/gfx/graphicengine.cpp
    scummvm/trunk/engines/sword25/gfx/graphicengine.h
    scummvm/trunk/engines/sword25/kernel/bs_stdint.h
    scummvm/trunk/engines/sword25/kernel/kernel.cpp
    scummvm/trunk/engines/sword25/kernel/kernel.h
    scummvm/trunk/engines/sword25/kernel/kernel_script.cpp

Modified: scummvm/trunk/engines/sword25/gfx/graphicengine.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/graphicengine.cpp	2010-10-13 10:12:35 UTC (rev 53402)
+++ scummvm/trunk/engines/sword25/gfx/graphicengine.cpp	2010-10-13 10:41:30 UTC (rev 53403)
@@ -83,7 +83,7 @@
 	m_Height(0),
 	m_BitDepth(0),
 	m_Windowed(0),
-	m_LastTimeStamp((uint64) - 1), // max. BS_INT64 um beim ersten Aufruf von _UpdateLastFrameDuration() einen Reset zu erzwingen
+	m_LastTimeStamp((uint) -1), // max. BS_INT64 um beim ersten Aufruf von _UpdateLastFrameDuration() einen Reset zu erzwingen
 	m_LastFrameDuration(0),
 	m_TimerActive(true),
 	m_FrameTimeSampleSlot(0),
@@ -378,23 +378,25 @@
 }
 
 void  GraphicEngine::UpdateLastFrameDuration() {
-	// Aktuelle Zeit holen
-	uint64_t CurrentTime = Kernel::GetInstance()->GetMicroTicks();
+	// Record current time
+	const uint currentTime = Kernel::GetInstance()->GetMilliTicks();
 
-	// Verstrichene Zeit seit letztem Frame berechnen und zu gro\xDFe Zeitspr\xFCnge ( > 250 msek.) unterbinden
-	// (kann vorkommen bei geladenen Spielst\xE4nden, w\xE4hrend des Debuggings oder Hardwareungenauigkeiten)
-	m_FrameTimeSamples[m_FrameTimeSampleSlot] = static_cast<uint>(CurrentTime - m_LastTimeStamp);
-	if (m_FrameTimeSamples[m_FrameTimeSampleSlot] > 250000) m_FrameTimeSamples[m_FrameTimeSampleSlot] = 250000;
+	// Compute the elapsed time since the last frame and prevent too big ( > 250 msecs) time jumps.
+	// These can occur when loading save states, during debugging or due to hardware inaccuracies.
+	m_FrameTimeSamples[m_FrameTimeSampleSlot] = static_cast<uint>(currentTime - m_LastTimeStamp);
+	if (m_FrameTimeSamples[m_FrameTimeSampleSlot] > 250000)
+		m_FrameTimeSamples[m_FrameTimeSampleSlot] = 250000;
 	m_FrameTimeSampleSlot = (m_FrameTimeSampleSlot + 1) % FRAMETIME_SAMPLE_COUNT;
 
-	// Die Framezeit wird \xFCber mehrere Frames gemittelt um Ausreisser zu eliminieren
+	// Compute the average frame duration over multiple frames to eliminate outliers.
 	Common::Array<uint>::const_iterator it = m_FrameTimeSamples.begin();
-	uint Sum = *it;
-	for (it++; it != m_FrameTimeSamples.end(); it++) Sum += *it;
-	m_LastFrameDuration = Sum / FRAMETIME_SAMPLE_COUNT;
+	uint sum = *it;
+	for (it++; it != m_FrameTimeSamples.end(); it++)
+		sum += *it;
+	m_LastFrameDuration = sum * 1000 / FRAMETIME_SAMPLE_COUNT;
 
-	// _LastTimeStamp auf die Zeit des aktuellen Frames setzen
-	m_LastTimeStamp = CurrentTime;
+	// Update m_LastTimeStamp with the current frame's timestamp
+	m_LastTimeStamp = currentTime;
 }
 
 namespace {

Modified: scummvm/trunk/engines/sword25/gfx/graphicengine.h
===================================================================
--- scummvm/trunk/engines/sword25/gfx/graphicengine.h	2010-10-13 10:12:35 UTC (rev 53402)
+++ scummvm/trunk/engines/sword25/gfx/graphicengine.h	2010-10-13 10:41:30 UTC (rev 53403)
@@ -189,17 +189,19 @@
 	/**
 	 * Specifies the time (in microseconds) since the last frame has passed
 	 */
-	int GetLastFrameDurationMicro() {
-		if (m_TimerActive) return m_LastFrameDuration;
-		else return 0;
+	int GetLastFrameDurationMicro() const {
+		if (!m_TimerActive)
+			return 0;
+		return m_LastFrameDuration;
 	}
 
 	/**
 	 * Specifies the time (in microseconds) the previous frame took
 	*/
-	float GetLastFrameDuration() {
-		if (m_TimerActive) return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
-		else return 0;
+	float GetLastFrameDuration() const {
+		if (!m_TimerActive)
+			return 0;
+		return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
 	}
 
 	void StopMainTimer() {
@@ -208,7 +210,7 @@
 	void ResumeMainTimer() {
 		m_TimerActive = true;
 	}
-	float GetSecondaryFrameDuration() {
+	float GetSecondaryFrameDuration() const {
 		return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
 	}
 
@@ -217,14 +219,14 @@
 	/**
 	 * Returns the width of the output buffer in pixels
 	 */
-	int         GetDisplayWidth() {
+	int         GetDisplayWidth() const {
 		return m_Width;
 	}
 
 	/**
 	 * Returns the height of the output buffer in pixels
 	 */
-	int         GetDisplayHeight() {
+	int         GetDisplayHeight() const {
 		return m_Height;
 	}
 
@@ -365,7 +367,7 @@
 
 	// LastFrameDuration Variables
 	// ---------------------------
-	uint64                      m_LastTimeStamp;
+	uint                      m_LastTimeStamp;
 	uint                m_LastFrameDuration;
 	bool                        m_TimerActive;
 	Common::Array<uint> m_FrameTimeSamples;

Modified: scummvm/trunk/engines/sword25/kernel/bs_stdint.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/bs_stdint.h	2010-10-13 10:12:35 UTC (rev 53402)
+++ scummvm/trunk/engines/sword25/kernel/bs_stdint.h	2010-10-13 10:41:30 UTC (rev 53403)
@@ -39,13 +39,6 @@
 
 #include "common/scummsys.h"
 
-typedef uint8 uint8_t;
-typedef uint16 uint16_t;
-typedef uint32 uint32_t;
-typedef int8 int8_t;
-typedef int16 int16_t;
-typedef int32 int32_t;
-
 typedef unsigned long long uint64_t;
 typedef signed long long int64_t;
 typedef unsigned long long uint64;

Modified: scummvm/trunk/engines/sword25/kernel/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel.cpp	2010-10-13 10:12:35 UTC (rev 53402)
+++ scummvm/trunk/engines/sword25/kernel/kernel.cpp	2010-10-13 10:41:30 UTC (rev 53403)
@@ -362,14 +362,6 @@
 	return g_system->getMillis();
 }
 
-/**
- * Returns the elapsed time since the system start in microseconds.
- * This method should be used only if GetMilliTick() for the desired application is inaccurate.
- */
-uint64 Kernel::GetMicroTicks() {
-	return g_system->getMillis() * 1000;
-}
-
 // Other methods
 // -----------------
 

Modified: scummvm/trunk/engines/sword25/kernel/kernel.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel.h	2010-10-13 10:12:35 UTC (rev 53402)
+++ scummvm/trunk/engines/sword25/kernel/kernel.h	2010-10-13 10:41:30 UTC (rev 53403)
@@ -160,12 +160,6 @@
 	uint GetMilliTicks();
 
 	/**
-	 * Returns the elapsed time since the system start in microseconds.
-	 * This method should be used only if GetMilliTick() for the desired application is inaccurate.
-	 */
-	uint64 GetMicroTicks();
-
-	/**
 	 * Specifies whether the kernel was successfully initialised
 	 */
 	bool GetInitSuccess() {

Modified: scummvm/trunk/engines/sword25/kernel/kernel_script.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel_script.cpp	2010-10-13 10:12:35 UTC (rev 53402)
+++ scummvm/trunk/engines/sword25/kernel/kernel_script.cpp	2010-10-13 10:41:30 UTC (rev 53403)
@@ -132,7 +132,7 @@
 	Kernel *pKernel = Kernel::GetInstance();
 	BS_ASSERT(pKernel);
 
-	lua_pushnumber(L, static_cast<lua_Number>(pKernel->GetMicroTicks()) / 1000000.0);
+	lua_pushnumber(L, static_cast<lua_Number>(pKernel->GetMilliTicks()) / 1000.0);
 
 	return 1;
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list