1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Merge pull request #968 from kambala-decapitator/disable-scripting

Disable scripting modules by default
This commit is contained in:
Andrii Danylchenko 2022-09-22 15:23:17 +03:00 committed by GitHub
commit afe84f16e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 132 additions and 17 deletions

View File

@ -16,7 +16,9 @@
#include "../../lib/CStack.h" #include "../../lib/CStack.h"
#include "../../lib/ScriptHandler.h" #include "../../lib/ScriptHandler.h"
#if SCRIPTING_ENABLED
using scripting::Pool; using scripting::Pool;
#endif
void actualizeEffect(TBonusListPtr target, const Bonus & ef) void actualizeEffect(TBonusListPtr target, const Bonus & ef)
{ {
@ -217,7 +219,9 @@ HypotheticBattle::HypotheticBattle(const Environment * ENV, Subject realBattle)
localEnvironment.reset(new HypotheticEnvironment(this, env)); localEnvironment.reset(new HypotheticEnvironment(this, env));
serverCallback.reset(new HypotheticServerCallback(this)); serverCallback.reset(new HypotheticServerCallback(this));
#if SCRIPTING_ENABLED
pool.reset(new scripting::PoolImpl(localEnvironment.get(), serverCallback.get())); pool.reset(new scripting::PoolImpl(localEnvironment.get(), serverCallback.get()));
#endif
} }
bool HypotheticBattle::unitHasAmmoCart(const battle::Unit * unit) const bool HypotheticBattle::unitHasAmmoCart(const battle::Unit * unit) const
@ -420,10 +424,12 @@ int64_t HypotheticBattle::getTreeVersion() const
return getBattleNode()->getTreeVersion() + bonusTreeVersion; return getBattleNode()->getTreeVersion() + bonusTreeVersion;
} }
#if SCRIPTING_ENABLED
Pool * HypotheticBattle::getContextPool() const Pool * HypotheticBattle::getContextPool() const
{ {
return pool.get(); return pool.get();
} }
#endif
ServerCallback * HypotheticBattle::getServerCallback() ServerCallback * HypotheticBattle::getServerCallback()
{ {

View File

@ -136,7 +136,9 @@ public:
int64_t getTreeVersion() const; int64_t getTreeVersion() const;
#if SCRIPTING_ENABLED
scripting::Pool * getContextPool() const override; scripting::Pool * getContextPool() const override;
#endif
ServerCallback * getServerCallback(); ServerCallback * getServerCallback();
@ -189,6 +191,8 @@ private:
std::unique_ptr<HypotheticServerCallback> serverCallback; std::unique_ptr<HypotheticServerCallback> serverCallback;
std::unique_ptr<HypotheticEnvironment> localEnvironment; std::unique_ptr<HypotheticEnvironment> localEnvironment;
#if SCRIPTING_ENABLED
mutable std::shared_ptr<scripting::Pool> pool; mutable std::shared_ptr<scripting::Pool> pool;
#endif
mutable std::shared_ptr<events::EventBus> eventBus; mutable std::shared_ptr<events::EventBus> eventBus;
}; };

View File

@ -366,10 +366,12 @@ void CCallback::unregisterBattleInterface(std::shared_ptr<IBattleEventsReceiver>
cl->additionalBattleInts[*player] -= battleEvents; cl->additionalBattleInts[*player] -= battleEvents;
} }
#if SCRIPTING_ENABLED
scripting::Pool * CBattleCallback::getContextPool() const scripting::Pool * CBattleCallback::getContextPool() const
{ {
return cl->getGlobalContextPool(); return cl->getGlobalContextPool();
} }
#endif
CBattleCallback::CBattleCallback(boost::optional<PlayerColor> Player, CClient *C ) CBattleCallback::CBattleCallback(boost::optional<PlayerColor> Player, CClient *C )
{ {

View File

@ -99,7 +99,9 @@ public:
int battleMakeAction(const BattleAction * action) override;//for casting spells by hero - DO NOT use it for moving active stack 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 bool battleMakeTacticAction(BattleAction * action) override; // performs tactic phase actions
#if SCRIPTING_ENABLED
scripting::Pool * getContextPool() const override; scripting::Pool * getContextPool() const override;
#endif
friend class CCallback; friend class CCallback;
friend class CClient; friend class CClient;

View File

@ -41,8 +41,8 @@ set(VCMI_VERSION_MAJOR 1)
set(VCMI_VERSION_MINOR 0) set(VCMI_VERSION_MINOR 0)
set(VCMI_VERSION_PATCH 0) set(VCMI_VERSION_PATCH 0)
option(ENABLE_ERM "Enable compilation of ERM scripting module" ON) option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF)
option(ENABLE_LUA "Enable compilation of LUA scripting module" ON) option(ENABLE_LUA "Enable compilation of LUA scripting module" OFF)
option(ENABLE_LAUNCHER "Enable compilation of launcher" ON) option(ENABLE_LAUNCHER "Enable compilation of launcher" ON)
option(ENABLE_TEST "Enable compilation of unit tests" ON) option(ENABLE_TEST "Enable compilation of unit tests" ON)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0") if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
@ -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_NAME_SUFFIX "" CACHE STRING "Suffix for CPack package name")
set(PACKAGE_FILE_NAME "" CACHE STRING "Override for CPack package filename") 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 # # Miscellaneous options #
############################################ ############################################
@ -214,6 +219,10 @@ if(NOT WIN32)
endif() endif()
endif() endif()
if(ENABLE_LUA)
add_compile_definitions(SCRIPTING_ENABLED=1)
endif()
############################################ ############################################
# Finding packages # # Finding packages #
############################################ ############################################

View File

@ -79,11 +79,7 @@
"name": "macos-arm-conan-ninja-release", "name": "macos-arm-conan-ninja-release",
"displayName": "Ninja+Conan arm64 release", "displayName": "Ninja+Conan arm64 release",
"description": "VCMI MacOS-arm64 Ninja using Conan", "description": "VCMI MacOS-arm64 Ninja using Conan",
"inherits": "macos-conan-ninja-release", "inherits": "macos-conan-ninja-release"
"cacheVariables": {
"ENABLE_ERM": "OFF",
"ENABLE_LUA": "OFF"
}
}, },
{ {
"name": "macos-xcode-release", "name": "macos-xcode-release",

View File

@ -71,10 +71,12 @@ const HeroTypeService * CGameInfo::heroTypes() const
return globalServices->heroTypes(); return globalServices->heroTypes();
} }
#if SCRIPTING_ENABLED
const scripting::Service * CGameInfo::scripts() const const scripting::Service * CGameInfo::scripts() const
{ {
return globalServices->scripts(); return globalServices->scripts();
} }
#endif
const spells::Service * CGameInfo::spells() const const spells::Service * CGameInfo::spells() const
{ {

View File

@ -59,7 +59,9 @@ public:
const FactionService * factions() const override; const FactionService * factions() const override;
const HeroClassService * heroClasses() const override; const HeroClassService * heroClasses() const override;
const HeroTypeService * heroTypes() const override; const HeroTypeService * heroTypes() const override;
#if SCRIPTING_ENABLED
const scripting::Service * scripts() const override; const scripting::Service * scripts() const override;
#endif
const spells::Service * spells() const override; const spells::Service * spells() const override;
const SkillService * skills() const override; const SkillService * skills() const override;
const BattleFieldService * battlefields() const override; const BattleFieldService * battlefields() const override;

View File

@ -686,6 +686,7 @@ void processCommand(const std::string &message)
std::cout << "\rExtracting done :)\n"; std::cout << "\rExtracting done :)\n";
std::cout << " Extracted files can be found in " << outPath << " directory\n"; std::cout << " Extracted files can be found in " << outPath << " directory\n";
} }
#if SCRIPTING_ENABLED
else if(message=="get scripts") else if(message=="get scripts")
{ {
std::cout << "Command accepted.\t"; std::cout << "Command accepted.\t";
@ -708,6 +709,7 @@ void processCommand(const std::string &message)
std::cout << "\rExtracting done :)\n"; std::cout << "\rExtracting done :)\n";
std::cout << " Extracted files can be found in " << outPath << " directory\n"; std::cout << " Extracted files can be found in " << outPath << " directory\n";
} }
#endif
else if(message=="get txt") else if(message=="get txt")
{ {
std::cout << "Command accepted.\t"; std::cout << "Command accepted.\t";

View File

@ -263,12 +263,14 @@ void CClient::serialize(BinarySerializer & h, const int version)
i->second->saveGame(h, version); i->second->saveGame(h, version);
} }
#if SCRIPTING_ENABLED
if(version >= 800) if(version >= 800)
{ {
JsonNode scriptsState; JsonNode scriptsState;
clientScripts->serializeState(h.saving, scriptsState); clientScripts->serializeState(h.saving, scriptsState);
h & scriptsState; h & scriptsState;
} }
#endif
} }
void CClient::serialize(BinaryDeserializer & h, const int version) void CClient::serialize(BinaryDeserializer & h, const int version)
@ -329,11 +331,13 @@ void CClient::serialize(BinaryDeserializer & h, const int version)
LOCPLINT = prevInt; LOCPLINT = prevInt;
} }
#if SCRIPTING_ENABLED
{ {
JsonNode scriptsState; JsonNode scriptsState;
h & scriptsState; h & scriptsState;
clientScripts->serializeState(h.saving, scriptsState); clientScripts->serializeState(h.saving, scriptsState);
} }
#endif
logNetwork->trace("Loaded client part of save %d ms", CSH->th->getDiff()); 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() void CClient::endGame()
{ {
#if SCRIPTING_ENABLED
clientScripts.reset(); clientScripts.reset();
#endif
//suggest interfaces to finish their stuff (AI should interrupt any bg working threads) //suggest interfaces to finish their stuff (AI should interrupt any bg working threads)
for(auto & i : playerint) for(auto & i : playerint)
@ -732,6 +738,7 @@ PlayerColor CClient::getLocalPlayer() const
return getCurrentPlayer(); return getCurrentPlayer();
} }
#if SCRIPTING_ENABLED
scripting::Pool * CClient::getGlobalContextPool() const scripting::Pool * CClient::getGlobalContextPool() const
{ {
return clientScripts.get(); return clientScripts.get();
@ -741,11 +748,14 @@ scripting::Pool * CClient::getContextPool() const
{ {
return clientScripts.get(); return clientScripts.get();
} }
#endif
void CClient::reinitScripting() void CClient::reinitScripting()
{ {
clientEventBus = make_unique<events::EventBus>(); clientEventBus = make_unique<events::EventBus>();
#if SCRIPTING_ENABLED
clientScripts.reset(new scripting::PoolImpl(this)); clientScripts.reset(new scripting::PoolImpl(this));
#endif
} }

View File

@ -39,10 +39,12 @@ namespace boost { class thread; }
template<typename T> class CApplier; template<typename T> class CApplier;
class CBaseForCLApply; class CBaseForCLApply;
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class PoolImpl; class PoolImpl;
} }
#endif
namespace events namespace events
{ {
@ -233,13 +235,18 @@ public:
void showInfoDialog(InfoWindow * iw) override {}; void showInfoDialog(InfoWindow * iw) override {};
void showInfoDialog(const std::string & msg, PlayerColor player) override {}; void showInfoDialog(const std::string & msg, PlayerColor player) override {};
#if SCRIPTING_ENABLED
scripting::Pool * getGlobalContextPool() const override; scripting::Pool * getGlobalContextPool() const override;
scripting::Pool * getContextPool() const override; scripting::Pool * getContextPool() const override;
#endif
private: private:
std::map<PlayerColor, std::shared_ptr<CBattleCallback>> battleCallbacks; //callbacks given to player interfaces std::map<PlayerColor, std::shared_ptr<CBattleCallback>> battleCallbacks; //callbacks given to player interfaces
std::map<PlayerColor, std::shared_ptr<CPlayerEnvironment>> playerEnvironments; std::map<PlayerColor, std::shared_ptr<CPlayerEnvironment>> playerEnvironments;
#if SCRIPTING_ENABLED
std::shared_ptr<scripting::PoolImpl> clientScripts; std::shared_ptr<scripting::PoolImpl> clientScripts;
#endif
std::unique_ptr<events::EventBus> clientEventBus; std::unique_ptr<events::EventBus> clientEventBus;
std::shared_ptr<CApplier<CBaseForCLApply>> applier; std::shared_ptr<CApplier<CBaseForCLApply>> applier;

View File

@ -32,10 +32,12 @@ namespace spells
} }
} }
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class Service; class Service;
} }
#endif
class DLL_LINKAGE Services class DLL_LINKAGE Services
{ {
@ -47,7 +49,9 @@ public:
virtual const FactionService * factions() const = 0; virtual const FactionService * factions() const = 0;
virtual const HeroClassService * heroClasses() const = 0; virtual const HeroClassService * heroClasses() const = 0;
virtual const HeroTypeService * heroTypes() const = 0; virtual const HeroTypeService * heroTypes() const = 0;
#if SCRIPTING_ENABLED
virtual const scripting::Service * scripts() const = 0; virtual const scripting::Service * scripts() const = 0;
#endif
virtual const spells::Service * spells() const = 0; virtual const spells::Service * spells() const = 0;
virtual const SkillService * skills() const = 0; virtual const SkillService * skills() const = 0;
virtual const BattleFieldService * battlefields() const = 0; virtual const BattleFieldService * battlefields() const = 0;

View File

@ -10,6 +10,7 @@
#pragma once #pragma once
#if SCRIPTING_ENABLED
#include <vcmi/Environment.h> #include <vcmi/Environment.h>
class Services; class Services;
@ -78,3 +79,4 @@ public:
} }
#endif

View File

@ -126,10 +126,12 @@ std::shared_ptr<CBattleGameInterface> CDynLibHandler::getNewBattleAI(std::string
return createAnyAI<CBattleGameInterface>(dllname, "GetNewBattleAI"); return createAnyAI<CBattleGameInterface>(dllname, "GetNewBattleAI");
} }
#if SCRIPTING_ENABLED
std::shared_ptr<scripting::Module> CDynLibHandler::getNewScriptingModule(const boost::filesystem::path & dllname) std::shared_ptr<scripting::Module> CDynLibHandler::getNewScriptingModule(const boost::filesystem::path & dllname)
{ {
return createAny<scripting::Module>(dllname, "GetNewModule"); return createAny<scripting::Module>(dllname, "GetNewModule");
} }
#endif
BattleAction CGlobalAI::activeStack(const CStack * stack) BattleAction CGlobalAI::activeStack(const CStack * stack)
{ {

View File

@ -56,10 +56,14 @@ class CSaveFile;
class BinaryDeserializer; class BinaryDeserializer;
class BinarySerializer; class BinarySerializer;
struct ArtifactLocation; struct ArtifactLocation;
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class Module; class Module;
} }
#endif
class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver
{ {
@ -110,7 +114,9 @@ class DLL_LINKAGE CDynLibHandler
public: public:
static std::shared_ptr<CGlobalAI> getNewAI(std::string dllname); static std::shared_ptr<CGlobalAI> getNewAI(std::string dllname);
static std::shared_ptr<CBattleGameInterface> getNewBattleAI(std::string dllname); static std::shared_ptr<CBattleGameInterface> getNewBattleAI(std::string dllname);
#if SCRIPTING_ENABLED
static std::shared_ptr<scripting::Module> getNewScriptingModule(const boost::filesystem::path & dllname); static std::shared_ptr<scripting::Module> getNewScriptingModule(const boost::filesystem::path & dllname);
#endif
}; };
class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate) class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate)

View File

@ -434,7 +434,9 @@ void CContentHandler::init()
handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell"))); 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("skills", ContentTypeHandler(VLC->skillh, "skill")));
handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template"))); handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template")));
#if SCRIPTING_ENABLED
handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script"))); 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("battlefields", ContentTypeHandler(VLC->battlefieldsHandler, "battlefield")));
handlers.insert(std::make_pair("obstacles", ContentTypeHandler(VLC->obstacleHandler, "obstacle"))); handlers.insert(std::make_pair("obstacles", ContentTypeHandler(VLC->obstacleHandler, "obstacle")));
//TODO: any other types of moddables? //TODO: any other types of moddables?
@ -1045,7 +1047,9 @@ void CModHandler::load()
for(const TModID & modName : activeMods) for(const TModID & modName : activeMods)
content->load(allMods[modName]); content->load(allMods[modName]);
#if SCRIPTING_ENABLED
VLC->scriptHandler->performRegistration(VLC);//todo: this should be done before any other handlers load VLC->scriptHandler->performRegistration(VLC);//todo: this should be done before any other handlers load
#endif
content->loadCustom(); content->loadCustom();

View File

@ -11,6 +11,7 @@
#include "CScriptingModule.h" #include "CScriptingModule.h"
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
@ -30,3 +31,4 @@ Module::Module()
Module::~Module() = default; Module::~Module() = default;
} }
#endif

View File

@ -9,6 +9,7 @@
*/ */
#pragma once #pragma once
#if SCRIPTING_ENABLED
#include <vcmi/scripting/Service.h> #include <vcmi/scripting/Service.h>
namespace spells namespace spells
@ -45,3 +46,4 @@ public:
}; };
} }
#endif

View File

@ -27,12 +27,13 @@ class CStackBasicDescriptor;
class CGCreature; class CGCreature;
struct ShashInt3; struct ShashInt3;
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class Context;
class Pool; class Pool;
class Script;
} }
#endif
class DLL_LINKAGE CPrivilegedInfoCallback : public CGameInfoCallback class DLL_LINKAGE CPrivilegedInfoCallback : public CGameInfoCallback
{ {
@ -132,7 +133,9 @@ class DLL_LINKAGE IGameCallback : public CPrivilegedInfoCallback, public IGameEv
public: public:
virtual ~IGameCallback(){}; virtual ~IGameCallback(){};
#if SCRIPTING_ENABLED
virtual scripting::Pool * getGlobalContextPool() const = 0; virtual scripting::Pool * getGlobalContextPool() const = 0;
#endif
//get info //get info
virtual bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero); virtual bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero);

View File

@ -11,6 +11,7 @@
#include "ScriptHandler.h" #include "ScriptHandler.h"
#if SCRIPTING_ENABLED
#include <vcmi/Services.h> #include <vcmi/Services.h>
#include <vcmi/Environment.h> #include <vcmi/Environment.h>
@ -311,3 +312,4 @@ void ScriptHandler::saveState(JsonNode & state)
} }
#endif

View File

@ -10,6 +10,7 @@
#pragma once #pragma once
#if SCRIPTING_ENABLED
#include <vcmi/scripting/Service.h> #include <vcmi/scripting/Service.h>
#include "IHandlerBase.h" #include "IHandlerBase.h"
#include "JsonNode.h" #include "JsonNode.h"
@ -131,3 +132,4 @@ private:
}; };
} }
#endif

View File

@ -82,10 +82,12 @@ const HeroTypeService * LibClasses::heroTypes() const
return heroh; return heroh;
} }
#if SCRIPTING_ENABLED
const scripting::Service * LibClasses::scripts() const const scripting::Service * LibClasses::scripts() const
{ {
return scriptHandler; return scriptHandler;
} }
#endif
const spells::Service * LibClasses::spells() const 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?) createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
#if SCRIPTING_ENABLED
createHandler(scriptHandler, "Script", pomtime); createHandler(scriptHandler, "Script", pomtime);
#endif
createHandler(battlefieldsHandler, "Battlefields", pomtime); createHandler(battlefieldsHandler, "Battlefields", pomtime);
@ -246,7 +250,9 @@ void LibClasses::clear()
delete bth; delete bth;
delete tplh; delete tplh;
delete terviewh; delete terviewh;
#if SCRIPTING_ENABLED
delete scriptHandler; delete scriptHandler;
#endif
delete battlefieldsHandler; delete battlefieldsHandler;
makeNull(); makeNull();
} }
@ -266,7 +272,9 @@ void LibClasses::makeNull()
bth = nullptr; bth = nullptr;
tplh = nullptr; tplh = nullptr;
terviewh = nullptr; terviewh = nullptr;
#if SCRIPTING_ENABLED
scriptHandler = nullptr; scriptHandler = nullptr;
#endif
battlefieldsHandler = nullptr; battlefieldsHandler = nullptr;
} }
@ -287,10 +295,12 @@ void LibClasses::callWhenDeserializing()
//modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config //modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config
} }
#if SCRIPTING_ENABLED
void LibClasses::scriptsLoaded() void LibClasses::scriptsLoaded()
{ {
scriptHandler->performRegistration(this); scriptHandler->performRegistration(this);
} }
#endif
LibClasses::~LibClasses() LibClasses::~LibClasses()
{ {

View File

@ -32,10 +32,13 @@ class CTerrainViewPatternConfig;
class CRmgTemplateStorage; class CRmgTemplateStorage;
class IHandlerBase; class IHandlerBase;
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class ScriptHandler; class ScriptHandler;
} }
#endif
/// Loads and constructs several handlers /// Loads and constructs several handlers
class DLL_LINKAGE LibClasses : public Services class DLL_LINKAGE LibClasses : public Services
@ -55,7 +58,9 @@ public:
const FactionService * factions() const override; const FactionService * factions() const override;
const HeroClassService * heroClasses() const override; const HeroClassService * heroClasses() const override;
const HeroTypeService * heroTypes() const override; const HeroTypeService * heroTypes() const override;
#if SCRIPTING_ENABLED
const scripting::Service * scripts() const override; const scripting::Service * scripts() const override;
#endif
const spells::Service * spells() const override; const spells::Service * spells() const override;
const SkillService * skills() const override; const SkillService * skills() const override;
const BattleFieldService * battlefields() const override; const BattleFieldService * battlefields() const override;
@ -82,7 +87,9 @@ public:
CRmgTemplateStorage * tplh; CRmgTemplateStorage * tplh;
BattleFieldHandler * battlefieldsHandler; BattleFieldHandler * battlefieldsHandler;
ObstacleHandler * obstacleHandler; ObstacleHandler * obstacleHandler;
#if SCRIPTING_ENABLED
scripting::ScriptHandler * scriptHandler; scripting::ScriptHandler * scriptHandler;
#endif
LibClasses(); //c-tor, loads .lods and NULLs handlers LibClasses(); //c-tor, loads .lods and NULLs handlers
~LibClasses(); ~LibClasses();
@ -92,15 +99,19 @@ public:
void loadFilesystem(bool onlyEssential);// basic initialization. should be called before init() void loadFilesystem(bool onlyEssential);// basic initialization. should be called before init()
#if SCRIPTING_ENABLED
void scriptsLoaded(); void scriptsLoaded();
#endif
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> 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 h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
if(!h.saving) if(!h.saving)
{ {
scriptsLoaded(); scriptsLoaded();
} }
#endif
h & heroh; h & heroh;
h & arth; h & arth;

View File

@ -965,12 +965,14 @@ CGHeroInstance * BattleInfo::battleGetFightingHero(ui8 side) const
return const_cast<CGHeroInstance*>(CBattleInfoEssentials::battleGetFightingHero(side)); return const_cast<CGHeroInstance*>(CBattleInfoEssentials::battleGetFightingHero(side));
} }
#if SCRIPTING_ENABLED
scripting::Pool * BattleInfo::getContextPool() const scripting::Pool * BattleInfo::getContextPool() const
{ {
//this is real battle, use global scripting context pool //this is real battle, use global scripting context pool
//TODO: make this line not ugly //TODO: make this line not ugly
return IObjectInterface::cb->getGlobalContextPool(); return IObjectInterface::cb->getGlobalContextPool();
} }
#endif
bool CMP_stack::operator()(const battle::Unit * a, const battle::Unit * b) bool CMP_stack::operator()(const battle::Unit * a, const battle::Unit * b)
{ {

View File

@ -144,7 +144,9 @@ public:
ui8 whatSide(PlayerColor player) const; ui8 whatSide(PlayerColor player) const;
protected: protected:
#if SCRIPTING_ENABLED
scripting::Pool * getContextPool() const override; scripting::Pool * getContextPool() const override;
#endif
}; };

View File

@ -23,13 +23,6 @@ struct CObstacleInstance;
class IBonusBearer; class IBonusBearer;
class CRandomGenerator; class CRandomGenerator;
namespace scripting
{
class Context;
class Pool;
class Script;
}
namespace spells namespace spells
{ {
class Caster; class Caster;

View File

@ -24,15 +24,19 @@ namespace battle
using UnitFilter = std::function<bool(const Unit *)>; using UnitFilter = std::function<bool(const Unit *)>;
} }
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class Pool; class Pool;
} }
#endif
class DLL_LINKAGE IBattleInfoCallback class DLL_LINKAGE IBattleInfoCallback
{ {
public: public:
#if SCRIPTING_ENABLED
virtual scripting::Pool * getContextPool() const = 0; virtual scripting::Pool * getContextPool() const = 0;
#endif
virtual Terrain battleTerrainType() const = 0; virtual Terrain battleTerrainType() const = 0;
virtual BattleField battleGetBattlefieldType() const = 0; virtual BattleField battleGetBattlefieldType() const = 0;

View File

@ -720,10 +720,12 @@ const CreatureService * BaseMechanics::creatures() const
return VLC->creatures(); //todo: redirect return VLC->creatures(); //todo: redirect
} }
#if SCRIPTING_ENABLED
const scripting::Service * BaseMechanics::scripts() const const scripting::Service * BaseMechanics::scripts() const
{ {
return VLC->scripts(); //todo: redirect return VLC->scripts(); //todo: redirect
} }
#endif
const Service * BaseMechanics::spells() const const Service * BaseMechanics::spells() const
{ {

View File

@ -35,10 +35,12 @@ namespace vstd
class RNG; class RNG;
} }
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class Service; class Service;
} }
#endif
///callback to be provided by server ///callback to be provided by server
@ -238,7 +240,9 @@ public:
//Global environment facade //Global environment facade
virtual const CreatureService * creatures() const = 0; virtual const CreatureService * creatures() const = 0;
#if SCRIPTING_ENABLED
virtual const scripting::Service * scripts() const = 0; virtual const scripting::Service * scripts() const = 0;
#endif
virtual const Service * spells() const = 0; virtual const Service * spells() const = 0;
virtual const IGameInfoCallback * game() const = 0; virtual const IGameInfoCallback * game() const = 0;
@ -296,7 +300,9 @@ public:
std::vector<AimType> getTargetTypes() const override; std::vector<AimType> getTargetTypes() const override;
const CreatureService * creatures() const override; const CreatureService * creatures() const override;
#if SCRIPTING_ENABLED
const scripting::Service * scripts() const override; const scripting::Service * scripts() const override;
#endif
const Service * spells() const override; const Service * spells() const override;
const IGameInfoCallback * game() const override; const IGameInfoCallback * game() const override;

View File

@ -1652,7 +1652,9 @@ CGameHandler::~CGameHandler()
void CGameHandler::reinitScripting() void CGameHandler::reinitScripting()
{ {
serverEventBus = make_unique<events::EventBus>(); serverEventBus = make_unique<events::EventBus>();
#if SCRIPTING_ENABLED
serverScripts.reset(new scripting::PoolImpl(this, spellEnv)); serverScripts.reset(new scripting::PoolImpl(this, spellEnv));
#endif
} }
void CGameHandler::init(StartInfo *si) void CGameHandler::init(StartInfo *si)
@ -2112,7 +2114,9 @@ void CGameHandler::run(bool resume)
logGlobal->info(sbuffer.str()); logGlobal->info(sbuffer.str());
} }
#if SCRIPTING_ENABLED
services()->scripts()->run(serverScripts); services()->scripts()->run(serverScripts);
#endif
if(resume) if(resume)
events::GameResumed::defaultExecute(serverEventBus.get()); events::GameResumed::defaultExecute(serverEventBus.get());
@ -7319,15 +7323,17 @@ CRandomGenerator & CGameHandler::getRandomGenerator()
return CRandomGenerator::getDefault(); return CRandomGenerator::getDefault();
} }
#if SCRIPTING_ENABLED
scripting::Pool * CGameHandler::getGlobalContextPool() const scripting::Pool * CGameHandler::getGlobalContextPool() const
{ {
return serverScripts.get(); return serverScripts.get();
} }
scripting::Pool * CGameHandler::getContextPool() const scripting::Pool * CGameHandler::getContextPool() const
{ {
return serverScripts.get(); return serverScripts.get();
} }
#endif
const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos) const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos)
{ {

View File

@ -34,10 +34,12 @@ class IMarket;
class SpellCastEnvironment; class SpellCastEnvironment;
#if SCRIPTING_ENABLED
namespace scripting namespace scripting
{ {
class PoolImpl; class PoolImpl;
} }
#endif
template<typename T> class CApplier; template<typename T> class CApplier;
@ -274,12 +276,14 @@ public:
h & finishingBattle; h & finishingBattle;
h & getRandomGenerator(); h & getRandomGenerator();
#if SCRIPTING_ENABLED
JsonNode scriptsState; JsonNode scriptsState;
if(h.saving) if(h.saving)
serverScripts->serializeState(h.saving, scriptsState); serverScripts->serializeState(h.saving, scriptsState);
h & scriptsState; h & scriptsState;
if(!h.saving) if(!h.saving)
serverScripts->serializeState(h.saving, scriptsState); serverScripts->serializeState(h.saving, scriptsState);
#endif
} }
void sendMessageToAll(const std::string &message); void sendMessageToAll(const std::string &message);
@ -326,13 +330,17 @@ public:
CRandomGenerator & getRandomGenerator(); CRandomGenerator & getRandomGenerator();
#if SCRIPTING_ENABLED
scripting::Pool * getGlobalContextPool() const override; scripting::Pool * getGlobalContextPool() const override;
scripting::Pool * getContextPool() const override; scripting::Pool * getContextPool() const override;
#endif
friend class CVCMIServer; friend class CVCMIServer;
private: private:
std::unique_ptr<events::EventBus> serverEventBus; std::unique_ptr<events::EventBus> serverEventBus;
#if SCRIPTING_ENABLED
std::shared_ptr<scripting::PoolImpl> serverScripts; std::shared_ptr<scripting::PoolImpl> serverScripts;
#endif
void reinitScripting(); void reinitScripting();