- floatified bmaporgx and bmaporgy, allowing to remove the gross overflow prevention hacks present in the blockmap code.

This commit is contained in:
Christoph Oelckers 2016-03-31 09:23:14 +02:00
parent f41afde545
commit 8fd76f0c8a
16 changed files with 74 additions and 154 deletions

View file

@ -1839,8 +1839,7 @@ void AM_drawGrid (int color)
// Figure out start of vertical gridlines
start = minx - extx;
double bmorgx = FIXED2DBL(bmaporgx);
start = ceil((start - bmorgx) / MAPBLOCKUNITS) * MAPBLOCKUNITS + bmorgx;
start = ceil((start - bmaporgx) / MAPBLOCKUNITS) * MAPBLOCKUNITS + bmaporgx;
end = minx + minlen - extx;
@ -1861,8 +1860,7 @@ void AM_drawGrid (int color)
// Figure out start of horizontal gridlines
start = miny - exty;
double bmorgy = FIXED2DBL(bmaporgy);
start = ceil((start - bmorgy) / MAPBLOCKUNITS) * MAPBLOCKUNITS + bmorgy;
start = ceil((start - bmaporgy) / MAPBLOCKUNITS) * MAPBLOCKUNITS + bmaporgy;
end = miny + minlen - exty;
// draw horizontal gridlines

View file

@ -27,8 +27,18 @@ extern int* blockmaplump; // offsets in blockmap are from here
extern int* blockmap;
extern int bmapwidth;
extern int bmapheight; // in mapblocks
extern fixed_t bmaporgx;
extern fixed_t bmaporgy; // origin of block map
extern double bmaporgx;
extern double bmaporgy; // origin of block map
extern FBlockNode** blocklinks; // for thing chains
inline int GetBlockX(double xpos)
{
return int((xpos - bmaporgx) / MAPBLOCKUNITS);
}
inline int GetBlockY(double ypos)
{
return int((ypos - bmaporgy) / MAPBLOCKUNITS);
}
#endif

View file

@ -44,20 +44,6 @@ struct FCheckPosition
PushTime = 0;
FromPMove = false;
}
inline fixed_t _f_X()
{
return FLOAT2FIXED(pos.X);
}
inline fixed_t _f_Y()
{
return FLOAT2FIXED(pos.Y);
}
inline fixed_t _f_Z()
{
return FLOAT2FIXED(pos.Z);
}
};

View file

@ -34,7 +34,6 @@ class player_t;
class AActor;
struct FPlayerStart;
class PClassActor;
struct fixedvec3;
class APlayerPawn;
struct line_t;
struct sector_t;
@ -61,28 +60,6 @@ struct FTranslatedLineTarget;
extern int bmapnegx;
extern int bmapnegy;
inline int GetSafeBlockX(int blockx)
{
blockx >>= MAPBLOCKSHIFT;
return (blockx <= bmapnegx) ? blockx & 0x1FF : blockx;
}
inline int GetSafeBlockX(long long blockx)
{
blockx >>= MAPBLOCKSHIFT;
return int((blockx <= bmapnegx) ? blockx & 0x1FF : blockx);
}
inline int GetSafeBlockY(int blocky)
{
blocky >>= MAPBLOCKSHIFT;
return (blocky <= bmapnegy) ? blocky & 0x1FF: blocky;
}
inline int GetSafeBlockY(long long blocky)
{
blocky >>= MAPBLOCKSHIFT;
return int((blocky <= bmapnegy) ? blocky & 0x1FF: blocky);
}
//#define GRAVITY FRACUNIT
#define MAXMOVE (30.)
@ -242,17 +219,11 @@ extern TArray<spechit_t> portalhit;
bool P_TestMobjLocation (AActor *mobj);
bool P_TestMobjZ (AActor *mobj, bool quick=true, AActor **pOnmobj = NULL);
bool P_CheckPosition(AActor *thing, const DVector2 &pos, bool actorsonly = false);
inline bool P_CheckPosition(AActor *thing, const DVector2 &pos, FCheckPosition &tm, bool actorsonly = false);
bool P_CheckPosition(AActor *thing, const DVector2 &pos, FCheckPosition &tm, bool actorsonly = false);
AActor *P_CheckOnmobj (AActor *thing);
void P_FakeZMovement (AActor *mo);
bool P_TryMove(AActor* thing, const DVector2 &pos, int dropoff, const secplane_t * onfloor, FCheckPosition &tm, bool missileCheck = false);
bool P_TryMove(AActor* thing, const DVector2 &pos, int dropoff, const secplane_t * onfloor = NULL);
/*
inline bool P_TryMove(AActor* thing, double x, double y, int dropoff, const secplane_t * onfloor = NULL)
{
return P_TryMove(thing, FLOAT2FIXED(x), FLOAT2FIXED(y), dropoff, onfloor);
}
*/
bool P_CheckMove(AActor *thing, const DVector2 &pos);
void P_ApplyTorque(AActor *mo);
@ -325,7 +296,6 @@ void P_TraceBleed(int damage, FTranslatedLineTarget *t, AActor *puff); // hitsc
void P_TraceBleed (int damage, AActor *target); // random direction version
bool P_HitFloor (AActor *thing);
bool P_HitWater (AActor *thing, sector_t *sec, const DVector3 &pos, bool checkabove = false, bool alert = true, bool force = false);
inline bool P_HitWater(AActor *thing, sector_t *sec, const fixedvec3 &pos, bool checkabove = false, bool alert = true, bool force = false) = delete;
void P_CheckSplash(AActor *self, double distance);
struct FRailParams
@ -389,8 +359,6 @@ bool Check_Sides(AActor *, int, int); // phares
// [RH]
const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move);
inline const secplane_t * P_CheckSlopeWalk(AActor *actor, fixed_t &xmove, fixed_t &ymove) = delete;
//
// P_SETUP
//

View file

@ -2947,7 +2947,7 @@ const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move)
if (t < 0)
{ // Desired location is behind (below) the plane
// (i.e. Walking up the plane)
if (plane->fixC() < STEEPSLOPE)
if (plane->fC() < STEEPSLOPE)
{ // Can't climb up slopes of ~45 degrees or more
if (actor->flags & MF_NOCLIP)
{

View file

@ -376,8 +376,8 @@ bool AActor::FixMapthingPos()
{
sector_t *secstart = P_PointInSectorBuggy(_f_X(), _f_Y());
int blockx = GetSafeBlockX(_f_X() - bmaporgx);
int blocky = GetSafeBlockY(_f_Y() - bmaporgy);
int blockx = GetBlockX(X());
int blocky = GetBlockY(Y());
bool success = false;
if ((unsigned int)blockx < (unsigned int)bmapwidth &&
@ -519,13 +519,12 @@ void AActor::LinkToWorld(bool spawningmapthing, sector_t *sector)
for (int i = -1; i < (int)check.Size(); i++)
{
DVector3 _pos = i==-1? Pos() : PosRelative(check[i]);
fixedvec3 pos = { FLOAT2FIXED(_pos.X), FLOAT2FIXED(_pos.Y),FLOAT2FIXED(_pos.Z) };
DVector3 pos = i==-1? Pos() : PosRelative(check[i]);
int x1 = GetSafeBlockX(pos.x - _f_radius() - bmaporgx);
int x2 = GetSafeBlockX(pos.x + _f_radius() - bmaporgx);
int y1 = GetSafeBlockY(pos.y - _f_radius() - bmaporgy);
int y2 = GetSafeBlockY(pos.y + _f_radius() - bmaporgy);
int x1 = GetBlockX(pos.X - radius);
int x2 = GetBlockX(pos.X + radius);
int y1 = GetBlockY(pos.Y - radius);
int y2 = GetBlockY(pos.Y + radius);
if (x1 >= bmapwidth || x2 < 0 || y1 >= bmapheight || y2 < 0)
{ // thing is off the map
@ -639,10 +638,10 @@ FBlockLinesIterator::FBlockLinesIterator(int _minx, int _miny, int _maxx, int _m
void FBlockLinesIterator::init(const FBoundingBox &box)
{
validcount++;
maxy = GetSafeBlockY(box.Top() - bmaporgy);
miny = GetSafeBlockY(box.Bottom() - bmaporgy);
maxx = GetSafeBlockX(box.Right() - bmaporgx);
minx = GetSafeBlockX(box.Left() - bmaporgx);
maxy = GetBlockY(FIXED2DBL(box.Top()));
miny = GetBlockY(FIXED2DBL(box.Bottom()));
maxx = GetBlockX(FIXED2DBL(box.Right()));
minx = GetBlockX(FIXED2DBL(box.Left()));
Reset();
}
@ -945,10 +944,10 @@ FBlockThingsIterator::FBlockThingsIterator(int _minx, int _miny, int _maxx, int
void FBlockThingsIterator::init(const FBoundingBox &box)
{
maxy = GetSafeBlockY(box.Top() - bmaporgy);
miny = GetSafeBlockY(box.Bottom() - bmaporgy);
maxx = GetSafeBlockX(box.Right() - bmaporgx);
minx = GetSafeBlockX(box.Left() - bmaporgx);
maxy = GetBlockY(FIXED2DBL(box.Top()));
miny = GetBlockY(FIXED2DBL(box.Bottom()));
maxx = GetBlockX(FIXED2DBL(box.Right()));
minx = GetBlockX(FIXED2DBL(box.Left()));
ClearHash();
Reset();
}
@ -1026,9 +1025,9 @@ AActor *FBlockThingsIterator::Next(bool centeronly)
if (centeronly)
{
// Block boundaries for compatibility mode
fixed_t blockleft = (curx << MAPBLOCKSHIFT) + bmaporgx;
fixed_t blockleft = (curx << MAPBLOCKSHIFT) + FLOAT2FIXED(bmaporgx);
fixed_t blockright = blockleft + MAPBLOCKSIZE;
fixed_t blockbottom = (cury << MAPBLOCKSHIFT) + bmaporgy;
fixed_t blockbottom = (cury << MAPBLOCKSHIFT) + FLOAT2FIXED(bmaporgy);
fixed_t blocktop = blockbottom + MAPBLOCKSIZE;
// only return actors with the center in this block
@ -1517,16 +1516,19 @@ void FPathTraverse::init (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, int fl
intercept_index = intercepts.Size();
this->startfrac = startfrac;
if ( ((x1-bmaporgx)&(MAPBLOCKSIZE-1)) == 0)
fixed_t _f_bmaporgx = FLOAT2FIXED(bmaporgx);
fixed_t _f_bmaporgy = FLOAT2FIXED(bmaporgy);
if ( ((x1-_f_bmaporgx)&(MAPBLOCKSIZE-1)) == 0)
x1 += FRACUNIT; // don't side exactly on a line
if ( ((y1-bmaporgy)&(MAPBLOCKSIZE-1)) == 0)
if ( ((y1-_f_bmaporgy)&(MAPBLOCKSIZE-1)) == 0)
y1 += FRACUNIT; // don't side exactly on a line
_x1 = (long long)x1 - bmaporgx;
_y1 = (long long)y1 - bmaporgy;
x1 -= bmaporgx;
y1 -= bmaporgy;
_x1 = (long long)x1 - _f_bmaporgx;
_y1 = (long long)y1 - _f_bmaporgy;
x1 -= _f_bmaporgx;
y1 -= _f_bmaporgy;
xt1 = int(_x1 >> MAPBLOCKSHIFT);
yt1 = int(_y1 >> MAPBLOCKSHIFT);
@ -1541,10 +1543,10 @@ void FPathTraverse::init (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, int fl
}
else
{
_x2 = (long long)x2 - bmaporgx;
_y2 = (long long)y2 - bmaporgy;
x2 -= bmaporgx;
y2 -= bmaporgy;
_x2 = (long long)x2 - _f_bmaporgx;
_y2 = (long long)y2 - _f_bmaporgy;
x2 -= _f_bmaporgx;
y2 -= _f_bmaporgy;
xt2 = int(_x2 >> MAPBLOCKSHIFT);
yt2 = int(_y2 >> MAPBLOCKSHIFT);
}
@ -1758,8 +1760,8 @@ AActor *P_BlockmapSearch (AActor *mo, int distance, AActor *(*check)(AActor*, in
int count;
AActor *target;
startX = GetSafeBlockX(mo->_f_X()-bmaporgx);
startY = GetSafeBlockY(mo->_f_Y()-bmaporgy);
startX = GetBlockX(mo->X());
startY = GetBlockY(mo->Y());
validcount++;
if (startX >= 0 && startX < bmapwidth && startY >= 0 && startY < bmapheight)

View file

@ -171,10 +171,8 @@ int bmapheight; // size in mapblocks
int *blockmap; // int for larger maps ([RH] Made int because BOOM does)
int *blockmaplump; // offsets in blockmap are from here
fixed_t bmaporgx; // origin of block map
fixed_t bmaporgy;
int bmapnegx; // min negs of block map before wrapping
int bmapnegy;
double bmaporgx; // origin of block map
double bmaporgy;
FBlockNode** blocklinks; // for thing chains
@ -3076,15 +3074,10 @@ void P_LoadBlockMap (MapData * map)
}
bmaporgx = blockmaplump[0] << FRACBITS;
bmaporgy = blockmaplump[1] << FRACBITS;
bmaporgx = blockmaplump[0];
bmaporgy = blockmaplump[1];
bmapwidth = blockmaplump[2];
bmapheight = blockmaplump[3];
// MAES: set blockmapxneg and blockmapyneg
// E.g. for a full 512x512 map, they should be both
// -1. For a 257*257, they should be both -255 etc.
bmapnegx = bmapwidth > 255 ? bmapwidth - 512 : -257;
bmapnegy = bmapheight > 255 ? bmapheight - 512 : -257;
// clear out mobj chains
count = bmapwidth*bmapheight;

View file

@ -632,9 +632,6 @@ bool SightCheck::P_SightPathTraverse ()
portals.Push({ 0, topslope, bottomslope, sector_t::floor, lastsector->SkyBoxes[sector_t::floor]->Sector->PortalGroup });
}
double bmaporgx = FIXED2DBL(::bmaporgx);
double bmaporgy = FIXED2DBL(::bmaporgy);
x1 -= bmaporgx;
y1 -= bmaporgy;
xt1 = x1 / MAPBLOCKUNITS;

View file

@ -837,15 +837,6 @@ enum
//Spawns teleport fog. Pass the actor to pluck TeleFogFromType and TeleFogToType. 'from' determines if this is the fog to spawn at the old position (true) or new (false).
void P_SpawnTeleportFog(AActor *mobj, const DVector3 &pos, bool beforeTele = true, bool setTarget = false);
void P_SpawnTeleportFog(AActor *mobj, fixed_t x, fixed_t y, fixed_t z, bool beforeTele = true, bool setTarget = false) = delete;
inline void P_SpawnTeleportFog(AActor *mobj, const fixedvec3 &pos, bool beforeTele = true, bool setTarget = false) = delete;
inline void P_SpawnTeleportFog(AActor *mobj, double x, double y, double z, bool beforeTele = true, bool setTarget = false) = delete;
/*
{
P_SpawnTeleportFog(mobj, FLOAT2FIXED(x), FLOAT2FIXED(y), FLOAT2FIXED(z), beforeTele, setTarget);
}
*/
inline bool P_Teleport(AActor *thing, DVector3 pos, DAngle angle, int flags);
bool EV_Teleport (int tid, int tag, line_t *line, int side, AActor *thing, int flags);
bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBOOL reverse);

View file

@ -165,8 +165,8 @@ void FTraceInfo::EnterSectorPortal(int position, double frac, sector_t *entersec
if (aimdir != -1 && aimdir != position) return;
AActor *portal = entersec->SkyBoxes[position];
if (aimdir == sector_t::ceiling && FLOAT2FIXED(portal->specialf1) < limitz) return;
else if (aimdir == sector_t::floor && FLOAT2FIXED(portal->specialf1) > limitz) return;
if (aimdir == sector_t::ceiling && portal->specialf1 < limitz) return;
else if (aimdir == sector_t::floor && portal->specialf1 > limitz) return;
FTraceInfo newtrace;
FTraceResults results;
@ -785,7 +785,7 @@ bool FTraceInfo::TraceTraverse (int ptflags)
}
// We have something closer in the storage for portal subtraces.
if (TempResults->HitType != TRACE_HitNone && FIXED2DBL(in->frac) > TempResults->Fraction)
if (TempResults->HitType != TRACE_HitNone && in->Frac > TempResults->Fraction)
{
break;
}

View file

@ -32,6 +32,7 @@
#include "p_blockmap.h"
#include "p_maputl.h"
#include "r_utility.h"
#include "p_blockmap.h"
// MACROS ------------------------------------------------------------------
@ -1095,10 +1096,10 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd)
ld = sd->linedef;
top = int((ld->bbox[BOXTOP] - FIXED2DBL(bmaporgy)) / 128.);
bottom = int((ld->bbox[BOXBOTTOM] - FIXED2DBL(bmaporgy)) / 128.);
left = int((ld->bbox[BOXLEFT] - FIXED2DBL(bmaporgx)) / 128.);
right = int((ld->bbox[BOXRIGHT] - FIXED2DBL(bmaporgx)) / 128.);
top = GetBlockY(ld->bbox[BOXTOP]);
bottom = GetBlockY(ld->bbox[BOXBOTTOM]);
left = GetBlockX(ld->bbox[BOXLEFT]);
right = GetBlockX(ld->bbox[BOXRIGHT]);
blocked = false;
checker.Clear();
@ -1219,10 +1220,10 @@ void FPolyObj::LinkPolyobj ()
vt = Sidedefs[i]->linedef->v2;
Bounds.AddToBox(vt->fixX(), vt->fixY());
}
bbox[BOXRIGHT] = GetSafeBlockX(Bounds.Right() - bmaporgx);
bbox[BOXLEFT] = GetSafeBlockX(Bounds.Left() - bmaporgx);
bbox[BOXTOP] = GetSafeBlockY(Bounds.Top() - bmaporgy);
bbox[BOXBOTTOM] = GetSafeBlockY(Bounds.Bottom() - bmaporgy);
bbox[BOXRIGHT] = GetBlockX(FIXED2DBL(Bounds.Right()));
bbox[BOXLEFT] = GetBlockX(FIXED2DBL(Bounds.Left()));
bbox[BOXTOP] = GetBlockY(FIXED2DBL(Bounds.Top()));
bbox[BOXBOTTOM] = GetBlockY(FIXED2DBL(Bounds.Bottom()));
// add the polyobj to each blockmap section
for(int j = bbox[BOXBOTTOM]*bmapwidth; j <= bbox[BOXTOP]*bmapwidth;
j += bmapwidth)

View file

@ -693,8 +693,8 @@ fixedvec2 P_GetOffsetPosition(fixed_t x, fixed_t y, fixed_t dx, fixed_t dy)
// Try some easily discoverable early-out first. If we know that the trace cannot possibly find a portal, this saves us from calling the traverser completely for vast parts of the map.
if (dx < 128 * FRACUNIT && dy < 128 * FRACUNIT)
{
fixed_t blockx = GetSafeBlockX(actx - bmaporgx);
fixed_t blocky = GetSafeBlockY(acty - bmaporgy);
int blockx = GetBlockX(FIXED2DBL(actx));
int blocky = GetBlockY(FIXED2DBL(acty));
if (blockx < 0 || blocky < 0 || blockx >= bmapwidth || blocky >= bmapheight || !PortalBlockmap(blockx, blocky).neighborContainsLines) return dest;
}
@ -1096,8 +1096,8 @@ void P_CreateLinkedPortals()
{
// This is a fatal condition. We have to remove one of the two portals. Choose the one that doesn't match the current plane
Printf("Error in sector %d: Ceiling portal at z=%d is below floor portal at z=%d\n", i, cz, fz);
fixed_t cp = -sectors[i].ceilingplane.fixD();
fixed_t fp = -sectors[i].ceilingplane.fixD();
double cp = -sectors[i].ceilingplane.fD();
double fp = -sectors[i].ceilingplane.fD();
if (cp < fp || fz == fp)
{
sectors[i].SkyBoxes[sector_t::ceiling] = NULL;

View file

@ -315,32 +315,6 @@ public:
d = FLOAT2FIXED(dd);
}
void changeD(double dd)
{
d += FLOAT2FIXED(dd);
}
fixed_t fixA() const
{
return a;
}
fixed_t fixB() const
{
return b;
}
fixed_t fixC() const
{
return c;
}
fixed_t fixD() const
{
return d;
}
fixed_t fixiC() const
{
return ic;
}
double fA() const
{
return FIXED2DBL(a);

View file

@ -91,7 +91,7 @@ visplane_t *ceilingplane;
// Empirically verified to be fairly uniform:
#define visplane_hash(picnum,lightlevel,height) \
((unsigned)((picnum)*3+(lightlevel)+((height).fixD())*7) & (MAXVISPLANES-1))
((unsigned)((picnum)*3+(lightlevel)+(FLOAT2FIXED((height).fD()))*7) & (MAXVISPLANES-1))
// These are copies of the main parameters used when drawing stacked sectors.
// When you change the main parameters, you should copy them here too *unless*
@ -605,7 +605,7 @@ visplane_t *R_FindPlane (const secplane_t &height, FTextureID picnum, int lightl
// always necessary, but it is needed if a floor and ceiling sky are in the
// same column but separated by a wall. If they both try to reside in the
// same visplane, then only the floor sky will be drawn.
plane.set(0, 0, height.fixC(), 0);
plane.set(0., 0., height.fC(), 0.);
isskybox = skybox != NULL && !skybox->bInSkybox;
}
else if (skybox != NULL && skybox->bAlways && !skybox->bInSkybox)
@ -1564,7 +1564,7 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
basexfrac = FixedMul (xscale, finecosine[planeang]) + x*xstepscale;
baseyfrac = FixedMul (yscale, -finesine[planeang]) + x*ystepscale;
planeheight = abs (FixedMul (pl->height.fixD(), -pl->height.fixiC()) - viewz);
planeheight = abs (int(pl->height.fD() * -pl->height.fiC() * 65536) - viewz);
GlobVis = FixedDiv (r_FloorVisibility, planeheight);
if (fixedlightlev >= 0)

View file

@ -162,8 +162,8 @@ enum SICommands
struct FBloodSFX
{
DWORD RelVol; // volume, 0-255
fixed_t Pitch; // pitch change
fixed_t PitchRange; // range of random pitch
int Pitch; // pitch change
int PitchRange; // range of random pitch
DWORD Format; // format of audio 1=11025 5=22050
SDWORD LoopStart; // loop position (-1 means no looping)
char RawName[9]; // name of RAW resource

View file

@ -540,7 +540,7 @@ void S_ParseSndSeq (int levellump)
int delaybase;
float volumebase;
int curseq = -1;
fixed_t val;
int val;
// First free the old SNDSEQ data. This allows us to reload this for each level
// and specify a level specific SNDSEQ lump!