From f54f8022e25b4e0758e35118771c48978766d72e Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Wed, 21 Sep 2022 17:47:57 +0300 Subject: [PATCH 1/3] disable scripting modules by default --- CMakeLists.txt | 4 ++-- CMakePresets.json | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb6cf8e6a..4f1b8c7d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,8 @@ set(VCMI_VERSION_MAJOR 1) set(VCMI_VERSION_MINOR 0) set(VCMI_VERSION_PATCH 0) -option(ENABLE_ERM "Enable compilation of ERM scripting module" ON) -option(ENABLE_LUA "Enable compilation of LUA scripting module" ON) +option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF) +option(ENABLE_LUA "Enable compilation of LUA scripting module" OFF) option(ENABLE_LAUNCHER "Enable compilation of launcher" ON) option(ENABLE_TEST "Enable compilation of unit tests" ON) if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0") diff --git a/CMakePresets.json b/CMakePresets.json index e1735cbfd..20a5a23ed 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -79,11 +79,7 @@ "name": "macos-arm-conan-ninja-release", "displayName": "Ninja+Conan arm64 release", "description": "VCMI MacOS-arm64 Ninja using Conan", - "inherits": "macos-conan-ninja-release", - "cacheVariables": { - "ENABLE_ERM": "OFF", - "ENABLE_LUA": "OFF" - } + "inherits": "macos-conan-ninja-release" }, { "name": "macos-xcode-release", From 4058c2c18abc13532d5f119575856ead5ed30b82 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Wed, 21 Sep 2022 19:07:49 +0300 Subject: [PATCH 2/3] model implicit ERM -> LUA dependency --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f1b8c7d2..e206ba0ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,11 @@ option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linu set(PACKAGE_NAME_SUFFIX "" CACHE STRING "Suffix for CPack package name") set(PACKAGE_FILE_NAME "" CACHE STRING "Override for CPack package filename") +# ERM depends on LUA implicitly +if(ENABLE_ERM AND NOT ENABLE_LUA) + set(ENABLE_LUA ON) +endif() + ############################################ # Miscellaneous options # ############################################ From 7e6ed0583caa328c60b23db7c94e2f64c550ac78 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Wed, 21 Sep 2022 19:31:14 +0300 Subject: [PATCH 3/3] disable all scripting code when configuring without scripting modules --- AI/BattleAI/StackWithBonuses.cpp | 6 ++++++ AI/BattleAI/StackWithBonuses.h | 4 ++++ CCallback.cpp | 2 ++ CCallback.h | 2 ++ CMakeLists.txt | 4 ++++ client/CGameInfo.cpp | 2 ++ client/CGameInfo.h | 2 ++ client/CMT.cpp | 2 ++ client/Client.cpp | 10 ++++++++++ client/Client.h | 7 +++++++ include/vcmi/Services.h | 4 ++++ include/vcmi/scripting/Service.h | 2 ++ lib/CGameInterface.cpp | 2 ++ lib/CGameInterface.h | 6 ++++++ lib/CModHandler.cpp | 4 ++++ lib/CScriptingModule.cpp | 2 ++ lib/CScriptingModule.h | 2 ++ lib/IGameCallback.h | 7 +++++-- lib/ScriptHandler.cpp | 2 ++ lib/ScriptHandler.h | 2 ++ lib/VCMI_Lib.cpp | 10 ++++++++++ lib/VCMI_Lib.h | 11 +++++++++++ lib/battle/BattleInfo.cpp | 2 ++ lib/battle/BattleInfo.h | 2 ++ lib/battle/CBattleInfoCallback.h | 7 ------- lib/battle/IBattleInfoCallback.h | 4 ++++ lib/spells/ISpellMechanics.cpp | 2 ++ lib/spells/ISpellMechanics.h | 6 ++++++ server/CGameHandler.cpp | 8 +++++++- server/CGameHandler.h | 8 ++++++++ 30 files changed, 124 insertions(+), 10 deletions(-) diff --git a/AI/BattleAI/StackWithBonuses.cpp b/AI/BattleAI/StackWithBonuses.cpp index 2b3679569..fc93ffc03 100644 --- a/AI/BattleAI/StackWithBonuses.cpp +++ b/AI/BattleAI/StackWithBonuses.cpp @@ -16,7 +16,9 @@ #include "../../lib/CStack.h" #include "../../lib/ScriptHandler.h" +#if SCRIPTING_ENABLED using scripting::Pool; +#endif void actualizeEffect(TBonusListPtr target, const Bonus & ef) { @@ -217,7 +219,9 @@ HypotheticBattle::HypotheticBattle(const Environment * ENV, Subject realBattle) localEnvironment.reset(new HypotheticEnvironment(this, env)); serverCallback.reset(new HypotheticServerCallback(this)); +#if SCRIPTING_ENABLED pool.reset(new scripting::PoolImpl(localEnvironment.get(), serverCallback.get())); +#endif } bool HypotheticBattle::unitHasAmmoCart(const battle::Unit * unit) const @@ -420,10 +424,12 @@ int64_t HypotheticBattle::getTreeVersion() const return getBattleNode()->getTreeVersion() + bonusTreeVersion; } +#if SCRIPTING_ENABLED Pool * HypotheticBattle::getContextPool() const { return pool.get(); } +#endif ServerCallback * HypotheticBattle::getServerCallback() { diff --git a/AI/BattleAI/StackWithBonuses.h b/AI/BattleAI/StackWithBonuses.h index dc2ac3ce7..eb8d57db5 100644 --- a/AI/BattleAI/StackWithBonuses.h +++ b/AI/BattleAI/StackWithBonuses.h @@ -136,7 +136,9 @@ public: int64_t getTreeVersion() const; +#if SCRIPTING_ENABLED scripting::Pool * getContextPool() const override; +#endif ServerCallback * getServerCallback(); @@ -189,6 +191,8 @@ private: std::unique_ptr serverCallback; std::unique_ptr localEnvironment; +#if SCRIPTING_ENABLED mutable std::shared_ptr pool; +#endif mutable std::shared_ptr eventBus; }; diff --git a/CCallback.cpp b/CCallback.cpp index cc1714849..a4c2de397 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -366,10 +366,12 @@ void CCallback::unregisterBattleInterface(std::shared_ptr cl->additionalBattleInts[*player] -= battleEvents; } +#if SCRIPTING_ENABLED scripting::Pool * CBattleCallback::getContextPool() const { return cl->getGlobalContextPool(); } +#endif CBattleCallback::CBattleCallback(boost::optional Player, CClient *C ) { diff --git a/CCallback.h b/CCallback.h index 76f4413d0..7fe4583d3 100644 --- a/CCallback.h +++ b/CCallback.h @@ -99,7 +99,9 @@ public: int battleMakeAction(const BattleAction * action) override;//for casting spells by hero - DO NOT use it for moving active stack bool battleMakeTacticAction(BattleAction * action) override; // performs tactic phase actions +#if SCRIPTING_ENABLED scripting::Pool * getContextPool() const override; +#endif friend class CCallback; friend class CClient; diff --git a/CMakeLists.txt b/CMakeLists.txt index e206ba0ed..98eaa413f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,10 @@ if(NOT WIN32) endif() endif() +if(ENABLE_LUA) + add_compile_definitions(SCRIPTING_ENABLED=1) +endif() + ############################################ # Finding packages # ############################################ diff --git a/client/CGameInfo.cpp b/client/CGameInfo.cpp index d8c58296a..b93f149db 100644 --- a/client/CGameInfo.cpp +++ b/client/CGameInfo.cpp @@ -71,10 +71,12 @@ const HeroTypeService * CGameInfo::heroTypes() const return globalServices->heroTypes(); } +#if SCRIPTING_ENABLED const scripting::Service * CGameInfo::scripts() const { return globalServices->scripts(); } +#endif const spells::Service * CGameInfo::spells() const { diff --git a/client/CGameInfo.h b/client/CGameInfo.h index 70b56905c..442be449d 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -59,7 +59,9 @@ public: const FactionService * factions() const override; const HeroClassService * heroClasses() const override; const HeroTypeService * heroTypes() const override; +#if SCRIPTING_ENABLED const scripting::Service * scripts() const override; +#endif const spells::Service * spells() const override; const SkillService * skills() const override; const BattleFieldService * battlefields() const override; diff --git a/client/CMT.cpp b/client/CMT.cpp index ebc5274f4..5754814b8 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -686,6 +686,7 @@ void processCommand(const std::string &message) std::cout << "\rExtracting done :)\n"; std::cout << " Extracted files can be found in " << outPath << " directory\n"; } +#if SCRIPTING_ENABLED else if(message=="get scripts") { std::cout << "Command accepted.\t"; @@ -708,6 +709,7 @@ void processCommand(const std::string &message) std::cout << "\rExtracting done :)\n"; std::cout << " Extracted files can be found in " << outPath << " directory\n"; } +#endif else if(message=="get txt") { std::cout << "Command accepted.\t"; diff --git a/client/Client.cpp b/client/Client.cpp index a200c2044..e145c1b12 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -263,12 +263,14 @@ void CClient::serialize(BinarySerializer & h, const int version) i->second->saveGame(h, version); } +#if SCRIPTING_ENABLED if(version >= 800) { JsonNode scriptsState; clientScripts->serializeState(h.saving, scriptsState); h & scriptsState; } +#endif } void CClient::serialize(BinaryDeserializer & h, const int version) @@ -329,11 +331,13 @@ void CClient::serialize(BinaryDeserializer & h, const int version) LOCPLINT = prevInt; } +#if SCRIPTING_ENABLED { JsonNode scriptsState; h & scriptsState; clientScripts->serializeState(h.saving, scriptsState); } +#endif logNetwork->trace("Loaded client part of save %d ms", CSH->th->getDiff()); } @@ -352,7 +356,9 @@ void CClient::save(const std::string & fname) void CClient::endGame() { +#if SCRIPTING_ENABLED clientScripts.reset(); +#endif //suggest interfaces to finish their stuff (AI should interrupt any bg working threads) for(auto & i : playerint) @@ -732,6 +738,7 @@ PlayerColor CClient::getLocalPlayer() const return getCurrentPlayer(); } +#if SCRIPTING_ENABLED scripting::Pool * CClient::getGlobalContextPool() const { return clientScripts.get(); @@ -741,11 +748,14 @@ scripting::Pool * CClient::getContextPool() const { return clientScripts.get(); } +#endif void CClient::reinitScripting() { clientEventBus = make_unique(); +#if SCRIPTING_ENABLED clientScripts.reset(new scripting::PoolImpl(this)); +#endif } diff --git a/client/Client.h b/client/Client.h index 7f93aa3fe..38a2b4551 100644 --- a/client/Client.h +++ b/client/Client.h @@ -39,10 +39,12 @@ namespace boost { class thread; } template class CApplier; class CBaseForCLApply; +#if SCRIPTING_ENABLED namespace scripting { class PoolImpl; } +#endif namespace events { @@ -233,13 +235,18 @@ public: void showInfoDialog(InfoWindow * iw) override {}; void showInfoDialog(const std::string & msg, PlayerColor player) override {}; +#if SCRIPTING_ENABLED scripting::Pool * getGlobalContextPool() const override; scripting::Pool * getContextPool() const override; +#endif + private: std::map> battleCallbacks; //callbacks given to player interfaces std::map> playerEnvironments; +#if SCRIPTING_ENABLED std::shared_ptr clientScripts; +#endif std::unique_ptr clientEventBus; std::shared_ptr> applier; diff --git a/include/vcmi/Services.h b/include/vcmi/Services.h index 7bd2a7bb0..1bc33a1dd 100644 --- a/include/vcmi/Services.h +++ b/include/vcmi/Services.h @@ -32,10 +32,12 @@ namespace spells } } +#if SCRIPTING_ENABLED namespace scripting { class Service; } +#endif class DLL_LINKAGE Services { @@ -47,7 +49,9 @@ public: virtual const FactionService * factions() const = 0; virtual const HeroClassService * heroClasses() const = 0; virtual const HeroTypeService * heroTypes() const = 0; +#if SCRIPTING_ENABLED virtual const scripting::Service * scripts() const = 0; +#endif virtual const spells::Service * spells() const = 0; virtual const SkillService * skills() const = 0; virtual const BattleFieldService * battlefields() const = 0; diff --git a/include/vcmi/scripting/Service.h b/include/vcmi/scripting/Service.h index d09882dfa..e94300598 100644 --- a/include/vcmi/scripting/Service.h +++ b/include/vcmi/scripting/Service.h @@ -10,6 +10,7 @@ #pragma once +#if SCRIPTING_ENABLED #include class Services; @@ -78,3 +79,4 @@ public: } +#endif diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index fc4731688..84b9e9745 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -126,10 +126,12 @@ std::shared_ptr CDynLibHandler::getNewBattleAI(std::string return createAnyAI(dllname, "GetNewBattleAI"); } +#if SCRIPTING_ENABLED std::shared_ptr CDynLibHandler::getNewScriptingModule(const boost::filesystem::path & dllname) { return createAny(dllname, "GetNewModule"); } +#endif BattleAction CGlobalAI::activeStack(const CStack * stack) { diff --git a/lib/CGameInterface.h b/lib/CGameInterface.h index 35b8671fe..c4ab18378 100644 --- a/lib/CGameInterface.h +++ b/lib/CGameInterface.h @@ -56,10 +56,14 @@ class CSaveFile; class BinaryDeserializer; class BinarySerializer; struct ArtifactLocation; + +#if SCRIPTING_ENABLED namespace scripting { class Module; } +#endif + class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver { @@ -110,7 +114,9 @@ class DLL_LINKAGE CDynLibHandler public: static std::shared_ptr getNewAI(std::string dllname); static std::shared_ptr getNewBattleAI(std::string dllname); +#if SCRIPTING_ENABLED static std::shared_ptr getNewScriptingModule(const boost::filesystem::path & dllname); +#endif }; class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate) diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 1c30b1208..8158c8621 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -434,7 +434,9 @@ void CContentHandler::init() handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell"))); handlers.insert(std::make_pair("skills", ContentTypeHandler(VLC->skillh, "skill"))); handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template"))); +#if SCRIPTING_ENABLED handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script"))); +#endif handlers.insert(std::make_pair("battlefields", ContentTypeHandler(VLC->battlefieldsHandler, "battlefield"))); handlers.insert(std::make_pair("obstacles", ContentTypeHandler(VLC->obstacleHandler, "obstacle"))); //TODO: any other types of moddables? @@ -986,7 +988,9 @@ void CModHandler::load() for(const TModID & modName : activeMods) content->load(allMods[modName]); +#if SCRIPTING_ENABLED VLC->scriptHandler->performRegistration(VLC);//todo: this should be done before any other handlers load +#endif content->loadCustom(); diff --git a/lib/CScriptingModule.cpp b/lib/CScriptingModule.cpp index e85e3c72e..c6da26f01 100644 --- a/lib/CScriptingModule.cpp +++ b/lib/CScriptingModule.cpp @@ -11,6 +11,7 @@ #include "CScriptingModule.h" +#if SCRIPTING_ENABLED namespace scripting { @@ -30,3 +31,4 @@ Module::Module() Module::~Module() = default; } +#endif diff --git a/lib/CScriptingModule.h b/lib/CScriptingModule.h index eacf0c599..77b59249f 100644 --- a/lib/CScriptingModule.h +++ b/lib/CScriptingModule.h @@ -9,6 +9,7 @@ */ #pragma once +#if SCRIPTING_ENABLED #include namespace spells @@ -45,3 +46,4 @@ public: }; } +#endif diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 532532dac..0f4ad0940 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -27,12 +27,13 @@ class CStackBasicDescriptor; class CGCreature; struct ShashInt3; +#if SCRIPTING_ENABLED namespace scripting { - class Context; class Pool; - class Script; } +#endif + class DLL_LINKAGE CPrivilegedInfoCallback : public CGameInfoCallback { @@ -132,7 +133,9 @@ class DLL_LINKAGE IGameCallback : public CPrivilegedInfoCallback, public IGameEv public: virtual ~IGameCallback(){}; +#if SCRIPTING_ENABLED virtual scripting::Pool * getGlobalContextPool() const = 0; +#endif //get info virtual bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero); diff --git a/lib/ScriptHandler.cpp b/lib/ScriptHandler.cpp index ebca5ce26..955ca2852 100644 --- a/lib/ScriptHandler.cpp +++ b/lib/ScriptHandler.cpp @@ -11,6 +11,7 @@ #include "ScriptHandler.h" +#if SCRIPTING_ENABLED #include #include @@ -311,3 +312,4 @@ void ScriptHandler::saveState(JsonNode & state) } +#endif diff --git a/lib/ScriptHandler.h b/lib/ScriptHandler.h index 37da9e975..53d91110c 100644 --- a/lib/ScriptHandler.h +++ b/lib/ScriptHandler.h @@ -10,6 +10,7 @@ #pragma once +#if SCRIPTING_ENABLED #include #include "IHandlerBase.h" #include "JsonNode.h" @@ -131,3 +132,4 @@ private: }; } +#endif diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 81fd2bd99..d79a9003a 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -82,10 +82,12 @@ const HeroTypeService * LibClasses::heroTypes() const return heroh; } +#if SCRIPTING_ENABLED const scripting::Service * LibClasses::scripts() const { return scriptHandler; } +#endif const spells::Service * LibClasses::spells() const { @@ -215,7 +217,9 @@ void LibClasses::init(bool onlyEssential) createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?) +#if SCRIPTING_ENABLED createHandler(scriptHandler, "Script", pomtime); +#endif createHandler(battlefieldsHandler, "Battlefields", pomtime); @@ -246,7 +250,9 @@ void LibClasses::clear() delete bth; delete tplh; delete terviewh; +#if SCRIPTING_ENABLED delete scriptHandler; +#endif delete battlefieldsHandler; makeNull(); } @@ -266,7 +272,9 @@ void LibClasses::makeNull() bth = nullptr; tplh = nullptr; terviewh = nullptr; +#if SCRIPTING_ENABLED scriptHandler = nullptr; +#endif battlefieldsHandler = nullptr; } @@ -287,10 +295,12 @@ void LibClasses::callWhenDeserializing() //modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config } +#if SCRIPTING_ENABLED void LibClasses::scriptsLoaded() { scriptHandler->performRegistration(this); } +#endif LibClasses::~LibClasses() { diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 774db316d..8a8a472ee 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -32,10 +32,13 @@ class CTerrainViewPatternConfig; class CRmgTemplateStorage; class IHandlerBase; +#if SCRIPTING_ENABLED namespace scripting { class ScriptHandler; } +#endif + /// Loads and constructs several handlers class DLL_LINKAGE LibClasses : public Services @@ -55,7 +58,9 @@ public: const FactionService * factions() const override; const HeroClassService * heroClasses() const override; const HeroTypeService * heroTypes() const override; +#if SCRIPTING_ENABLED const scripting::Service * scripts() const override; +#endif const spells::Service * spells() const override; const SkillService * skills() const override; const BattleFieldService * battlefields() const override; @@ -82,7 +87,9 @@ public: CRmgTemplateStorage * tplh; BattleFieldHandler * battlefieldsHandler; ObstacleHandler * obstacleHandler; +#if SCRIPTING_ENABLED scripting::ScriptHandler * scriptHandler; +#endif LibClasses(); //c-tor, loads .lods and NULLs handlers ~LibClasses(); @@ -92,15 +99,19 @@ public: void loadFilesystem(bool onlyEssential);// basic initialization. should be called before init() +#if SCRIPTING_ENABLED void scriptsLoaded(); +#endif template void serialize(Handler &h, const int version) { +#if SCRIPTING_ENABLED h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on if(!h.saving) { scriptsLoaded(); } +#endif h & heroh; h & arth; diff --git a/lib/battle/BattleInfo.cpp b/lib/battle/BattleInfo.cpp index f49d1e9a6..3ffa5d742 100644 --- a/lib/battle/BattleInfo.cpp +++ b/lib/battle/BattleInfo.cpp @@ -965,12 +965,14 @@ CGHeroInstance * BattleInfo::battleGetFightingHero(ui8 side) const return const_cast(CBattleInfoEssentials::battleGetFightingHero(side)); } +#if SCRIPTING_ENABLED scripting::Pool * BattleInfo::getContextPool() const { //this is real battle, use global scripting context pool //TODO: make this line not ugly return IObjectInterface::cb->getGlobalContextPool(); } +#endif bool CMP_stack::operator()(const battle::Unit * a, const battle::Unit * b) { diff --git a/lib/battle/BattleInfo.h b/lib/battle/BattleInfo.h index 1d0c128cc..73a4ad0cc 100644 --- a/lib/battle/BattleInfo.h +++ b/lib/battle/BattleInfo.h @@ -144,7 +144,9 @@ public: ui8 whatSide(PlayerColor player) const; protected: +#if SCRIPTING_ENABLED scripting::Pool * getContextPool() const override; +#endif }; diff --git a/lib/battle/CBattleInfoCallback.h b/lib/battle/CBattleInfoCallback.h index 146cf038d..b5cd714c3 100644 --- a/lib/battle/CBattleInfoCallback.h +++ b/lib/battle/CBattleInfoCallback.h @@ -23,13 +23,6 @@ struct CObstacleInstance; class IBonusBearer; class CRandomGenerator; -namespace scripting -{ - class Context; - class Pool; - class Script; -} - namespace spells { class Caster; diff --git a/lib/battle/IBattleInfoCallback.h b/lib/battle/IBattleInfoCallback.h index ad3d0e6e4..fcce0c7f2 100644 --- a/lib/battle/IBattleInfoCallback.h +++ b/lib/battle/IBattleInfoCallback.h @@ -24,15 +24,19 @@ namespace battle using UnitFilter = std::function; } +#if SCRIPTING_ENABLED namespace scripting { class Pool; } +#endif class DLL_LINKAGE IBattleInfoCallback { public: +#if SCRIPTING_ENABLED virtual scripting::Pool * getContextPool() const = 0; +#endif virtual Terrain battleTerrainType() const = 0; virtual BattleField battleGetBattlefieldType() const = 0; diff --git a/lib/spells/ISpellMechanics.cpp b/lib/spells/ISpellMechanics.cpp index a80475041..29578ff56 100644 --- a/lib/spells/ISpellMechanics.cpp +++ b/lib/spells/ISpellMechanics.cpp @@ -720,10 +720,12 @@ const CreatureService * BaseMechanics::creatures() const return VLC->creatures(); //todo: redirect } +#if SCRIPTING_ENABLED const scripting::Service * BaseMechanics::scripts() const { return VLC->scripts(); //todo: redirect } +#endif const Service * BaseMechanics::spells() const { diff --git a/lib/spells/ISpellMechanics.h b/lib/spells/ISpellMechanics.h index de9546757..927a5a308 100644 --- a/lib/spells/ISpellMechanics.h +++ b/lib/spells/ISpellMechanics.h @@ -35,10 +35,12 @@ namespace vstd class RNG; } +#if SCRIPTING_ENABLED namespace scripting { class Service; } +#endif ///callback to be provided by server @@ -238,7 +240,9 @@ public: //Global environment facade virtual const CreatureService * creatures() const = 0; +#if SCRIPTING_ENABLED virtual const scripting::Service * scripts() const = 0; +#endif virtual const Service * spells() const = 0; virtual const IGameInfoCallback * game() const = 0; @@ -296,7 +300,9 @@ public: std::vector getTargetTypes() const override; const CreatureService * creatures() const override; +#if SCRIPTING_ENABLED const scripting::Service * scripts() const override; +#endif const Service * spells() const override; const IGameInfoCallback * game() const override; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 5dcd2dcea..764051636 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1652,7 +1652,9 @@ CGameHandler::~CGameHandler() void CGameHandler::reinitScripting() { serverEventBus = make_unique(); +#if SCRIPTING_ENABLED serverScripts.reset(new scripting::PoolImpl(this, spellEnv)); +#endif } void CGameHandler::init(StartInfo *si) @@ -2112,7 +2114,9 @@ void CGameHandler::run(bool resume) logGlobal->info(sbuffer.str()); } +#if SCRIPTING_ENABLED services()->scripts()->run(serverScripts); +#endif if(resume) events::GameResumed::defaultExecute(serverEventBus.get()); @@ -7319,15 +7323,17 @@ CRandomGenerator & CGameHandler::getRandomGenerator() return CRandomGenerator::getDefault(); } +#if SCRIPTING_ENABLED scripting::Pool * CGameHandler::getGlobalContextPool() const { return serverScripts.get(); } -scripting::Pool * CGameHandler::getContextPool() const +scripting::Pool * CGameHandler::getContextPool() const { return serverScripts.get(); } +#endif const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos) { diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 2c90edf6e..56726028b 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -34,10 +34,12 @@ class IMarket; class SpellCastEnvironment; +#if SCRIPTING_ENABLED namespace scripting { class PoolImpl; } +#endif template class CApplier; @@ -274,12 +276,14 @@ public: h & finishingBattle; h & getRandomGenerator(); +#if SCRIPTING_ENABLED JsonNode scriptsState; if(h.saving) serverScripts->serializeState(h.saving, scriptsState); h & scriptsState; if(!h.saving) serverScripts->serializeState(h.saving, scriptsState); +#endif } void sendMessageToAll(const std::string &message); @@ -326,13 +330,17 @@ public: CRandomGenerator & getRandomGenerator(); +#if SCRIPTING_ENABLED scripting::Pool * getGlobalContextPool() const override; scripting::Pool * getContextPool() const override; +#endif friend class CVCMIServer; private: std::unique_ptr serverEventBus; +#if SCRIPTING_ENABLED std::shared_ptr serverScripts; +#endif void reinitScripting();