- floatified some stuff in g_shared.

Note: This commit does not handle z-spawn positions correctly.
This commit is contained in:
Christoph Oelckers 2016-03-23 00:53:09 +01:00
parent 301f5abadc
commit 2a0d5a621a
7 changed files with 79 additions and 105 deletions

View file

@ -1190,7 +1190,7 @@ public:
// no matter what (even if shot)
player_t *player; // only valid if type of APlayerPawn
TObjPtr<AActor> LastLookActor; // Actor last looked for (if TIDtoHate != 0)
fixed_t SpawnPoint[3]; // For nightmare respawn
DVector3 SpawnPoint; // For nightmare respawn
WORD SpawnAngle;
int StartHealth;
BYTE WeaveIndexXY; // Separated from special2 because it's used by globally accessible functions.
@ -1341,6 +1341,10 @@ public:
int GetTics(FState * newstate);
bool SetState (FState *newstate, bool nofunction=false);
virtual bool UpdateWaterLevel (fixed_t oldz, bool splash=true);
bool UpdateWaterLevel(double oldz, bool splash = true)
{
return UpdateWaterLevel(FLOAT2FIXED(oldz), splash);
}
bool isFast();
bool isSlow();
void SetIdle(bool nofunction=false);

View file

@ -22,13 +22,11 @@ IMPLEMENT_CLASS(AFastProjectile)
void AFastProjectile::Tick ()
{
int i;
fixed_t xfrac;
fixed_t yfrac;
fixed_t zfrac;
DVector3 frac;
int changexy;
ClearInterpolation();
fixed_t oldz = _f_Z();
double oldz = Z();
if (!(flags5 & MF5_NOTIMEFREEZE))
{
@ -43,26 +41,22 @@ void AFastProjectile::Tick ()
// [RH] Ripping is a little different than it was in Hexen
FCheckPosition tm(!!(flags2 & MF2_RIP));
int shift = 3;
int count = 8;
if (_f_radius() > 0)
if (radius > 0)
{
while ( ((abs(_f_velx()) >> shift) > _f_radius()) || ((abs(_f_vely()) >> shift) > _f_radius()))
while ( fabs(Vel.X) > radius * count || fabs(Vel.Y) > radius * count)
{
// we need to take smaller steps.
shift++;
count<<=1;
count += count;
}
}
// Handle movement
if (!Vel.isZero() || (Z() != floorz))
{
xfrac = _f_velx() >> shift;
yfrac = _f_vely() >> shift;
zfrac = _f_velz() >> shift;
changexy = xfrac || yfrac;
int ripcount = count >> 3;
frac = Vel / count;
changexy = frac.X != 0 || frac.Y != 0;
int ripcount = count / 8;
for (i = 0; i < count; i++)
{
if (changexy)
@ -72,14 +66,14 @@ void AFastProjectile::Tick ()
tm.LastRipped.Clear(); // [RH] Do rip damage each step, like Hexen
}
if (!P_TryMove (this, _f_X() + xfrac,_f_Y() + yfrac, true, NULL, tm))
if (!P_TryMove (this, X() + frac.X, Y() + frac.Y, true, NULL, tm))
{ // Blocked move
if (!(flags3 & MF3_SKYEXPLODE))
{
if (tm.ceilingline &&
tm.ceilingline->backsector &&
tm.ceilingline->backsector->GetTexture(sector_t::ceiling) == skyflatnum &&
_f_Z() >= tm.ceilingline->backsector->ceilingplane.ZatPoint(PosRelative(tm.ceilingline)))
Z() >= tm.ceilingline->backsector->ceilingplane.ZatPointF(PosRelative(tm.ceilingline)))
{
// Hack to prevent missiles exploding against the sky.
// Does not handle sky floors.
@ -98,10 +92,10 @@ void AFastProjectile::Tick ()
return;
}
}
_f_AddZ(zfrac);
AddZ(frac.Z);
UpdateWaterLevel (oldz);
oldz = _f_Z();
if (Z() <= floorz)
oldz = Z();
if (oldz <= floorz)
{ // Hit the floor
if (floorpic == skyflatnum && !(flags3 & MF3_SKYEXPLODE))

View file

@ -298,7 +298,7 @@ void APathFollower::Tick ()
if (CurrNode->args[2])
{
HoldTime = level.time + CurrNode->args[2] * TICRATE / 8;
SetXYZ(CurrNode->_f_X(), CurrNode->_f_Y(), CurrNode->_f_Z());
SetXYZ(CurrNode->Pos());
}
}
@ -352,37 +352,32 @@ void APathFollower::NewNode ()
bool APathFollower::Interpolate ()
{
fixed_t dx = 0, dy = 0, dz = 0;
DVector3 dpos(0, 0, 0);
if ((args[2] & 8) && Time > 0.f)
{
dx = _f_X();
dy = _f_Y();
dz = _f_Z();
dpos = Pos();
}
if (CurrNode->Next==NULL) return false;
UnlinkFromWorld ();
fixed_t x, y, z;
DVector3 newpos;
if (args[2] & 1)
{ // linear
x = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->_f_X()), FIXED2DBL(CurrNode->Next->_f_X())));
y = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->_f_Y()), FIXED2DBL(CurrNode->Next->_f_Y())));
z = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->_f_Z()), FIXED2DBL(CurrNode->Next->_f_Z())));
newpos.X = Lerp(CurrNode->X(), CurrNode->Next->X());
newpos.Y = Lerp(CurrNode->Y(), CurrNode->Next->Y());
newpos.Z = Lerp(CurrNode->Z(), CurrNode->Next->Z());
}
else
{ // spline
if (CurrNode->Next->Next==NULL) return false;
x = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->_f_X()), FIXED2DBL(CurrNode->_f_X()),
FIXED2DBL(CurrNode->Next->_f_X()), FIXED2DBL(CurrNode->Next->Next->_f_X())));
y = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->_f_Y()), FIXED2DBL(CurrNode->_f_Y()),
FIXED2DBL(CurrNode->Next->_f_Y()), FIXED2DBL(CurrNode->Next->Next->_f_Y())));
z = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->_f_Z()), FIXED2DBL(CurrNode->_f_Z()),
FIXED2DBL(CurrNode->Next->_f_Z()), FIXED2DBL(CurrNode->Next->Next->_f_Z())));
newpos.X = Splerp(PrevNode->X(), CurrNode->X(), CurrNode->Next->X(), CurrNode->Next->Next->X());
newpos.X = Splerp(PrevNode->Y(), CurrNode->Y(), CurrNode->Next->Y(), CurrNode->Next->Next->Y());
newpos.X = Splerp(PrevNode->Z(), CurrNode->Z(), CurrNode->Next->Z(), CurrNode->Next->Next->Z());
}
SetXYZ(x, y, z);
SetXYZ(newpos);
LinkToWorld ();
if (args[2] & 6)
@ -391,46 +386,35 @@ bool APathFollower::Interpolate ()
{
if (args[2] & 1)
{ // linear
dx = CurrNode->Next->_f_X() - CurrNode->_f_X();
dy = CurrNode->Next->_f_Y() - CurrNode->_f_Y();
dz = CurrNode->Next->_f_Z() - CurrNode->_f_Z();
dpos.X = CurrNode->Next->X() - CurrNode->X();
dpos.Y = CurrNode->Next->Y() - CurrNode->Y();
dpos.Z = CurrNode->Next->Z() - CurrNode->Z();
}
else if (Time > 0.f)
{ // spline
dx = x - dx;
dy = y - dy;
dz = z - dz;
dpos = newpos - dpos;
}
else
{
int realarg = args[2];
args[2] &= ~(2|4|8);
Time += 0.1f;
dx = x;
dy = y;
dz = z;
dpos = newpos;
Interpolate ();
Time -= 0.1f;
args[2] = realarg;
dx = x - dx;
dy = y - dy;
dz = z - dz;
x -= dx;
y -= dy;
z -= dz;
SetXYZ(x, y, z);
dpos = newpos - dpos;
newpos -= dpos;
SetXYZ(newpos);
}
if (args[2] & 2)
{ // adjust yaw
Angles.Yaw = VecToAngle(dx, dy);
Angles.Yaw = dpos.Angle();
}
if (args[2] & 4)
{ // adjust pitch; use floats for precision
double fdx = FIXED2DBL(dx);
double fdy = FIXED2DBL(dy);
double fdz = FIXED2DBL(-dz);
double dist = g_sqrt (fdx*fdx + fdy*fdy);
Angles.Pitch = dist != 0.f ? VecToAngle(dist, fdz) : 0.;
double dist = dpos.XY().Length();
Angles.Pitch = dist != 0.f ? VecToAngle(dist, -dpos.Z) : 0.;
}
}
else
@ -517,11 +501,11 @@ bool AActorMover::Interpolate ()
if (Super::Interpolate ())
{
fixed_t savedz = tracer->_f_Z();
tracer->_f_SetZ(_f_Z());
if (!P_TryMove (tracer, _f_X(), _f_Y(), true))
double savedz = tracer->Z();
tracer->SetZ(Z());
if (!P_TryMove (tracer, Pos(), true))
{
tracer->_f_SetZ(savedz);
tracer->SetZ(savedz);
return false;
}
@ -636,12 +620,10 @@ bool AMovingCamera::Interpolate ()
Angles.Yaw = AngleTo(tracer, true);
if (args[2] & 4)
{ // Also aim camera's pitch; use floats for precision
double dx = FIXED2DBL(_f_X() - tracer->_f_X());
double dy = FIXED2DBL(_f_Y() - tracer->_f_Y());
double dz = FIXED2DBL(_f_Z() - tracer->_f_Z() - tracer->_f_height()/2);
double dist = g_sqrt (dx*dx + dy*dy);
Angles.Pitch = dist != 0.f ? VecToAngle(dist, dz) : 0.;
{ // Also aim camera's pitch;
DVector3 diff = Pos() - tracer->PosPlusZ(tracer->Height / 2);
double dist = diff.XY().Length();
Angles.Pitch = dist != 0.f ? VecToAngle(dist, diff.Z) : 0.;
}
return true;

View file

@ -413,20 +413,17 @@ DEFINE_ACTION_FUNCTION(AActor, A_RestoreSpecialPosition)
PARAM_ACTION_PROLOGUE;
// Move item back to its original location
fixed_t _x, _y;
_x = self->SpawnPoint[0];
_y = self->SpawnPoint[1];
DVector2 sp = self->SpawnPoint;
self->UnlinkFromWorld();
self->SetXY(_x, _y);
self->SetXY(sp);
self->LinkToWorld(true);
self->_f_SetZ(self->Sector->floorplane.ZatPoint(_x, _y));
self->SetZ(self->Sector->floorplane.ZatPoint(sp));
P_FindFloorCeiling(self, FFCF_ONLYSPAWNPOS | FFCF_NOPORTALS); // no portal checks here so that things get spawned in this sector.
if (self->flags & MF_SPAWNCEILING)
{
self->_f_SetZ(self->_f_ceilingz() - self->_f_height() - self->SpawnPoint[2]);
self->SetZ(self->ceilingz - self->Height - self->SpawnPoint.Z);
}
else if (self->flags2 & MF2_SPAWNFLOAT)
{
@ -443,7 +440,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_RestoreSpecialPosition)
}
else
{
self->_f_SetZ(self->SpawnPoint[2] + self->_f_floorz());
self->SetZ(self->SpawnPoint.Z + self->floorz);
}
// Redo floor/ceiling check, in case of 3D floors and portals
P_FindFloorCeiling(self, FFCF_SAMESECTOR | FFCF_ONLY3DFLOORS | FFCF_3DRESTRICT);
@ -1354,7 +1351,7 @@ bool AInventory::DoRespawn ()
if (spot != NULL)
{
SetOrigin (spot->Pos(), false);
_f_SetZ(_f_floorz());
SetZ(floorz);
}
}
return true;

View file

@ -162,7 +162,7 @@ class ARandomSpawner : public AActor
// copy everything relevant
newmobj->SpawnAngle = SpawnAngle;
newmobj->Angles = Angles;
newmobj->SpawnPoint[2] = SpawnPoint[2];
newmobj->SpawnPoint = SpawnPoint;
newmobj->special = special;
newmobj->args[0] = args[0];
newmobj->args[1] = args[1];
@ -188,7 +188,7 @@ class ARandomSpawner : public AActor
// Handle special altitude flags
if (newmobj->flags & MF_SPAWNCEILING)
{
newmobj->_f_SetZ(newmobj->_f_ceilingz() - newmobj->_f_height() - SpawnPoint[2]);
newmobj->SetZ(newmobj->ceilingz - newmobj->Height - SpawnPoint.Z);
}
else if (newmobj->flags2 & MF2_SPAWNFLOAT)
{
@ -198,7 +198,7 @@ class ARandomSpawner : public AActor
space -= 40;
newmobj->SetZ((space * pr_randomspawn()) / 256. + newmobj->floorz + 40);
}
newmobj->_f_AddZ(SpawnPoint[2]);
newmobj->AddZ(SpawnPoint.Z);
}
if (newmobj->flags & MF_MISSILE)
P_CheckMissileSpawn(newmobj, 0);

View file

@ -315,7 +315,7 @@ void AActor::Serialize(FArchive &arc)
<< reactiontime
<< threshold
<< player
<< SpawnPoint[0] << SpawnPoint[1] << SpawnPoint[2]
<< SpawnPoint
<< SpawnAngle;
if (SaveVersion >= 4506)
{
@ -2739,7 +2739,7 @@ static void PlayerLandedOnThing (AActor *mo, AActor *onmobj)
//
void P_NightmareRespawn (AActor *mobj)
{
fixed_t x, y, z;
double z;
AActor *mo;
AActor *info = mobj->GetDefault();
@ -2754,13 +2754,11 @@ void P_NightmareRespawn (AActor *mobj)
z = ONFLOORZ;
// spawn it
x = mobj->SpawnPoint[0];
y = mobj->SpawnPoint[1];
mo = AActor::StaticSpawn(mobj->GetClass(), x, y, z, NO_REPLACE, true);
mo = AActor::StaticSpawn(mobj->GetClass(), mobj->SpawnPoint.X, mobj->SpawnPoint.Y, z, NO_REPLACE, true);
if (z == ONFLOORZ)
{
mo->_f_AddZ(mobj->SpawnPoint[2]);
mo->AddZ(mobj->SpawnPoint.Z);
if (mo->Z() < mo->floorz)
{ // Do not respawn monsters in the floor, even if that's where they
// started. The initial P_ZMovement() call would have put them on
@ -2775,7 +2773,7 @@ void P_NightmareRespawn (AActor *mobj)
}
else if (z == ONCEILINGZ)
{
mo->_f_AddZ(-mobj->SpawnPoint[2]);
mo->AddZ(-mobj->SpawnPoint.Z);
}
// If there are 3D floors, we need to find floor/ceiling again.
@ -2797,7 +2795,7 @@ void P_NightmareRespawn (AActor *mobj)
}
// something is occupying its position?
if (!P_CheckPosition(mo, mo->_f_X(), mo->_f_Y(), true))
if (!P_CheckPosition(mo, mo->Pos(), true))
{
//[GrafZahl] MF_COUNTKILL still needs to be checked here.
mo->ClearCounters();
@ -2808,9 +2806,7 @@ void P_NightmareRespawn (AActor *mobj)
z = mo->_f_Z();
// inherit attributes from deceased one
mo->SpawnPoint[0] = mobj->SpawnPoint[0];
mo->SpawnPoint[1] = mobj->SpawnPoint[1];
mo->SpawnPoint[2] = mobj->SpawnPoint[2];
mo->SpawnPoint = mobj->SpawnPoint;
mo->SpawnAngle = mobj->SpawnAngle;
mo->SpawnFlags = mobj->SpawnFlags & ~MTF_DORMANT; // It wasn't dormant when it died, so it's not dormant now, either.
mo->Angles.Yaw = (double)mobj->SpawnAngle;
@ -2822,13 +2818,13 @@ void P_NightmareRespawn (AActor *mobj)
mo->skillrespawncount = mobj->skillrespawncount;
mo->PrevZ = z; // Do not interpolate Z position if we changed it since spawning.
mo->PrevZ = FLOAT2FIXED(z); // Do not interpolate Z position if we changed it since spawning.
// spawn a teleport fog at old spot because of removal of the body?
P_SpawnTeleportFog(mobj, mobj->PosPlusZ(TELEFOGHEIGHT), true, true);
// spawn a teleport fog at the new spot
P_SpawnTeleportFog(mobj, FIXED2DBL(x), FIXED2DBL(y), FIXED2DBL(z) + TELEFOGHEIGHT, false, true);
P_SpawnTeleportFog(mobj, mobj->SpawnPoint.X, mobj->SpawnPoint.Y, z + TELEFOGHEIGHT, false, true);
// remove the old monster
mobj->Destroy ();
@ -4132,8 +4128,12 @@ bool AActor::UpdateWaterLevel (fixed_t oldz, bool dosplash)
//
//==========================================================================
AActor *AActor::StaticSpawn (PClassActor *type, fixed_t ix, fixed_t iy, fixed_t iz, replace_t allowreplacement, bool SpawningMapThing)
AActor *AActor::StaticSpawn (PClassActor *type, fixed_t _ix, fixed_t _iy, fixed_t _iz, replace_t allowreplacement, bool SpawningMapThing)
{
double ix = FIXED2DBL(_ix);
double iy = FIXED2DBL(_iy);
double iz = FIXED2DBL(_iz);
if (type == NULL)
{
I_Error ("Tried to spawn a class-less actor\n");
@ -4196,10 +4196,9 @@ AActor *AActor::StaticSpawn (PClassActor *type, fixed_t ix, fixed_t iy, fixed_t
actor->LinkToWorld (SpawningMapThing);
actor->ClearInterpolation();
actor->dropoffz = // killough 11/98: for tracking dropoffs
actor->Sector->floorplane.ZatPoint (ix, iy);
actor->floorz = FIXED2DBL(actor->dropoffz);
actor->ceilingz = FIXED2DBL(actor->Sector->ceilingplane.ZatPoint (ix, iy));
actor->floorz = actor->Sector->floorplane.ZatPoint (ix, iy);
actor->dropoffz = FLOAT2FIXED(actor->floorz); // killough 11/98: for tracking dropoffs
actor->ceilingz = actor->Sector->ceilingplane.ZatPoint (ix, iy);
// The z-coordinate needs to be set once before calling P_FindFloorCeiling
// For FLOATRANDZ just use the floor here.
@ -4243,8 +4242,8 @@ AActor *AActor::StaticSpawn (PClassActor *type, fixed_t ix, fixed_t iy, fixed_t
actor->ceilingsector = actor->Sector;
}
actor->SpawnPoint[0] = ix;
actor->SpawnPoint[1] = iy;
actor->SpawnPoint.X = ix;
actor->SpawnPoint.Y = iy;
if (iz == ONFLOORZ)
{
@ -4269,7 +4268,7 @@ AActor *AActor::StaticSpawn (PClassActor *type, fixed_t ix, fixed_t iy, fixed_t
}
else
{
actor->SpawnPoint[2] = (actor->_f_Z() - actor->Sector->floorplane.ZatPoint(actor));
actor->SpawnPoint.Z = (actor->Z() - actor->Sector->floorplane.ZatPointF(actor));
}
if (actor->FloatBobPhase == (BYTE)-1) actor->FloatBobPhase = rng(); // Don't make everything bob in sync (unless deliberately told to do)
@ -5129,9 +5128,7 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
else if (z == ONCEILINGZ)
mobj->_f_AddZ(-mthing->z);
mobj->SpawnPoint[0] = mthing->x;
mobj->SpawnPoint[1] = mthing->y;
mobj->SpawnPoint[2] = mthing->z;
mobj->SpawnPoint = { FIXED2DBL(mthing->x), FIXED2DBL(mthing->y),FIXED2DBL(mthing->z) };
mobj->SpawnAngle = mthing->angle;
mobj->SpawnFlags = mthing->flags;
if (mthing->FloatbobPhase >= 0 && mthing->FloatbobPhase < 64) mobj->FloatBobPhase = mthing->FloatbobPhase;

View file

@ -727,7 +727,7 @@ void CalculateCPUSpeed()
PerfToMillisec = PerfToSec * 1000.0;
}
if (!batchrun) Printf ("CPU _f_speed(): %.0f MHz\n", 0.001 / PerfToMillisec);
if (!batchrun) Printf ("CPU speed: %.0f MHz\n", 0.001 / PerfToMillisec);
}
//==========================================================================