mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-25 14:46:24 +00:00
feat(Core/Visibility): Far visibility worldobjects (#22828)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "Dynamic/TypeList.h"
|
||||
#include "GridRefMgr.h"
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* @class ContainerMapList is a mulit-type container for map elements
|
||||
@@ -50,6 +51,24 @@ struct ContainerMapList<TypeList<H, T>>
|
||||
ContainerMapList<T> _TailElements;
|
||||
};
|
||||
|
||||
template<class OBJECT>
|
||||
struct ContainerVector
|
||||
{
|
||||
std::vector<OBJECT*> _element;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ContainerVector<TypeNull>
|
||||
{
|
||||
};
|
||||
|
||||
template<class H, class T>
|
||||
struct ContainerVector<TypeList<H, T>>
|
||||
{
|
||||
ContainerVector<H> _elements;
|
||||
ContainerVector<T> _TailElements;
|
||||
};
|
||||
|
||||
template<class OBJECT, class KEY_TYPE>
|
||||
struct ContainerUnorderedMap
|
||||
{
|
||||
@@ -123,6 +142,33 @@ private:
|
||||
ContainerMapList<OBJECT_TYPES> i_elements;
|
||||
};
|
||||
|
||||
template<class OBJECT_TYPES>
|
||||
class TypeVectorContainer
|
||||
{
|
||||
public:
|
||||
template<class SPECIFIC_TYPE> [[nodiscard]] std::size_t Count() const { return Acore::Count(i_elements, (SPECIFIC_TYPE*)nullptr); }
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
bool Insert(SPECIFIC_TYPE* obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = Acore::Insert(i_elements, obj);
|
||||
return (t != nullptr);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
bool Remove(SPECIFIC_TYPE* obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = Acore::Remove(i_elements, obj);
|
||||
return (t != nullptr);
|
||||
}
|
||||
|
||||
ContainerVector<OBJECT_TYPES>& GetElements() { return i_elements; }
|
||||
[[nodiscard]] const ContainerVector<OBJECT_TYPES>& GetElements() const { return i_elements; }
|
||||
|
||||
private:
|
||||
ContainerVector<OBJECT_TYPES> i_elements;
|
||||
};
|
||||
|
||||
template<class OBJECT_TYPES, class KEY_TYPE>
|
||||
class TypeUnorderedMapContainer
|
||||
{
|
||||
|
||||
@@ -239,5 +239,101 @@ namespace Acore
|
||||
// SPECIFIC_TYPE* t = Remove(elements._elements, obj);
|
||||
// return ( t != nullptr ? t : Remove(elements._TailElements, obj));
|
||||
//}
|
||||
|
||||
/* ContainerVector Helpers */
|
||||
// count functions
|
||||
template<class SPECIFIC_TYPE>
|
||||
std::size_t Count(const ContainerVector<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return elements._element.getSize();
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
std::size_t Count(const ContainerVector<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
std::size_t Count(const ContainerVector<T>& /*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
std::size_t Count(const ContainerVector<TypeList<SPECIFIC_TYPE, T>>& elements, SPECIFIC_TYPE* fake)
|
||||
{
|
||||
return Count(elements._elements, fake);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
std::size_t Count(const ContainerVector<TypeList<H, T>>& elements, SPECIFIC_TYPE* fake)
|
||||
{
|
||||
return Count(elements._TailElements, fake);
|
||||
}
|
||||
|
||||
// non-const insert functions
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Insert(ContainerVector<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* obj)
|
||||
{
|
||||
elements._element.push_back(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Insert(ContainerVector<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// this is a missed
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
SPECIFIC_TYPE* Insert(ContainerVector<T>& /*elements*/, SPECIFIC_TYPE* /*obj*/)
|
||||
{
|
||||
return nullptr; // a missed
|
||||
}
|
||||
|
||||
// Recursion
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
SPECIFIC_TYPE* Insert(ContainerVector<TypeList<H, T>>& elements, SPECIFIC_TYPE* obj)
|
||||
{
|
||||
SPECIFIC_TYPE* t = Insert(elements._elements, obj);
|
||||
return (t != nullptr ? t : Insert(elements._TailElements, obj));
|
||||
}
|
||||
|
||||
// non-const remove method
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerVector<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
// Simple vector find/swap/pop, this container should be very lightly used
|
||||
// so I don't suspect the linear search complexity to be an issue
|
||||
auto itr = std::find(elements._element.begin(), elements._element.end(), obj);
|
||||
if (itr != elements._element.end())
|
||||
{
|
||||
// Swap the element to be removed with the last element
|
||||
std::swap(*itr, elements._element.back());
|
||||
|
||||
// Remove the last element (which is now the element we wanted to remove)
|
||||
elements._element.pop_back();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerVector<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// this is a missed
|
||||
template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Remove(ContainerVector<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return nullptr; // a missed
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T, class H> SPECIFIC_TYPE* Remove(ContainerVector<TypeList<H, T> > &elements, SPECIFIC_TYPE *obj)
|
||||
{
|
||||
// The head element is bad
|
||||
SPECIFIC_TYPE* t = Remove(elements._elements, obj);
|
||||
return ( t != nullptr ? t : Remove(elements._TailElements, obj));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -56,6 +56,27 @@ template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR& v, TypeM
|
||||
VisitorHelper(v, c.GetElements());
|
||||
}
|
||||
|
||||
// VectorContainer
|
||||
template<class VISITOR> void VisitorHelper(VISITOR& /*v*/, ContainerVector<TypeNull>& /*c*/) {}
|
||||
|
||||
template<class VISITOR, class T> void VisitorHelper(VISITOR& v, ContainerVector<T>& c)
|
||||
{
|
||||
v.Visit(c._element);
|
||||
}
|
||||
|
||||
// recursion container map list
|
||||
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR& v, ContainerVector<TypeList<H, T>>& c)
|
||||
{
|
||||
VisitorHelper(v, c._elements);
|
||||
VisitorHelper(v, c._TailElements);
|
||||
}
|
||||
|
||||
// for TypeMapContainer
|
||||
template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR& v, TypeVectorContainer<OBJECT_TYPES>& c)
|
||||
{
|
||||
VisitorHelper(v, c.GetElements());
|
||||
}
|
||||
|
||||
// TypeUnorderedMapContainer
|
||||
template<class VISITOR, class KEY_TYPE>
|
||||
void VisitorHelper(VISITOR& /*v*/, ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*c*/) { }
|
||||
|
||||
Reference in New Issue
Block a user