AVALANCHE: Messing around with GameDescription.

This commit is contained in:
uruk 2013-06-20 08:32:58 +02:00
parent cf80573799
commit b916ab6f02
3 changed files with 144 additions and 134 deletions

View file

@ -41,7 +41,7 @@ namespace Avalanche {
AvalancheEngine *AvalancheEngine::s_Engine = 0; AvalancheEngine *AvalancheEngine::s_Engine = 0;
AvalancheEngine::AvalancheEngine(OSystem *syst, const ADGameDescription *gd) : Engine(syst), _gameDescription(gd) { AvalancheEngine::AvalancheEngine(OSystem *syst, const AvalancheGameDescription *gd) : Engine(syst), _gameDescription(gd) {
_system = syst; _system = syst;
_console = new AvalancheConsole(this); _console = new AvalancheConsole(this);
_rnd = 0; _rnd = 0;

View file

@ -38,11 +38,13 @@ class RandomSource;
namespace Avalanche { namespace Avalanche {
struct AvalancheGameDescription;
static const int kSavegameVersion = 1; static const int kSavegameVersion = 1;
class AvalancheEngine : public Engine { class AvalancheEngine : public Engine {
public: public:
AvalancheEngine(OSystem *syst, const ADGameDescription *gd); AvalancheEngine(OSystem *syst, const AvalancheGameDescription *gd);
~AvalancheEngine(); ~AvalancheEngine();
OSystem *_system; OSystem *_system;
@ -51,11 +53,11 @@ public:
Common::RandomSource *_rnd; Common::RandomSource *_rnd;
const ADGameDescription *_gameDescription; const AvalancheGameDescription *_gameDescription;
uint32 getFeatures() const; uint32 getFeatures() const;
const char *getGameId() const; const char *getGameId() const;
void initGame(const ADGameDescription *gd); void initGame(const AvalancheGameDescription *gd);
Common::Platform getPlatform() const; Common::Platform getPlatform() const;

View file

@ -34,16 +34,24 @@
namespace Avalanche { namespace Avalanche {
struct AvalancheGameDescription {
ADGameDescription desc;
};
uint32 AvalancheEngine::getFeatures() const { uint32 AvalancheEngine::getFeatures() const {
return _gameDescription->flags; return _gameDescription->desc.flags;
} }
const char *AvalancheEngine::getGameId() const { const char *AvalancheEngine::getGameId() const {
return _gameDescription->gameid; return _gameDescription->desc.gameid;
} }
static const PlainGameDescriptor avalancheGames[] = {
{"avalot", "Lord Avalot d'Argent"},
{0, 0}
};
static const ADGameDescription gameDescriptions[] = { static const ADGameDescription gameDescriptions[] = {
// Avalanche English
{ {
"Avalanche", 0, "Avalanche", 0,
{ {
@ -52,7 +60,7 @@ static const ADGameDescription gameDescriptions[] = {
AD_LISTEND AD_LISTEND
}, },
Common::EN_ANY, Common::EN_ANY,
Common::kPlatformPCEngine, Common::kPlatformDOS,
ADGF_NO_FLAGS, ADGF_NO_FLAGS,
GUIO0() GUIO0()
}, },
@ -62,7 +70,7 @@ static const ADGameDescription gameDescriptions[] = {
class AvalancheMetaEngine : public AdvancedMetaEngine { class AvalancheMetaEngine : public AdvancedMetaEngine {
public: public:
AvalancheMetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), 0) { AvalancheMetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(AvalancheGameDescription), avalancheGames) {
} }
const char *getName() const { const char *getName() const {
@ -76,135 +84,135 @@ public:
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const; bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const;
bool hasFeature(MetaEngineFeature f) const; bool hasFeature(MetaEngineFeature f) const;
int getMaximumSaveSlot() const; /*int getMaximumSaveSlot() const;
SaveStateList listSaves(const char *target) const; SaveStateList listSaves(const char *target) const;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
void removeSaveState(const char *target, int slot) const; void removeSaveState(const char *target, int slot) const;*/
}; };
bool AvalancheMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const { bool AvalancheMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
if (gd) { if (gd) /*{*/
*engine = new AvalancheEngine(syst, (const ADGameDescription *)gd); *engine = new AvalancheEngine(syst, (const AvalancheGameDescription *)gd);
((AvalancheEngine *)*engine)->initGame((const ADGameDescription *)gd); /* ((AvalancheEngine *)*engine)->initGame((const ADGameDescription *)gd);
} }*/
return gd != 0; return gd != 0;
} }
bool AvalancheMetaEngine::hasFeature(MetaEngineFeature f) const { bool AvalancheMetaEngine::hasFeature(MetaEngineFeature f) const {
return return false;
(f == kSupportsListSaves) || /*(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) || (f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) || (f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) || (f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) || (f == kSavesSupportThumbnail) ||
(f == kSavesSupportCreationDate); (f == kSavesSupportCreationDate);*/
} }
int AvalancheMetaEngine::getMaximumSaveSlot() const { return 99; } //int AvalancheMetaEngine::getMaximumSaveSlot() const { return 99; }
//
SaveStateList AvalancheMetaEngine::listSaves(const char *target) const { //SaveStateList AvalancheMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); // Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames; // Common::StringArray filenames;
Common::String pattern = target; // Common::String pattern = target;
pattern += "-??.SAV"; // pattern += "-??.SAV";
//
filenames = saveFileMan->listSavefiles(pattern); // filenames = saveFileMan->listSavefiles(pattern);
sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) // sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
//
SaveStateList saveList; // SaveStateList saveList;
char slot[3]; // char slot[3];
int slotNum = 0; // int slotNum = 0;
for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { // for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
slot[0] = filename->c_str()[filename->size() - 6]; // slot[0] = filename->c_str()[filename->size() - 6];
slot[1] = filename->c_str()[filename->size() - 5]; // slot[1] = filename->c_str()[filename->size() - 5];
slot[2] = '\0'; // slot[2] = '\0';
// Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot // // Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot
slotNum = atoi(slot); // slotNum = atoi(slot);
if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) { // if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
Common::InSaveFile *file = saveFileMan->openForLoading(*filename); // Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
if (file) { // if (file) {
int saveVersion = file->readByte(); // int saveVersion = file->readByte();
//
if (saveVersion != kSavegameVersion) { // if (saveVersion != kSavegameVersion) {
warning("Savegame of incompatible version"); // warning("Savegame of incompatible version");
delete file; // delete file;
continue; // continue;
} // }
//
// read name // // read name
uint16 nameSize = file->readUint16BE(); // uint16 nameSize = file->readUint16BE();
if (nameSize >= 255) { // if (nameSize >= 255) {
delete file; // delete file;
continue; // continue;
} // }
char name[256]; // char name[256];
file->read(name, nameSize); // file->read(name, nameSize);
name[nameSize] = 0; // name[nameSize] = 0;
//
saveList.push_back(SaveStateDescriptor(slotNum, name)); // saveList.push_back(SaveStateDescriptor(slotNum, name));
delete file; // delete file;
} // }
} // }
} // }
//
return saveList; // return saveList;
} //}
//
SaveStateDescriptor AvalancheMetaEngine::querySaveMetaInfos(const char *target, int slot) const { //SaveStateDescriptor AvalancheMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot); // Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName); // Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName);
//
if (file) { // if (file) {
int saveVersion = file->readByte(); // int saveVersion = file->readByte();
//
if (saveVersion != kSavegameVersion) { // if (saveVersion != kSavegameVersion) {
warning("Savegame of incompatible version"); // warning("Savegame of incompatible version");
delete file; // delete file;
return SaveStateDescriptor(); // return SaveStateDescriptor();
} // }
//
uint32 saveNameLength = file->readUint16BE(); // uint32 saveNameLength = file->readUint16BE();
char saveName[256]; // char saveName[256];
file->read(saveName, saveNameLength); // file->read(saveName, saveNameLength);
saveName[saveNameLength] = 0; // saveName[saveNameLength] = 0;
//
SaveStateDescriptor desc(slot, saveName); // SaveStateDescriptor desc(slot, saveName);
//
Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file); // Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
desc.setThumbnail(thumbnail); // desc.setThumbnail(thumbnail);
//
desc.setDeletableFlag(true); // desc.setDeletableFlag(true);
desc.setWriteProtectedFlag(false); // desc.setWriteProtectedFlag(false);
//
uint32 saveDate = file->readUint32BE(); // uint32 saveDate = file->readUint32BE();
uint16 saveTime = file->readUint16BE(); // uint16 saveTime = file->readUint16BE();
//
int day = (saveDate >> 24) & 0xFF; // int day = (saveDate >> 24) & 0xFF;
int month = (saveDate >> 16) & 0xFF; // int month = (saveDate >> 16) & 0xFF;
int year = saveDate & 0xFFFF; // int year = saveDate & 0xFFFF;
//
desc.setSaveDate(year, month, day); // desc.setSaveDate(year, month, day);
//
int hour = (saveTime >> 8) & 0xFF; // int hour = (saveTime >> 8) & 0xFF;
int minutes = saveTime & 0xFF; // int minutes = saveTime & 0xFF;
//
desc.setSaveTime(hour, minutes); // desc.setSaveTime(hour, minutes);
//
// Slot 0 is used for the 'restart game' save in all Avalanche games, thus // // Slot 0 is used for the 'restart game' save in all Avalanche games, thus
// we prevent it from being deleted. // // we prevent it from being deleted.
desc.setDeletableFlag(slot != 0); // desc.setDeletableFlag(slot != 0);
desc.setWriteProtectedFlag(slot == 0); // desc.setWriteProtectedFlag(slot == 0);
//
delete file; // delete file;
return desc; // return desc;
} // }
return SaveStateDescriptor(); // return SaveStateDescriptor();
} //}
//
void AvalancheMetaEngine::removeSaveState(const char *target, int slot) const { //void AvalancheMetaEngine::removeSaveState(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot); // Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
g_system->getSavefileManager()->removeSavefile(fileName); // g_system->getSavefileManager()->removeSavefile(fileName);
} //}
} // End of namespace Avalanche } // End of namespace Avalanche
@ -214,10 +222,10 @@ REGISTER_PLUGIN_DYNAMIC(AVALANCHE, PLUGIN_TYPE_ENGINE, Avalanche::AvalancheMetaE
REGISTER_PLUGIN_STATIC(AVALANCHE, PLUGIN_TYPE_ENGINE, Avalanche::AvalancheMetaEngine); REGISTER_PLUGIN_STATIC(AVALANCHE, PLUGIN_TYPE_ENGINE, Avalanche::AvalancheMetaEngine);
#endif #endif
namespace Avalanche { //namespace Avalanche {
//
void AvalancheEngine::initGame(const ADGameDescription *gd) { //void AvalancheEngine::initGame(const ADGameDescription *gd) {
_platform = gd->platform; // _platform = gd->platform;
} //}
//
} // End of namespace Avalanche //} // End of namespace Avalanche