From 2e0c0009806860e4e8ac24663afdc5d926d1213f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 15 Mar 2023 14:52:54 +0100 Subject: src: add O(1) chunk access from entity --- serialize/world-reader.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'serialize') 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 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(); - 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()} : s.read(); @@ -195,12 +195,12 @@ void reader_state::read_chunks(reader_t& s) sc.delta = (std::uint16_t)Math::clamp(int(s.read() * 65535), 0, 65535); } } - - auto e = _world->make_entity({ coord, local_coords{i} }, sc); - chunk.add_entity_unsorted(e); + global_coords coord{ch, local_coords{i}}; + auto e = _world->make_entity(coord, sc); + c.add_entity_unsorted(e); } } - chunk.sort_entities(); + c.sort_entities(); } } -- cgit v1.2.3