2011-06-24 10:56:49 -04:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lastexpress/sound/entry.h"
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
#include "lastexpress/game/logic.h"
|
|
|
|
#include "lastexpress/game/savepoint.h"
|
|
|
|
#include "lastexpress/game/state.h"
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
#include "lastexpress/sound/queue.h"
|
2011-06-28 22:30:24 -04:00
|
|
|
#include "lastexpress/sound/sound.h"
|
2011-06-28 22:10:29 -04:00
|
|
|
|
2011-06-24 11:43:10 -04:00
|
|
|
#include "lastexpress/graphics.h"
|
2011-06-24 10:56:49 -04:00
|
|
|
#include "lastexpress/helpers.h"
|
|
|
|
#include "lastexpress/lastexpress.h"
|
2011-06-24 11:43:10 -04:00
|
|
|
#include "lastexpress/resource.h"
|
2011-06-24 10:56:49 -04:00
|
|
|
|
|
|
|
#include "common/stream.h"
|
|
|
|
|
|
|
|
namespace LastExpress {
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SoundEntry
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
SoundEntry::SoundEntry(LastExpressEngine *engine) : _engine(engine) {
|
2011-06-28 20:09:56 -04:00
|
|
|
_type = kSoundTypeNone;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_currentDataPtr = 0;
|
|
|
|
_soundData = NULL;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_blockCount = 0;
|
|
|
|
_time = 0;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_stream = NULL;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_field_34 = 0;
|
|
|
|
_field_38 = 0;
|
|
|
|
_field_3C = 0;
|
|
|
|
_field_40 = 0;
|
|
|
|
_entity = kEntityPlayer;
|
|
|
|
_field_48 = 0;
|
|
|
|
_priority = 0;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_subtitle = NULL;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_soundStream = NULL;
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundEntry::~SoundEntry() {
|
|
|
|
// Entries that have been queued would have their streamed disposed automatically
|
2011-06-28 20:09:56 -04:00
|
|
|
if (!_soundStream)
|
|
|
|
SAFE_DELETE(_stream);
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
delete _soundStream;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
// Zero passed pointers
|
2011-06-24 10:56:49 -04:00
|
|
|
_engine = NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
void SoundEntry::open(Common::String name, SoundFlag flag, int priority) {
|
|
|
|
_priority = priority;
|
|
|
|
setType(flag);
|
|
|
|
setStatus(flag);
|
|
|
|
|
|
|
|
// Add entry to sound list
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->addToQueue(this);
|
2011-06-28 20:09:56 -04:00
|
|
|
|
|
|
|
// Add entry to cache and load sound data
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->setupCache(this);
|
2011-06-28 20:09:56 -04:00
|
|
|
loadSoundData(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::close() {
|
|
|
|
_status.status |= kSoundStatusRemoved;
|
|
|
|
|
|
|
|
// Loop until ready
|
2011-06-28 22:10:29 -04:00
|
|
|
while (!(_status.status1 & 4) && !(getSoundQueue()->getFlag() & 8) && (getSoundQueue()->getFlag() & 1))
|
2011-06-28 20:09:56 -04:00
|
|
|
; // empty loop body
|
|
|
|
|
|
|
|
// The original game remove the entry from the cache here,
|
|
|
|
// but since we are called from within an iterator loop
|
|
|
|
// we will remove the entry there
|
|
|
|
// removeFromCache(entry);
|
|
|
|
|
|
|
|
if (_subtitle) {
|
|
|
|
_subtitle->draw();
|
|
|
|
SAFE_DELETE(_subtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_entity) {
|
|
|
|
if (_entity == kEntitySteam)
|
|
|
|
getSound()->playLoopingSound(2);
|
|
|
|
else if (_entity != kEntityTrain)
|
|
|
|
getSavePoints()->push(kEntityPlayer, _entity, kActionEndSound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::setType(SoundFlag flag) {
|
|
|
|
switch (flag & kFlagType9) {
|
|
|
|
default:
|
|
|
|
case kFlagNone:
|
2011-06-28 22:10:29 -04:00
|
|
|
_type = getSoundQueue()->getCurrentType();
|
|
|
|
getSoundQueue()->setCurrentType((SoundType)(_type + 1));
|
2011-06-28 20:09:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kFlagType1_2: {
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous2 = getSoundQueue()->getEntry(kSoundType2);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous2)
|
|
|
|
previous2->update(0);
|
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous = getSoundQueue()->getEntry(kSoundType1);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous) {
|
|
|
|
previous->setType(kSoundType2);
|
|
|
|
previous->update(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
_type = kSoundType1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFlagType3: {
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous = getSoundQueue()->getEntry(kSoundType3);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous) {
|
|
|
|
previous->setType(kSoundType4);
|
|
|
|
previous->update(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
_type = kSoundType11;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFlagType7: {
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous = getSoundQueue()->getEntry(kSoundType7);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous)
|
|
|
|
previous->setType(kSoundType8);
|
|
|
|
|
|
|
|
_type = kSoundType7;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFlagType9: {
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous = getSoundQueue()->getEntry(kSoundType9);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous)
|
|
|
|
previous->setType(kSoundType10);
|
|
|
|
|
|
|
|
_type = kSoundType9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFlagType11: {
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous = getSoundQueue()->getEntry(kSoundType11);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous)
|
|
|
|
previous->setType(kSoundType14);
|
|
|
|
|
|
|
|
_type = kSoundType11;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFlagType13: {
|
2011-06-28 22:10:29 -04:00
|
|
|
SoundEntry *previous = getSoundQueue()->getEntry(kSoundType13);
|
2011-06-28 20:09:56 -04:00
|
|
|
if (previous)
|
|
|
|
previous->setType(kSoundType14);
|
|
|
|
|
|
|
|
_type = kSoundType13;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:56:49 -04:00
|
|
|
void SoundEntry::setStatus(SoundFlag flag) {
|
|
|
|
SoundStatus statusFlag = (SoundStatus)flag;
|
|
|
|
if (!((statusFlag & 0xFF) & kSoundStatusClear1))
|
|
|
|
statusFlag = (SoundStatus)(statusFlag | kSoundStatusClear2);
|
|
|
|
|
|
|
|
if (((statusFlag & 0xFF00) >> 8) & kSoundStatusClear0)
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status = (uint32)statusFlag;
|
2011-06-24 10:56:49 -04:00
|
|
|
else
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status = (statusFlag | kSoundStatusClear4);
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::setInCache() {
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status |= kSoundStatusClear2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::loadSoundData(Common::String name) {
|
|
|
|
_name2 = name;
|
|
|
|
|
|
|
|
// Load sound data
|
|
|
|
_stream = getArchive(name);
|
|
|
|
|
|
|
|
if (!_stream)
|
|
|
|
_stream = getArchive("DEFAULT.SND");
|
|
|
|
|
|
|
|
if (_stream) {
|
2011-06-28 22:54:51 -04:00
|
|
|
warning("[Sound::loadSoundData] Not implemented");
|
2011-06-28 20:09:56 -04:00
|
|
|
} else {
|
|
|
|
_status.status = kSoundStatusRemoved;
|
|
|
|
}
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::update(uint val) {
|
2011-06-28 20:09:56 -04:00
|
|
|
if (!(_status.status3 & 64)) {
|
2011-06-24 10:56:49 -04:00
|
|
|
int value2 = val;
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status |= kSoundStatus_100000;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
|
|
|
if (val) {
|
2011-06-28 22:10:29 -04:00
|
|
|
if (getSoundQueue()->getFlag() & 32) {
|
2011-06-28 20:09:56 -04:00
|
|
|
_field_40 = val;
|
2011-06-24 10:56:49 -04:00
|
|
|
value2 = val * 2 + 1;
|
|
|
|
}
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_field_3C = value2;
|
2011-06-24 10:56:49 -04:00
|
|
|
} else {
|
2011-06-28 20:09:56 -04:00
|
|
|
_field_3C = 0;
|
|
|
|
_status.status |= kSoundStatus_40000000;
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::updateState() {
|
2011-06-28 22:10:29 -04:00
|
|
|
if (getSoundQueue()->getFlag() & 32) {
|
2011-06-28 20:09:56 -04:00
|
|
|
if (_type != kSoundType9 && _type != kSoundType7 && _type != kSoundType5) {
|
|
|
|
uint32 newStatus = _status.status & kSoundStatusClear1;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status &= kSoundStatusClearAll;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_field_40 = newStatus;
|
|
|
|
_status.status |= newStatus * 2 + 1;
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status |= kSoundStatus_20;
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::reset() {
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status |= kSoundStatusRemoved;
|
|
|
|
_entity = kEntityPlayer;
|
2011-06-24 10:56:49 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
if (_stream) {
|
|
|
|
if (!_soundStream) {
|
|
|
|
SAFE_DELETE(_stream);
|
2011-06-24 10:56:49 -04:00
|
|
|
} else {
|
2011-06-28 20:09:56 -04:00
|
|
|
_soundStream->stop();
|
|
|
|
SAFE_DELETE(_soundStream);
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
_stream = NULL;
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 11:43:10 -04:00
|
|
|
void SoundEntry::showSubtitle(Common::String filename) {
|
2011-06-28 20:09:56 -04:00
|
|
|
_subtitle = new SubtitleEntry(_engine);
|
|
|
|
_subtitle->load(filename, this);
|
2011-06-24 11:43:10 -04:00
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
if (_subtitle->getStatus().status2 & 4) {
|
|
|
|
_subtitle->draw();
|
|
|
|
SAFE_DELETE(_subtitle);
|
2011-06-24 11:43:10 -04:00
|
|
|
} else {
|
2011-06-28 20:09:56 -04:00
|
|
|
_status.status |= kSoundStatus_20000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundEntry::saveLoadWithSerializer(Common::Serializer &s) {
|
|
|
|
if (_name2.matchString("NISSND?") && (_status.status & kFlagType7) != kFlag3) {
|
|
|
|
s.syncAsUint32LE(_status.status);
|
|
|
|
s.syncAsUint32LE(_type);
|
|
|
|
s.syncAsUint32LE(_blockCount); // field_8;
|
|
|
|
s.syncAsUint32LE(_time);
|
|
|
|
s.syncAsUint32LE(_field_34); // field_10;
|
|
|
|
s.syncAsUint32LE(_field_38); // field_14;
|
|
|
|
s.syncAsUint32LE(_entity);
|
|
|
|
|
|
|
|
uint32 delta = (uint32)_field_48 - getSound()->getData2();
|
|
|
|
if (delta > kFlag8)
|
|
|
|
delta = 0;
|
|
|
|
s.syncAsUint32LE(delta);
|
|
|
|
|
|
|
|
s.syncAsUint32LE(_priority);
|
|
|
|
|
|
|
|
char name1[16];
|
|
|
|
strcpy((char *)&name1, _name1.c_str());
|
|
|
|
s.syncBytes((byte *)&name1, 16);
|
|
|
|
|
|
|
|
char name2[16];
|
|
|
|
strcpy((char *)&name2, _name2.c_str());
|
|
|
|
s.syncBytes((byte *)&name2, 16);
|
2011-06-24 11:43:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:56:49 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SubtitleEntry
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2011-06-24 11:43:10 -04:00
|
|
|
SubtitleEntry::SubtitleEntry(LastExpressEngine *engine) : _engine(engine) {
|
|
|
|
_sound = NULL;
|
|
|
|
_data = NULL;
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SubtitleEntry::~SubtitleEntry() {
|
2011-06-24 11:43:10 -04:00
|
|
|
SAFE_DELETE(_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleEntry::load(Common::String filename, SoundEntry *soundEntry) {
|
|
|
|
// Add ourselves to the list of active subtitles
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->addSubtitle(this);
|
2011-06-24 11:43:10 -04:00
|
|
|
|
|
|
|
// Set sound entry and filename
|
|
|
|
_filename = filename + ".SBE";
|
|
|
|
_sound = soundEntry;
|
|
|
|
|
|
|
|
// Load subtitle data
|
|
|
|
if (_engine->getResourceManager()->hasFile(filename)) {
|
2011-06-28 22:10:29 -04:00
|
|
|
if (getSoundQueue()->getSubtitleFlag() & 2)
|
2011-06-24 11:43:10 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
loadData();
|
|
|
|
} else {
|
|
|
|
_status.status = kSoundStatus_400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleEntry::loadData() {
|
|
|
|
_data = new SubtitleManager(_engine->getFont());
|
|
|
|
_data->load(getArchive(_filename));
|
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->setSubtitleFlag(getSoundQueue()->getSubtitleFlag() | 2);
|
|
|
|
getSoundQueue()->setCurrentSubtitle(this);
|
2011-06-24 11:43:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleEntry::setupAndDraw() {
|
|
|
|
if (!_data) {
|
|
|
|
_data = new SubtitleManager(_engine->getFont());
|
|
|
|
_data->load(getArchive(_filename));
|
|
|
|
}
|
|
|
|
|
2011-06-28 20:09:56 -04:00
|
|
|
if (_data->getMaxTime() > _sound->_time) {
|
2011-06-24 11:43:10 -04:00
|
|
|
_status.status = kSoundStatus_400;
|
|
|
|
} else {
|
2011-06-28 20:09:56 -04:00
|
|
|
_data->setTime((uint16)_sound->_time);
|
2011-06-24 11:43:10 -04:00
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
if (getSoundQueue()->getSubtitleFlag() & 1)
|
2011-06-24 11:43:10 -04:00
|
|
|
drawOnScreen();
|
|
|
|
}
|
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->setCurrentSubtitle(this);
|
2011-06-24 11:43:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleEntry::draw() {
|
|
|
|
// Remove ourselves from the queue
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->removeSubtitle(this);
|
2011-06-24 11:43:10 -04:00
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
if (this == getSoundQueue()->getCurrentSubtitle()) {
|
2011-06-24 11:43:10 -04:00
|
|
|
drawOnScreen();
|
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->setCurrentSubtitle(NULL);
|
|
|
|
getSoundQueue()->setSubtitleFlag(0);
|
2011-06-24 11:43:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleEntry::drawOnScreen() {
|
2011-06-28 22:10:29 -04:00
|
|
|
getSoundQueue()->setSubtitleFlag(getSoundQueue()->getSubtitleFlag() & -1);
|
2011-06-24 11:43:10 -04:00
|
|
|
|
|
|
|
if (_data == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-06-28 22:10:29 -04:00
|
|
|
if (getSoundQueue()->getSubtitleFlag() & 1)
|
2011-06-24 11:43:10 -04:00
|
|
|
_engine->getGraphicsManager()->draw(_data, GraphicsManager::kBackgroundOverlay);
|
2011-06-24 10:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace LastExpress
|