From a3550a9cb0510c18b3cfe3bd019640af952be30a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 10 Feb 2023 21:37:33 -0800 Subject: [PATCH] MM: Create common engine base engine class --- engines/mm/mm.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ engines/mm/mm.h | 38 ++++++++++++++++++++++++++++ engines/mm/mm1/mm1.cpp | 10 +------- engines/mm/mm1/mm1.h | 7 +----- engines/mm/module.mk | 1 + engines/mm/xeen/xeen.cpp | 26 +------------------- engines/mm/xeen/xeen.h | 26 +------------------- 7 files changed, 96 insertions(+), 65 deletions(-) create mode 100644 engines/mm/mm.cpp diff --git a/engines/mm/mm.cpp b/engines/mm/mm.cpp new file mode 100644 index 00000000000..8dfe75bc068 --- /dev/null +++ b/engines/mm/mm.cpp @@ -0,0 +1,53 @@ +/* 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 3 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, see . + * + */ + +#include "mm/mm.h" + +namespace MM { + +MMEngine::MMEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc) : + Engine(syst), _gameDescription(gameDesc), _randomSource("MightAndMagic") { +} + +bool MMEngine::hasFeature(EngineFeature f) const { + return + (f == kSupportsReturnToLauncher) || + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +} + +uint32 MMEngine::getGameID() const { + return _gameDescription->gameID; +} + +uint32 MMEngine::getFeatures() const { + return _gameDescription->desc.flags; +} + +Common::Language MMEngine::getLanguage() const { + return _gameDescription->desc.language; +} + +Common::Platform MMEngine::getPlatform() const { + return _gameDescription->desc.platform; +} + +} // namespace MM diff --git a/engines/mm/mm.h b/engines/mm/mm.h index e288edaf212..dec644e669e 100644 --- a/engines/mm/mm.h +++ b/engines/mm/mm.h @@ -22,6 +22,9 @@ #ifndef MM_MM_H #define MM_MM_H +#include "common/random.h" +#include "mm/detection.h" + namespace MM { enum MightAndMagicDebugChannels { @@ -31,6 +34,41 @@ enum MightAndMagicDebugChannels { kDebugSound = 1 << 3 }; +class MMEngine : public Engine { +protected: + const MightAndMagicGameDescription *_gameDescription; + Common::RandomSource _randomSource; +public: + MMEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc); + ~MMEngine() override {} + + /** + * Checks for feature flag + */ + bool hasFeature(EngineFeature f) const override; + + /** + * Returns the features + */ + uint32 getFeatures() const; + + /** + * Returns the game language + */ + Common::Language getLanguage() const; + + /** + * Returns the game's platform + */ + Common::Platform getPlatform() const; + + /** + * Gets the game Id + */ + uint32 getGameID() const; + +}; + } // namespace MM #endif // MM_MM_H diff --git a/engines/mm/mm1/mm1.cpp b/engines/mm/mm1/mm1.cpp index 062e9634fc9..5e3932793db 100644 --- a/engines/mm/mm1/mm1.cpp +++ b/engines/mm/mm1/mm1.cpp @@ -40,8 +40,7 @@ namespace MM1 { MM1Engine *g_engine = nullptr; MM1Engine::MM1Engine(OSystem *syst, const MightAndMagicGameDescription *gameDesc) - : Engine(syst), Events(gameDesc->features & GF_ENHANCED), - _gameDescription(gameDesc), _randomSource("MM1") { + : MMEngine(syst, gameDesc), Events(gameDesc->features & GF_ENHANCED) { g_engine = this; } @@ -118,13 +117,6 @@ bool MM1Engine::setupEnhanced() { return true; } -bool MM1Engine::hasFeature(EngineFeature f) const { - return - (f == kSupportsReturnToLauncher) || - (f == kSupportsLoadingDuringRuntime) || - (f == kSupportsSavingDuringRuntime); -} - bool MM1Engine::canSaveGameStateCurrently() { if (!g_events) return false; diff --git a/engines/mm/mm1/mm1.h b/engines/mm/mm1/mm1.h index 85aa57ffa27..24021f2dc51 100644 --- a/engines/mm/mm1/mm1.h +++ b/engines/mm/mm1/mm1.h @@ -35,10 +35,7 @@ namespace MM { namespace MM1 { -class MM1Engine : public Engine, public Events { -private: - const MightAndMagicGameDescription *_gameDescription; - Common::RandomSource _randomSource; +class MM1Engine : public MMEngine, public Events { private: // Engine APIs Common::Error run() override; @@ -51,8 +48,6 @@ public: MM1Engine(OSystem *syst, const MightAndMagicGameDescription *gameDesc); ~MM1Engine() override; - bool hasFeature(EngineFeature f) const override; - bool isEnhanced() const; /** diff --git a/engines/mm/module.mk b/engines/mm/module.mk index 0d770761e36..75ee3633d3f 100644 --- a/engines/mm/module.mk +++ b/engines/mm/module.mk @@ -2,6 +2,7 @@ MODULE := engines/mm MODULE_OBJS := \ metaengine.o \ + mm.o \ utils/bitmap_font.o \ utils/engine_data.o \ utils/strings.o \ diff --git a/engines/mm/xeen/xeen.cpp b/engines/mm/xeen/xeen.cpp index cd59dae2e75..8b622b4e554 100644 --- a/engines/mm/xeen/xeen.cpp +++ b/engines/mm/xeen/xeen.cpp @@ -34,8 +34,7 @@ namespace Xeen { XeenEngine *g_vm = nullptr; XeenEngine::XeenEngine(OSystem *syst, const MightAndMagicGameDescription *gameDesc) - : Engine(syst), _gameDescription(gameDesc), _randomSource("Xeen") { - + : MMEngine(syst, gameDesc) { _combat = nullptr; _debugger = nullptr; _events = nullptr; @@ -118,13 +117,6 @@ bool XeenEngine::initialize() { return true; } -bool XeenEngine::hasFeature(EngineFeature f) const { - return - (f == kSupportsReturnToLauncher) || - (f == kSupportsLoadingDuringRuntime) || - (f == kSupportsSavingDuringRuntime); -} - void XeenEngine::loadSettings() { _gameWon[0] = ConfMan.hasKey("game_won") && ConfMan.getBool("game_won"); _gameWon[1] = ConfMan.hasKey("game_won2") && ConfMan.getBool("game_won2"); @@ -335,10 +327,6 @@ void XeenEngine::GUIError(const Common::U32String &msg) { } -uint32 XeenEngine::getGameID() const { - return _gameDescription->gameID; -} - uint32 XeenEngine::getSpecificGameId() const { uint gameId = g_vm->getGameID(); if (gameId == GType_WorldOfXeen) @@ -351,18 +339,6 @@ uint32 XeenEngine::getGameFeatures() const { return _gameDescription->features; } -uint32 XeenEngine::getFeatures() const { - return _gameDescription->desc.flags; -} - -Common::Language XeenEngine::getLanguage() const { - return _gameDescription->desc.language; -} - -Common::Platform XeenEngine::getPlatform() const { - return _gameDescription->desc.platform; -} - bool XeenEngine::getIsCD() const { return getFeatures() & ADGF_CD; } diff --git a/engines/mm/xeen/xeen.h b/engines/mm/xeen/xeen.h index f15a1da2300..2f6b52fed3d 100644 --- a/engines/mm/xeen/xeen.h +++ b/engines/mm/xeen/xeen.h @@ -90,7 +90,7 @@ enum GameMode { #define XEEN_SAVEGAME_VERSION 2 -class XeenEngine : public Engine { +class XeenEngine : public MMEngine { /** * Container to a set of options newly introduced under ScummVM */ @@ -101,9 +101,6 @@ class XeenEngine : public Engine { ExtendedOptions() : _showItemCosts(false), _durableArmor(false) { } }; -private: - const MightAndMagicGameDescription *_gameDescription; - Common::RandomSource _randomSource; private: /** * Initializes all the engine sub-objects @@ -117,7 +114,6 @@ private: // Engine APIs Common::Error run() override; - bool hasFeature(EngineFeature f) const override; /** * Outer gameplay loop responsible for dispatching control to game-specific @@ -185,26 +181,6 @@ public: XeenEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc); ~XeenEngine() override; - /** - * Returns the features - */ - uint32 getFeatures() const; - - /** - * Returns the game language - */ - Common::Language getLanguage() const; - - /** - * Returns the game's platform - */ - Common::Platform getPlatform() const; - - /** - * Gets the game Id - */ - uint32 getGameID() const; - /** * Returns the game Id, but with a reuslt of Clouds or Dark Side for World of Xeen, * depending on which side the player is currently on