forked from teamnwah/openmw-tes3coop
added foundation for esm record class hierarchy
This commit is contained in:
parent
b584215680
commit
a70c3876a2
9 changed files with 148 additions and 15 deletions
|
@ -79,6 +79,9 @@ source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER})
|
|||
set(GAMEWORLD
|
||||
mwworld/world.cpp
|
||||
mwworld/globals.cpp
|
||||
mwworld/class.cpp
|
||||
mwworld/classes.cpp
|
||||
mwworld/activator.cpp
|
||||
)
|
||||
set(GAMEWORLD_HEADER
|
||||
mwworld/refdata.hpp
|
||||
|
@ -86,6 +89,9 @@ set(GAMEWORLD_HEADER
|
|||
mwworld/ptr.hpp
|
||||
mwworld/environment.hpp
|
||||
mwworld/globals.hpp
|
||||
mwworld/class.hpp
|
||||
mwworld/classes.hpp
|
||||
mwworld/activator.hpp
|
||||
)
|
||||
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "mwworld/world.hpp"
|
||||
#include "mwworld/ptr.hpp"
|
||||
#include "mwworld/environment.hpp"
|
||||
#include "mwworld/classes.hpp"
|
||||
|
||||
#include "mwmechanics/mechanicsmanager.hpp"
|
||||
|
||||
|
@ -78,6 +79,7 @@ OMW::Engine::Engine()
|
|||
, mScriptManager (0)
|
||||
, mScriptContext (0)
|
||||
{
|
||||
MWWorld::registerClasses();
|
||||
}
|
||||
|
||||
OMW::Engine::~Engine()
|
||||
|
|
14
apps/openmw/mwworld/activator.cpp
Normal file
14
apps/openmw/mwworld/activator.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
#include "activator.hpp"
|
||||
|
||||
#include <components/esm/loadacti.hpp>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
void Activator::registerSelf()
|
||||
{
|
||||
boost::shared_ptr<Class> instance (new Activator);
|
||||
|
||||
registerClass (typeid (ESM::Activator).name(), instance);
|
||||
}
|
||||
}
|
17
apps/openmw/mwworld/activator.hpp
Normal file
17
apps/openmw/mwworld/activator.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef GAME_MWWORLD_ACTIVATOR_H
|
||||
#define GAME_MWWORLD_ACTIVATOR_H
|
||||
|
||||
#include "class.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Activator : public Class
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
static void registerSelf();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
28
apps/openmw/mwworld/class.cpp
Normal file
28
apps/openmw/mwworld/class.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
#include "class.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
std::map<std::string, boost::shared_ptr<Class> > Class::sClasses;
|
||||
|
||||
Class::Class() {}
|
||||
|
||||
Class::~Class() {}
|
||||
|
||||
const Class& Class::get (const std::string& key)
|
||||
{
|
||||
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
||||
|
||||
if (iter==sClasses.end())
|
||||
throw std::logic_error ("unknown class key: " + key);
|
||||
|
||||
return *iter->second;
|
||||
}
|
||||
|
||||
void Class::registerClass (const std::string& key, boost::shared_ptr<Class> instance)
|
||||
{
|
||||
sClasses.insert (std::make_pair (key, instance));
|
||||
}
|
||||
}
|
37
apps/openmw/mwworld/class.hpp
Normal file
37
apps/openmw/mwworld/class.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef GAME_MWWORLD_CLASS_H
|
||||
#define GAME_MWWORLD_CLASS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
/// \brief Base class for referenceable esm records
|
||||
class Class
|
||||
{
|
||||
static std::map<std::string, boost::shared_ptr<Class> > sClasses;
|
||||
|
||||
// not implemented
|
||||
Class (const Class&);
|
||||
Class& operator= (const Class&);
|
||||
|
||||
protected:
|
||||
|
||||
Class();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Class();
|
||||
|
||||
|
||||
|
||||
static const Class& get (const std::string& key);
|
||||
///< If there is no class for this \a key, an exception is thrown.
|
||||
|
||||
static void registerClass (const std::string& key, boost::shared_ptr<Class> instance);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
12
apps/openmw/mwworld/classes.cpp
Normal file
12
apps/openmw/mwworld/classes.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
#include "classes.hpp"
|
||||
|
||||
#include "activator.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
void registerClasses()
|
||||
{
|
||||
Activator::registerSelf();
|
||||
}
|
||||
}
|
10
apps/openmw/mwworld/classes.hpp
Normal file
10
apps/openmw/mwworld/classes.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef GAME_MWWORLD_CLASSES_H
|
||||
#define GAME_MWWORLD_CLASSES_H
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
void registerClasses();
|
||||
///< register all known classes
|
||||
}
|
||||
|
||||
#endif
|
|
@ -27,6 +27,7 @@ namespace MWWorld
|
|||
ESM::CellRef *mCellRef;
|
||||
RefData *mRefData;
|
||||
CellStore *mCell;
|
||||
std::string mTypeName;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -43,6 +44,11 @@ namespace MWWorld
|
|||
return mPtr.type();
|
||||
}
|
||||
|
||||
const std::string& getTypeName() const
|
||||
{
|
||||
return mTypeName;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr (ESMS::LiveCellRef<T, RefData> *liveCellRef, CellStore *cell)
|
||||
{
|
||||
|
@ -50,6 +56,7 @@ namespace MWWorld
|
|||
mCellRef = &liveCellRef->ref;
|
||||
mRefData = &liveCellRef->mData;
|
||||
mCell = cell;
|
||||
mTypeName = typeid (T).name();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Reference in a new issue