1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 07:53:51 +00:00

replaced container store in ref data with new custom data implementation

This commit is contained in:
Marc Zinnschlag 2012-01-27 14:55:58 +01:00
parent b0256cea34
commit c081160591
8 changed files with 63 additions and 73 deletions

View file

@ -6,9 +6,39 @@
#include <components/esm_store/cell_store.hpp> #include <components/esm_store/cell_store.hpp>
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/customdata.hpp"
namespace
{
struct CustomData : public MWWorld::CustomData
{
MWWorld::ContainerStore<MWWorld::RefData> mContainerStore;
virtual MWWorld::CustomData *clone() const;
};
MWWorld::CustomData *CustomData::clone() const
{
return new CustomData (*this);
}
}
namespace MWClass namespace MWClass
{ {
void Container::ensureCustomData (const MWWorld::Ptr& ptr) const
{
if (!ptr.getRefData().getCustomData())
{
std::auto_ptr<CustomData> data (new CustomData);
// \todo add initial container content
// store
ptr.getRefData().setCustomData (data.release());
}
}
void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{ {
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref = ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
@ -50,17 +80,9 @@ namespace MWClass
MWWorld::ContainerStore<MWWorld::RefData>& Container::getContainerStore (const MWWorld::Ptr& ptr) MWWorld::ContainerStore<MWWorld::RefData>& Container::getContainerStore (const MWWorld::Ptr& ptr)
const const
{ {
if (!ptr.getRefData().getContainerStore().get()) ensureCustomData (ptr);
{
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
new MWWorld::ContainerStore<MWWorld::RefData>);
// TODO add initial content return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
ptr.getRefData().getContainerStore() = store;
}
return *ptr.getRefData().getContainerStore();
} }
std::string Container::getScript (const MWWorld::Ptr& ptr) const std::string Container::getScript (const MWWorld::Ptr& ptr) const

View file

@ -8,6 +8,8 @@ namespace MWClass
{ {
class Container : public MWWorld::Class class Container : public MWWorld::Class
{ {
void ensureCustomData (const MWWorld::Ptr& ptr) const;
public: public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;

View file

@ -4,19 +4,20 @@
#include <components/esm/loadcrea.hpp> #include <components/esm/loadcrea.hpp>
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp" #include "../mwworld/actiontalk.hpp"
#include "../mwworld/environment.hpp" #include "../mwworld/environment.hpp"
#include "../mwworld/customdata.hpp" #include "../mwworld/customdata.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
namespace namespace
{ {
struct CustomData : public MWWorld::CustomData struct CustomData : public MWWorld::CustomData
{ {
MWMechanics::CreatureStats mCreatureStats; MWMechanics::CreatureStats mCreatureStats;
MWWorld::ContainerStore<MWWorld::RefData> mContainerStore;
virtual MWWorld::CustomData *clone() const; virtual MWWorld::CustomData *clone() const;
}; };
@ -52,6 +53,8 @@ namespace MWClass
data->mCreatureStats.mLevel = ref->base->data.level; data->mCreatureStats.mLevel = ref->base->data.level;
// \todo add initial container content
// store // store
ptr.getRefData().setCustomData (data.release()); ptr.getRefData().setCustomData (data.release());
} }
@ -67,18 +70,8 @@ namespace MWClass
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{ {
/*ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
ptr.get<ESM::Creature>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{*/
MWRender::Actors& actors = renderingInterface.getActors(); MWRender::Actors& actors = renderingInterface.getActors();
actors.insertCreature(ptr); actors.insertCreature(ptr);
} }
void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
@ -92,7 +85,6 @@ namespace MWClass
if(!model.empty()){ if(!model.empty()){
physics.insertActorPhysics(ptr, "meshes\\" + model); physics.insertActorPhysics(ptr, "meshes\\" + model);
} }
} }
void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
@ -129,17 +121,9 @@ namespace MWClass
MWWorld::ContainerStore<MWWorld::RefData>& Creature::getContainerStore (const MWWorld::Ptr& ptr) MWWorld::ContainerStore<MWWorld::RefData>& Creature::getContainerStore (const MWWorld::Ptr& ptr)
const const
{ {
if (!ptr.getRefData().getContainerStore().get()) ensureCustomData (ptr);
{
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
new MWWorld::ContainerStore<MWWorld::RefData>);
// TODO add initial content return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
ptr.getRefData().getContainerStore() = store;
}
return *ptr.getRefData().getContainerStore();
} }
std::string Creature::getScript (const MWWorld::Ptr& ptr) const std::string Creature::getScript (const MWWorld::Ptr& ptr) const

View file

@ -9,14 +9,14 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/movement.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp" #include "../mwworld/actiontalk.hpp"
#include "../mwworld/environment.hpp" #include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp" #include "../mwworld/world.hpp"
#include "../mwmechanics/movement.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
namespace namespace
{ {
@ -28,6 +28,7 @@ namespace
MWMechanics::NpcStats mNpcStats; MWMechanics::NpcStats mNpcStats;
MWMechanics::CreatureStats mCreatureStats; MWMechanics::CreatureStats mCreatureStats;
MWMechanics::Movement mMovement; MWMechanics::Movement mMovement;
MWWorld::ContainerStore<MWWorld::RefData> mContainerStore;
virtual MWWorld::CustomData *clone() const; virtual MWWorld::CustomData *clone() const;
}; };
@ -74,6 +75,8 @@ namespace MWClass
data->mCreatureStats.mLevel = ref->base->npdt52.level; data->mCreatureStats.mLevel = ref->base->npdt52.level;
// \todo add initial container content
// store // store
ptr.getRefData().setCustomData (data.release()); ptr.getRefData().setCustomData (data.release());
} }
@ -155,17 +158,9 @@ namespace MWClass
MWWorld::ContainerStore<MWWorld::RefData>& Npc::getContainerStore (const MWWorld::Ptr& ptr) MWWorld::ContainerStore<MWWorld::RefData>& Npc::getContainerStore (const MWWorld::Ptr& ptr)
const const
{ {
if (!ptr.getRefData().getContainerStore().get()) ensureCustomData (ptr);
{
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
new MWWorld::ContainerStore<MWWorld::RefData>);
// TODO add initial content return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
ptr.getRefData().getContainerStore() = store;
}
return *ptr.getRefData().getContainerStore();
} }
std::string Npc::getScript (const MWWorld::Ptr& ptr) const std::string Npc::getScript (const MWWorld::Ptr& ptr) const

View file

@ -5,6 +5,8 @@
#include <boost/any.hpp> #include <boost/any.hpp>
#include <components/esm/loadcell.hpp>
#include <components/esm_store/cell_store.hpp> #include <components/esm_store/cell_store.hpp>
#include "refdata.hpp" #include "refdata.hpp"

View file

@ -1,6 +1,8 @@
#include "refdata.hpp" #include "refdata.hpp"
#include <components/esm_store/cell_store.hpp>
#include "customdata.hpp" #include "customdata.hpp"
namespace MWWorld namespace MWWorld
@ -14,8 +16,6 @@ namespace MWWorld
mCount = refData.mCount; mCount = refData.mCount;
mPosition = refData.mPosition; mPosition = refData.mPosition;
mContainerStore = refData.mContainerStore;
mCustomData = refData.mCustomData ? refData.mCustomData->clone() : 0; mCustomData = refData.mCustomData ? refData.mCustomData->clone() : 0;
} }
@ -27,7 +27,7 @@ namespace MWWorld
mCustomData = 0; mCustomData = 0;
} }
RefData::RefData (const ESMS::CellRef& cellRef) RefData::RefData (const ESM::CellRef& cellRef)
: mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mPosition (cellRef.pos), : mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mPosition (cellRef.pos),
mCustomData (0) mCustomData (0)
{} {}
@ -126,11 +126,6 @@ namespace MWWorld
mEnabled = true; mEnabled = true;
} }
boost::shared_ptr<ContainerStore<RefData> >& RefData::getContainerStore()
{
return mContainerStore;
}
ESM::Position& RefData::getPosition() ESM::Position& RefData::getPosition()
{ {
return mPosition; return mPosition;

View file

@ -3,17 +3,16 @@
#include <string> #include <string>
#include <boost/shared_ptr.hpp>
#include <Ogre.h> #include <Ogre.h>
#include "../mwscript/locals.hpp" #include <components/esm/defs.hpp>
#include "containerstore.hpp" #include "../mwscript/locals.hpp"
namespace ESM namespace ESM
{ {
class Script; class Script;
class CellRef;
} }
namespace MWWorld namespace MWWorld
@ -36,12 +35,6 @@ namespace MWWorld
CustomData *mCustomData; CustomData *mCustomData;
// we are using shared pointer here to avoid having to create custom copy-constructor,
// assignment operator and destructor. As a consequence though copying a RefData object
// manually will probably give unexcepted results. This is not a problem since RefData
// are never copied outside of container operations.
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
void copy (const RefData& refData); void copy (const RefData& refData);
void cleanup(); void cleanup();
@ -51,7 +44,7 @@ namespace MWWorld
/// @param cellRef Used to copy constant data such as position into this class where it can /// @param cellRef Used to copy constant data such as position into this class where it can
/// be altered without effecting the original data. This makes it possible /// be altered without effecting the original data. This makes it possible
/// to reset the position as the orignal data is still held in the CellRef /// to reset the position as the orignal data is still held in the CellRef
RefData (const ESMS::CellRef& cellRef); RefData (const ESM::CellRef& cellRef);
RefData (const RefData& refData); RefData (const RefData& refData);
@ -82,8 +75,6 @@ namespace MWWorld
void disable(); void disable();
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore();
ESM::Position& getPosition(); ESM::Position& getPosition();
void setCustomData (CustomData *data); void setCustomData (CustomData *data);

View file

@ -12,7 +12,6 @@
#include "store.hpp" #include "store.hpp"
#include "components/esm/records.hpp" #include "components/esm/records.hpp"
#include "components/esm/loadcell.hpp"
#include <list> #include <list>
#include <string> #include <string>