added unifying LiveCellRef pointer class

pull/7/head
Marc Zinnschlag 15 years ago
parent d51e6fb7c4
commit 3fae68b403

@ -61,7 +61,8 @@ set(GAMEWORLD
apps/openmw/mwworld/world.cpp)
set(GAMEWORLD_HEADER
apps/openmw/mwworld/refdata.hpp
apps/openmw/mwworld/world.hpp)
apps/openmw/mwworld/world.hpp
apps/openmw/mwworld/ptr.hpp)
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})

@ -17,13 +17,15 @@
#include "mwsound/soundmanager.hpp"
#include "mwworld/world.hpp"
#include "mwworld/ptr.hpp"
void OMW::Engine::executeLocalScripts()
{
for (MWWorld::World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin());
iter!=mWorld->getLocalScripts().end(); ++iter)
{
MWScript::InterpreterContext interpreterContext (*mWorld, *mSoundManager, iter->second);
MWScript::InterpreterContext interpreterContext (*mWorld, *mSoundManager,
&iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second));
mScriptManager->run (iter->first, interpreterContext);
}
}

@ -10,8 +10,8 @@
namespace MWScript
{
InterpreterContext::InterpreterContext (MWWorld::World& world,
MWSound::SoundManager& soundManager, MWScript::Locals *locals)
: mWorld (world), mSoundManager (soundManager), mLocals (locals)
MWSound::SoundManager& soundManager, MWScript::Locals *locals, MWWorld::Ptr reference)
: mWorld (world), mSoundManager (soundManager), mLocals (locals), mReference (reference)
{}
int InterpreterContext::getLocalShort (int index) const

@ -3,6 +3,8 @@
#include <components/interpreter/context.hpp>
#include "../mwworld/ptr.hpp"
namespace MWWorld
{
class World;
@ -22,11 +24,12 @@ namespace MWScript
MWWorld::World& mWorld;
MWSound::SoundManager& mSoundManager;
Locals *mLocals;
MWWorld::Ptr mReference;
public:
InterpreterContext (MWWorld::World& world, MWSound::SoundManager& soundManager,
MWScript::Locals *locals);
MWScript::Locals *locals, MWWorld::Ptr reference);
///< The ownership of \a locals is not transferred. 0-pointer allowed.
virtual int getLocalShort (int index) const;

@ -0,0 +1,55 @@
#ifndef GAME_MWWORLD_PTR_H
#define GAME_MWWORLD_PTR_H
#include <cassert>
#include <boost/any.hpp>
#include <components/esm_store/cell_store.hpp>
#include "refdata.hpp"
namespace MWWorld
{
/// \brief Pointer to a LiveCellRef
class Ptr
{
boost::any mPtr;
ESM::CellRef *mCellRef;
RefData *mRefData;
public:
Ptr() : mCellRef (0), mRefData (0) {}
template<typename T>
Ptr (ESMS::LiveCellRef<T, RefData> *liveCellRef)
{
mPtr = liveCellRef;
mCellRef = &liveCellRef->ref;
mRefData = &liveCellRef->mData;
}
template<typename T>
ESMS::LiveCellRef<T, RefData> *get() const
{
return boost::any_cast<const ESMS::LiveCellRef<T, RefData>*> (mPtr);
}
ESM::CellRef& getCellRef() const
{
assert (mCellRef);
return *mCellRef;
}
RefData& getRefData() const
{
assert (mRefData);
return *mRefData;
}
};
}
#endif

@ -26,7 +26,7 @@ namespace
iter->mData.setLocals (*script);
scriptList.push_back (
std::make_pair (iter->base->script, &iter->mData.getLocals()));
std::make_pair (iter->base->script, MWWorld::Ptr (&*iter)));
}
}
}

@ -12,6 +12,7 @@
#include "../mwrender/mwscene.hpp"
#include "refdata.hpp"
#include "ptr.hpp"
namespace Render
{
@ -32,7 +33,7 @@ namespace MWWorld
{
public:
typedef std::vector<std::pair<std::string, MWScript::Locals *> > ScriptList;
typedef std::vector<std::pair<std::string, Ptr> > ScriptList;
private:

Loading…
Cancel
Save