diff options
author | Littleboy | 2012-07-14 14:02:44 -0400 |
---|---|---|
committer | Littleboy | 2012-07-14 14:26:00 -0400 |
commit | 0635d99ec74ad431146e14aba4ad07a5f9e7e221 (patch) | |
tree | 8b4958d1c162be31c93b0d700cf56192f264dfed | |
parent | 732a2c80ddde4cf0ffd1b1742f514ae940c5301d (diff) | |
download | scummvm-rg350-0635d99ec74ad431146e14aba4ad07a5f9e7e221.tar.gz scummvm-rg350-0635d99ec74ad431146e14aba4ad07a5f9e7e221.tar.bz2 scummvm-rg350-0635d99ec74ad431146e14aba4ad07a5f9e7e221.zip |
LASTEXPRESS: Cleanup
- Add missing initializer/destructors
- Add some const modifiers
- Remove some unneeded casts
- Use enumeration values in switch constructs
-rw-r--r-- | engines/lastexpress/data/cursor.cpp | 2 | ||||
-rw-r--r-- | engines/lastexpress/data/scene.cpp | 12 | ||||
-rw-r--r-- | engines/lastexpress/data/snd.cpp | 9 | ||||
-rw-r--r-- | engines/lastexpress/data/subtitle.cpp | 2 | ||||
-rw-r--r-- | engines/lastexpress/detection.cpp | 3 | ||||
-rw-r--r-- | engines/lastexpress/fight/fight.cpp | 5 | ||||
-rw-r--r-- | engines/lastexpress/fight/fighter.cpp | 27 | ||||
-rw-r--r-- | engines/lastexpress/fight/fighter.h | 3 | ||||
-rw-r--r-- | engines/lastexpress/game/inventory.cpp | 14 | ||||
-rw-r--r-- | engines/lastexpress/game/inventory.h | 12 | ||||
-rw-r--r-- | engines/lastexpress/lastexpress.cpp | 13 | ||||
-rw-r--r-- | engines/lastexpress/resource.cpp | 5 | ||||
-rw-r--r-- | engines/lastexpress/resource.h | 2 | ||||
-rw-r--r-- | engines/lastexpress/sound/entry.cpp | 19 | ||||
-rw-r--r-- | engines/lastexpress/sound/queue.cpp | 13 | ||||
-rw-r--r-- | engines/lastexpress/sound/sound.cpp | 22 |
16 files changed, 98 insertions, 65 deletions
diff --git a/engines/lastexpress/data/cursor.cpp b/engines/lastexpress/data/cursor.cpp index 205c46f667..d176d963d1 100644 --- a/engines/lastexpress/data/cursor.cpp +++ b/engines/lastexpress/data/cursor.cpp @@ -128,7 +128,7 @@ Common::Rect Icon::draw(Graphics::Surface *surface) { for (int i = 0; i < 32; i++) { // Adjust brightness - if (_brightnessIndex == -1) + if (_brightnessIndex == -1 || _brightnessIndex >= ARRAYSIZE(brigthnessData)) *s = *image; else *s = (*image & brigthnessData[_brightnessIndex]) >> _brightnessIndex; diff --git a/engines/lastexpress/data/scene.cpp b/engines/lastexpress/data/scene.cpp index 79683d8067..fdb1ac6d46 100644 --- a/engines/lastexpress/data/scene.cpp +++ b/engines/lastexpress/data/scene.cpp @@ -121,7 +121,7 @@ bool SceneHotspot::isInside(const Common::Point &point) { // Scene Scene::~Scene() { // Free the hotspots - for (int i = 0; i < (int)_hotspots.size(); i++) + for (uint i = 0; i < _hotspots.size(); i++) delete _hotspots[i]; } @@ -171,7 +171,7 @@ bool Scene::checkHotSpot(const Common::Point &coord, SceneHotspot **hotspot) { bool found = false; int _location = 0; - for (int i = 0; i < (int)_hotspots.size(); i++) { + for (uint i = 0; i < _hotspots.size(); i++) { if (_hotspots[i]->isInside(coord)) { if (_location <= _hotspots[i]->location) { _location = _hotspots[i]->location; @@ -223,7 +223,7 @@ Common::String Scene::toString() { // Hotspots if (_hotspots.size() != 0) { output += "\nHotspots:\n"; - for (int i = 0; i < (int)_hotspots.size(); i++) + for (uint i = 0; i < _hotspots.size(); i++) output += _hotspots[i]->toString() + "\n"; } @@ -240,7 +240,7 @@ SceneLoader::~SceneLoader() { void SceneLoader::clear() { // Remove all scenes - for (int i = 0; i < (int)_scenes.size(); i++) + for (uint i = 0; i < _scenes.size(); i++) delete _scenes[i]; _scenes.clear(); @@ -291,9 +291,9 @@ Scene *SceneLoader::get(SceneIndex index) { return NULL; // Load the hotspots if needed - _scenes[(int)index]->loadHotspots(_stream); + _scenes[(uint)index]->loadHotspots(_stream); - return _scenes[(int)index]; + return _scenes[(uint)index]; } } // End of namespace LastExpress diff --git a/engines/lastexpress/data/snd.cpp b/engines/lastexpress/data/snd.cpp index 5010d6e763..6d64f6b82c 100644 --- a/engines/lastexpress/data/snd.cpp +++ b/engines/lastexpress/data/snd.cpp @@ -356,6 +356,8 @@ public: Audio::ADPCMStream(stream, disposeAfterUse, size, 44100, 1, blockSize) { _currentFilterId = -1; _nextFilterId = filterId; + _stepAdjust1 = 0; + _stepAdjust2 = 0; } int readBuffer(int16 *buffer, const int numSamples) { @@ -453,7 +455,9 @@ void SimpleSound::play(Audio::AudioStream *as) { ////////////////////////////////////////////////////////////////////////// StreamedSound::StreamedSound() : _as(NULL), _loaded(false) {} -StreamedSound::~StreamedSound() {} +StreamedSound::~StreamedSound() { + _as = NULL; +} bool StreamedSound::load(Common::SeekableReadStream *stream, int32 filterId) { if (!stream) @@ -482,6 +486,9 @@ bool StreamedSound::isFinished() { } void StreamedSound::setFilterId(int32 filterId) { + if (_as == NULL) + return; + ((LastExpress_ADPCMStream *)_as)->setFilterId(filterId); } diff --git a/engines/lastexpress/data/subtitle.cpp b/engines/lastexpress/data/subtitle.cpp index 9918cf7689..a9a8284588 100644 --- a/engines/lastexpress/data/subtitle.cpp +++ b/engines/lastexpress/data/subtitle.cpp @@ -150,7 +150,7 @@ SubtitleManager::~SubtitleManager() { } void SubtitleManager::reset() { - for (int i = 0; i < (int)_subtitles.size(); i++) + for (uint i = 0; i < _subtitles.size(); i++) delete _subtitles[i]; _subtitles.clear(); diff --git a/engines/lastexpress/detection.cpp b/engines/lastexpress/detection.cpp index 82a6520522..2fdeef910a 100644 --- a/engines/lastexpress/detection.cpp +++ b/engines/lastexpress/detection.cpp @@ -173,7 +173,7 @@ static const ADGameDescription gameDescriptions[] = { ADGF_UNSTABLE, GUIO1(GUIO_NOASPECT) }, - + // The Last Express (Russian) // expressw.exe 1999-04-05 15:33:56 // express.exe ??? @@ -211,6 +211,7 @@ public: return "LastExpress Engine (C) 1997 Smoking Car Productions"; } +protected: bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const; }; diff --git a/engines/lastexpress/fight/fight.cpp b/engines/lastexpress/fight/fight.cpp index be1653092f..22d9da80be 100644 --- a/engines/lastexpress/fight/fight.cpp +++ b/engines/lastexpress/fight/fight.cpp @@ -52,6 +52,8 @@ Fight::FightData::FightData() { index = 0; isFightRunning = false; + + memset(&sequences, 0, sizeof(sequences)); } Fight::FightData::~FightData() { @@ -398,6 +400,9 @@ end_load: } void Fight::setOpponents() { + if (!_data) + error("[Fight::setOpponents] Data not initialized"); + _data->player->setOpponent(_data->opponent); _data->opponent->setOpponent(_data->player); diff --git a/engines/lastexpress/fight/fighter.cpp b/engines/lastexpress/fight/fighter.cpp index bae7728a2b..4b1cddabd4 100644 --- a/engines/lastexpress/fight/fighter.cpp +++ b/engines/lastexpress/fight/fighter.cpp @@ -53,20 +53,20 @@ Fighter::Fighter(LastExpressEngine *engine) : _engine(engine) { } Fighter::~Fighter() { - clearSequences(); -} - -////////////////////////////////////////////////////////////////////////// -// Cleanup -////////////////////////////////////////////////////////////////////////// -void Fighter::clearSequences() { // The original game resets the function pointers to default values, just before deleting the struct getScenes()->removeAndRedraw(&_frame, false); // Free sequences - for (int i = 0; i < (int)_sequences.size(); i++) + for (uint i = 0; i < _sequences.size(); i++) SAFE_DELETE(_sequences[i]); + + // Zero-out passed pointers + _sequence = NULL; + _opponent = NULL; + _fight = NULL; + + _engine = NULL; } ////////////////////////////////////////////////////////////////////////// @@ -113,6 +113,9 @@ void Fighter::draw() { // Processing ////////////////////////////////////////////////////////////////////////// void Fighter::process() { + if (!_fight) + error("[Fighter::handleAction] Fighter not initialized properly"); + if (!_sequence) { if (_frame) { getScenes()->removeFromQueue(_frame); @@ -188,6 +191,9 @@ void Fighter::process() { // Default actions ////////////////////////////////////////////////////////////////////////// void Fighter::handleAction(FightAction action) { + if (!_opponent || !_fight) + error("[Fighter::handleAction] Fighter not initialized properly"); + switch (action) { default: return; @@ -243,7 +249,10 @@ void Opponent::update() { // Helpers ////////////////////////////////////////////////////////////////////////// bool Fighter::checkFrame(uint32 val) { - return (_frame->getInfo()->field_33 & val); + if (!_frame) + error("[Fighter::checkFrame] Invalid current frame"); + + return (bool)(_frame->getInfo()->field_33 & val); } } // End of namespace LastExpress diff --git a/engines/lastexpress/fight/fighter.h b/engines/lastexpress/fight/fighter.h index e37fe49d86..dad95af186 100644 --- a/engines/lastexpress/fight/fighter.h +++ b/engines/lastexpress/fight/fighter.h @@ -99,9 +99,6 @@ protected: void draw(); void process(); - // Cleanup - void clearSequences(); - // Helpers bool checkFrame(uint32 val); }; diff --git a/engines/lastexpress/game/inventory.cpp b/engines/lastexpress/game/inventory.cpp index 7b803bb1ca..bb382ea38e 100644 --- a/engines/lastexpress/game/inventory.cpp +++ b/engines/lastexpress/game/inventory.cpp @@ -259,7 +259,7 @@ void Inventory::handleMouseEvent(const Common::Event &ev) { // Change item highlight on list if (getFlags()->mouseLeftPressed) { - uint32 index = ev.mouse.y / 40; + uint32 index = (unsigned) (int) ev.mouse.y / 40; if (_highlightedItemIndex && _highlightedItemIndex != index) drawHighlight(_highlightedItemIndex, true); @@ -416,12 +416,12 @@ void Inventory::show() { drawEgg(); } -void Inventory::setPortrait(InventoryItem item) { +void Inventory::setPortrait(InventoryItem item) const { getProgress().portrait = item; drawItem((CursorStyle)getProgress().portrait, 0, 0); } -void Inventory::showHourGlass(){ +void Inventory::showHourGlass() const { if (!getMenu()->isShown()) drawItem(kCursorHourGlass, 608, 448); @@ -611,7 +611,7 @@ void Inventory::examine(InventoryItem item) { } } -void Inventory::drawEgg() { +void Inventory::drawEgg() const { if (!getMenu()->isShown()) drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448, _eggHightlighted ? 0 : 1); @@ -652,7 +652,7 @@ void Inventory::drawBlinkingEgg() { askForRedraw(); } -void Inventory::drawItem(CursorStyle id, uint16 x, uint16 y, int16 brightnessIndex) { +void Inventory::drawItem(CursorStyle id, uint16 x, uint16 y, int16 brightnessIndex) const { Icon icon(id); icon.setPosition(x, y); @@ -676,7 +676,7 @@ void Inventory::drawSelectedItem() { } } -void Inventory::clearSelectedItem() { +void Inventory::clearSelectedItem() const { _engine->getGraphicsManager()->clear(GraphicsManager::kBackgroundInventory, Common::Rect(44, 0, 44 + 32, 32)); } @@ -731,7 +731,7 @@ void Inventory::drawHighlight(uint32 currentIndex, bool reset) { } } -uint32 Inventory::getItemIndex(uint32 currentIndex) { +uint32 Inventory::getItemIndex(uint32 currentIndex) const { uint32 count = 0; for (uint32 i = 1; i < ARRAYSIZE(_entries); i++) { diff --git a/engines/lastexpress/game/inventory.h b/engines/lastexpress/game/inventory.h index b1995adce3..15dd29053d 100644 --- a/engines/lastexpress/game/inventory.h +++ b/engines/lastexpress/game/inventory.h @@ -107,9 +107,9 @@ public: // UI Control void show(); void blinkEgg(bool enabled); - void showHourGlass(); - void setPortrait(InventoryItem item); - void drawEgg(); + void showHourGlass() const; + void setPortrait(InventoryItem item) const; + void drawEgg() const; void drawBlinkingEgg(); // Handle inventory UI events. @@ -168,14 +168,14 @@ private: void close(); void examine(InventoryItem item); void drawHighlight(uint32 currentIndex, bool reset); - uint32 getItemIndex(uint32 currentIndex); + uint32 getItemIndex(uint32 currentIndex) const; bool isItemSceneParameter(InventoryItem item) const; - void drawItem(CursorStyle id, uint16 x, uint16 y, int16 brighnessIndex = -1); + void drawItem(CursorStyle id, uint16 x, uint16 y, int16 brighnessIndex = -1) const; void drawSelectedItem(); - void clearSelectedItem(); + void clearSelectedItem() const; }; } // End of namespace LastExpress diff --git a/engines/lastexpress/lastexpress.cpp b/engines/lastexpress/lastexpress.cpp index cc3795651d..74d1969e01 100644 --- a/engines/lastexpress/lastexpress.cpp +++ b/engines/lastexpress/lastexpress.cpp @@ -52,18 +52,17 @@ const char *g_entityNames[] = { "Player", "Anna", "August", "Mertens", "Coudert" namespace LastExpress { LastExpressEngine::LastExpressEngine(OSystem *syst, const ADGameDescription *gd) : - Engine(syst), _gameDescription(gd), - _debugger(NULL), _cursor(NULL), - _font(NULL), _logic(NULL), _menu(NULL), - _frameCounter(0), _lastFrameCount(0), + Engine(syst), _gameDescription(gd), + _debugger(NULL), _random("lastexpress"), _cursor(NULL), + _font(NULL), _logic(NULL), _menu(NULL), + _frameCounter(0), _lastFrameCount(0), _graphicsMan(NULL), _resMan(NULL), _sceneMan(NULL), _soundMan(NULL), _eventMouse(NULL), _eventTick(NULL), - _eventMouseBackup(NULL), _eventTickBackup(NULL), - _random("lastexpress") + _eventMouseBackup(NULL), _eventTickBackup(NULL) { // Setup mixer - syncSoundSettings(); + Engine::syncSoundSettings(); // Adding the default directories const Common::FSNode gameDataDir(ConfMan.get("path")); diff --git a/engines/lastexpress/resource.cpp b/engines/lastexpress/resource.cpp index bbbd139b97..1d010355ac 100644 --- a/engines/lastexpress/resource.cpp +++ b/engines/lastexpress/resource.cpp @@ -128,13 +128,10 @@ bool ResourceManager::loadArchive(const Common::String &name) { // Get a stream to file in the archive // - same as createReadStreamForMember except it checks if the file exists and will assert / output a debug message if not -Common::SeekableReadStream *ResourceManager::getFileStream(const Common::String &name) { +Common::SeekableReadStream *ResourceManager::getFileStream(const Common::String &name) const { // Check if the file exits in the archive if (!hasFile(name)) { -//#ifdef _DEBUG -// error("[ResourceManager::getFileStream] Cannot open file: %s", name.c_str()); -//#endif debugC(2, kLastExpressDebugResource, "Error opening file: %s", name.c_str()); return NULL; } diff --git a/engines/lastexpress/resource.h b/engines/lastexpress/resource.h index f2f5d63bce..90ac9b87ad 100644 --- a/engines/lastexpress/resource.h +++ b/engines/lastexpress/resource.h @@ -42,7 +42,7 @@ public: // Loading bool loadArchive(ArchiveIndex type); static bool isArchivePresent(ArchiveIndex type); - Common::SeekableReadStream *getFileStream(const Common::String &name); + Common::SeekableReadStream *getFileStream(const Common::String &name) const; // Archive functions bool hasFile(const Common::String &name) const; diff --git a/engines/lastexpress/sound/entry.cpp b/engines/lastexpress/sound/entry.cpp index 85bb8eb479..3d2b05895f 100644 --- a/engines/lastexpress/sound/entry.cpp +++ b/engines/lastexpress/sound/entry.cpp @@ -44,6 +44,8 @@ namespace LastExpress { SoundEntry::SoundEntry(LastExpressEngine *engine) : _engine(engine) { _type = kSoundTypeNone; + _currentDataPtr = NULL; + _blockCount = 0; _time = 0; @@ -68,7 +70,13 @@ SoundEntry::~SoundEntry() { // Entries that have been queued will have their streamed disposed automatically if (!_soundStream) SAFE_DELETE(_stream); - delete _soundStream; + + SAFE_DELETE(_soundStream); + + free(_currentDataPtr); + + _subtitle = NULL; + _stream = NULL; // Zero passed pointers _engine = NULL; @@ -274,7 +282,7 @@ bool SoundEntry::updateSound() { int l = strlen(sub) + 1; if (l - 1 > 4) - sub[l - 1 - 4] = 0; + sub[l - (1 + 4)] = 0; showSubtitle(sub); } } else { @@ -390,6 +398,10 @@ SubtitleEntry::SubtitleEntry(LastExpressEngine *engine) : _engine(engine) { SubtitleEntry::~SubtitleEntry() { SAFE_DELETE(_data); + + // Zero-out passed pointers + _sound = NULL; + _engine = NULL; } void SubtitleEntry::load(Common::String filename, SoundEntry *soundEntry) { @@ -420,6 +432,9 @@ void SubtitleEntry::loadData() { } void SubtitleEntry::setupAndDraw() { + if (!_sound) + error("[SubtitleEntry::setupAndDraw] Sound entry not initialized"); + if (!_data) { _data = new SubtitleManager(_engine->getFont()); _data->load(getArchive(_filename)); diff --git a/engines/lastexpress/sound/queue.cpp b/engines/lastexpress/sound/queue.cpp index cfbb3091a4..5f3ab96d81 100644 --- a/engines/lastexpress/sound/queue.cpp +++ b/engines/lastexpress/sound/queue.cpp @@ -38,6 +38,7 @@ SoundQueue::SoundQueue(LastExpressEngine *engine) : _engine(engine) { _subtitlesFlag = 0; _currentSubtitle = NULL; + _soundCacheData = NULL; } SoundQueue::~SoundQueue() { @@ -50,6 +51,7 @@ SoundQueue::~SoundQueue() { _subtitles.clear(); _currentSubtitle = NULL; + SAFE_DELETE(_soundCacheData); // Zero passed pointers _engine = NULL; @@ -133,7 +135,7 @@ void SoundQueue::updateQueue() { // Original update the current entry, loading another set of samples to be decoded - getFlags()->flag_3 = 0; + getFlags()->flag_3 = false; --_flag; } @@ -339,13 +341,14 @@ void SoundQueue::updateSubtitles() { return; } + if (!subtitle) + return; + if (_subtitlesFlag & 1) subtitle->drawOnScreen(); - if (subtitle) { - subtitle->loadData(); - subtitle->setupAndDraw(); - } + subtitle->loadData(); + subtitle->setupAndDraw(); } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/lastexpress/sound/sound.cpp b/engines/lastexpress/sound/sound.cpp index 17d51fe9f4..4f6a7b8f93 100644 --- a/engines/lastexpress/sound/sound.cpp +++ b/engines/lastexpress/sound/sound.cpp @@ -1329,23 +1329,23 @@ void SoundManager::playLoopingSound(int param) { } } else { switch (getEntityData(kEntityPlayer)->car) { - case 1: - case 6: + case kCarBaggageRear: + case kCarBaggage: partNumber = 4; break; - case 2: - case 3: - case 4: - case 5: + case kCarKronos: + case kCarGreenSleeping: + case kCarRedSleeping: + case kCarRestaurant: partNumber = 1; break; - case 7: + case kCarCoalTender: partNumber = 5; break; - case 8: + case kCarLocomotive: partNumber = 99; break; - case 9: + case kCar9: partNumber = 3; break; default: @@ -1356,13 +1356,13 @@ void SoundManager::playLoopingSound(int param) { } if (partNumber != 99) - sprintf(tmp, "LOOP%d%c.SND", partNumber, _engine->getRandom().getRandomNumber(numLoops[partNumber] - 1) + 'A'); + sprintf(tmp, "LOOP%d%c.SND", partNumber, (char)(_engine->getRandom().getRandomNumber(numLoops[partNumber] - 1) + 'A')); } if (getFlags()->flag_3) fnameLen = 5; - if (!entry || scumm_strnicmp(entry->getName2().c_str(), tmp, fnameLen)) { + if (!entry || scumm_strnicmp(entry->getName2().c_str(), tmp, (uint)fnameLen)) { _loopingSoundDuration = _engine->getRandom().getRandomNumber(319) + 260; if (partNumber != 99) { |