[Scummvm-git-logs] scummvm master -> 33d1804b4ea0de6011108d0658aaf2ad572b9071

athrxx noreply at scummvm.org
Tue Nov 16 19:36:44 UTC 2021


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

Summary:
3b061ae0e8 BACKENDS: (OPENGL/SURFACESDL) - include mouse pointer in screen shakes
33d1804b4e SCUMM: fix bug no. 13065 ("Incorrect screen shaking")


Commit: 3b061ae0e8e85952266cf2f351f817aee578981e
    https://github.com/scummvm/scummvm/commit/3b061ae0e8e85952266cf2f351f817aee578981e
Author: athrxx (athrxx at scummvm.org)
Date: 2021-11-16T20:34:20+01:00

Commit Message:
BACKENDS: (OPENGL/SURFACESDL) - include mouse pointer in screen shakes

This is the original behaviour of DOS games (where the screen shakes are done by writing certain offsets into the crt cotnrol register of the vga adapter).

Usually it doesn't matter much, since the shake is an effect that passes quickly. But the difference can be noticed in cases like DOTT when switching on the stereo in green tentacle's room. The shaking will continue until the stereo is turned off again. In that case it is really more appealing if the mouse cursor "sticks" to the background.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/opengl-graphics.h
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp


diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index e649e27562..eda1ad03fd 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -67,7 +67,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager()
 	  _cursor(nullptr),
 	  _cursorHotspotX(0), _cursorHotspotY(0),
 	  _cursorHotspotXScaled(0), _cursorHotspotYScaled(0), _cursorWidthScaled(0), _cursorHeightScaled(0),
-	  _cursorKeyColor(0), _cursorDontScale(false), _cursorPaletteEnabled(false)
+	  _cursorKeyColor(0), _cursorDontScale(false), _cursorPaletteEnabled(false), _shakeOffsetScaled()
 #ifdef USE_OSD
 	  , _osdMessageChangeRequest(false), _osdMessageAlpha(0), _osdMessageFadeStartTime(0), _osdMessageSurface(nullptr),
 	  _osdIconSurface(nullptr)
@@ -537,8 +537,8 @@ void OpenGLGraphicsManager::updateScreen() {
 		_backBuffer.enableBlend(Framebuffer::kBlendModePremultipliedTransparency);
 
 		g_context.getActivePipeline()->drawTexture(_cursor->getGLTexture(),
-		                         _cursorX - _cursorHotspotXScaled,
-		                         _cursorY - _cursorHotspotYScaled,
+		                         _cursorX - _cursorHotspotXScaled + _shakeOffsetScaled.x,
+		                         _cursorY - _cursorHotspotYScaled + _shakeOffsetScaled.y,
 		                         _cursorWidthScaled, _cursorHeightScaled);
 	}
 
@@ -1257,6 +1257,9 @@ void OpenGLGraphicsManager::recalculateDisplayAreas() {
 	                          _gameDrawRect.width(),
 	                          _gameDrawRect.height());
 
+	_shakeOffsetScaled = Common::Point(_gameScreenShakeXOffset * _activeArea.drawRect.width() / _activeArea.width,
+		_gameScreenShakeYOffset * _activeArea.drawRect.height() / _activeArea.height);
+
 	// Update the cursor position to adjust for new display area.
 	setMousePosition(_cursorX, _cursorY);
 
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index 0f1ca9fc67..ecb00a2ead 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -236,6 +236,11 @@ private:
 	 */
 	int _stretchMode;
 
+	/**
+	 * Scaled version of _gameScreenShakeXOffset and _gameScreenShakeYOffset (as a Common::Point)
+	 */
+	Common::Point _shakeOffsetScaled;
+
 protected:
 	/**
 	 * Set up the requested video mode. This takes parameters which describe
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index b0ce6af1b7..0487907bd8 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -2143,6 +2143,11 @@ void SurfaceSdlGraphicsManager::drawMouse() {
 		hotY = _mouseCurState.rHotY;
 	}
 
+	// The offsets must be applied if no shake view is set, since the call
+	// to convertWindowToVirtual() counteracts the move of the view port.
+	dst.x += _gameScreenShakeXOffset;
+	dst.y += _gameScreenShakeYOffset;
+
 	// The mouse is undrawn using virtual coordinates, i.e. they may be
 	// scaled and aspect-ratio corrected.
 


Commit: 33d1804b4ea0de6011108d0658aaf2ad572b9071
    https://github.com/scummvm/scummvm/commit/33d1804b4ea0de6011108d0658aaf2ad572b9071
Author: athrxx (athrxx at scummvm.org)
Date: 2021-11-16T20:35:32+01:00

Commit Message:
SCUMM: fix bug no. 13065 ("Incorrect screen shaking")

Changed paths:
    engines/scumm/gfx.cpp
    engines/scumm/scumm.cpp
    engines/scumm/scumm.h


diff --git a/engines/scumm/gfx.cpp b/engines/scumm/gfx.cpp
index 3c563d0db7..a256cb07cf 100644
--- a/engines/scumm/gfx.cpp
+++ b/engines/scumm/gfx.cpp
@@ -73,7 +73,7 @@ enum {
 
 #define NUM_SHAKE_POSITIONS 8
 static const int8 shake_positions[NUM_SHAKE_POSITIONS] = {
-	0, 1 * 2, 2 * 2, 1 * 2, 0 * 2, 2 * 2, 3 * 2, 1 * 2
+	0, 1, 2, 1, 0, 2, 3, 1
 };
 
 /**
@@ -532,15 +532,6 @@ void ScummEngine::drawDirtyScreenParts() {
 	} else {
 		updateDirtyScreen(kMainVirtScreen);
 	}
-
-	// Handle shaking
-	if (_shakeEnabled) {
-		_shakeFrame = (_shakeFrame + 1) % NUM_SHAKE_POSITIONS;
-		_system->setShakePos(0, shake_positions[_shakeFrame]);
-	} else if (!_shakeEnabled &&_shakeFrame != 0) {
-		_shakeFrame = 0;
-		_system->setShakePos(0, 0);
-	}
 }
 
 void ScummEngine_v6::drawDirtyScreenParts() {
@@ -4211,4 +4202,31 @@ void ScummEngine::unkScreenEffect6() {
 		dissolveEffect(8, 4);
 }
 
+void ScummEngine::updateScreenShakeEffect() {
+	if (!_shakeEnabled) {
+		if (_shakeFrame) {
+			_shakeFrame = 0;
+			_system->setShakePos(0, 0);
+		}
+		_shakeNextTick = _shakeTickCounter = 0;
+		return;
+	}
+
+	uint32 now = _system->getMillis();
+	if (!_shakeNextTick)
+		_shakeNextTick = now;
+
+	while (now >= _shakeNextTick) {
+		_shakeFrame = (_shakeFrame + 1) % NUM_SHAKE_POSITIONS;
+		_system->setShakePos(0, -shake_positions[_shakeFrame]);
+		// In DOTT (and probably all other imuse games) this runs on the imuse timer which is a PIT 0 Timer at 291304 Hz.
+		// Apparently it is the same timer setting for all sound drivers although it is set up not in the main executable
+		// but inside each respective ims driver during the driver load/init process. The screen shakes update every 8 ticks.
+		// I assume that this might be slightly different per SCUMM version, target platform etc...
+		_shakeTickCounter += ((1000000000 / 291304) * 8);
+		_shakeNextTick += (_shakeTickCounter / 1000);
+		_shakeTickCounter %= 1000;
+	}
+}
+
 } // End of namespace Scumm
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 7a7d6f8bdd..e7cd938603 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -264,6 +264,7 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
 	_doEffect = false;
 	_snapScroll = false;
 	_shakeEnabled = false;
+	_shakeNextTick = _shakeTickCounter = 0;
 	_shakeFrame = 0;
 	_screenStartStrip = 0;
 	_screenEndStrip = 0;
@@ -2419,7 +2420,7 @@ Common::Error ScummEngine::go() {
 		// This is important for the door-closing action in the dungeon,
 		// otherwise (delta < 6) a single kid is able to escape.
 		if (_game.version == 1 && isScriptRunning(137)) {
-				delta = 6;
+			delta = 6;
 		}
 
 		// Wait...
@@ -2458,6 +2459,8 @@ void ScummEngine::waitForTimer(int msec_delay) {
 		_sound->updateCD(); // Loop CD Audio if needed
 		parseEvents();
 
+		updateScreenShakeEffect();
+
 #ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
 		uint32 screenUpdateTimerStart = _system->getMillis();
 		towns_updateGfx();
@@ -3072,6 +3075,8 @@ void ScummEngine::pauseEngineIntern(bool pause) {
 		_scrollTimer = 0;
 		towns_updateGfx();
 #endif
+		_shakeNextTick = _shakeTickCounter = 0;
+
 		// Update the screen to make it less likely that the player will see a
 		// brief cursor palette glitch when the GUI is disabled.
 		_system->updateScreen();
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index af27cfbb30..b522d7c29b 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -988,9 +988,14 @@ protected:
 	void dissolveEffect(int width, int height);
 	void scrollEffect(int dir);
 
+	void updateScreenShakeEffect();
+
 protected:
 	bool _shakeEnabled;
 	uint _shakeFrame;
+	uint32 _shakeNextTick;
+	uint32 _shakeTickCounter;
+
 	void setShake(int mode);
 
 	int _drawObjectQueNr;




More information about the Scummvm-git-logs mailing list