Skip to content

Commit

Permalink
Massive optimization: Prevent reprediction literally every step due to
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geneotech committed Apr 9, 2024
1 parent 2113244 commit 99069aa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/application/input/entropy_accumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion src/augs/misc/basic_input_intent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class K>
Expand Down
16 changes: 13 additions & 3 deletions src/augs/readwrite/json_readwrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ namespace augs {
else if constexpr(std::is_same_v<T, double>) {
to.Double(from);
}
else if constexpr(std::is_same_v<T, int>) {
else if constexpr(std::is_same_v<T, int> || std::is_same_v<T, short>) {
to.Int(from);
}
else if constexpr(std::is_same_v<T, uint64_t>) {
Expand All @@ -332,6 +332,16 @@ namespace augs {
}
}

template <class T>
decltype(auto) json_stringize(const T& val) {
if constexpr(std::is_enum_v<T>) {
return enum_to_string(val);
}
else {
return val;
}
}

template <class F, class T>
void write_json(F& to, const T& from) {
if constexpr(representable_as_json_value_v<T>) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/augs/readwrite/json_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace augs {

template <class T>
struct key_representable_as_string<T, decltype(typename T::key_type(), void())>
: std::bool_constant<std::is_same_v<std::string, typename T::key_type>> {
: std::bool_constant<std::is_enum_v<typename T::key_type> || std::is_same_v<std::string, typename T::key_type>> {
};

template <class T>
Expand Down

0 comments on commit 99069aa

Please sign in to comment.