- restored floating point pusher code.

This commit is contained in:
Christoph Oelckers 2016-03-28 22:47:45 +02:00
parent 9145181b79
commit 0283df4c42
2 changed files with 31 additions and 50 deletions

View File

@ -1,6 +1,7 @@
#ifndef __P_MAPUTL_H #ifndef __P_MAPUTL_H
#define __P_MAPUTL_H #define __P_MAPUTL_H
#include <float.h>
#include "r_defs.h" #include "r_defs.h"
#include "doomstat.h" #include "doomstat.h"
#include "m_bbox.h" #include "m_bbox.h"

View File

@ -56,9 +56,8 @@ public:
int CheckForSectorMatch (EPusher type, int tag); int CheckForSectorMatch (EPusher type, int tag);
void ChangeValues (int magnitude, int angle) void ChangeValues (int magnitude, int angle)
{ {
angle_t ang = ((angle_t)(angle<<24)) >> ANGLETOFINESHIFT; DAngle ang = angle * (360. / 256.);
m_Xmag = (magnitude * finecosine[ang]) >> FRACBITS; m_PushVec = ang.ToVector(magnitude);
m_Ymag = (magnitude * finesine[ang]) >> FRACBITS;
m_Magnitude = magnitude; m_Magnitude = magnitude;
} }
@ -67,12 +66,9 @@ public:
protected: protected:
EPusher m_Type; EPusher m_Type;
TObjPtr<AActor> m_Source;// Point source if point pusher TObjPtr<AActor> m_Source;// Point source if point pusher
int m_Xmag; // X Strength DVector2 m_PushVec;
int m_Ymag; // Y Strength double m_Magnitude; // Vector strength for point pusher
int m_Magnitude; // Vector strength for point pusher double m_Radius; // Effective radius for point pusher
int m_Radius; // Effective radius for point pusher
int m_X; // X of point source if point pusher
int m_Y; // Y of point source if point pusher
int m_Affectee; // Number of affected sector int m_Affectee; // Number of affected sector
friend bool PIT_PushThing (AActor *thing); friend bool PIT_PushThing (AActor *thing);
@ -100,12 +96,9 @@ void DPusher::Serialize (FArchive &arc)
Super::Serialize (arc); Super::Serialize (arc);
arc << m_Type arc << m_Type
<< m_Source << m_Source
<< m_Xmag << m_PushVec
<< m_Ymag
<< m_Magnitude << m_Magnitude
<< m_Radius << m_Radius
<< m_X
<< m_Y
<< m_Affectee; << m_Affectee;
} }
@ -155,7 +148,7 @@ void DPusher::Serialize (FArchive &arc)
// types 1 & 2 is the sector containing the MT_PUSH/MT_PULL Thing. // types 1 & 2 is the sector containing the MT_PUSH/MT_PULL Thing.
#define PUSH_FACTOR 7 #define PUSH_FACTOR 128
///////////////////////////// /////////////////////////////
// //
@ -168,9 +161,8 @@ DPusher::DPusher (DPusher::EPusher type, line_t *l, int magnitude, int angle,
m_Type = type; m_Type = type;
if (l) if (l)
{ {
m_Xmag = l->dx>>FRACBITS; m_PushVec = l->Delta();
m_Ymag = l->dy>>FRACBITS; m_Magnitude = m_PushVec.Length();
m_Magnitude = P_AproxDistance (m_Xmag, m_Ymag);
} }
else else
{ // [RH] Allow setting magnitude and angle with parameters { // [RH] Allow setting magnitude and angle with parameters
@ -178,9 +170,7 @@ DPusher::DPusher (DPusher::EPusher type, line_t *l, int magnitude, int angle,
} }
if (source) // point source exist? if (source) // point source exist?
{ {
m_Radius = (m_Magnitude) << (FRACBITS+1); // where force goes to zero m_Radius = m_Magnitude * 2; // where force goes to zero
m_X = m_Source->X();
m_Y = m_Source->Y();
} }
m_Affectee = affectee; m_Affectee = affectee;
} }
@ -204,8 +194,7 @@ void DPusher::Tick ()
sector_t *sec; sector_t *sec;
AActor *thing; AActor *thing;
msecnode_t *node; msecnode_t *node;
int xspeed,yspeed; double ht;
int ht;
if (!var_pushers) if (!var_pushers)
return; return;
@ -243,7 +232,7 @@ void DPusher::Tick ()
// point pusher. Crosses sectors, so use blockmap. // point pusher. Crosses sectors, so use blockmap.
FPortalGroupArray check(FPortalGroupArray::PGA_NoSectorPortals); // no sector portals because this thing is utterly z-unaware. FPortalGroupArray check(FPortalGroupArray::PGA_NoSectorPortals); // no sector portals because this thing is utterly z-unaware.
FMultiBlockThingsIterator it(check, m_X, m_Y, 0, 0, m_Radius, false, m_Source->Sector); FMultiBlockThingsIterator it(check, m_Source, FLOAT2FIXED(m_Radius));
FMultiBlockThingsIterator::CheckResult cres; FMultiBlockThingsIterator::CheckResult cres;
@ -262,22 +251,18 @@ void DPusher::Tick ()
if ((pusharound) ) if ((pusharound) )
{ {
int sx = m_X; DVector2 pos = m_Source->Vec2To(thing);
int sy = m_Y; double dist = pos.Length();
int dist = thing->AproxDistance (sx, sy); double speed = (m_Magnitude - (dist/2)) / (PUSH_FACTOR * 2);
int speed = (m_Magnitude - ((dist>>FRACBITS)>>1))<<(FRACBITS-PUSH_FACTOR-1);
// If speed <= 0, you're outside the effective radius. You also have // If speed <= 0, you're outside the effective radius. You also have
// to be able to see the push/pull source point. // to be able to see the push/pull source point.
if ((speed > 0) && (P_CheckSight (thing, m_Source, SF_IGNOREVISIBILITY))) if ((speed > 0) && (P_CheckSight (thing, m_Source, SF_IGNOREVISIBILITY)))
{ {
angle_t pushangle = thing->AngleTo(sx, sy); DAngle pushangle = pos.Angle();
if (m_Source->GetClass()->TypeName == NAME_PointPusher) if (m_Source->GetClass()->TypeName == NAME_PointPuller) pushangle += 180;
pushangle += ANG180; // away thing->Thrust(pushangle, speed);
pushangle >>= ANGLETOFINESHIFT;
thing->vel.x += FixedMul (speed, finecosine[pushangle]);
thing->vel.y += FixedMul (speed, finesine[pushangle]);
} }
} }
} }
@ -294,38 +279,35 @@ void DPusher::Tick ()
continue; continue;
sector_t *hsec = sec->GetHeightSec(); sector_t *hsec = sec->GetHeightSec();
fixedvec3 pos = thing->PosRelative(sec); fixedvec3 pos = thing->_f_PosRelative(sec);
DVector2 pushvel;
if (m_Type == p_wind) if (m_Type == p_wind)
{ {
if (hsec == NULL) if (hsec == NULL)
{ // NOT special water sector { // NOT special water sector
if (thing->Z() > thing->floorz) // above ground if (thing->Z() > thing->floorz) // above ground
{ {
xspeed = m_Xmag; // full force pushvel = m_PushVec; // full force
yspeed = m_Ymag;
} }
else // on ground else // on ground
{ {
xspeed = (m_Xmag)>>1; // half force pushvel = m_PushVec / 2; // half force
yspeed = (m_Ymag)>>1;
} }
} }
else // special water sector else // special water sector
{ {
ht = hsec->floorplane.ZatPoint(pos); ht = hsec->floorplane.ZatPointF(pos);
if (thing->Z() > ht) // above ground if (thing->Z() > ht) // above ground
{ {
xspeed = m_Xmag; // full force pushvel = m_PushVec; // full force
yspeed = m_Ymag;
} }
else if (thing->player->viewz < ht) // underwater else if (thing->player->viewz < ht) // underwater
{ {
xspeed = yspeed = 0; // no force pushvel.Zero(); // no force
} }
else // wading in water else // wading in water
{ {
xspeed = (m_Xmag)>>1; // half force pushvel = m_PushVec / 2; // full force
yspeed = (m_Ymag)>>1;
} }
} }
} }
@ -341,18 +323,16 @@ void DPusher::Tick ()
{ // special water sector { // special water sector
floor = &hsec->floorplane; floor = &hsec->floorplane;
} }
if (thing->Z() > floor->ZatPoint(pos)) if (thing->Z() > floor->ZatPointF(pos))
{ // above ground { // above ground
xspeed = yspeed = 0; // no force pushvel.Zero(); // no force
} }
else else
{ // on ground/underwater { // on ground/underwater
xspeed = m_Xmag; // full force pushvel = m_PushVec; // full force
yspeed = m_Ymag;
} }
} }
thing->vel.x += xspeed<<(FRACBITS-PUSH_FACTOR); thing->Vel += pushvel / PUSH_FACTOR;
thing->vel.y += yspeed<<(FRACBITS-PUSH_FACTOR);
} }
} }