载入中...
搜索中...
未找到
SpatialHash2D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "spatial/Bounds.h"
6#include "spatial/QueryIds.h"
7
8#include <unordered_map>
9#include <unordered_set>
10#include <vector>
11
12namespace eve::spatial {
13
19public:
21 explicit SpatialHash2D(float cellSize = 64.f);
23 ~SpatialHash2D() = default;
24
25 SpatialHash2D(const SpatialHash2D &) = delete;
27
29 void clear();
31 void setCellSize(float cellSize);
33 float getCellSize() const { return cellSize_; }
34
36 bool insert(int id, float minX, float minY, float maxX, float maxY);
38 bool remove(int id);
40 bool update(int id, float minX, float minY, float maxX, float maxY);
42 bool contains(int id) const;
44 int getCount() const { return static_cast<int>(items_.size()); }
45
47 int queryPoint(float x, float y);
49 int queryRect(float minX, float minY, float maxX, float maxY);
51 int queryCircle(float cx, float cy, float radius);
52
54 int getResultCount() const { return results_.getCount(); }
56 int getResultId(int index) const { return results_.getId(index); }
57
58private:
59 void cellRange(const AABB2 &b, int &minCX, int &minCY, int &maxCX, int &maxCY) const;
60 void insertCells(int id, const AABB2 &b);
61 void eraseCells(int id, const AABB2 &b);
62 void queryCells(int minCX, int minCY, int maxCX, int maxCY, const AABB2 *rect, float cx,
63 float cy, float radius, bool useCircle, bool usePoint);
64
65 float cellSize_ = 64.f;
66 std::unordered_map<int, AABB2> items_;
67 std::unordered_map<uint64_t, std::vector<int>> cells_;
68 QueryIds results_;
69};
70
71} // namespace eve::spatial
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
MeleePoint3 b
Definition MeleeHit.cpp:41
float radius
uint32_t index
Last-query hit buffer shared by spatial indexes. Script pattern: call query* → getResultCount / getRe...
Definition QueryIds.h:11
Uniform-grid spatial hash for 2D AABB queries (map / particle / entity culling). Items are registered...
int getResultId(int index) const
Hit id at dense index from the last query*, or -1.
SpatialHash2D & operator=(const SpatialHash2D &)=delete
~SpatialHash2D()=default
Releases hash buckets.
int getCount() const
Number of stored ids.
SpatialHash2D(const SpatialHash2D &)=delete
float getCellSize() const
Current uniform cell size.
int getResultCount() const
Number of hits from the last query*.
Axis-aligned 2D bounding box (min/max inclusive).
Definition Bounds.h:10