2020-10-11 14:33:43 +00:00
# pragma once
# include "m_fixed.h"
# include "binaryangle.h"
# include "gamecvars.h"
# include "packet.h"
2020-11-22 10:45:16 +00:00
int getincangle ( int a , int na ) ;
2020-11-26 06:26:29 +00:00
double getincanglef ( double a , double na ) ;
2020-11-22 10:45:16 +00:00
fixed_t getincangleq16 ( fixed_t a , fixed_t na ) ;
lookangle getincanglebam ( binangle a , binangle na ) ;
2020-10-11 14:33:43 +00:00
struct PlayerHorizon
{
2021-03-31 08:44:50 +00:00
fixedhoriz horiz , ohoriz , horizoff , ohorizoff , target ;
double adjustment ;
2020-10-11 14:33:43 +00:00
void backup ( )
{
ohoriz = horiz ;
ohorizoff = horizoff ;
}
void restore ( )
{
horiz = ohoriz ;
horizoff = ohorizoff ;
}
void addadjustment ( double value )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) )
2020-10-11 14:33:43 +00:00
{
2020-10-18 11:00:39 +00:00
adjustment + = value * FRACUNIT ;
2020-10-11 14:33:43 +00:00
}
else
{
horiz + = q16horiz ( FloatToFixed ( value ) ) ;
}
}
void resetadjustment ( )
{
adjustment = 0 ;
}
2021-03-31 08:44:50 +00:00
void settarget ( int value , bool backup = false )
{
if ( ! SyncInput ( ) & & ! backup )
{
target = buildhoriz ( value ) ;
if ( target . asq16 ( ) = = 0 ) target = q16horiz ( 1 ) ;
}
else
{
horiz = buildhoriz ( value ) ;
if ( backup ) ohoriz = horiz ;
}
}
2020-10-11 14:33:43 +00:00
void settarget ( double value , bool backup = false )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) & & ! backup )
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:44:50 +00:00
target = buildfhoriz ( value ) ;
if ( target . asq16 ( ) = = 0 ) target = q16horiz ( 1 ) ;
}
else
{
horiz = buildfhoriz ( value ) ;
if ( backup ) ohoriz = horiz ;
}
}
void settarget ( fixedhoriz value , bool backup = false )
{
if ( ! SyncInput ( ) & & ! backup )
{
target = value ;
if ( target . asq16 ( ) = = 0 ) target = q16horiz ( 1 ) ;
2020-10-11 14:33:43 +00:00
}
else
{
2021-03-31 08:44:50 +00:00
horiz = value ;
2020-10-11 14:33:43 +00:00
if ( backup ) ohoriz = horiz ;
}
}
void processhelpers ( double const scaleAdjust )
{
2021-03-31 08:44:50 +00:00
if ( target . asq16 ( ) )
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:44:50 +00:00
horiz + = q16horiz ( xs_CRoundToInt ( scaleAdjust * ( target - horiz ) . asq16 ( ) ) ) ;
2020-10-11 14:33:43 +00:00
2021-03-31 08:44:50 +00:00
if ( abs ( ( horiz - target ) . asq16 ( ) ) < FRACUNIT )
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:44:50 +00:00
horiz = target ;
target = q16horiz ( 0 ) ;
2020-10-11 14:33:43 +00:00
}
}
else if ( adjustment )
{
2020-10-18 11:00:39 +00:00
horiz + = q16horiz ( xs_CRoundToInt ( 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 )
{
2020-10-18 11:00:39 +00:00
double const ratio = smoothratio * ( 1. / FRACUNIT ) ;
2020-10-18 11:43:42 +00:00
fixed_t const prev = osum ( ) . asq16 ( ) ;
fixed_t const curr = sum ( ) . asq16 ( ) ;
2020-10-11 14:33:43 +00:00
return q16horiz ( prev + xs_CRoundToInt ( ratio * ( curr - prev ) ) ) ;
}
} ;
struct PlayerAngle
{
2021-03-31 08:43:41 +00:00
binangle ang , oang , target ;
2020-10-11 14:33:43 +00:00
lookangle look_ang , olook_ang , rotscrnang , orotscrnang , spin ;
2021-03-31 08:43:41 +00:00
double adjustment ;
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 ;
}
2020-11-22 10:47:13 +00:00
void addadjustment ( int value )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) )
2020-11-22 10:47:13 +00:00
{
adjustment + = BAngToBAM ( value ) ;
}
else
{
ang + = buildang ( value ) ;
}
}
2020-10-11 14:33:43 +00:00
void addadjustment ( double value )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) )
2020-10-11 14:33:43 +00:00
{
2020-10-18 11:00:39 +00:00
adjustment + = value * BAMUNIT ;
2020-10-11 14:33:43 +00:00
}
else
{
ang + = bamang ( xs_CRoundToUInt ( value * BAMUNIT ) ) ;
}
}
2020-11-22 10:47:13 +00:00
void addadjustment ( lookangle value )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) )
2020-11-22 10:47:13 +00:00
{
adjustment + = value . asbam ( ) ;
}
else
{
ang + = bamang ( value . asbam ( ) ) ;
}
}
void addadjustment ( binangle value )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) )
2020-11-22 10:47:13 +00:00
{
adjustment + = value . asbam ( ) ;
}
else
{
ang + = value ;
}
}
2020-10-11 14:33:43 +00:00
void resetadjustment ( )
{
adjustment = 0 ;
}
2020-11-22 09:54:59 +00:00
void settarget ( int value , bool backup = false )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) & & ! backup )
2020-11-22 09:54:59 +00:00
{
2021-03-31 08:43:41 +00:00
target = buildang ( value & 2047 ) ;
if ( target . asbam ( ) = = 0 ) target = bamang ( 1 ) ;
2020-11-22 09:54:59 +00:00
}
else
{
2021-03-31 08:43:41 +00:00
ang = buildang ( value & 2047 ) ;
2020-11-22 09:54:59 +00:00
if ( backup ) oang = ang ;
}
}
2020-10-11 14:33:43 +00:00
void settarget ( double value , bool backup = false )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) & & ! backup )
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:43:41 +00:00
target = buildfang ( fmod ( value , 2048 ) ) ;
if ( target . asbam ( ) = = 0 ) target = bamang ( 1 ) ;
2020-10-11 14:33:43 +00:00
}
else
{
2021-03-31 08:43:41 +00:00
ang = buildfang ( fmod ( value , 2048 ) ) ;
2020-10-11 14:33:43 +00:00
if ( backup ) oang = ang ;
}
}
2020-11-22 12:57:35 +00:00
void settarget ( binangle value , bool backup = false )
{
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) & & ! backup )
2020-11-22 12:57:35 +00:00
{
2021-03-31 08:43:41 +00:00
target = value ;
if ( target . asbam ( ) = = 0 ) target = bamang ( 1 ) ;
2020-11-22 12:57:35 +00:00
}
else
{
ang = value ;
if ( backup ) oang = ang ;
}
}
2020-10-11 14:33:43 +00:00
void processhelpers ( double const scaleAdjust )
{
2021-03-31 08:43:41 +00:00
if ( target . asbam ( ) )
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:43:41 +00:00
ang + = bamang ( xs_CRoundToUInt ( scaleAdjust * getincanglebam ( ang , target ) . asbam ( ) ) ) ;
2020-10-11 14:33:43 +00:00
2021-03-31 08:43:41 +00:00
if ( getincanglebam ( ang , target ) . asbam ( ) < BAMUNIT )
2020-10-11 14:33:43 +00:00
{
2021-03-31 08:43:41 +00:00
ang = target ;
target = bamang ( 0 ) ;
2020-10-11 14:33:43 +00:00
}
}
else if ( adjustment )
{
2020-10-18 11:00:39 +00:00
ang + = bamang ( xs_CRoundToUInt ( 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 )
{
2020-10-18 11:05:21 +00:00
double const ratio = smoothratio * ( 1. / FRACUNIT ) ;
2020-10-12 05:28:05 +00:00
uint32_t const dang = UINT32_MAX > > 1 ;
2020-10-18 11:43:42 +00:00
int64_t const prev = osum ( ) . asbam ( ) ;
int64_t const curr = sum ( ) . asbam ( ) ;
2020-10-11 14:33:43 +00:00
return bamang ( prev + xs_CRoundToUInt ( ratio * ( ( ( curr + dang - prev ) & 0xFFFFFFFF ) - dang ) ) ) ;
}
2020-11-26 05:37:37 +00:00
lookangle interpolatedlookang ( double const smoothratio )
{
double const ratio = smoothratio * ( 1. / FRACUNIT ) ;
return bamlook ( olook_ang . asbam ( ) + xs_CRoundToInt ( ratio * ( look_ang - olook_ang ) . asbam ( ) ) ) ;
}
2020-10-11 14:33:43 +00:00
lookangle interpolatedrotscrn ( double const smoothratio )
{
2020-11-22 13:17:07 +00:00
double const ratio = smoothratio * ( 1. / FRACUNIT ) ;
return bamlook ( orotscrnang . asbam ( ) + xs_CRoundToInt ( ratio * ( rotscrnang - orotscrnang ) . asbam ( ) ) ) ;
2020-10-11 14:33:43 +00:00
}
2020-11-26 05:37:37 +00:00
double look_anghalf ( double const smoothratio )
{
2020-11-30 22:40:16 +00:00
return ( ! SyncInput ( ) ? look_ang : interpolatedlookang ( smoothratio ) ) . asbam ( ) * ( 0.5 / BAMUNIT ) ; // Used within draw code for weapon and crosshair when looking left/right.
2020-11-26 05:37:37 +00:00
}
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 ) ;
2020-11-07 07:25:06 +00:00
void sethorizon ( fixedhoriz * horiz , float const horz , ESyncBits * actions , double const scaleAdjust = 1 ) ;
void applylook ( PlayerAngle * angle , float const avel , ESyncBits * actions , double const scaleAdjust = 1 ) ;
2021-01-01 22:32:19 +00:00
void calcviewpitch ( vec2_t const pos , fixedhoriz * horizoff , binangle const ang , bool const aimmode , bool const canslopetilt , int const cursectnum , double const scaleAdjust = 1 , bool const climbing = false ) ;