From 1439d1b591b696aa82fa44bc5123edd0813f8ac3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 9 Apr 2024 15:00:15 +0200 Subject: w --- serialize/savegame.cpp | 72 ++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 46 deletions(-) (limited to 'serialize') diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp index 97fb61d4..df541634 100644 --- a/serialize/savegame.cpp +++ b/serialize/savegame.cpp @@ -151,26 +151,24 @@ struct visitor_ Derived& self = static_cast(*this); template - requires std::is_arithmetic_v> - static void visit(T&& x, F&& f) + requires (!IsWriter) + static CORRADE_ALWAYS_INLINE void visit(T& x, F&& f) { f(forward(x)); } - template - void visit(T&& x, F&& f) + template void visit(T&& x, F&& f) { constexpr auto N = std::remove_cvref_t::Size; for (uint32_t i = 0; i < N; i++) - f(forward(x).data()[i]); + visit(forward(x).data()[i], f); } - template - void visit(E&& x, F&& f) - { - using U = std::underlying_type_t>; - f(non_const_(U(x))); - } + template requires (!IsWriter) CORRADE_ALWAYS_INLINE void visit(E& x, F&& f) + { using U = std::underlying_type_t>; auto xʹ = U(x); f(xʹ); } + + template requires (IsWriter) CORRADE_ALWAYS_INLINE void visit(E x, F&& f) + { using U = std::underlying_type_t; f(static_cast(x)); } template void visit_object_header(o_object& obj, const object_header_s& s, F&& f) @@ -216,15 +214,14 @@ struct visitor_ // immediately after this function's return, read sc_type and then read scenery_proto } - template - void visit(tile_ref c, F&& f) + template static inline void visit(tile_ref c, F&& f) { do_visit(c.ground(), f); do_visit(c.wall_north(), f); do_visit(c.wall_west(), f); } - template static void visit(qual& coord, F&& f) + template static inline void visit(qual& coord, F&& f) { f(coord.x); f(coord.y); @@ -241,8 +238,7 @@ struct visitor_ flag_interactive = 1 << 2, }; - template - void visit_scenery_proto(o_sc_g& s, F&& f) + template void visit_scenery_proto(o_sc_g& s, F&& f) { using T = std::conditional_t; // todo! make bitmask reader/writer @@ -278,8 +274,7 @@ struct visitor_ } } - template - void visit_scenery_proto(o_sc_door& s, F&& f) + template void visit_scenery_proto(o_sc_door& s, F&& f) { using T = std::conditional_t; constexpr struct { @@ -317,8 +312,7 @@ struct visitor_ } } - template - void visit_object_proto(o_critter& obj, critter_header_s&& s, F&& f) + template void visit_object_proto(o_critter& obj, critter_header_s&& s, F&& f) { self.visit(obj.name, f); @@ -380,9 +374,7 @@ struct writer final : visitor_ buffer header_buf{}, string_buf{}; - explicit writer(const world& w) : - w{ w } - {} + explicit writer(const world& w) : w{ w } {} struct size_counter { @@ -405,8 +397,7 @@ struct writer final : visitor_ } }; - template - void visit(qual>& a, atlas_type type, F&& f) + template void visit(qual>& a, atlas_type type, F&& f) { atlasid id = intern_atlas(a, type); visit(id, f); @@ -422,8 +413,7 @@ struct writer final : visitor_ f(intern_string(name)); } - template - void write_scenery_proto(const scenery& obj, F&& f) // todo! replace scenery::subtype with inheritance! + template void write_scenery_proto(const scenery& obj, F&& f) // todo! replace scenery::subtype with inheritance! { auto sc_type = obj.scenery_type(); visit(sc_type, f); @@ -433,8 +423,7 @@ struct writer final : visitor_ ); } - template - void write_object(o_object& obj, chunk* c, F&& f) + template void write_object(o_object& obj, chunk* c, F&& f) { auto id = obj.id; auto type = obj.type(); @@ -471,8 +460,7 @@ struct writer final : visitor_ ok: void(); } - template - void intern_atlas_(const void* atlas, atlas_type type, F&& f) + template void intern_atlas_(const void* atlas, atlas_type type, F&& f) { visit(type, f); @@ -542,8 +530,7 @@ ok: void(); return pair->second; } - template - void serialize_objects_(chunk& c, F&& f) + template void serialize_objects_(chunk& c, F&& f) { uint32_t count = 0; for (const std::shared_ptr& obj : c.objects()) @@ -813,8 +800,7 @@ struct reader final : visitor_ } }; - template - void visit(String& str, F&& f) + template void visit(String& str, F&& f) { atlasid id; f(id); @@ -828,8 +814,7 @@ struct reader final : visitor_ pt = local_coords{i}; } - template - void visit(std::shared_ptr& a, atlas_type type, F&& f) + template void visit(std::shared_ptr& a, atlas_type type, F&& f) { atlasid id = (atlasid)-1; f(id); @@ -849,8 +834,7 @@ struct reader final : visitor_ } } - template - void visit_object_proto(o_scenery& obj, std::nullptr_t, F&& f) + template void visit_object_proto(o_scenery& obj, std::nullptr_t, F&& f) { auto sc_type = scenery_type::none; visit(sc_type, f); @@ -889,9 +873,7 @@ struct reader final : visitor_ return w.make_object(h0.id, coord, move(p)); } - template - [[nodiscard]] - std::shared_ptr read_object(chunk* ch, F&& f) + template [[nodiscard]] std::shared_ptr read_object(chunk* ch, F&& f) { std::shared_ptr obj; object_id id = 0; @@ -977,8 +959,7 @@ ok: return strings[id]; } - template - StringView get_atlas(atlasid id) + template StringView get_atlas(atlasid id) { fm_soft_assert(id < atlases.size()); auto a = atlases[id]; @@ -1028,8 +1009,7 @@ ok: } } - template - void deserialize_tile_part(auto&& g, uint32_t& i, byte_reader& r) + template void deserialize_tile_part(auto&& g, uint32_t& i, byte_reader& r) { constexpr auto highbit = reader::highbit; constexpr auto null = reader::null; -- cgit v1.2.3