mirror of
https://github.com/mangosfour/server.git
synced 2025-12-27 01:37:04 +00:00
[9775] Cleanups in framework library.
* Removed last bits of threading in grid code. * Removed some weird and unneeded declarations. * General code style fixes. * (Perhaps some things I forgot.) Thanks to Lynx3d for the usual GCC-stabbing...
This commit is contained in:
parent
4d89b41f60
commit
7532061a79
25 changed files with 774 additions and 398 deletions
|
|
@ -42,13 +42,13 @@ template
|
|||
<
|
||||
class ACTIVE_OBJECT,
|
||||
class WORLD_OBJECT_TYPES,
|
||||
class GRID_OBJECT_TYPES,
|
||||
class ThreadModel = MaNGOS::SingleThreaded<ACTIVE_OBJECT>
|
||||
class GRID_OBJECT_TYPES
|
||||
>
|
||||
class MANGOS_DLL_DECL Grid
|
||||
{
|
||||
// allows the GridLoader to access its internals
|
||||
template<class A, class T, class O> friend class GridLoader;
|
||||
|
||||
public:
|
||||
|
||||
/** destructor to clean up its resources. This includes unloading the
|
||||
|
|
@ -58,74 +58,71 @@ class MANGOS_DLL_DECL Grid
|
|||
|
||||
/** an object of interested enters the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> bool AddWorldObject(SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
bool AddWorldObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return i_objects.template insert<SPECIFIC_OBJECT>(obj);
|
||||
}
|
||||
|
||||
/** an object of interested exits the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> bool RemoveWorldObject(SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
bool RemoveWorldObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return i_objects.template remove<SPECIFIC_OBJECT>(obj);
|
||||
}
|
||||
|
||||
/** Refreshes/update the grid. This required for remote grids.
|
||||
*/
|
||||
void RefreshGrid(void) { /* TBI */}
|
||||
|
||||
/** Locks a grid. Any object enters must wait until the grid is unlock.
|
||||
*/
|
||||
void LockGrid(void) { /* TBI */ }
|
||||
|
||||
/** Unlocks the grid.
|
||||
*/
|
||||
void UnlockGrid(void) { /* TBI */ }
|
||||
|
||||
/** Grid visitor for grid objects
|
||||
*/
|
||||
template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
|
||||
template<class T>
|
||||
void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
|
||||
{
|
||||
visitor.Visit(i_container);
|
||||
}
|
||||
|
||||
/** Grid visitor for world objects
|
||||
*/
|
||||
template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
|
||||
template<class T>
|
||||
void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
|
||||
{
|
||||
visitor.Visit(i_objects);
|
||||
}
|
||||
|
||||
/** Returns the number of object within the grid.
|
||||
*/
|
||||
unsigned int ActiveObjectsInGrid(void) const { return m_activeGridObjects.size()+i_objects.template Count<ACTIVE_OBJECT>(); }
|
||||
uint32 ActiveObjectsInGrid() const
|
||||
{
|
||||
return m_activeGridObjects.size() + i_objects.template Count<ACTIVE_OBJECT>();
|
||||
}
|
||||
|
||||
/** Inserts a container type object into the grid.
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
bool AddGridObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(obj->isActiveObject())
|
||||
if (obj->isActiveObject())
|
||||
m_activeGridObjects.insert(obj);
|
||||
|
||||
return i_container.template insert<SPECIFIC_OBJECT>(obj);
|
||||
}
|
||||
|
||||
/** Removes a containter type object from the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
bool RemoveGridObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(obj->isActiveObject())
|
||||
if (obj->isActiveObject())
|
||||
m_activeGridObjects.erase(obj);
|
||||
|
||||
return i_container.template remove<SPECIFIC_OBJECT>(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
typedef typename ThreadModel::Lock Guard;
|
||||
typedef typename ThreadModel::VolatileType VolatileType;
|
||||
|
||||
TypeMapContainer<GRID_OBJECT_TYPES> i_container;
|
||||
TypeMapContainer<WORLD_OBJECT_TYPES> i_objects;
|
||||
typedef std::set<void*> ActiveGridObjects;
|
||||
ActiveGridObjects m_activeGridObjects;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -47,30 +47,26 @@ class MANGOS_DLL_DECL GridLoader
|
|||
/** Loads the grid
|
||||
*/
|
||||
template<class LOADER>
|
||||
void Load(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader)
|
||||
void Load(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader)
|
||||
{
|
||||
grid.LockGrid();
|
||||
loader.Load(grid);
|
||||
grid.UnlockGrid();
|
||||
}
|
||||
|
||||
/** Stop the grid
|
||||
*/
|
||||
template<class STOPER>
|
||||
void Stop(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper)
|
||||
void Stop(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper)
|
||||
{
|
||||
grid.LockGrid();
|
||||
stoper.Stop(grid);
|
||||
grid.UnlockGrid();
|
||||
}
|
||||
|
||||
/** Unloads the grid
|
||||
*/
|
||||
template<class UNLOADER>
|
||||
void Unload(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader)
|
||||
void Unload(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader)
|
||||
{
|
||||
grid.LockGrid();
|
||||
unloader.Unload(grid);
|
||||
grid.UnlockGrid();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,17 +21,24 @@
|
|||
|
||||
#include "Utilities/LinkedReference/RefManager.h"
|
||||
|
||||
template<class OBJECT>
|
||||
class GridReference;
|
||||
template<class OBJECT> class GridReference;
|
||||
|
||||
template<class OBJECT>
|
||||
class GridRefManager : public RefManager<GridRefManager<OBJECT>, OBJECT>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef LinkedListHead::Iterator< GridReference<OBJECT> > iterator;
|
||||
|
||||
GridReference<OBJECT>* getFirst() { return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getFirst(); }
|
||||
GridReference<OBJECT>* getLast() { return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getLast(); }
|
||||
GridReference<OBJECT>* getFirst()
|
||||
{
|
||||
return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getFirst();
|
||||
}
|
||||
|
||||
GridReference<OBJECT>* getLast()
|
||||
{
|
||||
return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getLast();
|
||||
}
|
||||
|
||||
iterator begin() { return iterator(getFirst()); }
|
||||
iterator end() { return iterator(NULL); }
|
||||
|
|
|
|||
|
|
@ -21,32 +21,49 @@
|
|||
|
||||
#include "Utilities/LinkedReference/Reference.h"
|
||||
|
||||
template<class OBJECT>
|
||||
class GridRefManager;
|
||||
template<class OBJECT> class GridRefManager;
|
||||
|
||||
template<class OBJECT>
|
||||
class MANGOS_DLL_SPEC GridReference : public Reference<GridRefManager<OBJECT>, OBJECT>
|
||||
{
|
||||
protected:
|
||||
|
||||
void targetObjectBuildLink()
|
||||
{
|
||||
// called from link()
|
||||
this->getTarget()->insertFirst(this);
|
||||
this->getTarget()->incSize();
|
||||
}
|
||||
|
||||
void targetObjectDestroyLink()
|
||||
{
|
||||
// called from unlink()
|
||||
if(this->isValid()) this->getTarget()->decSize();
|
||||
if (this->isValid())
|
||||
this->getTarget()->decSize();
|
||||
}
|
||||
|
||||
void sourceObjectDestroyLink()
|
||||
{
|
||||
// called from invalidate()
|
||||
this->getTarget()->decSize();
|
||||
}
|
||||
|
||||
public:
|
||||
GridReference() : Reference<GridRefManager<OBJECT>, OBJECT>() {}
|
||||
~GridReference() { this->unlink(); }
|
||||
GridReference *next() { return (GridReference*)Reference<GridRefManager<OBJECT>, OBJECT>::next(); }
|
||||
|
||||
GridReference()
|
||||
: Reference<GridRefManager<OBJECT>, OBJECT>()
|
||||
{
|
||||
}
|
||||
|
||||
~GridReference()
|
||||
{
|
||||
this->unlink();
|
||||
}
|
||||
|
||||
GridReference *next()
|
||||
{
|
||||
return (GridReference*)Reference<GridRefManager<OBJECT>, OBJECT>::next();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,27 +28,42 @@
|
|||
|
||||
class GridInfo
|
||||
{
|
||||
public:
|
||||
GridInfo()
|
||||
: i_timer(0), i_unloadActiveLockCount(0), i_unloadExplicitLock(false), i_unloadReferenceLock(false) {}
|
||||
GridInfo(time_t expiry, bool unload = true )
|
||||
: i_timer(expiry), i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false) {}
|
||||
const TimeTracker& getTimeTracker() const { return i_timer; }
|
||||
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; }
|
||||
void setUnloadExplicitLock( bool on ) { i_unloadExplicitLock = on; }
|
||||
void setUnloadReferenceLock( bool on ) { i_unloadReferenceLock = on; }
|
||||
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
|
||||
void decUnloadActiveLock() { if(i_unloadActiveLockCount) --i_unloadActiveLockCount; }
|
||||
public:
|
||||
|
||||
void setTimer(const TimeTracker& pTimer) { i_timer = pTimer; }
|
||||
void ResetTimeTracker(time_t interval) { i_timer.Reset(interval); }
|
||||
void UpdateTimeTracker(time_t diff) { i_timer.Update(diff); }
|
||||
GridInfo()
|
||||
: i_timer(0), i_unloadActiveLockCount(0), i_unloadExplicitLock(false),
|
||||
i_unloadReferenceLock(false)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
TimeTracker i_timer;
|
||||
uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading)
|
||||
bool i_unloadExplicitLock : 1; // explicit manual lock or config setting
|
||||
bool i_unloadReferenceLock : 1; // lock from instance map copy
|
||||
GridInfo(time_t expiry, bool unload = true )
|
||||
: i_timer(expiry), i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload),
|
||||
i_unloadReferenceLock(false)
|
||||
{
|
||||
}
|
||||
|
||||
const TimeTracker& getTimeTracker() const { return i_timer; }
|
||||
|
||||
bool getUnloadLock() const
|
||||
{
|
||||
return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock;
|
||||
}
|
||||
|
||||
void setUnloadExplicitLock( bool on ) { i_unloadExplicitLock = on; }
|
||||
void setUnloadReferenceLock( bool on ) { i_unloadReferenceLock = on; }
|
||||
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
|
||||
void decUnloadActiveLock() { if (i_unloadActiveLockCount) --i_unloadActiveLockCount; }
|
||||
|
||||
void setTimer(const TimeTracker& pTimer) { i_timer = pTimer; }
|
||||
void ResetTimeTracker(time_t interval) { i_timer.Reset(interval); }
|
||||
void UpdateTimeTracker(time_t diff) { i_timer.Update(diff); }
|
||||
|
||||
private:
|
||||
|
||||
TimeTracker i_timer;
|
||||
uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading)
|
||||
bool i_unloadExplicitLock : 1; // explicit manual lock or config setting
|
||||
bool i_unloadReferenceLock : 1; // lock from instance map copy
|
||||
};
|
||||
|
||||
typedef enum
|
||||
|
|
@ -56,104 +71,112 @@ typedef enum
|
|||
GRID_STATE_INVALID = 0,
|
||||
GRID_STATE_ACTIVE = 1,
|
||||
GRID_STATE_IDLE = 2,
|
||||
GRID_STATE_REMOVAL= 3,
|
||||
GRID_STATE_REMOVAL = 3,
|
||||
MAX_GRID_STATE = 4
|
||||
} grid_state_t;
|
||||
|
||||
template
|
||||
<
|
||||
unsigned int N,
|
||||
uint32 N,
|
||||
class ACTIVE_OBJECT,
|
||||
class WORLD_OBJECT_TYPES,
|
||||
class GRID_OBJECT_TYPES,
|
||||
class ThreadModel = MaNGOS::SingleThreaded<ACTIVE_OBJECT>
|
||||
class GRID_OBJECT_TYPES
|
||||
>
|
||||
class MANGOS_DLL_DECL NGrid
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> GridType;
|
||||
NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true)
|
||||
typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> GridType;
|
||||
|
||||
NGrid(uint32 id, uint32 x, uint32 y, time_t expiry, bool unload = true)
|
||||
: i_gridId(id), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false)
|
||||
{
|
||||
i_GridInfo = GridInfo(expiry, unload);
|
||||
}
|
||||
|
||||
const GridType& operator()(unsigned short x, unsigned short y) const
|
||||
const GridType& operator()(uint32 x, uint32 y) const
|
||||
{
|
||||
ASSERT(x < N);
|
||||
ASSERT(y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
GridType& operator()(unsigned short x, unsigned short y)
|
||||
GridType& operator()(uint32 x, uint32 y)
|
||||
{
|
||||
ASSERT(x < N);
|
||||
ASSERT(y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
const uint32& GetGridId(void) const { return i_gridId; }
|
||||
const uint32& GetGridId() const { return i_gridId; }
|
||||
void SetGridId(const uint32 id) const { i_gridId = id; }
|
||||
grid_state_t GetGridState(void) const { return i_cellstate; }
|
||||
grid_state_t GetGridState() const { return i_cellstate; }
|
||||
void SetGridState(grid_state_t s) { i_cellstate = s; }
|
||||
int32 getX() const { return i_x; }
|
||||
int32 getY() const { return i_y; }
|
||||
uint32 getX() const { return i_x; }
|
||||
uint32 getY() const { return i_y; }
|
||||
|
||||
void link(GridRefManager<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> >* pTo)
|
||||
void link(GridRefManager<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> >* pTo)
|
||||
{
|
||||
i_Reference.link(pTo, this);
|
||||
}
|
||||
|
||||
bool isGridObjectDataLoaded() const { return i_GridObjectDataLoaded; }
|
||||
void setGridObjectDataLoaded(bool pLoaded) { i_GridObjectDataLoaded = pLoaded; }
|
||||
|
||||
GridInfo* getGridInfoRef() { return &i_GridInfo; }
|
||||
const TimeTracker& getTimeTracker() const { return i_GridInfo.getTimeTracker(); }
|
||||
bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); }
|
||||
void setUnloadExplicitLock( bool on ) { i_GridInfo.setUnloadExplicitLock(on); }
|
||||
void setUnloadReferenceLock( bool on ) { i_GridInfo.setUnloadReferenceLock(on); }
|
||||
void setUnloadExplicitLock(bool on) { i_GridInfo.setUnloadExplicitLock(on); }
|
||||
void setUnloadReferenceLock(bool on) { i_GridInfo.setUnloadReferenceLock(on); }
|
||||
void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); }
|
||||
void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); }
|
||||
void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); }
|
||||
void UpdateTimeTracker(time_t diff) { i_GridInfo.UpdateTimeTracker(diff); }
|
||||
|
||||
template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).AddWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).RemoveWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class T, class TT> void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
template<class T, class TT>
|
||||
void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
{
|
||||
for(unsigned int x=0; x < N; ++x)
|
||||
for(unsigned int y=0; y < N; ++y)
|
||||
for (uint32 x = 0; x < N; ++x)
|
||||
for (uint32 y = 0; y < N; ++y)
|
||||
i_cells[x][y].Visit(visitor);
|
||||
}
|
||||
|
||||
template<class T, class TT> void Visit(const uint32 &x, const uint32 &y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
template<class T, class TT>
|
||||
void Visit(const uint32 &x, const uint32 &y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
{
|
||||
getGridType(x, y).Visit(visitor);
|
||||
}
|
||||
|
||||
unsigned int ActiveObjectsInGrid(void) const
|
||||
uint32 ActiveObjectsInGrid() const
|
||||
{
|
||||
unsigned int count=0;
|
||||
for(unsigned int x=0; x < N; ++x)
|
||||
for(unsigned int y=0; y < N; ++y)
|
||||
uint32 count = 0;
|
||||
for (uint32 x = 0; x < N; ++x)
|
||||
for (uint32 y = 0; y < N; ++y)
|
||||
count += i_cells[x][y].ActiveObjectsInGrid();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).AddGridObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
template<class SPECIFIC_OBJECT>
|
||||
bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).RemoveGridObject(obj);
|
||||
}
|
||||
|
|
@ -169,11 +192,12 @@ class MANGOS_DLL_DECL NGrid
|
|||
|
||||
uint32 i_gridId;
|
||||
GridInfo i_GridInfo;
|
||||
GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> > i_Reference;
|
||||
int32 i_x;
|
||||
int32 i_y;
|
||||
GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> > i_Reference;
|
||||
uint32 i_x;
|
||||
uint32 i_y;
|
||||
grid_state_t i_cellstate;
|
||||
GridType i_cells[N][N];
|
||||
bool i_GridObjectDataLoaded;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,14 +31,19 @@
|
|||
#include "Utilities/UnorderedMap.h"
|
||||
#include "GameSystem/GridRefManager.h"
|
||||
|
||||
template<class OBJECT, class KEY_TYPE> struct ContainerUnorderedMap
|
||||
template<class OBJECT, class KEY_TYPE>
|
||||
struct ContainerUnorderedMap
|
||||
{
|
||||
UNORDERED_MAP<KEY_TYPE, OBJECT*> _element;
|
||||
};
|
||||
template<class KEY_TYPE> struct ContainerUnorderedMap<TypeNull, KEY_TYPE>
|
||||
|
||||
template<class KEY_TYPE>
|
||||
struct ContainerUnorderedMap<TypeNull, KEY_TYPE>
|
||||
{
|
||||
};
|
||||
template<class H, class T, class KEY_TYPE> struct ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >
|
||||
|
||||
template<class H, class T, class KEY_TYPE>
|
||||
struct ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >
|
||||
{
|
||||
ContainerUnorderedMap<H, KEY_TYPE> _elements;
|
||||
ContainerUnorderedMap<T, KEY_TYPE> _TailElements;
|
||||
|
|
@ -48,24 +53,33 @@ template<class OBJECT_TYPES, class KEY_TYPE = OBJECT_HANDLE>
|
|||
class TypeUnorderedMapContainer
|
||||
{
|
||||
public:
|
||||
template<class SPECIFIC_TYPE> bool insert(KEY_TYPE handle, SPECIFIC_TYPE* obj)
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
bool insert(KEY_TYPE handle, SPECIFIC_TYPE* obj)
|
||||
{
|
||||
return TypeUnorderedMapContainer::insert(i_elements, handle, obj);
|
||||
}
|
||||
template<class SPECIFIC_TYPE> bool erase(KEY_TYPE handle, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
bool erase(KEY_TYPE handle, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return TypeUnorderedMapContainer::erase(i_elements, handle, (SPECIFIC_TYPE*)NULL);
|
||||
}
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* find(KEY_TYPE hdl, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* find(KEY_TYPE hdl, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return TypeUnorderedMapContainer::find(i_elements, hdl, (SPECIFIC_TYPE*)NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE> i_elements;
|
||||
|
||||
// Helpers
|
||||
// Insert helpers
|
||||
template<class SPECIFIC_TYPE> static bool insert(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE handle, SPECIFIC_TYPE* obj)
|
||||
template<class SPECIFIC_TYPE>
|
||||
static bool insert(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE handle, SPECIFIC_TYPE* obj)
|
||||
{
|
||||
typename UNORDERED_MAP<KEY_TYPE, SPECIFIC_TYPE*>::iterator i = elements._element.find(handle);
|
||||
if (i == elements._element.end())
|
||||
|
|
@ -75,25 +89,33 @@ class TypeUnorderedMapContainer
|
|||
}
|
||||
else
|
||||
{
|
||||
assert (i->second == obj && "Object with certain key already in but objects are different!");
|
||||
ASSERT(i->second == obj && "Object with certain key already in but objects are different!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template<class SPECIFIC_TYPE> static bool insert(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
static bool insert(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
template<class SPECIFIC_TYPE, class T> static bool insert(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
static bool insert(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
template<class SPECIFIC_TYPE, class H, class T> static bool insert(ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >& elements, KEY_TYPE handle, SPECIFIC_TYPE* obj)
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
static bool insert(ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >& elements, KEY_TYPE handle, SPECIFIC_TYPE* obj)
|
||||
{
|
||||
bool ret = TypeUnorderedMapContainer::insert(elements._elements, handle, obj);
|
||||
return ret ? ret : TypeUnorderedMapContainer::insert(elements._TailElements, handle, obj);
|
||||
}
|
||||
|
||||
// Find helpers
|
||||
template<class SPECIFIC_TYPE> static SPECIFIC_TYPE* find(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE hdl, SPECIFIC_TYPE* /*obj*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
static SPECIFIC_TYPE* find(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE hdl, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
typename UNORDERED_MAP<KEY_TYPE, SPECIFIC_TYPE*>::iterator i = elements._element.find(hdl);
|
||||
if (i == elements._element.end())
|
||||
|
|
@ -101,35 +123,49 @@ class TypeUnorderedMapContainer
|
|||
else
|
||||
return i->second;
|
||||
}
|
||||
template<class SPECIFIC_TYPE> static SPECIFIC_TYPE* find(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE /*hdl*/, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
static SPECIFIC_TYPE* find(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE /*hdl*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
template<class SPECIFIC_TYPE, class T> static SPECIFIC_TYPE* find(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE /*hdl*/, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
static SPECIFIC_TYPE* find(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE /*hdl*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
template<class SPECIFIC_TYPE, class H, class T> static SPECIFIC_TYPE* find(ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >& elements, KEY_TYPE hdl, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
static SPECIFIC_TYPE* find(ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >& elements, KEY_TYPE hdl, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
SPECIFIC_TYPE* ret = TypeUnorderedMapContainer::find(elements._elements, hdl, (SPECIFIC_TYPE*)NULL);
|
||||
return ret ? ret : TypeUnorderedMapContainer::find(elements._TailElements, hdl, (SPECIFIC_TYPE*)NULL);
|
||||
}
|
||||
|
||||
// Erase helpers
|
||||
template<class SPECIFIC_TYPE> static bool erase(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE handle, SPECIFIC_TYPE* /*obj*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
static bool erase(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE handle, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
elements._element.erase(handle);
|
||||
|
||||
return true;
|
||||
}
|
||||
template<class SPECIFIC_TYPE> static bool erase(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
static bool erase(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
template<class SPECIFIC_TYPE, class T> static bool erase(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
static bool erase(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE /*handle*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
template<class SPECIFIC_TYPE, class H, class T> static bool erase(ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >& elements, KEY_TYPE handle, SPECIFIC_TYPE* /*obj*/)
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
static bool erase(ContainerUnorderedMap< TypeList<H, T>, KEY_TYPE >& elements, KEY_TYPE handle, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
bool ret = TypeUnorderedMapContainer::erase(elements._elements, handle, (SPECIFIC_TYPE*)NULL);
|
||||
return ret ? ret : TypeUnorderedMapContainer::erase(elements._TailElements, handle, (SPECIFIC_TYPE*)NULL);
|
||||
|
|
@ -141,21 +177,24 @@ class TypeUnorderedMapContainer
|
|||
* By itself its meaningless but collaborate along with TypeContainers,
|
||||
* it become the most powerfully container in the whole system.
|
||||
*/
|
||||
template<class OBJECT> struct ContainerMapList
|
||||
template<class OBJECT>
|
||||
struct ContainerMapList
|
||||
{
|
||||
GridRefManager<OBJECT> _element;
|
||||
};
|
||||
|
||||
template<> struct ContainerMapList<TypeNull> /* nothing is in type null */
|
||||
template<>
|
||||
struct ContainerMapList<TypeNull> /* nothing is in type null */
|
||||
{
|
||||
};
|
||||
template<class H, class T> struct ContainerMapList<TypeList<H, T> >
|
||||
|
||||
template<class H, class T>
|
||||
struct ContainerMapList<TypeList<H, T> >
|
||||
{
|
||||
ContainerMapList<H> _elements;
|
||||
ContainerMapList<T> _TailElements;
|
||||
};
|
||||
|
||||
|
||||
#include "TypeContainerFunctions.h"
|
||||
|
||||
/*
|
||||
|
|
@ -169,26 +208,32 @@ template<class OBJECT_TYPES>
|
|||
class MANGOS_DLL_DECL TypeMapContainer
|
||||
{
|
||||
public:
|
||||
template<class SPECIFIC_TYPE> size_t Count() const { return MaNGOS::Count(i_elements, (SPECIFIC_TYPE*)NULL); }
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
size_t Count() const { return MaNGOS::Count(i_elements, (SPECIFIC_TYPE*)NULL); }
|
||||
|
||||
/// inserts a specific object into the container
|
||||
template<class SPECIFIC_TYPE> bool insert(SPECIFIC_TYPE *obj)
|
||||
template<class SPECIFIC_TYPE>
|
||||
bool insert(SPECIFIC_TYPE *obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = MaNGOS::Insert(i_elements, obj);
|
||||
return (t != NULL);
|
||||
}
|
||||
|
||||
/// Removes the object from the container, and returns the removed object
|
||||
template<class SPECIFIC_TYPE> bool remove(SPECIFIC_TYPE* obj)
|
||||
template<class SPECIFIC_TYPE>
|
||||
bool remove(SPECIFIC_TYPE* obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = MaNGOS::Remove(i_elements, obj);
|
||||
return (t != NULL);
|
||||
}
|
||||
|
||||
ContainerMapList<OBJECT_TYPES> & GetElements(void) { return i_elements; }
|
||||
const ContainerMapList<OBJECT_TYPES> & GetElements(void) const { return i_elements;}
|
||||
ContainerMapList<OBJECT_TYPES> & GetElements() { return i_elements; }
|
||||
const ContainerMapList<OBJECT_TYPES> & GetElements() const { return i_elements;}
|
||||
|
||||
private:
|
||||
|
||||
ContainerMapList<OBJECT_TYPES> i_elements;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,81 +33,94 @@ namespace MaNGOS
|
|||
{
|
||||
/* ContainerMapList Helpers */
|
||||
// count functions
|
||||
template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE* /*fake*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
size_t Count(const ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return elements._element.getSize();
|
||||
};
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
size_t Count(const ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
size_t Count(const ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
{
|
||||
return Count(elements._elements,fake);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
size_t Count(const ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
{
|
||||
return Count(elements._TailElements, fake);
|
||||
}
|
||||
|
||||
// non-const insert functions
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE *obj)
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
//elements._element[hdl] = obj;
|
||||
obj->GetGridRef().link(&elements._element, obj);
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// this is a missed
|
||||
template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Insert(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
SPECIFIC_TYPE* Insert(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return NULL; // a missed
|
||||
}
|
||||
|
||||
// Recursion
|
||||
template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE *obj)
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t= Insert(elements._elements, obj);
|
||||
return (t != NULL ? t : Insert(elements._TailElements, obj));
|
||||
}
|
||||
|
||||
// non-const remove method
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<SPECIFIC_TYPE> & /*elements*/, SPECIFIC_TYPE *obj)
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Remove(ContainerMapList<SPECIFIC_TYPE> & /*elements*/, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
obj->GetGridRef().unlink();
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// this is a missed
|
||||
template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Remove(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
SPECIFIC_TYPE* Remove(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return NULL; // a missed
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T, class H> SPECIFIC_TYPE* Remove(ContainerMapList<TypeList<H, T> > &elements, SPECIFIC_TYPE *obj)
|
||||
template<class SPECIFIC_TYPE, class T, class H>
|
||||
SPECIFIC_TYPE* Remove(ContainerMapList<TypeList<H, T> > &elements, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
// The head element is bad
|
||||
SPECIFIC_TYPE* t = Remove(elements._elements, obj);
|
||||
return ( t != NULL ? t : Remove(elements._TailElements, obj) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -32,30 +32,35 @@
|
|||
template<class T, class Y> class TypeContainerVisitor;
|
||||
|
||||
// visitor helper
|
||||
template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
|
||||
template<class VISITOR, class TYPE_CONTAINER>
|
||||
void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
|
||||
{
|
||||
v.Visit(c);
|
||||
};
|
||||
}
|
||||
|
||||
// terminate condition container map list
|
||||
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/)
|
||||
template<class VISITOR>
|
||||
void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/)
|
||||
{
|
||||
}
|
||||
|
||||
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c)
|
||||
template<class VISITOR, class T>
|
||||
void VisitorHelper(VISITOR &v, ContainerMapList<T> &c)
|
||||
{
|
||||
v.Visit(c._element);
|
||||
}
|
||||
|
||||
// recursion container map list
|
||||
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c)
|
||||
template<class VISITOR, class H, class T>
|
||||
void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c)
|
||||
{
|
||||
VisitorHelper(v, c._elements);
|
||||
VisitorHelper(v, c._TailElements);
|
||||
}
|
||||
|
||||
// for TypeMapContainer
|
||||
template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c)
|
||||
template<class VISITOR, class OBJECT_TYPES>
|
||||
void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c)
|
||||
{
|
||||
VisitorHelper(v, c.GetElements());
|
||||
}
|
||||
|
|
@ -64,7 +69,11 @@ template<class VISITOR, class TYPE_CONTAINER>
|
|||
class MANGOS_DLL_DECL TypeContainerVisitor
|
||||
{
|
||||
public:
|
||||
TypeContainerVisitor(VISITOR &v) : i_visitor(v) {}
|
||||
|
||||
TypeContainerVisitor(VISITOR &v)
|
||||
: i_visitor(v)
|
||||
{
|
||||
}
|
||||
|
||||
void Visit(TYPE_CONTAINER &c)
|
||||
{
|
||||
|
|
@ -77,6 +86,8 @@ class MANGOS_DLL_DECL TypeContainerVisitor
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
VISITOR &i_visitor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue