[Scummvm-git-logs] scummvm master -> 75f8cfac56371efe6acd9fd39b36bdec2dd18aa2

criezy criezy at scummvm.org
Sat May 2 23:13:43 UTC 2020


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:
75f8cfac56 DREAMWEB: Use more accurate vsync timing


Commit: 75f8cfac56371efe6acd9fd39b36bdec2dd18aa2
    https://github.com/scummvm/scummvm/commit/75f8cfac56371efe6acd9fd39b36bdec2dd18aa2
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-05-03T00:13:33+01:00

Commit Message:
DREAMWEB: Use more accurate vsync timing

The vsync delay is 14 ms (1000 / 70), and using a loop with
a sleep of 10ms until we had passed that delay meant we were
actually waiting anytime between 14 and 23 milliseconds, which
made the game slower than it should be. This was partially
corrected by using a delay of 11 ms (800 / 70), but this was
still inacurate and too slow in average.

In addition, since the change in commit 87c8b60, it was ignoring
the time spent in the game loop, which on slow devices is not
negligeable, and this has been fixed as well.

Finally also change the fast speed from 20 to 4. In commit
87c8b60 the delay was changed from macroseconds to milliseconds,
and any speed above 14 would then result in a delay of 0 due to
the integer division. We have the turbo mode for that, so it
seems to make sense to make the fast mode a bit slower rather
than having two modes that do the same thing.

Changed paths:
    engines/dreamweb/dreamweb.cpp
    engines/dreamweb/dreamweb.h


diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp
index de2e4647bb..cafe8a50f5 100644
--- a/engines/dreamweb/dreamweb.cpp
+++ b/engines/dreamweb/dreamweb.cpp
@@ -49,6 +49,7 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam
 	DebugMan.addDebugChannel(kDebugAnimation, "Animation", "Animation Debug Flag");
 	DebugMan.addDebugChannel(kDebugSaveLoad, "SaveLoad", "Track Save/Load Function");
 
+	_vSyncPrevTick = 0;
 	_sound = 0;
 	_speed = 1;
 	_turbo = false;
@@ -272,22 +273,25 @@ DreamWebEngine::~DreamWebEngine() {
 	delete _sound;
 }
 
-void DreamWebEngine::waitForVSync() {
-	const uint32 previousTicks = _system->getMillis();
-	// Originally, this was an interval for a thread that was
-	// called every 1000000 / 70 nanoseconds. It has been
-	// adjusted to be a delay instead.
-	const uint32 delay = 800 / 70 / _speed;
+void DreamWebEngine::pauseEngineIntern(bool pause) {
+	Engine::pauseEngineIntern(pause);
+	if (!pause)
+		_vSyncPrevTick = _system->getMillis();
+}
 
+void DreamWebEngine::waitForVSync() {
 	if (isPaused())
 		return;
 
 	processEvents();
 
-	while (!_turbo && _system->getMillis() - previousTicks < delay) {
-		processEvents(false);
-		_system->delayMillis(10);
+	if (!_turbo) {
+		const uint32 delay =  1000 / 70 / _speed;
+		uint32 elapsed = _system->getMillis() - _vSyncPrevTick;
+		if (elapsed < delay)
+			_system->delayMillis(delay - elapsed);
 	}
+	_vSyncPrevTick = _system->getMillis();
 
 	doShake();
 	doFade();
@@ -320,7 +324,7 @@ void DreamWebEngine::processEvents(bool processSoundEvents) {
 				switch (event.kbd.keycode) {
 
 				case Common::KEYCODE_f:
-					setSpeed(_speed != 20? 20: 1);
+					setSpeed(_speed != 4? 4: 1);
 					break;
 
 				case Common::KEYCODE_g:
@@ -399,6 +403,7 @@ Common::Error DreamWebEngine::run() {
 	_brightPalette = ConfMan.getBool("bright_palette");
 	_copyProtection = ConfMan.getBool("copy_protection");
 
+	_vSyncPrevTick = _system->getMillis();
 	dreamweb();
 	dreamwebFinalize();
 	_quitRequested = false;
diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h
index c01017b185..3e65e2c115 100644
--- a/engines/dreamweb/dreamweb.h
+++ b/engines/dreamweb/dreamweb.h
@@ -101,11 +101,13 @@ class DreamWebSound;
 class DreamWebEngine : public Engine {
 private:
 	DreamWebSound *_sound;
+	uint32 _vSyncPrevTick;
 
 protected:
 	// Engine APIs
 	Common::Error run() override;
 	bool hasFeature(EngineFeature f) const override;
+	void pauseEngineIntern(bool pause) override;
 
 public:
 	DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gameDesc);




More information about the Scummvm-git-logs mailing list