[Scummvm-git-logs] scummvm master -> 862bd7d05f8c75b71d37ebf1e1df94df1462b94e

aquadran aquadran at gmail.com
Wed Oct 27 21:11:26 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
862bd7d05f GRAPHICS: Move FrameLimiter from engines to common graphics code


Commit: 862bd7d05f8c75b71d37ebf1e1df94df1462b94e
    https://github.com/scummvm/scummvm/commit/862bd7d05f8c75b71d37ebf1e1df94df1462b94e
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-10-27T23:11:20+02:00

Commit Message:
GRAPHICS: Move FrameLimiter from engines to common graphics code

Changed paths:
  A graphics/framelimiter.cpp
  A graphics/framelimiter.h
  R engines/playground3d/framelimiter.cpp
  R engines/playground3d/framelimiter.h
  R engines/stark/gfx/framelimiter.cpp
  R engines/stark/gfx/framelimiter.h
    engines/myst3/gfx.cpp
    engines/myst3/gfx.h
    engines/myst3/myst3.cpp
    engines/myst3/myst3.h
    engines/myst3/transition.cpp
    engines/myst3/transition.h
    engines/playground3d/module.mk
    engines/playground3d/playground3d.cpp
    engines/playground3d/playground3d.h
    engines/stark/module.mk
    engines/stark/stark.cpp
    engines/stark/stark.h
    graphics/module.mk


diff --git a/engines/myst3/gfx.cpp b/engines/myst3/gfx.cpp
index 0935745020..2f6c0947a7 100644
--- a/engines/myst3/gfx.cpp
+++ b/engines/myst3/gfx.cpp
@@ -305,31 +305,6 @@ Common::Point Window::scalePoint(const Common::Point &screen) const {
 	return scaledPosition;
 }
 
-FrameLimiter::FrameLimiter(OSystem *system, const uint framerate) :
-	_system(system),
-	_speedLimitMs(0),
-	_startFrameTime(0) {
-	// The frame limiter is disabled when vsync is enabled.
-	_enabled = !_system->getFeatureState(OSystem::kFeatureVSync) && framerate != 0;
-
-	if (_enabled) {
-		_speedLimitMs = 1000 / CLIP<uint>(framerate, 0, 100);
-	}
-}
-
-void FrameLimiter::startFrame() {
-	_startFrameTime = _system->getMillis();
-}
-
-void FrameLimiter::delayBeforeSwap() {
-	uint endFrameTime = _system->getMillis();
-	uint frameDuration = endFrameTime - _startFrameTime;
-
-	if (_enabled && frameDuration < _speedLimitMs) {
-		_system->delayMillis(_speedLimitMs - frameDuration);
-	}
-}
-
 const Graphics::PixelFormat Texture::getRGBAPixelFormat() {
 #ifdef SCUMM_BIG_ENDIAN
 	return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
diff --git a/engines/myst3/gfx.h b/engines/myst3/gfx.h
index e6d3916898..f817fe8900 100644
--- a/engines/myst3/gfx.h
+++ b/engines/myst3/gfx.h
@@ -195,28 +195,6 @@ protected:
 	Math::Matrix4 makeProjectionMatrix(float fov) const;
 };
 
-/**
- * A framerate limiter
- *
- * Ensures the framerate does not exceed the specified value
- * by delaying until all of the timeslot allocated to the frame
- * is consumed.
- * Allows to curb CPU usage and have a stable framerate.
- */
-class FrameLimiter {
-public:
-	FrameLimiter(OSystem *system, const uint framerate);
-
-	void startFrame();
-	void delayBeforeSwap();
-private:
-	OSystem *_system;
-
-	bool _enabled;
-	uint _speedLimitMs;
-	uint _startFrameTime;
-};
-
 Renderer *CreateGfxOpenGL(OSystem *system);
 Renderer *CreateGfxOpenGLShader(OSystem *system);
 Renderer *CreateGfxTinyGL(OSystem *system);
diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp
index e8d79b922f..843a53b890 100644
--- a/engines/myst3/myst3.cpp
+++ b/engines/myst3/myst3.cpp
@@ -57,6 +57,7 @@
 #include "graphics/conversion.h"
 #include "graphics/renderer.h"
 #include "graphics/yuv_to_rgb.h"
+#include "graphics/framelimiter.h"
 
 #include "math/vector2d.h"
 
@@ -148,7 +149,7 @@ Common::Error Myst3Engine::run() {
 	_gfx->init();
 	_gfx->clear();
 
-	_frameLimiter = new FrameLimiter(_system, ConfMan.getInt("engine_speed"));
+	_frameLimiter = new Graphics::FrameLimiter(_system, ConfMan.getInt("engine_speed"));
 	_sound = new Sound(this);
 	_ambient = new Ambient(this);
 	_rnd = new Common::RandomSource("sprint");
diff --git a/engines/myst3/myst3.h b/engines/myst3/myst3.h
index cb205d29ca..a719c85db7 100644
--- a/engines/myst3/myst3.h
+++ b/engines/myst3/myst3.h
@@ -34,6 +34,7 @@
 
 namespace Graphics {
 struct Surface;
+class FrameLimiter;
 }
 
 namespace Common {
@@ -79,7 +80,6 @@ class ScriptedMovie;
 class ShakeEffect;
 class RotationEffect;
 class Transition;
-class FrameLimiter;
 struct NodeData;
 struct Myst3GameDescription;
 
@@ -212,7 +212,7 @@ private:
 	// Used by Voltaic's spinning gears
 	RotationEffect *_rotationEffect;
 
-	FrameLimiter *_frameLimiter;
+	Graphics::FrameLimiter *_frameLimiter;
 	Transition *_transition;
 
 	bool _inputSpacePressed;
diff --git a/engines/myst3/transition.cpp b/engines/myst3/transition.cpp
index 0fb98f1346..a694d9924f 100644
--- a/engines/myst3/transition.cpp
+++ b/engines/myst3/transition.cpp
@@ -28,6 +28,7 @@
 #include "engines/myst3/state.h"
 
 #include "graphics/surface.h"
+#include "graphics/framelimiter.h"
 
 namespace Myst3 {
 
@@ -35,7 +36,7 @@ Transition::Transition(Myst3Engine *vm) :
 		_vm(vm),
 		_type(kTransitionNone),
 		_sourceScreenshot(nullptr),
-		_frameLimiter(new FrameLimiter(g_system, ConfMan.getInt("engine_speed"))) {
+		_frameLimiter(new Graphics::FrameLimiter(g_system, ConfMan.getInt("engine_speed"))) {
 
 	// Capture a screenshot of the source node
 	int durationTicks = computeDuration();
diff --git a/engines/myst3/transition.h b/engines/myst3/transition.h
index e016ce1ef8..f2dc90d656 100644
--- a/engines/myst3/transition.h
+++ b/engines/myst3/transition.h
@@ -27,9 +27,11 @@
 
 #include "engines/myst3/gfx.h"
 
-namespace Myst3 {
-
+namespace Graphics {
 class FrameLimiter;
+}
+
+namespace Myst3 {
 
 class Transition {
 public:
@@ -44,7 +46,7 @@ private:
 	void playSound();
 
 	Myst3Engine *_vm;
-	FrameLimiter *_frameLimiter;
+	Graphics::FrameLimiter *_frameLimiter;
 	TransitionType _type;
 
 	Texture *_sourceScreenshot;
diff --git a/engines/playground3d/module.mk b/engines/playground3d/module.mk
index d0e2f280c3..020c0255ca 100644
--- a/engines/playground3d/module.mk
+++ b/engines/playground3d/module.mk
@@ -2,7 +2,6 @@ MODULE := engines/playground3d
 
 MODULE_OBJS := \
 	metaengine.o \
-	framelimiter.o \
 	gfx.o \
 	gfx_opengl.o \
 	gfx_opengl_shaders.o \
diff --git a/engines/playground3d/playground3d.cpp b/engines/playground3d/playground3d.cpp
index 79d5ed3d02..9b086096ea 100644
--- a/engines/playground3d/playground3d.cpp
+++ b/engines/playground3d/playground3d.cpp
@@ -59,7 +59,7 @@ Common::Error Playground3dEngine::run() {
 	_gfx = createRenderer(_system);
 	_gfx->init();
 
-	_frameLimiter = new Gfx::FrameLimiter(_system, ConfMan.getInt("engine_speed"));
+	_frameLimiter = new Graphics::FrameLimiter(_system, ConfMan.getInt("engine_speed"));
 
 	_system->showMouse(true);
 
diff --git a/engines/playground3d/playground3d.h b/engines/playground3d/playground3d.h
index b571f53321..4b55ad7a6a 100644
--- a/engines/playground3d/playground3d.h
+++ b/engines/playground3d/playground3d.h
@@ -25,10 +25,11 @@
 
 #include "common/array.h"
 
+#include "graphics/framelimiter.h"
+
 #include "engines/engine.h"
 
 #include "engines/playground3d/gfx.h"
-#include "engines/playground3d/framelimiter.h"
 
 namespace Playground3d {
 
@@ -48,7 +49,7 @@ public:
 private:
 	OSystem *_system;
 	Renderer *_gfx;
-	Gfx::FrameLimiter *_frameLimiter;
+	Graphics::FrameLimiter *_frameLimiter;
 	Math::Vector4d _clearColor;
 	float _fade;
 	bool _fadeIn;
diff --git a/engines/stark/gfx/framelimiter.cpp b/engines/stark/gfx/framelimiter.cpp
deleted file mode 100644
index 2fa2d85c7b..0000000000
--- a/engines/stark/gfx/framelimiter.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/* ResidualVM - A 3D game interpreter
- *
- * ResidualVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "engines/stark/gfx/framelimiter.h"
-
-#include "common/util.h"
-
-namespace Stark {
-namespace Gfx {
-
-FrameLimiter::FrameLimiter(OSystem *system, const uint framerate) :
-		_system(system),
-		_speedLimitMs(0),
-		_startFrameTime(0),
-		_lastFrameDurationMs(_speedLimitMs) {
-	// The frame limiter is disabled when vsync is enabled.
-	_enabled = !_system->getFeatureState(OSystem::kFeatureVSync) && framerate != 0;
-
-	if (_enabled) {
-		_speedLimitMs = 1000 / CLIP<uint>(framerate, 0, 100);
-	}
-}
-
-void FrameLimiter::startFrame() {
-	uint currentTime = _system->getMillis();
-
-	if (_startFrameTime != 0) {
-		_lastFrameDurationMs = currentTime - _startFrameTime;
-	}
-
-	_startFrameTime = currentTime;
-}
-
-void FrameLimiter::delayBeforeSwap() {
-	uint endFrameTime = _system->getMillis();
-	uint frameDuration = endFrameTime - _startFrameTime;
-
-	if (_enabled && frameDuration < _speedLimitMs) {
-		_system->delayMillis(_speedLimitMs - frameDuration);
-	}
-}
-
-void FrameLimiter::pause(bool pause) {
-	if (!pause) {
-		// Make sure the frame duration value is consistent when resuming
-		_startFrameTime = 0;
-	}
-}
-
-uint FrameLimiter::getLastFrameDuration() const {
-	return _lastFrameDurationMs;
-}
-
-} // End of namespace Gfx
-} // End of namespace Stark
diff --git a/engines/stark/gfx/framelimiter.h b/engines/stark/gfx/framelimiter.h
deleted file mode 100644
index b83fb2484b..0000000000
--- a/engines/stark/gfx/framelimiter.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* ResidualVM - A 3D game interpreter
- *
- * ResidualVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef STARK_GFX_FRAMELIMITER_H
-#define STARK_GFX_FRAMELIMITER_H
-
-#include "common/system.h"
-
-namespace Stark {
-
-namespace Gfx {
-
-/**
- * A framerate limiter
- *
- * Ensures the framerate does not exceed the specified value
- * by delaying until all of the timeslot allocated to the frame
- * is consumed.
- * Allows to curb CPU usage and have a stable framerate.
- */
-class FrameLimiter {
-public:
-	FrameLimiter(OSystem *system, const uint framerate);
-
-	void startFrame();
-	void delayBeforeSwap();
-
-	void pause(bool pause);
-
-	uint getLastFrameDuration() const;
-private:
-	OSystem *_system;
-
-	bool _enabled;
-	uint _speedLimitMs;
-	uint _startFrameTime;
-	uint _lastFrameDurationMs;
-};
-
-} // End of namespace Gfx
-} // End of namespace Stark
-
-#endif // STARK_GFX_FRAMELIMITER_H
diff --git a/engines/stark/module.mk b/engines/stark/module.mk
index a8e44099e6..aa32e30cc5 100644
--- a/engines/stark/module.mk
+++ b/engines/stark/module.mk
@@ -3,7 +3,6 @@ MODULE := engines/stark
 MODULE_OBJS := \
 	console.o \
 	gfx/driver.o \
-	gfx/framelimiter.o \
 	gfx/opengls.o \
 	gfx/openglsactor.o \
 	gfx/openglsfade.o \
diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp
index c9a3a38049..5ef91529b2 100644
--- a/engines/stark/stark.cpp
+++ b/engines/stark/stark.cpp
@@ -43,7 +43,6 @@
 #include "engines/stark/services/gamechapter.h"
 #include "engines/stark/services/gamemessage.h"
 #include "engines/stark/gfx/driver.h"
-#include "engines/stark/gfx/framelimiter.h"
 
 #include "audio/mixer.h"
 #include "common/config-manager.h"
@@ -56,6 +55,7 @@
 #include "common/translation.h"
 #include "engines/advancedDetector.h"
 #include "graphics/renderer.h"
+#include "graphics/framelimiter.h"
 #include "gui/message.h"
 
 namespace Stark {
@@ -94,7 +94,7 @@ StarkEngine::~StarkEngine() {
 
 Common::Error StarkEngine::run() {
 	setDebugger(new Console());
-	_frameLimiter = new Gfx::FrameLimiter(_system, ConfMan.getInt("engine_speed"));
+	_frameLimiter = new Graphics::FrameLimiter(_system, ConfMan.getInt("engine_speed"));
 
 	// Get the screen prepared
 	Gfx::Driver *gfx = Gfx::Driver::create();
diff --git a/engines/stark/stark.h b/engines/stark/stark.h
index 3eddbbe349..fc0235e319 100644
--- a/engines/stark/stark.h
+++ b/engines/stark/stark.h
@@ -34,11 +34,14 @@ namespace Common {
 class RandomSource;
 }
 
+namespace Graphics {
+class FrameLimiter;
+}
+
 namespace Stark {
 
 namespace Gfx {
 class Driver;
-class FrameLimiter;
 }
 
 class ArchiveLoader;
@@ -91,7 +94,7 @@ private:
 	void addModsToSearchPath() const;
 	static void checkRecommendedDatafiles();
 
-	Gfx::FrameLimiter *_frameLimiter;
+	Graphics::FrameLimiter *_frameLimiter;
 	PauseToken _gamePauseToken;
 
 	const ADGameDescription *_gameDescription;
diff --git a/engines/playground3d/framelimiter.cpp b/graphics/framelimiter.cpp
similarity index 93%
rename from engines/playground3d/framelimiter.cpp
rename to graphics/framelimiter.cpp
index e3040e61ea..d6fcd8064c 100644
--- a/engines/playground3d/framelimiter.cpp
+++ b/graphics/framelimiter.cpp
@@ -20,12 +20,11 @@
  *
  */
 
-#include "engines/playground3d/framelimiter.h"
+#include "graphics/framelimiter.h"
 
 #include "common/util.h"
 
-namespace Playground3d {
-namespace Gfx {
+namespace Graphics {
 
 FrameLimiter::FrameLimiter(OSystem *system, const uint framerate) :
 		_system(system),
@@ -70,5 +69,4 @@ uint FrameLimiter::getLastFrameDuration() const {
 	return _lastFrameDurationMs;
 }
 
-} // End of namespace Gfx
-} // End of namespace Playground3d
+} // End of namespace Graphics
diff --git a/engines/playground3d/framelimiter.h b/graphics/framelimiter.h
similarity index 87%
rename from engines/playground3d/framelimiter.h
rename to graphics/framelimiter.h
index c06a31b134..f2078a864d 100644
--- a/engines/playground3d/framelimiter.h
+++ b/graphics/framelimiter.h
@@ -20,14 +20,12 @@
  *
  */
 
-#ifndef PLAYGROUND3D_GFX_FRAMELIMITER_H
-#define PLAYGROUND3D_GFX_FRAMELIMITER_H
+#ifndef GFX_FRAMELIMITER_H
+#define GFX_FRAMELIMITER_H
 
 #include "common/system.h"
 
-namespace Playground3d {
-
-namespace Gfx {
+namespace Graphics {
 
 /**
  * A framerate limiter
@@ -56,7 +54,6 @@ private:
 	uint _lastFrameDurationMs;
 };
 
-} // End of namespace Gfx
-} // End of namespace Playground3d
+} // End of namespace Graphics
 
-#endif // PLAYGROUND3D_GFX_FRAMELIMITER_H
+#endif // GFX_FRAMELIMITER_H
diff --git a/graphics/module.mk b/graphics/module.mk
index 6e43fa6478..00b5f005e7 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -13,6 +13,7 @@ MODULE_OBJS := \
 	fonts/newfont.o \
 	fonts/ttf.o \
 	fonts/winfont.o \
+	framelimiter.o \
 	korfont.o \
 	larryScale.o \
 	maccursor.o \




More information about the Scummvm-git-logs mailing list