mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 18:45:33 +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
|
||||
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
|
||||
actionequip timestamp actionalchemy cellstore actionapply actioneat
|
||||
store esmstore recordcmp fallback actionrepair actionsoulgem livecellref actiondoor
|
||||
|
|
|
@ -241,9 +241,9 @@ namespace MWWorld
|
|||
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)
|
||||
: mMergeTo(mergeTo)
|
||||
, mMovedHere(movedHere)
|
||||
|
@ -275,9 +275,9 @@ namespace MWWorld
|
|||
void CellStore::updateMergedRefs()
|
||||
{
|
||||
mMergedRefs.clear();
|
||||
MergeFunctor functor(mMergedRefs, mMovedHere, mMovedToAnotherCell);
|
||||
forEachInternal(functor);
|
||||
functor.merge();
|
||||
MergeVisitor visitor(mMergedRefs, mMovedHere, mMovedToAnotherCell);
|
||||
forEachInternal(visitor);
|
||||
visitor.merge();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
struct SearchFunctor
|
||||
struct SearchVisitor
|
||||
{
|
||||
MWWorld::Ptr mFound;
|
||||
std::string mIdToFind;
|
||||
|
@ -332,12 +332,12 @@ namespace MWWorld
|
|||
{
|
||||
bool oldState = mHasState;
|
||||
|
||||
SearchFunctor searchFunctor;
|
||||
searchFunctor.mIdToFind = id;
|
||||
forEach(searchFunctor);
|
||||
SearchVisitor searchVisitor;
|
||||
searchVisitor.mIdToFind = id;
|
||||
forEach(searchVisitor);
|
||||
|
||||
mHasState = oldState;
|
||||
return searchFunctor.mFound;
|
||||
return searchVisitor.mFound;
|
||||
}
|
||||
|
||||
Ptr CellStore::searchViaActorId (int id)
|
||||
|
|
|
@ -125,45 +125,45 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
// helper function for forEachInternal
|
||||
template<class Functor, class List>
|
||||
bool forEachImp (Functor& functor, List& list)
|
||||
template<class Visitor, class List>
|
||||
bool forEachImp (Visitor& visitor, List& list)
|
||||
{
|
||||
for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end();
|
||||
++iter)
|
||||
{
|
||||
if (iter->mData.isDeletedByContentFile())
|
||||
continue;
|
||||
if (!functor (MWWorld::Ptr(&*iter, this)))
|
||||
if (!visitor (MWWorld::Ptr(&*iter, this)))
|
||||
return false;
|
||||
}
|
||||
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.
|
||||
template<class Functor>
|
||||
bool forEachInternal (Functor& functor)
|
||||
template<class Visitor>
|
||||
bool forEachInternal (Visitor& visitor)
|
||||
{
|
||||
return
|
||||
forEachImp (functor, mActivators) &&
|
||||
forEachImp (functor, mPotions) &&
|
||||
forEachImp (functor, mAppas) &&
|
||||
forEachImp (functor, mArmors) &&
|
||||
forEachImp (functor, mBooks) &&
|
||||
forEachImp (functor, mClothes) &&
|
||||
forEachImp (functor, mContainers) &&
|
||||
forEachImp (functor, mDoors) &&
|
||||
forEachImp (functor, mIngreds) &&
|
||||
forEachImp (functor, mItemLists) &&
|
||||
forEachImp (functor, mLights) &&
|
||||
forEachImp (functor, mLockpicks) &&
|
||||
forEachImp (functor, mMiscItems) &&
|
||||
forEachImp (functor, mProbes) &&
|
||||
forEachImp (functor, mRepairs) &&
|
||||
forEachImp (functor, mStatics) &&
|
||||
forEachImp (functor, mWeapons) &&
|
||||
forEachImp (functor, mCreatures) &&
|
||||
forEachImp (functor, mNpcs) &&
|
||||
forEachImp (functor, mCreatureLists);
|
||||
forEachImp (visitor, mActivators) &&
|
||||
forEachImp (visitor, mPotions) &&
|
||||
forEachImp (visitor, mAppas) &&
|
||||
forEachImp (visitor, mArmors) &&
|
||||
forEachImp (visitor, mBooks) &&
|
||||
forEachImp (visitor, mClothes) &&
|
||||
forEachImp (visitor, mContainers) &&
|
||||
forEachImp (visitor, mDoors) &&
|
||||
forEachImp (visitor, mIngreds) &&
|
||||
forEachImp (visitor, mItemLists) &&
|
||||
forEachImp (visitor, mLights) &&
|
||||
forEachImp (visitor, mLockpicks) &&
|
||||
forEachImp (visitor, mMiscItems) &&
|
||||
forEachImp (visitor, mProbes) &&
|
||||
forEachImp (visitor, mRepairs) &&
|
||||
forEachImp (visitor, mStatics) &&
|
||||
forEachImp (visitor, mWeapons) &&
|
||||
forEachImp (visitor, mCreatures) &&
|
||||
forEachImp (visitor, mNpcs) &&
|
||||
forEachImp (visitor, mCreatureLists);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -222,12 +222,12 @@ namespace MWWorld
|
|||
void preload ();
|
||||
///< 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.
|
||||
/// \attention This function also lists deleted (count 0) objects!
|
||||
/// \return Iteration completed?
|
||||
template<class Functor>
|
||||
bool forEach (Functor& functor)
|
||||
template<class Visitor>
|
||||
bool forEach (Visitor& visitor)
|
||||
{
|
||||
if (mState != State_Loaded)
|
||||
return false;
|
||||
|
@ -239,7 +239,7 @@ namespace MWWorld
|
|||
if (mMergedRefs[i]->mData.isDeletedByContentFile())
|
||||
continue;
|
||||
|
||||
if (!functor(MWWorld::Ptr(mMergedRefs[i], this)))
|
||||
if (!visitor(MWWorld::Ptr(mMergedRefs[i], this)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef GAME_MWWORLD_CELLFUNCTORS_H
|
||||
#define GAME_MWWORLD_CELLFUNCTORS_H
|
||||
#ifndef GAME_MWWORLD_CELLVISITORS_H
|
||||
#define GAME_MWWORLD_CELLVISITORS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace MWWorld
|
||||
{
|
||||
struct ListAndResetObjects
|
||||
struct ListAndResetObjectsVisitor
|
||||
{
|
||||
std::vector<MWWorld::Ptr> mObjects;
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
#include "localscripts.hpp"
|
||||
#include "esmstore.hpp"
|
||||
#include "class.hpp"
|
||||
#include "cellfunctors.hpp"
|
||||
#include "cellvisitors.hpp"
|
||||
#include "cellstore.hpp"
|
||||
|
||||
namespace
|
||||
|
@ -78,7 +78,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
struct InsertFunctor
|
||||
struct InsertVisitor
|
||||
{
|
||||
MWWorld::CellStore& mCell;
|
||||
bool mRescale;
|
||||
|
@ -86,13 +86,13 @@ namespace
|
|||
MWPhysics::PhysicsSystem& mPhysics;
|
||||
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);
|
||||
|
||||
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,
|
||||
MWRender::RenderingManager& rendering)
|
||||
: mCell (cell), mRescale (rescale), mLoadingListener (loadingListener),
|
||||
|
@ -100,7 +100,7 @@ namespace
|
|||
mRendering (rendering)
|
||||
{}
|
||||
|
||||
bool InsertFunctor::operator() (const MWWorld::Ptr& ptr)
|
||||
bool InsertVisitor::operator() (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
if (mRescale)
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ namespace
|
|||
return true;
|
||||
}
|
||||
|
||||
struct AdjustPositionFunctor
|
||||
struct AdjustPositionVisitor
|
||||
{
|
||||
bool operator() (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
|
@ -206,11 +206,11 @@ namespace MWWorld
|
|||
void Scene::unloadCell (CellStoreCollection::iterator iter)
|
||||
{
|
||||
std::cout << "Unloading cell\n";
|
||||
ListAndResetObjects functor;
|
||||
ListAndResetObjectsVisitor visitor;
|
||||
|
||||
(*iter)->forEach<ListAndResetObjects>(functor);
|
||||
for (std::vector<MWWorld::Ptr>::const_iterator iter2 (functor.mObjects.begin());
|
||||
iter2!=functor.mObjects.end(); ++iter2)
|
||||
(*iter)->forEach<ListAndResetObjectsVisitor>(visitor);
|
||||
for (std::vector<MWWorld::Ptr>::const_iterator iter2 (visitor.mObjects.begin());
|
||||
iter2!=visitor.mObjects.end(); ++iter2)
|
||||
{
|
||||
mPhysics->remove(*iter2);
|
||||
}
|
||||
|
@ -561,12 +561,12 @@ namespace MWWorld
|
|||
|
||||
void Scene::insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener)
|
||||
{
|
||||
InsertFunctor functor (cell, rescale, *loadingListener, *mPhysics, mRendering);
|
||||
cell.forEach (functor);
|
||||
InsertVisitor insertVisitor (cell, rescale, *loadingListener, *mPhysics, mRendering);
|
||||
cell.forEach (insertVisitor);
|
||||
|
||||
// do adjustPosition (snapping actors to ground) after objects are loaded, so we don't depend on the loading order
|
||||
AdjustPositionFunctor adjustPosFunctor;
|
||||
cell.forEach (adjustPosFunctor);
|
||||
AdjustPositionVisitor adjustPosVisitor;
|
||||
cell.forEach (adjustPosVisitor);
|
||||
}
|
||||
|
||||
void Scene::addObjectToScene (const Ptr& ptr)
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
#include "player.hpp"
|
||||
#include "manualref.hpp"
|
||||
#include "cellstore.hpp"
|
||||
#include "cellfunctors.hpp"
|
||||
#include "containerstore.hpp"
|
||||
#include "inventorystore.hpp"
|
||||
#include "actionteleport.hpp"
|
||||
|
@ -690,12 +689,12 @@ namespace MWWorld
|
|||
return mWorldScene->searchPtrViaActorId (actorId);
|
||||
}
|
||||
|
||||
struct FindContainerFunctor
|
||||
struct FindContainerVisitor
|
||||
{
|
||||
Ptr mContainedPtr;
|
||||
Ptr mResult;
|
||||
|
||||
FindContainerFunctor(const Ptr& containedPtr) : mContainedPtr(containedPtr) {}
|
||||
FindContainerVisitor(const Ptr& containedPtr) : mContainedPtr(containedPtr) {}
|
||||
|
||||
bool operator() (Ptr ptr)
|
||||
{
|
||||
|
@ -721,11 +720,11 @@ namespace MWWorld
|
|||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
||||
{
|
||||
FindContainerFunctor functor(ptr);
|
||||
//(*cellIt)->forEachContainer(functor);
|
||||
FindContainerVisitor visitor(ptr);
|
||||
//(*cellIt)->forEachContainer(visitor);
|
||||
|
||||
if (!functor.mResult.isEmpty())
|
||||
return functor.mResult;
|
||||
if (!visitor.mResult.isEmpty())
|
||||
return visitor.mResult;
|
||||
}
|
||||
|
||||
return Ptr();
|
||||
|
@ -2262,7 +2261,7 @@ namespace MWWorld
|
|||
*/
|
||||
}
|
||||
|
||||
struct ListObjectsFunctor
|
||||
struct ListObjectsVisitor
|
||||
{
|
||||
std::vector<MWWorld::Ptr> mObjects;
|
||||
|
||||
|
@ -2279,10 +2278,10 @@ namespace MWWorld
|
|||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
||||
{
|
||||
ListObjectsFunctor functor;
|
||||
(*cellIt)->forEach<ListObjectsFunctor>(functor);
|
||||
ListObjectsVisitor visitor;
|
||||
(*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()))
|
||||
out.push_back(*it);
|
||||
}
|
||||
|
@ -2886,9 +2885,9 @@ namespace MWWorld
|
|||
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)
|
||||
{
|
||||
}
|
||||
|
@ -2968,13 +2967,13 @@ namespace MWWorld
|
|||
|
||||
dist = feetToGameUnits(dist);
|
||||
|
||||
AddDetectedReference functor (out, ptr, type, dist*dist);
|
||||
AddDetectedReferenceVisitor visitor (out, ptr, type, dist*dist);
|
||||
|
||||
const Scene::CellStoreCollection& active = mWorldScene->getActiveCells();
|
||||
for (Scene::CellStoreCollection::const_iterator it = active.begin(); it != active.end(); ++it)
|
||||
{
|
||||
MWWorld::CellStore* cellStore = *it;
|
||||
cellStore->forEach(functor);
|
||||
cellStore->forEach(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3230,7 +3229,7 @@ namespace MWWorld
|
|||
interpreterContext.executeActivation(object, actor);
|
||||
}
|
||||
|
||||
struct ResetActorsFunctor
|
||||
struct ResetActorsVisitor
|
||||
{
|
||||
bool operator() (Ptr ptr)
|
||||
{
|
||||
|
@ -3252,8 +3251,8 @@ namespace MWWorld
|
|||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
||||
{
|
||||
CellStore* cellstore = *iter;
|
||||
ResetActorsFunctor functor;
|
||||
cellstore->forEach(functor);
|
||||
ResetActorsVisitor visitor;
|
||||
cellstore->forEach(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue