From c081160591acde123942940a1b7a827832112347 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 27 Jan 2012 14:55:58 +0100 Subject: [PATCH] replaced container store in ref data with new custom data implementation --- apps/openmw/mwclass/container.cpp | 44 +++++++++++++++++++++-------- apps/openmw/mwclass/container.hpp | 2 ++ apps/openmw/mwclass/creature.cpp | 34 ++++++---------------- apps/openmw/mwclass/npc.cpp | 21 ++++++-------- apps/openmw/mwworld/ptr.hpp | 2 ++ apps/openmw/mwworld/refdata.cpp | 11 ++------ apps/openmw/mwworld/refdata.hpp | 17 +++-------- components/esm_store/cell_store.hpp | 5 ++-- 8 files changed, 63 insertions(+), 73 deletions(-) diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 4157ce17a..f81e0b9db 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -6,9 +6,39 @@ #include #include "../mwworld/ptr.hpp" +#include "../mwworld/containerstore.hpp" +#include "../mwworld/customdata.hpp" + +namespace +{ + struct CustomData : public MWWorld::CustomData + { + MWWorld::ContainerStore mContainerStore; + + virtual MWWorld::CustomData *clone() const; + }; + + MWWorld::CustomData *CustomData::clone() const + { + return new CustomData (*this); + } +} namespace MWClass { + void Container::ensureCustomData (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getCustomData()) + { + std::auto_ptr 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 { ESMS::LiveCellRef *ref = @@ -16,7 +46,7 @@ namespace MWClass assert (ref->base != NULL); const std::string &model = ref->base->model; - + if (!model.empty()) { MWRender::Objects& objects = renderingInterface.getObjects(); @@ -50,17 +80,9 @@ namespace MWClass MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr) const { - if (!ptr.getRefData().getContainerStore().get()) - { - boost::shared_ptr > store ( - new MWWorld::ContainerStore); - - // TODO add initial content - - ptr.getRefData().getContainerStore() = store; - } + ensureCustomData (ptr); - return *ptr.getRefData().getContainerStore(); + return dynamic_cast (*ptr.getRefData().getCustomData()).mContainerStore; } std::string Container::getScript (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 01763870a..9039d11ea 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -8,6 +8,8 @@ namespace MWClass { class Container : public MWWorld::Class { + void ensureCustomData (const MWWorld::Ptr& ptr) const; + public: virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const; diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index ab0e6e7fa..12a56e0ee 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -4,19 +4,20 @@ #include #include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/mechanicsmanager.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/customdata.hpp" - -#include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwworld/containerstore.hpp" namespace { struct CustomData : public MWWorld::CustomData { MWMechanics::CreatureStats mCreatureStats; + MWWorld::ContainerStore mContainerStore; virtual MWWorld::CustomData *clone() const; }; @@ -52,6 +53,8 @@ namespace MWClass data->mCreatureStats.mLevel = ref->base->data.level; + // \todo add initial container content + // store ptr.getRefData().setCustomData (data.release()); } @@ -67,18 +70,8 @@ namespace MWClass void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { - - /*ESMS::LiveCellRef *ref = - ptr.get(); - - assert (ref->base != NULL); - const std::string &model = ref->base->model; - - if (!model.empty()) - {*/ - MWRender::Actors& actors = renderingInterface.getActors(); - actors.insertCreature(ptr); - + MWRender::Actors& actors = renderingInterface.getActors(); + actors.insertCreature(ptr); } void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const @@ -92,7 +85,6 @@ namespace MWClass if(!model.empty()){ physics.insertActorPhysics(ptr, "meshes\\" + model); } - } void Creature::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const @@ -129,17 +121,9 @@ namespace MWClass MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr) const { - if (!ptr.getRefData().getContainerStore().get()) - { - boost::shared_ptr > store ( - new MWWorld::ContainerStore); - - // TODO add initial content - - ptr.getRefData().getContainerStore() = store; - } + ensureCustomData (ptr); - return *ptr.getRefData().getContainerStore(); + return dynamic_cast (*ptr.getRefData().getCustomData()).mContainerStore; } std::string Creature::getScript (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 38db494e2..f3f5ca597 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -9,14 +9,14 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" +#include "../mwmechanics/movement.hpp" +#include "../mwmechanics/mechanicsmanager.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" -#include "../mwmechanics/movement.hpp" - -#include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwworld/containerstore.hpp" namespace { @@ -28,6 +28,7 @@ namespace MWMechanics::NpcStats mNpcStats; MWMechanics::CreatureStats mCreatureStats; MWMechanics::Movement mMovement; + MWWorld::ContainerStore mContainerStore; virtual MWWorld::CustomData *clone() const; }; @@ -74,6 +75,8 @@ namespace MWClass data->mCreatureStats.mLevel = ref->base->npdt52.level; + // \todo add initial container content + // store ptr.getRefData().setCustomData (data.release()); } @@ -155,17 +158,9 @@ namespace MWClass MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr) const { - if (!ptr.getRefData().getContainerStore().get()) - { - boost::shared_ptr > store ( - new MWWorld::ContainerStore); - - // TODO add initial content - - ptr.getRefData().getContainerStore() = store; - } + ensureCustomData (ptr); - return *ptr.getRefData().getContainerStore(); + return dynamic_cast (*ptr.getRefData().getCustomData()).mContainerStore; } std::string Npc::getScript (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 8bf75aa3c..389c9349d 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -5,6 +5,8 @@ #include +#include + #include #include "refdata.hpp" diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index 133440e0f..03d04a50e 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -1,6 +1,8 @@ #include "refdata.hpp" +#include + #include "customdata.hpp" namespace MWWorld @@ -14,8 +16,6 @@ namespace MWWorld mCount = refData.mCount; mPosition = refData.mPosition; - mContainerStore = refData.mContainerStore; - mCustomData = refData.mCustomData ? refData.mCustomData->clone() : 0; } @@ -27,7 +27,7 @@ namespace MWWorld 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), mCustomData (0) {} @@ -126,11 +126,6 @@ namespace MWWorld mEnabled = true; } - boost::shared_ptr >& RefData::getContainerStore() - { - return mContainerStore; - } - ESM::Position& RefData::getPosition() { return mPosition; diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 075693533..30d676f13 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -3,17 +3,16 @@ #include -#include - #include -#include "../mwscript/locals.hpp" +#include -#include "containerstore.hpp" +#include "../mwscript/locals.hpp" namespace ESM { class Script; + class CellRef; } namespace MWWorld @@ -36,12 +35,6 @@ namespace MWWorld 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 > mContainerStore; - void copy (const RefData& refData); void cleanup(); @@ -51,7 +44,7 @@ namespace MWWorld /// @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 /// 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); @@ -82,8 +75,6 @@ namespace MWWorld void disable(); - boost::shared_ptr >& getContainerStore(); - ESM::Position& getPosition(); void setCustomData (CustomData *data); diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index d064312f1..c4bcf84d8 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -12,7 +12,6 @@ #include "store.hpp" #include "components/esm/records.hpp" -#include "components/esm/loadcell.hpp" #include #include @@ -36,7 +35,7 @@ namespace ESMS { LiveCellRef(const CellRef& cref, const X* b = NULL) : base(b), ref(cref), mData(ref) {} - + LiveCellRef(const X* b = NULL) : base(b), mData(ref) {} @@ -187,7 +186,7 @@ namespace ESMS ++iter) if (!functor (iter->ref, iter->mData)) return false; - + return true; }