From 7ee4f4964926238423ab5e22f23343cfc3b26a11 Mon Sep 17 00:00:00 2001 From: Mitch Richters Date: Sat, 30 Oct 2021 20:07:52 +1100 Subject: [PATCH] - gameinput.h: Remove some of the verticality from the `PlayerHorizon` and `PlayerAngle` structs. --- source/core/gameinput.h | 192 ++++++++++------------------------------ 1 file changed, 48 insertions(+), 144 deletions(-) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index ccfe6d11e..6ab0abde0 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -15,63 +15,44 @@ struct PlayerHorizon friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def); + // Prototypes for functions in gameinput.cpp. + void applyinput(float const horz, ESyncBits* actions, double const scaleAdjust = 1); + void calcviewpitch(vec2_t const pos, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false); + + // Interpolation helpers. void backup() { ohoriz = horiz; ohorizoff = horizoff; } - void restore() { horiz = ohoriz; horizoff = ohorizoff; } - void addadjustment(double value) - { - __addadjustment(buildfhoriz(value)); - } + // Commonly used getters. + fixedhoriz osum() { return ohoriz + ohorizoff; } + fixedhoriz sum() { return horiz + horizoff; } + fixedhoriz interpolatedsum(double const smoothratio) { return q16horiz(interpolatedvalue(osum().asq16(), sum().asq16(), smoothratio)); } - void addadjustment(fixedhoriz value) - { - __addadjustment(value); - } + // Ticrate playsim adjustment helpers. + void addadjustment(double value) { __addadjustment(buildfhoriz(value)); } + void addadjustment(fixedhoriz value) { __addadjustment(value); } + void settarget(double value, bool backup = false) { __settarget(buildfhoriz(value), backup); } + void settarget(fixedhoriz value, bool backup = false) { __settarget(value, backup); } + void resetadjustment() { adjustment = 0; } + bool targetset() { return target.asq16(); } - void resetadjustment() - { - adjustment = 0; - } + // Input locking helpers. + void lockinput() { inputdisabled = true; } + void unlockinput() { inputdisabled = false; } + bool movementlocked() { return target.asq16() || inputdisabled; } - void settarget(double value, bool backup = false) - { - __settarget(buildfhoriz(value), backup); - } - - void settarget(fixedhoriz value, bool backup = false) - { - __settarget(value, backup); - } - - void lockinput() - { - inputdisabled = true; - } - - void unlockinput() - { - inputdisabled = false; - } - - bool targetset() - { - return target.asq16(); - } - - bool movementlocked() - { - return target.asq16() || inputdisabled; - } + // Draw code helpers. + double horizsumfrac(double const smoothratio) { return (!SyncInput() ? sum() : interpolatedsum(smoothratio)).asbuildf() * (1. / 16.); } + // Ticrate playsim adjustment processor. void processhelpers(double const scaleAdjust) { if (targetset()) @@ -94,29 +75,6 @@ struct PlayerHorizon } } - fixedhoriz osum() - { - return ohoriz + ohorizoff; - } - - fixedhoriz sum() - { - return horiz + horizoff; - } - - fixedhoriz interpolatedsum(double const smoothratio) - { - return q16horiz(interpolatedvalue(osum().asq16(), sum().asq16(), smoothratio)); - } - - double horizsumfrac(double const smoothratio) - { - return (!SyncInput() ? sum() : interpolatedsum(smoothratio)).asbuildf() * (1. / 16.); // Used within draw code for Duke. - } - - void applyinput(float const horz, ESyncBits* actions, double const scaleAdjust = 1); - void calcviewpitch(vec2_t const pos, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false); - private: fixedhoriz target; double adjustment; @@ -158,13 +116,16 @@ struct PlayerAngle friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def); + // Prototypes for functions in gameinput.cpp. + void applyinput(float const avel, ESyncBits* actions, double const scaleAdjust = 1); + + // Interpolation helpers. void backup() { oang = ang; olook_ang = look_ang; orotscrnang = rotscrnang; } - void restore() { ang = oang; @@ -172,51 +133,31 @@ struct PlayerAngle rotscrnang = orotscrnang; } - void addadjustment(double value) - { - __addadjustment(buildfang(value)); - } + // Commonly used getters. + binangle osum() { return oang + olook_ang; } + binangle sum() { return ang + look_ang; } + binangle interpolatedsum(double const smoothratio) { return interpolatedangle(osum(), sum(), smoothratio); } + binangle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); } + binangle interpolatedrotscrn(double const smoothratio) { return interpolatedangle(orotscrnang, rotscrnang, smoothratio); } - void addadjustment(binangle value) - { - __addadjustment(value); - } + // Ticrate playsim adjustment helpers. + void addadjustment(double value) { __addadjustment(buildfang(value)); } + void addadjustment(binangle value) { __addadjustment(value); } + void settarget(double value, bool backup = false) { __settarget(buildfang(value), backup); } + void settarget(binangle value, bool backup = false) { __settarget(value, backup); } + void resetadjustment() { adjustment = 0; } + bool targetset() { return target.asbam(); } - void resetadjustment() - { - adjustment = 0; - } + // Input locking helpers. + void lockinput() { inputdisabled = true; } + void unlockinput() { inputdisabled = false; } + bool movementlocked() { return target.asq16() || inputdisabled; } - void settarget(double value, bool backup = false) - { - __settarget(buildfang(value), backup); - } - - void settarget(binangle value, bool backup = false) - { - __settarget(value, backup); - } - - void lockinput() - { - inputdisabled = true; - } - - void unlockinput() - { - inputdisabled = false; - } - - bool targetset() - { - return target.asbam(); - } - - bool movementlocked() - { - return target.asq16() || inputdisabled; - } + // Draw code helpers. + double look_anghalf(double const smoothratio) { return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; } + double looking_arc(double const smoothratio) { return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); } + // Ticrate playsim adjustment processor. void processhelpers(double const scaleAdjust) { if (targetset()) @@ -239,43 +180,6 @@ struct PlayerAngle } } - binangle osum() - { - return oang + olook_ang; - } - - binangle sum() - { - return ang + look_ang; - } - - binangle interpolatedsum(double const smoothratio) - { - return interpolatedangle(osum(), sum(), smoothratio); - } - - binangle interpolatedlookang(double const smoothratio) - { - return interpolatedangle(olook_ang, look_ang, smoothratio); - } - - binangle interpolatedrotscrn(double const smoothratio) - { - return interpolatedangle(orotscrnang, rotscrnang, smoothratio); - } - - double look_anghalf(double const smoothratio) - { - return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; // Used within draw code for weapon and crosshair when looking left/right. - } - - double looking_arc(double const smoothratio) - { - return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); // Used within draw code for weapon and crosshair when looking left/right. - } - - void applyinput(float const avel, ESyncBits* actions, double const scaleAdjust = 1); - private: binangle target; double adjustment;