- Replace >>MAPBLOCKSHIFT with GetSafeBlockX/GetSafeBlockY from Mocha Doom.

SVN r3486 (trunk)
This commit is contained in:
Randy Heit 2012-03-28 03:49:38 +00:00
parent 13869d2173
commit cfd5b84535
5 changed files with 66 additions and 34 deletions

View file

@ -46,6 +46,31 @@
#define MAPBMASK (MAPBLOCKSIZE-1)
#define MAPBTOFRAC (MAPBLOCKSHIFT-FRACBITS)
// Inspired by Maes
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);
}
// MAXRADIUS is for precalculated sector block boxes
// the spider demon is larger,

View file

@ -362,10 +362,10 @@ void AActor::LinkToWorld (sector_t *sec)
// link into blockmap (inert things don't need to be in the blockmap)
if ( !(flags & MF_NOBLOCKMAP) )
{
int x1 = (x - radius - bmaporgx)>>MAPBLOCKSHIFT;
int x2 = (x + radius - bmaporgx)>>MAPBLOCKSHIFT;
int y1 = (y - radius - bmaporgy)>>MAPBLOCKSHIFT;
int y2 = (y + radius - bmaporgy)>>MAPBLOCKSHIFT;
int x1 = GetSafeBlockX(x - radius - bmaporgx);
int x2 = GetSafeBlockX(x + radius - bmaporgx);
int y1 = GetSafeBlockY(y - radius - bmaporgy);
int y2 = GetSafeBlockY(y + radius - bmaporgy);
if (x1 >= bmapwidth || x2 < 0 || y1 >= bmapheight || y2 < 0)
{ // thing is off the map
@ -491,8 +491,8 @@ sector_t *AActor::LinkToWorldForMapThing ()
// one-sided line might go into a subsector behind the line, so
// the line would not be included as one of its subsector's segs.
int blockx = (x - bmaporgx) >> MAPBLOCKSHIFT;
int blocky = (y - bmaporgy) >> MAPBLOCKSHIFT;
int blockx = GetSafeBlockX(x - bmaporgx);
int blocky = GetSafeBlockY(y - bmaporgy);
if ((unsigned int)blockx < (unsigned int)bmapwidth &&
(unsigned int)blocky < (unsigned int)bmapheight)
@ -637,10 +637,10 @@ FBlockLinesIterator::FBlockLinesIterator(int _minx, int _miny, int _maxx, int _m
FBlockLinesIterator::FBlockLinesIterator(const FBoundingBox &box)
{
validcount++;
maxy = (box.Top() - bmaporgy) >> MAPBLOCKSHIFT;
miny = (box.Bottom() - bmaporgy) >> MAPBLOCKSHIFT;
maxx = (box.Right() - bmaporgx) >> MAPBLOCKSHIFT;
minx = (box.Left() - bmaporgx) >> MAPBLOCKSHIFT;
maxy = GetSafeBlockY(box.Top() - bmaporgy);
miny = GetSafeBlockY(box.Bottom() - bmaporgy);
maxx = GetSafeBlockX(box.Right() - bmaporgx);
minx = GetSafeBlockX(box.Left() - bmaporgx);
Reset();
}
@ -772,10 +772,10 @@ FBlockThingsIterator::FBlockThingsIterator(int _minx, int _miny, int _maxx, int
FBlockThingsIterator::FBlockThingsIterator(const FBoundingBox &box)
: DynHash(0)
{
maxy = (box.Top() - bmaporgy) >> MAPBLOCKSHIFT;
miny = (box.Bottom() - bmaporgy) >> MAPBLOCKSHIFT;
maxx = (box.Right() - bmaporgx) >> MAPBLOCKSHIFT;
minx = (box.Left() - bmaporgx) >> MAPBLOCKSHIFT;
maxy = GetSafeBlockY(box.Top() - bmaporgy);
miny = GetSafeBlockY(box.Bottom() - bmaporgy);
maxx = GetSafeBlockX(box.Right() - bmaporgx);
minx = GetSafeBlockX(box.Left() - bmaporgx);
ClearHash();
Reset();
}
@ -1202,13 +1202,13 @@ FPathTraverse::FPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, in
x1 -= bmaporgx;
y1 -= bmaporgy;
xt1 = x1>>MAPBLOCKSHIFT;
yt1 = y1>>MAPBLOCKSHIFT;
xt1 = GetSafeBlockX(x1);
yt1 = GetSafeBlockY(y1);
x2 -= bmaporgx;
y2 -= bmaporgy;
xt2 = x2>>MAPBLOCKSHIFT;
yt2 = y2>>MAPBLOCKSHIFT;
xt2 = GetSafeBlockX(x2);
yt2 = GetSafeBlockY(y2);
if (xt2 > xt1)
{
@ -1381,8 +1381,8 @@ AActor *P_BlockmapSearch (AActor *mo, int distance, AActor *(*check)(AActor*, in
int count;
AActor *target;
startX = (mo->x-bmaporgx)>>MAPBLOCKSHIFT;
startY = (mo->y-bmaporgy)>>MAPBLOCKSHIFT;
startX = GetSafeBlockX(mo->x-bmaporgx);
startY = GetSafeBlockY(mo->y-bmaporgy);
validcount++;
if (startX >= 0 && startX < bmapwidth && startY >= 0 && startY < bmapheight)

View file

@ -164,6 +164,8 @@ 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;
FBlockNode** blocklinks; // for thing chains
@ -2960,10 +2962,15 @@ void P_LoadBlockMap (MapData * map)
}
bmaporgx = blockmaplump[0]<<FRACBITS;
bmaporgy = blockmaplump[1]<<FRACBITS;
bmaporgx = blockmaplump[0] << FRACBITS;
bmaporgy = blockmaplump[1] << FRACBITS;
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

@ -484,13 +484,13 @@ bool SightCheck::P_SightPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_
x1 -= bmaporgx;
y1 -= bmaporgy;
xt1 = x1>>MAPBLOCKSHIFT;
yt1 = y1>>MAPBLOCKSHIFT;
xt1 = GetSafeBlockX(x1);
yt1 = GetSafeBlockY(y1);
x2 -= bmaporgx;
y2 -= bmaporgy;
xt2 = x2>>MAPBLOCKSHIFT;
yt2 = y2>>MAPBLOCKSHIFT;
xt2 = GetSafeBlockX(x2);
yt2 = GetSafeBlockY(y2);
// points should never be out of bounds, but check once instead of
// each block

View file

@ -1159,10 +1159,10 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd)
ld = sd->linedef;
top = (ld->bbox[BOXTOP]-bmaporgy) >> MAPBLOCKSHIFT;
bottom = (ld->bbox[BOXBOTTOM]-bmaporgy) >> MAPBLOCKSHIFT;
left = (ld->bbox[BOXLEFT]-bmaporgx) >> MAPBLOCKSHIFT;
right = (ld->bbox[BOXRIGHT]-bmaporgx) >> MAPBLOCKSHIFT;
top = GetSafeBlockY(ld->bbox[BOXTOP]-bmaporgy);
bottom = GetSafeBlockY(ld->bbox[BOXBOTTOM]-bmaporgy);
left = GetSafeBlockX(ld->bbox[BOXLEFT]-bmaporgx);
right = GetSafeBlockX(ld->bbox[BOXRIGHT]-bmaporgx);
blocked = false;
checker.Clear();
@ -1268,10 +1268,10 @@ void FPolyObj::LinkPolyobj ()
vt = Sidedefs[i]->linedef->v2;
Bounds.AddToBox(vt->x, vt->y);
}
bbox[BOXRIGHT] = (Bounds.Right() - bmaporgx) >> MAPBLOCKSHIFT;
bbox[BOXLEFT] = (Bounds.Left() - bmaporgx) >> MAPBLOCKSHIFT;
bbox[BOXTOP] = (Bounds.Top() - bmaporgy) >> MAPBLOCKSHIFT;
bbox[BOXBOTTOM] = (Bounds.Bottom() - bmaporgy) >> MAPBLOCKSHIFT;
bbox[BOXRIGHT] = GetSafeBlockX(Bounds.Right() - bmaporgx);
bbox[BOXLEFT] = GetSafeBlockX(Bounds.Left() - bmaporgx);
bbox[BOXTOP] = GetSafeBlockY(Bounds.Top() - bmaporgy);
bbox[BOXBOTTOM] = GetSafeBlockY(Bounds.Bottom() - bmaporgy);
// add the polyobj to each blockmap section
for(int j = bbox[BOXBOTTOM]*bmapwidth; j <= bbox[BOXTOP]*bmapwidth;
j += bmapwidth)