- use access functions for reading _vect.

This commit is contained in:
Christoph Oelckers 2022-10-13 00:04:47 +02:00
parent 7f3c5ae18d
commit 4547372d4d
7 changed files with 71 additions and 63 deletions

View file

@ -584,6 +584,10 @@ struct REMOTE_CONTROL
vec2_t _vect, _ovect, _slide_vect;
DVector3 pos;
SECTOR_OBJECT* sop_control;
vec2_t int_vect() const { return _vect; }
vec2_t int_ovect() const { return _ovect; }
vec2_t int_slide_vect() const { return _slide_vect; }
};
struct PLAYER
@ -630,6 +634,10 @@ struct PLAYER
DAngle siang;
vec2_t _vect, _ovect, _slide_vect; // these need floatification, but must be done together. vect is in 14.18 format!
vec2_t int_vect() const { return _vect; }
vec2_t int_ovect() const { return _ovect; }
vec2_t int_slide_vect() const { return _slide_vect; }
int friction;
int16_t slide_ang; // todo: floatify
int slide_dec;
@ -2240,7 +2248,7 @@ inline bool SpriteInUnderwaterArea(DSWActor* a)
// just determine if the player is moving
inline bool PLAYER_MOVING(PLAYER* pp)
{
return (pp->_vect.X | pp->_vect.Y);
return (pp->int_vect().X | pp->int_vect().Y);
}
inline void PlaySound(int num, DSWActor* actor, int flags, int channel = 8, EChanFlags sndflags = CHANF_NONE)

View file

@ -1303,8 +1303,8 @@ int PlayerInitChemBomb(PLAYER* pp)
UpdateChange(actorNew, 0.5);
// adjust xvel according to player velocity
actorNew->user.change.X += FixedToFloat<18>(pp->_vect.X);
actorNew->user.change.Y += FixedToFloat<18>(pp->_vect.Y);
actorNew->user.change.X += FixedToFloat<18>(pp->int_vect().X);
actorNew->user.change.Y += FixedToFloat<18>(pp->int_vect().Y);
// Smoke will come out for this many seconds
actorNew->user.WaitTics = CHEMTICS;
@ -1659,8 +1659,8 @@ int PlayerInitCaltrops(PLAYER* pp)
UpdateChange(actorNew, 0.5);
// adjust xvel according to player velocity
actorNew->user.change.X += FixedToFloat<18>(pp->_vect.X);
actorNew->user.change.Y += FixedToFloat<18>(pp->_vect.Y);
actorNew->user.change.X += FixedToFloat<18>(pp->int_vect().X);
actorNew->user.change.Y += FixedToFloat<18>(pp->int_vect().Y);
SetupSpriteForBreak(actorNew); // Put Caltrops in the break queue
return 0;

View file

@ -98,7 +98,7 @@ Collision MultiClipMove(PLAYER* pp, double zz, double floordist)
pos[i].Z = zz;
// move the box
clipmove(pos[i], &pp->cursector, pp->_vect.X, pp->_vect.Y, (int)sop->clipbox_dist[i], Z(4), int(floordist * zworldtoint), CLIPMASK_PLAYER, coll);
clipmove(pos[i], &pp->cursector, pp->int_vect().X, pp->int_vect().Y, (int)sop->clipbox_dist[i], Z(4), int(floordist * zworldtoint), CLIPMASK_PLAYER, coll);
// save the dist moved
dist = (pos[i].XY() - opos[i].XY()).Length();
@ -205,7 +205,7 @@ int RectClipMove(PLAYER* pp, DVector2* qpos)
int i;
DVector2 xy[4];
int point_num;
DVector2 pvect((pp->_vect.X >> 14) * inttoworld, (pp->_vect.Y >> 14) * inttoworld);
DVector2 pvect((pp->int_vect().X >> 14) * inttoworld, (pp->int_vect().Y >> 14) * inttoworld);
for (i = 0; i < 4; i++)
{

View file

@ -6307,7 +6307,7 @@ void pWeaponBob(PANEL_SPRITE* psp, short condition)
{
double xdiff = 0, ydiff = 0;
double bobvel = fFindDistance2D(psp->PlayerP->_vect.X, psp->PlayerP->_vect.Y) * (1. / 32768.);
double bobvel = fFindDistance2D(psp->PlayerP->int_vect().X, psp->PlayerP->int_vect().Y) * (1. / 32768.);
bobvel = bobvel + (bobvel * (1. / 4.));
bobvel = min(bobvel, 128.);

View file

@ -1561,8 +1561,8 @@ void SlipSlope(PLAYER* pp)
ang = NORM_ANGLE(ang + 512);
pp->_vect.X += MulScale(bcos(ang), pp->cursector->floorheinum, sectu->speed);
pp->_vect.Y += MulScale(bsin(ang), pp->cursector->floorheinum, sectu->speed);
pp->_vect .X += MulScale(bcos(ang), pp->cursector->floorheinum, sectu->speed);
pp->_vect .Y += MulScale(bsin(ang), pp->cursector->floorheinum, sectu->speed);
}
void DoPlayerHorizon(PLAYER* pp, float const horz, double const scaleAdjust)
@ -1959,8 +1959,8 @@ void DoPlayerMove(PLAYER* pp)
DoPlayerSlide(pp);
pp->_ovect.X = pp->_vect.X;
pp->_ovect.Y = pp->_vect.Y;
pp->_ovect.X = pp->int_vect().X;
pp->_ovect.Y = pp->int_vect().Y;
pp->_vect.X += ((pp->input.fvel*synctics*2)<<6);
pp->_vect.Y += ((pp->input.svel*synctics*2)<<6);
@ -1971,26 +1971,26 @@ void DoPlayerMove(PLAYER* pp)
friction -= pp->WadeDepth * 100;
}
pp->_vect.X = MulScale(pp->_vect.X, friction, 16);
pp->_vect.Y = MulScale(pp->_vect.Y, friction, 16);
pp->_vect.X = MulScale(pp->int_vect().X, friction, 16);
pp->_vect.Y = MulScale(pp->int_vect().Y, friction, 16);
if (pp->Flags & (PF_FLYING))
{
// do a bit of weighted averaging
pp->_vect.X = (pp->_vect.X + (pp->_ovect.X*1))/2;
pp->_vect.Y = (pp->_vect.Y + (pp->_ovect.Y*1))/2;
pp->_vect .X = (pp->int_vect().X + (pp->_ovect.X*1))/2;
pp->_vect .Y = (pp->int_vect().Y + (pp->_ovect.Y*1))/2;
}
else if (pp->Flags & (PF_DIVING))
{
// do a bit of weighted averaging
pp->_vect.X = (pp->_vect.X + (pp->_ovect.X*2))/3;
pp->_vect.Y = (pp->_vect.Y + (pp->_ovect.Y*2))/3;
pp->_vect .X = (pp->int_vect().X + (pp->_ovect.X*2))/3;
pp->_vect .Y = (pp->int_vect().Y + (pp->_ovect.Y*2))/3;
}
if (abs(pp->_vect.X) < 12800 && abs(pp->_vect.Y) < 12800)
pp->_vect.X = pp->_vect.Y = 0;
if (abs(pp->int_vect().X) < 12800 && abs(pp->int_vect().Y) < 12800)
pp->_vect .X = pp->_vect .Y = 0;
actor->set_int_xvel(FindDistance2D(pp->_vect.X,pp->_vect.Y)>>14);
actor->set_int_xvel(FindDistance2D(pp->int_vect().X,pp->int_vect().Y)>>14);
if (pp->Flags & (PF_CLIP_CHEAT))
{
@ -1999,7 +1999,7 @@ void DoPlayerMove(PLAYER* pp)
{
pp->opos.XY() = pp->pos.XY();
}
pp->add_int_ppos_XY({ pp->_vect.X >> 14, pp->_vect.Y >> 14 });
pp->add_int_ppos_XY({ pp->int_vect().X >> 14, pp->int_vect().Y >> 14 });
updatesector(pp->pos, &sect);
if (sect != nullptr)
pp->cursector = sect;
@ -2029,7 +2029,7 @@ void DoPlayerMove(PLAYER* pp)
actor->spr.cstat &= ~(CSTAT_SPRITE_BLOCK);
Collision coll;
updatesector(pp->int_ppos().X, pp->int_ppos().Y, &pp->cursector);
clipmove(pp->pos, &pp->cursector, pp->_vect.X, pp->_vect.Y, ((int)actor->spr.clipdist<<2), pp->p_ceiling_dist, pp->p_floor_dist, CLIPMASK_PLAYER, coll);
clipmove(pp->pos, &pp->cursector, pp->int_vect().X, pp->int_vect().Y, ((int)actor->spr.clipdist<<2), pp->p_ceiling_dist, pp->p_floor_dist, CLIPMASK_PLAYER, coll);
actor->spr.cstat = save_cstat;
PlayerCheckValidMove(pp);
@ -2200,8 +2200,8 @@ void DoTankTreads(PLAYER* pp)
if (Prediction)
return;
vel = FindDistance2D(pp->_vect.X>>8, pp->_vect.Y>>8);
dot = DOT_PRODUCT_2D(pp->_vect.X, pp->_vect.Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
vel = FindDistance2D(pp->int_vect().X>>8, pp->int_vect().Y>>8);
dot = DOT_PRODUCT_2D(pp->int_vect().X, pp->int_vect().Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
if (dot < 0)
reverse = true;
@ -2310,7 +2310,7 @@ void DriveCrush(PLAYER* pp, DVector2* quad)
return;
// not moving - don't crush
if ((pp->_vect.X|pp->_vect.Y) == 0 && pp->input.avel == 0)
if ((pp->int_vect().X|pp->int_vect().Y) == 0 && pp->input.avel == 0)
return;
// main sector
@ -2358,10 +2358,10 @@ void DriveCrush(PLAYER* pp, DVector2* quad)
if (actor->int_pos().Z < sop->crush_z)
continue;
int32_t const vel = FindDistance2D(pp->_vect.X>>8, pp->_vect.Y>>8);
int32_t const vel = FindDistance2D(pp->int_vect().X>>8, pp->int_vect().Y>>8);
if (vel < 9000)
{
DoActorBeginSlide(actor, VecToAngle(pp->_vect.X, pp->_vect.Y), vel/8 * inttoworld);
DoActorBeginSlide(actor, VecToAngle(pp->int_vect().X, pp->int_vect().Y), vel/8 * inttoworld);
if (DoActorSlide(actor))
continue;
}
@ -2478,32 +2478,32 @@ void DoPlayerMoveVehicle(PLAYER* pp)
else
pp->Flags |= (PF_PLAYER_MOVED);
pp->_ovect.X = pp->_vect.X;
pp->_ovect.Y = pp->_vect.Y;
pp->_ovect.X = pp->int_vect().X;
pp->_ovect.Y = pp->int_vect().Y;
if (sop->drive_speed)
{
pp->_vect.X = MulScale(pp->input.fvel, sop->drive_speed, 6);
pp->_vect.Y = MulScale(pp->input.svel, sop->drive_speed, 6);
pp->_vect .X = MulScale(pp->input.fvel, sop->drive_speed, 6);
pp->_vect .Y = MulScale(pp->input.svel, sop->drive_speed, 6);
// does sliding/momentum
pp->_vect.X = (pp->_vect.X + (pp->_ovect.X*(sop->drive_slide-1)))/sop->drive_slide;
pp->_vect.Y = (pp->_vect.Y + (pp->_ovect.Y*(sop->drive_slide-1)))/sop->drive_slide;
pp->_vect .X = (pp->int_vect().X + (pp->_ovect.X*(sop->drive_slide-1)))/sop->drive_slide;
pp->_vect .Y = (pp->int_vect().Y + (pp->_ovect.Y*(sop->drive_slide-1)))/sop->drive_slide;
}
else
{
pp->_vect.X += ((pp->input.fvel*synctics*2)<<6);
pp->_vect.Y += ((pp->input.svel*synctics*2)<<6);
pp->_vect.X = MulScale(pp->_vect.X, TANK_FRICTION, 16);
pp->_vect.Y = MulScale(pp->_vect.Y, TANK_FRICTION, 16);
pp->_vect.X = MulScale(pp->int_vect().X, TANK_FRICTION, 16);
pp->_vect.Y = MulScale(pp->int_vect().Y, TANK_FRICTION, 16);
pp->_vect.X = (pp->_vect.X + (pp->_ovect.X*1))/2;
pp->_vect.Y = (pp->_vect.Y + (pp->_ovect.Y*1))/2;
pp->_vect .X = (pp->int_vect().X + (pp->_ovect.X*1))/2;
pp->_vect .Y = (pp->int_vect().Y + (pp->_ovect.Y*1))/2;
}
if (abs(pp->_vect.X) < 12800 && abs(pp->_vect.Y) < 12800)
pp->_vect.X = pp->_vect.Y = 0;
if (abs(pp->int_vect().X) < 12800 && abs(pp->int_vect().Y) < 12800)
pp->_vect .X = pp->_vect .Y = 0;
pp->lastcursector = pp->cursector;
z = pp->int_ppos().Z + Z(10);
@ -2553,7 +2553,7 @@ void DoPlayerMoveVehicle(PLAYER* pp)
if (!ret)
{
vel = FindDistance2D(pp->_vect.X>>8, pp->_vect.Y>>8);
vel = FindDistance2D(pp->int_vect().X>>8, pp->int_vect().Y>>8);
if (vel > 13000)
{
@ -2583,7 +2583,7 @@ void DoPlayerMoveVehicle(PLAYER* pp)
if (vel > 12000)
{
pp->_vect.X = pp->_vect.Y = pp->_ovect.X = pp->_ovect.Y = 0;
pp->_vect .X = pp->_vect .Y = pp->_ovect.X = pp->_ovect.Y = 0;
}
}
}
@ -2603,7 +2603,7 @@ void DoPlayerMoveVehicle(PLAYER* pp)
if (pp->sop->clipdist)
{
Collision coll;
clipmove(pp->pos, &pp->cursector, pp->_vect.X, pp->_vect.Y, (int)pp->sop->clipdist, Z(4), floor_dist, CLIPMASK_PLAYER, actor->user.coll);
clipmove(pp->pos, &pp->cursector, pp->int_vect().X, pp->int_vect().Y, (int)pp->sop->clipdist, Z(4), floor_dist, CLIPMASK_PLAYER, actor->user.coll);
}
else
{
@ -2615,20 +2615,20 @@ void DoPlayerMoveVehicle(PLAYER* pp)
{
int vel;
vel = FindDistance2D(pp->_vect.X>>8, pp->_vect.Y>>8);
vel = FindDistance2D(pp->int_vect().X>>8, pp->int_vect().Y>>8);
if (vel > 13000)
{
VehicleMoveHit(actor);
pp->_slide_vect.X = -pp->_vect.X<<1;
pp->_slide_vect.Y = -pp->_vect.Y<<1;
pp->_slide_vect.X = -pp->int_vect().X<<1;
pp->_slide_vect.Y = -pp->int_vect().Y<<1;
if (!(sop->flags & SOBJ_NO_QUAKE))
SetPlayerQuake(pp);
}
if (vel > 12000)
{
pp->_vect.X = pp->_vect.Y = pp->_ovect.X = pp->_ovect.Y = 0;
pp->_vect .X = pp->_vect .Y = pp->_ovect.X = pp->_ovect.Y = 0;
}
}
}
@ -3089,13 +3089,13 @@ void DoPlayerClimb(PLAYER* pp)
pp->_vect.X += ((pp->input.fvel*synctics*2)<<6);
pp->_vect.Y += ((pp->input.svel*synctics*2)<<6);
pp->_vect.X = MulScale(pp->_vect.X, PLAYER_CLIMB_FRICTION, 16);
pp->_vect.Y = MulScale(pp->_vect.Y, PLAYER_CLIMB_FRICTION, 16);
if (abs(pp->_vect.X) < 12800 && abs(pp->_vect.Y) < 12800)
pp->_vect.X = pp->_vect.Y = 0;
pp->_vect.X = MulScale(pp->int_vect().X, PLAYER_CLIMB_FRICTION, 16);
pp->_vect.Y = MulScale(pp->int_vect().Y, PLAYER_CLIMB_FRICTION, 16);
if (abs(pp->int_vect().X) < 12800 && abs(pp->int_vect().Y) < 12800)
pp->_vect .X = pp->_vect .Y = 0;
climbVel = DVector2(pp->_vect.X, pp->_vect.Y).Length() * (1. / 512) * zinttoworld;
dot = DOT_PRODUCT_2D(pp->_vect.X, pp->_vect.Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
climbVel = DVector2(pp->int_vect().X, pp->int_vect().Y).Length() * (1. / 512) * zinttoworld;
dot = DOT_PRODUCT_2D(pp->int_vect().X, pp->int_vect().Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
if (dot < 0)
climbVel = -climbVel;
@ -3588,7 +3588,7 @@ bool PlayerOnLadder(PLAYER* pp)
neartag(pp->int_ppos(), pp->cursector, pp->angle.ang.Buildang(), near, 1024 + 768, NTAG_SEARCH_LO_HI);
dir = DOT_PRODUCT_2D(pp->_vect.X, pp->_vect.Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
dir = DOT_PRODUCT_2D(pp->int_vect().X, pp->int_vect().Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
if (dir < 0)
return false;

View file

@ -406,8 +406,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, REMOTE_CONTROL& w,
}
if (arc.isReading())
{
w._ovect.Y = w._vect.X;
w._ovect.Y = w._vect.Y;
w._ovect.Y = w.int_vect().X;
w._ovect.Y = w.int_vect().Y;
}
return arc;
}
@ -576,8 +576,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER*
if (arc.isReading())
{
w.opos = w.pos;
w._ovect.X = w._vect.X;
w._ovect.Y = w._vect.Y;
w._ovect.X = w.int_vect().X;
w._ovect.Y = w.int_vect().Y;
w.obob_z = w.bob_z;
w.input = {};
w.lastinput = {};

View file

@ -15877,8 +15877,8 @@ int InitGrenade(PLAYER* pp)
if (!auto_aim)
{
// adjust xvel according to player velocity
actorNew->user.change.X += FixedToFloat<18>(pp->_vect.X);
actorNew->user.change.Y += FixedToFloat<18>(pp->_vect.Y);
actorNew->user.change.X += FixedToFloat<18>(pp->int_vect().X);
actorNew->user.change.Y += FixedToFloat<18>(pp->int_vect().Y);
}
actorNew->user.Counter2 = true; // Phosphorus Grenade
@ -15974,14 +15974,14 @@ int InitMine(PLAYER* pp)
UpdateChange(actorNew, 0.5);
dot = DOT_PRODUCT_2D(pp->_vect.X, pp->_vect.Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
dot = DOT_PRODUCT_2D(pp->int_vect().X, pp->int_vect().Y, pp->angle.ang.Cos() * (1 << 14), pp->angle.ang.Sin() * (1 << 14));
// don't adjust for strafing
if (abs(dot) > 10000)
{
// adjust xvel according to player velocity
actorNew->user.change.X += FixedToFloat<18>(2 * pp->_vect.X);
actorNew->user.change.Y += FixedToFloat<18>(2 * pp->_vect.Y);
actorNew->user.change.X += FixedToFloat<18>(2 * pp->int_vect().X);
actorNew->user.change.Y += FixedToFloat<18>(2 * pp->int_vect().Y);
}
return 0;