- gamecontrol: Initial setup of PlayerHorizon struct and deployment within Duke.

* Started with the most complicated game first.
* Struct made up of fixedhoriz class units.
* Append currently outgoing function names with `2` at the end to avoid conflict.
This commit is contained in:
Mitchell Richters 2020-10-07 17:12:37 +11:00
parent 0e3604ac9e
commit f39939d114
24 changed files with 275 additions and 157 deletions

View file

@ -56,7 +56,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
if (gView->pXSprite->health != 0)
{
applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0);
sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust);
sethorizon2(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust);
}
playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust);

View file

@ -1364,7 +1364,7 @@ void ProcessInput(PLAYER *pPlayer)
}
pPlayer->deathTime += 4;
if (!bSeqStat)
playerAddHoriz(&pPlayer->q16horiz, &pPlayer->horizAdjust, FixedToFloat(mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime<<3, 1024))>>15), gi->playerHorizMax()) - pPlayer->q16horiz));
playerAddHoriz2(&pPlayer->q16horiz, &pPlayer->horizAdjust, FixedToFloat(mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime<<3, 1024))>>15), gi->playerHorizMax()) - pPlayer->q16horiz));
if (pPlayer->curWeapon)
pInput->setNewWeapon(pPlayer->curWeapon);
if (pInput->actions & SB_OPEN)
@ -1558,7 +1558,7 @@ void ProcessInput(PLAYER *pPlayer)
if (cl_syncinput)
{
sethorizon(&pPlayer->q16horiz, pInput->q16horz, &pInput->actions, 1);
sethorizon2(&pPlayer->q16horiz, pInput->q16horz, &pInput->actions, 1);
}
int nSector = pSprite->sectnum;

View file

@ -1568,7 +1568,7 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn
//
//---------------------------------------------------------------------------
void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust)
void sethorizon2(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust)
{
// Calculate adjustment as true pitch (Fixed point math really sucks...)
double horizAngle = HorizToPitch(*q16horiz);
@ -1628,6 +1628,73 @@ void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, do
*q16horiz = clamp(PitchToHoriz(horizAngle), gi->playerHorizMin(), gi->playerHorizMax());
}
//---------------------------------------------------------------------------
//
// Player's horizon function, called from game's ticker or from gi->GetInput() as required.
//
//---------------------------------------------------------------------------
static double const aimamount = HorizToPitch(250. / GameTicRate);
static double const lookamount = HorizToPitch(500. / GameTicRate);
void sethorizon(fixedhoriz* horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust)
{
// Store current horizon as true pitch.
double pitch = horiz->aspitch();
if (q16horz)
{
*actions &= ~SB_CENTERVIEW;
pitch += FixedToFloat(q16horz);
}
// this is the locked type
if (*actions & (SB_AIM_UP|SB_AIM_DOWN))
{
*actions &= ~SB_CENTERVIEW;
if (*actions & SB_AIM_DOWN)
pitch -= scaleAdjust * aimamount;
if (*actions & SB_AIM_UP)
pitch += scaleAdjust * aimamount;
}
// this is the unlocked type
if (*actions & (SB_LOOK_UP|SB_LOOK_DOWN))
{
*actions |= SB_CENTERVIEW;
if (*actions & SB_LOOK_DOWN)
pitch -= scaleAdjust * lookamount;
if (*actions & SB_LOOK_UP)
pitch += scaleAdjust * lookamount;
}
// clamp pitch after processing
pitch = clamp(pitch, -90, 90);
// return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{
if (abs(pitch) > 0.1375)
{
// move pitch back to 0
pitch += -scaleAdjust * pitch * (9. / GameTicRate);
}
else
{
// not looking anymore because pitch is back at 0
pitch = 0;
*actions &= ~SB_CENTERVIEW;
}
}
// clamp before returning
*horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
}
//---------------------------------------------------------------------------
//
// Player's angle function, called from game's ticker or from gi->GetInput() as required.
@ -1722,7 +1789,7 @@ void playerSetAngle(fixed_t* q16ang, fixed_t* helper, double adjustment)
}
}
void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment)
void playerAddHoriz2(fixed_t* q16horiz, double* helper, double adjustment)
{
if (!cl_syncinput)
{
@ -1734,7 +1801,7 @@ void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment)
}
}
void playerSetHoriz(fixed_t* q16horiz, fixed_t* helper, double adjustment)
void playerSetHoriz2(fixed_t* q16horiz, fixed_t* helper, double adjustment)
{
if (!cl_syncinput)
{

View file

@ -68,13 +68,87 @@ void CompleteLevel(MapRecord* map);
int getincangle(int c, int n);
fixed_t getincangleq16(fixed_t c, fixed_t n);
struct PlayerHorizon
{
fixedhoriz horiz, ohoriz, horizoff, ohorizoff;
fixed_t target;
double adjustment;
void backup()
{
ohoriz = horiz;
ohorizoff = horizoff;
}
void addadjustment(double value)
{
if (!cl_syncinput)
{
adjustment += value;
}
else
{
horiz += q16horiz(FloatToFixed(value));
}
}
void resetadjustment()
{
adjustment = 0;
}
void settarget(double value)
{
if (!cl_syncinput)
{
target = FloatToFixed(value);
if (target == 0) target += 1;
}
else
{
horiz = q16horiz(FloatToFixed(value));
}
}
void processhelpers(double const scaleAdjust)
{
if (target)
{
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * (target - horiz.asq16())));
if (abs(horiz.asq16() - target) < FRACUNIT)
{
horiz = q16horiz(target);
target = 0;
}
}
else if (adjustment)
{
horiz += q16horiz(FloatToFixed(scaleAdjust * adjustment));
}
}
fixedhoriz sum()
{
return horiz + horizoff;
}
fixedhoriz interpolatedsum(double const smoothratio)
{
fixedhoriz prev = ohoriz + ohorizoff;
fixedhoriz curr = horiz + horizoff;
return q16horiz(prev.asq16() + mulscale16(curr.asq16() - prev.asq16(), smoothratio));
}
};
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);
void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust);
void sethorizon(fixedhoriz* horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust);
void sethorizon2(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust);
void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching);
void playerAddAngle(fixed_t* q16ang, double* helper, double adjustment);
void playerSetAngle(fixed_t* q16ang, fixed_t* helper, double adjustment);
void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment);
void playerSetHoriz(fixed_t* q16horiz, fixed_t* helper, double adjustment);
void playerAddHoriz2(fixed_t* q16horiz, double* helper, double adjustment);
void playerSetHoriz2(fixed_t* q16horiz, fixed_t* helper, double adjustment);
void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, fixed_t* q16horiz, double* horizAdjust, fixed_t* horizTarget, double const scaleAdjust);
struct UserConfig

View file

@ -129,7 +129,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
if (!nFreeze)
{
applylook(&pPlayer->q16angle, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080);
sethorizon(&pPlayer->q16horiz, input.q16horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
sethorizon2(&pPlayer->q16horiz, input.q16horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
}
playerProcessHelpers(&pPlayer->q16angle, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust);

View file

@ -1050,7 +1050,7 @@ void FuncPlayer(int a, int nDamage, int nRun)
PlayerList[nPlayer].oq16angle = PlayerList[nPlayer].q16angle;
sprite[nPlayerSprite].ang = ang;
playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 0);
playerSetHoriz2(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 0);
PlayerList[nPlayer].oq16horiz = PlayerList[nPlayer].q16horiz;
lPlayerXVel = 0;
@ -1069,11 +1069,11 @@ void FuncPlayer(int a, int nDamage, int nRun)
if (currentLevel->levelNumber == 11)
{
playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 46);
playerSetHoriz2(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 46);
}
else
{
playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 11);
playerSetHoriz2(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 11);
}
}
}
@ -2669,7 +2669,7 @@ loc_1BD2E:
if (cl_syncinput)
{
Player* pPlayer = &PlayerList[nPlayer];
sethorizon(&pPlayer->q16horiz, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions, 1);
sethorizon2(&pPlayer->q16horiz, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions, 1);
}
}
else // else, player's health is less than 0
@ -2791,16 +2791,16 @@ loc_1BD2E:
{
if (PlayerList[nPlayer].q16horiz < 0)
{
playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 0);
playerSetHoriz2(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 0);
eyelevel[nPlayer] -= (dVertPan[nPlayer] << 8);
}
else
{
playerAddHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizAdjust, dVertPan[nPlayer]);
playerAddHoriz2(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizAdjust, dVertPan[nPlayer]);
if (PlayerList[nPlayer].q16horiz > gi->playerHorizMax())
{
playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, gi->playerHorizMax());
playerSetHoriz2(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, gi->playerHorizMax());
}
else if (PlayerList[nPlayer].q16horiz <= 0)
{

View file

@ -1852,7 +1852,7 @@ void moveweapons_d(void)
if (s->picnum == SPIT)
{
playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32);
ps[p].horizon.addadjustment(32);
ps[p].sync.actions |= SB_CENTERVIEW;
if (ps[p].loogcnt == 0)
@ -2504,7 +2504,7 @@ static void greenslime(int i)
s->z = ps[p].posz + ps[p].pyoff - t[2] + (8 << 8);
s->z += -ps[p].getq16horiz() >> 12;
s->z += -ps[p].horizon.horiz.asq16() >> 12;
if (t[2] > 512)
t[2] -= 128;

View file

@ -1399,7 +1399,7 @@ void moveweapons_r(void)
guts_r(s, RABBITJIBC, 2, myconnectindex);
}
playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32);
ps[p].horizon.addadjustment(32);
ps[p].sync.actions |= SB_CENTERVIEW;
if (ps[p].loogcnt == 0)

View file

@ -119,7 +119,7 @@ static int osdcmd_warptocoords(CCmdFuncPtr parm)
if (parm->numparms == 5)
{
p->oq16horiz = p->q16horiz = IntToFixed(atoi(parm->parms[4]));
p->horizon.ohoriz = p->horizon.horiz = buildhoriz(atoi(parm->parms[4]));
}
return CCMD_OK;

View file

@ -242,7 +242,6 @@ int* animateptr(int i);
void backuppos(player_struct* p, bool noclipping = false);
void backuplook(player_struct* p);
void backupview(player_struct* p);
void backupweapon(player_struct* p);
void resetinputhelpers(player_struct* p);
void checkhardlanding(player_struct* p);

View file

@ -330,16 +330,21 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl
break;
case PLAYER_HORIZ:
if (bSet) playerSetHoriz(&ps[iPlayer].q16horiz, &ps[iPlayer].horizTarget - 100, lValue);
else SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horiz + 100), sActor, sPlayer);
if (bSet) ps[iPlayer].horizon.settarget(lValue - 100);
else SetGameVarID((int)lVar2, ps[iPlayer].horizon.horiz.asbuild() + 100, sActor, sPlayer);
break;
case PLAYER_OHORIZ:
if (!bSet) SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horiz + 100), sActor, sPlayer);
if (!bSet) SetGameVarID((int)lVar2, ps[iPlayer].horizon.ohoriz.asbuild() + 100, sActor, sPlayer);
break;
case PLAYER_HORIZOFF:
if (bSet) ps[iPlayer].horizon.horizoff = buildhoriz(lValue);
else SetGameVarID((int)lVar2, ps[iPlayer].horizon.horizoff.asbuild(), sActor, sPlayer);
break;
case PLAYER_OHORIZOFF:
if (!bSet) SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horizoff), sActor, sPlayer);
if (!bSet) SetGameVarID((int)lVar2, ps[iPlayer].horizon.ohorizoff.asbuild(), sActor, sPlayer);
break;
case PLAYER_INVDISPTIME:
@ -520,11 +525,6 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl
else SetGameVarID((int)lVar2, ps[iPlayer].tipincs, sActor, sPlayer);
break;
case PLAYER_HORIZOFF:
if (bSet) ps[iPlayer].q16horizoff = IntToFixed(lValue);
else SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horizoff), sActor, sPlayer);
break;
case PLAYER_WANTWEAPONFIRE:
if (bSet) ps[iPlayer].wantweaponfire = lValue;
else SetGameVarID((int)lVar2, ps[iPlayer].wantweaponfire, sActor, sPlayer);
@ -2246,10 +2246,10 @@ int ParseState::parse(void)
ps[g_p].last_extra = g_sp->extra = max_player_health;
ps[g_p].wantweaponfire = -1;
ps[g_p].sethoriz(0);
ps[g_p].horizon.ohoriz = ps[g_p].horizon.horiz = q16horiz(0);
ps[g_p].on_crane = -1;
ps[g_p].frag_ps = g_p;
ps[g_p].sethorizoff(0);
ps[g_p].horizon.ohorizoff = ps[g_p].horizon.horizoff = q16horiz(0);
ps[g_p].opyoff = 0;
ps[g_p].wackedbyactor = -1;
ps[g_p].shield_amount = max_armour_amount;

View file

@ -191,15 +191,15 @@ inline void backupplayer(player_struct* p)
{
backuppos(p);
backuplook(p);
backupview(p);
p->horizon.backup();
}
// the weapon display code uses this.
inline double get16thOfHoriz(int snum, bool interpolate, double smoothratio)
{
struct player_struct *p = &ps[snum];
fixed_t ohorz = p->oq16horiz - p->oq16horizoff;
fixed_t horz = p->q16horiz - p->q16horizoff;
fixed_t ohorz = p->horizon.ohoriz.asq16() - p->horizon.ohorizoff.asq16();
fixed_t horz = p->horizon.horiz.asq16() - p->horizon.horizoff.asq16();
return (!interpolate ? horz : ohorz + fmulscale16(horz - ohorz, smoothratio)) * (0.0625 / FRACUNIT);
}

View file

@ -923,10 +923,15 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
calcviewpitch(p, scaleAdjust);
processq16avel(p, &input.q16avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, input.q16avel, &p->sync.actions, scaleAdjust, p->crouch_toggle || p->sync.actions & SB_CROUCH);
sethorizon(&p->q16horiz, input.q16horz, &p->sync.actions, scaleAdjust);
sethorizon(&p->horizon.horiz, input.q16horz, &p->sync.actions, scaleAdjust);
}
playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust);
// temporary vals to pass through to playerProcessHelpers().
fixed_t horiz = 0;
fixed_t target = 0;
double adjust = 0;
playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &horiz, &adjust, &target, scaleAdjust);
p->horizon.processhelpers(scaleAdjust);
}
if (packet)

View file

@ -91,30 +91,30 @@ void calcviewpitch(player_struct *p, double factor)
{
int psect = p->cursectnum;
int psectlotag = sector[psect].lotag;
if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2))
{
int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5);
int y = p->posy + (sintable[p->getang() & 2047] >> 5);
short tempsect = psect;
updatesector(x, y, &tempsect);
if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2))
{
int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5);
int y = p->posy + (sintable[p->getang() & 2047] >> 5);
short tempsect = psect;
updatesector(x, y, &tempsect);
if (tempsect >= 0)
{
int k = getflorzofslope(psect, x, y);
if (psect == tempsect || abs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8))
p->addhorizoff(factor * mulscale16(p->truefz - k, 160));
}
}
if (p->q16horizoff > 0)
{
p->addhorizoff(-factor * FixedToFloat((p->q16horizoff >> 3) + FRACUNIT));
if (p->q16horizoff < 0) p->q16horizoff = 0;
}
else if (p->q16horizoff < 0)
{
p->addhorizoff(-factor * FixedToFloat((p->q16horizoff >> 3) + FRACUNIT));
if (p->q16horizoff > 0) p->q16horizoff = 0;
}
if (tempsect >= 0)
{
int k = getflorzofslope(psect, x, y);
if (psect == tempsect || abs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8))
p->horizon.horizoff += q16horiz(FloatToFixed(factor * mulscale16(p->truefz - k, 160)));
}
}
if (p->horizon.horizoff.asq16() > 0)
{
p->horizon.horizoff += q16horiz(xs_CRoundToInt(-factor * ((p->horizon.horizoff.asq16() >> 3) + FRACUNIT)));
if (p->horizon.horizoff.asq16() < 0) p->horizon.horizoff = q16horiz(0);
}
else if (p->horizon.horizoff.asq16() < 0)
{
p->horizon.horizoff += q16horiz(xs_CRoundToInt(-factor * ((p->horizon.horizoff.asq16() >> 3) + FRACUNIT)));
if (p->horizon.horizoff.asq16() > 0) p->horizon.horizoff = q16horiz(0);
}
}
//---------------------------------------------------------------------------
@ -164,7 +164,7 @@ void forceplayerangle(int snum)
n = 128 - (krand() & 255);
playerAddHoriz(&p->q16horiz, &p->horizAdjust, 64);
p->horizon.addadjustment(64);
p->sync.actions |= SB_CENTERVIEW;
p->setlookang(n >> 1);
p->setrotscrnang(n >> 1);
@ -375,7 +375,7 @@ int aim(spritetype* s, int aang)
if (sdist > 512 && sdist < smax)
{
if (s->picnum == TILE_APLAYER)
a = (abs(scale(sp->z - s->z, 10, sdist) - ps[s->yvel].gethorizsum()) < 100);
a = (abs(scale(sp->z - s->z, 10, sdist) - ps[s->yvel].horizon.sum().asbuild()) < 100);
else a = 1;
cans = cansee(sp->x, sp->y, sp->z - (32 << 8) + actorinfo[sp->picnum].aimoffset, sp->sectnum, s->x, s->y, s->z - (32 << 8), s->sectnum);
@ -406,7 +406,7 @@ void dokneeattack(int snum, int pi, const std::initializer_list<int> & respawnli
if (p->knee_incs > 0)
{
p->knee_incs++;
playerAddHoriz(&p->q16horiz, &p->horizAdjust, -48);
p->horizon.addadjustment(-48);
p->sync.actions |= SB_CENTERVIEW;
if (p->knee_incs > 15)
{
@ -649,8 +649,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
backupplayer(p);
p->sethoriz(0);
p->q16horizoff = 0;
p->horizon.horizoff = p->horizon.horiz = q16horiz(0);
updatesector(p->posx, p->posy, &p->cursectnum);
@ -844,18 +843,6 @@ void backuplook(player_struct* p)
//
//---------------------------------------------------------------------------
void backupview(player_struct* p)
{
p->oq16horiz = p->q16horiz;
p->oq16horizoff = p->q16horizoff;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void backupweapon(player_struct* p)
{
p->oweapon_sway = p->weapon_sway;
@ -873,7 +860,7 @@ void backupweapon(player_struct* p)
void resetinputhelpers(player_struct* p)
{
p->horizAdjust = 0;
p->horizon.resetadjustment();
p->angAdjust = 0;
}
@ -887,7 +874,7 @@ void checkhardlanding(player_struct* p)
{
if (p->hard_landing > 0)
{
playerAddHoriz(&p->q16horiz, &p->horizAdjust, -(p->hard_landing << 4));
p->horizon.addadjustment(-(p->hard_landing << 4));
p->hard_landing--;
}
}

View file

@ -166,7 +166,7 @@ void shoot_d(int i, int atwith)
}
else
{
zvel = -mulscale16(ps[p].getq16horizsum(), 98);
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
sx += sintable[(sa + 860) & 0x7FF] / 448;
sy += sintable[(sa + 348) & 0x7FF] / 448;
sz += (3 << 8);
@ -224,7 +224,7 @@ void shoot_d(int i, int atwith)
}
else
{
zvel = -mulscale16(ps[p].getq16horizsum(), 81);
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81);
if (sprite[ps[p].i].xvel != 0)
vel = (int)((((512 - (1024
- abs(abs(getangle(sx - ps[p].oposx, sy - ps[p].oposy) - sa) - 1024)))
@ -292,7 +292,7 @@ void shoot_d(int i, int atwith)
{
if (p >= 0)
{
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
sz += (6 << 8);
sa += 15;
}
@ -464,14 +464,14 @@ void shoot_d(int i, int atwith)
if (j == -1)
{
// no target
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
}
zvel += (zRange / 2) - (krand() & (zRange - 1));
}
else if (j == -1)
{
sa += 16 - (krand() & 31);
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
zvel += 128 - (krand() & 255);
}
@ -681,7 +681,7 @@ void shoot_d(int i, int atwith)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
else
zvel = -mulscale16(ps[p].getq16horizsum(), 98);
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
}
else
{
@ -769,7 +769,7 @@ void shoot_d(int i, int atwith)
if (sprite[j].picnum != RECON)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
else zvel = -mulscale16(ps[p].getq16horizsum(), 81);
else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81);
if (atwith == RPG)
S_PlayActorSound(RPG_SHOOT, i);
@ -914,7 +914,7 @@ void shoot_d(int i, int atwith)
case HANDHOLDINGLASER:
if (p >= 0)
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
else zvel = 0;
hitscan(sx, sy, sz - ps[p].pyoff, sect,
@ -1015,7 +1015,7 @@ void shoot_d(int i, int atwith)
else
{
sa += 16 - (krand() & 31);
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
zvel += 128 - (krand() & 255);
}
@ -1090,7 +1090,7 @@ void shoot_d(int i, int atwith)
zvel = ((sprite[j].z - sz - dal - (4 << 8)) * 768) / (ldist(&sprite[ps[p].i], &sprite[j]));
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
else zvel = -mulscale16(ps[p].getq16horizsum(), 98);
else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
}
else if (s->statnum != 3)
{
@ -1940,7 +1940,7 @@ int operateTripbomb(int snum)
hitscan(p->posx, p->posy, p->posz,
p->cursectnum, sintable[(p->getang() + 512) & 2047],
sintable[p->getang() & 2047], -p->getq16horizsum() >> 11,
sintable[p->getang() & 2047], -p->horizon.sum().asq16() >> 11,
&sect, &hw, &hitsp, &sx, &sy, &sz, CLIPMASK1);
if (sect < 0 || hitsp >= 0)
@ -2122,12 +2122,12 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
if (p->on_ground && (actions & SB_CROUCH))
{
k = 15;
i = mulscale16(p->getq16horizsum(), 20);
i = mulscale16(p->horizon.sum().asq16(), 20);
}
else
{
k = 140;
i = -512 - mulscale16(p->getq16horizsum(), 20);
i = -512 - mulscale16(p->horizon.sum().asq16(), 20);
}
j = EGS(p->cursectnum,
@ -2707,7 +2707,7 @@ void processinput_d(int snum)
if (cl_syncinput)
{
backupview(p);
p->horizon.backup();
calcviewpitch(p, 1);
}
@ -3072,7 +3072,7 @@ HORIZONLY:
if (cl_syncinput)
{
sethorizon(&p->q16horiz, PlayerHorizon(snum), &p->sync.actions, 1);
sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions, 1);
}
checkhardlanding(p);

View file

@ -154,7 +154,7 @@ void shoot_r(int i, int atwith)
{
if (p >= 0)
{
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
sz += (6 << 8);
sa += 15;
}
@ -333,7 +333,7 @@ void shoot_r(int i, int atwith)
if (j == -1)
{
sa += 16 - (krand() & 31);
zvel = -ps[p].getq16horizsum() >> 11;
zvel = -ps[p].horizon.sum().asq16() >> 11;
zvel += 128 - (krand() & 255);
}
}
@ -343,7 +343,7 @@ void shoot_r(int i, int atwith)
sa += 64 - (krand() & 127);
else
sa += 16 - (krand() & 31);
if (j == -1) zvel = -ps[p].getq16horizsum() >> 11;
if (j == -1) zvel = -ps[p].horizon.sum().asq16() >> 11;
zvel += 128 - (krand() & 255);
}
sz -= (2 << 8);
@ -602,7 +602,7 @@ void shoot_r(int i, int atwith)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
else
zvel = -mulscale16(ps[p].getq16horizsum(), 98);
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
}
else
{
@ -693,7 +693,7 @@ void shoot_r(int i, int atwith)
{
sx += sintable[(s->ang + 512 + 160) & 2047] >> 7;
sy += sintable[(s->ang + 160) & 2047] >> 7;
zvel = -mulscale16(ps[p].getq16horizsum(), 98);
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
}
}
else
@ -804,7 +804,7 @@ void shoot_r(int i, int atwith)
if (sprite[j].picnum != RECON)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
else zvel = -mulscale16(ps[p].getq16horizsum(), 81);
else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81);
if (atwith == RPG)
S_PlayActorSound(RPG_SHOOT, i);
else if (isRRRA())
@ -1476,7 +1476,7 @@ void checkweapons_r(struct player_struct* p)
sprite[j].owner = p->ammo_amount[MOTORCYCLE_WEAPON];
p->OnMotorcycle = 0;
p->gotweapon.Clear(MOTORCYCLE_WEAPON);
p->sethoriz(0);
p->horizon.horiz = q16horiz(0);
p->moto_do_bump = 0;
p->MotoSpeed = 0;
p->TiltStatus = 0;
@ -1492,7 +1492,7 @@ void checkweapons_r(struct player_struct* p)
sprite[j].owner = p->ammo_amount[BOAT_WEAPON];
p->OnBoat = 0;
p->gotweapon.Clear(BOAT_WEAPON);
p->sethoriz(0);
p->horizon.horiz = q16horiz(0);
p->moto_do_bump = 0;
p->MotoSpeed = 0;
p->TiltStatus = 0;
@ -1762,7 +1762,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
}
if (horiz != 0)
{
playerAddHoriz(&p->q16horiz, &p->horizAdjust, horiz - FixedToFloat(p->q16horiz));
p->horizon.addadjustment(horiz - FixedToFloat(p->horizon.horiz.asq16()));
}
if (p->MotoSpeed >= 20 && p->on_ground == 1 && (var74 || var7c))
@ -2091,7 +2091,7 @@ static void onBoat(int snum, ESyncBits &actions)
}
if (horiz != 0)
{
playerAddHoriz(&p->q16horiz, &p->horizAdjust, horiz - FixedToFloat(p->q16horiz));
p->horizon.addadjustment(horiz - FixedToFloat(p->horizon.horiz.asq16()));
}
if (p->MotoSpeed > 0 && p->on_ground == 1 && (varbc || varc4))
@ -2843,12 +2843,12 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
if (p->on_ground && (actions & SB_CROUCH) && !p->OnMotorcycle)
{
k = 15;
i = -mulscale16(p->getq16horizsum(), 20);
i = -mulscale16(p->horizon.sum().asq16(), 20);
}
else
{
k = 140;
i = -512 - -mulscale16(p->getq16horizsum(), 20);
i = -512 - -mulscale16(p->horizon.sum().asq16(), 20);
}
j = EGS(p->cursectnum,
@ -3066,7 +3066,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
case RIFLEGUN_WEAPON:
p->kickback_pic++;
playerAddHoriz(&p->q16horiz, &p->horizAdjust, 1);
p->horizon.addadjustment(1);
p->recoil++;
if (p->kickback_pic <= 12)
@ -3238,7 +3238,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
{
p->posxv -= sintable[(p->getang() + 512) & 2047] << 4;
p->posyv -= sintable[p->getang() & 2047] << 4;
playerAddHoriz(&p->q16horiz, &p->horizAdjust, 20);
p->horizon.addadjustment(20);
p->recoil += 20;
}
if (p->kickback_pic > 20)
@ -3253,12 +3253,12 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
if (p->on_ground && (actions & SB_CROUCH) && !p->OnMotorcycle)
{
k = 15;
i = mulscale16(p->getq16horizsum(), 20);
i = mulscale16(p->horizon.sum().asq16(), 20);
}
else
{
k = 32;
i = -512 - mulscale16(p->getq16horizsum(), 20);
i = -512 - mulscale16(p->horizon.sum().asq16(), 20);
}
j = EGS(p->cursectnum,
@ -3535,7 +3535,7 @@ void processinput_r(int snum)
if (cl_syncinput)
{
backupview(p);
p->horizon.backup();
calcviewpitch(p, 1);
}
@ -4092,12 +4092,12 @@ HORIZONLY:
if (!d)
d = 1;
p->recoil -= d;
playerAddHoriz(&p->q16horiz, &p->horizAdjust, -d);
p->horizon.addadjustment(-d);
}
if (cl_syncinput)
{
sethorizon(&p->q16horiz, PlayerHorizon(snum), &p->sync.actions, 1);
sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions, 1);
}
checkhardlanding(p);
@ -4181,7 +4181,7 @@ void OnMotorcycle(struct player_struct *p, int motosprite)
p->gotweapon.Set(MOTORCYCLE_WEAPON);
p->posxv = 0;
p->posyv = 0;
p->sethoriz(0);
p->horizon.horiz = q16horiz(0);
}
if (!S_CheckActorSoundPlaying(p->i,186))
S_PlayActorSound(186, p->i);
@ -4212,7 +4212,7 @@ void OffMotorcycle(struct player_struct *p)
p->gotweapon.Clear(MOTORCYCLE_WEAPON);
p->curr_weapon = p->last_full_weapon;
checkavailweapon(p);
p->sethoriz(0);
p->horizon.horiz = q16horiz(0);
p->moto_do_bump = 0;
p->MotoSpeed = 0;
p->TiltStatus = 0;
@ -4258,7 +4258,7 @@ void OnBoat(struct player_struct *p, int boatsprite)
p->gotweapon.Set(BOAT_WEAPON);
p->posxv = 0;
p->posyv = 0;
p->sethoriz(0);
p->horizon.horiz = q16horiz(0);
}
}
@ -4277,7 +4277,7 @@ void OffBoat(struct player_struct *p)
p->gotweapon.Clear(BOAT_WEAPON);
p->curr_weapon = p->last_full_weapon;
checkavailweapon(p);
p->sethoriz(0);
p->horizon.horiz = q16horiz(0);
p->moto_do_bump = 0;
p->MotoSpeed = 0;
p->TiltStatus = 0;

View file

@ -333,12 +333,12 @@ void operateweapon_ww(int snum, ESyncBits actions, int psect)
if (p->on_ground && (actions & SB_CROUCH))
{
k = 15;
i = mulscale16(p->getq16horizsum(), 20);
i = mulscale16(p->horizon.sum().asq16(), 20);
}
else
{
k = 140;
i = -512 - mulscale16(p->getq16horizsum(), 20);
i = -512 - mulscale16(p->horizon.sum().asq16(), 20);
}
j = EGS(p->cursectnum,

View file

@ -55,8 +55,8 @@ void resetmys()
myz = omyz = ps[myconnectindex].posz;
myxvel = myyvel = myzvel = 0;
q16myang = oq16myang = ps[myconnectindex].q16ang;
q16myhoriz = oq16myhoriz = ps[myconnectindex].q16horiz;
q16myhorizoff = oq16myhorizoff = ps[myconnectindex].q16horizoff;
q16myhoriz = oq16myhoriz = ps[myconnectindex].horizon.horiz.asq16();
q16myhorizoff = oq16myhorizoff = ps[myconnectindex].horizon.horizoff.asq16();
mycursectnum = ps[myconnectindex].cursectnum;
myjumpingcounter = ps[myconnectindex].jumping_counter;
myjumpingtoggle = ps[myconnectindex].jumping_toggle;

View file

@ -112,10 +112,8 @@ void resetplayerstats(int snum)
p->footprintpal = 0;
p->footprintshade = 0;
p->jumping_toggle = 0;
p->sethoriz(40); //!!
p->oq16horiz = p->q16horiz;
p->sethorizoff(0);
p->oq16horizoff = p->q16horizoff;
p->horizon.ohoriz = p->horizon.horiz = q16horiz(40);
p->horizon.ohorizoff = p->horizon.horizoff = q16horiz(0);
p->bobcounter = 0;
p->on_ground = 0;
p->player_par = 0;

View file

@ -574,9 +574,7 @@ void displayrooms(int snum, double smoothratio)
if (cl_syncinput)
{
// Original code for when the values are passed through the sync struct
fixed_t ohorz = (p->oq16horiz + p->oq16horizoff);
fixed_t horz = (p->q16horiz + p->q16horizoff);
choriz = q16horiz(ohorz + xs_CRoundToInt(fmulscale16(horz - ohorz, smoothratio)));
choriz = p->horizon.interpolatedsum(smoothratio);
fixed_t oang = (p->oq16ang + p->oq16look_ang);
fixed_t ang = (p->q16ang + p->q16look_ang);
@ -586,7 +584,7 @@ void displayrooms(int snum, double smoothratio)
{
// This is for real time updating of the view direction.
cang = q16ang(p->q16ang + p->q16look_ang);
choriz = q16horiz(p->q16horiz + p->q16horizoff);
choriz = p->horizon.sum();
}
}

View file

@ -114,8 +114,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w,
("posy", w.posy)
("posz", w.posz)
("q16ang", w.q16ang)
("q16horiz", w.q16horiz)
("q16horizoff", w.q16horizoff)
//("q16horiz", w.horizon.horiz.asq16())
//("q16horizoff", w.horizon.horizoff.asq16())
("q16rotscrnang", w.q16rotscrnang)
("q16look_ang", w.q16look_ang)
("one_eighty_count", w.one_eighty_count)
@ -285,8 +285,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w,
w.invdisptime = 0;
w.oq16ang = w.q16ang;
w.oq16horiz = w.q16horiz;
w.oq16horizoff = w.q16horizoff;
//w.horizon.ohoriz = w.horizon.horiz;
//w.horizon.ohorizoff = w.horizon.horizoff;
w.oq16rotscrnang = w.q16rotscrnang;
w.oposx = w.posx;
w.oposy = w.posy;
@ -297,8 +297,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w,
w.okickback_pic = w.kickback_pic;
w.orandom_club_frame = w.random_club_frame;
w.ohard_landing = w.hard_landing;
w.horizAdjust = 0;
w.angAdjust = 0;
w.sync.actions &= SB_CENTERVIEW; // this is the only bit we need to preserve.
}
return arc;

View file

@ -438,7 +438,7 @@ void initshell(int j, int i, bool isshell)
a = ps[snum].getang() - (krand() & 63) + 8; //Fine tune
t[0] = krand() & 1;
sp->z = (3 << 8) + ps[snum].pyoff + ps[snum].posz - (ps[snum].getq16horizsum() >> 12) + (!isshell ? (3 << 8) : 0);
sp->z = (3 << 8) + ps[snum].pyoff + ps[snum].posz - (ps[snum].horizon.sum().asq16() >> 12) + (!isshell ? (3 << 8) : 0);
sp->zvel = -(krand() & 255);
}
else

View file

@ -95,11 +95,14 @@ struct player_struct
struct { int32_t posx, posy, posz; };
};
// input handles angle and horizon as fixed16 numbers. We need to account for that as well.
fixed_t q16ang, q16horiz, q16horizoff, q16rotscrnang, q16look_ang;
fixed_t oq16ang, oq16horiz, oq16horizoff, oq16rotscrnang, oq16look_ang; // These are only needed with synchronous mouse input.
// input handles angle as fixed16 numbers. We need to account for that as well.
fixed_t q16ang, q16rotscrnang, q16look_ang;
fixed_t oq16ang, oq16rotscrnang, oq16look_ang; // These are only needed with synchronous mouse input.
fixed_t one_eighty_count;
// player's horison struct.
PlayerHorizon horizon;
// using a bit field for this to save a bit of space.
FixedBitArray<MAX_WEAPONS> gotweapon;
@ -207,12 +210,12 @@ struct player_struct
int8_t crouch_toggle;
// input stuff.
double horizAdjust, angAdjust;
fixed_t horizTarget, angTarget;
double angAdjust;
fixed_t angTarget;
InputPacket sync;
// Access helpers for the widened angle and horizon fields.
// Access helpers for the widened angle fields.
void setlookang(int b) { q16look_ang = IntToFixed(b); }
void addlookang(int b) { q16look_ang += IntToFixed(b); }
void addlookang(double b) { q16look_ang += FloatToFixed(b); }
@ -224,17 +227,6 @@ struct player_struct
void setang(int v) { q16ang = IntToFixed(v); }
void addang(int v) { q16ang = (q16ang + IntToFixed(v)) & 0x7FFFFFF; }
void setoang(int v) { oq16ang = IntToFixed(v); }
void addhoriz(int v) { q16horiz += (IntToFixed(v)); }
void addhorizoff(int v) { q16horiz += (IntToFixed(v)); }
void addhorizoff(double v) { q16horiz += FloatToFixed(v); }
void sethoriz(int v) { q16horiz = IntToFixed(v); }
void sethorizoff(int v) { q16horizoff = IntToFixed(v); }
int gethoriz() { return FixedToInt(q16horiz); }
int gethorizof() { return FixedToInt(q16horizoff); }
int gethorizsum() { return FixedToInt(q16horiz + q16horizoff); }
int getq16horiz() { return q16horiz; }
int getq16horizof() { return q16horizoff; }
int getq16horizsum() { return q16horiz + q16horizoff; }
};

View file

@ -1741,7 +1741,7 @@ DoPlayerHorizon(PLAYERp pp, fixed_t const q16horz, double const scaleAdjust)
PlayerAutoLook(pp, scaleAdjust);
// apply default horizon from backend
sethorizon(&pp->q16horiz, q16horz, &pp->input.actions, scaleAdjust);
sethorizon2(&pp->q16horiz, q16horz, &pp->input.actions, scaleAdjust);
}
void
@ -6140,12 +6140,12 @@ DoPlayerDeathHoriz(PLAYERp pp, short target, short speed)
{
if ((pp->q16horiz - IntToFixed(target)) > FRACUNIT)
{
playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, -speed);
playerAddHoriz2(&pp->q16horiz, &pp->horizAdjust, -speed);
}
if ((IntToFixed(target) - pp->q16horiz) > FRACUNIT)
{
playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, speed);
playerAddHoriz2(&pp->q16horiz, &pp->horizAdjust, speed);
}
}