1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Removed magical initialization of registry via static variables

This commit is contained in:
Ivan Savenko 2023-04-08 21:29:04 +03:00
parent 1590c710dd
commit 84af64ce6b
16 changed files with 36 additions and 75 deletions

View File

@ -12,7 +12,9 @@
#include "../lib/NetPackVisitor.h"
class CClient;
VCMI_LIB_NAMESPACE_BEGIN
class CGameState;
VCMI_LIB_NAMESPACE_END
class ApplyOnLobbyHandlerNetPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor)
{

View File

@ -23,15 +23,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:catapult";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Catapult, EFFECT_NAME);
bool Catapult::applicable(Problem & problem, const Mechanics * m) const
{
const auto *town = m->battle()->battleGetDefendedTown();

View File

@ -19,15 +19,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:clone";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Clone, EFFECT_NAME);
void Clone::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{
for(const Destination & dest : target)

View File

@ -22,15 +22,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:damage";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Damage, EFFECT_NAME);
void Damage::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{
StacksInjured stacksInjured;

View File

@ -19,15 +19,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:demonSummon";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(DemonSummon, EFFECT_NAME);
void DemonSummon::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{
BattleUnitsChanged pack;

View File

@ -23,15 +23,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:dispel";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Dispel, EFFECT_NAME);
void Dispel::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{
const bool describe = server->describeChanges();

View File

@ -35,9 +35,6 @@ class Effects;
class Effect;
class Registry;
template<typename F>
class RegisterEffect;
using TargetType = spells::AimType;
class DLL_LINKAGE Effect

View File

@ -22,16 +22,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:heal";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Heal, EFFECT_NAME);
void Heal::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{
apply(m->getEffectValue(), server, m, target);

View File

@ -21,15 +21,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:obstacle";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Obstacle, EFFECT_NAME);
using RelativeShape = std::vector<std::vector<BattleHex::EDir>>;
static void serializeRelativeShape(JsonSerializeFormat & handler, const std::string & fieldName, RelativeShape & value)

View File

@ -11,6 +11,23 @@
#include "Registry.h"
#include "Catapult.h"
#include "Clone.h"
#include "Damage.h"
#include "DemonSummon.h"
#include "Dispel.h"
#include "Effect.h"
#include "Effects.h"
#include "Heal.h"
#include "LocationEffect.h"
#include "Obstacle.h"
#include "RemoveObstacle.h"
#include "Sacrifice.h"
#include "Summon.h"
#include "Teleport.h"
#include "Timed.h"
#include "UnitEffect.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace spells
@ -23,6 +40,22 @@ namespace detail
class RegistryImpl : public Registry
{
public:
RegistryImpl()
{
add("core:catapult", std::make_shared<EffectFactory<Catapult>>());
add("core:clone", std::make_shared<EffectFactory<Clone>>());
add("core:damage", std::make_shared<EffectFactory<Damage>>());
add("core:demonSummon", std::make_shared<EffectFactory<DemonSummon>>());
add("core:dispel", std::make_shared<EffectFactory<Dispel>>());
add("core:heal", std::make_shared<EffectFactory<Heal>>());
add("core:obstacle", std::make_shared<EffectFactory<Obstacle>>());
add("core:removeObstacle", std::make_shared<EffectFactory<RemoveObstacle>>());
add("core:sacrifice", std::make_shared<EffectFactory<Sacrifice>>());
add("core:summon", std::make_shared<EffectFactory<Summon>>());
add("core:teleport", std::make_shared<EffectFactory<Teleport>>());
add("core:timed", std::make_shared<EffectFactory<Timed>>());
}
const IEffectFactory * find(const std::string & name) const override
{
auto iter = data.find(name);

View File

@ -12,13 +12,6 @@
#include "Effect.h"
#define VCMI_REGISTER_SPELL_EFFECT(Type, Name) \
namespace\
{\
RegisterEffect<Type> register ## Type(Name);\
}\
\
VCMI_LIB_NAMESPACE_BEGIN
namespace spells
@ -60,17 +53,6 @@ public:
}
};
template<typename E>
class RegisterEffect
{
public:
RegisterEffect(const std::string & name)
{
auto f = std::make_shared<EffectFactory<E>>();
GlobalRegistry::get()->add(name, f);
}
};
}
}

View File

@ -22,15 +22,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:removeObstacle";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(RemoveObstacle, EFFECT_NAME);
bool RemoveObstacle::applicable(Problem & problem, const Mechanics * m) const
{
if (getTargets(m, EffectTarget(), true).empty())

View File

@ -21,16 +21,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:sacrifice";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Sacrifice, EFFECT_NAME);
void Sacrifice::adjustTargetTypes(std::vector<TargetType> & types) const
{
if(!types.empty())

View File

@ -24,16 +24,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:summon";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Summon, EFFECT_NAME);
void Summon::adjustAffectedHexes(std::set<BattleHex> & hexes, const Mechanics * m, const Target & spellTarget) const
{
//no hexes affected

View File

@ -18,16 +18,10 @@
VCMI_LIB_NAMESPACE_BEGIN
//TODO: Teleport effect
static const std::string EFFECT_NAME = "core:teleport";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Teleport, EFFECT_NAME);
void Teleport::adjustTargetTypes(std::vector<TargetType> & types) const
{

View File

@ -20,15 +20,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static const std::string EFFECT_NAME = "core:timed";
namespace spells
{
namespace effects
{
VCMI_REGISTER_SPELL_EFFECT(Timed, EFFECT_NAME);
static void describeEffect(std::vector<MetaString> & log, const Mechanics * m, const std::vector<Bonus> & bonuses, const battle::Unit * target)
{
auto addLogLine = [&](const int32_t baseTextID, const boost::logic::tribool & plural)