mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-27 22:42:57 +00:00
- more refactoring of AActor coordinate access.
This commit is contained in:
parent
5b610390e1
commit
c611456397
9 changed files with 105 additions and 51 deletions
44
src/actor.h
44
src/actor.h
|
@ -951,6 +951,23 @@ public:
|
|||
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);
|
||||
|
||||
bool IsVisibleToPlayer() const;
|
||||
|
@ -1168,7 +1185,7 @@ public:
|
|||
void LinkToWorld (sector_t *sector);
|
||||
void UnlinkFromWorld ();
|
||||
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);
|
||||
int GetTics(FState * newstate);
|
||||
bool SetState (FState *newstate, bool nofunction=false);
|
||||
|
@ -1210,6 +1227,10 @@ public:
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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 (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>
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -427,7 +427,7 @@ void FCajunMaster::SetBodyAt (fixed_t x, fixed_t y, fixed_t z, int hostnum)
|
|||
{
|
||||
if (body1)
|
||||
{
|
||||
body1->SetOrigin (x, y, z);
|
||||
body1->SetOrigin (x, y, z, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -438,7 +438,7 @@ void FCajunMaster::SetBodyAt (fixed_t x, fixed_t y, fixed_t z, int hostnum)
|
|||
{
|
||||
if (body2)
|
||||
{
|
||||
body2->SetOrigin (x, y, z);
|
||||
body2->SetOrigin (x, y, z, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -465,10 +465,7 @@ fixed_t FCajunMaster::FakeFire (AActor *source, AActor *dest, ticcmd_t *cmd)
|
|||
|
||||
float speed = (float)th->Speed;
|
||||
|
||||
FVector3 velocity;
|
||||
velocity[0] = FIXED2FLOAT(dest->x - source->x);
|
||||
velocity[1] = FIXED2FLOAT(dest->y - source->y);
|
||||
velocity[2] = FIXED2FLOAT(dest->z - source->z);
|
||||
TVector3<double> velocity = source->Vec3To(dest);
|
||||
velocity.MakeUnit();
|
||||
th->velx = FLOAT2FIXED(velocity[0] * 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)
|
||||
{
|
||||
dist += th->Speed;
|
||||
th->SetOrigin (th->x + th->velx, th->y + th->vely, th->z + th->velz);
|
||||
if (!CleanAhead (th, th->x, th->y, cmd))
|
||||
th->Move(th->velx, th->vely, th->velz);
|
||||
if (!CleanAhead (th, th->X(), th->Y(), cmd))
|
||||
break;
|
||||
}
|
||||
th->Destroy ();
|
||||
|
|
|
@ -124,9 +124,6 @@ bool DBot::TryWalk (ticcmd_t *cmd)
|
|||
|
||||
void DBot::NewChaseDir (ticcmd_t *cmd)
|
||||
{
|
||||
fixed_t deltax;
|
||||
fixed_t deltay;
|
||||
|
||||
dirtype_t d[3];
|
||||
|
||||
int tdir;
|
||||
|
@ -145,19 +142,18 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
|
|||
olddir = (dirtype_t)player->mo->movedir;
|
||||
turnaround = opposite[olddir];
|
||||
|
||||
deltax = dest->x - player->mo->x;
|
||||
deltay = dest->y - player->mo->y;
|
||||
fixedvec2 delta = player->mo->Vec2To(dest);
|
||||
|
||||
if (deltax > 10*FRACUNIT)
|
||||
if (delta.x > 10*FRACUNIT)
|
||||
d[1] = DI_EAST;
|
||||
else if (deltax < -10*FRACUNIT)
|
||||
else if (delta.x < -10*FRACUNIT)
|
||||
d[1] = DI_WEST;
|
||||
else
|
||||
d[1] = DI_NODIR;
|
||||
|
||||
if (deltay < -10*FRACUNIT)
|
||||
if (delta.y < -10*FRACUNIT)
|
||||
d[2] = DI_SOUTH;
|
||||
else if (deltay > 10*FRACUNIT)
|
||||
else if (delta.y > 10*FRACUNIT)
|
||||
d[2] = DI_NORTH;
|
||||
else
|
||||
d[2] = DI_NODIR;
|
||||
|
@ -165,14 +161,14 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
|
|||
// try direct route
|
||||
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))
|
||||
return;
|
||||
}
|
||||
|
||||
// try other directions
|
||||
if (pr_botnewchasedir() > 200
|
||||
|| abs(deltay)>abs(deltax))
|
||||
|| abs(delta.y)>abs(delta.x))
|
||||
{
|
||||
tdir=d[1];
|
||||
d[1]=d[2];
|
||||
|
|
|
@ -2319,10 +2319,12 @@ void Net_DoCommand (int type, BYTE **stream, int player)
|
|||
else
|
||||
{
|
||||
const AActor *def = GetDefaultByType (typeinfo);
|
||||
AActor *spawned = Spawn (typeinfo,
|
||||
source->x + FixedMul (def->radius * 2 + source->radius, finecosine[source->angle>>ANGLETOFINESHIFT]),
|
||||
source->y + FixedMul (def->radius * 2 + source->radius, finesine[source->angle>>ANGLETOFINESHIFT]),
|
||||
source->z + 8 * FRACUNIT, ALLOW_REPLACE);
|
||||
fixedvec3 spawnpos = source->Vec3Offset(
|
||||
FixedMul (def->radius * 2 + source->radius, finecosine[source->angle>>ANGLETOFINESHIFT]),
|
||||
FixedMul (def->radius * 2 + source->radius, finesine[source->angle>>ANGLETOFINESHIFT]),
|
||||
8 * FRACUNIT);
|
||||
|
||||
AActor *spawned = Spawn (typeinfo, spawnpos, ALLOW_REPLACE);
|
||||
if (spawned != NULL)
|
||||
{
|
||||
if (type == DEM_SUMMONFRIEND || type == DEM_SUMMONFRIEND2 || type == DEM_SUMMONMBF)
|
||||
|
|
|
@ -1441,7 +1441,7 @@ bool G_CheckSpot (int playernum, FPlayerStart *mthing)
|
|||
}
|
||||
|
||||
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
|
||||
// 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;
|
||||
i = P_CheckPosition(players[playernum].mo, x, y);
|
||||
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)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -795,7 +795,7 @@ void P_LineOpening_XFloors (FLineOpening &open, AActor * thing, const line_t *li
|
|||
highestfloorpic = *rover->top.texture;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8602,7 +8602,7 @@ scriptwait:
|
|||
}
|
||||
else
|
||||
{
|
||||
STACK(1) = (&actor->x)[pcd - PCD_GETACTORX];
|
||||
STACK(1) = pcd == PCD_GETACTORX ? actor->X() : pcd == PCD_GETACTORY ? actor->Y() : actor->Z();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -356,9 +356,10 @@ static void MakeFountain (AActor *actor, int color1, int color2)
|
|||
angle_t an = M_Random()<<(24-ANGLETOFINESHIFT);
|
||||
fixed_t out = FixedMul (actor->radius, M_Random()<<8);
|
||||
|
||||
particle->x = actor->x + FixedMul (out, finecosine[an]);
|
||||
particle->y = actor->y + FixedMul (out, finesine[an]);
|
||||
particle->z = actor->z + actor->height + FRACUNIT;
|
||||
fixedvec3 pos = actor->Vec3Offset(FixedMul(out, finecosine[an]), FixedMul(out, finesine[an]), actor->height + FRACUNIT);
|
||||
particle->x = pos.x;
|
||||
particle->y = pos.y;
|
||||
particle->z = pos.z;
|
||||
if (out < actor->radius/8)
|
||||
particle->velz += FRACUNIT*10/3;
|
||||
else
|
||||
|
@ -395,9 +396,10 @@ void P_RunEffect (AActor *actor, int effects)
|
|||
{
|
||||
// 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 backz = actor->z - (actor->height>>3) * (actor->velz>>16) + (2*actor->height)/3;
|
||||
|
||||
fixed_t backx = - FixedMul (finecosine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2);
|
||||
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;
|
||||
int speed;
|
||||
|
@ -405,9 +407,13 @@ void P_RunEffect (AActor *actor, int effects)
|
|||
particle = JitterParticle (3 + (M_Random() & 31));
|
||||
if (particle) {
|
||||
fixed_t pathdist = M_Random()<<8;
|
||||
particle->x = backx - FixedMul(actor->velx, pathdist);
|
||||
particle->y = backy - FixedMul(actor->vely, pathdist);
|
||||
particle->z = backz - FixedMul(actor->velz, pathdist);
|
||||
fixedvec3 pos = actor->Vec3Offset(
|
||||
backx - FixedMul(actor->velx, 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);
|
||||
particle->velx += FixedMul (speed, finecosine[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));
|
||||
if (particle) {
|
||||
fixed_t pathdist = M_Random()<<8;
|
||||
particle->x = backx - FixedMul(actor->velx, pathdist);
|
||||
particle->y = backy - FixedMul(actor->vely, pathdist);
|
||||
particle->z = backz - FixedMul(actor->velz, pathdist) + (M_Random() << 10);
|
||||
fixedvec3 pos = actor->Vec3Offset(
|
||||
backx - FixedMul(actor->velx, pathdist),
|
||||
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);
|
||||
particle->velx += FixedMul (speed, finecosine[an]);
|
||||
particle->vely += FixedMul (speed, finesine[an]);
|
||||
|
@ -441,10 +451,12 @@ void P_RunEffect (AActor *actor, int effects)
|
|||
{
|
||||
// Grenade trail
|
||||
|
||||
P_DrawSplash2 (6,
|
||||
actor->x - FixedMul (finecosine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2),
|
||||
actor->y - FixedMul (finesine[(moveangle)>>ANGLETOFINESHIFT], actor->radius*2),
|
||||
actor->z - (actor->height>>3) * (actor->velz>>16) + (2*actor->height)/3,
|
||||
fixedvec3 pos = actor->Vec3Offset(
|
||||
-FixedMul(finecosine[(moveangle) >> ANGLETOFINESHIFT], actor->radius * 2),
|
||||
-FixedMul(finesine[(moveangle) >> ANGLETOFINESHIFT], actor->radius * 2),
|
||||
-(actor->height >> 3) * (actor->velz >> 16) + (2 * actor->height) / 3);
|
||||
|
||||
P_DrawSplash2 (6, pos.x, pos.y, pos.z,
|
||||
moveangle + ANG180, 2, 2);
|
||||
}
|
||||
if (effects & FX_FOUNTAINMASK)
|
||||
|
@ -476,10 +488,11 @@ void P_RunEffect (AActor *actor, int effects)
|
|||
if (particle != NULL)
|
||||
{
|
||||
angle_t ang = M_Random () << (32-ANGLETOFINESHIFT-8);
|
||||
particle->x = actor->x + FixedMul (actor->radius, finecosine[ang]);
|
||||
particle->y = actor->y + FixedMul (actor->radius, finesine[ang]);
|
||||
fixedvec3 pos = actor->Vec3Offset(FixedMul (actor->radius, finecosine[ang]), FixedMul (actor->radius, finesine[ang]), 0);
|
||||
particle->x = pos.x;
|
||||
particle->y = pos.y;
|
||||
particle->z = pos.z;
|
||||
particle->color = *protectColors[M_Random() & 1];
|
||||
particle->z = actor->z;
|
||||
particle->velz = FRACUNIT;
|
||||
particle->accz = M_Random () << 7;
|
||||
particle->size = 1;
|
||||
|
@ -832,9 +845,13 @@ void P_DisconnectEffect (AActor *actor)
|
|||
if (!p)
|
||||
break;
|
||||
|
||||
p->x = actor->x + ((M_Random()-128)<<9) * (actor->radius>>FRACBITS);
|
||||
p->y = actor->y + ((M_Random()-128)<<9) * (actor->radius>>FRACBITS);
|
||||
p->z = actor->z + (M_Random()<<8) * (actor->height>>FRACBITS);
|
||||
fixedvec3 pos = actor->Vec3Offset(
|
||||
((M_Random()-128)<<9) * (actor->radius>>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->color = M_Random() < 128 ? maroon1 : maroon2;
|
||||
p->size = 4;
|
||||
|
|
|
@ -585,7 +585,7 @@ sector_t *AActor::LinkToWorldForMapThing ()
|
|||
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 ();
|
||||
x = ix;
|
||||
|
|
Loading…
Reference in a new issue