18 #ifndef INCLUDED_SPATIAL
19 #define INCLUDED_SPATIAL
71 items.push_back(value);
77 if ((
int)
items.size() > 1)
88 int count = (int)
items.size();
91 LOGWARNING(L
"SpatialSubdivision Query too large. Results truncated.");
96 for (
int i = 0; i < count; ++i)
126 for (
size_t i = 0; i < n; ++i)
140 for (
size_t i = 0; i < n; ++i)
173 std::sort(a.begin(), a.end());
174 std::sort(b.begin(), b.end());
183 return !(*
this == rhs);
202 ENSURE(toMin.
X <= toMax.
X && toMin.
Y <= toMax.
Y);
208 for (
u32 j = j0; j <= j1; ++j)
210 for (
u32 i = i0; i <= i1; ++i)
224 ENSURE(fromMin.
X <= fromMax.
X && fromMin.
Y <= fromMax.
Y);
230 for (
u32 j = j0; j <= j1; ++j)
232 for (
u32 i = i0; i <= i1; ++i)
235 int size = div.
items.size();
236 for (
int n = 0; n < size; ++n)
238 if (div.
items[n] == item)
257 Remove(item, fromMin, fromMax);
258 Add(item, toMin, toMax);
283 Move(item, from, from, to, to);
293 ENSURE(posMin.
X <= posMax.
X && posMin.
Y <= posMax.
Y);
299 for (
u32 j = j0; j <= j1; ++j)
301 for (
u32 i = i0; i <= i1; ++i)
370 for (
size_t i = 0; i < count; ++i)
382 for (
size_t i = 0; i < count; ++i)
387 #endif // INCLUDED_SPATIAL
A simple fixed-point number class.
uint32_t GetWidth() const
void GetInRange(SpatialQueryArray &out, CFixedVector2D posMin, CFixedVector2D posMax)
Returns a sorted list of unique items that includes all items within the given axis-aligned square ra...
void NumberFixed_Unbounded(const char *name, fixed value)
Serialize a number.
Helper templates for serializing/deserializing common objects.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
uint32_t GetI0(entity_pos_t x)
void GetNear(SpatialQueryArray &out, CFixedVector2D pos, entity_pos_t range)
Returns a sorted list of unique items that includes all items within the given circular distance of t...
void Remove(uint32_t item, CFixedVector2D fromMin, CFixedVector2D fromMax)
Remove an item with the given 'from' size.
void Reset(entity_pos_t maxX, entity_pos_t maxZ, entity_pos_t divisionSize)
void copy_items(SpatialQueryArray &out)
const uint32_t & operator[](int index) const
Serialization interface; see serialization overview.
SpatialSubdivision & operator=(const SpatialSubdivision &rhs)
static void out(const wchar_t *fmt,...)
uint32_t GetHeight() const
void Create(size_t count)
virtual void NumberU32_Unbounded(const char *name, uint32_t &out)
uint32_t GetIndex0(CFixedVector2D pos)
T Clamp(T val, T min, T max)
low-level aka "lib"
virtual void NumberFixed_Unbounded(const char *name, fixed &out)
entity_pos_t m_DivisionSize
void Remove(uint32_t item, CFixedVector2D from)
Convenience function for Remove() of individual points.
friend struct SerializeSubDivisionGrid
uint32_t & operator[](int index)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
bool operator==(const SpatialSubdivision &rhs)
Equivalence test (ignoring order of items within each subdivision)
uint32_t GetI1(entity_pos_t x)
uint32_t GetJ0(entity_pos_t z)
void operator()(IDeserializer &serialize, const char *name, SpatialSubdivision &value)
void push_back(uint32_t value)
void NumberU32_Unbounded(const char *name, uint32_t value)
Serialize a number.
void Add(uint32_t item, CFixedVector2D to)
Convenience function for Add() of individual points.
A very basic subdivision scheme for finding items in ranges.
uint32_t GetJ1(entity_pos_t z)
SubDivisionGrid * m_Divisions
bool operator!=(const SpatialSubdivision &rhs)
void Move(uint32_t item, CFixedVector2D from, CFixedVector2D to)
Convenience function for Move() of individual points.
SpatialSubdivision(const SpatialSubdivision &rhs)
uint32_t items[MAX_COUNT]
A simple fixed-size array that works similar to an std::vector but is obviously limited in its max it...
void Move(uint32_t item, CFixedVector2D fromMin, CFixedVector2D fromMax, CFixedVector2D toMin, CFixedVector2D toMax)
Equivalent to Remove() then Add(), but potentially faster.
Serialization helper template for SpatialSubdivision.
void Add(uint32_t item, CFixedVector2D toMin, CFixedVector2D toMax)
Add an item with the given 'to' size.
uint32_t GetIndex1(CFixedVector2D pos)
void operator()(ISerializer &serialize, const char *name, SpatialSubdivision &value)
std::vector< uint32_t > items
entity_pos_t GetDivisionSize() const
Deserialization interface; see serialization overview.