diff options
Diffstat (limited to 'src/chunk-bbox.cpp')
| -rw-r--r-- | src/chunk-bbox.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/chunk-bbox.cpp b/src/chunk-bbox.cpp index 78c10a4f..50bbd56a 100644 --- a/src/chunk-bbox.cpp +++ b/src/chunk-bbox.cpp @@ -8,7 +8,7 @@ namespace floormat { template<> -struct chunk::insert_into_lqt<false> +struct chunk::lqt_ops<false> { using BB = loose_quadtree::BoundingBox<std::int16_t>; using TBBE = loose_quadtree::TrivialBBExtractor<std::int16_t>; @@ -17,19 +17,29 @@ struct chunk::insert_into_lqt<false> vec.push_back(bbox); return &vec.back(); } + static void clear_vec(std::vector<BB>& vec) + { + vec.clear(); + } + static void reserve_vec(std::vector<BB>& vec, std::size_t size) + { + vec.reserve(size); + } }; template<> -struct chunk::insert_into_lqt<true> +struct chunk::lqt_ops<true> { using BB = loose_quadtree::BoundingBox<std::int16_t>; - static compact_bb* insert(const BB& bbox, std::vector<void**>&) + static compact_bb* insert(const BB& bbox, unsigned char&) { if constexpr(sizeof(void*) >= sizeof(BB)) return std::bit_cast<compact_bb*>(bbox); else return {}; } + static void clear_vec(unsigned char&) {} + static void reserve_vec(unsigned char&, std::size_t) {} }; struct collision_bbox final @@ -67,12 +77,16 @@ void chunk::ensure_passability() noexcept if (!_lqt_view) _lqt_view = make_lqt(); + using ops = lqt_ops<lqt_compact_bb>; + _lqt_move->Clear(); _lqt_shoot->Clear(); _lqt_view->Clear(); - _bboxes.clear(); + ops::clear_vec(_bboxes); - std::vector<collision_bbox> bboxes; bboxes.reserve(TILE_COUNT*4); + std::vector<collision_bbox> bboxes; + if constexpr(!lqt_compact_bb) + bboxes.reserve(TILE_COUNT*4); constexpr auto whole_tile = [](std::size_t k, pass_mode p) constexpr -> collision_bbox { auto start = tile_start(k); @@ -106,12 +120,11 @@ void chunk::ensure_passability() noexcept bboxes.push_back(wall_west(i, p)); } - if constexpr (!lqt_compact_bb) - _bboxes.reserve(bboxes.size()); + ops::reserve_vec(_bboxes, bboxes.size()); for (const collision_bbox& bbox : bboxes) { - auto* ptr = insert_into_lqt<lqt_compact_bb>::insert(bbox, _bboxes); + auto* ptr = ops::insert(bbox, _bboxes); switch (bbox.pass_mode) { |
