From 99069aaf1205633da6b00bf7b482d60360e96b9f Mon Sep 17 00:00:00 2001 From: geneotech Date: Wed, 10 Apr 2024 00:46:41 +0200 Subject: [PATCH] Massive optimization: Prevent reprediction literally every step due to empty cosmic entropies having an empty local player entry which caused it to compare not equal to the actual server entropy - that one has no entries in the map. --- src/application/input/entropy_accumulator.h | 6 +++++- src/augs/misc/basic_input_intent.h | 6 +++++- src/augs/readwrite/json_readwrite.h | 16 +++++++++++++--- src/augs/readwrite/json_traits.h | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/application/input/entropy_accumulator.h b/src/application/input/entropy_accumulator.h index e9dfd5deb..8d7de995b 100644 --- a/src/application/input/entropy_accumulator.h +++ b/src/application/input/entropy_accumulator.h @@ -60,7 +60,7 @@ struct entropy_accumulator { if (handle) { const auto player_id = handle.get_id(); - auto& player_entry = out.cosmic[player_id]; + cosmic_entropy::player_entropy_type player_entry; player_entry.settings = in.settings.character; auto& player = player_entry.commands; @@ -87,6 +87,10 @@ struct entropy_accumulator { concatenate(player.intents, new_intents); player += cosmic; + + if (!player.empty()) { + out.cosmic.players.try_emplace(player_id, std::move(player_entry)); + } } out.clear_dead_entities(handle.get_cosmos()); diff --git a/src/augs/misc/basic_input_intent.h b/src/augs/misc/basic_input_intent.h index 45dea72c0..865102e7f 100644 --- a/src/augs/misc/basic_input_intent.h +++ b/src/augs/misc/basic_input_intent.h @@ -3,8 +3,12 @@ #include "augs/math/vec2.h" enum class intent_change { + // GEN INTROSPECTOR enum class intent_change RELEASED, - PRESSED + PRESSED, + + COUNT + // END GEN INTROSPECTOR }; template diff --git a/src/augs/readwrite/json_readwrite.h b/src/augs/readwrite/json_readwrite.h index 53d0f8cf0..2a28b6999 100644 --- a/src/augs/readwrite/json_readwrite.h +++ b/src/augs/readwrite/json_readwrite.h @@ -315,7 +315,7 @@ namespace augs { else if constexpr(std::is_same_v) { to.Double(from); } - else if constexpr(std::is_same_v) { + else if constexpr(std::is_same_v || std::is_same_v) { to.Int(from); } else if constexpr(std::is_same_v) { @@ -332,6 +332,16 @@ namespace augs { } } + template + decltype(auto) json_stringize(const T& val) { + if constexpr(std::is_enum_v) { + return enum_to_string(val); + } + else { + return val; + } + } + template void write_json(F& to, const T& from) { if constexpr(representable_as_json_value_v) { @@ -346,7 +356,7 @@ namespace augs { to.StartObject(); for (const auto& it : from) { - to.Key(it.first); + to.Key(json_stringize(it.first)); write_json(to, it.second); } @@ -443,7 +453,7 @@ namespace augs { const auto defaults = typename Container::mapped_type(); for (const auto& it : from) { - to.Key(it.first); + to.Key(json_stringize(it.first)); write_json_diff(to, it.second, defaults, true); } diff --git a/src/augs/readwrite/json_traits.h b/src/augs/readwrite/json_traits.h index bc3acec32..10ad128b4 100644 --- a/src/augs/readwrite/json_traits.h +++ b/src/augs/readwrite/json_traits.h @@ -44,7 +44,7 @@ namespace augs { template struct key_representable_as_string - : std::bool_constant> { + : std::bool_constant || std::is_same_v> { }; template