1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 03:53:54 +00:00

Use static object to register classes

This commit is contained in:
elsid 2022-04-04 02:44:53 +02:00
parent 43057dbb68
commit dc20e799e1
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
46 changed files with 252 additions and 245 deletions

View file

@ -28,6 +28,10 @@
namespace MWClass
{
Activator::Activator()
: MWWorld::RegisteredClass<Activator>(ESM::Activator::sRecordId)
{
}
void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -84,13 +88,6 @@ namespace MWClass
return ref->mBase->mScript;
}
void Activator::registerSelf()
{
std::shared_ptr<Class> instance (new Activator);
registerClass (ESM::Activator::sRecordId, instance);
}
bool Activator::hasToolTip (const MWWorld::ConstPtr& ptr) const
{
return !getName(ptr).empty();

View file

@ -1,19 +1,21 @@
#ifndef GAME_MWCLASS_ACTIVATOR_H
#define GAME_MWCLASS_ACTIVATOR_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Activator : public MWWorld::Class
class Activator final : public MWWorld::RegisteredClass<Activator>
{
friend MWWorld::RegisteredClass<Activator>;
Activator();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
static int getSndGenTypeFromName(const std::string &name);
public:
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
@ -36,8 +38,6 @@ namespace MWClass
std::shared_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override;
///< Generate action for activation
static void registerSelf();
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
bool useAnim() const override;

View file

@ -17,7 +17,7 @@ namespace MWClass
{
protected:
Actor() = default;
explicit Actor(unsigned type) : Class(type) {}
template <class GMST>
float getSwimSpeedImpl(const MWWorld::Ptr& ptr, const GMST& gmst, const MWMechanics::MagicEffects& mageffects, float baseSpeed) const

View file

@ -18,6 +18,10 @@
namespace MWClass
{
Apparatus::Apparatus()
: MWWorld::RegisteredClass<Apparatus>(ESM::Apparatus::sRecordId)
{
}
void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -65,13 +69,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Apparatus::registerSelf()
{
std::shared_ptr<Class> instance (new Apparatus);
registerClass (ESM::Apparatus::sRecordId, instance);
}
std::string Apparatus::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Apparatus Up");

View file

@ -1,12 +1,15 @@
#ifndef GAME_MWCLASS_APPARATUS_H
#define GAME_MWCLASS_APPARATUS_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Apparatus : public MWWorld::Class
class Apparatus : public MWWorld::RegisteredClass<Apparatus>
{
friend MWWorld::RegisteredClass<Apparatus>;
Apparatus();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
@ -33,8 +36,6 @@ namespace MWClass
MWGui::ToolTipInfo getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const override;
///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -26,6 +26,10 @@
namespace MWClass
{
Armor::Armor()
: MWWorld::RegisteredClass<Armor>(ESM::Armor::sRecordId)
{
}
void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -159,13 +163,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Armor::registerSelf()
{
std::shared_ptr<Class> instance (new Armor);
registerClass (ESM::Armor::sRecordId, instance);
}
std::string Armor::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
int es = getEquipmentSkill(ptr);

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_ARMOR_H
#define GAME_MWCLASS_ARMOR_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Armor : public MWWorld::Class
class Armor : public MWWorld::RegisteredClass<Armor>
{
friend MWWorld::RegisteredClass<Armor>;
Armor();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -46,8 +50,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -7,6 +7,10 @@
namespace MWClass
{
BodyPart::BodyPart()
: MWWorld::RegisteredClass<BodyPart>(ESM::BodyPart::sRecordId)
{
}
MWWorld::Ptr BodyPart::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
{
@ -32,13 +36,6 @@ namespace MWClass
return false;
}
void BodyPart::registerSelf()
{
std::shared_ptr<MWWorld::Class> instance (new BodyPart);
registerClass (ESM::BodyPart::sRecordId, instance);
}
std::string BodyPart::getModel(const MWWorld::ConstPtr &ptr) const
{
const MWWorld::LiveCellRef<ESM::BodyPart> *ref = ptr.get<ESM::BodyPart>();

View file

@ -1,13 +1,17 @@
#ifndef GAME_MWCLASS_BODYPART_H
#define GAME_MWCLASS_BODYPART_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class BodyPart : public MWWorld::Class
class BodyPart : public MWWorld::RegisteredClass<BodyPart>
{
friend MWWorld::RegisteredClass<BodyPart>;
BodyPart();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -21,8 +25,6 @@ namespace MWClass
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;
///< @return true if this object has a tooltip when focused (default implementation: true)
static void registerSelf();
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
};

View file

@ -23,6 +23,10 @@
namespace MWClass
{
Book::Book()
: MWWorld::RegisteredClass<Book>(ESM::Book::sRecordId)
{
}
void Book::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -82,13 +86,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Book::registerSelf()
{
std::shared_ptr<Class> instance (new Book);
registerClass (ESM::Book::sRecordId, instance);
}
std::string Book::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Book Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_BOOK_H
#define GAME_MWCLASS_BOOK_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Book : public MWWorld::Class
class Book : public MWWorld::RegisteredClass<Book>
{
friend MWWorld::RegisteredClass<Book>;
Book();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -30,8 +34,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -21,6 +21,10 @@
namespace MWClass
{
Clothing::Clothing()
: MWWorld::RegisteredClass<Clothing>(ESM::Clothing::sRecordId)
{
}
void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -117,13 +121,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Clothing::registerSelf()
{
std::shared_ptr<Class> instance (new Clothing);
registerClass (ESM::Clothing::sRecordId, instance);
}
std::string Clothing::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_CLOTHING_H
#define GAME_MWCLASS_CLOTHING_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Clothing : public MWWorld::Class
class Clothing : public MWWorld::RegisteredClass<Clothing>
{
friend MWWorld::RegisteredClass<Clothing>;
Clothing();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -38,8 +42,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -54,8 +54,9 @@ namespace MWClass
}
Container::Container()
: MWWorld::RegisteredClass<Container>(ESM::Container::sRecordId)
, mHarvestEnabled(Settings::Manager::getBool("graphic herbalism", "Game"))
{
mHarvestEnabled = Settings::Manager::getBool("graphic herbalism", "Game");
}
void Container::ensureCustomData (const MWWorld::Ptr& ptr) const
@ -236,13 +237,6 @@ namespace MWClass
return ref->mBase->mScript;
}
void Container::registerSelf()
{
std::shared_ptr<Class> instance (new Container);
registerClass (ESM::Container::sRecordId, instance);
}
bool Container::hasToolTip (const MWWorld::ConstPtr& ptr) const
{
if (const MWWorld::CustomData* data = ptr.getRefData().getCustomData())

View file

@ -1,7 +1,7 @@
#ifndef GAME_MWCLASS_CONTAINER_H
#define GAME_MWCLASS_CONTAINER_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/customdata.hpp"
@ -26,9 +26,13 @@ namespace MWClass
friend class Container;
};
class Container : public MWWorld::Class
class Container : public MWWorld::RegisteredClass<Container>
{
bool mHarvestEnabled;
friend MWWorld::RegisteredClass<Container>;
const bool mHarvestEnabled;
Container();
void ensureCustomData (const MWWorld::Ptr& ptr) const;
@ -37,8 +41,6 @@ namespace MWClass
bool canBeHarvested(const MWWorld::ConstPtr& ptr) const;
public:
Container();
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
@ -81,8 +83,6 @@ namespace MWClass
void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const override;
///< Write additional state from \a ptr into \a state.
static void registerSelf();
void respawn (const MWWorld::Ptr& ptr) const override;
std::string getModel(const MWWorld::ConstPtr &ptr) const override;

View file

@ -78,6 +78,11 @@ namespace MWClass
{
}
Creature::Creature()
: MWWorld::RegisteredClass<Creature, Actor>(ESM::Creature::sRecordId)
{
}
const Creature::GMST& Creature::getGmst()
{
static const GMST staticGmst = []
@ -496,13 +501,6 @@ namespace MWClass
return isFlagBitSet(ptr, ESM::Creature::Essential);
}
void Creature::registerSelf()
{
std::shared_ptr<Class> instance (new Creature);
registerClass (ESM::Creature::sRecordId, instance);
}
float Creature::getMaxSpeed(const MWWorld::Ptr &ptr) const
{
const MWMechanics::CreatureStats& stats = getCreatureStats(ptr);

View file

@ -1,6 +1,8 @@
#ifndef GAME_MWCLASS_CREATURE_H
#define GAME_MWCLASS_CREATURE_H
#include "../mwworld/registeredclass.hpp"
#include "actor.hpp"
namespace ESM
@ -10,8 +12,12 @@ namespace ESM
namespace MWClass
{
class Creature : public Actor
class Creature : public MWWorld::RegisteredClass<Creature, Actor>
{
friend MWWorld::RegisteredClass<Creature, Actor>;
Creature();
void ensureCustomData (const MWWorld::Ptr& ptr) const;
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
@ -96,8 +102,6 @@ namespace MWClass
float getMaxSpeed (const MWWorld::Ptr& ptr) const override;
static void registerSelf();
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
void getModelsToPreload(const MWWorld::Ptr& ptr, std::vector<std::string>& models) const override;

View file

@ -28,6 +28,11 @@ namespace MWClass
}
};
CreatureLevList::CreatureLevList()
: MWWorld::RegisteredClass<CreatureLevList>(ESM::CreatureLevList::sRecordId)
{
}
MWWorld::Ptr CreatureLevList::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
{
const MWWorld::LiveCellRef<ESM::CreatureLevList> *ref = ptr.get<ESM::CreatureLevList>();
@ -91,13 +96,6 @@ namespace MWClass
customData.mSpawn = true;
}
void CreatureLevList::registerSelf()
{
std::shared_ptr<Class> instance (new CreatureLevList);
registerClass (ESM::CreatureLevList::sRecordId, instance);
}
void CreatureLevList::getModelsToPreload(const MWWorld::Ptr &ptr, std::vector<std::string> &models) const
{
// disable for now, too many false positives

View file

@ -1,13 +1,17 @@
#ifndef GAME_MWCLASS_CREATURELEVLIST_H
#define GAME_MWCLASS_CREATURELEVLIST_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class CreatureLevList : public MWWorld::Class
class CreatureLevList : public MWWorld::RegisteredClass<CreatureLevList>
{
void ensureCustomData (const MWWorld::Ptr& ptr) const;
friend MWWorld::RegisteredClass<CreatureLevList>;
CreatureLevList();
void ensureCustomData (const MWWorld::Ptr& ptr) const;
public:
@ -17,8 +21,6 @@ namespace MWClass
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;
///< @return true if this object has a tooltip when focused (default implementation: true)
static void registerSelf();
void getModelsToPreload(const MWWorld::Ptr& ptr, std::vector<std::string>& models) const override;
///< Get a list of models to preload that this object may use (directly or indirectly). default implementation: list getModel().

View file

@ -46,6 +46,11 @@ namespace MWClass
}
};
Door::Door()
: MWWorld::RegisteredClass<Door>(ESM::Door::sRecordId)
{
}
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
if (!model.empty())
@ -259,13 +264,6 @@ namespace MWClass
return ref->mBase->mScript;
}
void Door::registerSelf()
{
std::shared_ptr<Class> instance (new Door);
registerClass (ESM::Door::sRecordId, instance);
}
MWGui::ToolTipInfo Door::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
{
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();

View file

@ -3,12 +3,16 @@
#include <components/esm3/loaddoor.hpp>
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Door : public MWWorld::Class
class Door : public MWWorld::RegisteredClass<Door>
{
friend MWWorld::RegisteredClass<Door>;
Door();
void ensureCustomData (const MWWorld::Ptr& ptr) const;
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
@ -46,8 +50,6 @@ namespace MWClass
std::string getScript (const MWWorld::ConstPtr& ptr) const override;
///< Return name of the script attached to ptr
static void registerSelf();
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
MWWorld::DoorState getDoorState (const MWWorld::ConstPtr &ptr) const override;

View file

@ -20,6 +20,10 @@
namespace MWClass
{
Ingredient::Ingredient()
: MWWorld::RegisteredClass<Ingredient>(ESM::Ingredient::sRecordId)
{
}
void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -77,13 +81,6 @@ namespace MWClass
return action;
}
void Ingredient::registerSelf()
{
std::shared_ptr<Class> instance (new Ingredient);
registerClass (ESM::Ingredient::sRecordId, instance);
}
std::string Ingredient::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Ingredient Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_INGREDIENT_H
#define GAME_MWCLASS_INGREDIENT_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Ingredient : public MWWorld::Class
class Ingredient : public MWWorld::RegisteredClass<Ingredient>
{
friend MWWorld::RegisteredClass<Ingredient>;
Ingredient();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -32,8 +36,6 @@ namespace MWClass
std::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
///< Generate action for using via inventory menu
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -4,6 +4,10 @@
namespace MWClass
{
ItemLevList::ItemLevList()
: MWWorld::RegisteredClass<ItemLevList>(ESM::ItemLevList::sRecordId)
{
}
std::string ItemLevList::getName (const MWWorld::ConstPtr& ptr) const
{
@ -14,11 +18,4 @@ namespace MWClass
{
return false;
}
void ItemLevList::registerSelf()
{
std::shared_ptr<Class> instance (new ItemLevList);
registerClass (ESM::ItemLevList::sRecordId, instance);
}
}

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_ITEMLEVLIST_H
#define GAME_MWCLASS_ITEMLEVLIST_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class ItemLevList : public MWWorld::Class
class ItemLevList : public MWWorld::RegisteredClass<ItemLevList>
{
friend MWWorld::RegisteredClass<ItemLevList>;
ItemLevList();
public:
std::string getName (const MWWorld::ConstPtr& ptr) const override;
@ -14,8 +18,6 @@ namespace MWClass
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;
///< @return true if this object has a tooltip when focused (default implementation: true)
static void registerSelf();
};
}

View file

@ -23,6 +23,10 @@
namespace MWClass
{
Light::Light()
: MWWorld::RegisteredClass<Light>(ESM::Light::sRecordId)
{
}
void Light::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -120,13 +124,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Light::registerSelf()
{
std::shared_ptr<Class> instance (new Light);
registerClass (ESM::Light::sRecordId, instance);
}
std::string Light::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Misc Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_LIGHT_H
#define GAME_MWCLASS_LIGHT_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Light : public MWWorld::Class
class Light : public MWWorld::RegisteredClass<Light>
{
friend MWWorld::RegisteredClass<Light>;
Light();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -44,8 +48,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -20,6 +20,10 @@
namespace MWClass
{
Lockpick::Lockpick()
: MWWorld::RegisteredClass<Lockpick>(ESM::Lockpick::sRecordId)
{
}
void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -76,13 +80,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Lockpick::registerSelf()
{
std::shared_ptr<Class> instance (new Lockpick);
registerClass (ESM::Lockpick::sRecordId, instance);
}
std::string Lockpick::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Lockpick Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_LOCKPICK_H
#define GAME_MWCLASS_LOCKPICK_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Lockpick : public MWWorld::Class
class Lockpick : public MWWorld::RegisteredClass<Lockpick>
{
friend MWWorld::RegisteredClass<Lockpick>;
Lockpick();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -34,8 +38,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -21,6 +21,11 @@
namespace MWClass
{
Miscellaneous::Miscellaneous()
: MWWorld::RegisteredClass<Miscellaneous>(ESM::Miscellaneous::sRecordId)
{
}
bool Miscellaneous::isGold (const MWWorld::ConstPtr& ptr) const
{
return Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_001")
@ -102,13 +107,6 @@ namespace MWClass
return value;
}
void Miscellaneous::registerSelf()
{
std::shared_ptr<Class> instance (new Miscellaneous);
registerClass (ESM::Miscellaneous::sRecordId, instance);
}
std::string Miscellaneous::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
if (isGold(ptr))

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_MISC_H
#define GAME_MWCLASS_MISC_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Miscellaneous : public MWWorld::Class
class Miscellaneous : public MWWorld::RegisteredClass<Miscellaneous>
{
friend MWWorld::RegisteredClass<Miscellaneous>;
Miscellaneous();
public:
MWWorld::Ptr copyToCell(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell, int count) const override;
@ -30,8 +34,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -245,6 +245,10 @@ namespace
namespace MWClass
{
Npc::Npc()
: MWWorld::RegisteredClass<Npc, Actor>(ESM::NPC::sRecordId)
{
}
class NpcCustomData : public MWWorld::TypedCustomData<NpcCustomData>
{
@ -1039,12 +1043,6 @@ namespace MWClass
return (ref->mBase->mFlags & ESM::NPC::Essential) != 0;
}
void Npc::registerSelf()
{
std::shared_ptr<Class> instance (new Npc);
registerClass (ESM::NPC::sRecordId, instance);
}
bool Npc::hasToolTip(const MWWorld::ConstPtr& ptr) const
{
if (!ptr.getRefData().getCustomData() || MWBase::Environment::get().getWindowManager()->isGuiMode())

View file

@ -1,6 +1,8 @@
#ifndef GAME_MWCLASS_NPC_H
#define GAME_MWCLASS_NPC_H
#include "../mwworld/registeredclass.hpp"
#include "actor.hpp"
namespace ESM
@ -10,8 +12,12 @@ namespace ESM
namespace MWClass
{
class Npc : public Actor
class Npc : public MWWorld::RegisteredClass<Npc, Actor>
{
friend MWWorld::RegisteredClass<Npc, Actor>;
Npc();
void ensureCustomData (const MWWorld::Ptr& ptr) const;
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
@ -125,8 +131,6 @@ namespace MWClass
std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const override;
static void registerSelf();
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
float getSkill(const MWWorld::Ptr& ptr, int skill) const override;

View file

@ -22,6 +22,10 @@
namespace MWClass
{
Potion::Potion()
: MWWorld::RegisteredClass<Potion>(ESM::Potion::sRecordId)
{
}
void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -70,13 +74,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Potion::registerSelf()
{
std::shared_ptr<Class> instance (new Potion);
registerClass (ESM::Potion::sRecordId, instance);
}
std::string Potion::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Potion Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_POTION_H
#define GAME_MWCLASS_POTION_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Potion : public MWWorld::Class
class Potion : public MWWorld::RegisteredClass<Potion>
{
friend MWWorld::RegisteredClass<Potion>;
Potion();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -33,8 +37,6 @@ namespace MWClass
std::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
///< Generate action for using via inventory menu
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -20,6 +20,10 @@
namespace MWClass
{
Probe::Probe()
: MWWorld::RegisteredClass<Probe>(ESM::Probe::sRecordId)
{
}
void Probe::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -76,13 +80,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Probe::registerSelf()
{
std::shared_ptr<Class> instance (new Probe);
registerClass (ESM::Probe::sRecordId, instance);
}
std::string Probe::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Probe Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_PROBE_H
#define GAME_MWCLASS_PROBE_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Probe : public MWWorld::Class
class Probe : public MWWorld::RegisteredClass<Probe>
{
friend MWWorld::RegisteredClass<Probe>;
Probe();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -34,8 +38,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -17,6 +17,10 @@
namespace MWClass
{
Repair::Repair()
: MWWorld::RegisteredClass<Repair>(ESM::Repair::sRecordId)
{
}
void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -65,13 +69,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Repair::registerSelf()
{
std::shared_ptr<Class> instance (new Repair);
registerClass (ESM::Repair::sRecordId, instance);
}
std::string Repair::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
return std::string("Item Repair Up");

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_REPAIR_H
#define GAME_MWCLASS_REPAIR_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Repair : public MWWorld::Class
class Repair : public MWWorld::RegisteredClass<Repair>
{
friend MWWorld::RegisteredClass<Repair>;
Repair();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -30,8 +34,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -13,6 +13,10 @@
namespace MWClass
{
Static::Static()
: MWWorld::RegisteredClass<Static>(ESM::Static::sRecordId)
{
}
void Static::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -54,13 +58,6 @@ namespace MWClass
return false;
}
void Static::registerSelf()
{
std::shared_ptr<Class> instance (new Static);
registerClass (ESM::Static::sRecordId, instance);
}
MWWorld::Ptr Static::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
{
const MWWorld::LiveCellRef<ESM::Static> *ref = ptr.get<ESM::Static>();

View file

@ -1,12 +1,16 @@
#ifndef GAME_MWCLASS_STATIC_H
#define GAME_MWCLASS_STATIC_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Static : public MWWorld::Class
class Static : public MWWorld::RegisteredClass<Static>
{
friend MWWorld::RegisteredClass<Static>;
Static();
MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
@ -23,8 +27,6 @@ namespace MWClass
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;
///< @return true if this object has a tooltip when focused (default implementation: true)
static void registerSelf();
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
};
}

View file

@ -26,6 +26,10 @@
namespace MWClass
{
Weapon::Weapon()
: MWWorld::RegisteredClass<Weapon>(ESM::Weapon::sRecordId)
{
}
void Weapon::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
@ -121,13 +125,6 @@ namespace MWClass
return ref->mBase->mData.mValue;
}
void Weapon::registerSelf()
{
std::shared_ptr<Class> instance (new Weapon);
registerClass (ESM::Weapon::sRecordId, instance);
}
std::string Weapon::getUpSoundId (const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();

View file

@ -1,16 +1,19 @@
#ifndef GAME_MWCLASS_WEAPON_H
#define GAME_MWCLASS_WEAPON_H
#include "../mwworld/class.hpp"
#include "../mwworld/registeredclass.hpp"
namespace MWClass
{
class Weapon : public MWWorld::Class
class Weapon : public MWWorld::RegisteredClass<Weapon>
{
friend MWWorld::RegisteredClass<Weapon>;
MWWorld::Ptr
copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override;
public:
Weapon();
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
@ -45,8 +48,6 @@ namespace MWClass
int getValue (const MWWorld::ConstPtr& ptr) const override;
///< Return trade value of the object. Throws an exception, if the object can't be traded.
static void registerSelf();
std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override;
///< Return the pick up sound Id

View file

@ -21,7 +21,11 @@
namespace MWWorld
{
std::map<unsigned int, std::shared_ptr<Class> > Class::sClasses;
std::map<unsigned, Class*>& Class::getClasses()
{
static std::map<unsigned, Class*> values;
return values;
}
void Class::insertObjectRendering (const Ptr& ptr, const std::string& mesh, MWRender::RenderingInterface& renderingInterface) const
{
@ -228,9 +232,10 @@ namespace MWWorld
const Class& Class::get (unsigned int key)
{
auto iter = sClasses.find (key);
const auto& classes = getClasses();
auto iter = classes.find(key);
if (iter==sClasses.end())
if (iter == classes.end())
throw std::logic_error ("Class::get(): unknown class key: " + std::to_string(key));
return *iter->second;
@ -241,10 +246,9 @@ namespace MWWorld
throw std::runtime_error ("class does not support persistence");
}
void Class::registerClass(unsigned int key, std::shared_ptr<Class> instance)
void Class::registerClass(Class& instance)
{
instance->mType = key;
sClasses.insert(std::make_pair(key, instance));
getClasses().emplace(instance.getType(), &instance);
}
std::string Class::getUpSoundId (const ConstPtr& ptr) const

View file

@ -54,12 +54,13 @@ namespace MWWorld
/// \brief Base class for referenceable esm records
class Class
{
static std::map<unsigned int, std::shared_ptr<Class> > sClasses;
unsigned int mType;
const unsigned mType;
static std::map<unsigned, Class*>& getClasses();
protected:
Class() = default;
explicit Class(unsigned type) : mType(type) {}
std::shared_ptr<Action> defaultItemActivate(const Ptr &ptr, const Ptr &actor) const;
///< Generate default action for activating inventory items
@ -340,7 +341,7 @@ namespace MWWorld
static const Class& get (unsigned int key);
///< If there is no class for this \a key, an exception is thrown.
static void registerClass (unsigned int key, std::shared_ptr<Class> instance);
static void registerClass(Class& instance);
virtual int getBaseGold(const MWWorld::ConstPtr& ptr) const;

View file

@ -0,0 +1,23 @@
#ifndef GAME_MWWORLD_REGISTEREDCLASS_H
#define GAME_MWWORLD_REGISTEREDCLASS_H
#include "class.hpp"
namespace MWWorld
{
template <class Derived, class Base = Class>
class RegisteredClass : public Base
{
public:
static void registerSelf()
{
static Derived instance;
Base::registerClass(instance);
}
protected:
explicit RegisteredClass(unsigned type) : Base(type) {}
};
}
#endif