1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +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/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()
{

View File

@ -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<HypotheticServerCallback> serverCallback;
std::unique_ptr<HypotheticEnvironment> localEnvironment;
#if SCRIPTING_ENABLED
mutable std::shared_ptr<scripting::Pool> pool;
#endif
mutable std::shared_ptr<events::EventBus> eventBus;
};

View File

@ -366,10 +366,12 @@ void CCallback::unregisterBattleInterface(std::shared_ptr<IBattleEventsReceiver>
cl->additionalBattleInts[*player] -= battleEvents;
}
#if SCRIPTING_ENABLED
scripting::Pool * CBattleCallback::getContextPool() const
{
return cl->getGlobalContextPool();
}
#endif
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
bool battleMakeTacticAction(BattleAction * action) override; // performs tactic phase actions
#if SCRIPTING_ENABLED
scripting::Pool * getContextPool() const override;
#endif
friend class CCallback;
friend class CClient;

View File

@ -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")
@ -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 #
############################################
@ -214,6 +219,10 @@ if(NOT WIN32)
endif()
endif()
if(ENABLE_LUA)
add_compile_definitions(SCRIPTING_ENABLED=1)
endif()
############################################
# Finding packages #
############################################

View File

@ -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",

View File

@ -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
{

View File

@ -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;

View File

@ -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";

View File

@ -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<events::EventBus>();
#if SCRIPTING_ENABLED
clientScripts.reset(new scripting::PoolImpl(this));
#endif
}

View File

@ -39,10 +39,12 @@ namespace boost { class thread; }
template<typename T> 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<PlayerColor, std::shared_ptr<CBattleCallback>> battleCallbacks; //callbacks given to player interfaces
std::map<PlayerColor, std::shared_ptr<CPlayerEnvironment>> playerEnvironments;
#if SCRIPTING_ENABLED
std::shared_ptr<scripting::PoolImpl> clientScripts;
#endif
std::unique_ptr<events::EventBus> clientEventBus;
std::shared_ptr<CApplier<CBaseForCLApply>> applier;

View File

@ -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;

View File

@ -10,6 +10,7 @@
#pragma once
#if SCRIPTING_ENABLED
#include <vcmi/Environment.h>
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");
}
#if SCRIPTING_ENABLED
std::shared_ptr<scripting::Module> CDynLibHandler::getNewScriptingModule(const boost::filesystem::path & dllname)
{
return createAny<scripting::Module>(dllname, "GetNewModule");
}
#endif
BattleAction CGlobalAI::activeStack(const CStack * stack)
{

View File

@ -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<CGlobalAI> getNewAI(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);
#endif
};
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("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?
@ -1045,7 +1047,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();

View File

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

View File

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

View File

@ -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);

View File

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

View File

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

View File

@ -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()
{

View File

@ -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 <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
if(!h.saving)
{
scriptsLoaded();
}
#endif
h & heroh;
h & arth;

View File

@ -965,12 +965,14 @@ CGHeroInstance * BattleInfo::battleGetFightingHero(ui8 side) const
return const_cast<CGHeroInstance*>(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)
{

View File

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

View File

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

View File

@ -24,15 +24,19 @@ namespace battle
using UnitFilter = std::function<bool(const Unit *)>;
}
#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;

View File

@ -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
{

View File

@ -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<AimType> 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;

View File

@ -1652,7 +1652,9 @@ CGameHandler::~CGameHandler()
void CGameHandler::reinitScripting()
{
serverEventBus = make_unique<events::EventBus>();
#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)
{

View File

@ -34,10 +34,12 @@ class IMarket;
class SpellCastEnvironment;
#if SCRIPTING_ENABLED
namespace scripting
{
class PoolImpl;
}
#endif
template<typename T> 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<events::EventBus> serverEventBus;
#if SCRIPTING_ENABLED
std::shared_ptr<scripting::PoolImpl> serverScripts;
#endif
void reinitScripting();