[Scummvm-git-logs] scummvm master -> 80812c2f9e3a40471d0bde95e2d44b80a19f01e9

athrxx noreply at scummvm.org
Fri Dec 3 20:32:06 UTC 2021


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

Summary:
e751768622 KYRA: (LoK/Mac) - improve sound driver resource loading performance
6f2df10d03 KYRA: (LoK/Mac) - fix linebreak chars
80812c2f9e KYRA: (LoK/Mac+FM-Towns) - fix fireberry cave glitch


Commit: e751768622631934faa6f1e6905bea15281b02c4
    https://github.com/scummvm/scummvm/commit/e751768622631934faa6f1e6905bea15281b02c4
Author: athrxx (athrxx at scummvm.org)
Date: 2021-12-03T21:30:54+01:00

Commit Message:
KYRA: (LoK/Mac) - improve sound driver resource loading performance

Starting a sound effect will lock up the mixer thread in a mutex until the sound effect has been loaded and initialized. Which means the music may be disrupted if that period is too long. This commit tries to speed up the process...

Changed paths:
    engines/kyra/sound/sound_mac_lok.cpp
    engines/kyra/sound/sound_mac_res.h


diff --git a/engines/kyra/sound/sound_mac_lok.cpp b/engines/kyra/sound/sound_mac_lok.cpp
index 4ec71c7865..c8c59c3215 100644
--- a/engines/kyra/sound/sound_mac_lok.cpp
+++ b/engines/kyra/sound/sound_mac_lok.cpp
@@ -39,8 +39,9 @@
 
 namespace Kyra {
 
-SoundMacRes::SoundMacRes(KyraEngine_v1 *vm) : _macRes(nullptr), _stuffItArchive(nullptr) {
-	_macRes = new Common::MacResManager();
+SoundMacRes::SoundMacRes(KyraEngine_v1 *vm) : _resMan(0), _stuffItArchive(nullptr) {
+	_resMan = new Common::MacResManager[2];
+
 	if (vm->gameFlags().useInstallerPackage) {
 		Common::String str = Util::findMacResourceFile("Install Legend of Kyrandia");
 		if (str.empty())
@@ -52,32 +53,23 @@ SoundMacRes::SoundMacRes(KyraEngine_v1 *vm) : _macRes(nullptr), _stuffItArchive(
 }
 
 SoundMacRes::~SoundMacRes() {
-	delete _macRes;
+	delete[] _resMan;
 }
 
 bool SoundMacRes::init() {
-	if (!_macRes)
+	if (!_resMan)
 		return false;
 
-	if (!_stuffItArchive) {
-		_kyraMacExe = Util::findMacResourceFile("Legend of Kyrandia");
+	_kyraMacExe = _stuffItArchive ? "Legend of Kyrandia\xaa" : Util::findMacResourceFile("Legend of Kyrandia");
 
-		if (_kyraMacExe.empty()) {
-			warning("SoundMacRes::init(): Legend of Kyrandia resource fork not found");
-			return false;
-		}
+	if (_kyraMacExe.empty()) {
+		warning("SoundMacRes::init(): Legend of Kyrandia resource fork not found");
+		return false;
 	}
 
-	setQuality(true);
-
-	if (!_stuffItArchive) {
-		for (Common::StringArray::iterator i = _resFiles.begin(); i != _resFiles.end(); ++i) {
-			if (!_macRes->exists(*i)) {
-				warning("SoundMacRes::init(): Error opening data file: '%s'", i->c_str());
-				return false;
-			}
-		}
-	}
+	// This will also test whether the resource containers are available.
+	if (!setQuality(true))
+		return false;
 
 	// Test actual resource fork reading...
 	Common::SeekableReadStream *test = getResource(2, 'SMOD');
@@ -100,30 +92,37 @@ bool SoundMacRes::init() {
 Common::SeekableReadStream *SoundMacRes::getResource(uint16 id, uint32 type) {
 	Common::SeekableReadStream *res = nullptr;
 
-	for (Common::StringArray::iterator i = _resFiles.begin(); i != _resFiles.end(); ++i) {
-		if (_stuffItArchive) {
-			if (!_macRes->open(Common::Path(*i), *_stuffItArchive)) {
-				warning("SoundMacRes::getResource(): Error opening archive member: '%s'", i->c_str());
-			}
-		} else {
-			if (!_macRes->open(Common::Path(*i)))
-				warning("SoundMacRes::getResource(): Error opening data file: '%s'", i->c_str());
-		}
-
-		if ((res = _macRes->getResource(type, id)))
+	for (int i = 0; i < 2; ++i) {
+		if ((res = _resMan[i].getResource(type, id)))
 			break;
 	}
+
 	return res;
 }
 
-void SoundMacRes::setQuality(bool hi) {
-	_resFiles.clear();
-	_resFiles.push_back(hi ? "HQ_Music.res" : "LQ_Music.res");
+bool SoundMacRes::setQuality(bool hi) {
+	Common::String s[2];
+	s[0] = hi ? "HQ_Music.res" : "LQ_Music.res";
+	s[1] = _kyraMacExe;
+	int err = 0;
+
 	if (_stuffItArchive) {
-		_resFiles.push_back("Legend of Kyrandia\xaa");
+		for (int i = 0; i < 2; ++i)
+			err |= (_resMan[i].open(Common::Path(s[i]), *_stuffItArchive) ? 0 : (1 << i));
 	} else {
-		_resFiles.push_back(_kyraMacExe);
+		for (int i = 0; i < 2; ++i)
+			err |= (_resMan[i].open(Common::Path(s[i])) ? 0 : (1 << i));
+	}
+
+	if (err) {
+		for (int i = 0; i < 2; ++i) {
+			if (err & (1 << i))
+				warning("SoundMacRes::setQuality(): Error opening resource container: '%s'", s[i].c_str());
+		}
+		return false;
 	}
+
+	return true;
 }
 
 SoundMac::SoundMac(KyraEngine_v1 *vm, Audio::Mixer *mixer) : Sound(vm, mixer), _driver(nullptr), _res(nullptr), _currentResourceSet(-1), _resIDMusic(nullptr), _ready(false) {
diff --git a/engines/kyra/sound/sound_mac_res.h b/engines/kyra/sound/sound_mac_res.h
index 5fceb862e4..b4dbf53483 100644
--- a/engines/kyra/sound/sound_mac_res.h
+++ b/engines/kyra/sound/sound_mac_res.h
@@ -37,13 +37,12 @@ public:
 	SoundMacRes(KyraEngine_v1 *vm);
 	~SoundMacRes();
 	bool init();
-	void setQuality(bool hi);
+	bool setQuality(bool hi);
 	Common::SeekableReadStream *getResource(uint16 id, uint32 type);
 
 private:
-	Common::MacResManager *_macRes;
 	Common::String _kyraMacExe;
-	Common::Array<Common::String> _resFiles;
+	Common::MacResManager *_resMan;
 	Common::Archive *_stuffItArchive;
 };
 


Commit: 6f2df10d03449a0d8dcf2907c4fb8466589622a9
    https://github.com/scummvm/scummvm/commit/6f2df10d03449a0d8dcf2907c4fb8466589622a9
Author: athrxx (athrxx at scummvm.org)
Date: 2021-12-03T21:31:05+01:00

Commit Message:
KYRA: (LoK/Mac) - fix linebreak chars

Mac uses '\n' instead of '\r'. I have verified from disasm that it only uses '\n'. '\r' is not used at all.

Now, I know only 2 cases where it matters and these are hard coded cases: "That snake must\nbe poisonous!" and "The flask is now filled\nwith %s water.". So I could just hard code these differently.
But the scripts might have more of these linebreaks, so it makes sense to have it accurate...

Changed paths:
    engines/kyra/graphics/screen.cpp
    engines/kyra/graphics/screen.h
    engines/kyra/text/text.cpp
    engines/kyra/text/text.h


diff --git a/engines/kyra/graphics/screen.cpp b/engines/kyra/graphics/screen.cpp
index 9b54c93a14..7ee566b00c 100644
--- a/engines/kyra/graphics/screen.cpp
+++ b/engines/kyra/graphics/screen.cpp
@@ -79,6 +79,7 @@ Screen::Screen(KyraEngine_v1 *vm, OSystem *system, const ScreenDim *dimTable, co
 	_customDimTable = nullptr;
 	_curDim = nullptr;
 
+	_lineBreakChar = (_vm->gameFlags().platform == Common::kPlatformMacintosh) ? '\n' : '\r';
 	_yTransOffs = 0;
 }
 
@@ -1420,7 +1421,7 @@ int Screen::getTextWidth(const char *str, bool nextWordOnly) {
 
 		if (c == 0 || (nextWordOnly && (c == 2 || c == 6 || c == 13 || c == 32 || c == 0x4081))) {
 			break;
-		} else if (c == '\r') {
+		} else if (c == _lineBreakChar) {
 			if (curLineLen > maxLineLen)
 				maxLineLen = curLineLen;
 			else
@@ -1479,7 +1480,7 @@ void Screen::printText(const char *str, int x, int y, uint8 color1, uint8 color2
 
 		if (c == 0) {
 			break;
-		} else if (c == '\r') {
+		} else if (c == _lineBreakChar) {
 			x = x_start;
 			y += (charHeight + _lineSpacing);
 		} else {
diff --git a/engines/kyra/graphics/screen.h b/engines/kyra/graphics/screen.h
index 3e481ea05e..23252371b7 100644
--- a/engines/kyra/graphics/screen.h
+++ b/engines/kyra/graphics/screen.h
@@ -650,6 +650,8 @@ public:
 
 	const ScreenDim *_curDim;
 
+	char _lineBreakChar;
+
 	// shape handling
 	uint8 *encodeShape(int x, int y, int w, int h, int flags);
 
diff --git a/engines/kyra/text/text.cpp b/engines/kyra/text/text.cpp
index 222e709423..fe9db5f8f2 100644
--- a/engines/kyra/text/text.cpp
+++ b/engines/kyra/text/text.cpp
@@ -35,6 +35,7 @@ TextDisplayer::TextDisplayer(KyraEngine_v1 *vm, Screen *screen) {
 	_talkMessageY = 0xC;
 	_talkMessageH = 0;
 	_talkMessagePrinted = false;
+	_lineBreakChar = (_vm->gameFlags().platform == Common::kPlatformMacintosh) ? '\n' : '\r';
 	memset(_talkSubstrings, 0, sizeof(_talkSubstrings));
 	memset(_talkBuffer, 0, sizeof(_talkBuffer));
 }
@@ -76,7 +77,7 @@ int TextDisplayer::dropCRIntoString(char *str, int offs) {
 	str += offs;
 	while (*str) {
 		if (*str == ' ') {
-			*str = '\r';
+			*str = _lineBreakChar;
 			return pos;
 		}
 		++str;
@@ -96,7 +97,7 @@ char *TextDisplayer::preprocessString(const char *str) {
 
 	char *p = _talkBuffer;
 	while (*p) {
-		if (*p == '\r') {
+		if (*p == _lineBreakChar) {
 			return _talkBuffer;
 		}
 		++p;
@@ -131,7 +132,7 @@ int TextDisplayer::buildMessageSubstrings(const char *str) {
 	int currentLine = 0;
 	int pos = 0;
 	while (*str) {
-		if (*str == '\r') {
+		if (*str == _lineBreakChar) {
 			assert(currentLine < TALK_SUBSTRING_NUM);
 			_talkSubstrings[currentLine * TALK_SUBSTRING_LEN + pos] = '\0';
 			++currentLine;
diff --git a/engines/kyra/text/text.h b/engines/kyra/text/text.h
index 27dbfe48ca..ed337a1a17 100644
--- a/engines/kyra/text/text.h
+++ b/engines/kyra/text/text.h
@@ -74,6 +74,8 @@ protected:
 	char _talkSubstrings[TALK_SUBSTRING_LEN * TALK_SUBSTRING_NUM];
 	TalkCoords _talkCoords;
 	bool _talkMessagePrinted;
+
+	char _lineBreakChar;
 };
 
 } // End of namespace Kyra


Commit: 80812c2f9e3a40471d0bde95e2d44b80a19f01e9
    https://github.com/scummvm/scummvm/commit/80812c2f9e3a40471d0bde95e2d44b80a19f01e9
Author: athrxx (athrxx at scummvm.org)
Date: 2021-12-03T21:31:15+01:00

Commit Message:
KYRA: (LoK/Mac+FM-Towns) - fix fireberry cave glitch

(Thanks to eriktorbjorn for this. I would never have seen this)

Changed paths:
    engines/kyra/script/script_lok.cpp


diff --git a/engines/kyra/script/script_lok.cpp b/engines/kyra/script/script_lok.cpp
index a1afb34e1f..4540b1a991 100644
--- a/engines/kyra/script/script_lok.cpp
+++ b/engines/kyra/script/script_lok.cpp
@@ -1140,7 +1140,7 @@ int KyraEngine_LoK::o1_findBrightestFireberry(EMCState *script) {
 	// The following rooms are only a "A fireberry bush" scene in the CD version
 	// of Kyrandia 1. In all other versions they are a usual dark cave, thus we do only
 	// return a glow value of "29" over here, when we are running a CD version.
-	if (_flags.isTalkie) {
+	if (_flags.isTalkie || (_flags.platform == Common::kPlatformMacintosh) || (_flags.platform == Common::kPlatformFMTowns)) {
 		if (_currentCharacter->sceneId == 133 || _currentCharacter->sceneId == 137 ||
 		        _currentCharacter->sceneId == 165 || _currentCharacter->sceneId == 173)
 			return 29;




More information about the Scummvm-git-logs mailing list