[Scummvm-git-logs] scummvm master -> 0c9f074d72937d473864e9915d67cd35138feae2

Strangerke noreply at scummvm.org
Sat Jan 25 07:19:24 UTC 2025


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:
3801b1a30d GOT: Remove useless code in setupBoss, remove related global variables
0c9f074d72 GOT: Rewrite the sound code for the boss sounds as it wasn't working in the previous implementation (only partially test


Commit: 3801b1a30dc18b106d604590a0be700f0dffbf46
    https://github.com/scummvm/scummvm/commit/3801b1a30dc18b106d604590a0be700f0dffbf46
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-01-25T08:19:07+01:00

Commit Message:
GOT: Remove useless code in setupBoss, remove related global variables

Changed paths:
    engines/got/game/init.cpp
    engines/got/vars.h


diff --git a/engines/got/game/init.cpp b/engines/got/game/init.cpp
index aae75c3f073..3ca05096fda 100644
--- a/engines/got/game/init.cpp
+++ b/engines/got/game/init.cpp
@@ -123,8 +123,6 @@ int setupBoss(const int num) {
 		for (int rep = 0; rep < 3; rep++) {
 			if (_G(boss_sound[rep]))
 				free(_G(boss_sound[rep]));
-			if (_G(boss_pcsound[rep]))
-				free(_G(boss_pcsound[rep]));
 		}
 	}
 
@@ -146,49 +144,6 @@ int setupBoss(const int num) {
 		return 0;
 	_G(dig_sound[NUM_SOUNDS - 1]) = _G(boss_sound[2]);
 
-	Common::String prefix = (num == 2) ? "BOSSP1" : Common::String::format("BOSSP%d", num);
-	ressourceName = prefix + "1";
-	_G(boss_pcsound[0]) = (byte *)resourceAllocRead(ressourceName);
-	if (!_G(boss_pcsound[0]))
-		return 0;
-
-	_G(pc_sound[NUM_SOUNDS - 3]) = _G(boss_pcsound[0]);
-	_G(pc_sound[NUM_SOUNDS - 3][0]) = 0;
-	_G(pc_sound[NUM_SOUNDS - 3][1]) = 0;
-
-	Common::File f;
-	if (!f.open(Common::Path(ressourceName)))
-		return 0;
-	_G(pcsound_length[NUM_SOUNDS - 3]) = f.size();
-	f.close();
-
-	ressourceName = prefix + "2";
-	_G(boss_pcsound[1]) = (byte *)resourceAllocRead(ressourceName);
-	if (!_G(boss_pcsound[1]))
-		return 0;
-
-	_G(pc_sound[NUM_SOUNDS - 2]) = _G(boss_pcsound[1]);
-	_G(pc_sound[NUM_SOUNDS - 2][0]) = 0;
-	_G(pc_sound[NUM_SOUNDS - 2][1]) = 0;
-
-	if (!f.open(Common::Path(ressourceName)))
-		return 0;
-	_G(pcsound_length[NUM_SOUNDS - 2]) = f.size();
-	f.close();
-
-	ressourceName = prefix + "3";
-	_G(boss_pcsound[2]) = (byte *)resourceAllocRead(ressourceName);
-	if (!_G(boss_pcsound[2]))
-		return 0;
-	_G(pc_sound[NUM_SOUNDS - 1]) = _G(boss_pcsound[2]);
-	_G(pc_sound[NUM_SOUNDS - 1][0]) = 0;
-	_G(pc_sound[NUM_SOUNDS - 1][1]) = 0;
-
-	if (!f.open(Common::Path(ressourceName)))
-		return 0;
-	_G(pcsound_length[NUM_SOUNDS - 1]) = f.size();
-	f.close();
-
 	_G(currentBossLoaded) = num;
 	return 1;
 }
diff --git a/engines/got/vars.h b/engines/got/vars.h
index c9313e2fa75..6ff29c46727 100644
--- a/engines/got/vars.h
+++ b/engines/got/vars.h
@@ -175,13 +175,7 @@ public:
 
 	bool _warpFlag = false;
 
-	int8 *_std_sound_start = nullptr;
-	int8 *_pcstd_sound_start = nullptr;
-	int8 *_std_sound = nullptr;
-	int8 *_pcstd_sounds = nullptr;
 	byte *_boss_sound[3] = {};
-	byte *_boss_pcsound[3] = {};
-	long _pcsound_length[NUM_SOUNDS] = {};
 	int _rand1 = 0, _rand2 = 0;
 	int _hourglass_flag = 0, _thunder_flag = 0;
 	bool _lightning_used = false, _tornado_used = false;
@@ -199,7 +193,6 @@ public:
 	bool _carry_inform = false;
 	bool _killgg_inform = false;
 
-	byte *_pc_sound[NUM_SOUNDS] = {};
 	byte *_dig_sound[NUM_SOUNDS] = {};
 	bool _boss_active = false;
 	bool _story_flag = true;


Commit: 0c9f074d72937d473864e9915d67cd35138feae2
    https://github.com/scummvm/scummvm/commit/0c9f074d72937d473864e9915d67cd35138feae2
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-01-25T08:19:07+01:00

Commit Message:
GOT: Rewrite the sound code for the boss sounds as it wasn't working in the previous implementation (only partially tested, waiting to progress in a playthrough for a validation)

Changed paths:
    engines/got/game/init.cpp
    engines/got/game/init.h
    engines/got/sound.cpp
    engines/got/sound.h
    engines/got/vars.h


diff --git a/engines/got/game/init.cpp b/engines/got/game/init.cpp
index 3ca05096fda..8aabf5cfa08 100644
--- a/engines/got/game/init.cpp
+++ b/engines/got/game/init.cpp
@@ -115,37 +115,4 @@ void initGame() {
 	_G(startup) = false;
 }
 
-int setupBoss(const int num) {
-	if (_G(currentBossLoaded) == num)
-		return 1;
-
-	if (_G(currentBossLoaded)) {
-		for (int rep = 0; rep < 3; rep++) {
-			if (_G(boss_sound[rep]))
-				free(_G(boss_sound[rep]));
-		}
-	}
-
-	Common::String ressourceName = Common::String::format("BOSSV%d1", num);
-	_G(boss_sound[0]) = (byte *)resourceAllocRead(ressourceName);
-	if (!_G(boss_sound[0]))
-		return 0;
-	_G(dig_sound[NUM_SOUNDS - 3]) = _G(boss_sound[0]);
-
-	ressourceName = Common::String::format("BOSSV%d2", num);
-	_G(boss_sound[1]) = (byte *)resourceAllocRead(ressourceName);
-	if (!_G(boss_sound[1]))
-		return 0;
-	_G(dig_sound[NUM_SOUNDS - 2]) = _G(boss_sound[1]);
-
-	ressourceName = Common::String::format("BOSSV%d3", num);
-	_G(boss_sound[2]) = (byte *)resourceAllocRead(ressourceName);
-	if (!_G(boss_sound[2]))
-		return 0;
-	_G(dig_sound[NUM_SOUNDS - 1]) = _G(boss_sound[2]);
-
-	_G(currentBossLoaded) = num;
-	return 1;
-}
-
 } // namespace Got
diff --git a/engines/got/game/init.h b/engines/got/game/init.h
index c83132f6d7b..c53e4d3aacd 100644
--- a/engines/got/game/init.h
+++ b/engines/got/game/init.h
@@ -28,7 +28,6 @@ namespace Got {
  * Handles in-game initialization the first time
  */
 extern void initGame();
-extern int setupBoss(int num);
 
 } // namespace Got
 
diff --git a/engines/got/sound.cpp b/engines/got/sound.cpp
index 80fde9bbd2b..b5a3d184547 100644
--- a/engines/got/sound.cpp
+++ b/engines/got/sound.cpp
@@ -30,6 +30,18 @@ namespace Got {
 
 static const byte SOUND_PRIORITY[] = {1, 2, 3, 3, 3, 1, 4, 4, 4, 5, 4, 3, 1, 2, 2, 5, 1, 3, 1};
 
+Sound::Sound() {
+	for (int i = 0; i < 3; i++)
+		_bossSounds[i] = nullptr;
+}
+
+Sound::~Sound() {
+	delete[] _soundData;
+	for (int i = 0; i < 3; i++) {
+		delete(_bossSounds[i]);
+	}
+}
+
 void Sound::load() {
 	File f("DIGSOUND");
 
@@ -42,6 +54,32 @@ void Sound::load() {
 	f.read(_soundData, f.size() - 16 * 8);
 }
 
+void Sound::setupBoss(const int num) {
+	if (_currentBossLoaded == num)
+		// Boss sounds are already loaded
+		return;
+
+	if (_currentBossLoaded) {
+		// Boss sounds have already been loaded. Delete them to avoid memory leak
+		for (int i = 0; i < 3; i++)
+			delete(_bossSounds[i]);
+	}
+
+	// Information concerning boss sounds is stored in _digiSounds 16 to 18, but the data is stored in _bossSounds
+	for (int i = 0; i < 3; ++i) {
+		Common::String ressourceName = Common::String::format("BOSSV%d%d", num, i + 1);
+		File f(ressourceName);
+		const int size = f.size();
+		_bossSounds[i] = new byte[size];
+		_digiSounds[16 + i]._length = size;
+		_digiSounds[16 + i]._offset = 0;
+		f.read(_bossSounds[i], size);
+		f.close();
+	}
+
+	_currentBossLoaded = num;
+}
+
 void Sound::playSound(const int index, const bool override) {
 	if (index >= NUM_SOUNDS)
 		return;
@@ -54,11 +92,16 @@ void Sound::playSound(const int index, const bool override) {
 		g_engine->_mixer->stopHandle(_soundHandle);
 	}
 
+	Common::MemoryReadStream *stream;
+	if (index >= 16) {
+		// Boss sounds are not stored in the normal sound data, it's in 3 buffers in _bossSounds.
+		stream = new Common::MemoryReadStream(_bossSounds[index - 16], _digiSounds[index]._length);
+	} else {
+		// Normal digital sound
+		stream = new Common::MemoryReadStream(_soundData + _digiSounds[index]._offset, _digiSounds[index]._length);
+	}
 	// Play the new sound
-	Common::MemoryReadStream *stream = new Common::MemoryReadStream(
-		_soundData + _digiSounds[index]._offset, _digiSounds[index]._length);
-	Audio::AudioStream *audioStream = Audio::makeVOCStream(stream, Audio::FLAG_UNSIGNED,
-														   DisposeAfterUse::YES);
+	Audio::AudioStream *audioStream = Audio::makeVOCStream(stream, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
 	g_engine->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, audioStream);
 }
 
@@ -308,4 +351,8 @@ void musicResume() {
 	_G(sound).musicResume();
 }
 
+void setupBoss(int num) {
+	_G(sound).setupBoss(num);
+}
+
 } // namespace Got
diff --git a/engines/got/sound.h b/engines/got/sound.h
index 6a1c46ca36e..93230e2c97b 100644
--- a/engines/got/sound.h
+++ b/engines/got/sound.h
@@ -55,9 +55,11 @@ enum {
 class Sound {
 private:
 	byte *_soundData = nullptr;
+	byte *_bossSounds[3];
 	Header _digiSounds[NUM_SOUNDS];
 	Audio::SoundHandle _soundHandle;
 	int _currentPriority = 0;
+	int8 _currentBossLoaded = 0;
 
 	const char *_currentMusic = nullptr;
 	Audio::SoundHandle _musicHandle;
@@ -65,10 +67,11 @@ private:
 	const char *getMusicName(int num) const;
 
 public:
-	~Sound() {
-		delete[] _soundData;
-	}
+	Sound();
+	~Sound();
+	
 	void load();
+	void setupBoss(int num);
 
 	void playSound(int index, bool override);
 	void playSound(const Gfx::GraphicChunk &src);
@@ -91,6 +94,7 @@ extern void musicPlay(int num, bool override);
 extern void musicPlay(const char *name, bool override);
 extern void musicPause();
 extern void musicResume();
+extern void setupBoss(int num);
 
 } // namespace Got
 
diff --git a/engines/got/vars.h b/engines/got/vars.h
index 6ff29c46727..639eeddda14 100644
--- a/engines/got/vars.h
+++ b/engines/got/vars.h
@@ -144,7 +144,6 @@ public:
 	int8 _thorIcon4 = 0;
 	int8 _levelMusic = 0;
 	int8 _currentMusic = -1;
-	int8 _currentBossLoaded = 0;
 	int8 _appleDropCounter = 0;
 	bool _cheat = false;
 	int8 _area = 1;
@@ -175,7 +174,6 @@ public:
 
 	bool _warpFlag = false;
 
-	byte *_boss_sound[3] = {};
 	int _rand1 = 0, _rand2 = 0;
 	int _hourglass_flag = 0, _thunder_flag = 0;
 	bool _lightning_used = false, _tornado_used = false;
@@ -193,7 +191,6 @@ public:
 	bool _carry_inform = false;
 	bool _killgg_inform = false;
 
-	byte *_dig_sound[NUM_SOUNDS] = {};
 	bool _boss_active = false;
 	bool _story_flag = true;
 	int8 *_scr = nullptr;




More information about the Scummvm-git-logs mailing list