STARTREK: Split detection features & adapt to new plugins.

This commit is contained in:
aryanrawlani28 2020-08-06 23:14:24 +05:30 committed by Eugene Sandulenko
parent af47301cca
commit 65f13a0b26
7 changed files with 282 additions and 184 deletions

2
configure vendored
View File

@ -6166,7 +6166,7 @@ declare -a static_detect_engines=("PLUMBERS" "AGI" "SCUMM" "SKY" "DREAMWEB" "DRA
"GRIFFON" "GROOVIE" "HDB" "HOPKINS" "HUGO" "ILLUSIONS" "KINGDOM"
"KYRA" "LAB" "LASTEXPRESS" "LILLIPUT" "MACVENTURE" "MADE" "MADS"
"MORTEVIELLE" "MUTATIONOFJB" "NEVERHOOD" "PARALLACTION" "PEGASUS"
"PETKA" "PINK" "PRINCE" "SHERLOCK" "SLUDGE")
"PETKA" "PINK" "PRINCE" "SHERLOCK" "SLUDGE" "STARTREK")
detectId="_DETECTION"
echo "Creating engines/plugins_table.h"

View File

@ -24,40 +24,11 @@
#include "engines/advancedDetector.h"
#include "graphics/thumbnail.h"
#include "common/config-manager.h"
#include "common/file.h"
#include "common/savefile.h"
#include "startrek/startrek.h"
namespace StarTrek {
struct StarTrekGameDescription {
ADGameDescription desc;
uint8 gameType;
uint32 features;
};
uint32 StarTrekEngine::getFeatures() const {
return _gameDescription->features;
}
Common::Platform StarTrekEngine::getPlatform() const {
return _gameDescription->desc.platform;
}
uint8 StarTrekEngine::getGameType() const {
return _gameDescription->gameType;
}
Common::Language StarTrekEngine::getLanguage() const {
return _gameDescription->desc.language;
}
} // End of Namespace StarTrek
#include "startrek/detection.h"
#include "startrek/detection_enums.h"
static const PlainGameDescriptor starTrekGames[] = {
{"st25", "Star Trek: 25th Anniversary"},
@ -333,150 +304,8 @@ public:
const char *getOriginalCopyright() const override {
return "Star Trek: 25th Anniversary, Star Trek: Judgment Rites (C) Interplay";
}
bool hasFeature(MetaEngineFeature f) const override;
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
SaveStateList listSaves(const char *target) const override;
int getMaximumSaveSlot() const override;
void removeSaveState(const char *target, int slot) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
};
bool StarTrekMetaEngine::hasFeature(MetaEngineFeature f) const {
return
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
(f == kSavesSupportCreationDate) ||
(f == kSavesSupportPlayTime) ||
(f == kSimpleSavesNames);
}
bool StarTrekMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
const StarTrek::StarTrekGameDescription *gd = (const StarTrek::StarTrekGameDescription *)desc;
*engine = new StarTrek::StarTrekEngine(syst, gd);
return (gd != 0);
}
SaveStateList StarTrekMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String pattern = target;
pattern += ".###";
filenames = saveFileMan->listSavefiles(pattern);
SaveStateList saveList;
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNr = atoi(file->c_str() + file->size() - 3);
if (slotNr >= 0 && slotNr <= getMaximumSaveSlot()) {
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
if (in) {
StarTrek::SavegameMetadata meta;
StarTrek::saveOrLoadMetadata(in, nullptr, &meta);
delete in;
uint16 descriptionPos = 0;
// Security-check, if saveDescription has a terminating NUL
while (meta.description[descriptionPos]) {
descriptionPos++;
if (descriptionPos >= sizeof(meta.description))
break;
}
if (descriptionPos >= sizeof(meta.description)) {
strcpy(meta.description, "[broken saved game]");
}
saveList.push_back(SaveStateDescriptor(slotNr, meta.description));
}
}
}
// Sort saves based on slot number.
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
return saveList;
}
int StarTrekMetaEngine::getMaximumSaveSlot() const {
return 999;
}
void StarTrekMetaEngine::removeSaveState(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s.%03d", target, slot);
g_system->getSavefileManager()->removeSavefile(fileName);
}
SaveStateDescriptor StarTrekMetaEngine::querySaveMetaInfos(const char *target, int slotNr) const {
Common::String fileName = Common::String::format("%s.%03d", target, slotNr);
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fileName);
if (in) {
StarTrek::SavegameMetadata meta;
StarTrek::saveOrLoadMetadata(in, nullptr, &meta);
delete in;
uint16 descriptionPos = 0;
while (meta.description[descriptionPos]) {
descriptionPos++;
if (descriptionPos >= sizeof(meta.description))
break;
}
if (descriptionPos >= sizeof(meta.description)) {
// broken meta.description, ignore it
SaveStateDescriptor descriptor(slotNr, "[broken saved game]");
return descriptor;
}
SaveStateDescriptor descriptor(slotNr, meta.description);
// Do not allow save slot 0 (used for auto-saving) to be deleted or
// overwritten.
if (slotNr == 0) {
descriptor.setWriteProtectedFlag(true);
descriptor.setDeletableFlag(false);
} else {
descriptor.setWriteProtectedFlag(false);
descriptor.setDeletableFlag(true);
}
if (meta.thumbnail == nullptr) {
return SaveStateDescriptor();
}
descriptor.setThumbnail(meta.thumbnail);
descriptor.setPlayTime(meta.playTime);
descriptor.setSaveDate(meta.getYear(), meta.getMonth(), meta.getDay());
descriptor.setSaveTime(meta.getHour(), meta.getMinute());
return descriptor;
} else {
SaveStateDescriptor emptySave;
// Do not allow save slot 0 (used for auto-saving) to be overwritten.
if (slotNr == 0) {
emptySave.setWriteProtectedFlag(true);
} else {
emptySave.setWriteProtectedFlag(false);
}
return emptySave;
}
}
#if PLUGIN_ENABLED_DYNAMIC(STARTREK)
REGISTER_PLUGIN_DYNAMIC(STARTREK, PLUGIN_TYPE_ENGINE, StarTrekMetaEngine);
#else
REGISTER_PLUGIN_STATIC(STARTREK, PLUGIN_TYPE_ENGINE, StarTrekMetaEngine);
#endif
REGISTER_PLUGIN_STATIC(STARTREK_DETECTION, PLUGIN_TYPE_METAENGINE, StarTrekMetaEngine);

View File

@ -0,0 +1,32 @@
/* 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.
*
*/
namespace StarTrek {
struct StarTrekGameDescription {
ADGameDescription desc;
uint8 gameType;
uint32 features;
};
} // End of Namespace StarTrek

View File

@ -0,0 +1,35 @@
/* 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.
*
*/
namespace StarTrek {
enum StarTrekGameType {
GType_ST25 = 1,
GType_STJR = 2
};
enum StarTrekGameFeatures {
GF_DEMO = (1 << 0),
GF_CDROM = (1 << 1)
};
} // End of namespace StarTrek

View File

@ -0,0 +1,206 @@
/* 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 "base/plugins.h"
#include "engines/advancedDetector.h"
#include "graphics/thumbnail.h"
#include "common/config-manager.h"
#include "common/file.h"
#include "common/savefile.h"
#include "startrek/startrek.h"
#include "startrek/detection.h"
namespace StarTrek {
uint32 StarTrekEngine::getFeatures() const {
return _gameDescription->features;
}
Common::Platform StarTrekEngine::getPlatform() const {
return _gameDescription->desc.platform;
}
uint8 StarTrekEngine::getGameType() const {
return _gameDescription->gameType;
}
Common::Language StarTrekEngine::getLanguage() const {
return _gameDescription->desc.language;
}
} // End of Namespace StarTrek
class StarTrekMetaEngineConnect : public AdvancedMetaEngineConnect {
public:
const char *getName() const override {
return "startrek";
}
bool hasFeature(MetaEngineFeature f) const override;
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
SaveStateList listSaves(const char *target) const override;
int getMaximumSaveSlot() const override;
void removeSaveState(const char *target, int slot) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
};
bool StarTrekMetaEngineConnect::hasFeature(MetaEngineFeature f) const {
return
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
(f == kSavesSupportCreationDate) ||
(f == kSavesSupportPlayTime) ||
(f == kSimpleSavesNames);
}
bool StarTrekMetaEngineConnect::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
const StarTrek::StarTrekGameDescription *gd = (const StarTrek::StarTrekGameDescription *)desc;
*engine = new StarTrek::StarTrekEngine(syst, gd);
return (gd != 0);
}
SaveStateList StarTrekMetaEngineConnect::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String pattern = target;
pattern += ".###";
filenames = saveFileMan->listSavefiles(pattern);
SaveStateList saveList;
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNr = atoi(file->c_str() + file->size() - 3);
if (slotNr >= 0 && slotNr <= getMaximumSaveSlot()) {
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
if (in) {
StarTrek::SavegameMetadata meta;
StarTrek::saveOrLoadMetadata(in, nullptr, &meta);
delete in;
uint16 descriptionPos = 0;
// Security-check, if saveDescription has a terminating NUL
while (meta.description[descriptionPos]) {
descriptionPos++;
if (descriptionPos >= sizeof(meta.description))
break;
}
if (descriptionPos >= sizeof(meta.description)) {
strcpy(meta.description, "[broken saved game]");
}
saveList.push_back(SaveStateDescriptor(slotNr, meta.description));
}
}
}
// Sort saves based on slot number.
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
return saveList;
}
int StarTrekMetaEngineConnect::getMaximumSaveSlot() const {
return 999;
}
void StarTrekMetaEngineConnect::removeSaveState(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s.%03d", target, slot);
g_system->getSavefileManager()->removeSavefile(fileName);
}
SaveStateDescriptor StarTrekMetaEngineConnect::querySaveMetaInfos(const char *target, int slotNr) const {
Common::String fileName = Common::String::format("%s.%03d", target, slotNr);
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fileName);
if (in) {
StarTrek::SavegameMetadata meta;
StarTrek::saveOrLoadMetadata(in, nullptr, &meta);
delete in;
uint16 descriptionPos = 0;
while (meta.description[descriptionPos]) {
descriptionPos++;
if (descriptionPos >= sizeof(meta.description))
break;
}
if (descriptionPos >= sizeof(meta.description)) {
// broken meta.description, ignore it
SaveStateDescriptor descriptor(slotNr, "[broken saved game]");
return descriptor;
}
SaveStateDescriptor descriptor(slotNr, meta.description);
// Do not allow save slot 0 (used for auto-saving) to be deleted or
// overwritten.
if (slotNr == 0) {
descriptor.setWriteProtectedFlag(true);
descriptor.setDeletableFlag(false);
} else {
descriptor.setWriteProtectedFlag(false);
descriptor.setDeletableFlag(true);
}
if (meta.thumbnail == nullptr) {
return SaveStateDescriptor();
}
descriptor.setThumbnail(meta.thumbnail);
descriptor.setPlayTime(meta.playTime);
descriptor.setSaveDate(meta.getYear(), meta.getMonth(), meta.getDay());
descriptor.setSaveTime(meta.getHour(), meta.getMinute());
return descriptor;
} else {
SaveStateDescriptor emptySave;
// Do not allow save slot 0 (used for auto-saving) to be overwritten.
if (slotNr == 0) {
emptySave.setWriteProtectedFlag(true);
} else {
emptySave.setWriteProtectedFlag(false);
}
return emptySave;
}
}
#if PLUGIN_ENABLED_DYNAMIC(STARTREK)
REGISTER_PLUGIN_DYNAMIC(STARTREK, PLUGIN_TYPE_ENGINE, StarTrekMetaEngineConnect);
#else
REGISTER_PLUGIN_STATIC(STARTREK, PLUGIN_TYPE_ENGINE, StarTrekMetaEngineConnect);
#endif

View File

@ -6,7 +6,6 @@ MODULE_OBJS = \
bitmap.o \
common.o \
console.o \
detection.o \
events.o \
font.o \
graphics.o \
@ -15,6 +14,7 @@ MODULE_OBJS = \
lzss.o \
menu.o \
resource.o \
metaengine.o \
room.o \
saveload.o \
sound.o \
@ -88,3 +88,6 @@ endif
# Include common rules
include $(srcdir)/rules.mk
# Detection objects
DETECT_OBJS += $(MODULE)/detection.o

View File

@ -48,6 +48,7 @@
#include "startrek/object.h"
#include "startrek/sound.h"
#include "startrek/space.h"
#include "startrek/detection_enums.h"
using Common::SharedPtr;
@ -116,15 +117,7 @@ const int MAX_BUFFERED_WALK_ACTIONS = 32;
const int MAX_BAN_FILES = 16;
enum StarTrekGameType {
GType_ST25 = 1,
GType_STJR = 2
};
enum StarTrekGameFeatures {
GF_DEMO = (1 << 0),
GF_CDROM = (1 << 1)
};
enum kDebugLevels {
kDebugSound = 1 << 0,