diff options
author | Vladimir Menshakov | 2009-10-18 12:13:58 +0000 |
---|---|---|
committer | Vladimir Menshakov | 2009-10-18 12:13:58 +0000 |
commit | 343bd3fb4d0eef928fe06c6cbc488e84d7a4185b (patch) | |
tree | f237f3e8e4260c04b6d60e714ea7aecdd3c9d676 /engines | |
parent | 783198941e25459c113945a0e39dc4d6775eb79d (diff) | |
download | scummvm-rg350-343bd3fb4d0eef928fe06c6cbc488e84d7a4185b.tar.gz scummvm-rg350-343bd3fb4d0eef928fe06c6cbc488e84d7a4185b.tar.bz2 scummvm-rg350-343bd3fb4d0eef928fe06c6cbc488e84d7a4185b.zip |
added thumbnails for the save states. removed snprintf's.
svn-id: r45219
Diffstat (limited to 'engines')
-rw-r--r-- | engines/teenagent/detection.cpp | 57 | ||||
-rw-r--r-- | engines/teenagent/scene.cpp | 2 | ||||
-rw-r--r-- | engines/teenagent/teenagent.cpp | 16 |
3 files changed, 54 insertions, 21 deletions
diff --git a/engines/teenagent/detection.cpp b/engines/teenagent/detection.cpp index 2d3937cd54..3a42370c39 100644 --- a/engines/teenagent/detection.cpp +++ b/engines/teenagent/detection.cpp @@ -24,11 +24,13 @@ #include "common/system.h" #include "common/savefile.h" +#include "common/algorithm.h" #include "base/plugins.h" #include "engines/advancedDetector.h" #include "teenagent/teenagent.h" +#include "graphics/thumbnail.h" static const PlainGameDescriptor teenAgentGames[] = { { "teenagent", "Teen Agent" }, @@ -91,7 +93,8 @@ public: case kSupportsListSaves: case kSupportsDeleteSave: case kSupportsLoadingDuringStartup: - //case kSavesSupportThumbnail: + case kSavesSupportMetaInfo: + case kSavesSupportThumbnail: return true; default: return false; @@ -110,9 +113,7 @@ public: // } static Common::String generateGameStateFileName(const char *target, int slot) { - char slotStr[16]; - snprintf(slotStr, sizeof(slotStr), ".%d", slot); - return slotStr; + return Common::String::printf("%s.%02d", target, slot); } virtual SaveStateList listSaves(const char *target) const { @@ -120,8 +121,8 @@ public: pattern += ".*"; Common::StringList filenames = g_system->getSavefileManager()->listSavefiles(pattern); - bool slotsTable[MAX_SAVES]; - memset(slotsTable, 0, sizeof(slotsTable)); + Common::sort(filenames.begin(), filenames.end()); + SaveStateList saveList; for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { int slot; @@ -129,18 +130,17 @@ public: if (ext && (slot = atoi(ext + 1)) >= 0 && slot < MAX_SAVES) { Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); if (in) { - slotsTable[slot] = true; + char buf[25]; + in->seek(0); + in->read(buf, 24); + buf[24] = 0; + Common::String description = buf; + saveList.push_back(SaveStateDescriptor(slot, description)); + delete in; } } } - for (int slot = 0; slot < MAX_SAVES; ++slot) { - if (slotsTable[slot]) { - char description[64]; - snprintf(description, sizeof(description), "teenagent.%02d", slot); - saveList.push_back(SaveStateDescriptor(slot, description)); - } - } return saveList; } @@ -152,6 +152,35 @@ public: Common::String filename = generateGameStateFileName(target, slot); g_system->getSavefileManager()->removeSavefile(filename); } + + virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const { + Common::String filename = generateGameStateFileName(target, slot); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename); + if (in == NULL) + return SaveStateDescriptor(); + + char buf[25]; + in->seek(0); + in->read(buf, 24); + buf[24] = 0; + + Common::String desc = buf; + + in->seek(0x777a); + if (!Graphics::checkThumbnailHeader(*in)) + return SaveStateDescriptor(slot, desc); + + Graphics::Surface *thumb = new Graphics::Surface; + if (!Graphics::loadThumbnail(*in, *thumb)) { + delete thumb; + return SaveStateDescriptor(slot, desc); + } + + SaveStateDescriptor ssd(slot, desc); + ssd.setThumbnail(thumb); + + return ssd; + } }; #if PLUGIN_ENABLED_DYNAMIC(TEENAGENT) diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp index 1b92176929..b96bb603f0 100644 --- a/engines/teenagent/scene.cpp +++ b/engines/teenagent/scene.cpp @@ -86,7 +86,7 @@ void Scene::moveTo(const Common::Point &_point, byte orient, bool validate) { destination = point; orientation = orient; position0 = position; - progress_total = 1 + (int)(sqrt((float)position.sqrDist(destination)) / 10); + progress_total = 1 + (int)(0.5f + sqrt((float)position.sqrDist(destination)) / 10); progress = 0; } diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp index a1176e04ef..b8a4c059ed 100644 --- a/engines/teenagent/teenagent.cpp +++ b/engines/teenagent/teenagent.cpp @@ -33,6 +33,7 @@ #include "teenagent/scene.h" #include "teenagent/objects.h" #include "teenagent/music.h" +#include "graphics/thumbnail.h" namespace TeenAgent { @@ -162,9 +163,10 @@ void TeenAgentEngine::deinit() { Common::Error TeenAgentEngine::loadGameState(int slot) { debug(0, "loading from slot %d", slot); - char slotStr[16]; - snprintf(slotStr, sizeof(slotStr), "teenagent.%d", slot); - Common::InSaveFile *in = _saveFileMan->openForLoading(slotStr); + Common::InSaveFile *in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot)); + if (in == NULL) + in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot)); + if (in == NULL) return Common::kReadPermissionDenied; @@ -172,6 +174,7 @@ Common::Error TeenAgentEngine::loadGameState(int slot) { assert(res->dseg.size() >= 0x6478 + 0x777a); char data[0x777a]; + in->seek(0); if (in->read(data, 0x777a) != 0x777a) { delete in; return Common::kReadingFailed; @@ -193,9 +196,7 @@ Common::Error TeenAgentEngine::loadGameState(int slot) { Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) { debug(0, "saving to slot %d", slot); - char slotStr[16]; - snprintf(slotStr, sizeof(slotStr), "teenagent.%d", slot); - Common::OutSaveFile *out = _saveFileMan->openForSaving(slotStr); + Common::OutSaveFile *out = _saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot)); if (out == NULL) return Common::kWritePermissionDenied; @@ -208,7 +209,10 @@ Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) { assert(res->dseg.size() >= 0x6478 + 0x777a); strncpy((char *)res->dseg.ptr(0x6478), desc, 0x16); out->write(res->dseg.ptr(0x6478), 0x777a); + if (!Graphics::saveThumbnail(*out)) + warning("saveThumbnail failed"); delete out; + return Common::kNoError; } |