diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 03:18:00 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 03:18:00 +0100 |
commit | f3d870a400395e75f601f32a3bbb3e68502d9000 (patch) | |
tree | 3735b14eaa74d4a80d9197ac973b5dbffbd675d6 /src | |
parent | b91deae59c69ca41d5feffaf4f16b29ee47af64d (diff) |
fix some todo's
Diffstat (limited to 'src')
-rw-r--r-- | src/chunk-render.cpp | 18 | ||||
-rw-r--r-- | src/chunk.cpp | 5 | ||||
-rw-r--r-- | src/chunk.hpp | 7 | ||||
-rw-r--r-- | src/object.cpp | 3 | ||||
-rw-r--r-- | src/tile.cpp | 12 |
5 files changed, 21 insertions, 24 deletions
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp index 586018b1..d019a948 100644 --- a/src/chunk-render.cpp +++ b/src/chunk-render.cpp @@ -36,17 +36,17 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple return { ground_mesh, {}, 0 }; if (!_ground_modified) - return { ground_mesh, _ground->ground_indexes, size_t(ground_mesh.count()/6) }; + return { ground_mesh, _ground->indexes, size_t(ground_mesh.count()/6) }; _ground_modified = false; size_t count = 0; for (auto i = 0uz; i < TILE_COUNT; i++) - if (_ground->_ground_atlases[i]) - _ground->ground_indexes[count++] = uint8_t(i); + if (_ground->atlases[i]) + _ground->indexes[count++] = uint8_t(i); - std::sort(_ground->ground_indexes.begin(), _ground->ground_indexes.begin() + count, + std::sort(_ground->indexes.begin(), _ground->indexes.begin() + count, [this](uint8_t a, uint8_t b) { - return _ground->_ground_atlases[a] < _ground->_ground_atlases[b]; + return _ground->atlases[a] < _ground->atlases[b]; }); float hack_offset = _coord.z <= 0 ? -16 : 0; // XXX hack @@ -54,11 +54,11 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple std::array<std::array<vertex, 4>, TILE_COUNT> vertexes; for (auto k = 0uz; k < count; k++) { - const uint8_t i = _ground->ground_indexes[k]; - const auto& atlas = _ground->_ground_atlases[i]; + const uint8_t i = _ground->indexes[k]; + const auto& atlas = _ground->atlases[i]; const local_coords pos{i}; const auto quad = floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2); - const auto texcoords = atlas->texcoords_for_id(_ground->_ground_variants[i]); + const auto texcoords = atlas->texcoords_for_id(_ground->variants[i]); const float depth = tile_shader::depth_value(pos, tile_shader::ground_depth_offset + hack_offset); auto& v = vertexes[k]; for (auto j = 0uz; j < 4; j++) @@ -74,7 +74,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple .setIndexBuffer(GL::Buffer{vert_index_view}, 0, GL::MeshIndexType::UnsignedShort) .setCount(int32_t(6 * count)); ground_mesh = Utility::move(mesh); - return { ground_mesh, _ground->ground_indexes, count }; + return { ground_mesh, _ground->indexes, count }; } diff --git a/src/chunk.cpp b/src/chunk.cpp index aabb69f8..a49669c5 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -28,7 +28,7 @@ bool chunk::empty(bool force) const noexcept return false; for (auto i = 0uz; i < TILE_COUNT; i++) if (!_objects.empty() || - _ground && _ground->_ground_atlases[i] || + _ground && _ground->atlases[i] || _walls && (_walls->atlases[i*2+0] || _walls->atlases[i*2+1])) return _maybe_empty = false; if (!_objects.empty()) @@ -36,7 +36,7 @@ bool chunk::empty(bool force) const noexcept return true; } -tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground ? _ground->_ground_atlases[i].get() : nullptr; } +tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground ? _ground->atlases[i].get() : nullptr; } tile_ref chunk::operator[](size_t idx) noexcept { return { *this, uint8_t(idx) }; } tile_proto chunk::operator[](size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast<chunk*>(this), uint8_t(idx) }); } @@ -86,7 +86,6 @@ void chunk::mark_ground_modified() noexcept mark_passability_modified(); } -// todo this can use _replace_bbox too void chunk::mark_walls_modified() noexcept { if (!_walls_modified && !is_log_quiet()) diff --git a/src/chunk.hpp b/src/chunk.hpp index f2434281..3005475c 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -129,10 +129,9 @@ struct chunk final private: struct ground_stuff { - // todo remove "_ground" prefix - std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> _ground_atlases; - std::array<uint8_t, TILE_COUNT> ground_indexes = {}; - std::array<variant_t, TILE_COUNT> _ground_variants = {}; + std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> atlases; + std::array<uint8_t, TILE_COUNT> indexes = {}; + std::array<variant_t, TILE_COUNT> variants = {}; }; struct wall_stuff diff --git a/src/object.cpp b/src/object.cpp index 71ce905c..9d5aec5a 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -21,7 +21,7 @@ constexpr auto object_id_lessp = [](const auto& a, const auto& b) { return a->id #pragma GCC diagnostic ignored "-Wignored-qualifiers" #endif -// todo try this instead: x = 31; int((x+64+32)/64), (x + 64 + 32)%64 - 1 +// todo rewrite using bitwise ops. try this instead: x = 31; int((x+64+32)/64), (x + 64 + 32)%64 - 1 template<int tile_size> constexpr inline Pair<int, int8_t> normalize_coord(const int8_t cur, const int new_off) { @@ -141,7 +141,6 @@ void object::rotate(size_t, rotation new_r) const_cast<rotation&>(r) = new_r; } -// todo rewrite using bitwise ops point object::normalize_coords(global_coords coord, Vector2b cur, Vector2i new_off) { auto [cx, ox] = normalize_coord<iTILE_SIZE2.x()>(cur.x(), new_off.x()); diff --git a/src/tile.cpp b/src/tile.cpp index 4f49f214..ce21d506 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -18,22 +18,22 @@ wall_image_proto tile_proto::wall_west() const noexcept { return { wall_west_at tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {} -std::shared_ptr<tile_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->_ground_atlases[i] : nullptr; } +std::shared_ptr<tile_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } std::shared_ptr<wall_atlas> tile_ref::wall_north_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } std::shared_ptr<wall_atlas> tile_ref::wall_west_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; } -std::shared_ptr<const tile_atlas> tile_ref::ground_atlas() const noexcept { return _chunk->_ground ? _chunk->_ground->_ground_atlases[i] : nullptr; } +std::shared_ptr<const tile_atlas> tile_ref::ground_atlas() const noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } std::shared_ptr<const wall_atlas> tile_ref::wall_north_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } std::shared_ptr<const wall_atlas> tile_ref::wall_west_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; } -tile_image_ref tile_ref::ground() noexcept { _chunk->ensure_alloc_ground(); return {_chunk->_ground->_ground_atlases[i], _chunk->_ground->_ground_variants[i] }; } +tile_image_ref tile_ref::ground() noexcept { _chunk->ensure_alloc_ground(); return {_chunk->_ground->atlases[i], _chunk->_ground->variants[i] }; } wall_image_ref tile_ref::wall_north() noexcept { _chunk->ensure_alloc_walls(); return {_chunk->_walls->atlases[i*2+0], _chunk->_walls->variants[i*2+0] }; } wall_image_ref tile_ref::wall_west() noexcept { _chunk->ensure_alloc_walls(); return {_chunk->_walls->atlases[i*2+1], _chunk->_walls->variants[i*2+1] }; } tile_image_proto tile_ref::ground() const noexcept { _chunk->ensure_alloc_ground(); - return { _chunk->_ground->_ground_atlases[i], _chunk->_ground->_ground_variants[i] }; + return { _chunk->_ground->atlases[i], _chunk->_ground->variants[i] }; } wall_image_proto tile_ref::wall_north() const noexcept @@ -57,8 +57,8 @@ tile_ref::operator tile_proto() const noexcept _chunk->ensure_alloc_ground(); _chunk->ensure_alloc_walls(); return { - _chunk->_ground->_ground_atlases[i], _chunk->_walls->atlases[i*2+0], _chunk->_walls->atlases[i*2+1], - _chunk->_ground->_ground_variants[i], _chunk->_walls->variants[i*2+0], _chunk->_walls->variants[i*2+1], + _chunk->_ground->atlases[i], _chunk->_walls->atlases[i*2+0], _chunk->_walls->atlases[i*2+1], + _chunk->_ground->variants[i], _chunk->_walls->variants[i*2+0], _chunk->_walls->variants[i*2+1], }; } |