aboutsummaryrefslogtreecommitdiff
path: root/engines/pink/objects
diff options
context:
space:
mode:
Diffstat (limited to 'engines/pink/objects')
-rw-r--r--engines/pink/objects/actions/action_play_with_sfx.cpp23
-rw-r--r--engines/pink/objects/actions/action_play_with_sfx.h10
-rw-r--r--engines/pink/objects/actions/action_sound.cpp29
-rw-r--r--engines/pink/objects/actions/action_sound.h9
-rw-r--r--engines/pink/objects/actions/action_talk.cpp11
-rw-r--r--engines/pink/objects/actions/action_talk.h2
-rw-r--r--engines/pink/objects/pages/page.cpp4
-rw-r--r--engines/pink/objects/pages/page.h2
-rw-r--r--engines/pink/objects/sequences/sequence.cpp12
-rw-r--r--engines/pink/objects/sequences/sequence.h3
10 files changed, 30 insertions, 75 deletions
diff --git a/engines/pink/objects/actions/action_play_with_sfx.cpp b/engines/pink/objects/actions/action_play_with_sfx.cpp
index 056ce6e9b3..3805b8fe3c 100644
--- a/engines/pink/objects/actions/action_play_with_sfx.cpp
+++ b/engines/pink/objects/actions/action_play_with_sfx.cpp
@@ -78,13 +78,6 @@ void ActionPlayWithSfx::updateSound() {
}
}
-ActionSfx::ActionSfx()
- : _sound(nullptr) {}
-
-ActionSfx::~ActionSfx() {
- end();
-}
-
void ActionSfx::deserialize(Pink::Archive &archive) {
_frame = archive.readDWORD();
_volume = archive.readDWORD();
@@ -97,20 +90,8 @@ void ActionSfx::toConsole() {
}
void ActionSfx::play(Page *page) {
- if (!_sound)
- _sound = page->loadSound(_sfxName);
-
- if (!_sound->isPlaying())
- _sound->play(Audio::Mixer::kSFXSoundType, _volume, 0);
-}
-
-void ActionSfx::end() {
- delete _sound;
- _sound = nullptr;
-}
-
-uint32 ActionSfx::getFrame() {
- return _frame;
+ if (!_sound.isPlaying())
+ _sound.play(page->getResourceStream(_sfxName), Audio::Mixer::kSFXSoundType, _volume);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_play_with_sfx.h b/engines/pink/objects/actions/action_play_with_sfx.h
index 7e8b0c8ed2..16a3cada99 100644
--- a/engines/pink/objects/actions/action_play_with_sfx.h
+++ b/engines/pink/objects/actions/action_play_with_sfx.h
@@ -24,6 +24,7 @@
#define PINK_ACTION_PLAY_WITH_SFX_H
#include "pink/objects/actions/action_play.h"
+#include "pink/sound.h"
namespace Pink {
@@ -49,26 +50,21 @@ private:
uint32 _isLoop;
};
-class Sound;
class Page;
class ActionSfx : public Object {
public:
- ActionSfx();
- ~ActionSfx() override;
-
void deserialize(Archive &archive) override;
void toConsole() override;
void play(Page *page);
- void end();
- uint32 getFrame();
+ uint32 getFrame() { return _frame; }
private:
- Sound *_sound;
Common::String _sfxName;
+ Sound _sound;
uint32 _volume;
uint32 _frame;
};
diff --git a/engines/pink/objects/actions/action_sound.cpp b/engines/pink/objects/actions/action_sound.cpp
index d63d57c7f3..e67717f04a 100644
--- a/engines/pink/objects/actions/action_sound.cpp
+++ b/engines/pink/objects/actions/action_sound.cpp
@@ -31,10 +31,7 @@
namespace Pink {
-ActionSound::ActionSound()
- : _sound(nullptr) {}
-
-ActionSound::~ActionSound(){
+ActionSound::~ActionSound() {
end();
}
@@ -52,16 +49,12 @@ void ActionSound::toConsole() {
}
void ActionSound::start() {
- assert(!_sound);
- _sound = _actor->getPage()->loadSound(_fileName);
-
- Audio::Mixer::SoundType soundType = _isBackground ? Audio::Mixer::kMusicSoundType
- : Audio::Mixer::kSpeechSoundType;
+ Audio::Mixer::SoundType soundType = _isBackground ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType;
Director *director = _actor->getPage()->getGame()->getDirector();
director->addSound(this);
- _sound->play(soundType, _volume, _isLoop);
+ _sound.play(_actor->getPage()->getResourceStream(_fileName), soundType, _volume, _isLoop);
if (_isLoop)
_actor->endAction();
@@ -69,25 +62,21 @@ void ActionSound::start() {
}
void ActionSound::end() {
- if (_sound) {
- debug("ActionSound %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
+ _sound.stop();
+ debug("ActionSound %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
- Director *director = _actor->getPage()->getGame()->getDirector();
- director->removeSound(this);
+ Director *director = _actor->getPage()->getGame()->getDirector();
+ director->removeSound(this);
- delete _sound;
- _sound = nullptr;
- }
}
void ActionSound::update() {
- if (!_sound->isPlaying())
+ if (!_sound.isPlaying())
_actor->endAction();
}
void ActionSound::pause(bool paused) {
- if (_sound)
- _sound->pause(paused);
+ _sound.pause(paused);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_sound.h b/engines/pink/objects/actions/action_sound.h
index c614951557..e502f34293 100644
--- a/engines/pink/objects/actions/action_sound.h
+++ b/engines/pink/objects/actions/action_sound.h
@@ -24,16 +24,13 @@
#define PINK_ACTION_SOUND_H
#include "pink/objects/actions/action.h"
+#include "pink/sound.h"
namespace Pink {
-class Sound;
-
class ActionSound : public Action {
public:
- ActionSound();
- ~ActionSound();
-
+ ~ActionSound() override;
void deserialize(Archive &archive) override;
void toConsole() override;
@@ -46,8 +43,8 @@ public:
void pause(bool paused) override;
private:
- Sound *_sound;
Common::String _fileName;
+ Sound _sound;
uint32 _volume;
bool _isLoop;
bool _isBackground;
diff --git a/engines/pink/objects/actions/action_talk.cpp b/engines/pink/objects/actions/action_talk.cpp
index c142dca0e6..f46afb312c 100644
--- a/engines/pink/objects/actions/action_talk.cpp
+++ b/engines/pink/objects/actions/action_talk.cpp
@@ -42,7 +42,7 @@ void ActionTalk::toConsole() {
void ActionTalk::update() {
ActionLoop::update();
- if (!_sound->isPlaying()) {
+ if (!_sound.isPlaying()) {
_decoder->stop();
_actor->endAction();
}
@@ -50,20 +50,17 @@ void ActionTalk::update() {
void ActionTalk::end() {
ActionPlay::end();
- delete _sound;
- _sound = nullptr;
+ _sound.stop();
}
void ActionTalk::pause(bool paused) {
ActionCEL::pause(paused);
- if (_sound)
- _sound->pause(paused);
+ _sound.pause(paused);
}
void ActionTalk::onStart() {
ActionPlay::onStart();
- _sound = _actor->getPage()->loadSound(_vox);
- _sound->play(Audio::Mixer::kSpeechSoundType, 100, 0);
+ _sound.play(_actor->getPage()->getResourceStream(_vox), Audio::Mixer::kSpeechSoundType);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_talk.h b/engines/pink/objects/actions/action_talk.h
index 672e0249a6..f29dc0f5fc 100644
--- a/engines/pink/objects/actions/action_talk.h
+++ b/engines/pink/objects/actions/action_talk.h
@@ -45,7 +45,7 @@ protected:
void onStart() override;
private:
- Sound *_sound;
+ Sound _sound;
Common::String _vox;
};
diff --git a/engines/pink/objects/pages/page.cpp b/engines/pink/objects/pages/page.cpp
index 2266cd5a2a..bb93d17f93 100644
--- a/engines/pink/objects/pages/page.cpp
+++ b/engines/pink/objects/pages/page.cpp
@@ -47,10 +47,6 @@ Actor *Page::findActor(const Common::String &name) {
return nullptr;
}
-Sound *Page::loadSound(Common::String &fileName) {
- return _resMgr.loadSound(fileName);
-}
-
CelDecoder *Page::loadCel(Common::String &fileName) {
return _resMgr.loadCEL(fileName);
diff --git a/engines/pink/objects/pages/page.h b/engines/pink/objects/pages/page.h
index 0ed16db2c8..9ccfe20166 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();
- Sound *loadSound(Common::String &fileName);
+ Common::SafeSeekableSubReadStream *getResourceStream(const Common::String &fileName) { return _resMgr.getResourceStream(fileName); }
CelDecoder *loadCel(Common::String &fileName);
virtual void clear();
diff --git a/engines/pink/objects/sequences/sequence.cpp b/engines/pink/objects/sequences/sequence.cpp
index 8e2f38c549..e7d5783050 100644
--- a/engines/pink/objects/sequences/sequence.cpp
+++ b/engines/pink/objects/sequences/sequence.cpp
@@ -160,27 +160,25 @@ void SequenceAudio::start(int unk) {
}
void SequenceAudio::end() {
- delete _sound;
- _sound = nullptr;
+ _sound.stop();
Sequence::end();
}
void SequenceAudio::update() {
- if (!_sound->isPlaying())
+ if (!_sound.isPlaying())
end();
- else if (_sample <= _sound->getCurrentSample())
+ else if (_sample <= _sound.getCurrentSample())
start(0);
}
void SequenceAudio::init(int unk) {
_sample = 0;
- _sound = _sequencer->_page->loadSound(_soundName);
- _sound->play(Audio::Mixer::kMusicSoundType, 100, 0);
+ _sound.play(_sequencer->_page->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
Sequence::init(unk);
}
void SequenceAudio::restart() {
- _sound->play(Audio::Mixer::kMusicSoundType, 100, 0);
+ _sound.play(_sequencer->_page->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
Sequence::restart();
}
diff --git a/engines/pink/objects/sequences/sequence.h b/engines/pink/objects/sequences/sequence.h
index 34863256f2..93dcb25d26 100644
--- a/engines/pink/objects/sequences/sequence.h
+++ b/engines/pink/objects/sequences/sequence.h
@@ -23,6 +23,7 @@
#ifndef PINK_SEQUENCE_H
#define PINK_SEQUENCE_H
+#include "pink/sound.h"
#include "pink/objects/object.h"
namespace Pink {
@@ -79,7 +80,7 @@ public:
private:
Common::String _soundName;
- Sound *_sound;
+ Sound _sound;
uint _sample;
};