[Scummvm-git-logs] scummvm master -> 3f92dd47e663eadd19231f113563e28cabb8d459

sev- noreply at scummvm.org
Thu Jul 20 14:19:25 UTC 2023


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:
d059dc2984 DIRECTOR: Add "the member" support for D5
3f92dd47e6 DIRECTOR: Fix edge cases in Frame::readMainChannelsD5


Commit: d059dc29843fd1147be18bbeee48ab6899fa48aa
    https://github.com/scummvm/scummvm/commit/d059dc29843fd1147be18bbeee48ab6899fa48aa
Author: Scott Percival (code at moral.net.au)
Date: 2023-07-20T16:19:20+02:00

Commit Message:
DIRECTOR: Add "the member" support for D5

Changed paths:
    engines/director/lingo/lingo-bytecode.cpp
    engines/director/lingo/lingo.cpp
    engines/director/movie.cpp
    engines/director/movie.h


diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index 78fbfc7b972..b90f820d26d 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -738,6 +738,12 @@ void LC::cb_v4theentitypush() {
 		case kTEAItemId:
 			{
 				Datum id = g_lingo->pop();
+				if (entity == kTheCast && g_director->getVersion() >= 500) {
+					// For "the member", D5 and above have a lib ID followed by a member ID
+					// Pre-resolve them here.
+					CastMemberID resolved = g_lingo->resolveCastMember(g_lingo->pop(), id, kCastTypeAny);
+					id = Datum(resolved);
+				}
 				debugC(3, kDebugLingoExec, "cb_v4theentitypush: calling getTheEntity(%s, %s, %s)", g_lingo->entity2str(entity), id.asString(true).c_str(), g_lingo->field2str(field));
 				result = g_lingo->getTheEntity(entity, id, field);
 			}
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index ad339c51a18..3c4b1a474bf 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -1743,18 +1743,18 @@ CastMemberID Lingo::resolveCastMember(const Datum &memberID, const Datum &castLi
 
 	switch (memberID.type) {
 	case STRING:
-		{
-			CastMember *member = movie->getCastMemberByNameAndType(memberID.asString(), castLib.asInt(), type);
-			if (member)
-				return CastMemberID(member->getID(), castLib.asInt());
-
-			warning("Lingo::resolveCastMember: reference to non-existent cast member: %s", memberID.asString().c_str());
-			return CastMemberID(-1, castLib.asInt());
-		}
+		return movie->getCastMemberIDByNameAndType(memberID.asString(), castLib.asInt(), type);
 		break;
 	case INT:
 	case FLOAT:
-		return CastMemberID(memberID.asInt(), castLib.asInt());
+		if (castLib.asInt() == 0) {
+			// When specifying 0 as the castlib, D5 will assume this
+			// means the default (i.e. first) cast library. It will not
+			// try other libraries for matches if the member is a number.
+			return CastMemberID(memberID.asInt(), DEFAULT_CAST_LIB);
+		} else {
+			return CastMemberID(memberID.asInt(), castLib.asInt());
+		}
 		break;
 	case VOID:
 		warning("Lingo::resolveCastMember: reference to VOID member ID");
diff --git a/engines/director/movie.cpp b/engines/director/movie.cpp
index bf41be2be10..378c386cb74 100644
--- a/engines/director/movie.cpp
+++ b/engines/director/movie.cpp
@@ -33,6 +33,7 @@
 #include "director/movie.h"
 #include "director/score.h"
 #include "director/window.h"
+#include "director/castmember/castmember.h"
 #include "director/lingo/lingo.h"
 #include "director/lingo/lingo-object.h"
 
@@ -428,15 +429,38 @@ bool Movie::eraseCastMember(CastMemberID memberID) {
 	return false;
 }
 
-CastMember *Movie::getCastMemberByNameAndType(const Common::String &name, int castLib, CastType type) {
-	CastMember *result = nullptr;
+CastMemberID Movie::getCastMemberIDByNameAndType(const Common::String &name, int castLib, CastType type) {
+	CastMemberID result(-1, 0);
 	if (_casts.contains(castLib)) {
-		result = _casts.getVal(castLib)->getCastMemberByNameAndType(name, type);
-		if (result == nullptr && _sharedCast) {
-			result = _sharedCast->getCastMemberByNameAndType(name, type);
+		CastMember *member = _casts.getVal(castLib)->getCastMemberByNameAndType(name, type);
+		if (member) {
+			result = CastMemberID(member->getID(), castLib);
+		}
+		if (result.member == -1 && _sharedCast) {
+			member = _sharedCast->getCastMemberByNameAndType(name, type);
+			if (member) {
+				result = CastMemberID(member->getID(), castLib);
+			}
+		}
+	} else if (castLib == 0) {
+		// Search all cast libraries for a match
+		for (auto &cast : _casts) {
+			CastMember *member = cast._value->getCastMemberByNameAndType(name, type);
+			if (member) {
+				result = CastMemberID(member->getID(), cast._key);
+				break;
+			}
+		}
+		if (result.member == -1 && _sharedCast) {
+			CastMember *member = _sharedCast->getCastMemberByNameAndType(name, type);
+			if (member)
+				result = CastMemberID(member->getID(), DEFAULT_CAST_LIB);
 		}
 	} else {
-		warning("Movie::getCastMemberByNameAndType: Unknown castLib %d", castLib);
+		warning("Movie::getCastMemberIDByNameAndType: Unknown castLib %d", castLib);
+	}
+	if (result.member == -1) {
+		warning("Movie::getCastMemberIDByNameAndType: No match found for member name %s and lib %d", name.c_str(), castLib);
 	}
 	return result;
 }
diff --git a/engines/director/movie.h b/engines/director/movie.h
index 657b0556254..633912a5537 100644
--- a/engines/director/movie.h
+++ b/engines/director/movie.h
@@ -110,7 +110,7 @@ public:
 	CastMember *getCastMember(CastMemberID memberID);
 	CastMember *createOrReplaceCastMember(CastMemberID memberID, CastMember *cast);
 	bool eraseCastMember(CastMemberID memberID);
-	CastMember *getCastMemberByNameAndType(const Common::String &name, int castLib, CastType type);
+	CastMemberID getCastMemberIDByNameAndType(const Common::String &name, int castLib, CastType type);
 	CastMemberInfo *getCastMemberInfo(CastMemberID memberID);
 	const Stxt *getStxt(CastMemberID memberID);
 


Commit: 3f92dd47e663eadd19231f113563e28cabb8d459
    https://github.com/scummvm/scummvm/commit/3f92dd47e663eadd19231f113563e28cabb8d459
Author: Scott Percival (code at moral.net.au)
Date: 2023-07-20T16:19:20+02:00

Commit Message:
DIRECTOR: Fix edge cases in Frame::readMainChannelsD5

Changed paths:
    engines/director/frame.cpp


diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp
index 7dacbbf5745..6cb12601bf9 100644
--- a/engines/director/frame.cpp
+++ b/engines/director/frame.cpp
@@ -685,68 +685,57 @@ void Frame::readMainChannelsD5(Common::MemoryReadStreamEndian &stream, uint16 of
 
 	while (stream.pos() < finishPosition) {
 		switch (stream.pos() - initPos + offset) {
-		case 0: {
-				// Sound/Tempo/Transition
-				uint16 actionCastLib = stream.readUint16();
-				uint16 actionId = stream.readUint16();
-				_mainChannels.actionId = CastMemberID(actionId, actionCastLib);
-			}
+		case 0:
+			// Sound/Tempo/Transition
+			_mainChannels.actionId.castLib = stream.readUint16();
 			break;
-		case 2: {
-				uint16 actionId = stream.readUint16();
-				_mainChannels.actionId = CastMemberID(actionId, _mainChannels.actionId.castLib);  // Inherit castLinb from previous frame
-			}
+		case 2:
+			_mainChannels.actionId.member = stream.readUint16();
 			break;
-		case 4: {
-				uint16 sound1CastLib = stream.readUint16();
-				uint16 sound1Id = stream.readUint16();
-				_mainChannels.sound1 = CastMemberID(sound1Id, sound1CastLib);
-			}
+		case 4:
+			_mainChannels.sound1.castLib = stream.readUint16();
 			break;
-		case 6: {
-				uint16 sound1Id = stream.readUint16();
-				_mainChannels.sound1 = CastMemberID(sound1Id, _mainChannels.sound1.castLib);	// Inherit castLinb from previous frame
-			}
+		case 6:
+			_mainChannels.sound1.member = stream.readUint16();
 			break;
-		case 8: {
-				uint16 sound2CastLib = stream.readUint16();
-				uint16 sound2Id = stream.readUint16();
-				_mainChannels.sound2 = CastMemberID(sound2Id, sound2CastLib);
-			}
+		case 8:
+			_mainChannels.sound2.castLib = stream.readUint16();
 			break;
-		case 10: {
-				uint16 sound2Id = stream.readUint16();
-				_mainChannels.sound2 = CastMemberID(sound2Id, _mainChannels.sound2.castLib);	// Inherit castLinb from previous frame
-			}
+		case 10:
+			_mainChannels.sound2.member = stream.readUint16();
 			break;
-		case 12: {
-				uint16 transCastLib = stream.readUint16();
-				uint16 transId = stream.readUint16();
-				_mainChannels.trans = CastMemberID(transId, transCastLib);
-			}
+		case 12:
+			_mainChannels.trans.castLib = stream.readUint16();
+			break;
+		case 14:
+			_mainChannels.trans.member = stream.readUint16();
 			break;
 		case 16:
-			stream.read(unk, 4);
-			warning("Frame::readMainChannelsD5(): STUB: unk1: 0x%02x 0x%02x 0x%02x 0x%02x", unk[0], unk[1], unk[2], unk[3]);
+			stream.read(unk, 2);
+			warning("Frame::readMainChannelsD5(): STUB: unk1: 0x%02x 0x%02x", unk[0], unk[1]);
+			break;
+		case 18:
+			stream.read(unk, 2);
+			warning("Frame::readMainChannelsD5(): STUB: unk2: 0x%02x 0x%02x", unk[0], unk[1]);
 			break;
 		case 20:
 			stream.read(unk, 1);
-			warning("Frame::readMainChannelsD5(): STUB: unk2: 0x%02x", unk[0]);
+			warning("Frame::readMainChannelsD5(): STUB: unk3: 0x%02x", unk[0]);
 			break;
 		case 21:
 			_mainChannels.tempo = stream.readByte();
 			break;
 		case 22:
 			stream.read(unk, 2);
-			warning("Frame::readMainChannelsD5(): STUB: unk3: 0x%02x 0x%02x", unk[0], unk[1]);
+			warning("Frame::readMainChannelsD5(): STUB: unk4: 0x%02x 0x%02x", unk[0], unk[1]);
 			break;
-		case 24: {
-				int16 paletteCastLib = stream.readSint16();
-				int16 paletteId = stream.readSint16(); // 26
-				_mainChannels.palette.paletteId = CastMemberID(paletteId, paletteCastLib);
-				if (!_mainChannels.palette.paletteId.isNull())
-					_mainChannels.scoreCachedPaletteId = _mainChannels.palette.paletteId;
-			}
+		case 24:
+			_mainChannels.palette.paletteId.castLib = stream.readSint16();
+			break;
+		case 26:
+			_mainChannels.palette.paletteId.member = stream.readSint16();
+			if (!_mainChannels.palette.paletteId.isNull())
+				_mainChannels.scoreCachedPaletteId = _mainChannels.palette.paletteId;
 			break;
 		case 28:
 			_mainChannels.palette.speed = stream.readByte(); // 28
@@ -768,14 +757,22 @@ void Frame::readMainChannelsD5(Common::MemoryReadStreamEndian &stream, uint16 of
 		case 34:
 			_mainChannels.palette.cycleCount = stream.readUint16(); // 34
 			break;
-		case 36: {
-				stream.read(unk, 12);
+		case 36:
+			stream.read(unk, 2);
+			warning("Frame::readMainChannelsD5(): STUB: unk5: 0x%02x 0x%02x", unk[0], unk[1]);
+			break;
+		case 38:
+			stream.read(unk, 2);
+			warning("Frame::readMainChannelsD5(): STUB: unk6: 0x%02x 0x%02x", unk[0], unk[1]);
+			break;
+		case 40: {
+				stream.read(unk, 8);
 
 				Common::String s;
-				for (int i = 0; i < 12; i++)
+				for (int i = 0; i < 8; i++)
 					s += Common::String::format("0x%02x ", unk[i]);
 
-				warning("Frame::readMainChannelsD5(): STUB: unk4: %s", s.c_str());
+				warning("Frame::readMainChannelsD5(): STUB: unk7: %s", s.c_str());
 			}
 			break;
 		default:




More information about the Scummvm-git-logs mailing list