summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-24 23:15:50 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-24 23:15:50 +0100
commit3adb32e27798c59b4477a86484a3c82b75ce574d (patch)
tree1aeb91172813cda8dfd347942b43ee94dbcbec4c /src
parentb2720141c73d7e6770774e832786d00d17a02e19 (diff)
pass explicit collision_data for rtree node
Diffstat (limited to 'src')
-rw-r--r--src/chunk-collision.cpp22
-rw-r--r--src/chunk.cpp2
-rw-r--r--src/chunk.hpp4
-rw-r--r--src/collision.hpp2
4 files changed, 19 insertions, 11 deletions
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index cfb157a9..b6ac2745 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -11,13 +11,21 @@
namespace floormat {
+bool collision_data::operator==(const collision_data&) const noexcept = default;
+bool chunk::bbox::operator==(const floormat::chunk::bbox& other) const noexcept = default;
+
chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &*_rtree; }
namespace {
+constexpr collision_data make_id_(collision_type type, pass_mode p, object_id id)
+{
+ return collision_data { (object_id)type, (object_id)p, id };
+}
+
constexpr object_id make_id(collision_type type, pass_mode p, object_id id)
{
- return std::bit_cast<object_id>(collision_data { (object_id)type, (object_id)p, id });
+ return std::bit_cast<object_id>(make_id_(type, p, id));
}
} // namespace
@@ -69,8 +77,8 @@ void chunk::ensure_passability() noexcept
bool chunk::_bbox_for_scenery(const object& s, local_coords local, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, bbox& value) noexcept
{
auto [start, end] = scenery_tile(local, offset, bbox_offset, bbox_size);
- auto id = make_id(collision_type::scenery, s.pass, s.id);
- value = { .id = id, .start = start, .end = end };
+ auto id = make_id_(collision_type::scenery, s.pass, s.id);
+ value = { .data = id, .start = start, .end = end };
return s.atlas && !Vector2ui(s.bbox_size).isZero();
}
@@ -82,13 +90,13 @@ bool chunk::_bbox_for_scenery(const object& s, bbox& value) noexcept
void chunk::_remove_bbox(const bbox& x)
{
auto start = Vector2(x.start), end = Vector2(x.end);
- _rtree->Remove(start.data(), end.data(), x.id);
+ _rtree->Remove(start.data(), end.data(), std::bit_cast<object_id>(x.data));
}
void chunk::_add_bbox(const bbox& x)
{
auto start = Vector2(x.start), end = Vector2(x.end);
- _rtree->Insert(start.data(), end.data(), x.id);
+ _rtree->Insert(start.data(), end.data(), std::bit_cast<object_id>(x.data));
}
void chunk::_replace_bbox(const bbox& x0, const bbox& x1, bool b0, bool b1)
@@ -96,10 +104,10 @@ void chunk::_replace_bbox(const bbox& x0, const bbox& x1, bool b0, bool b1)
if (_pass_modified)
return;
- unsigned i = (unsigned)b1 << 1 | (unsigned)(b0 ? 1 : 0) << 0;
+ unsigned i = (unsigned)b1 << 1 | (unsigned)!!b0 << 0;
CORRADE_ASSUME(i < 4u); (void)0;
- switch (i) // NOLINT(hicpp-multiway-paths-covered)
+ switch (i)
{
case 1 << 1 | 1 << 0:
if (x1 == x0)
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 0c02495e..18b8a6f1 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -159,8 +159,6 @@ chunk::~chunk() noexcept
chunk::chunk(chunk&&) noexcept = default;
chunk& chunk::operator=(chunk&&) noexcept = default;
-bool chunk::bbox::operator==(const bbox& other) const noexcept = default;
-
void chunk::add_object_unsorted(const std::shared_ptr<object>& e)
{
_objects_sorted = false;
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 0efe9847..cc48bb26 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -162,9 +162,9 @@ private:
static void delete_pass_region(pass_region*& ptr);
- struct bbox final // NOLINT(cppcoreguidelines-pro-type-member-init)
+ struct bbox final
{
- object_id id; // todo change to collision_data
+ collision_data data;
Vector2i start, end;
bool operator==(const bbox& other) const noexcept;
diff --git a/src/collision.hpp b/src/collision.hpp
index e5605f4e..623ae79c 100644
--- a/src/collision.hpp
+++ b/src/collision.hpp
@@ -16,6 +16,8 @@ struct collision_data final {
uint64_t tag : 2;
uint64_t pass : 2;
uint64_t data : collision_data_BITS;
+
+ bool operator==(const collision_data&) const noexcept;
};
} // namespace floormat