diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 14:52:54 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 15:09:09 +0100 |
commit | 2e0c0009806860e4e8ac24663afdc5d926d1213f (patch) | |
tree | 24a88dfa818e52179b0955a463da4b9cfa834b4d /serialize | |
parent | c6c3c887e99c57fb567252053190ce4a24f65455 (diff) |
src: add O(1) chunk access from entity
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/world-reader.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 83a77ffb..07dc1bbf 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -125,15 +125,15 @@ void reader_state::read_chunks(reader_t& s) std::decay_t<decltype(chunk_magic)> magic; magic << s; if (magic != chunk_magic) - fm_throw("bad chunk magic"_cf); - chunk_coords coord; - coord.x << s; - coord.y << s; - auto& chunk = (*_world)[coord]; + fm_throw("bad c magic"_cf); + chunk_coords ch; + ch.x << s; + ch.y << s; + auto& c = (*_world)[ch]; for (auto i = 0_uz; i < TILE_COUNT; i++) { const tilemeta flags = s.read<tilemeta>(); - tile_ref t = chunk[i]; + tile_ref t = c[i]; using uchar = std::uint8_t; const auto make_atlas = [&]() -> tile_image_proto { auto id = flags & meta_short_atlasid ? atlasid{s.read<uchar>()} : s.read<atlasid>(); @@ -195,12 +195,12 @@ void reader_state::read_chunks(reader_t& s) sc.delta = (std::uint16_t)Math::clamp(int(s.read<float>() * 65535), 0, 65535); } } - - auto e = _world->make_entity<scenery>({ coord, local_coords{i} }, sc); - chunk.add_entity_unsorted(e); + global_coords coord{ch, local_coords{i}}; + auto e = _world->make_entity<scenery>(coord, sc); + c.add_entity_unsorted(e); } } - chunk.sort_entities(); + c.sort_entities(); } } |