[Scummvm-git-logs] scummvm master -> 68f540dd268480c5841cb900096692eb99555d87

npjg nathanael.gentrydb8 at gmail.com
Wed Jul 22 16:13:50 UTC 2020


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:
61f533e3e9 DIRECTOR: Fix cursor hotspot registration
68f540dd26 DIRECTOR: Implement basic sound fading


Commit: 61f533e3e9d8d116426af1dd108c6458f367cd71
    https://github.com/scummvm/scummvm/commit/61f533e3e9d8d116426af1dd108c6458f367cd71
Author: Nathanael Gentry (nathanael.gentrydb8 at gmail.com)
Date: 2020-07-22T10:32:39-04:00

Commit Message:
DIRECTOR: Fix cursor hotspot registration

Changed paths:
    engines/director/cursor.cpp


diff --git a/engines/director/cursor.cpp b/engines/director/cursor.cpp
index 4127872d8b..00e947e197 100644
--- a/engines/director/cursor.cpp
+++ b/engines/director/cursor.cpp
@@ -95,8 +95,8 @@ void Cursor::readFromCast(uint cursorId, uint maskId) {
 	}
 
 	BitmapCastMember *bc = (BitmapCastMember *)(cursorCast);
-	_hotspotX = bc->_initialRect.left - bc->_regX;
-	_hotspotY = bc->_initialRect.top - bc->_regY;
+	_hotspotX = bc->_regX - bc->_initialRect.left;
+	_hotspotY = bc->_regY - bc->_initialRect.top;
 }
 
 void Cursor::readFromResource(int resourceId) {
@@ -153,6 +153,9 @@ void Cursor::resetCursor(Graphics::MacCursorType type, bool shouldClear, int res
 
 	_cursorCastId = castId;
 	_cursorMaskId = maskId;
+
+	_hotspotX = 0;
+	_hotspotY = 0;
 }
 
 } // end of namespace Director


Commit: 68f540dd268480c5841cb900096692eb99555d87
    https://github.com/scummvm/scummvm/commit/68f540dd268480c5841cb900096692eb99555d87
Author: Nathanael Gentry (nathanael.gentrydb8 at gmail.com)
Date: 2020-07-22T12:13:39-04:00

Commit Message:
DIRECTOR: Implement basic sound fading

Changed paths:
    engines/director/lingo/lingo-builtins.cpp
    engines/director/sound.cpp
    engines/director/sound.h


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index d6a243753f..42d098bd2d 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -2087,6 +2087,7 @@ void LB::b_sound(int nargs) {
 		return;
 	}
 
+	int ticks;
 	Datum secondArg = g_lingo->pop();
 	Datum firstArg = g_lingo->pop();
 	Datum verb;
@@ -2109,13 +2110,30 @@ void LB::b_sound(int nargs) {
 		}
 
 		TYPECHECK(firstArg, INT);
-
 		g_director->getSoundManager()->stopSound(firstArg.u.i);
 	} else if (verb.u.s->equalsIgnoreCase("fadeIn")) {
-		warning("STUB: sound fadeIn");
+		// TODO: Check for case when sound channel changes while sound is being played.
+		if (nargs > 2) {
+			TYPECHECK(secondArg, INT);
+			ticks = secondArg.u.i;
+		} else {
+			ticks = 15 * (60 / g_director->getCurrentMovie()->getScore()->_currentFrameRate);
+		}
+
+		TYPECHECK(firstArg, INT);
+		g_director->getSoundManager()->playFade(firstArg.u.i, true, ticks);
 		return;
 	} else if (verb.u.s->equalsIgnoreCase("fadeOut")) {
-		warning("STUB: sound fadeOut");
+		// TODO: Check for case when sound channel changes while sound is being played.
+		if (nargs > 2) {
+			TYPECHECK(secondArg, INT);
+			ticks = secondArg.u.i;
+		} else {
+			ticks = 15 * (60 / g_director->getCurrentMovie()->getScore()->_currentFrameRate);
+		}
+
+		TYPECHECK(firstArg, INT);
+		g_director->getSoundManager()->playFade(firstArg.u.i, false, ticks);
 		return;
 	} else if (verb.u.s->equalsIgnoreCase("playFile")) {
 		ARGNUMCHECK(3)
diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index 14f1c3a11e..57eb43db69 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -133,6 +133,39 @@ void DirectorSound::playCastMember(int castId, uint8 soundChannel, bool allowRep
 	}
 }
 
+void DirectorSound::playFade(uint8 soundChannel, bool fadeIn, int ticks) {
+	Audio::SoundHandle handle = _channels[soundChannel - 1].handle;
+
+	if (!isChannelActive(soundChannel))
+			return;
+
+	float startVolume = fadeIn ? 0 :  _channels[soundChannel - 1].volume;
+	float targetVolume = fadeIn ? _channels[soundChannel - 1].volume : 0;
+	int lastVolume = 0;
+
+	_mixer->setChannelVolume(handle, startVolume);
+
+	int startTicks = _vm->getMacTicks();
+	int lapsedTicks = 0, lastTicks = 0;
+
+	while (lapsedTicks < ticks) {
+		lapsedTicks = _vm->getMacTicks() - startTicks;
+		if (lapsedTicks == lastTicks)
+			continue;
+
+		lastTicks = lapsedTicks;
+		if (fadeIn) {
+			lastVolume = MIN(lapsedTicks * (targetVolume / ticks), (float)Audio::Mixer::kMaxChannelVolume);
+		} else {
+			lastVolume = MAX((ticks - lapsedTicks) * (startVolume / ticks), (float)0);
+		}
+
+		_mixer->setChannelVolume(handle, lastVolume);
+	}
+
+	_mixer->setChannelVolume(handle, targetVolume);
+}
+
 bool DirectorSound::isChannelActive(uint8 soundChannel) {
 	if (soundChannel == 0 || soundChannel > _channels.size()) {
 		warning("Invalid sound channel %d", soundChannel);
diff --git a/engines/director/sound.h b/engines/director/sound.h
index 75fe3fb882..e0d76e6245 100644
--- a/engines/director/sound.h
+++ b/engines/director/sound.h
@@ -61,7 +61,9 @@ public:
 	void playMCI(Audio::AudioStream &stream, uint32 from, uint32 to);
 	void playStream(Audio::AudioStream &stream, uint8 soundChannel);
 	void playCastMember(int castId, uint8 soundChannel, bool allowRepeat = true);
+	void playFade(uint8 soundChannel, bool fadeIn, int ticks);
 	void systemBeep();
+
 	bool isChannelActive(uint8 soundChannel);
 	int lastPlayingCast(uint8 soundChannel);
 	void stopSound(uint8 soundChannel);




More information about the Scummvm-git-logs mailing list