diff options
| author | Matthew Hoops | 2011-08-26 22:44:17 -0400 |
|---|---|---|
| committer | Matthew Hoops | 2011-08-26 22:44:17 -0400 |
| commit | 4a69dc13d92e82fff85dc5a3a923b74ced259ffa (patch) | |
| tree | 8945cd3745fd65f28b043caf7b1beddbbce2b2a1 /engines/drascula | |
| parent | ad293b249e74dd1cfbdbd721d02145efbdaf9eca (diff) | |
| parent | 5e174cbfe466dbbe8e5470b0a00de1481b986181 (diff) | |
| download | scummvm-rg350-4a69dc13d92e82fff85dc5a3a923b74ced259ffa.tar.gz scummvm-rg350-4a69dc13d92e82fff85dc5a3a923b74ced259ffa.tar.bz2 scummvm-rg350-4a69dc13d92e82fff85dc5a3a923b74ced259ffa.zip | |
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'engines/drascula')
| -rw-r--r-- | engines/drascula/drascula.h | 8 | ||||
| -rw-r--r-- | engines/drascula/resource.cpp | 9 | ||||
| -rw-r--r-- | engines/drascula/saveload.cpp | 109 |
3 files changed, 68 insertions, 58 deletions
diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h index 2b6aa0f291..6f98c50fdc 100644 --- a/engines/drascula/drascula.h +++ b/engines/drascula/drascula.h @@ -30,6 +30,7 @@ #include "common/file.h" #include "common/hash-str.h" #include "common/keyboard.h" +#include "common/ptr.h" #include "common/random.h" #include "common/savefile.h" #include "common/system.h" @@ -264,15 +265,13 @@ private: }; class TextResourceParser { - Common::SeekableReadStream *_stream; - DisposeAfterUse::Flag _dispose; + Common::DisposablePtr<Common::SeekableReadStream> _stream; int _maxLen; void getLine(char *buf); public: TextResourceParser(Common::SeekableReadStream *stream, DisposeAfterUse::Flag dispose); - ~TextResourceParser(); void parseInt(int &result); void parseString(char *result); @@ -496,6 +495,8 @@ public: void updateVolume(Audio::Mixer::SoundType soundType, int prevVolume); void volumeControls(); bool saveLoadScreen(); + void loadSaveNames(); + void saveSaveNames(); void print_abc(const char *, int, int); void delay(int ms); bool confirmExit(); @@ -776,6 +777,7 @@ private: RoomUpdate *_roomPreUpdates, *_roomUpdates; RoomTalkAction *_roomActions; TalkSequenceCommand *_talkSequences; + char _saveNames[10][23]; char **loadTexts(Common::File &in); void freeTexts(char **ptr); diff --git a/engines/drascula/resource.cpp b/engines/drascula/resource.cpp index 6da43e7cba..95a95e3487 100644 --- a/engines/drascula/resource.cpp +++ b/engines/drascula/resource.cpp @@ -42,7 +42,7 @@ Common::SeekableReadStream *ArchiveMan::open(const Common::String &filename) { } TextResourceParser::TextResourceParser(Common::SeekableReadStream *stream, DisposeAfterUse::Flag dispose) : - _stream(stream), _dispose(dispose) { + _stream(stream, dispose) { // NOTE: strangely enough, the code before this refactoring used the size of // the stream as a fixed maximum length for the parser. Using an updated @@ -50,12 +50,6 @@ TextResourceParser::TextResourceParser(Common::SeekableReadStream *stream, Dispo _maxLen = _stream->size(); } -TextResourceParser::~TextResourceParser() { - if (_dispose == DisposeAfterUse::YES) { - delete _stream; - } -} - void TextResourceParser::getLine(char *buf) { byte c; char *b; @@ -101,4 +95,3 @@ void TextResourceParser::parseString(char* result) { } // End of namespace Drascula - diff --git a/engines/drascula/saveload.cpp b/engines/drascula/saveload.cpp index 664a082eb4..c8622f3c92 100644 --- a/engines/drascula/saveload.cpp +++ b/engines/drascula/saveload.cpp @@ -26,20 +26,26 @@ namespace Drascula { -bool DrasculaEngine::saveLoadScreen() { - char names[10][23]; - Common::String file; - int n, n2, num_sav = 0, y = 27; +/** + * Loads the save names from the EPA index file. + * + * TODO: We should move the save names in their respective save files and get + * rid of this completely. A good example is the sword1 engine, which also used + * to have an index file for its saves, that has been removed. + * sword1 contains code that converts the old index-based saves into the new + * format without the index file, so we could apply this idea to drascula as + * well. + */ +void DrasculaEngine::loadSaveNames() { Common::InSaveFile *sav; - - clearRoom(); - Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str()); + + // Create and initialize the index file, if it doesn't exist if (!(sav = _saveFileMan->openForLoading(fileEpa))) { Common::OutSaveFile *epa; if (!(epa = _saveFileMan->openForSaving(fileEpa))) error("Can't open %s file", fileEpa.c_str()); - for (n = 0; n < NUM_SAVES; n++) + for (int n = 0; n < NUM_SAVES; n++) epa->writeString("*\n"); epa->finalize(); delete epa; @@ -47,11 +53,47 @@ bool DrasculaEngine::saveLoadScreen() { error("Can't open %s file", fileEpa.c_str()); } } - for (n = 0; n < NUM_SAVES; n++) { - strncpy(names[n], sav->readLine().c_str(), 23); - names[n][22] = '\0'; // make sure the savegame name is 0-terminated + + // Load the index file + for (int n = 0; n < NUM_SAVES; n++) { + strncpy(_saveNames[n], sav->readLine().c_str(), 23); + _saveNames[n][22] = '\0'; // make sure the savegame name is 0-terminated } delete sav; +} + +/** + * Saves the save names into the EPA index file. + * + * TODO: We should move the save names in their respective save files and get + * rid of this completely. A good example is the sword1 engine, which also used + * to have an index file for its saves, that has been removed. + * sword1 contains code that converts the old index-based saves into the new + * format without the index file, so we could apply this idea to drascula as + * well. + */ +void DrasculaEngine::saveSaveNames() { + Common::OutSaveFile *tsav; + Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str()); + + if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { + error("Can't open %s file", fileEpa.c_str()); + } + for (int n = 0; n < NUM_SAVES; n++) { + tsav->writeString(_saveNames[n]); + tsav->writeString("\n"); + } + tsav->finalize(); + delete tsav; +} + +bool DrasculaEngine::saveLoadScreen() { + Common::String file; + int n, n2, num_sav = 0, y = 27; + + clearRoom(); + + loadSaveNames(); loadPic("savescr.alg", bgSurface, HALF_PAL); @@ -66,7 +108,7 @@ bool DrasculaEngine::saveLoadScreen() { y = 27; copyBackground(); for (n = 0; n < NUM_SAVES; n++) { - print_abc(names[n], 116, y); + print_abc(_saveNames[n], 116, y); y = y + 9; } print_abc(select, 117, 15); @@ -79,33 +121,24 @@ bool DrasculaEngine::saveLoadScreen() { delay(50); for (n = 0; n < NUM_SAVES; n++) { if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) { - strcpy(select, names[n]); + strcpy(select, _saveNames[n]); if (strcmp(select, "*")) selectionMade = 1; else { enterName(); - strcpy(names[n], select); + strcpy(_saveNames[n], select); if (selectionMade == 1) { file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); saveGame(file.c_str()); - Common::OutSaveFile *tsav; - if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa.c_str()); - } - for (n = 0; n < NUM_SAVES; n++) { - tsav->writeString(names[n]); - tsav->writeString("\n"); - } - tsav->finalize(); - delete tsav; + saveSaveNames(); } } print_abc(select, 117, 15); y = 27; for (n2 = 0; n2 < NUM_SAVES; n2++) { - print_abc(names[n2], 116, y); + print_abc(_saveNames[n2], 116, y); y = y + 9; } if (selectionMade == 1) { @@ -117,27 +150,18 @@ bool DrasculaEngine::saveLoadScreen() { if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) { enterName(); - strcpy(names[num_sav], select); + strcpy(_saveNames[num_sav], select); print_abc(select, 117, 15); y = 27; for (n2 = 0; n2 < NUM_SAVES; n2++) { - print_abc(names[n2], 116, y); + print_abc(_saveNames[n2], 116, y); y = y + 9; } if (selectionMade == 1) { file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); saveGame(file.c_str()); - Common::OutSaveFile *tsav; - if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa.c_str()); - } - for (n = 0; n < NUM_SAVES; n++) { - tsav->writeString(names[n]); - tsav->writeString("\n"); - } - tsav->finalize(); - delete tsav; + saveSaveNames(); } } @@ -149,16 +173,7 @@ bool DrasculaEngine::saveLoadScreen() { break; } else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) { saveGame(file.c_str()); - Common::OutSaveFile *tsav; - if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa.c_str()); - } - for (n = 0; n < NUM_SAVES; n++) { - tsav->writeString(names[n]); - tsav->writeString("\n"); - } - tsav->finalize(); - delete tsav; + saveSaveNames(); } else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180) break; else if (selectionMade == 0) { |
