mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[9307] Grid containers, cleanup
Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
aac24092c2
commit
0c8fccbd47
9 changed files with 48 additions and 228 deletions
|
|
@ -58,23 +58,18 @@ class MANGOS_DLL_DECL Grid
|
|||
|
||||
/** an object of interested enters the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> bool AddWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> bool AddWorldObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return i_objects.template insert<SPECIFIC_OBJECT>(hdl, 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, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> bool RemoveWorldObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return i_objects.template remove<SPECIFIC_OBJECT>(obj, hdl);
|
||||
return i_objects.template remove<SPECIFIC_OBJECT>(obj);
|
||||
}
|
||||
|
||||
/** Accessors: Returns a specific type of object in the WORDL_OBJECT_TYPES
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetWorldObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT* fake) const { return i_objects.template find<SPECIFIC_OBJECT>(hdl); }
|
||||
template<class SPECIFIC_OBJECT> SPECIFIC_OBJECT* GetWorldObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) { return i_objects.template find<SPECIFIC_OBJECT>(hdl, fake); }
|
||||
|
||||
/** Refreshes/update the grid. This required for remote grids.
|
||||
*/
|
||||
void RefreshGrid(void) { /* TBI */}
|
||||
|
|
@ -105,27 +100,22 @@ class MANGOS_DLL_DECL Grid
|
|||
*/
|
||||
unsigned int ActiveObjectsInGrid(void) const { return m_activeGridObjects.size()+i_objects.template Count<ACTIVE_OBJECT>(); }
|
||||
|
||||
/** Accessors: Returns a specific type of object in the GRID_OBJECT_TYPES
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetGridObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) const { return i_container.template find<SPECIFIC_OBJECT>(hdl, fake); }
|
||||
template<class SPECIFIC_OBJECT> SPECIFIC_OBJECT* GetGridObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) { return i_container.template find<SPECIFIC_OBJECT>(hdl, fake); }
|
||||
|
||||
/** Inserts a container type object into the grid.
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(obj->isActiveObject())
|
||||
m_activeGridObjects.insert(obj);
|
||||
return i_container.template insert<SPECIFIC_OBJECT>(hdl, 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, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(obj->isActiveObject())
|
||||
m_activeGridObjects.erase(obj);
|
||||
return i_container.template remove<SPECIFIC_OBJECT>(obj, hdl);
|
||||
return i_container.template remove<SPECIFIC_OBJECT>(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -117,14 +117,14 @@ class MANGOS_DLL_DECL NGrid
|
|||
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, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).AddWorldObject(obj, hdl);
|
||||
getGridType(x, y).AddWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).RemoveWorldObject(obj, hdl);
|
||||
getGridType(x, y).RemoveWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class T, class TT> void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
|
|
@ -148,24 +148,14 @@ class MANGOS_DLL_DECL NGrid
|
|||
return count;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetGridObject(const uint32 x, const uint32 y, OBJECT_HANDLE hdl) const
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).template GetGridObject<SPECIFIC_OBJECT>(hdl);
|
||||
return getGridType(x, y).AddGridObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> SPECIFIC_OBJECT* GetGridObject(const uint32 x, const uint32 y, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).template GetGridObject<SPECIFIC_OBJECT>(hdl);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
|
||||
{
|
||||
return getGridType(x, y).AddGridObject(hdl, obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
|
||||
{
|
||||
return getGridType(x, y).RemoveGridObject(obj, hdl);
|
||||
return getGridType(x, y).RemoveGridObject(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -143,7 +143,6 @@ class TypeUnorderedMapContainer
|
|||
*/
|
||||
template<class OBJECT> struct ContainerMapList
|
||||
{
|
||||
//std::map<OBJECT_HANDLE, OBJECT *> _element;
|
||||
GridRefManager<OBJECT> _element;
|
||||
};
|
||||
|
||||
|
|
@ -156,40 +155,6 @@ template<class H, class T> struct ContainerMapList<TypeList<H, T> >
|
|||
ContainerMapList<T> _TailElements;
|
||||
};
|
||||
|
||||
/*
|
||||
* @class ContaierArrayList is a multi-type container for
|
||||
* array of elements.
|
||||
*/
|
||||
template<class OBJECT> struct ContainerArrayList
|
||||
{
|
||||
std::vector<OBJECT> _element;
|
||||
};
|
||||
|
||||
// termination condition
|
||||
template<> struct ContainerArrayList<TypeNull> {};
|
||||
// recursion
|
||||
template<class H, class T> struct ContainerArrayList<TypeList<H, T> >
|
||||
{
|
||||
ContainerArrayList<H> _elements;
|
||||
ContainerArrayList<T> _TailElements;
|
||||
};
|
||||
|
||||
/*
|
||||
* @class ContainerList is a simple list of different types of elements
|
||||
*
|
||||
*/
|
||||
template<class OBJECT> struct ContainerList
|
||||
{
|
||||
OBJECT _element;
|
||||
};
|
||||
|
||||
/* TypeNull is underfined */
|
||||
template<> struct ContainerList<TypeNull> {};
|
||||
template<class H, class T> struct ContainerList<TypeList<H, T> >
|
||||
{
|
||||
ContainerList<H> _elements;
|
||||
ContainerMapList<T> _TailElements;
|
||||
};
|
||||
|
||||
#include "TypeContainerFunctions.h"
|
||||
|
||||
|
|
@ -206,22 +171,17 @@ 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> SPECIFIC_TYPE* find(OBJECT_HANDLE hdl, SPECIFIC_TYPE *fake) { return MaNGOS::Find(i_elements, hdl,fake); }
|
||||
|
||||
/// find a specific type of object in the container
|
||||
template<class SPECIFIC_TYPE> const SPECIFIC_TYPE* find(OBJECT_HANDLE hdl, SPECIFIC_TYPE *fake) const { return MaNGOS::Find(i_elements, hdl,fake); }
|
||||
|
||||
/// inserts a specific object into the container
|
||||
template<class SPECIFIC_TYPE> bool insert(OBJECT_HANDLE hdl, SPECIFIC_TYPE *obj)
|
||||
template<class SPECIFIC_TYPE> bool insert(SPECIFIC_TYPE *obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = MaNGOS::Insert(i_elements, obj, hdl);
|
||||
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, OBJECT_HANDLE hdl)
|
||||
template<class SPECIFIC_TYPE> bool remove(SPECIFIC_TYPE* obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = MaNGOS::Remove(i_elements, obj, hdl);
|
||||
SPECIFIC_TYPE* t = MaNGOS::Remove(i_elements, obj);
|
||||
return (t != NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,114 +58,55 @@ namespace MaNGOS
|
|||
return Count(elements._TailElements, fake);
|
||||
}
|
||||
|
||||
// non-const find functions
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Find(ContainerMapList<SPECIFIC_TYPE> &/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
//typename std::map<OBJECT_HANDLE, SPECIFIC_TYPE *>::iterator iter = elements._element.find(hdl);
|
||||
//return (iter == elements._element.end() ? NULL : iter->second);
|
||||
return NULL;
|
||||
};
|
||||
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Find(ContainerMapList<TypeNull> &/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return NULL; // terminate recursion
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Find(ContainerMapList<T> &/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return NULL; // this is a missed
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Find(ContainerMapList<TypeList<H, T> >&/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
//SPECIFIC_TYPE* t = Find(elements._elements, hdl,fake);
|
||||
//return (t != NULL ? t :Find(elements._TailElements, hdl,fake));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// const find functions
|
||||
template<class SPECIFIC_TYPE> const SPECIFIC_TYPE* Find(const ContainerMapList<SPECIFIC_TYPE> &/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
//typename SPECIFIC_TYPE::iterator iter = elements._element.find(hdl);
|
||||
//return (iter == elements._element.end() ? NULL : iter->second);
|
||||
return NULL;
|
||||
};
|
||||
|
||||
template<class SPECIFIC_TYPE> const SPECIFIC_TYPE* Find(const ContainerMapList<TypeNull> &/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T> const SPECIFIC_TYPE* Find(const ContainerMapList<T> &/*elements*/, OBJECT_HANDLE /*hdl*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Find(const ContainerMapList<TypeList<H, T> >&elements, OBJECT_HANDLE hdl, SPECIFIC_TYPE* fake)
|
||||
{
|
||||
SPECIFIC_TYPE* t = Find(elements._elements, hdl,fake);
|
||||
if( t)
|
||||
return t;
|
||||
|
||||
return Find(elements._TailElement, hdl,fake);
|
||||
}
|
||||
|
||||
// non-const insert functions
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE *obj, OBJECT_HANDLE /*hdl*/)
|
||||
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*/, OBJECT_HANDLE /*hdl*/)
|
||||
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*/, OBJECT_HANDLE /*hdl*/)
|
||||
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, OBJECT_HANDLE hdl)
|
||||
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, hdl);
|
||||
return (t != NULL ? t : Insert(elements._TailElements, obj, hdl));
|
||||
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, OBJECT_HANDLE /*hdl*/)
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<SPECIFIC_TYPE> & /*elements*/, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
/*typename std::map<OBJECT_HANDLE, SPECIFIC_TYPE *>::iterator iter = elements._element.find(hdl);
|
||||
if( iter != elements._element.end() )
|
||||
{
|
||||
SPECIFIC_TYPE* t = iter->second;
|
||||
elements._element.erase(iter);
|
||||
return t;
|
||||
}*/
|
||||
obj->GetGridRef().unlink();
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/, OBJECT_HANDLE /*hdl*/)
|
||||
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*/, OBJECT_HANDLE /*hdl*/)
|
||||
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, OBJECT_HANDLE hdl)
|
||||
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, hdl);
|
||||
return ( t != NULL ? t : Remove(elements._TailElements, obj, hdl) );
|
||||
SPECIFIC_TYPE* t = Remove(elements._elements, obj);
|
||||
return ( t != NULL ? t : Remove(elements._TailElements, obj) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
/*
|
||||
* @class TypeContainerVisitor is implemented as a visitor pattern. It is
|
||||
* a visitor to the TypeContainerList or TypeContainerMapList. The visitor has
|
||||
* a visitor to the TypeMapContainer or ContainerMapList. The visitor has
|
||||
* to overload its types as a visit method is called.
|
||||
*/
|
||||
|
||||
|
|
@ -37,23 +37,6 @@ template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYP
|
|||
v.Visit(c);
|
||||
};
|
||||
|
||||
// terminate condition for container list
|
||||
template<class VISITOR> void VisitorHelper(VISITOR &v, ContainerList<TypeNull> &c)
|
||||
{
|
||||
}
|
||||
|
||||
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerList<T> &c)
|
||||
{
|
||||
v.Visit(c._element);
|
||||
}
|
||||
|
||||
// recursion for container list
|
||||
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerList<TypeList<H, T> > &c)
|
||||
{
|
||||
VisitorHelper(v, c._elements);
|
||||
VisitorHelper(v, c._TailElements);
|
||||
}
|
||||
|
||||
// terminate condition container map list
|
||||
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/)
|
||||
{
|
||||
|
|
@ -71,23 +54,6 @@ template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, Contain
|
|||
VisitorHelper(v, c._TailElements);
|
||||
}
|
||||
|
||||
// array list
|
||||
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<T> &c)
|
||||
{
|
||||
v.Visit(c._element);
|
||||
}
|
||||
|
||||
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerArrayList<TypeNull> &/*c*/)
|
||||
{
|
||||
}
|
||||
|
||||
// recursion
|
||||
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue