- gameinput.h: Add initial structure for PlayerPosition as companion to PlayerAngle and PlayerHorizon structs.

This commit is contained in:
Mitch Richters 2021-10-30 20:20:10 +11:00 committed by Christoph Oelckers
parent 7ee4f49649
commit 15c4d38694
2 changed files with 50 additions and 0 deletions

View file

@ -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;
}

View file

@ -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);