载入中...
搜索中...
未找到
CrowdSpatialIndex.cpp
浏览该文件的文档.
2namespace eve::crowd {
3std::int64_t CrowdSpatialIndex::coordinate(double value, double cell) {
4 const double key = std::floor(value / cell);
5 if (!std::isfinite(key) || key < -0x1p63 || key >= 0x1p63)
6 throw WorkLimit{"Crowd spatial coordinate exceeds signed 64-bit range"};
7 return static_cast<std::int64_t>(key);
8}
9std::int64_t CrowdSpatialIndex::queryBound(double value, double cell) noexcept {
10 const double key = std::floor(value / cell);
11 if (key < -0x1p63) return std::numeric_limits<std::int64_t>::min();
12 if (key >= 0x1p63) return std::numeric_limits<std::int64_t>::max();
13 return static_cast<std::int64_t>(key);
14}
15void CrowdSpatialIndex::rebuild(std::span<const float> xs, std::span<const float> ys, std::span<const CrowdTieKey> ties,
16 double cellSize, std::int64_t maxCells, std::int64_t& comparisons) {
17 if (xs.size() != ys.size() || xs.size() != ties.size() || xs.size() > std::numeric_limits<int>::max() ||
18 !std::isfinite(cellSize) || cellSize < 1.0 || maxCells < 1)
19 throw WorkLimit{"Invalid Crowd spatial input or cell budget"};
20 clear();
21 cellSize_ = cellSize;
22 members_.reserve(xs.size());
23 for (std::size_t i = 0; i < xs.size(); ++i)
24 members_.push_back({coordinate(xs[i], cellSize_), coordinate(ys[i], cellSize_), ties[i], static_cast<int>(i)});
25 std::sort(members_.begin(), members_.end(), [&](const Member& a, const Member& b) {
26 ++comparisons;
27 if (a.y != b.y) return a.y < b.y;
28 if (a.x != b.x) return a.x < b.x;
29 return a.tie < b.tie;
30 });
31 for (std::size_t begin = 0; begin < members_.size();) {
32 std::size_t end = begin + 1;
33 while (end < members_.size() && members_[end].x == members_[begin].x && members_[end].y == members_[begin].y)
34 ++end;
35 if (cells_.size() >= static_cast<std::uint64_t>(maxCells))
36 throw WorkLimit{"Crowd occupied cell budget exhausted"};
37 cells_.push_back({members_[begin].x, members_[begin].y, begin, end});
38 begin = end;
39 }
40 for (std::size_t begin = 0; begin < cells_.size();) {
41 std::size_t end = begin + 1;
42 while (end < cells_.size() && cells_[end].y == cells_[begin].y) ++end;
43 rows_.push_back({cells_[begin].y, begin, end});
44 begin = end;
45 }
46}
47} // namespace eve::crowd
SQObjectPtr key
Definition ECS.cpp:155
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
Object::Ptr value
size_t begin
size_t end
Cell cell
void rebuild(std::span< const float > xs, std::span< const float > ys, std::span< const CrowdTieKey > ties, double cellSize, std::int64_t maxCells, std::int64_t &comparisons)
Rebuild owning directories; failure is handled by the surrounding advance rollback....
void clear() noexcept
Invalidate derived directories without releasing reusable capacity; no callbacks.
Non-allocating internal unwind signal, translated at the checked simulation boundary.