diff options
author | Max Horn | 2010-10-13 10:41:30 +0000 |
---|---|---|
committer | Max Horn | 2010-10-13 10:41:30 +0000 |
commit | 02322c562cfb27d7519a9ed86d1f2ff99cd379cc (patch) | |
tree | c04527ca8ee7070391c9de933eb426de427595ec /engines/sword25/gfx | |
parent | 655e4a961af0bd21b30ec3162b230ed387c1df21 (diff) | |
download | scummvm-rg350-02322c562cfb27d7519a9ed86d1f2ff99cd379cc.tar.gz scummvm-rg350-02322c562cfb27d7519a9ed86d1f2ff99cd379cc.tar.bz2 scummvm-rg350-02322c562cfb27d7519a9ed86d1f2ff99cd379cc.zip |
SWORD25: Get rid of Kernel::GetMicroTicks()
svn-id: r53403
Diffstat (limited to 'engines/sword25/gfx')
-rw-r--r-- | engines/sword25/gfx/graphicengine.cpp | 30 | ||||
-rw-r--r-- | engines/sword25/gfx/graphicengine.h | 22 |
2 files changed, 28 insertions, 24 deletions
diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp index ea0c8c82c5..9f3ce665cd 100644 --- a/engines/sword25/gfx/graphicengine.cpp +++ b/engines/sword25/gfx/graphicengine.cpp @@ -83,7 +83,7 @@ GraphicEngine::GraphicEngine(Kernel *pKernel) : 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::DrawDebugLine(const Vertex &Start, const Vertex &End, uint C } void GraphicEngine::UpdateLastFrameDuration() { - // Aktuelle Zeit holen - uint64_t CurrentTime = Kernel::GetInstance()->GetMicroTicks(); - - // Verstrichene Zeit seit letztem Frame berechnen und zu große Zeitsprünge ( > 250 msek.) unterbinden - // (kann vorkommen bei geladenen Spielständen, während 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; + // Record current time + const uint currentTime = Kernel::GetInstance()->GetMilliTicks(); + + // 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 über 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 { diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h index 019f5eec4c..ecbfa377c8 100644 --- a/engines/sword25/gfx/graphicengine.h +++ b/engines/sword25/gfx/graphicengine.h @@ -189,17 +189,19 @@ public: /** * 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 @@ public: void ResumeMainTimer() { m_TimerActive = true; } - float GetSecondaryFrameDuration() { + float GetSecondaryFrameDuration() const { return static_cast<float>(m_LastFrameDuration) / 1000000.0f; } @@ -217,14 +219,14 @@ public: /** * 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 @@ private: // LastFrameDuration Variables // --------------------------- - uint64 m_LastTimeStamp; + uint m_LastTimeStamp; uint m_LastFrameDuration; bool m_TimerActive; Common::Array<uint> m_FrameTimeSamples; |