aboutsummaryrefslogtreecommitdiff
path: root/engines/lastexpress/game
diff options
context:
space:
mode:
authorLittleboy2011-06-24 10:56:49 -0400
committerLittleboy2011-06-24 10:56:49 -0400
commit5d020fffad44c78414b91de7c26653b11b78b60f (patch)
tree50899050b92b6e30f8bda0204d923c89aa5c7416 /engines/lastexpress/game
parent08375150ca0b4719ddda7932d5f5061fff225a28 (diff)
downloadscummvm-rg350-5d020fffad44c78414b91de7c26653b11b78b60f.tar.gz
scummvm-rg350-5d020fffad44c78414b91de7c26653b11b78b60f.tar.bz2
scummvm-rg350-5d020fffad44c78414b91de7c26653b11b78b60f.zip
LASTEXPRESS: Refactor Sound class
- Move entry-related functions to separate class - Move enumeration to shared header and rename FlagType to SoundFlag
Diffstat (limited to 'engines/lastexpress/game')
-rw-r--r--engines/lastexpress/game/action.cpp18
-rw-r--r--engines/lastexpress/game/entities.cpp6
-rw-r--r--engines/lastexpress/game/inventory.cpp2
-rw-r--r--engines/lastexpress/game/logic.cpp2
-rw-r--r--engines/lastexpress/game/scenes.cpp6
-rw-r--r--engines/lastexpress/game/sound.cpp168
-rw-r--r--engines/lastexpress/game/sound.h239
7 files changed, 88 insertions, 353 deletions
diff --git a/engines/lastexpress/game/action.cpp b/engines/lastexpress/game/action.cpp
index 7540d18ed8..54bb8759ee 100644
--- a/engines/lastexpress/game/action.cpp
+++ b/engines/lastexpress/game/action.cpp
@@ -466,7 +466,7 @@ IMPLEMENT_ACTION(playMusic)
Common::String filename = Common::String::format("MUS%03d", hotspot.param1);
if (!getSound()->isBuffered(filename) && (hotspot.param1 != 50 || getProgress().chapter == kChapter5))
- getSound()->playSound(kEntityPlayer, filename, SoundManager::kFlagDefault, hotspot.param2);
+ getSound()->playSound(kEntityPlayer, filename, kFlagDefault, hotspot.param2);
return kSceneInvalid;
}
@@ -806,7 +806,7 @@ IMPLEMENT_ACTION(enterCompartment)
getSound()->playSoundEvent(kEntityPlayer, 15, 22);
if (getProgress().field_78 && !getSound()->isBuffered("MUS003")) {
- getSound()->playSound(kEntityPlayer, "MUS003", SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, "MUS003", kFlagDefault);
getProgress().field_78 = 0;
}
@@ -1084,7 +1084,7 @@ IMPLEMENT_ACTION(25)
case 2:
if (!getSound()->isBuffered("MUS021"))
- getSound()->playSound(kEntityPlayer, "MUS021", SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, "MUS021", kFlagDefault);
break;
case 3:
@@ -1183,7 +1183,7 @@ IMPLEMENT_ACTION(29)
Common::String filename = Common::String::format("MUS%03d", hotspot.param3);
if (!getSound()->isBuffered(filename))
- getSound()->playSound(kEntityPlayer, filename, SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, filename, kFlagDefault);
return kSceneInvalid;
}
@@ -1345,7 +1345,7 @@ IMPLEMENT_ACTION(openBed)
//////////////////////////////////////////////////////////////////////////
// Action 37
IMPLEMENT_ACTION(dialog)
- getSound()->playDialog(kEntityTables4, (EntityIndex)hotspot.param1, SoundManager::kFlagDefault, 0);
+ getSound()->playDialog(kEntityTables4, (EntityIndex)hotspot.param1, kFlagDefault, 0);
return kSceneInvalid;
}
@@ -1355,7 +1355,7 @@ IMPLEMENT_ACTION(dialog)
IMPLEMENT_ACTION(eggBox)
getSound()->playSoundEvent(kEntityPlayer, 43);
if (getProgress().field_7C && !getSound()->isBuffered("MUS003")) {
- getSound()->playSound(kEntityPlayer, "MUS003", SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, "MUS003", kFlagDefault);
getProgress().field_7C = 0;
}
@@ -1367,7 +1367,7 @@ IMPLEMENT_ACTION(eggBox)
IMPLEMENT_ACTION(39)
getSound()->playSoundEvent(kEntityPlayer, 24);
if (getProgress().field_80 && !getSound()->isBuffered("MUS003")) {
- getSound()->playSound(kEntityPlayer, "MUS003", SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, "MUS003", kFlagDefault);
getProgress().field_80 = 0;
}
@@ -1409,7 +1409,7 @@ IMPLEMENT_ACTION(playMusicChapter)
Common::String filename = Common::String::format("MUS%03d", id);
if (!getSound()->isBuffered(filename))
- getSound()->playSound(kEntityPlayer, filename, SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, filename, kFlagDefault);
}
return kSceneInvalid;
@@ -1441,7 +1441,7 @@ IMPLEMENT_ACTION(playMusicChapterSetupTrain)
Common::String filename = Common::String::format("MUS%03d", hotspot.param1);
if (!getSound()->isBuffered(filename) && hotspot.param3 & id) {
- getSound()->playSound(kEntityPlayer, filename, SoundManager::kFlagDefault);
+ getSound()->playSound(kEntityPlayer, filename, kFlagDefault);
getSavePoints()->call(kEntityPlayer, kEntityTrain, kAction203863200, filename.c_str());
getSavePoints()->push(kEntityPlayer, kEntityTrain, kAction222746496, hotspot.param2);
diff --git a/engines/lastexpress/game/entities.cpp b/engines/lastexpress/game/entities.cpp
index 513ad114b0..0fa3af36b7 100644
--- a/engines/lastexpress/game/entities.cpp
+++ b/engines/lastexpress/game/entities.cpp
@@ -299,7 +299,7 @@ void Entities::setupChapter(ChapterIndex chapter) {
memset(&_compartments1, 0, sizeof(_compartments1));
memset(&_positions, 0, sizeof(_positions));
- getSound()->resetQueue(SoundManager::kSoundType13);
+ getSound()->resetQueue(kSoundType13);
}
// we skip the header when doing entity setup
@@ -2355,7 +2355,7 @@ bool Entities::changeCar(EntityData::EntityCallData *data, EntityIndex entity, C
if (data->car == newCar) {
if (isInGreenCarEntrance(kEntityPlayer)) {
getSound()->playSoundEvent(kEntityPlayer, 14);
- getSound()->excuseMe(entity, kEntityPlayer, SoundManager::kFlagDefault);
+ getSound()->excuseMe(entity, kEntityPlayer, kFlagDefault);
getScenes()->loadSceneFromPosition(kCarGreenSleeping, 1);
getSound()->playSound(kEntityPlayer, "CAT1127A");
getSound()->playSoundEvent(kEntityPlayer, 15);
@@ -2374,7 +2374,7 @@ bool Entities::changeCar(EntityData::EntityCallData *data, EntityIndex entity, C
if (data->car == newCar) {
if (isInKronosCarEntrance(kEntityPlayer)) {
getSound()->playSoundEvent(kEntityPlayer, 14);
- getSound()->excuseMe(entity, kEntityPlayer, SoundManager::kFlagDefault);
+ getSound()->excuseMe(entity, kEntityPlayer, kFlagDefault);
getScenes()->loadSceneFromPosition(kCarGreenSleeping, 62);
getSound()->playSound(kEntityPlayer, "CAT1127A");
getSound()->playSoundEvent(kEntityPlayer, 15);
diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp
index 07ad8d936b..4d75fcaca5 100644
--- a/engines/lastexpress/game/inventory.cpp
+++ b/engines/lastexpress/game/inventory.cpp
@@ -156,7 +156,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) {
_portraitHighlighted = false;
_isOpened = false;
- getSound()->playSoundWithSubtitles("LIB039.SND", SoundManager::kFlagMenuClock, kEntityPlayer);
+ getSound()->playSoundWithSubtitles("LIB039.SND", kFlagMenuClock, kEntityPlayer);
getMenu()->show(true, kSavegameTypeIndex, 0);
diff --git a/engines/lastexpress/game/logic.cpp b/engines/lastexpress/game/logic.cpp
index 3bd7d6da68..c1237eefe9 100644
--- a/engines/lastexpress/game/logic.cpp
+++ b/engines/lastexpress/game/logic.cpp
@@ -432,7 +432,7 @@ void Logic::gameOver(SavegameType type, uint32 value, SceneIndex sceneIndex, boo
if (showScene) {
- getSound()->processEntry(SoundManager::kSoundType11);
+ getSound()->processEntry(kSoundType11);
if (sceneIndex && !getFlags()->mouseRightClick) {
getScenes()->loadScene(sceneIndex);
diff --git a/engines/lastexpress/game/scenes.cpp b/engines/lastexpress/game/scenes.cpp
index e830b1d128..b346c9daf8 100644
--- a/engines/lastexpress/game/scenes.cpp
+++ b/engines/lastexpress/game/scenes.cpp
@@ -1132,7 +1132,7 @@ void SceneManager::postProcessScene() {
}
if (progress)
- getSound()->excuseMe((progress == 1) ? entities[0] : entities[rnd(progress)], kEntityPlayer, SoundManager::kFlagDefault);
+ getSound()->excuseMe((progress == 1) ? entities[0] : entities[rnd(progress)], kEntityPlayer, kFlagDefault);
}
if (hotspot->scene)
@@ -1157,8 +1157,8 @@ void SceneManager::postProcessScene() {
if (getState()->time >= kTimeCityGalanta || getProgress().field_18 == 4)
break;
- getSound()->processEntry(SoundManager::kSoundType7);
- getSound()->playSound(kEntityTrain, "LIB050", SoundManager::kFlagDefault);
+ getSound()->processEntry(kSoundType7);
+ getSound()->playSound(kEntityTrain, "LIB050", kFlagDefault);
switch (getProgress().chapter) {
default:
diff --git a/engines/lastexpress/game/sound.cpp b/engines/lastexpress/game/sound.cpp
index 6cd5731e54..f8bee17d61 100644
--- a/engines/lastexpress/game/sound.cpp
+++ b/engines/lastexpress/game/sound.cpp
@@ -30,6 +30,8 @@
#include "lastexpress/game/savepoint.h"
#include "lastexpress/game/state.h"
+#include "lastexpress/sound/entry.h"
+
#include "lastexpress/helpers.h"
#include "lastexpress/graphics.h"
#include "lastexpress/lastexpress.h"
@@ -96,12 +98,21 @@ static const char *const locomotiveSounds[5] = {
"ZFX1007B"
};
-static const SoundManager::FlagType soundFlags[32] = {
- SoundManager::kFlagDefault, SoundManager::kFlag15, SoundManager::kFlag14, SoundManager::kFlag13, SoundManager::kFlag12,
- SoundManager::kFlag11, SoundManager::kFlag11, SoundManager::kFlag10, SoundManager::kFlag10, SoundManager::kFlag9, SoundManager::kFlag9, SoundManager::kFlag8, SoundManager::kFlag8,
- SoundManager::kFlag7, SoundManager::kFlag7, SoundManager::kFlag7, SoundManager::kFlag6, SoundManager::kFlag6, SoundManager::kFlag6,
- SoundManager::kFlag5, SoundManager::kFlag5, SoundManager::kFlag5, SoundManager::kFlag5, SoundManager::kFlag4, SoundManager::kFlag4, SoundManager::kFlag4, SoundManager::kFlag4,
- SoundManager::kFlag3, SoundManager::kFlag3, SoundManager::kFlag3, SoundManager::kFlag3, SoundManager::kFlag3
+static const SoundFlag soundFlags[32] = {
+ kFlagDefault,
+ kFlag15,
+ kFlag14,
+ kFlag13,
+ kFlag12,
+ kFlag11, kFlag11,
+ kFlag10, kFlag10,
+ kFlag9, kFlag9,
+ kFlag8, kFlag8,
+ kFlag7, kFlag7, kFlag7,
+ kFlag6, kFlag6, kFlag6,
+ kFlag5, kFlag5, kFlag5, kFlag5,
+ kFlag4, kFlag4, kFlag4, kFlag4,
+ kFlag3, kFlag3, kFlag3, kFlag3, kFlag3
};
SoundManager::SoundManager(LastExpressEngine *engine) : _engine(engine), _state(0), _currentType(kSoundType16), _flag(0) {
@@ -179,7 +190,7 @@ void SoundManager::resetQueue(SoundType type1, SoundType type2) {
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
if ((*i)->type != type1 && (*i)->type != type2)
- resetEntry(*i);
+ (*i)->reset();
}
}
@@ -188,7 +199,7 @@ void SoundManager::removeFromQueue(EntityIndex entity) {
SoundEntry *entry = getEntry(entity);
if (entry)
- resetEntry(entry);
+ entry->reset();
}
void SoundManager::removeFromQueue(Common::String filename) {
@@ -196,7 +207,7 @@ void SoundManager::removeFromQueue(Common::String filename) {
SoundEntry *entry = getEntry(filename);
if (entry)
- resetEntry(entry);
+ entry->reset();
}
void SoundManager::clearQueue() {
@@ -244,13 +255,13 @@ bool SoundManager::isBuffered(Common::String filename, bool testForEntity) {
//////////////////////////////////////////////////////////////////////////
// Entry
//////////////////////////////////////////////////////////////////////////
-void SoundManager::setupEntry(SoundEntry *entry, Common::String name, FlagType flag, int a4) {
+void SoundManager::setupEntry(SoundEntry *entry, Common::String name, SoundFlag flag, int a4) {
if (!entry)
error("SoundManager::setupEntry: Invalid entry!");
entry->field_4C = a4;
setEntryType(entry, flag);
- setEntryStatus(entry, flag);
+ entry->setStatus(flag);
// Add entry to sound list
_soundList.push_back(entry);
@@ -260,7 +271,7 @@ void SoundManager::setupEntry(SoundEntry *entry, Common::String name, FlagType f
loadSoundData(entry, name);
}
-void SoundManager::setEntryType(SoundEntry *entry, FlagType flag) {
+void SoundManager::setEntryType(SoundEntry *entry, SoundFlag flag) {
switch (flag & kFlagType9) {
default:
case kFlagNone:
@@ -271,12 +282,12 @@ void SoundManager::setEntryType(SoundEntry *entry, FlagType flag) {
case kFlagType1_2: {
SoundEntry *previous2 = getEntry(kSoundType2);
if (previous2)
- updateEntry(previous2, 0);
+ previous2->update(0);
SoundEntry *previous = getEntry(kSoundType1);
if (previous) {
previous->type = kSoundType2;
- updateEntry(previous, 0);
+ previous->update(0);
}
entry->type = kSoundType1;
@@ -287,7 +298,7 @@ void SoundManager::setEntryType(SoundEntry *entry, FlagType flag) {
SoundEntry *previous = getEntry(kSoundType3);
if (previous) {
previous->type = kSoundType4;
- updateEntry(previous, 0);
+ previous->update(0);
}
entry->type = kSoundType11;
@@ -332,21 +343,6 @@ void SoundManager::setEntryType(SoundEntry *entry, FlagType flag) {
}
}
-void SoundManager::setEntryStatus(SoundEntry *entry, FlagType flag) const {
- SoundStatus status = (SoundStatus)flag;
- if (!((status & 0xFF) & kSoundStatusClear1))
- status = (SoundStatus)(status | kSoundStatusClear2);
-
- if (((status & 0xFF00) >> 8) & kSoundStatusClear0)
- entry->status.status = (uint32)status;
- else
- entry->status.status = (status | kSoundStatusClear4);
-}
-
-void SoundManager::setInCache(SoundEntry *entry) {
- entry->status.status |= kSoundStatusClear2;
-}
-
bool SoundManager::setupCache(SoundEntry *entry) {
if (entry->soundData)
return true;
@@ -370,8 +366,10 @@ bool SoundManager::setupCache(SoundEntry *entry) {
if (entry->field_4C <= size)
return false;
- if (cacheEntry)
- setInCache(cacheEntry);
+ if (!cacheEntry)
+ error("[SoundManager::setupCache] Cannot find a valid entry");
+
+ cacheEntry->setInCache();
// TODO: Wait until the cache entry is ready to be removed
while (!(cacheEntry->status.status1 & 1))
@@ -425,23 +423,6 @@ void SoundManager::loadSoundData(SoundEntry *entry, Common::String name) {
}
}
-void SoundManager::resetEntry(SoundEntry *entry) const {
- entry->status.status |= kSoundStatusRemoved;
- entry->entity = kEntityPlayer;
-
- if (entry->stream) {
- if (!entry->soundStream) {
- SAFE_DELETE(entry->stream);
- } else {
- entry->soundStream->stop();
- SAFE_DELETE(entry->soundStream);
- }
-
- entry->stream = NULL;
- }
-}
-
-
void SoundManager::removeEntry(SoundEntry *entry) {
entry->status.status |= kSoundStatusRemoved;
@@ -467,47 +448,12 @@ void SoundManager::removeEntry(SoundEntry *entry) {
}
}
-void SoundManager::updateEntry(SoundEntry *entry, uint value) const {
- if (!(entry->status.status3 & 64)) {
- int value2 = value;
-
- entry->status.status |= kSoundStatus_100000;
-
- if (value) {
- if (_flag & 32) {
- entry->field_40 = value;
- value2 = value * 2 + 1;
- }
-
- entry->field_3C = value2;
- } else {
- entry->field_3C = 0;
- entry->status.status |= kSoundStatus_40000000;
- }
- }
-}
-
-void SoundManager::updateEntryState(SoundEntry *entry) const {
- if (_flag & 32) {
- if (entry->type != kSoundType9 && entry->type != kSoundType7 && entry->type != kSoundType5) {
- uint32 status = entry->status.status & kSoundStatusClear1;
-
- entry->status.status &= kSoundStatusClearAll;
-
- entry->field_40 = status;
- entry->status.status |= status * 2 + 1;
- }
- }
-
- entry->status.status |= kSoundStatus_20;
-}
-
void SoundManager::processEntry(EntityIndex entity) {
Common::StackLock locker(_mutex);
SoundEntry *entry = getEntry(entity);
if (entry) {
- updateEntry(entry, 0);
+ entry->update(0);
entry->entity = kEntityPlayer;
}
}
@@ -517,7 +463,7 @@ void SoundManager::processEntry(SoundType type) {
SoundEntry *entry = getEntry(type);
if (entry)
- updateEntry(entry, 0);
+ entry->update(0);
}
void SoundManager::setupEntry(SoundType type, EntityIndex index) {
@@ -533,7 +479,7 @@ void SoundManager::processEntry(Common::String filename) {
SoundEntry *entry = getEntry(filename);
if (entry) {
- updateEntry(entry, 0);
+ entry->update(0);
entry->entity = kEntityPlayer;
}
}
@@ -567,7 +513,7 @@ void SoundManager::unknownFunction4() {
//////////////////////////////////////////////////////////////////////////
// Entry search
//////////////////////////////////////////////////////////////////////////
-SoundManager::SoundEntry *SoundManager::getEntry(EntityIndex index) {
+SoundEntry *SoundManager::getEntry(EntityIndex index) {
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
if ((*i)->entity == index)
return *i;
@@ -576,7 +522,7 @@ SoundManager::SoundEntry *SoundManager::getEntry(EntityIndex index) {
return NULL;
}
-SoundManager::SoundEntry *SoundManager::getEntry(Common::String name) {
+SoundEntry *SoundManager::getEntry(Common::String name) {
if (!name.contains('.'))
name += ".SND";
@@ -588,7 +534,7 @@ SoundManager::SoundEntry *SoundManager::getEntry(Common::String name) {
return NULL;
}
-SoundManager::SoundEntry *SoundManager::getEntry(SoundType type) {
+SoundEntry *SoundManager::getEntry(SoundType type) {
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
if ((*i)->type == type)
return *i;
@@ -663,11 +609,11 @@ uint32 SoundManager::count() {
//////////////////////////////////////////////////////////////////////////
// Game-related functions
//////////////////////////////////////////////////////////////////////////
-void SoundManager::playSound(EntityIndex entity, Common::String filename, FlagType flag, byte a4) {
+void SoundManager::playSound(EntityIndex entity, Common::String filename, SoundFlag flag, byte a4) {
if (isBuffered(entity) && entity)
removeFromQueue(entity);
- FlagType currentFlag = (flag == -1) ? getSoundFlag(entity) : (FlagType)(flag | 0x80000);
+ SoundFlag currentFlag = (flag == -1) ? getSoundFlag(entity) : (SoundFlag)(flag | 0x80000);
// Add .SND at the end of the filename if needed
if (!filename.contains('.'))
@@ -678,8 +624,8 @@ void SoundManager::playSound(EntityIndex entity, Common::String filename, FlagTy
getSavePoints()->push(kEntityPlayer, entity, kActionEndSound);
}
-bool SoundManager::playSoundWithSubtitles(Common::String filename, FlagType flag, EntityIndex entity, byte a4) {
- SoundEntry *entry = new SoundEntry();
+bool SoundManager::playSoundWithSubtitles(Common::String filename, SoundFlag flag, EntityIndex entity, byte a4) {
+ SoundEntry *entry = new SoundEntry(_engine);
Common::StackLock locker(_mutex);
@@ -695,7 +641,7 @@ bool SoundManager::playSoundWithSubtitles(Common::String filename, FlagType flag
filename.deleteLastChar();
showSubtitle(entry, filename);
- updateEntryState(entry);
+ entry->updateState();
}
return (entry->type != kSoundTypeNone);
@@ -711,7 +657,7 @@ void SoundManager::playSoundEvent(EntityIndex entity, byte action, byte a3) {
return;
int _action = (int)action;
- FlagType flag = getSoundFlag(entity);
+ SoundFlag flag = getSoundFlag(entity);
switch (action) {
case 36: {
@@ -886,7 +832,7 @@ void SoundManager::playFightSound(byte action, byte a4) {
playSound(kEntityTrain, Common::String::format("LIB%03d.SND", _action), kFlagDefault, a4);
}
-void SoundManager::playDialog(EntityIndex entity, EntityIndex entityDialog, FlagType flag, byte a4) {
+void SoundManager::playDialog(EntityIndex entity, EntityIndex entityDialog, SoundFlag flag, byte a4) {
if (isBuffered(getDialogName(entityDialog)))
removeFromQueue(getDialogName(entityDialog));
@@ -894,7 +840,7 @@ void SoundManager::playDialog(EntityIndex entity, EntityIndex entityDialog, Flag
}
void SoundManager::playLocomotiveSound() {
- playSound(kEntityPlayer, locomotiveSounds[rnd(5)], (FlagType)(rnd(15) + 2));
+ playSound(kEntityPlayer, locomotiveSounds[rnd(5)], (SoundFlag)(rnd(15) + 2));
}
const char *SoundManager::getDialogName(EntityIndex entity) const {
@@ -1400,7 +1346,7 @@ void SoundManager::playWarningCompartment(EntityIndex entity, ObjectIndex compar
_lastWarning[compartment - 28] = getState()->timeTicks;
}
-void SoundManager::excuseMe(EntityIndex entity, EntityIndex entity2, FlagType flag) {
+void SoundManager::excuseMe(EntityIndex entity, EntityIndex entity2, SoundFlag flag) {
if (isBuffered(entity) && entity != kEntityPlayer && entity != kEntityChapters && entity != kEntityTrain)
return;
@@ -1750,7 +1696,7 @@ const char *SoundManager::justAMinuteCath() const {
//////////////////////////////////////////////////////////////////////////
// Sound flags
//////////////////////////////////////////////////////////////////////////
-SoundManager::FlagType SoundManager::getSoundFlag(EntityIndex entity) const {
+SoundFlag SoundManager::getSoundFlag(EntityIndex entity) const {
if (entity == kEntityPlayer)
return kFlagDefault;
@@ -1758,7 +1704,7 @@ SoundManager::FlagType SoundManager::getSoundFlag(EntityIndex entity) const {
return kFlagNone;
// Compute sound value
- FlagType ret = kFlag2;
+ SoundFlag ret = kFlag2;
// Get default value if valid
int index = ABS(getEntityData(entity)->entityPosition - getEntityData(kEntityPlayer)->entityPosition) / 230;
@@ -1771,7 +1717,7 @@ SoundManager::FlagType SoundManager::getSoundFlag(EntityIndex entity) const {
&& !getEntities()->isOutsideAnnaWindow())
return kFlagNone;
- return (FlagType)(ret / 6);
+ return (SoundFlag)(ret / 6);
}
switch (getEntityData(entity)->car) {
@@ -1780,25 +1726,25 @@ SoundManager::FlagType SoundManager::getSoundFlag(EntityIndex entity) const {
case kCarKronos:
if (getEntities()->isInKronosSalon(entity) != getEntities()->isInKronosSalon(kEntityPlayer))
- ret = (FlagType)(ret * 2);
+ ret = (SoundFlag)(ret * 2);
break;
case kCarGreenSleeping:
case kCarRedSleeping:
if (getEntities()->isInGreenCarEntrance(kEntityPlayer) && !getEntities()->isInKronosSalon(entity))
- ret = (FlagType)(ret * 2);
+ ret = (SoundFlag)(ret * 2);
if (getEntityData(kEntityPlayer)->location
&& (getEntityData(entity)->entityPosition != kPosition_1 || !getEntities()->isDistanceBetweenEntities(kEntityPlayer, entity, 400)))
- ret = (FlagType)(ret * 2);
+ ret = (SoundFlag)(ret * 2);
break;
case kCarRestaurant:
if (getEntities()->isInSalon(entity) == getEntities()->isInSalon(kEntityPlayer)
&& (getEntities()->isInRestaurant(entity) != getEntities()->isInRestaurant(kEntityPlayer)))
- ret = (FlagType)(ret * 2);
+ ret = (SoundFlag)(ret * 2);
else
- ret = (FlagType)(ret * 4);
+ ret = (SoundFlag)(ret * 4);
break;
}
@@ -1865,7 +1811,7 @@ void SoundManager::showSubtitle(SoundEntry *entry, Common::String filename) {
}
}
-SoundManager::SubtitleEntry *SoundManager::loadSubtitle(Common::String filename, SoundEntry *soundEntry) {
+SubtitleEntry *SoundManager::loadSubtitle(Common::String filename, SoundEntry *soundEntry) {
SubtitleEntry *entry = new SubtitleEntry();
_subtitles.push_back(entry);
@@ -1950,7 +1896,7 @@ void SoundManager::playLoopingSound(int param) {
}
byte numLoops[8];
- static const EntityPosition positions[8] = { kPosition_8200, kPosition_7500,
+ static const EntityPosition positions[8] = { kPosition_8200, kPosition_7500,
kPosition_6470, kPosition_5790,
kPosition_4840, kPosition_4070,
kPosition_3050, kPosition_2740 };
@@ -2033,11 +1979,11 @@ void SoundManager::playLoopingSound(int param) {
playSoundWithSubtitles(tmp, kFlagLoopedSound, kEntitySteam);
if (*snd)
- updateEntry(*snd, 0);
+ (*snd)->update(0);
for (snd = _soundList.begin(); snd != _soundList.end(); ++snd) {
if ((*snd)->type == kSoundType1) {
- updateEntry((*snd), 7);
+ (*snd)->update(7);
break;
}
}
diff --git a/engines/lastexpress/game/sound.h b/engines/lastexpress/game/sound.h
index f49f2bc9f0..a87bb9bb80 100644
--- a/engines/lastexpress/game/sound.h
+++ b/engines/lastexpress/game/sound.h
@@ -23,52 +23,6 @@
#ifndef LASTEXPRESS_SOUND_H
#define LASTEXPRESS_SOUND_H
-/*
-
- Sound entry: 68 bytes (this is what appears in the savegames)
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - entity
- uint32 {4} - ??
- uint32 {4} - ??
- char {16} - name 1
- char {16} - name 2
-
- Sound queue entry: 120 bytes
- uint16 {2} - status
- byte {1} - ??
- byte {1} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - file data pointer
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - archive structure pointer
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - ??
- uint32 {4} - entity
- uint32 {4} - ??
- uint32 {4} - ??
- char {16} - name 1
- char {16} - name 2
- uint32 {4} - pointer to next entry in the queue
- uint32 {4} - subtitle data pointer
-
-*/
-
-#include "lastexpress/data/snd.h"
-#include "lastexpress/data/subtitle.h"
-
#include "lastexpress/shared.h"
#include "lastexpress/helpers.h"
@@ -82,61 +36,11 @@ namespace LastExpress {
class LastExpressEngine;
class SubtitleManager;
+class SoundEntry;
+class SubtitleEntry;
class SoundManager : Common::Serializable {
public:
- enum SoundType {
- kSoundTypeNone = 0,
- kSoundType1,
- kSoundType2,
- kSoundType3,
- kSoundType4,
- kSoundType5,
- kSoundType6,
- kSoundType7,
- kSoundType8,
- kSoundType9,
- kSoundType10,
- kSoundType11,
- kSoundType12,
- kSoundType13,
- kSoundType14,
- kSoundType15,
- kSoundType16
- };
-
- enum FlagType {
- kFlagInvalid = -1,
- kFlagNone = 0x0,
- kFlag2 = 0x2,
- kFlag3 = 0x3,
- kFlag4 = 0x4,
- kFlag5 = 0x5,
- kFlag6 = 0x6,
- kFlag7 = 0x7,
- kFlag8 = 0x8,
- kFlag9 = 0x9,
- kFlag10 = 0xA,
- kFlag11 = 0xB,
- kFlag12 = 0xC,
- kFlag13 = 0xD,
- kFlag14 = 0xE,
- kFlag15 = 0xF,
- kFlagDefault = 0x10,
-
- kFlagType1_2 = 0x1000000,
- kFlagLoopedSound = 0x1001001,
- kFlagSteam = 0x1001007,
- kFlagType13 = 0x3000000,
- kFlagMenuClock = 0x3080010,
- kFlagType7 = 0x4000000,
- kFlagType11 = 0x5000000,
- kFlagMusic = 0x5000010,
- kFlagType3 = 0x6000000,
- kFlagLoop = 0x6001008,
- kFlagType9 = 0x7000000
- };
-
SoundManager(LastExpressEngine *engine);
~SoundManager();
@@ -171,10 +75,10 @@ public:
void clearStatus();
// Sound playing
- void playSound(EntityIndex entity, Common::String filename, FlagType flag = kFlagInvalid, byte a4 = 0);
- bool playSoundWithSubtitles(Common::String filename, FlagType flag, EntityIndex entity, byte a4 = 0);
+ void playSound(EntityIndex entity, Common::String filename, SoundFlag flag = kFlagInvalid, byte a4 = 0);
+ bool playSoundWithSubtitles(Common::String filename, SoundFlag flag, EntityIndex entity, byte a4 = 0);
void playSoundEvent(EntityIndex entity, byte action, byte a3 = 0);
- void playDialog(EntityIndex entity, EntityIndex entityDialog, FlagType flag, byte a4);
+ void playDialog(EntityIndex entity, EntityIndex entityDialog, SoundFlag flag, byte a4);
void playSteam(CityIndex index);
void playFightSound(byte action, byte a4);
void playLocomotiveSound();
@@ -185,14 +89,14 @@ public:
const char *getDialogName(EntityIndex entity) const;
// Sound bites
- void excuseMe(EntityIndex entity, EntityIndex entity2 = kEntityPlayer, FlagType flag = kFlagNone);
+ void excuseMe(EntityIndex entity, EntityIndex entity2 = kEntityPlayer, SoundFlag flag = kFlagNone);
void excuseMeCath();
const char *justCheckingCath() const;
const char *wrongDoorCath() const;
const char *justAMinuteCath() const;
// FLags
- SoundManager::FlagType getSoundFlag(EntityIndex index) const;
+ SoundFlag getSoundFlag(EntityIndex index) const;
// Debug
void stopAllSound();
@@ -201,129 +105,18 @@ public:
void saveLoadWithSerializer(Common::Serializer &ser);
uint32 count();
+ // Accessors
+ uint32 getFlag() { return _flag; }
+
private:
typedef int32 *SoundBuffer;
- enum SoundStatus {
- kSoundStatus_20 = 0x20,
- kSoundStatus_40 = 0x40,
- kSoundStatus_180 = 0x180,
- kSoundStatusRemoved = 0x200,
- kSoundStatus_400 = 0x400,
-
- kSoundStatus_8000 = 0x8000,
- kSoundStatus_20000 = 0x20000,
- kSoundStatus_100000 = 0x100000,
- kSoundStatus_40000000 = 0x40000000,
-
- kSoundStatusClear0 = 0x10,
- kSoundStatusClear1 = 0x1F,
- kSoundStatusClear2 = 0x80,
- kSoundStatusClear3 = 0x200,
- kSoundStatusClear4 = 0x800,
- kSoundStatusClearAll = 0xFFFFFFE0
- };
-
enum SoundState {
kSoundState0 = 0,
kSoundState1 = 1,
kSoundState2 = 2
};
- union SoundStatusUnion {
- uint32 status;
- byte status1;
- byte status2;
- byte status3;
- byte status4;
-
- SoundStatusUnion() {
- status = 0;
- }
- };
-
- struct SubtitleEntry;
-
- struct SoundEntry {
- SoundStatusUnion status;
- SoundType type; // int
- //int data;
- //int endOffset;
- int currentDataPtr;
- void *soundData;
- //int currentBufferPtr;
- int blockCount;
- uint32 time;
- //int size;
- //int field_28;
- Common::SeekableReadStream *stream; // int
- //int field_30;
- int field_34;
- int field_38;
- int field_3C;
- int field_40;
- EntityIndex entity;
- int field_48;
- uint32 field_4C;
- Common::String name1; //char[16];
- Common::String name2; //char[16];
- //int next; // offset to the next structure in the list (not used)
- SubtitleEntry *subtitle;
-
- // Sound stream
- StreamedSound *soundStream;
-
- SoundEntry() {
- status.status = 0;
- type = kSoundTypeNone;
-
- currentDataPtr = 0;
- soundData = NULL;
-
- blockCount = 0;
- time = 0;
-
- stream = NULL;
-
- field_34 = 0;
- field_38 = 0;
- field_3C = 0;
- field_40 = 0;
- entity = kEntityPlayer;
- field_48 = 0;
- field_4C = 0;
-
- subtitle = NULL;
-
- soundStream = NULL;
- }
-
- ~SoundEntry() {
- // Entries that have been queued would have their streamed disposed automatically
- if (!soundStream)
- SAFE_DELETE(stream);
-
- delete soundStream;
- }
- };
-
- struct SubtitleEntry {
- Common::String filename;
- SoundStatusUnion status;
- SoundEntry *sound;
- SubtitleManager *data;
-
- SubtitleEntry() {
- status.status = 0;
- sound = NULL;
- data = NULL;
- }
-
- ~SubtitleEntry() {
- SAFE_DELETE(data);
- }
- };
-
// Engine
LastExpressEngine *_engine;
@@ -337,6 +130,8 @@ private:
uint32 _data0;
uint32 _data1;
uint32 _data2;
+
+ // TODO: this seems to be a synchronization flag for the sound timer
uint32 _flag;
// Filters
@@ -358,17 +153,11 @@ private:
SoundEntry *getEntry(Common::String name);
SoundEntry *getEntry(SoundType type);
- void setupEntry(SoundEntry *entry, Common::String name, FlagType flag, int a4);
- void setEntryType(SoundEntry *entry, FlagType flag);
- void setEntryStatus(SoundEntry *entry, FlagType flag) const;
- void setInCache(SoundEntry *entry);
+ void setupEntry(SoundEntry *entry, Common::String name, SoundFlag flag, int a4);
+ void setEntryType(SoundEntry *entry, SoundFlag flag);
bool setupCache(SoundEntry *entry);
void removeFromCache(SoundEntry *entry);
void loadSoundData(SoundEntry *entry, Common::String name);
-
- void updateEntry(SoundEntry *entry, uint value) const;
- void updateEntryState(SoundEntry *entry) const;
- void resetEntry(SoundEntry *entry) const;
void removeEntry(SoundEntry *entry);
// Subtitles