aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLittleboy2011-06-24 11:43:10 -0400
committerLittleboy2011-06-24 11:43:10 -0400
commit3f4d2c8130ac1db51f9a2fc5fcb5a2413b215f45 (patch)
treee0f4e05c9252d41721bf585a615e525d9f0aab3e
parent5d020fffad44c78414b91de7c26653b11b78b60f (diff)
downloadscummvm-rg350-3f4d2c8130ac1db51f9a2fc5fcb5a2413b215f45.tar.gz
scummvm-rg350-3f4d2c8130ac1db51f9a2fc5fcb5a2413b215f45.tar.bz2
scummvm-rg350-3f4d2c8130ac1db51f9a2fc5fcb5a2413b215f45.zip
LASTEXPRESS: Move subtitle-related methods to the SubtitleEntry class
-rw-r--r--engines/lastexpress/game/sound.cpp103
-rw-r--r--engines/lastexpress/game/sound.h16
-rw-r--r--engines/lastexpress/sound/entry.cpp91
-rw-r--r--engines/lastexpress/sound/entry.h27
4 files changed, 125 insertions, 112 deletions
diff --git a/engines/lastexpress/game/sound.cpp b/engines/lastexpress/game/sound.cpp
index f8bee17d61..adb82816f5 100644
--- a/engines/lastexpress/game/sound.cpp
+++ b/engines/lastexpress/game/sound.cpp
@@ -127,7 +127,7 @@ SoundManager::SoundManager(LastExpressEngine *engine) : _engine(engine), _state(
// Sound cache
_soundCacheData = malloc(6 * SOUNDCACHE_ENTRY_SIZE);
- _drawSubtitles = 0;
+ _subtitlesFlag = 0;
_currentSubtitle = NULL;
_loopingSoundDuration = 0;
@@ -436,7 +436,7 @@ void SoundManager::removeEntry(SoundEntry *entry) {
// removeFromCache(entry);
if (entry->subtitle) {
- drawSubtitle(entry->subtitle);
+ entry->subtitle->draw();
SAFE_DELETE(entry->subtitle);
}
@@ -640,7 +640,7 @@ bool SoundManager::playSoundWithSubtitles(Common::String filename, SoundFlag fla
while (filename.size() > 4)
filename.deleteLastChar();
- showSubtitle(entry, filename);
+ entry->showSubtitle(filename);
entry->updateState();
}
@@ -785,7 +785,7 @@ void SoundManager::playSteam(CityIndex index) {
// Get the new sound entry and show subtitles
SoundEntry *entry = getEntry(kSoundType1);
if (entry)
- showSubtitle(entry, cities[index]);
+ entry->showSubtitle(cities[index]);
}
void SoundManager::playFightSound(byte action, byte a4) {
@@ -1762,7 +1762,7 @@ void SoundManager::updateSubtitles() {
for (Common::List<SubtitleEntry *>::iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
uint32 current_index = 0;
- SoundEntry *soundEntry = (*i)->sound;
+ SoundEntry *soundEntry = (*i)->getSoundEntry();
SoundStatus status = (SoundStatus)soundEntry->status.status;
if (!(status & kSoundStatus_40)
@@ -1786,103 +1786,20 @@ void SoundManager::updateSubtitles() {
if (_currentSubtitle == subtitle) {
if (subtitle)
- setupSubtitleAndDraw(subtitle);
+ subtitle->setupAndDraw();
return;
}
- if (_drawSubtitles & 1)
- drawSubtitleOnScreen(subtitle);
+ if (_subtitlesFlag & 1)
+ subtitle->drawOnScreen();
if (subtitle) {
- loadSubtitleData(subtitle);
- setupSubtitleAndDraw(subtitle);
+ subtitle->loadData();
+ subtitle->setupAndDraw();
}
}
-void SoundManager::showSubtitle(SoundEntry *entry, Common::String filename) {
- entry->subtitle = loadSubtitle(filename, entry);
-
- if (entry->subtitle->status.status2 & 4) {
- drawSubtitle(entry->subtitle);
- SAFE_DELETE(entry->subtitle);
- } else {
- entry->status.status |= kSoundStatus_20000;
- }
-}
-
-SubtitleEntry *SoundManager::loadSubtitle(Common::String filename, SoundEntry *soundEntry) {
- SubtitleEntry *entry = new SubtitleEntry();
- _subtitles.push_back(entry);
-
- // Set sound entry and filename
- entry->filename = filename + ".SBE";
- entry->sound = soundEntry;
-
- // Load subtitle data
- if (_engine->getResourceManager()->hasFile(filename)) {
- if (_drawSubtitles & 2)
- return entry;
-
- loadSubtitleData(entry);
- } else {
- entry->status.status = kSoundStatus_400;
- }
-
- return entry;
-}
-
-void SoundManager::loadSubtitleData(SubtitleEntry * entry) {
- entry->data = new SubtitleManager(_engine->getFont());
- entry->data->load(getArchive(entry->filename));
-
- _drawSubtitles |= 2;
- _currentSubtitle = entry;
-}
-
-void SoundManager::setupSubtitleAndDraw(SubtitleEntry *subtitle) {
- if (!subtitle->data) {
- subtitle->data = new SubtitleManager(_engine->getFont());
- subtitle->data->load(getArchive(subtitle->filename));
- }
-
- if (subtitle->data->getMaxTime() > subtitle->sound->time) {
- subtitle->status.status = kSoundStatus_400;
- } else {
- subtitle->data->setTime((uint16)subtitle->sound->time);
-
- if (_drawSubtitles & 1)
- drawSubtitleOnScreen(subtitle);
- }
-
- _currentSubtitle = subtitle;
-}
-
-void SoundManager::drawSubtitle(SubtitleEntry *subtitle) {
- // Remove subtitle from queue
- _subtitles.remove(subtitle);
-
- if (subtitle == _currentSubtitle) {
- drawSubtitleOnScreen(subtitle);
-
- _currentSubtitle = NULL;
- _drawSubtitles = 0;
- }
-}
-
-void SoundManager::drawSubtitleOnScreen(SubtitleEntry *subtitle) {
- if (!subtitle)
- error("SoundManager::drawSubtitleOnScreen: Invalid subtitle entry!");
-
- _drawSubtitles &= ~1;
-
- if (subtitle->data == NULL)
- return;
-
- if (_drawSubtitles & 1)
- _engine->getGraphicsManager()->draw(subtitle->data, GraphicsManager::kBackgroundOverlay);
-}
-
//////////////////////////////////////////////////////////////////////////
// Misc
//////////////////////////////////////////////////////////////////////////
diff --git a/engines/lastexpress/game/sound.h b/engines/lastexpress/game/sound.h
index a87bb9bb80..b2a1b4387b 100644
--- a/engines/lastexpress/game/sound.h
+++ b/engines/lastexpress/game/sound.h
@@ -107,6 +107,14 @@ public:
// Accessors
uint32 getFlag() { return _flag; }
+ int getSubtitleFlag() { return _subtitlesFlag; }
+ void setSubtitleFlag(int flag) { _subtitlesFlag = flag; }
+
+ // Subtitles
+ void addSubtitle(SubtitleEntry *entry) { _subtitles.push_back(entry); }
+ void removeSubtitle(SubtitleEntry *entry) { _subtitles.remove(entry); }
+ void setCurrentSubtitle(SubtitleEntry *entry) { _currentSubtitle = entry; }
+ SubtitleEntry *getCurrentSubtitle() { return _currentSubtitle; }
private:
typedef int32 *SoundBuffer;
@@ -161,15 +169,9 @@ private:
void removeEntry(SoundEntry *entry);
// Subtitles
- int _drawSubtitles;
+ int _subtitlesFlag;
Common::List<SubtitleEntry *> _subtitles;
SubtitleEntry *_currentSubtitle;
- void showSubtitle(SoundEntry *entry, Common::String filename);
- SubtitleEntry *loadSubtitle(Common::String filename, SoundEntry *soundEntry);
- void loadSubtitleData(SubtitleEntry * entry);
- void setupSubtitleAndDraw(SubtitleEntry *subtitle);
- void drawSubtitle(SubtitleEntry *subtitle);
- void drawSubtitleOnScreen(SubtitleEntry *subtitle);
// Sound filter
void applyFilter(SoundEntry *entry, int16 *buffer);
diff --git a/engines/lastexpress/sound/entry.cpp b/engines/lastexpress/sound/entry.cpp
index 309996886a..848e728ba4 100644
--- a/engines/lastexpress/sound/entry.cpp
+++ b/engines/lastexpress/sound/entry.cpp
@@ -24,8 +24,10 @@
#include "lastexpress/game/sound.h"
+#include "lastexpress/graphics.h"
#include "lastexpress/helpers.h"
#include "lastexpress/lastexpress.h"
+#include "lastexpress/resource.h"
#include "common/stream.h"
@@ -35,7 +37,6 @@ namespace LastExpress {
// SoundEntry
//////////////////////////////////////////////////////////////////////////
SoundEntry::SoundEntry(LastExpressEngine *engine) : _engine(engine) {
- status.status = 0;
type = kSoundTypeNone;
currentDataPtr = 0;
@@ -135,17 +136,95 @@ void SoundEntry::reset() {
}
}
+void SoundEntry::showSubtitle(Common::String filename) {
+ subtitle = new SubtitleEntry(_engine);
+ subtitle->load(filename, this);
+
+ if (subtitle->getStatus().status2 & 4) {
+ subtitle->draw();
+ SAFE_DELETE(subtitle);
+ } else {
+ status.status |= kSoundStatus_20000;
+ }
+}
+
//////////////////////////////////////////////////////////////////////////
// SubtitleEntry
//////////////////////////////////////////////////////////////////////////
-SubtitleEntry::SubtitleEntry() {
- status.status = 0;
- sound = NULL;
- data = NULL;
+SubtitleEntry::SubtitleEntry(LastExpressEngine *engine) : _engine(engine) {
+ _sound = NULL;
+ _data = NULL;
}
SubtitleEntry::~SubtitleEntry() {
- SAFE_DELETE(data);
+ SAFE_DELETE(_data);
+}
+
+void SubtitleEntry::load(Common::String filename, SoundEntry *soundEntry) {
+ // Add ourselves to the list of active subtitles
+ getSound()->addSubtitle(this);
+
+ // Set sound entry and filename
+ _filename = filename + ".SBE";
+ _sound = soundEntry;
+
+ // Load subtitle data
+ if (_engine->getResourceManager()->hasFile(filename)) {
+ if (getSound()->getSubtitleFlag() & 2)
+ return;
+
+ loadData();
+ } else {
+ _status.status = kSoundStatus_400;
+ }
+}
+
+void SubtitleEntry::loadData() {
+ _data = new SubtitleManager(_engine->getFont());
+ _data->load(getArchive(_filename));
+
+ getSound()->setSubtitleFlag(getSound()->getSubtitleFlag() | 2);
+ getSound()->setCurrentSubtitle(this);
+}
+
+void SubtitleEntry::setupAndDraw() {
+ if (!_data) {
+ _data = new SubtitleManager(_engine->getFont());
+ _data->load(getArchive(_filename));
+ }
+
+ if (_data->getMaxTime() > _sound->time) {
+ _status.status = kSoundStatus_400;
+ } else {
+ _data->setTime((uint16)_sound->time);
+
+ if (getSound()->getSubtitleFlag() & 1)
+ drawOnScreen();
+ }
+
+ getSound()->setCurrentSubtitle(this);
+}
+
+void SubtitleEntry::draw() {
+ // Remove ourselves from the queue
+ getSound()->removeSubtitle(this);
+
+ if (this == getSound()->getCurrentSubtitle()) {
+ drawOnScreen();
+
+ getSound()->setCurrentSubtitle(NULL);
+ getSound()->setSubtitleFlag(0);
+ }
+}
+
+void SubtitleEntry::drawOnScreen() {
+ getSound()->setSubtitleFlag(getSound()->getSubtitleFlag() & -1);
+
+ if (_data == NULL)
+ return;
+
+ if (getSound()->getSubtitleFlag() & 1)
+ _engine->getGraphicsManager()->draw(_data, GraphicsManager::kBackgroundOverlay);
}
} // End of namespace LastExpress
diff --git a/engines/lastexpress/sound/entry.h b/engines/lastexpress/sound/entry.h
index 9ed091b225..5671e0e74b 100644
--- a/engines/lastexpress/sound/entry.h
+++ b/engines/lastexpress/sound/entry.h
@@ -120,6 +120,9 @@ public:
void updateState();
void reset();
+ // Subtitles
+ void showSubtitle(Common::String filename);
+
private:
LastExpressEngine *_engine;
@@ -158,14 +161,26 @@ public:
//////////////////////////////////////////////////////////////////////////
class SubtitleEntry {
public:
- SubtitleEntry();
+ SubtitleEntry(LastExpressEngine *engine);
~SubtitleEntry();
-public:
- Common::String filename;
- SoundStatusUnion status;
- SoundEntry *sound;
- SubtitleManager *data;
+ void load(Common::String filename, SoundEntry *soundEntry);
+ void loadData();
+ void draw();
+ void setupAndDraw();
+ void drawOnScreen();
+
+ // Accessors
+ SoundStatusUnion getStatus() { return _status; }
+ SoundEntry *getSoundEntry() { return _sound; }
+
+private:
+ LastExpressEngine *_engine;
+
+ Common::String _filename;
+ SoundStatusUnion _status;
+ SoundEntry *_sound;
+ SubtitleManager *_data;
};
} // End of namespace LastExpress