diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-01 22:27:30 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-01 22:27:30 +0200 |
| commit | 31fd5bbc08234686cf798a93a18e0bb73615d1bf (patch) | |
| tree | 59b964d01885916c5d49fef3c168ff10dcbdd93f /serialize | |
| parent | 053ea3aa1c443c368f8b43591e3e970e12b50c70 (diff) | |
rename entity -> object
Diffstat (limited to 'serialize')
| -rw-r--r-- | serialize/scenery.cpp | 4 | ||||
| -rw-r--r-- | serialize/world-impl.hpp | 14 | ||||
| -rw-r--r-- | serialize/world-reader.cpp | 62 | ||||
| -rw-r--r-- | serialize/world-writer.cpp | 58 |
4 files changed, 69 insertions, 69 deletions
diff --git a/serialize/scenery.cpp b/serialize/scenery.cpp index 6bcd5fa9..33f81285 100644 --- a/serialize/scenery.cpp +++ b/serialize/scenery.cpp @@ -137,7 +137,7 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& f) default: fm_throw("unhandled scenery type '{}'"_cf, (unsigned)type); case scenery_type::generic: - f.type = entity_type::scenery; + f.type = object_type::scenery; f.sc_type = scenery_type::generic; f.r = r; f.frame = frame; @@ -150,7 +150,7 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& f) break; case scenery_type::door: fm_assert(f.atlas->info().fps > 0 && f.atlas->info().nframes > 0); - f.type = entity_type::scenery; + f.type = object_type::scenery; f.sc_type = scenery_type::door; f.r = r; f.frame = uint16_t(f.atlas->group(r).frames.size()-1); diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index d56c432c..b01e81ba 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -6,7 +6,7 @@ #include "src/tile.hpp" #include "src/pass-mode.hpp" #include "src/rotation.hpp" -#include "src/entity-type.hpp" +#include "src/object-type.hpp" #include <bit> #include <cstdio> #include <limits> @@ -24,16 +24,16 @@ * 9) Interned strings. * 10) Chunk Z level. * 11) RLE empty tiles. - * 12) Don't write entity name twice. + * 12) Don't write object name twice. * 13) Entity counter initialized to 1024. - * 14) Always store entity offset, rework how sc_exact works. + * 14) Always store object offset, rework how sc_exact works. * 15) Add light alpha. * 16) One more bit for light falloff enum. */ namespace floormat { -struct entity; -struct entity_proto; +struct object; +struct object_proto; } // namespace floormat namespace floormat::Serialize { @@ -63,7 +63,7 @@ constexpr inline auto scenery_magic = (uint16_t)~0xb00b; using pass_mode_i = std::underlying_type_t<pass_mode>; constexpr inline pass_mode_i pass_mask = (1 << pass_mode_BITS)-1; -using entity_type_i = std::underlying_type_t<entity_type>; +using object_type_i = std::underlying_type_t<object_type>; template<typename T, size_t N, size_t off> constexpr inline auto highbits = (T(1) << N)-1 << sizeof(T)*8-N-off; @@ -78,7 +78,7 @@ constexpr inline atlasid scenery_id_max = int_max<atlasid> & ~scenery_id_flag_ma } // namespace -template<typename T> concept entity_subtype = std::is_base_of_v<entity, T> || std::is_base_of_v<entity_proto, T>; +template<typename T> concept object_subtype = std::is_base_of_v<object, T> || std::is_base_of_v<object_proto, T>; enum : tilemeta { meta_ground = 1 << 2, diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index b9dc0027..769dda20 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -40,7 +40,7 @@ private: world* _world; uint16_t PROTO = proto_version; - Array<chunk::entity_draw_order> draw_array; + Array<chunk::object_draw_order> draw_array; Array<std::array<chunk::vertex, 4>> draw_vertexes; Array<std::array<UnsignedShort, 6>> draw_indexes; }; @@ -63,26 +63,26 @@ void reader_state::read_atlases(reader_t& s) } } -template<typename T, entity_subtype U> -bool read_entity_flags(binary_reader<T>& s, U& e) +template<typename T, object_subtype U> +bool read_object_flags(binary_reader<T>& s, U& e) { - constexpr auto tag = entity_type_<U>::value; + constexpr auto tag = object_type_<U>::value; uint8_t flags; flags << s; e.pass = pass_mode(flags & pass_mask); if (e.type != tag) - fm_throw("invalid entity type '{}'"_cf, (int)e.type); - if constexpr(tag == entity_type::scenery) + fm_throw("invalid object type '{}'"_cf, (int)e.type); + if constexpr(tag == object_type::scenery) { e.active = !!(flags & 1 << 2); e.closing = !!(flags & 1 << 3); e.interactive = !!(flags & 1 << 4); } - else if constexpr(tag == entity_type::character) + else if constexpr(tag == object_type::character) { e.playable = !!(flags & 1 << 2); } else - static_assert(tag == entity_type::none); + static_assert(tag == object_type::none); return flags & 1 << 7; } @@ -109,7 +109,7 @@ void reader_state::read_sceneries(reader_t& s) atlasid id; id << s; fm_soft_assert(id < sz); fm_soft_assert(!sceneries[id]); - bool short_frame = read_entity_flags(s, sc); + bool short_frame = read_object_flags(s, sc); fm_debug_assert(sc.atlas != nullptr); if (short_frame) sc.frame = s.read<uint8_t>(); @@ -164,7 +164,7 @@ StringView reader_state::lookup_string(uint32_t idx) void reader_state::read_chunks(reader_t& s) { - Array<typename chunk::entity_draw_order> array; + Array<typename chunk::object_draw_order> array; const auto N = s.read<chunksiz>(); #ifndef FM_NO_DEBUG [[maybe_unused]] size_t nbytes_read = 0; @@ -230,18 +230,18 @@ void reader_state::read_chunks(reader_t& s) read_old_scenery(s, ch, i); SET_CHUNK_SIZE(); } - uint32_t entity_count = 0; + uint32_t object_count = 0; if (PROTO >= 8) [[likely]] - entity_count << s; + object_count << s; SET_CHUNK_SIZE(); - for (auto i = 0uz; i < entity_count; i++) + for (auto i = 0uz; i < object_count; i++) { object_id _id; _id << s; const auto oid = _id & lowbits<60, object_id>; fm_soft_assert(oid != 0); - const auto type = entity_type(_id >> 61); + const auto type = object_type(_id >> 61); const auto local = local_coords{s.read<uint8_t>()}; Vector2b offset; @@ -259,12 +259,12 @@ void reader_state::read_chunks(reader_t& s) SET_CHUNK_SIZE(); switch (type) { - case entity_type::character: { + case object_type::character: { character_proto proto; proto.offset = offset; uint8_t id; id << s; proto.r = rotation(id >> sizeof(id)*8-1-rotation_BITS & rotation_MASK); - if (read_entity_flags(s, proto)) + if (read_object_flags(s, proto)) proto.frame = s.read<uint8_t>(); else proto.frame << s; @@ -297,12 +297,12 @@ void reader_state::read_chunks(reader_t& s) read_bbox(s, proto); } SET_CHUNK_SIZE(); - auto e = _world->make_entity<character, false>(oid, {ch, local}, proto); + auto e = _world->make_object<character, false>(oid, {ch, local}, proto); e->offset_frac = offset_frac; (void)e; break; } - case entity_type::scenery: { + case object_type::scenery: { atlasid id; id << s; const bool exact = id & meta_short_scenery_bit; const auto r = rotation(id >> sizeof(id)*8-1-rotation_BITS & rotation_MASK); @@ -313,7 +313,7 @@ void reader_state::read_chunks(reader_t& s) sc.r = r; if (!exact) { - if (read_entity_flags(s, sc)) + if (read_object_flags(s, sc)) sc.frame = s.read<uint8_t>(); else sc.frame << s; @@ -327,11 +327,11 @@ void reader_state::read_chunks(reader_t& s) if (sc.active) sc.delta << s; } - auto e = _world->make_entity<scenery, false>(oid, {ch, local}, sc); + auto e = _world->make_object<scenery, false>(oid, {ch, local}, sc); (void)e; break; } - case entity_type::light: { + case object_type::light: { light_proto proto; proto.offset = offset; @@ -364,20 +364,20 @@ void reader_state::read_chunks(reader_t& s) read_bbox(s, proto); } SET_CHUNK_SIZE(); - auto L = _world->make_entity<light, false>(oid, {ch, local}, proto); + auto L = _world->make_object<light, false>(oid, {ch, local}, proto); L->enabled = enabled; (void)L; break; } default: - fm_throw("invalid_entity_type '{}'"_cf, (int)type); + fm_throw("invalid_object_type '{}'"_cf, (int)type); } } SET_CHUNK_SIZE(); fm_assert(c.is_scenery_modified()); fm_assert(c.is_passability_modified()); - c.sort_entities(); + c.sort_objects(); c.ensure_ground_mesh(); c.ensure_wall_mesh(); c.ensure_scenery_mesh({ draw_array, draw_vertexes, draw_indexes }); @@ -396,7 +396,7 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords_ ch, size_t i) sc.r = r; if (!exact) { - if (read_entity_flags(s, sc)) + if (read_object_flags(s, sc)) sc.frame = s.read<uint8_t>(); else sc.frame << s; @@ -424,7 +424,7 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords_ ch, size_t i) } } global_coords coord{ch, local_coords{i}}; - auto e = _world->make_entity<scenery, false>(_world->make_id(), coord, sc); + auto e = _world->make_object<scenery, false>(_world->make_id(), coord, sc); (void)e; } @@ -441,22 +441,22 @@ void reader_state::deserialize_world(ArrayView<const char> buf) (size_t)proto, (size_t)min_proto_version, (size_t)proto_version); PROTO = proto; fm_assert(PROTO > 0); - object_id entity_counter = world::entity_counter_init; + object_id object_counter = world::object_counter_init; read_atlases(s); if (PROTO >= 3) [[likely]] read_sceneries(s); if (PROTO >= 9) [[likely]] read_strings(s); if (PROTO >= 8) [[likely]] - entity_counter << s; + object_counter << s; read_chunks(s); s.assert_end(); if (PROTO >= 8) [[likely]] - fm_assert(_world->entity_counter() == world::entity_counter_init); + fm_assert(_world->object_counter() == world::object_counter_init); if (PROTO >= 13) [[likely]] - _world->set_entity_counter(entity_counter); + _world->set_object_counter(object_counter); else if (PROTO >= 8) [[likely]] - _world->set_entity_counter(std::max(world::entity_counter_init, entity_counter)); + _world->set_object_counter(std::max(world::object_counter_init, object_counter)); _world = nullptr; } diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index b07de09a..6d32762f 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -77,7 +77,7 @@ private: constexpr auto tile_size = sizeof(tilemeta) + (sizeof(atlasid) + sizeof(variant_t)) * 3; constexpr auto chunkbuf_size = sizeof(chunk_magic) + sizeof(chunk_coords_) + tile_size * TILE_COUNT + sizeof(uint32_t); -constexpr auto entity_size = std::max({ sizeof(character), sizeof(scenery), sizeof(light), }); +constexpr auto object_size = std::max({ sizeof(character), sizeof(scenery), sizeof(light), }); writer_state::writer_state(const world& world) : _world{&world} { @@ -178,28 +178,28 @@ scenery_pair writer_state::intern_scenery(const scenery& sc, bool create) return {}; } -template<typename T, entity_subtype U> -void write_entity_flags(binary_writer<T>& s, const U& e) +template<typename T, object_subtype U> +void write_object_flags(binary_writer<T>& s, const U& e) { uint8_t flags = 0; auto pass = (pass_mode_i)e.pass; fm_assert((pass & pass_mask) == pass); flags |= pass; - constexpr auto tag = entity_type_<U>::value; + constexpr auto tag = object_type_<U>::value; if (e.type_of() != tag) - fm_abort("invalid entity type '%d'", (int)e.type_of()); - if constexpr(tag == entity_type::scenery) + fm_abort("invalid object type '%d'", (int)e.type_of()); + if constexpr(tag == object_type::scenery) { flags |= (1 << 2) * e.active; flags |= (1 << 3) * e.closing; flags |= (1 << 4) * e.interactive; } - else if constexpr(tag == entity_type::character) + else if constexpr(tag == object_type::character) { flags |= (1 << 2) * e.playable; } else - static_assert(tag == entity_type::none); + static_assert(tag == object_type::none); flags |= (1 << 7) * (e.frame <= 0xff); s << flags; } @@ -287,7 +287,7 @@ void writer_state::serialize_scenery_names() s.write_asciiz_string(sc->name); } s << idx; - write_entity_flags(s, sc->proto); + write_object_flags(s, sc->proto); if (sc->proto.frame <= 0xff) s << (uint8_t)sc->proto.frame; else @@ -322,19 +322,19 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) { constexpr auto def_char_bbox_size = Vector2ub(iTILE_SIZE2); // copied from character_proto - const auto entity_count = (uint32_t)c.entities().size(); - s << entity_count; - fm_assert(entity_count == c.entities().size()); - for (const auto& e_ : c.entities()) + const auto object_count = (uint32_t)c.objects().size(); + s << object_count; + fm_assert(object_count == c.objects().size()); + for (const auto& e_ : c.objects()) { const auto& e = *e_; - fm_assert(s.bytes_written() + entity_size <= chunk_buf.size()); + fm_assert(s.bytes_written() + object_size <= chunk_buf.size()); object_id oid = e.id; fm_assert((oid & lowbits<60, object_id>) == e.id); const auto type = e.type(); - const auto type_ = (entity_type_i)type; - fm_assert(type_ == (type_ & lowbits<entity_type_BITS, entity_type_i>)); - oid |= (object_id)type << 64 - entity_type_BITS; + const auto type_ = (object_type_i)type; + fm_assert(type_ == (type_ & lowbits<object_type_BITS, object_type_i>)); + oid |= (object_id)type << 64 - object_type_BITS; s << oid; const auto local = e.coord.local(); s << local.to_index(); @@ -350,8 +350,8 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) switch (type) { default: - fm_abort("invalid entity type '%d'", (int)type); - case entity_type::character: { + fm_abort("invalid object type '%d'", (int)type); + case object_type::character: { const auto& C = static_cast<const character&>(e); uint8_t id = 0; const auto sc_exact = @@ -360,7 +360,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) id |= meta_short_scenery_bit * sc_exact; id |= static_cast<decltype(id)>(C.r) << sizeof(id)*8-1-rotation_BITS; s << id; - write_entity_flags(s, C); + write_object_flags(s, C); if (C.frame <= 0xff) s << (uint8_t)C.frame; else @@ -373,7 +373,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) write_bbox(s, C); break; } - case entity_type::scenery: { + case object_type::scenery: { const auto& sc = static_cast<const scenery&>(e); auto [ss, img_s, sc_exact] = intern_scenery(sc, true); sc_exact = sc_exact && @@ -391,7 +391,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) s << id; if (!sc_exact) { - write_entity_flags(s, sc); + write_object_flags(s, sc); fm_assert(sc.active || sc.delta == 0); if (sc.frame <= 0xff) s << (uint8_t)sc.frame; @@ -403,7 +403,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) } break; } - case entity_type::light: { + case object_type::light: { const auto& L = static_cast<const light&>(e); const auto exact = L.frame == 0 && L.pass == pass_mode::pass && L.bbox_offset.isZero() && L.bbox_size.isZero(); @@ -441,7 +441,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s) void writer_state::serialize_chunk(const chunk& c, chunk_coords_ coord) { fm_assert(chunk_buf.empty()); - const auto es_size = sizeof(uint32_t) + entity_size*c.entities().size(); + const auto es_size = sizeof(uint32_t) + object_size*c.objects().size(); chunk_buf.resize(std::max(chunk_buf.size(), chunkbuf_size + es_size)); auto s = binary_writer{chunk_buf.begin()}; @@ -534,16 +534,16 @@ ArrayView<const char> writer_state::serialize_world() for (const auto& [_, c] : _world->chunks()) { - for (const auto& e_ : c.entities()) + for (const auto& e_ : c.objects()) { const auto& e = *e_; switch (e.type()) { - case entity_type::scenery: + case object_type::scenery: intern_scenery(static_cast<const scenery&>(e), false); break; - case entity_type::character: - case entity_type::light: + case object_type::character: + case object_type::light: break; default: fm_abort("invalid scenery type '%d'", (int)e.type()); @@ -597,7 +597,7 @@ ArrayView<const char> writer_state::serialize_world() copy(atlas_buf); copy(scenery_buf); copy(string_buf); - copy_int((object_id)_world->entity_counter()); + copy_int((object_id)_world->object_counter()); copy_int((chunksiz)_world->size()); for (const auto& buf : chunk_bufs) copy(buf); |
