mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 20:19:40 +00:00
Rename CellStore Functor to Visitor
This commit is contained in:
parent
2301080c63
commit
5e99a3eda6
6 changed files with 74 additions and 75 deletions
|
@ -62,7 +62,7 @@ add_openmw_dir (mwsound
|
||||||
|
|
||||||
add_openmw_dir (mwworld
|
add_openmw_dir (mwworld
|
||||||
refdata worldimp scene globals class action nullaction actionteleport
|
refdata worldimp scene globals class action nullaction actionteleport
|
||||||
containerstore actiontalk actiontake manualref player cellfunctors failedaction
|
containerstore actiontalk actiontake manualref player cellvisitors failedaction
|
||||||
cells localscripts customdata inventorystore ptr actionopen actionread
|
cells localscripts customdata inventorystore ptr actionopen actionread
|
||||||
actionequip timestamp actionalchemy cellstore actionapply actioneat
|
actionequip timestamp actionalchemy cellstore actionapply actioneat
|
||||||
store esmstore recordcmp fallback actionrepair actionsoulgem livecellref actiondoor
|
store esmstore recordcmp fallback actionrepair actionsoulgem livecellref actiondoor
|
||||||
|
|
|
@ -241,9 +241,9 @@ namespace MWWorld
|
||||||
return MWWorld::Ptr(object.getBase(), cellToMoveTo);
|
return MWWorld::Ptr(object.getBase(), cellToMoveTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MergeFunctor
|
struct MergeVisitor
|
||||||
{
|
{
|
||||||
MergeFunctor(std::vector<LiveCellRefBase*>& mergeTo, const std::map<LiveCellRefBase*, MWWorld::CellStore*>& movedHere,
|
MergeVisitor(std::vector<LiveCellRefBase*>& mergeTo, const std::map<LiveCellRefBase*, MWWorld::CellStore*>& movedHere,
|
||||||
const std::map<LiveCellRefBase*, MWWorld::CellStore*>& movedToAnotherCell)
|
const std::map<LiveCellRefBase*, MWWorld::CellStore*>& movedToAnotherCell)
|
||||||
: mMergeTo(mergeTo)
|
: mMergeTo(mergeTo)
|
||||||
, mMovedHere(movedHere)
|
, mMovedHere(movedHere)
|
||||||
|
@ -275,9 +275,9 @@ namespace MWWorld
|
||||||
void CellStore::updateMergedRefs()
|
void CellStore::updateMergedRefs()
|
||||||
{
|
{
|
||||||
mMergedRefs.clear();
|
mMergedRefs.clear();
|
||||||
MergeFunctor functor(mMergedRefs, mMovedHere, mMovedToAnotherCell);
|
MergeVisitor visitor(mMergedRefs, mMovedHere, mMovedToAnotherCell);
|
||||||
forEachInternal(functor);
|
forEachInternal(visitor);
|
||||||
functor.merge();
|
visitor.merge();
|
||||||
}
|
}
|
||||||
|
|
||||||
CellStore::CellStore (const ESM::Cell *cell, const MWWorld::ESMStore& esmStore, std::vector<ESM::ESMReader>& readerList)
|
CellStore::CellStore (const ESM::Cell *cell, const MWWorld::ESMStore& esmStore, std::vector<ESM::ESMReader>& readerList)
|
||||||
|
@ -313,7 +313,7 @@ namespace MWWorld
|
||||||
return const_cast<CellStore *> (this)->search (id).isEmpty();
|
return const_cast<CellStore *> (this)->search (id).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SearchFunctor
|
struct SearchVisitor
|
||||||
{
|
{
|
||||||
MWWorld::Ptr mFound;
|
MWWorld::Ptr mFound;
|
||||||
std::string mIdToFind;
|
std::string mIdToFind;
|
||||||
|
@ -332,12 +332,12 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
bool oldState = mHasState;
|
bool oldState = mHasState;
|
||||||
|
|
||||||
SearchFunctor searchFunctor;
|
SearchVisitor searchVisitor;
|
||||||
searchFunctor.mIdToFind = id;
|
searchVisitor.mIdToFind = id;
|
||||||
forEach(searchFunctor);
|
forEach(searchVisitor);
|
||||||
|
|
||||||
mHasState = oldState;
|
mHasState = oldState;
|
||||||
return searchFunctor.mFound;
|
return searchVisitor.mFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr CellStore::searchViaActorId (int id)
|
Ptr CellStore::searchViaActorId (int id)
|
||||||
|
|
|
@ -125,45 +125,45 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function for forEachInternal
|
// helper function for forEachInternal
|
||||||
template<class Functor, class List>
|
template<class Visitor, class List>
|
||||||
bool forEachImp (Functor& functor, List& list)
|
bool forEachImp (Visitor& visitor, List& list)
|
||||||
{
|
{
|
||||||
for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end();
|
for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end();
|
||||||
++iter)
|
++iter)
|
||||||
{
|
{
|
||||||
if (iter->mData.isDeletedByContentFile())
|
if (iter->mData.isDeletedByContentFile())
|
||||||
continue;
|
continue;
|
||||||
if (!functor (MWWorld::Ptr(&*iter, this)))
|
if (!visitor (MWWorld::Ptr(&*iter, this)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// listing only objects owned by this cell. Internal use only, you probably want to use forEach() so that moved objects are accounted for.
|
// listing only objects owned by this cell. Internal use only, you probably want to use forEach() so that moved objects are accounted for.
|
||||||
template<class Functor>
|
template<class Visitor>
|
||||||
bool forEachInternal (Functor& functor)
|
bool forEachInternal (Visitor& visitor)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
forEachImp (functor, mActivators) &&
|
forEachImp (visitor, mActivators) &&
|
||||||
forEachImp (functor, mPotions) &&
|
forEachImp (visitor, mPotions) &&
|
||||||
forEachImp (functor, mAppas) &&
|
forEachImp (visitor, mAppas) &&
|
||||||
forEachImp (functor, mArmors) &&
|
forEachImp (visitor, mArmors) &&
|
||||||
forEachImp (functor, mBooks) &&
|
forEachImp (visitor, mBooks) &&
|
||||||
forEachImp (functor, mClothes) &&
|
forEachImp (visitor, mClothes) &&
|
||||||
forEachImp (functor, mContainers) &&
|
forEachImp (visitor, mContainers) &&
|
||||||
forEachImp (functor, mDoors) &&
|
forEachImp (visitor, mDoors) &&
|
||||||
forEachImp (functor, mIngreds) &&
|
forEachImp (visitor, mIngreds) &&
|
||||||
forEachImp (functor, mItemLists) &&
|
forEachImp (visitor, mItemLists) &&
|
||||||
forEachImp (functor, mLights) &&
|
forEachImp (visitor, mLights) &&
|
||||||
forEachImp (functor, mLockpicks) &&
|
forEachImp (visitor, mLockpicks) &&
|
||||||
forEachImp (functor, mMiscItems) &&
|
forEachImp (visitor, mMiscItems) &&
|
||||||
forEachImp (functor, mProbes) &&
|
forEachImp (visitor, mProbes) &&
|
||||||
forEachImp (functor, mRepairs) &&
|
forEachImp (visitor, mRepairs) &&
|
||||||
forEachImp (functor, mStatics) &&
|
forEachImp (visitor, mStatics) &&
|
||||||
forEachImp (functor, mWeapons) &&
|
forEachImp (visitor, mWeapons) &&
|
||||||
forEachImp (functor, mCreatures) &&
|
forEachImp (visitor, mCreatures) &&
|
||||||
forEachImp (functor, mNpcs) &&
|
forEachImp (visitor, mNpcs) &&
|
||||||
forEachImp (functor, mCreatureLists);
|
forEachImp (visitor, mCreatureLists);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -222,12 +222,12 @@ namespace MWWorld
|
||||||
void preload ();
|
void preload ();
|
||||||
///< Build ID list from content file.
|
///< Build ID list from content file.
|
||||||
|
|
||||||
/// Call functor (ref) for each reference. functor must return a bool. Returning
|
/// Call visitor (ref) for each reference. visitor must return a bool. Returning
|
||||||
/// false will abort the iteration.
|
/// false will abort the iteration.
|
||||||
/// \attention This function also lists deleted (count 0) objects!
|
/// \attention This function also lists deleted (count 0) objects!
|
||||||
/// \return Iteration completed?
|
/// \return Iteration completed?
|
||||||
template<class Functor>
|
template<class Visitor>
|
||||||
bool forEach (Functor& functor)
|
bool forEach (Visitor& visitor)
|
||||||
{
|
{
|
||||||
if (mState != State_Loaded)
|
if (mState != State_Loaded)
|
||||||
return false;
|
return false;
|
||||||
|
@ -239,7 +239,7 @@ namespace MWWorld
|
||||||
if (mMergedRefs[i]->mData.isDeletedByContentFile())
|
if (mMergedRefs[i]->mData.isDeletedByContentFile())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!functor(MWWorld::Ptr(mMergedRefs[i], this)))
|
if (!visitor(MWWorld::Ptr(mMergedRefs[i], this)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef GAME_MWWORLD_CELLFUNCTORS_H
|
#ifndef GAME_MWWORLD_CELLVISITORS_H
|
||||||
#define GAME_MWWORLD_CELLFUNCTORS_H
|
#define GAME_MWWORLD_CELLVISITORS_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
struct ListAndResetObjects
|
struct ListAndResetObjectsVisitor
|
||||||
{
|
{
|
||||||
std::vector<MWWorld::Ptr> mObjects;
|
std::vector<MWWorld::Ptr> mObjects;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "localscripts.hpp"
|
#include "localscripts.hpp"
|
||||||
#include "esmstore.hpp"
|
#include "esmstore.hpp"
|
||||||
#include "class.hpp"
|
#include "class.hpp"
|
||||||
#include "cellfunctors.hpp"
|
#include "cellvisitors.hpp"
|
||||||
#include "cellstore.hpp"
|
#include "cellstore.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -78,7 +78,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InsertFunctor
|
struct InsertVisitor
|
||||||
{
|
{
|
||||||
MWWorld::CellStore& mCell;
|
MWWorld::CellStore& mCell;
|
||||||
bool mRescale;
|
bool mRescale;
|
||||||
|
@ -86,13 +86,13 @@ namespace
|
||||||
MWPhysics::PhysicsSystem& mPhysics;
|
MWPhysics::PhysicsSystem& mPhysics;
|
||||||
MWRender::RenderingManager& mRendering;
|
MWRender::RenderingManager& mRendering;
|
||||||
|
|
||||||
InsertFunctor (MWWorld::CellStore& cell, bool rescale, Loading::Listener& loadingListener,
|
InsertVisitor (MWWorld::CellStore& cell, bool rescale, Loading::Listener& loadingListener,
|
||||||
MWPhysics::PhysicsSystem& physics, MWRender::RenderingManager& rendering);
|
MWPhysics::PhysicsSystem& physics, MWRender::RenderingManager& rendering);
|
||||||
|
|
||||||
bool operator() (const MWWorld::Ptr& ptr);
|
bool operator() (const MWWorld::Ptr& ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
InsertFunctor::InsertFunctor (MWWorld::CellStore& cell, bool rescale,
|
InsertVisitor::InsertVisitor (MWWorld::CellStore& cell, bool rescale,
|
||||||
Loading::Listener& loadingListener, MWPhysics::PhysicsSystem& physics,
|
Loading::Listener& loadingListener, MWPhysics::PhysicsSystem& physics,
|
||||||
MWRender::RenderingManager& rendering)
|
MWRender::RenderingManager& rendering)
|
||||||
: mCell (cell), mRescale (rescale), mLoadingListener (loadingListener),
|
: mCell (cell), mRescale (rescale), mLoadingListener (loadingListener),
|
||||||
|
@ -100,7 +100,7 @@ namespace
|
||||||
mRendering (rendering)
|
mRendering (rendering)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool InsertFunctor::operator() (const MWWorld::Ptr& ptr)
|
bool InsertVisitor::operator() (const MWWorld::Ptr& ptr)
|
||||||
{
|
{
|
||||||
if (mRescale)
|
if (mRescale)
|
||||||
{
|
{
|
||||||
|
@ -129,7 +129,7 @@ namespace
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AdjustPositionFunctor
|
struct AdjustPositionVisitor
|
||||||
{
|
{
|
||||||
bool operator() (const MWWorld::Ptr& ptr)
|
bool operator() (const MWWorld::Ptr& ptr)
|
||||||
{
|
{
|
||||||
|
@ -206,11 +206,11 @@ namespace MWWorld
|
||||||
void Scene::unloadCell (CellStoreCollection::iterator iter)
|
void Scene::unloadCell (CellStoreCollection::iterator iter)
|
||||||
{
|
{
|
||||||
std::cout << "Unloading cell\n";
|
std::cout << "Unloading cell\n";
|
||||||
ListAndResetObjects functor;
|
ListAndResetObjectsVisitor visitor;
|
||||||
|
|
||||||
(*iter)->forEach<ListAndResetObjects>(functor);
|
(*iter)->forEach<ListAndResetObjectsVisitor>(visitor);
|
||||||
for (std::vector<MWWorld::Ptr>::const_iterator iter2 (functor.mObjects.begin());
|
for (std::vector<MWWorld::Ptr>::const_iterator iter2 (visitor.mObjects.begin());
|
||||||
iter2!=functor.mObjects.end(); ++iter2)
|
iter2!=visitor.mObjects.end(); ++iter2)
|
||||||
{
|
{
|
||||||
mPhysics->remove(*iter2);
|
mPhysics->remove(*iter2);
|
||||||
}
|
}
|
||||||
|
@ -561,12 +561,12 @@ namespace MWWorld
|
||||||
|
|
||||||
void Scene::insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener)
|
void Scene::insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener)
|
||||||
{
|
{
|
||||||
InsertFunctor functor (cell, rescale, *loadingListener, *mPhysics, mRendering);
|
InsertVisitor insertVisitor (cell, rescale, *loadingListener, *mPhysics, mRendering);
|
||||||
cell.forEach (functor);
|
cell.forEach (insertVisitor);
|
||||||
|
|
||||||
// do adjustPosition (snapping actors to ground) after objects are loaded, so we don't depend on the loading order
|
// do adjustPosition (snapping actors to ground) after objects are loaded, so we don't depend on the loading order
|
||||||
AdjustPositionFunctor adjustPosFunctor;
|
AdjustPositionVisitor adjustPosVisitor;
|
||||||
cell.forEach (adjustPosFunctor);
|
cell.forEach (adjustPosVisitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::addObjectToScene (const Ptr& ptr)
|
void Scene::addObjectToScene (const Ptr& ptr)
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "manualref.hpp"
|
#include "manualref.hpp"
|
||||||
#include "cellstore.hpp"
|
#include "cellstore.hpp"
|
||||||
#include "cellfunctors.hpp"
|
|
||||||
#include "containerstore.hpp"
|
#include "containerstore.hpp"
|
||||||
#include "inventorystore.hpp"
|
#include "inventorystore.hpp"
|
||||||
#include "actionteleport.hpp"
|
#include "actionteleport.hpp"
|
||||||
|
@ -690,12 +689,12 @@ namespace MWWorld
|
||||||
return mWorldScene->searchPtrViaActorId (actorId);
|
return mWorldScene->searchPtrViaActorId (actorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FindContainerFunctor
|
struct FindContainerVisitor
|
||||||
{
|
{
|
||||||
Ptr mContainedPtr;
|
Ptr mContainedPtr;
|
||||||
Ptr mResult;
|
Ptr mResult;
|
||||||
|
|
||||||
FindContainerFunctor(const Ptr& containedPtr) : mContainedPtr(containedPtr) {}
|
FindContainerVisitor(const Ptr& containedPtr) : mContainedPtr(containedPtr) {}
|
||||||
|
|
||||||
bool operator() (Ptr ptr)
|
bool operator() (Ptr ptr)
|
||||||
{
|
{
|
||||||
|
@ -721,11 +720,11 @@ namespace MWWorld
|
||||||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
||||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
||||||
{
|
{
|
||||||
FindContainerFunctor functor(ptr);
|
FindContainerVisitor visitor(ptr);
|
||||||
//(*cellIt)->forEachContainer(functor);
|
//(*cellIt)->forEachContainer(visitor);
|
||||||
|
|
||||||
if (!functor.mResult.isEmpty())
|
if (!visitor.mResult.isEmpty())
|
||||||
return functor.mResult;
|
return visitor.mResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ptr();
|
return Ptr();
|
||||||
|
@ -2262,7 +2261,7 @@ namespace MWWorld
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ListObjectsFunctor
|
struct ListObjectsVisitor
|
||||||
{
|
{
|
||||||
std::vector<MWWorld::Ptr> mObjects;
|
std::vector<MWWorld::Ptr> mObjects;
|
||||||
|
|
||||||
|
@ -2279,10 +2278,10 @@ namespace MWWorld
|
||||||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
||||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
||||||
{
|
{
|
||||||
ListObjectsFunctor functor;
|
ListObjectsVisitor visitor;
|
||||||
(*cellIt)->forEach<ListObjectsFunctor>(functor);
|
(*cellIt)->forEach(visitor);
|
||||||
|
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it = functor.mObjects.begin(); it != functor.mObjects.end(); ++it)
|
for (std::vector<MWWorld::Ptr>::iterator it = visitor.mObjects.begin(); it != visitor.mObjects.end(); ++it)
|
||||||
if (Misc::StringUtils::ciEqual(it->getCellRef().getOwner(), npc.getCellRef().getRefId()))
|
if (Misc::StringUtils::ciEqual(it->getCellRef().getOwner(), npc.getCellRef().getRefId()))
|
||||||
out.push_back(*it);
|
out.push_back(*it);
|
||||||
}
|
}
|
||||||
|
@ -2886,9 +2885,9 @@ namespace MWWorld
|
||||||
mWeatherManager->update(duration, paused);
|
mWeatherManager->update(duration, paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AddDetectedReference
|
struct AddDetectedReferenceVisitor
|
||||||
{
|
{
|
||||||
AddDetectedReference(std::vector<Ptr>& out, Ptr detector, World::DetectionType type, float squaredDist)
|
AddDetectedReferenceVisitor(std::vector<Ptr>& out, Ptr detector, World::DetectionType type, float squaredDist)
|
||||||
: mOut(out), mDetector(detector), mSquaredDist(squaredDist), mType(type)
|
: mOut(out), mDetector(detector), mSquaredDist(squaredDist), mType(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -2968,13 +2967,13 @@ namespace MWWorld
|
||||||
|
|
||||||
dist = feetToGameUnits(dist);
|
dist = feetToGameUnits(dist);
|
||||||
|
|
||||||
AddDetectedReference functor (out, ptr, type, dist*dist);
|
AddDetectedReferenceVisitor visitor (out, ptr, type, dist*dist);
|
||||||
|
|
||||||
const Scene::CellStoreCollection& active = mWorldScene->getActiveCells();
|
const Scene::CellStoreCollection& active = mWorldScene->getActiveCells();
|
||||||
for (Scene::CellStoreCollection::const_iterator it = active.begin(); it != active.end(); ++it)
|
for (Scene::CellStoreCollection::const_iterator it = active.begin(); it != active.end(); ++it)
|
||||||
{
|
{
|
||||||
MWWorld::CellStore* cellStore = *it;
|
MWWorld::CellStore* cellStore = *it;
|
||||||
cellStore->forEach(functor);
|
cellStore->forEach(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3230,7 +3229,7 @@ namespace MWWorld
|
||||||
interpreterContext.executeActivation(object, actor);
|
interpreterContext.executeActivation(object, actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResetActorsFunctor
|
struct ResetActorsVisitor
|
||||||
{
|
{
|
||||||
bool operator() (Ptr ptr)
|
bool operator() (Ptr ptr)
|
||||||
{
|
{
|
||||||
|
@ -3252,8 +3251,8 @@ namespace MWWorld
|
||||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
||||||
{
|
{
|
||||||
CellStore* cellstore = *iter;
|
CellStore* cellstore = *iter;
|
||||||
ResetActorsFunctor functor;
|
ResetActorsVisitor visitor;
|
||||||
cellstore->forEach(functor);
|
cellstore->forEach(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue