From 15c4d38694711c8fc2eb2dfeb7a6b45f7158dbab Mon Sep 17 00:00:00 2001 From: Mitch Richters Date: Sat, 30 Oct 2021 20:20:10 +1100 Subject: [PATCH] - gameinput.h: Add initial structure for `PlayerPosition` as companion to `PlayerAngle` and `PlayerHorizon` structs. --- source/core/gameinput.cpp | 14 ++++++++++++++ source/core/gameinput.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 1cefe3b97..65524935b 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -484,3 +484,17 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, } return arc; } + +FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerPosition& w, PlayerPosition* def) +{ + if (arc.BeginObject(keyname)) + { + arc("pos", w.pos).EndObject(); + + if (arc.isReading()) + { + w.opos = w.pos; + } + } + return arc; +} diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 6ab0abde0..8f7b9ad58 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -212,9 +212,45 @@ private: } }; +struct PlayerPosition +{ + vec3_t pos, opos; + + // Interpolation helpers. + void backupx() { opos.x = pos.x; } + void backupy() { opos.y = pos.y; } + void backupz() { opos.z = pos.z; } + void backuppos() { opos = pos; } + + // Interpolated points. + int32_t interpolatedx(double const smoothratio, int const scale = 16) { return interpolatedvalue(opos.x, pos.x, smoothratio, scale); } + int32_t interpolatedy(double const smoothratio, int const scale = 16) { return interpolatedvalue(opos.y, pos.y, smoothratio, scale); } + int32_t interpolatedz(double const smoothratio, int const scale = 16) { return interpolatedvalue(opos.z, pos.z, smoothratio, scale); } + + // Interpolated vectors. + vec2_t interpolatedvec2(double const smoothratio, int const scale = 16) + { + return + { + interpolatedx(smoothratio, scale), + interpolatedy(smoothratio, scale) + }; + } + vec3_t interpolatedvec3(double const smoothratio, int const scale = 16) + { + return + { + interpolatedx(smoothratio, scale), + interpolatedy(smoothratio, scale), + interpolatedz(smoothratio, scale) + }; + } +}; + class FSerializer; FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def); FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def); +FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerPosition& w, PlayerPosition* def); void updateTurnHeldAmt(double const scaleAdjust);