- Clean-up of input functions.

* Remove unused `getincanglef()`.
* Remove unused `getincangleq16()`.
* In `PlayerHorizon` struct, clamp value when setting target in `__settarget()`, not each public `settarget()` overload.
* Rename `PlayerAngle` method `applylook()` to `applyinput()`.
* Rename `PlayerHorizon` method `sethorizon()` to `applyinput()`.
* In `PlayerHorizon::applylook()`, slightly clean return to centre code so it doesn't do math if already at 0.
* In `PlayerAngle::applylook()`, slightly clean rotscrnang/look_ang code so it doesn't do math if already at 0 and reposition where mouse input is applied so that if input is applied, the player never enters a spin.
* In `Duke3d::player_struct::apply_seasick()`, use `buildfang()` method instead of scaling float to BAM within function.
This commit is contained in:
Mitchell Richters 2021-04-21 20:41:04 +10:00
parent b49de68c86
commit 93edeac791
11 changed files with 54 additions and 81 deletions

View file

@ -50,34 +50,6 @@ int getincangle(int a, int na)
return na-a; return na-a;
} }
double getincanglef(double a, double na)
{
a = fmod(a, 2048.);
na = fmod(na, 2048.);
if(fabs(a-na) >= 1024)
{
if(na > 1024) na -= 2048;
if(a > 1024) a -= 2048;
}
return na-a;
}
fixed_t getincangleq16(fixed_t a, fixed_t na)
{
a &= 0x7FFFFFF;
na &= 0x7FFFFFF;
if(abs(a-na) >= IntToFixed(1024))
{
if(na > IntToFixed(1024)) na -= IntToFixed(2048);
if(a > IntToFixed(1024)) a -= IntToFixed(2048);
}
return na-a;
}
binangle getincanglebam(binangle a, binangle na) binangle getincanglebam(binangle a, binangle na)
{ {
int64_t cura = a.asbam(); int64_t cura = a.asbam();
@ -272,7 +244,7 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void PlayerHorizon::sethorizon(float const horz, ESyncBits* actions, double const scaleAdjust) void PlayerHorizon::applyinput(float const horz, ESyncBits* actions, double const scaleAdjust)
{ {
// Process only if no targeted horizon set. // Process only if no targeted horizon set.
if (!targetset()) if (!targetset())
@ -316,14 +288,11 @@ void PlayerHorizon::sethorizon(float const horz, ESyncBits* actions, double cons
horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax())); horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
// return to center if conditions met. // return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)) && horiz.asq16())
{
if (abs(horiz.asq16()) > (FRACUNIT >> 2))
{ {
// move horiz back to 0 // move horiz back to 0
horiz -= buildfhoriz(scaleAdjust * horiz.asbuildf() * (10. / GameTicRate)); horiz -= buildfhoriz(scaleAdjust * horiz.asbuildf() * (10. / GameTicRate));
} if (abs(horiz.asq16()) < (FRACUNIT >> 2))
else
{ {
// not looking anymore because horiz is back at 0 // not looking anymore because horiz is back at 0
horiz = q16horiz(0); horiz = q16horiz(0);
@ -343,15 +312,21 @@ void PlayerHorizon::sethorizon(float const horz, ESyncBits* actions, double cons
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void PlayerAngle::applylook(float const avel, ESyncBits* actions, double const scaleAdjust) void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const scaleAdjust)
{ {
// return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit if (rotscrnang.asbam())
{
// return rotscrnang to 0
rotscrnang -= buildfang(scaleAdjust * rotscrnang.signedbuildf() * (15. / GameTicRate)); rotscrnang -= buildfang(scaleAdjust * rotscrnang.signedbuildf() * (15. / GameTicRate));
if (abs(rotscrnang.signedbam()) < (BAMUNIT >> 2)) rotscrnang = bamang(0); if (abs(rotscrnang.signedbam()) < (BAMUNIT >> 2)) rotscrnang = bamang(0);
}
// return q16look_ang to 0 and set to 0 if less than a quarter of a unit if (look_ang.asbam())
{
// return look_ang to 0
look_ang -= buildfang(scaleAdjust * look_ang.signedbuildf() * (7.5 / GameTicRate)); look_ang -= buildfang(scaleAdjust * look_ang.signedbuildf() * (7.5 / GameTicRate));
if (abs(look_ang.signedbam()) < (BAMUNIT >> 2)) look_ang = bamang(0); if (abs(look_ang.signedbam()) < (BAMUNIT >> 2)) look_ang = bamang(0);
}
if (*actions & SB_LOOK_LEFT) if (*actions & SB_LOOK_LEFT)
{ {
@ -379,6 +354,13 @@ void PlayerAngle::applylook(float const avel, ESyncBits* actions, double const s
*actions &= ~SB_TURNAROUND; *actions &= ~SB_TURNAROUND;
} }
if (avel)
{
// add player's input
ang += degang(avel);
spin = 0;
}
if (spin < 0) if (spin < 0)
{ {
// return spin to 0 // return spin to 0
@ -392,13 +374,6 @@ void PlayerAngle::applylook(float const avel, ESyncBits* actions, double const s
} }
ang += buildfang(add); ang += buildfang(add);
} }
if (avel)
{
// add player's input
ang += degang(avel);
spin = 0;
}
} }
else else
{ {

View file

@ -7,8 +7,6 @@
#include "packet.h" #include "packet.h"
int getincangle(int a, int na); int getincangle(int a, int na);
double getincanglef(double a, double na);
fixed_t getincangleq16(fixed_t a, fixed_t na);
binangle getincanglebam(binangle a, binangle na); binangle getincanglebam(binangle a, binangle na);
struct PlayerHorizon struct PlayerHorizon
@ -44,12 +42,12 @@ struct PlayerHorizon
void settarget(double value, bool backup = false) void settarget(double value, bool backup = false)
{ {
__settarget(buildfhoriz(clamp(value, FixedToFloat(gi->playerHorizMin()), FixedToFloat(gi->playerHorizMax()))), backup); __settarget(buildfhoriz(value), backup);
} }
void settarget(fixedhoriz value, bool backup = false) void settarget(fixedhoriz value, bool backup = false)
{ {
__settarget(q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax())), backup); __settarget(value, backup);
} }
bool targetset() bool targetset()
@ -99,7 +97,7 @@ struct PlayerHorizon
return (!SyncInput() ? sum() : interpolatedsum(smoothratio)).asbuildf() * (1. / 16.); // Used within draw code for Duke. return (!SyncInput() ? sum() : interpolatedsum(smoothratio)).asbuildf() * (1. / 16.); // Used within draw code for Duke.
} }
void sethorizon(float const horz, ESyncBits* actions, double const scaleAdjust = 1); 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); 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: private:
@ -120,6 +118,8 @@ private:
void __settarget(fixedhoriz value, bool backup) void __settarget(fixedhoriz value, bool backup)
{ {
value = q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
if (!SyncInput() && !backup) if (!SyncInput() && !backup)
{ {
target = value; target = value;
@ -239,7 +239,7 @@ struct PlayerAngle
return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); // Used within draw code for weapon and crosshair when looking left/right. return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); // Used within draw code for weapon and crosshair when looking left/right.
} }
void applylook(float const avel, ESyncBits* actions, double const scaleAdjust = 1); void applyinput(float const avel, ESyncBits* actions, double const scaleAdjust = 1);
private: private:
binangle target; binangle target;

View file

@ -58,8 +58,8 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
// Perform unsynchronised angle/horizon if not dead. // Perform unsynchronised angle/horizon if not dead.
if (gView->pXSprite->health != 0) if (gView->pXSprite->health != 0)
{ {
pPlayer->angle.applylook(input.avel, &pPlayer->input.actions, scaleAdjust); pPlayer->angle.applyinput(input.avel, &pPlayer->input.actions, scaleAdjust);
pPlayer->horizon.sethorizon(input.horz, &pPlayer->input.actions, scaleAdjust); pPlayer->horizon.applyinput(input.horz, &pPlayer->input.actions, scaleAdjust);
doslopetilting(pPlayer, scaleAdjust); doslopetilting(pPlayer, scaleAdjust);
} }

View file

@ -1422,7 +1422,7 @@ void ProcessInput(PLAYER *pPlayer)
if (SyncInput()) if (SyncInput())
{ {
pPlayer->angle.applylook(pInput->avel, &pInput->actions); pPlayer->angle.applyinput(pInput->avel, &pInput->actions);
} }
// unconditionally update the player's sprite angle // unconditionally update the player's sprite angle
@ -1549,7 +1549,7 @@ void ProcessInput(PLAYER *pPlayer)
if (SyncInput()) if (SyncInput())
{ {
pPlayer->horizon.sethorizon(pInput->horz, &pInput->actions); pPlayer->horizon.applyinput(pInput->horz, &pInput->actions);
doslopetilting(pPlayer); doslopetilting(pPlayer);
} }

View file

@ -834,9 +834,9 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
{ {
// Do these in the same order as the old code. // Do these in the same order as the old code.
doslopetilting(p, scaleAdjust); doslopetilting(p, scaleAdjust);
p->angle.applylook(p->adjustavel(input.avel), &p->sync.actions, scaleAdjust); p->angle.applyinput(p->adjustavel(input.avel), &p->sync.actions, scaleAdjust);
p->apply_seasick(scaleAdjust); p->apply_seasick(scaleAdjust);
p->horizon.sethorizon(input.horz, &p->sync.actions, scaleAdjust); p->horizon.applyinput(input.horz, &p->sync.actions, scaleAdjust);
} }
p->angle.processhelpers(scaleAdjust); p->angle.processhelpers(scaleAdjust);

View file

@ -741,16 +741,16 @@ void player_struct::apply_seasick(double factor)
if (SeaSick < 250) if (SeaSick < 250)
{ {
if (SeaSick >= 180) if (SeaSick >= 180)
angle.rotscrnang += bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang += buildfang(24 * factor);
else if (SeaSick >= 130) else if (SeaSick >= 130)
angle.rotscrnang -= bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang -= buildfang(24 * factor);
else if (SeaSick >= 70) else if (SeaSick >= 70)
angle.rotscrnang += bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang += buildfang(24 * factor);
else if (SeaSick >= 20) else if (SeaSick >= 20)
angle.rotscrnang -= bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang -= buildfang(24 * factor);
} }
if (SeaSick < 250) if (SeaSick < 250)
angle.look_ang = bamang(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT)); angle.look_ang = buildfang(((krand() & 255) - 128) * factor);
} }
} }

View file

@ -2729,7 +2729,6 @@ void processinput_d(int snum)
int j, k, doubvel, fz, cz, truefdist; int j, k, doubvel, fz, cz, truefdist;
Collision chz, clz; Collision chz, clz;
bool shrunk; bool shrunk;
ESyncBits actions;
short psect, psectlotag; short psect, psectlotag;
struct player_struct* p; struct player_struct* p;
spritetype* s; spritetype* s;
@ -2741,7 +2740,7 @@ void processinput_d(int snum)
p->horizon.resetadjustment(); p->horizon.resetadjustment();
p->angle.resetadjustment(); p->angle.resetadjustment();
actions = PlayerInputBits(snum, SB_ALL); ESyncBits& actions = p->sync.actions;
auto sb_fvel = PlayerInputForwardVel(snum); auto sb_fvel = PlayerInputForwardVel(snum);
auto sb_svel = PlayerInputSideVel(snum); auto sb_svel = PlayerInputSideVel(snum);
@ -2906,7 +2905,7 @@ void processinput_d(int snum)
// may still be needed later for demo recording // may still be needed later for demo recording
sb_avel = p->adjustavel(sb_avel); sb_avel = p->adjustavel(sb_avel);
p->angle.applylook(sb_avel, &p->sync.actions); p->angle.applyinput(sb_avel, &actions);
} }
if (p->spritebridge == 0) if (p->spritebridge == 0)
@ -3139,7 +3138,7 @@ HORIZONLY:
if (SyncInput()) if (SyncInput())
{ {
p->horizon.sethorizon(PlayerHorizon(snum), &p->sync.actions); p->horizon.applyinput(PlayerHorizon(snum), &actions);
} }
p->checkhardlanding(); p->checkhardlanding();

View file

@ -3353,7 +3353,6 @@ void processinput_r(int snum)
int i, k, doubvel, fz, cz, truefdist; int i, k, doubvel, fz, cz, truefdist;
Collision chz, clz; Collision chz, clz;
char shrunk; char shrunk;
ESyncBits actions;
short psect, psectlotag; short psect, psectlotag;
auto p = &ps[snum]; auto p = &ps[snum];
@ -3363,7 +3362,7 @@ void processinput_r(int snum)
p->horizon.resetadjustment(); p->horizon.resetadjustment();
p->angle.resetadjustment(); p->angle.resetadjustment();
actions = PlayerInputBits(snum, SB_ALL); ESyncBits& actions = p->sync.actions;
auto sb_fvel = PlayerInputForwardVel(snum); auto sb_fvel = PlayerInputForwardVel(snum);
auto sb_svel = PlayerInputSideVel(snum); auto sb_svel = PlayerInputSideVel(snum);
@ -3639,7 +3638,7 @@ void processinput_r(int snum)
// may still be needed later for demo recording // may still be needed later for demo recording
sb_avel = p->adjustavel(sb_avel); sb_avel = p->adjustavel(sb_avel);
p->angle.applylook(sb_avel, &p->sync.actions); p->angle.applyinput(sb_avel, &actions);
} }
if (p->spritebridge == 0) if (p->spritebridge == 0)
@ -4001,7 +4000,7 @@ HORIZONLY:
if (SyncInput()) if (SyncInput())
{ {
p->horizon.sethorizon(PlayerHorizon(snum), &p->sync.actions); p->horizon.applyinput(PlayerHorizon(snum), &actions);
} }
p->checkhardlanding(); p->checkhardlanding();

View file

@ -124,8 +124,8 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
{ {
if (!nFreeze) if (!nFreeze)
{ {
pPlayer->angle.applylook(input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); pPlayer->angle.applyinput(input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
pPlayer->horizon.sethorizon(input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); pPlayer->horizon.applyinput(input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
if (input.horz) if (input.horz)
{ {

View file

@ -915,7 +915,7 @@ void FuncPlayer(int a, int nDamage, int nRun)
if (SyncInput()) if (SyncInput())
{ {
Player* pPlayer = &PlayerList[nPlayer]; Player* pPlayer = &PlayerList[nPlayer];
pPlayer->angle.applylook(sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions); pPlayer->angle.applyinput(sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions);
UpdatePlayerSpriteAngle(pPlayer); UpdatePlayerSpriteAngle(pPlayer);
} }
@ -2640,7 +2640,7 @@ loc_1BD2E:
if (SyncInput()) if (SyncInput())
{ {
pPlayer->horizon.sethorizon(sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions); pPlayer->horizon.applyinput(sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions);
} }
if (actions & (SB_LOOK_UP | SB_LOOK_DOWN) || sPlayerInput[nPlayer].pan) if (actions & (SB_LOOK_UP | SB_LOOK_DOWN) || sPlayerInput[nPlayer].pan)

View file

@ -1516,7 +1516,7 @@ UpdatePlayerSpriteAngle(PLAYERp pp)
void void
DoPlayerTurn(PLAYERp pp, float const avel, double const scaleAdjust) DoPlayerTurn(PLAYERp pp, float const avel, double const scaleAdjust)
{ {
pp->angle.applylook(avel, &pp->input.actions, scaleAdjust); pp->angle.applyinput(avel, &pp->input.actions, scaleAdjust);
UpdatePlayerSpriteAngle(pp); UpdatePlayerSpriteAngle(pp);
} }
@ -1668,7 +1668,7 @@ DoPlayerHorizon(PLAYERp pp, float const horz, double const scaleAdjust)
{ {
bool const canslopetilt = !TEST(pp->Flags, PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING) && TEST(sector[pp->cursectnum].floorstat, FLOOR_STAT_SLOPE); bool const canslopetilt = !TEST(pp->Flags, PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING) && TEST(sector[pp->cursectnum].floorstat, FLOOR_STAT_SLOPE);
pp->horizon.calcviewpitch(pp->pos.vec2, pp->angle.ang, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursectnum, scaleAdjust, TEST(pp->Flags, PF_CLIMBING)); pp->horizon.calcviewpitch(pp->pos.vec2, pp->angle.ang, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursectnum, scaleAdjust, TEST(pp->Flags, PF_CLIMBING));
pp->horizon.sethorizon(horz, &pp->input.actions, scaleAdjust); pp->horizon.applyinput(horz, &pp->input.actions, scaleAdjust);
} }
void void