summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/region.cpp15
-rw-r--r--editor/tests/region-test.cpp4
-rw-r--r--src/chunk-region.cpp40
-rw-r--r--src/chunk.cpp5
-rw-r--r--src/chunk.hpp13
-rw-r--r--src/object.cpp4
-rw-r--r--test/region.cpp23
7 files changed, 26 insertions, 78 deletions
diff --git a/bench/region.cpp b/bench/region.cpp
index 0e2c460e..1e27800a 100644
--- a/bench/region.cpp
+++ b/bench/region.cpp
@@ -66,35 +66,34 @@ void Chunk_Region(benchmark::State& state)
auto& c5 = make_chunk1(w[chunk_coords_{5, 0, 0}], false, true);
auto& c6 = make_chunk1(w[chunk_coords_{6, 0, 0}], false, false);
auto& c7 = make_chunk1(w[chunk_coords_{7, 0, 0}], true, true);
- chunk::pass_region p;
for (auto _ : state)
{
- { p = {}; c1.make_pass_region(p);
+ { auto p = c1.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt == p.bits.size());
}
- { p = {}; c2.make_pass_region(p);
+ { auto p = c2.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt != 0 && cnt != p.bits.size());
}
- { p = {}; c3.make_pass_region(p);
+ { auto p = c3.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt == 0);
}
- { p = {}; c4.make_pass_region(p);
+ { auto p = c4.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt != 0 && cnt < 100);
}
- { p = {}; c5.make_pass_region(p);
+ { auto p = c5.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt != 0 && cnt != p.bits.size());
}
- { p = {}; c6.make_pass_region(p);
+ { auto p = c6.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt != 0 && cnt != p.bits.size());
}
- { p = {}; c7.make_pass_region(p);
+ { auto p = c7.make_pass_region();
auto cnt = p.bits.count();
fm_assert(cnt != 0 && cnt != p.bits.size());
}
diff --git a/editor/tests/region-test.cpp b/editor/tests/region-test.cpp
index 907ea99c..47272593 100644
--- a/editor/tests/region-test.cpp
+++ b/editor/tests/region-test.cpp
@@ -152,10 +152,8 @@ void region_test::do_region_extraction(world& w, chunk_coords_ coord)
{
if (auto* c = w.at(coord))
{
- chunk::pass_region r;
- c->make_pass_region(r);
result = {
- .is_passable = r.bits,
+ .is_passable = c->make_pass_region().bits,
.c = coord,
.exists = true,
};
diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp
index c976fd28..c0afe9f0 100644
--- a/src/chunk-region.cpp
+++ b/src/chunk-region.cpp
@@ -128,44 +128,14 @@ auto default_region_predicate(chunk& c) noexcept
} // namespace
-void chunk::delete_pass_region(pass_region*& ptr)
+auto chunk::make_pass_region() -> pass_region
{
- if (ptr)
- {
- delete ptr;
- ptr = nullptr;
- }
+ return make_pass_region(default_region_predicate(*this));
}
-auto chunk::get_pass_region() -> const pass_region*
+auto chunk::make_pass_region(const pred& f) -> pass_region
{
- if (!_region_modified)
- {
- fm_debug_assert(_region != nullptr);
- return _region;
- }
- _region_modified = false;
-
- if (!_region)
- _region = new pass_region;
- else
- _region->bits = {};
-
- make_pass_region(*_region);
- return _region;
-}
-
-bool chunk::is_region_modified() const noexcept { return _region_modified; }
-void chunk::mark_region_modified() noexcept { _region_modified = true; }
-
-void chunk::make_pass_region(pass_region& ret)
-{
- return make_pass_region(ret, default_region_predicate(*this));
-}
-
-void chunk::make_pass_region(pass_region& ret, const pred& f)
-{
- ret = {};
+ pass_region ret;
auto& tmp = get_tmp();
const auto nbs = _world->neighbors(_coord);
@@ -204,6 +174,8 @@ void chunk::make_pass_region(pass_region& ret, const pred& f)
tmp.append(ret.bits, pos);
}
}
+
+ return ret;
}
} // namespace floormat
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 18b8a6f1..a3c03b81 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -126,7 +126,6 @@ void chunk::mark_passability_modified() noexcept
if (!_pass_modified && is_log_verbose()) [[unlikely]]
fm_debug("pass reload %zu", ++_reload_no_);
_pass_modified = true;
- _region_modified = true;
}
bool chunk::is_passability_modified() const noexcept { return _pass_modified; }
@@ -153,7 +152,6 @@ chunk::~chunk() noexcept
arrayResize(_objects, 0);
arrayShrink(_objects);
_rtree->RemoveAll();
- delete_pass_region(_region);
}
chunk::chunk(chunk&&) noexcept = default;
@@ -162,7 +160,6 @@ chunk& chunk::operator=(chunk&&) noexcept = default;
void chunk::add_object_unsorted(const std::shared_ptr<object>& e)
{
_objects_sorted = false;
- _region_modified = true;
if (!e->is_dynamic())
mark_scenery_modified();
if (bbox bb; _bbox_for_scenery(*e, bb))
@@ -185,7 +182,6 @@ void chunk::sort_objects()
void chunk::add_object(const std::shared_ptr<object>& e)
{
fm_assert(_objects_sorted);
- _region_modified = true;
if (!e->is_dynamic())
mark_scenery_modified();
if (bbox bb; _bbox_for_scenery(*e, bb))
@@ -199,7 +195,6 @@ void chunk::add_object(const std::shared_ptr<object>& e)
void chunk::remove_object(size_t i)
{
fm_assert(_objects_sorted);
- _region_modified = true;
auto& es = _objects;
fm_debug_assert(i < es.size());
const auto e = es[i];
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 682482f7..e2b812fb 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -27,7 +27,6 @@ public:
friend struct tile_ref;
friend struct object;
friend class world;
- struct pass_region;
tile_ref operator[](size_t idx) noexcept;
tile_proto operator[](size_t idx) const noexcept;
@@ -63,12 +62,10 @@ public:
void mark_walls_modified() noexcept;
void mark_scenery_modified() noexcept;
void mark_passability_modified() noexcept;
- void mark_region_modified() noexcept;
void mark_modified() noexcept;
bool is_passability_modified() const noexcept;
bool is_scenery_modified() const noexcept;
- bool is_region_modified() const noexcept;
struct ground_mesh_tuple final {
GL::Mesh& mesh;
@@ -84,6 +81,7 @@ public:
struct object_draw_order;
struct scenery_mesh_tuple;
struct scenery_scratch_buffers;
+ struct pass_region;
struct vertex {
Vector3 position;
@@ -119,9 +117,8 @@ public:
static constexpr size_t max_wall_quad_count =
TILE_COUNT*Wall::Direction_COUNT*(Wall::Group_COUNT+4);
- const pass_region* get_pass_region();
- void make_pass_region(pass_region& ret);
- void make_pass_region(pass_region& ret, const Search::pred& f);
+ pass_region make_pass_region();
+ pass_region make_pass_region(const Search::pred& f);
private:
struct ground_stuff
@@ -140,7 +137,6 @@ private:
Pointer<ground_stuff> _ground;
Pointer<wall_stuff> _walls;
- pass_region* _region = nullptr;
Array<std::shared_ptr<object>> _objects;
class world* _world;
GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate};
@@ -152,15 +148,12 @@ private:
_walls_modified : 1 = true,
_scenery_modified : 1 = true,
_pass_modified : 1 = true,
- _region_modified : 1 = true,
_teardown : 1 = false,
_objects_sorted : 1 = true;
void ensure_scenery_buffers(scenery_scratch_buffers bufs);
static topo_sort_data make_topo_sort_data(object& e, uint32_t mesh_idx);
- static void delete_pass_region(pass_region*& ptr);
-
struct bbox final
{
collision_data data;
diff --git a/src/object.cpp b/src/object.cpp
index 010c1aa5..307a2155 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -68,7 +68,6 @@ object::~object() noexcept
if (chunk::bbox bb; c->_bbox_for_scenery(*this, bb))
c->_remove_bbox(bb);
c->_world->do_kill_object(id);
- c->mark_region_modified();
const_cast<object_id&>(id) = 0;
}
@@ -241,7 +240,6 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r)
if (coord_.chunk() == coord.chunk())
{
c->_replace_bbox(bb0, bb1, b0, b1);
- c->mark_region_modified();
const_cast<global_coords&>(coord) = coord_;
set_bbox_(offset_, bb_offset, bb_size, pass);
const_cast<rotation&>(r) = new_r;
@@ -253,7 +251,6 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r)
c2.mark_scenery_modified();
c2._add_bbox(bb1);
c->remove_object(i);
- c->mark_region_modified();
auto& es = c2._objects;
auto it = std::lower_bound(es.cbegin(), es.cend(), e_, object_id_lessp);
const_cast<global_coords&>(coord) = coord_;
@@ -305,7 +302,6 @@ void object::set_bbox(Vector2b offset_, Vector2b bb_offset_, Vector2ub bb_size_,
set_bbox_(offset_, bb_offset_, bb_size_, pass);
const bool b = c->_bbox_for_scenery(*this, bb);
c->_replace_bbox(bb0, bb, b0, b);
- c->mark_region_modified();
}
bool object::can_activate(size_t) const { return false; }
diff --git a/test/region.cpp b/test/region.cpp
index 9b09cdf9..ab0d552a 100644
--- a/test/region.cpp
+++ b/test/region.cpp
@@ -49,16 +49,14 @@ void test1()
{
auto w = world();
auto& c = make_chunk1(w[COORD], true, false);
- auto p = chunk::pass_region{};
- c.make_pass_region(p);
+ auto p = c.make_pass_region();
const auto count = p.bits.count();
fm_assert(count > 1000);
fm_assert(p.bits.size() - count > 2000);
- fm_assert(c.get_pass_region()->bits == p.bits);
+ fm_assert(c.make_pass_region().bits == p.bits);
{ auto w = world();
auto& c = make_chunk1(w[COORD], true, true);
- auto p2 = chunk::pass_region{};
- c.make_pass_region(p2);
+ auto p2 = c.make_pass_region();
fm_assert(p2.bits.count() == count);
}
}
@@ -67,15 +65,13 @@ void test2()
{
auto w = world();
auto& c = make_chunk1(w[COORD], false, false);
- auto p = chunk::pass_region{};
- c.make_pass_region(p);
+ auto p = c.make_pass_region();
const auto count = p.bits.count();
fm_assert(count > 1000);
fm_assert(p.bits.size() - count > 2000);
{ auto w = world();
auto& c = make_chunk1(w[COORD], false, true);
- auto p2 = chunk::pass_region{};
- c.make_pass_region(p2);
+ auto p2 = c.make_pass_region();
fm_assert(p2.bits.count() == count);
}
}
@@ -84,11 +80,10 @@ void test3()
{
auto w = world();
auto& c = make_chunk1(w[COORD], true, false);
- const auto bits = c.get_pass_region()->bits;
+ const auto bits = c.make_pass_region().bits;
fm_assert(bits.count() > 1000);
- { auto p2 = chunk::pass_region{};
- c.make_pass_region(p2);
+ { auto p2 = c.make_pass_region();
fm_assert(p2.bits == bits);
}
@@ -96,10 +91,10 @@ void test3()
fm_assert(c[{0, 0}].ground() != empty);
c[{0, 0}].ground() = empty;
- fm_assert(c.get_pass_region()->bits == bits);
+ fm_assert(c.make_pass_region().bits == bits);
c.mark_passability_modified();
- fm_assert(c.get_pass_region()->bits != bits);
+ fm_assert(c.make_pass_region().bits != bits);
}
}