[Scummvm-git-logs] scummvm master -> 39bcf1a69a132d7d9668e27cb5981cda6d55d18d

elasota noreply at scummvm.org
Fri Jul 5 05:37:34 UTC 2024


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

Summary:
39bcf1a69a VCRUISE: Add preload sounds option


Commit: 39bcf1a69a132d7d9668e27cb5981cda6d55d18d
    https://github.com/scummvm/scummvm/commit/39bcf1a69a132d7d9668e27cb5981cda6d55d18d
Author: elasota (1137273+elasota at users.noreply.github.com)
Date: 2024-07-05T01:37:16-04:00

Commit Message:
VCRUISE: Add preload sounds option

Changed paths:
    engines/vcruise/detection.cpp
    engines/vcruise/detection.h
    engines/vcruise/metaengine.cpp
    engines/vcruise/runtime.cpp
    engines/vcruise/runtime.h
    engines/vcruise/vcruise.cpp


diff --git a/engines/vcruise/detection.cpp b/engines/vcruise/detection.cpp
index e93adf80cac..0b66222f129 100644
--- a/engines/vcruise/detection.cpp
+++ b/engines/vcruise/detection.cpp
@@ -49,7 +49,7 @@ static const char *const g_vcruiseDirectoryGlobs[] = {
 class VCruiseMetaEngineDetection : public AdvancedMetaEngineDetection<VCruise::VCruiseGameDescription> {
 public:
 	VCruiseMetaEngineDetection() : AdvancedMetaEngineDetection(VCruise::gameDescriptions, g_vcruiseGames) {
-		_guiOptions = GUIO4(GAMEOPTION_FAST_ANIMATIONS, GAMEOPTION_INCREASE_DRAG_DISTANCE, GAMEOPTION_LAUNCH_DEBUG, GAMEOPTION_SKIP_MENU);
+		_guiOptions = GUIO5(GAMEOPTION_FAST_ANIMATIONS, GAMEOPTION_INCREASE_DRAG_DISTANCE, GAMEOPTION_LAUNCH_DEBUG, GAMEOPTION_SKIP_MENU, GAMEOPTION_PRELOAD_SOUNDS);
 		_maxScanDepth = 3;
 		_directoryGlobs = g_vcruiseDirectoryGlobs;
 		_flags = kADFlagCanPlayUnknownVariants;
diff --git a/engines/vcruise/detection.h b/engines/vcruise/detection.h
index 20293390521..47f682a5497 100644
--- a/engines/vcruise/detection.h
+++ b/engines/vcruise/detection.h
@@ -64,6 +64,7 @@ struct VCruiseGameDescription {
 #define GAMEOPTION_SKIP_MENU					GUIO_GAMEOPTIONS3
 #define GAMEOPTION_INCREASE_DRAG_DISTANCE		GUIO_GAMEOPTIONS4
 #define GAMEOPTION_USE_4BIT_GRAPHICS			GUIO_GAMEOPTIONS5
+#define GAMEOPTION_PRELOAD_SOUNDS				GUIO_GAMEOPTIONS6
 
 
 } // End of namespace VCruise
diff --git a/engines/vcruise/metaengine.cpp b/engines/vcruise/metaengine.cpp
index f0d6af80eb7..ae3b7eac247 100644
--- a/engines/vcruise/metaengine.cpp
+++ b/engines/vcruise/metaengine.cpp
@@ -91,6 +91,17 @@ static const ADExtraGuiOptionsMap optionsList[] = {
 			0
 		}
 	},
+	{
+		GAMEOPTION_PRELOAD_SOUNDS,
+		{
+			_s("Preload sounds"),
+			_s("Preload sounds. May improve performance on slow hard drives."),
+			"vcruise_preload_sounds",
+			false,
+			0,
+			0
+		}
+	},
 	AD_EXTRA_GUI_OPTIONS_TERMINATOR
 };
 
diff --git a/engines/vcruise/runtime.cpp b/engines/vcruise/runtime.cpp
index c25e9f94169..f0b747268ba 100644
--- a/engines/vcruise/runtime.cpp
+++ b/engines/vcruise/runtime.cpp
@@ -1467,8 +1467,8 @@ Runtime::Runtime(OSystem *system, Audio::Mixer *mixer, MidiDriver *midiDrv, cons
 	: _system(system), _mixer(mixer), _midiDrv(midiDrv), _roomNumber(1), _screenNumber(0), _direction(0), _hero(0), _disc(0), _swapOutRoom(0), _swapOutScreen(0), _swapOutDirection(0),
 	  _haveHorizPanAnimations(false), _loadedRoomNumber(0), _activeScreenNumber(0),
 	  _gameState(kGameStateBoot), _gameID(gameID), _havePendingScreenChange(false), _forceScreenChange(false), _havePendingPreIdleActions(false), _havePendingReturnToIdleState(false), _havePendingPostSwapScreenReset(false),
-	  _havePendingCompletionCheck(false), _havePendingPlayAmbientSounds(false), _ambientSoundFinishTime(0), _escOn(false), _debugMode(false), _fastAnimationMode(false), _lowQualityGraphicsMode(false),
-	  _musicTrack(0), _musicActive(true), _musicMute(false), _musicMuteDisabled(false),
+	  _havePendingCompletionCheck(false), _havePendingPlayAmbientSounds(false), _ambientSoundFinishTime(0), _escOn(false), _debugMode(false), _fastAnimationMode(false), _preloadSounds(false),
+	  _lowQualityGraphicsMode(false), _musicTrack(0), _musicActive(true), _musicMute(false), _musicMuteDisabled(false),
 	  _scoreSectionEndTime(0), _musicVolume(getDefaultSoundVolume()), _musicVolumeRampStartTime(0), _musicVolumeRampStartVolume(0), _musicVolumeRampRatePerMSec(0), _musicVolumeRampEnd(0),
 	  _panoramaDirectionFlags(0),
 	  _loadedAnimation(0), _loadedAnimationHasSound(false),
@@ -1668,6 +1668,10 @@ void Runtime::setFastAnimationMode(bool fastAnimationMode) {
 	_fastAnimationMode = fastAnimationMode;
 }
 
+void Runtime::setPreloadSounds(bool preloadSounds) {
+	_preloadSounds = preloadSounds;
+}
+
 void Runtime::setLowQualityGraphicsMode(bool lowQualityGraphicsMode) {
 	_lowQualityGraphicsMode = lowQualityGraphicsMode;
 }
@@ -3492,12 +3496,37 @@ SoundCache *Runtime::loadCache(SoundInstance &sound) {
 		return nullptr;
 	}
 
+	if (_preloadSounds) {
+		if (stream->size() > static_cast<int64>(0xffffffffu)) {
+			warning("Sound stream is too large");
+			delete stream;
+			return nullptr;
+		}
+
+		uint32 streamSize = static_cast<uint32>(stream->size());
+
+		byte *streamContents = new byte[streamSize];
+
+		if (stream->read(streamContents, streamSize) != streamSize) {
+			warning("Couldn't preload sound contents for sound '%s'", sound.name.c_str());
+			delete[] streamContents;
+			delete stream;
+			return nullptr;
+		}
+
+		Common::MemoryReadStream *memStream = new Common::MemoryReadStream(streamContents, streamSize);
+		delete stream;
+
+		stream = memStream;
+	}
+
 	Common::SharedPtr<SoundLoopInfo> loopInfo;
 
 	if (_gameID == GID_SCHIZM) {
 		loopInfo = SoundLoopInfo::readFromWaveFile(*stream);
 		if (!stream->seek(0)) {
 			warning("Couldn't reset stream to 0 after reading sample table for sound '%s'", sound.name.c_str());
+			delete stream;
 			return nullptr;
 		}
 	}
diff --git a/engines/vcruise/runtime.h b/engines/vcruise/runtime.h
index d720952dc7e..dfbaccb40f5 100644
--- a/engines/vcruise/runtime.h
+++ b/engines/vcruise/runtime.h
@@ -657,6 +657,7 @@ public:
 	void loadCursors(const char *exeName);
 	void setDebugMode(bool debugMode);
 	void setFastAnimationMode(bool fastAnimationMode);
+	void setPreloadSounds(bool preloadSounds);
 	void setLowQualityGraphicsMode(bool lowQualityGraphicsMode);
 
 	bool runFrame();
@@ -1337,6 +1338,7 @@ private:
 	bool _escOn;
 	bool _debugMode;
 	bool _fastAnimationMode;
+	bool _preloadSounds;
 	bool _lowQualityGraphicsMode;
 
 	VCruiseGameID _gameID;
diff --git a/engines/vcruise/vcruise.cpp b/engines/vcruise/vcruise.cpp
index 0b02f86a237..c2aedd8e3ff 100644
--- a/engines/vcruise/vcruise.cpp
+++ b/engines/vcruise/vcruise.cpp
@@ -234,6 +234,10 @@ Common::Error VCruiseEngine::run() {
 		_runtime->setFastAnimationMode(true);
 	}
 
+	if (ConfMan.getBool("vcruise_preload_sounds")) {
+		_runtime->setPreloadSounds(true);
+	}
+
 	if (ConfMan.getBool("vcruise_use_4bit")) {
 		_runtime->setLowQualityGraphicsMode(true);
 	}




More information about the Scummvm-git-logs mailing list