diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-06 22:30:06 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-06 22:30:06 +0100 |
| commit | ef690aa28d8d12e2c998de94816a719170a5d696 (patch) | |
| tree | 5e1f3227b8f062d0659db460527eb1929237d43f /src | |
| parent | 646f9d9774d72e9459f50726b200a586d7e07614 (diff) | |
src/chunk: remove remaining lqt vector calls on 64-bit
Diffstat (limited to 'src')
| -rw-r--r-- | src/chunk-bbox.cpp | 29 | ||||
| -rw-r--r-- | src/chunk.hpp | 4 |
2 files changed, 23 insertions, 10 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) { diff --git a/src/chunk.hpp b/src/chunk.hpp index 2d2a5c75..3a6ea3df 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -99,10 +99,10 @@ private: std::array<std::shared_ptr<anim_atlas>, TILE_COUNT> _scenery_atlases; std::array<scenery, TILE_COUNT> _scenery_variants = {}; - template<bool> struct insert_into_lqt; + template<bool> struct lqt_ops; std::unique_ptr<lqt> _lqt_move, _lqt_shoot, _lqt_view; - std::vector<std::conditional_t<lqt_compact_bb, void**, loose_quadtree::BoundingBox<std::int16_t>>> _bboxes; + std::conditional_t<lqt_compact_bb, unsigned char, std::vector<loose_quadtree::BoundingBox<std::int16_t>>> _bboxes; GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}; mutable bool _maybe_empty : 1 = true, |
