From 991b579fcec8d9e879f473d09d3ea022915ae5f6 Mon Sep 17 00:00:00 2001
From: Eugene Sandulenko <sev@scummvm.org>
Date: Mon, 10 May 2021 18:30:33 +0200
Subject: [PATCH] PINK: Switch whole engine to MemoryReadStream

---
 engines/pink/objects/actions/action_sound.cpp | 13 +------------
 engines/pink/objects/pages/page.h             |  2 +-
 engines/pink/resource_mgr.cpp                 | 12 +++++++-----
 engines/pink/resource_mgr.h                   |  2 +-
 engines/pink/sound.cpp                        |  2 +-
 engines/pink/sound.h                          |  6 +-----
 6 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/engines/pink/objects/actions/action_sound.cpp b/engines/pink/objects/actions/action_sound.cpp
index 5ca720e1dc4..9be81b58fca 100644
--- a/engines/pink/objects/actions/action_sound.cpp
+++ b/engines/pink/objects/actions/action_sound.cpp
@@ -21,8 +21,6 @@
  */
 
 #include "common/debug.h"
-#include "common/memstream.h"
-#include "common/substream.h"
 
 #include "pink/archive.h"
 #include "pink/pink.h"
@@ -62,16 +60,7 @@ void ActionSound::start() {
 	} else
 		_actor->endAction();
 
-	Common::SafeSeekableSubReadStream *stream = page->getResourceStream(_fileName);
-	byte *data = (byte *)malloc(stream->size());
-	stream->read(data, stream->size());
-
-	Common::MemoryReadStream *memstream = new Common::MemoryReadStream(data, stream->size(), DisposeAfterUse::YES);
-	delete stream;
-
-	Common::SafeSeekableSubReadStream *stream2 = new Common::SafeSeekableSubReadStream(memstream, 0, memstream->size(), DisposeAfterUse::YES);
-
-	_sound.play(stream2, soundType, _volume, 0, _isLoop);
+	_sound.play(page->getResourceStream(_fileName), soundType, _volume, 0, _isLoop);
 
 	debugC(6, kPinkDebugActions, "Actor %s has now ActionSound %s", _actor->getName().c_str(), _name.c_str());
 }
diff --git a/engines/pink/objects/pages/page.h b/engines/pink/objects/pages/page.h
index d541fa79c32..8cf7a8d6122 100644
--- a/engines/pink/objects/pages/page.h
+++ b/engines/pink/objects/pages/page.h
@@ -46,7 +46,7 @@ public:
 	Actor *findActor(const Common::String &name);
 	LeadActor *getLeadActor() { return _leadActor; }
 
-	Common::SafeSeekableSubReadStream *getResourceStream(const Common::String &fileName) { return _resMgr.getResourceStream(fileName); }
+	Common::SeekableReadStream *getResourceStream(const Common::String &fileName) { return _resMgr.getResourceStream(fileName); }
 
 	virtual void clear();
 	void pause(bool paused);
diff --git a/engines/pink/resource_mgr.cpp b/engines/pink/resource_mgr.cpp
index dbbfd01e639..42f7ee1297d 100644
--- a/engines/pink/resource_mgr.cpp
+++ b/engines/pink/resource_mgr.cpp
@@ -20,8 +20,6 @@
  *
  */
 
-#include "common/substream.h"
-
 #include "pink/cel_decoder.h"
 #include "pink/file.h"
 #include "pink/pink.h"
@@ -59,7 +57,7 @@ static int resDescComp(const void *a, const void *b) {
 	return scumm_stricmp((const char *)a, (const char *)b);
 }
 
-Common::SafeSeekableSubReadStream *ResourceMgr::getResourceStream(const Common::String &name) {
+Common::SeekableReadStream *ResourceMgr::getResourceStream(const Common::String &name) {
 	Common::SeekableReadStream *stream;
 
 	ResourceDescription *desc = (ResourceDescription *)bsearch(name.c_str(), _resDescTable, _resCount, sizeof(ResourceDescription), resDescComp);
@@ -71,9 +69,13 @@ Common::SafeSeekableSubReadStream *ResourceMgr::getResourceStream(const Common::
 
 	stream->seek(desc->offset);
 
+	byte *data = (byte *)malloc(desc->size);
+	stream->read(data, desc->size);
+
+	Common::MemoryReadStream *memstream = new Common::MemoryReadStream(data, desc->size, DisposeAfterUse::YES);
+
 	debugC(kPinkDebugLoadingResources, "Got stream of %s resource", name.c_str());
-	return new Common::SafeSeekableSubReadStream(stream, desc->offset,
-												 desc->offset + desc->size);
+	return memstream;
 }
 
 } // End of namespace Pink
diff --git a/engines/pink/resource_mgr.h b/engines/pink/resource_mgr.h
index 6fc40aed0bc..08e9eab0efe 100644
--- a/engines/pink/resource_mgr.h
+++ b/engines/pink/resource_mgr.h
@@ -46,7 +46,7 @@ public:
 
 	void clear();
 
-	Common::SafeSeekableSubReadStream *getResourceStream(const Common::String &name);
+	Common::SeekableReadStream *getResourceStream(const Common::String &name);
 
 	PinkEngine *getGame() const { return _game; }
 
diff --git a/engines/pink/sound.cpp b/engines/pink/sound.cpp
index 7caba2472f2..56e73026f67 100644
--- a/engines/pink/sound.cpp
+++ b/engines/pink/sound.cpp
@@ -29,7 +29,7 @@
 
 namespace Pink {
 
-void Sound::play(Common::SafeSeekableSubReadStream *stream, Audio::Mixer::SoundType type, byte volume, int8 balance, bool isLoop) {
+void Sound::play(Common::SeekableReadStream *stream, Audio::Mixer::SoundType type, byte volume, int8 balance, bool isLoop) {
 	// Vox files in pink have wave format.
 	// RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 22050 Hz
 
diff --git a/engines/pink/sound.h b/engines/pink/sound.h
index 6287cb320ad..b286ca294d1 100644
--- a/engines/pink/sound.h
+++ b/engines/pink/sound.h
@@ -30,17 +30,13 @@
 
 #include "pink/constants.h"
 
-namespace Common {
-	class SafeSeekableSubReadStream;
-}
-
 namespace Pink {
 
 class Sound {
 public:
 	~Sound() { stop(); }
 
-	void play(Common::SafeSeekableSubReadStream *stream, Audio::Mixer::SoundType type, byte volume = 100, int8 balance = 0, bool isLoop = false);
+	void play(Common::SeekableReadStream *stream, Audio::Mixer::SoundType type, byte volume = 100, int8 balance = 0, bool isLoop = false);
 
 	bool isPlaying() const { return g_system->getMixer()->isSoundHandleActive(_handle); }