LASTEXPRESS: Make SoundEntry members private

This commit is contained in:
Littleboy 2011-06-28 23:17:13 -04:00
parent b4ac4988cc
commit 04933a1937
4 changed files with 52 additions and 32 deletions

View File

@ -307,6 +307,13 @@ void SoundEntry::saveLoadWithSerializer(Common::Serializer &s) {
}
}
void SoundEntry::loadStream() {
if (!_soundStream)
_soundStream = new StreamedSound();
_soundStream->load(_stream);
}
//////////////////////////////////////////////////////////////////////////
// SubtitleEntry
//////////////////////////////////////////////////////////////////////////
@ -352,10 +359,10 @@ void SubtitleEntry::setupAndDraw() {
_data->load(getArchive(_filename));
}
if (_data->getMaxTime() > _sound->_time) {
if (_data->getMaxTime() > _sound->getTime()) {
_status.status = kSoundStatus_400;
} else {
_data->setTime((uint16)_sound->_time);
_data->setTime((uint16)_sound->getTime());
if (getSoundQueue()->getSubtitleFlag() & 1)
drawOnScreen();

View File

@ -86,6 +86,7 @@ enum SoundStatus {
kSoundStatus_8000 = 0x8000,
kSoundStatus_20000 = 0x20000,
kSoundStatus_100000 = 0x100000,
kSoundStatus_20000000 = 0x20000000,
kSoundStatus_40000000 = 0x40000000,
kSoundStatusClear0 = 0x10,
@ -127,6 +128,8 @@ public:
void updateState();
void reset();
void loadStream();
// Subtitles
void showSubtitle(Common::String filename);
@ -134,22 +137,34 @@ public:
void saveLoadWithSerializer(Common::Serializer &ser);
// Accessors
void setType(SoundType type) { _type = type; }
SoundType getType() { return _type; }
void setStatus(int status) { _status.status = status; }
void setType(SoundType type) { _type = type; }
void setEntity(EntityIndex entity) { _entity = entity; }
EntityIndex getEntity() { return _entity; }
void setField48(int val) { _field_48 = val; }
SoundStatusUnion getStatus() { return _status; }
SoundType getType() { return _type; }
uint32 getTime() { return _time; }
EntityIndex getEntity() { return _entity; }
uint32 getPriority() { return _priority; }
Common::String getName2() { return _name2; }
// Streams
Common::SeekableReadStream *getStream() { return _stream; }
StreamedSound *getStreamedSound() { return _soundStream; }
public:
// TODO replace by on-the-fly allocated buffer
void *_soundData;
private:
LastExpressEngine *_engine;
public:
SoundStatusUnion _status;
SoundType _type; // int
//int _data;
//int _endOffset;
int _currentDataPtr;
void *_soundData;
//int _currentBufferPtr;
int _blockCount;
uint32 _time;

View File

@ -76,15 +76,13 @@ void SoundQueue::handleTimer() {
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
SoundEntry *entry = (*i);
if (entry->_stream == NULL) {
if (entry->getStream() == NULL) {
SAFE_DELETE(*i);
i = _soundList.reverse_erase(i);
continue;
} else if (!entry->_soundStream) {
entry->_soundStream = new StreamedSound();
} else if (!entry->getStreamedSound()) {
// TODO: stream any sound in the queue after filtering
entry->_soundStream->load(entry->_stream);
entry->loadStream();
}
}
}
@ -180,7 +178,7 @@ void SoundQueue::clearStatus() {
Common::StackLock locker(_mutex);
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
(*i)->_status.status |= kSoundStatusClear3;
(*i)->setStatus((*i)->getStatus().status | kSoundStatusClear3);
}
//////////////////////////////////////////////////////////////////////////
@ -243,7 +241,7 @@ SoundEntry *SoundQueue::getEntry(Common::String name) {
name += ".SND";
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
if ((*i)->_name2 == name)
if ((*i)->getName2() == name)
return *i;
}
@ -264,7 +262,7 @@ uint32 SoundQueue::getEntryTime(EntityIndex index) {
SoundEntry *entry = getEntry(index);
if (entry)
return entry->_time;
return entry->getTime();
return 0;
}
@ -298,16 +296,16 @@ void SoundQueue::updateSubtitles() {
for (Common::List<SubtitleEntry *>::iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
uint32 current_index = 0;
SoundEntry *soundEntry = (*i)->getSoundEntry();
SoundStatus status = (SoundStatus)soundEntry->_status.status;
SoundStatus status = (SoundStatus)soundEntry->getStatus().status;
if (!(status & kSoundStatus_40)
|| status & kSoundStatus_180
|| soundEntry->_time == 0
|| soundEntry->getTime() == 0
|| (status & kSoundStatusClear1) < 6
|| ((getFlags()->nis & 0x8000) && soundEntry->_priority < 90)) {
|| ((getFlags()->nis & 0x8000) && soundEntry->getPriority() < 90)) {
current_index = 0;
} else {
current_index = soundEntry->_priority + (status & kSoundStatusClear1);
current_index = soundEntry->getPriority() + (status & kSoundStatusClear1);
if (_currentSubtitle == (*i))
current_index += 4;
@ -348,8 +346,8 @@ bool SoundQueue::setupCache(SoundEntry *entry) {
uint32 size = 1000;
for (Common::List<SoundEntry *>::iterator i = _soundCache.begin(); i != _soundCache.end(); ++i) {
if (!((*i)->_status.status & kSoundStatus_180)) {
uint32 newSize = (*i)->_priority + ((*i)->_status.status & kSoundStatusClear1);
if (!((*i)->getStatus().status & kSoundStatus_180)) {
uint32 newSize = (*i)->getPriority() + ((*i)->getStatus().status & kSoundStatusClear1);
if (newSize < size) {
cacheEntry = (*i);
@ -358,7 +356,7 @@ bool SoundQueue::setupCache(SoundEntry *entry) {
}
}
if (entry->_priority <= size)
if (entry->getPriority() <= size)
return false;
if (!cacheEntry)
@ -367,7 +365,7 @@ bool SoundQueue::setupCache(SoundEntry *entry) {
cacheEntry->setInCache();
// TODO: Wait until the cache entry is ready to be removed
while (!(cacheEntry->_status.status1 & 1))
while (!(cacheEntry->getStatus().status1 & 1))
;
if (cacheEntry->_soundData)
@ -427,7 +425,7 @@ uint32 SoundQueue::count() {
uint32 numEntries = 0;
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
if ((*i)->_name2.matchString("NISSND?"))
if ((*i)->getName2().matchString("NISSND?"))
++numEntries;
return numEntries;
@ -749,9 +747,9 @@ static void soundFilter(byte *data, int16 *buffer, int p1, int p2);
void SoundQueue::applyFilter(SoundEntry *entry, int16 *buffer) {
if ((((byte *)entry->_soundData)[1] << 6) > 0x1600) {
entry->_status.status |= 0x20000000;
entry->setStatus(entry->getStatus().status | kSoundStatus_20000000);
} else {
int variant = entry->_status.status & 0x1f;
int variant = entry->getStatus().status & 0x1f;
soundFilter((byte *)entry->_soundData, buffer, p1s[variant], p2s[variant]);
}
@ -789,7 +787,7 @@ void SoundQueue::stopAllSound() {
Common::StackLock locker(_mutex);
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
(*i)->_soundStream->stop();
(*i)->getStreamedSound()->stop();
}
} // End of namespace LastExpress

View File

@ -155,11 +155,11 @@ bool SoundManager::playSoundWithSubtitles(Common::String filename, SoundFlag fla
SoundEntry *entry = new SoundEntry(_engine);
entry->open(filename, flag, 30);
entry->_entity = entity;
entry->setEntity(entity);
if (a4) {
entry->_field_48 = _data2 + 2 * a4;
entry->_status.status |= kSoundStatus_8000;
entry->setField48(_data2 + 2 * a4);
entry->setStatus(entry->getStatus().status | kSoundStatus_8000);
} else {
// Get subtitles name
while (filename.size() > 4)
@ -1359,7 +1359,7 @@ void SoundManager::playLoopingSound(int param) {
if (getFlags()->flag_3)
fnameLen = 5;
if (!entry || scumm_strnicmp(entry->_name2.c_str(), tmp, fnameLen)) {
if (!entry || scumm_strnicmp(entry->getName2().c_str(), tmp, fnameLen)) {
_loopingSoundDuration = _engine->getRandom().getRandomNumber(319) + 260;
if (partNumber != 99) {