- more refactoring of AActor coordinate access.

This commit is contained in:
Christoph Oelckers 2016-01-17 18:36:14 +01:00
parent 5b610390e1
commit c611456397
9 changed files with 105 additions and 51 deletions

View file

@ -951,6 +951,23 @@ public:
return ret; return ret;
} }
fixedvec2 Vec2Offset(fixed_t dx, fixed_t dy) const
{
fixedvec2 ret = { x + dx, y + dy };
return ret;
}
fixedvec3 Vec3Offset(fixed_t dx, fixed_t dy, fixed_t dz) const
{
fixedvec3 ret = { x + dx, y + dy, z + dz };
return ret;
}
void Move(fixed_t dx, fixed_t dy, fixed_t dz)
{
SetOrigin(x + dx, y + dy, z + dz, true);
}
inline void SetFriendPlayer(player_t *player); inline void SetFriendPlayer(player_t *player);
bool IsVisibleToPlayer() const; bool IsVisibleToPlayer() const;
@ -1168,7 +1185,7 @@ public:
void LinkToWorld (sector_t *sector); void LinkToWorld (sector_t *sector);
void UnlinkFromWorld (); void UnlinkFromWorld ();
void AdjustFloorClip (); void AdjustFloorClip ();
void SetOrigin (fixed_t x, fixed_t y, fixed_t z); void SetOrigin (fixed_t x, fixed_t y, fixed_t z, bool moving = false);
bool InStateSequence(FState * newstate, FState * basestate); bool InStateSequence(FState * newstate, FState * basestate);
int GetTics(FState * newstate); int GetTics(FState * newstate);
bool SetState (FState *newstate, bool nofunction=false); bool SetState (FState *newstate, bool nofunction=false);
@ -1210,6 +1227,10 @@ public:
{ {
return z; return z;
} }
void SetZ(fixed_t newz)
{
z = newz;
}
}; };
@ -1284,15 +1305,36 @@ inline AActor *Spawn (const PClass *type, fixed_t x, fixed_t y, fixed_t z, repla
return AActor::StaticSpawn (type, x, y, z, allowreplacement); return AActor::StaticSpawn (type, x, y, z, allowreplacement);
} }
inline AActor *Spawn (const PClass *type, const fixedvec3 &pos, replace_t allowreplacement)
{
return AActor::StaticSpawn (type, pos.x, pos.y, pos.z, allowreplacement);
}
AActor *Spawn (const char *type, fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement); AActor *Spawn (const char *type, fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement);
AActor *Spawn (FName classname, fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement); AActor *Spawn (FName classname, fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement);
inline AActor *Spawn (const char *type, const fixedvec3 &pos, replace_t allowreplacement)
{
return Spawn (type, pos.x, pos.y, pos.z, allowreplacement);
}
inline AActor *Spawn (FName classname, const fixedvec3 &pos, replace_t allowreplacement)
{
return Spawn (classname, pos.x, pos.y, pos.z, allowreplacement);
}
template<class T> template<class T>
inline T *Spawn (fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement) inline T *Spawn (fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement)
{ {
return static_cast<T *>(AActor::StaticSpawn (RUNTIME_CLASS(T), x, y, z, allowreplacement)); return static_cast<T *>(AActor::StaticSpawn (RUNTIME_CLASS(T), x, y, z, allowreplacement));
} }
template<class T>
inline T *Spawn (const fixedvec3 &pos, replace_t allowreplacement)
{
return static_cast<T *>(AActor::StaticSpawn (RUNTIME_CLASS(T), pos.x, pos.y, pos.z, allowreplacement));
}
void PrintMiscActorInfo(AActor * query); void PrintMiscActorInfo(AActor * query);

View file

@ -427,7 +427,7 @@ void FCajunMaster::SetBodyAt (fixed_t x, fixed_t y, fixed_t z, int hostnum)
{ {
if (body1) if (body1)
{ {
body1->SetOrigin (x, y, z); body1->SetOrigin (x, y, z, false);
} }
else else
{ {
@ -438,7 +438,7 @@ void FCajunMaster::SetBodyAt (fixed_t x, fixed_t y, fixed_t z, int hostnum)
{ {
if (body2) if (body2)
{ {
body2->SetOrigin (x, y, z); body2->SetOrigin (x, y, z, false);
} }
else else
{ {
@ -465,10 +465,7 @@ fixed_t FCajunMaster::FakeFire (AActor *source, AActor *dest, ticcmd_t *cmd)
float speed = (float)th->Speed; float speed = (float)th->Speed;
FVector3 velocity; TVector3<double> velocity = source->Vec3To(dest);
velocity[0] = FIXED2FLOAT(dest->x - source->x);
velocity[1] = FIXED2FLOAT(dest->y - source->y);
velocity[2] = FIXED2FLOAT(dest->z - source->z);
velocity.MakeUnit(); velocity.MakeUnit();
th->velx = FLOAT2FIXED(velocity[0] * speed); th->velx = FLOAT2FIXED(velocity[0] * speed);
th->vely = FLOAT2FIXED(velocity[1] * speed); th->vely = FLOAT2FIXED(velocity[1] * speed);
@ -479,8 +476,8 @@ fixed_t FCajunMaster::FakeFire (AActor *source, AActor *dest, ticcmd_t *cmd)
while (dist < SAFE_SELF_MISDIST) while (dist < SAFE_SELF_MISDIST)
{ {
dist += th->Speed; dist += th->Speed;
th->SetOrigin (th->x + th->velx, th->y + th->vely, th->z + th->velz); th->Move(th->velx, th->vely, th->velz);
if (!CleanAhead (th, th->x, th->y, cmd)) if (!CleanAhead (th, th->X(), th->Y(), cmd))
break; break;
} }
th->Destroy (); th->Destroy ();

View file

@ -124,9 +124,6 @@ bool DBot::TryWalk (ticcmd_t *cmd)
void DBot::NewChaseDir (ticcmd_t *cmd) void DBot::NewChaseDir (ticcmd_t *cmd)
{ {
fixed_t deltax;
fixed_t deltay;
dirtype_t d[3]; dirtype_t d[3];
int tdir; int tdir;
@ -145,19 +142,18 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
olddir = (dirtype_t)player->mo->movedir; olddir = (dirtype_t)player->mo->movedir;
turnaround = opposite[olddir]; turnaround = opposite[olddir];
deltax = dest->x - player->mo->x; fixedvec2 delta = player->mo->Vec2To(dest);
deltay = dest->y - player->mo->y;
if (deltax > 10*FRACUNIT) if (delta.x > 10*FRACUNIT)
d[1] = DI_EAST; d[1] = DI_EAST;
else if (deltax < -10*FRACUNIT) else if (delta.x < -10*FRACUNIT)
d[1] = DI_WEST; d[1] = DI_WEST;
else else
d[1] = DI_NODIR; d[1] = DI_NODIR;
if (deltay < -10*FRACUNIT) if (delta.y < -10*FRACUNIT)
d[2] = DI_SOUTH; d[2] = DI_SOUTH;
else if (deltay > 10*FRACUNIT) else if (delta.y > 10*FRACUNIT)
d[2] = DI_NORTH; d[2] = DI_NORTH;
else else
d[2] = DI_NODIR; d[2] = DI_NODIR;
@ -165,14 +161,14 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
// try direct route // try direct route
if (d[1] != DI_NODIR && d[2] != DI_NODIR) if (d[1] != DI_NODIR && d[2] != DI_NODIR)
{ {
player->mo->movedir = diags[((deltay<0)<<1)+(deltax>0)]; player->mo->movedir = diags[((delta.y<0)<<1)+(delta.x>0)];
if (player->mo->movedir != turnaround && TryWalk(cmd)) if (player->mo->movedir != turnaround && TryWalk(cmd))
return; return;
} }
// try other directions // try other directions
if (pr_botnewchasedir() > 200 if (pr_botnewchasedir() > 200
|| abs(deltay)>abs(deltax)) || abs(delta.y)>abs(delta.x))
{ {
tdir=d[1]; tdir=d[1];
d[1]=d[2]; d[1]=d[2];

View file

@ -2319,10 +2319,12 @@ void Net_DoCommand (int type, BYTE **stream, int player)
else else
{ {
const AActor *def = GetDefaultByType (typeinfo); const AActor *def = GetDefaultByType (typeinfo);
AActor *spawned = Spawn (typeinfo, fixedvec3 spawnpos = source->Vec3Offset(
source->x + FixedMul (def->radius * 2 + source->radius, finecosine[source->angle>>ANGLETOFINESHIFT]), FixedMul (def->radius * 2 + source->radius, finecosine[source->angle>>ANGLETOFINESHIFT]),
source->y + FixedMul (def->radius * 2 + source->radius, finesine[source->angle>>ANGLETOFINESHIFT]), FixedMul (def->radius * 2 + source->radius, finesine[source->angle>>ANGLETOFINESHIFT]),
source->z + 8 * FRACUNIT, ALLOW_REPLACE); 8 * FRACUNIT);
AActor *spawned = Spawn (typeinfo, spawnpos, ALLOW_REPLACE);
if (spawned != NULL) if (spawned != NULL)
{ {
if (type == DEM_SUMMONFRIEND || type == DEM_SUMMONFRIEND2 || type == DEM_SUMMONMBF) if (type == DEM_SUMMONFRIEND || type == DEM_SUMMONFRIEND2 || type == DEM_SUMMONMBF)

View file

@ -1441,7 +1441,7 @@ bool G_CheckSpot (int playernum, FPlayerStart *mthing)
} }
oldz = players[playernum].mo->Z(); // [RH] Need to save corpse's z-height oldz = players[playernum].mo->Z(); // [RH] Need to save corpse's z-height
players[playernum].mo->z = z; // [RH] Checks are now full 3-D players[playernum].mo->SetZ(z); // [RH] Checks are now full 3-D
// killough 4/2/98: fix bug where P_CheckPosition() uses a non-solid // killough 4/2/98: fix bug where P_CheckPosition() uses a non-solid
// corpse to detect collisions with other players in DM starts // corpse to detect collisions with other players in DM starts
@ -1453,7 +1453,7 @@ bool G_CheckSpot (int playernum, FPlayerStart *mthing)
players[playernum].mo->flags |= MF_SOLID; players[playernum].mo->flags |= MF_SOLID;
i = P_CheckPosition(players[playernum].mo, x, y); i = P_CheckPosition(players[playernum].mo, x, y);
players[playernum].mo->flags &= ~MF_SOLID; players[playernum].mo->flags &= ~MF_SOLID;
players[playernum].mo->z = oldz; // [RH] Restore corpse's height players[playernum].mo->SetZ(oldz); // [RH] Restore corpse's height
if (!i) if (!i)
return false; return false;

View file

@ -795,7 +795,7 @@ void P_LineOpening_XFloors (FLineOpening &open, AActor * thing, const line_t *li
highestfloorpic = *rover->top.texture; highestfloorpic = *rover->top.texture;
highestfloorterrain = rover->model->GetTerrain(rover->top.isceiling); highestfloorterrain = rover->model->GetTerrain(rover->top.isceiling);
} }
if(ff_top > lowestfloor[j] && ff_top <= thing->z + thing->MaxStepHeight) lowestfloor[j] = ff_top; if(ff_top > lowestfloor[j] && ff_top <= thing->Z() + thing->MaxStepHeight) lowestfloor[j] = ff_top;
} }
} }

View file

@ -8602,7 +8602,7 @@ scriptwait:
} }
else else
{ {
STACK(1) = (&actor->x)[pcd - PCD_GETACTORX]; STACK(1) = pcd == PCD_GETACTORX ? actor->X() : pcd == PCD_GETACTORY ? actor->Y() : actor->Z();
} }
} }
break; break;

View file

@ -356,9 +356,10 @@ static void MakeFountain (AActor *actor, int color1, int color2)
angle_t an = M_Random()<<(24-ANGLETOFINESHIFT); angle_t an = M_Random()<<(24-ANGLETOFINESHIFT);
fixed_t out = FixedMul (actor->radius, M_Random()<<8); fixed_t out = FixedMul (actor->radius, M_Random()<<8);
particle->x = actor->x + FixedMul (out, finecosine[an]); fixedvec3 pos = actor->Vec3Offset(FixedMul(out, finecosine[an]), FixedMul(out, finesine[an]), actor->height + FRACUNIT);
particle->y = actor->y + FixedMul (out, finesine[an]); particle->x = pos.x;
particle->z = actor->z + actor->height + FRACUNIT; particle->y = pos.y;
particle->z = pos.z;
if (out < actor->radius/8) if (out < actor->radius/8)
particle->velz += FRACUNIT*10/3; particle->velz += FRACUNIT*10/3;
else else
@ -395,9 +396,10 @@ void P_RunEffect (AActor *actor, int effects)
{ {
// Rocket trail // Rocket trail
fixed_t backx = actor->x - FixedMul (finecosine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2);
fixed_t backy = actor->y - FixedMul (finesine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2); fixed_t backx = - FixedMul (finecosine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2);
fixed_t backz = actor->z - (actor->height>>3) * (actor->velz>>16) + (2*actor->height)/3; fixed_t backy = - FixedMul (finesine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2);
fixed_t backz = - (actor->height>>3) * (actor->velz>>16) + (2*actor->height)/3;
angle_t an = (moveangle + ANG90) >> ANGLETOFINESHIFT; angle_t an = (moveangle + ANG90) >> ANGLETOFINESHIFT;
int speed; int speed;
@ -405,9 +407,13 @@ void P_RunEffect (AActor *actor, int effects)
particle = JitterParticle (3 + (M_Random() & 31)); particle = JitterParticle (3 + (M_Random() & 31));
if (particle) { if (particle) {
fixed_t pathdist = M_Random()<<8; fixed_t pathdist = M_Random()<<8;
particle->x = backx - FixedMul(actor->velx, pathdist); fixedvec3 pos = actor->Vec3Offset(
particle->y = backy - FixedMul(actor->vely, pathdist); backx - FixedMul(actor->velx, pathdist),
particle->z = backz - FixedMul(actor->velz, pathdist); backy - FixedMul(actor->vely, pathdist),
backz - FixedMul(actor->velz, pathdist));
particle->x = pos.x;
particle->y = pos.y;
particle->z = pos.z;
speed = (M_Random () - 128) * (FRACUNIT/200); speed = (M_Random () - 128) * (FRACUNIT/200);
particle->velx += FixedMul (speed, finecosine[an]); particle->velx += FixedMul (speed, finecosine[an]);
particle->vely += FixedMul (speed, finesine[an]); particle->vely += FixedMul (speed, finesine[an]);
@ -420,9 +426,13 @@ void P_RunEffect (AActor *actor, int effects)
particle_t *particle = JitterParticle (3 + (M_Random() & 31)); particle_t *particle = JitterParticle (3 + (M_Random() & 31));
if (particle) { if (particle) {
fixed_t pathdist = M_Random()<<8; fixed_t pathdist = M_Random()<<8;
particle->x = backx - FixedMul(actor->velx, pathdist); fixedvec3 pos = actor->Vec3Offset(
particle->y = backy - FixedMul(actor->vely, pathdist); backx - FixedMul(actor->velx, pathdist),
particle->z = backz - FixedMul(actor->velz, pathdist) + (M_Random() << 10); backy - FixedMul(actor->vely, pathdist),
backz - FixedMul(actor->velz, pathdist) + (M_Random() << 10);
particle->x = pos.x;
particle->y = pos.y;
particle->z = pos.z;
speed = (M_Random () - 128) * (FRACUNIT/200); speed = (M_Random () - 128) * (FRACUNIT/200);
particle->velx += FixedMul (speed, finecosine[an]); particle->velx += FixedMul (speed, finecosine[an]);
particle->vely += FixedMul (speed, finesine[an]); particle->vely += FixedMul (speed, finesine[an]);
@ -441,10 +451,12 @@ void P_RunEffect (AActor *actor, int effects)
{ {
// Grenade trail // Grenade trail
P_DrawSplash2 (6, fixedvec3 pos = actor->Vec3Offset(
actor->x - FixedMul (finecosine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2), -FixedMul(finecosine[(moveangle) >> ANGLETOFINESHIFT], actor->radius * 2),
actor->y - FixedMul (finesine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2), -FixedMul(finesine[(moveangle) >> ANGLETOFINESHIFT], actor->radius * 2),
actor->z - (actor->height>>3) * (actor->velz>>16) + (2*actor->height)/3, -(actor->height >> 3) * (actor->velz >> 16) + (2 * actor->height) / 3);
P_DrawSplash2 (6, pos.x, pos.y, pos.z,
moveangle + ANG180, 2, 2); moveangle + ANG180, 2, 2);
} }
if (effects & FX_FOUNTAINMASK) if (effects & FX_FOUNTAINMASK)
@ -476,10 +488,11 @@ void P_RunEffect (AActor *actor, int effects)
if (particle != NULL) if (particle != NULL)
{ {
angle_t ang = M_Random () << (32-ANGLETOFINESHIFT-8); angle_t ang = M_Random () << (32-ANGLETOFINESHIFT-8);
particle->x = actor->x + FixedMul (actor->radius, finecosine[ang]); fixedvec3 pos = actor->Vec3Offset(FixedMul (actor->radius, finecosine[ang]), FixedMul (actor->radius, finesine[ang]), 0);
particle->y = actor->y + FixedMul (actor->radius, finesine[ang]); particle->x = pos.x;
particle->y = pos.y;
particle->z = pos.z;
particle->color = *protectColors[M_Random() & 1]; particle->color = *protectColors[M_Random() & 1];
particle->z = actor->z;
particle->velz = FRACUNIT; particle->velz = FRACUNIT;
particle->accz = M_Random () << 7; particle->accz = M_Random () << 7;
particle->size = 1; particle->size = 1;
@ -832,9 +845,13 @@ void P_DisconnectEffect (AActor *actor)
if (!p) if (!p)
break; break;
p->x = actor->x + ((M_Random()-128)<<9) * (actor->radius>>FRACBITS); fixedvec3 pos = actor->Vec3Offset(
p->y = actor->y + ((M_Random()-128)<<9) * (actor->radius>>FRACBITS); ((M_Random()-128)<<9) * (actor->radius>>FRACBITS),
p->z = actor->z + (M_Random()<<8) * (actor->height>>FRACBITS); ((M_Random()-128)<<9) * (actor->radius>>FRACBITS),
(M_Random()<<8) * (actor->height>>FRACBITS));
p->x = pos.x;
p->y = pos.y;
p->z = pos.z;
p->accz -= FRACUNIT/4096; p->accz -= FRACUNIT/4096;
p->color = M_Random() < 128 ? maroon1 : maroon2; p->color = M_Random() < 128 ? maroon1 : maroon2;
p->size = 4; p->size = 4;

View file

@ -585,7 +585,7 @@ sector_t *AActor::LinkToWorldForMapThing ()
return ssec->sector; return ssec->sector;
} }
void AActor::SetOrigin (fixed_t ix, fixed_t iy, fixed_t iz) void AActor::SetOrigin (fixed_t ix, fixed_t iy, fixed_t iz, bool moving)
{ {
UnlinkFromWorld (); UnlinkFromWorld ();
x = ix; x = ix;