2020-10-11 14:33:43 +00:00
# pragma once
# include "m_fixed.h"
# include "binaryangle.h"
# include "gamecvars.h"
2021-04-02 11:46:43 +00:00
# include "gamestruct.h"
2020-10-11 14:33:43 +00:00
# include "packet.h"
2020-11-22 10:45:16 +00:00
int getincangle ( int a , int na ) ;
2021-04-11 05:43:11 +00:00
binangle getincanglebam ( binangle a , binangle na ) ;
2020-10-11 14:33:43 +00:00
struct PlayerHorizon
{
fixedhoriz horiz , ohoriz , horizoff , ohorizoff ;
void backup ( )
{
ohoriz = horiz ;
ohorizoff = horizoff ;
}
void restore ( )
{
horiz = ohoriz ;
horizoff = ohorizoff ;
}
void addadjustment ( double value )
{
2021-04-11 05:43:11 +00:00
__addadjustment ( buildfhoriz ( value ) ) ;
2021-05-12 01:44:05 +00:00
}
2020-10-11 14:33:43 +00:00
2021-04-11 05:43:11 +00:00
void addadjustment ( fixedhoriz value )
2020-10-11 14:33:43 +00:00
{
2021-04-11 05:43:11 +00:00
__addadjustment ( value ) ;
2020-10-11 14:33:43 +00:00
}
2021-04-11 05:43:11 +00:00
void resetadjustment ( )
2021-03-31 08:44:50 +00:00
{
2021-04-11 05:43:11 +00:00
adjustment = 0 ;
2021-03-31 08:44:50 +00:00
}
2020-10-11 14:33:43 +00:00
void settarget ( double value , bool backup = false )
{
2021-04-21 10:41:04 +00:00
__settarget ( buildfhoriz ( value ) , backup ) ;
2021-03-31 08:44:50 +00:00
}
void settarget ( fixedhoriz value , bool backup = false )
2021-05-12 01:44:05 +00:00
{
2021-04-21 10:41:04 +00:00
__settarget ( value , backup ) ;
2021-05-12 01:44:05 +00:00
}
2021-04-02 11:46:43 +00:00
bool targetset ( )
2021-05-12 01:44:05 +00:00
{
2021-04-02 11:46:43 +00:00
return target . asq16 ( ) ;
2021-05-12 01:44:05 +00:00
}
2020-10-11 14:33:43 +00:00
void processhelpers ( double const scaleAdjust )
{
2021-04-02 11:46:43 +00:00
if ( targetset ( ) )
2020-10-11 14:33:43 +00:00
{
2021-04-11 05:43:11 +00:00
auto delta = ( target - horiz ) . asbuildf ( ) ;
2020-10-11 14:33:43 +00:00
2021-04-11 05:43:11 +00:00
if ( abs ( delta ) > 1 )
2020-10-11 14:33:43 +00:00
{
2021-04-11 05:43:11 +00:00
horiz + = buildfhoriz ( scaleAdjust * delta ) ;
2020-10-11 14:33:43 +00:00
}
2021-04-02 11:46:43 +00:00
else
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:44:50 +00:00
horiz = target ;
target = q16horiz ( 0 ) ;
2021-05-12 01:44:05 +00:00
}
2020-10-11 14:33:43 +00:00
}
else if ( adjustment )
{
2021-04-11 05:43:11 +00:00
horiz + = buildfhoriz ( scaleAdjust * adjustment ) ;
2020-10-11 14:33:43 +00:00
}
}
2020-10-18 11:43:42 +00:00
fixedhoriz osum ( )
{
return ohoriz + ohorizoff ;
}
2020-10-11 14:33:43 +00:00
fixedhoriz sum ( )
{
return horiz + horizoff ;
}
fixedhoriz interpolatedsum ( double const smoothratio )
{
2021-04-11 07:50:32 +00:00
return q16horiz ( interpolatedvalue ( osum ( ) . asq16 ( ) , sum ( ) . asq16 ( ) , smoothratio ) ) ;
2020-10-11 14:33:43 +00:00
}
2020-11-03 07:55:39 +00:00
2021-04-20 11:12:17 +00:00
double horizsumfrac ( double const smoothratio )
2021-04-15 03:35:42 +00:00
{
2021-04-20 11:12:17 +00:00
return ( ! SyncInput ( ) ? sum ( ) : interpolatedsum ( smoothratio ) ) . asbuildf ( ) * ( 1. / 16. ) ; // Used within draw code for Duke.
2021-04-15 03:35:42 +00:00
}
2020-11-03 07:55:39 +00:00
fixedhoriz interpolatedoff ( double const smoothratio )
{
double const ratio = smoothratio * ( 1. / FRACUNIT ) ;
return q16horiz ( ohorizoff . asq16 ( ) + xs_CRoundToInt ( ratio * ( horizoff - ohorizoff ) . asq16 ( ) ) ) ;
}
2021-04-05 12:12:44 +00:00
2021-04-21 10:41:04 +00:00
void applyinput ( float const horz , ESyncBits * actions , double const scaleAdjust = 1 ) ;
2021-04-19 10:50:01 +00:00
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 ) ;
2021-04-02 11:46:43 +00:00
private :
fixedhoriz target ;
double adjustment ;
void __addadjustment ( fixedhoriz value )
{
if ( ! SyncInput ( ) )
{
2021-04-11 05:43:11 +00:00
adjustment + = value . asbuildf ( ) ;
2021-04-02 11:46:43 +00:00
}
else
{
horiz + = value ;
}
}
2021-04-11 05:43:11 +00:00
void __settarget ( fixedhoriz value , bool backup )
2021-04-02 11:46:43 +00:00
{
2021-04-21 10:41:04 +00:00
value = q16horiz ( clamp ( value . asq16 ( ) , gi - > playerHorizMin ( ) , gi - > playerHorizMax ( ) ) ) ;
2021-04-02 11:46:43 +00:00
if ( ! SyncInput ( ) & & ! backup )
{
target = value ;
if ( ! targetset ( ) ) target = q16horiz ( 1 ) ;
}
else
{
horiz = value ;
if ( backup ) ohoriz = horiz ;
}
}
2020-10-11 14:33:43 +00:00
} ;
struct PlayerAngle
{
2021-04-11 05:43:11 +00:00
binangle ang , oang , look_ang , olook_ang , rotscrnang , orotscrnang ;
double spin ;
2020-10-11 14:33:43 +00:00
void backup ( )
{
oang = ang ;
olook_ang = look_ang ;
orotscrnang = rotscrnang ;
}
void restore ( )
{
ang = oang ;
look_ang = olook_ang ;
rotscrnang = orotscrnang ;
}
void addadjustment ( double value )
{
2021-04-11 05:43:11 +00:00
__addadjustment ( buildfang ( value ) ) ;
2021-05-12 01:44:05 +00:00
}
2020-11-22 10:47:13 +00:00
void addadjustment ( binangle value )
{
2021-04-11 05:43:11 +00:00
__addadjustment ( value ) ;
2021-05-12 01:44:05 +00:00
}
2020-11-22 10:47:13 +00:00
2020-10-11 14:33:43 +00:00
void resetadjustment ( )
{
adjustment = 0 ;
}
void settarget ( double value , bool backup = false )
{
2021-04-11 05:43:11 +00:00
__settarget ( buildfang ( value ) , backup ) ;
2021-05-12 01:44:05 +00:00
}
2020-10-11 14:33:43 +00:00
2020-11-22 12:57:35 +00:00
void settarget ( binangle value , bool backup = false )
{
2021-04-02 11:46:43 +00:00
__settarget ( value , backup ) ;
2021-05-12 01:44:05 +00:00
}
2021-04-02 11:46:43 +00:00
bool targetset ( )
2021-05-12 01:44:05 +00:00
{
2021-04-02 11:46:43 +00:00
return target . asbam ( ) ;
2021-05-12 01:44:05 +00:00
}
2020-10-11 14:33:43 +00:00
void processhelpers ( double const scaleAdjust )
{
2021-04-02 11:46:43 +00:00
if ( targetset ( ) )
2020-10-11 14:33:43 +00:00
{
2021-04-11 05:43:11 +00:00
auto delta = getincanglebam ( ang , target ) . signedbuildf ( ) ;
2020-10-11 14:33:43 +00:00
2021-04-11 05:43:11 +00:00
if ( abs ( delta ) > 1 )
2020-10-11 14:33:43 +00:00
{
2021-04-11 05:43:11 +00:00
ang + = buildfang ( scaleAdjust * delta ) ;
2020-10-11 14:33:43 +00:00
}
2021-04-02 11:46:43 +00:00
else
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:43:41 +00:00
ang = target ;
target = bamang ( 0 ) ;
2021-05-12 01:44:05 +00:00
}
2020-10-11 14:33:43 +00:00
}
else if ( adjustment )
{
2021-04-11 05:43:11 +00:00
ang + = buildfang ( scaleAdjust * adjustment ) ;
2020-10-11 14:33:43 +00:00
}
}
2020-10-18 11:43:42 +00:00
binangle osum ( )
{
2020-11-22 13:17:07 +00:00
return oang + olook_ang ;
2020-10-18 11:43:42 +00:00
}
2020-10-11 14:33:43 +00:00
binangle sum ( )
{
2020-11-22 13:17:07 +00:00
return ang + look_ang ;
2020-10-11 14:33:43 +00:00
}
binangle interpolatedsum ( double const smoothratio )
{
2021-04-11 06:45:19 +00:00
return interpolatedangle ( osum ( ) , sum ( ) , smoothratio ) ;
2020-10-11 14:33:43 +00:00
}
2021-04-11 05:43:11 +00:00
binangle interpolatedlookang ( double const smoothratio )
2020-11-26 05:37:37 +00:00
{
2021-04-11 06:45:19 +00:00
return interpolatedangle ( olook_ang , look_ang , smoothratio ) ;
2020-11-26 05:37:37 +00:00
}
2021-04-11 05:43:11 +00:00
binangle interpolatedrotscrn ( double const smoothratio )
2020-10-11 14:33:43 +00:00
{
2021-04-11 06:45:19 +00:00
return interpolatedangle ( orotscrnang , rotscrnang , smoothratio ) ;
2020-10-11 14:33:43 +00:00
}
2020-11-26 05:37:37 +00:00
2021-04-20 11:12:17 +00:00
double look_anghalf ( double const smoothratio )
2021-04-15 03:35:42 +00:00
{
2021-04-20 11:12:17 +00:00
return ( ! SyncInput ( ) ? look_ang : interpolatedlookang ( smoothratio ) ) . signedbuildf ( ) * 0.5 ; // Used within draw code for weapon and crosshair when looking left/right.
2021-04-15 03:35:42 +00:00
}
2021-04-20 11:12:17 +00:00
double looking_arc ( double const smoothratio )
2020-11-26 05:37:37 +00:00
{
2021-04-20 11:12:17 +00:00
return fabs ( ( ! SyncInput ( ) ? look_ang : interpolatedlookang ( smoothratio ) ) . signedbuildf ( ) ) * ( 1. / 9. ) ; // Used within draw code for weapon and crosshair when looking left/right.
2020-10-11 14:33:43 +00:00
}
2021-04-02 11:46:43 +00:00
2021-04-21 10:41:04 +00:00
void applyinput ( float const avel , ESyncBits * actions , double const scaleAdjust = 1 ) ;
2021-04-19 10:50:01 +00:00
2021-04-02 11:46:43 +00:00
private :
binangle target ;
double adjustment ;
2021-04-11 05:43:11 +00:00
void __addadjustment ( binangle value )
2021-04-02 11:46:43 +00:00
{
if ( ! SyncInput ( ) )
{
2021-04-11 07:52:29 +00:00
adjustment + = value . signedbuildf ( ) ;
2021-04-02 11:46:43 +00:00
}
else
{
ang + = value ;
}
}
2021-04-11 05:43:11 +00:00
void __settarget ( binangle value , bool backup )
2021-04-02 11:46:43 +00:00
{
if ( ! SyncInput ( ) & & ! backup )
{
target = value ;
if ( ! targetset ( ) ) target = bamang ( 1 ) ;
}
else
{
ang = value ;
if ( backup ) oang = ang ;
}
}
2020-10-11 14:33:43 +00:00
} ;
2020-10-11 14:55:12 +00:00
class FSerializer ;
FSerializer & Serialize ( FSerializer & arc , const char * keyname , PlayerAngle & w , PlayerAngle * def ) ;
FSerializer & Serialize ( FSerializer & arc , const char * keyname , PlayerHorizon & w , PlayerHorizon * def ) ;
2021-01-01 22:53:03 +00:00
void updateTurnHeldAmt ( double const scaleAdjust ) ;
bool const isTurboTurnTime ( ) ;
void resetTurnHeldAmt ( ) ;
2020-10-11 14:33:43 +00:00
void processMovement ( InputPacket * currInput , InputPacket * inputBuffer , ControlInfo * const hidInput , double const scaleAdjust , int const drink_amt = 0 , bool const allowstrafe = true , double const turnscale = 1 ) ;