mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-14 08:31:23 +00:00
- Replace >>MAPBLOCKSHIFT with GetSafeBlockX/GetSafeBlockY from Mocha Doom.
SVN r3486 (trunk)
This commit is contained in:
parent
13869d2173
commit
cfd5b84535
5 changed files with 66 additions and 34 deletions
|
@ -46,6 +46,31 @@
|
||||||
#define MAPBMASK (MAPBLOCKSIZE-1)
|
#define MAPBMASK (MAPBLOCKSIZE-1)
|
||||||
#define MAPBTOFRAC (MAPBLOCKSHIFT-FRACBITS)
|
#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
|
// MAXRADIUS is for precalculated sector block boxes
|
||||||
// the spider demon is larger,
|
// the spider demon is larger,
|
||||||
|
|
|
@ -362,10 +362,10 @@ void AActor::LinkToWorld (sector_t *sec)
|
||||||
// link into blockmap (inert things don't need to be in the blockmap)
|
// link into blockmap (inert things don't need to be in the blockmap)
|
||||||
if ( !(flags & MF_NOBLOCKMAP) )
|
if ( !(flags & MF_NOBLOCKMAP) )
|
||||||
{
|
{
|
||||||
int x1 = (x - radius - bmaporgx)>>MAPBLOCKSHIFT;
|
int x1 = GetSafeBlockX(x - radius - bmaporgx);
|
||||||
int x2 = (x + radius - bmaporgx)>>MAPBLOCKSHIFT;
|
int x2 = GetSafeBlockX(x + radius - bmaporgx);
|
||||||
int y1 = (y - radius - bmaporgy)>>MAPBLOCKSHIFT;
|
int y1 = GetSafeBlockY(y - radius - bmaporgy);
|
||||||
int y2 = (y + radius - bmaporgy)>>MAPBLOCKSHIFT;
|
int y2 = GetSafeBlockY(y + radius - bmaporgy);
|
||||||
|
|
||||||
if (x1 >= bmapwidth || x2 < 0 || y1 >= bmapheight || y2 < 0)
|
if (x1 >= bmapwidth || x2 < 0 || y1 >= bmapheight || y2 < 0)
|
||||||
{ // thing is off the map
|
{ // 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
|
// 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.
|
// the line would not be included as one of its subsector's segs.
|
||||||
|
|
||||||
int blockx = (x - bmaporgx) >> MAPBLOCKSHIFT;
|
int blockx = GetSafeBlockX(x - bmaporgx);
|
||||||
int blocky = (y - bmaporgy) >> MAPBLOCKSHIFT;
|
int blocky = GetSafeBlockY(y - bmaporgy);
|
||||||
|
|
||||||
if ((unsigned int)blockx < (unsigned int)bmapwidth &&
|
if ((unsigned int)blockx < (unsigned int)bmapwidth &&
|
||||||
(unsigned int)blocky < (unsigned int)bmapheight)
|
(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)
|
FBlockLinesIterator::FBlockLinesIterator(const FBoundingBox &box)
|
||||||
{
|
{
|
||||||
validcount++;
|
validcount++;
|
||||||
maxy = (box.Top() - bmaporgy) >> MAPBLOCKSHIFT;
|
maxy = GetSafeBlockY(box.Top() - bmaporgy);
|
||||||
miny = (box.Bottom() - bmaporgy) >> MAPBLOCKSHIFT;
|
miny = GetSafeBlockY(box.Bottom() - bmaporgy);
|
||||||
maxx = (box.Right() - bmaporgx) >> MAPBLOCKSHIFT;
|
maxx = GetSafeBlockX(box.Right() - bmaporgx);
|
||||||
minx = (box.Left() - bmaporgx) >> MAPBLOCKSHIFT;
|
minx = GetSafeBlockX(box.Left() - bmaporgx);
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,10 +772,10 @@ FBlockThingsIterator::FBlockThingsIterator(int _minx, int _miny, int _maxx, int
|
||||||
FBlockThingsIterator::FBlockThingsIterator(const FBoundingBox &box)
|
FBlockThingsIterator::FBlockThingsIterator(const FBoundingBox &box)
|
||||||
: DynHash(0)
|
: DynHash(0)
|
||||||
{
|
{
|
||||||
maxy = (box.Top() - bmaporgy) >> MAPBLOCKSHIFT;
|
maxy = GetSafeBlockY(box.Top() - bmaporgy);
|
||||||
miny = (box.Bottom() - bmaporgy) >> MAPBLOCKSHIFT;
|
miny = GetSafeBlockY(box.Bottom() - bmaporgy);
|
||||||
maxx = (box.Right() - bmaporgx) >> MAPBLOCKSHIFT;
|
maxx = GetSafeBlockX(box.Right() - bmaporgx);
|
||||||
minx = (box.Left() - bmaporgx) >> MAPBLOCKSHIFT;
|
minx = GetSafeBlockX(box.Left() - bmaporgx);
|
||||||
ClearHash();
|
ClearHash();
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
@ -1202,13 +1202,13 @@ FPathTraverse::FPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, in
|
||||||
|
|
||||||
x1 -= bmaporgx;
|
x1 -= bmaporgx;
|
||||||
y1 -= bmaporgy;
|
y1 -= bmaporgy;
|
||||||
xt1 = x1>>MAPBLOCKSHIFT;
|
xt1 = GetSafeBlockX(x1);
|
||||||
yt1 = y1>>MAPBLOCKSHIFT;
|
yt1 = GetSafeBlockY(y1);
|
||||||
|
|
||||||
x2 -= bmaporgx;
|
x2 -= bmaporgx;
|
||||||
y2 -= bmaporgy;
|
y2 -= bmaporgy;
|
||||||
xt2 = x2>>MAPBLOCKSHIFT;
|
xt2 = GetSafeBlockX(x2);
|
||||||
yt2 = y2>>MAPBLOCKSHIFT;
|
yt2 = GetSafeBlockY(y2);
|
||||||
|
|
||||||
if (xt2 > xt1)
|
if (xt2 > xt1)
|
||||||
{
|
{
|
||||||
|
@ -1381,8 +1381,8 @@ AActor *P_BlockmapSearch (AActor *mo, int distance, AActor *(*check)(AActor*, in
|
||||||
int count;
|
int count;
|
||||||
AActor *target;
|
AActor *target;
|
||||||
|
|
||||||
startX = (mo->x-bmaporgx)>>MAPBLOCKSHIFT;
|
startX = GetSafeBlockX(mo->x-bmaporgx);
|
||||||
startY = (mo->y-bmaporgy)>>MAPBLOCKSHIFT;
|
startY = GetSafeBlockY(mo->y-bmaporgy);
|
||||||
validcount++;
|
validcount++;
|
||||||
|
|
||||||
if (startX >= 0 && startX < bmapwidth && startY >= 0 && startY < bmapheight)
|
if (startX >= 0 && startX < bmapwidth && startY >= 0 && startY < bmapheight)
|
||||||
|
|
|
@ -164,6 +164,8 @@ int *blockmaplump; // offsets in blockmap are from here
|
||||||
|
|
||||||
fixed_t bmaporgx; // origin of block map
|
fixed_t bmaporgx; // origin of block map
|
||||||
fixed_t bmaporgy;
|
fixed_t bmaporgy;
|
||||||
|
int bmapnegx; // min negs of block map before wrapping
|
||||||
|
int bmapnegy;
|
||||||
|
|
||||||
FBlockNode** blocklinks; // for thing chains
|
FBlockNode** blocklinks; // for thing chains
|
||||||
|
|
||||||
|
@ -2960,10 +2962,15 @@ void P_LoadBlockMap (MapData * map)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bmaporgx = blockmaplump[0]<<FRACBITS;
|
bmaporgx = blockmaplump[0] << FRACBITS;
|
||||||
bmaporgy = blockmaplump[1]<<FRACBITS;
|
bmaporgy = blockmaplump[1] << FRACBITS;
|
||||||
bmapwidth = blockmaplump[2];
|
bmapwidth = blockmaplump[2];
|
||||||
bmapheight = blockmaplump[3];
|
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
|
// clear out mobj chains
|
||||||
count = bmapwidth*bmapheight;
|
count = bmapwidth*bmapheight;
|
||||||
|
|
|
@ -484,13 +484,13 @@ bool SightCheck::P_SightPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_
|
||||||
|
|
||||||
x1 -= bmaporgx;
|
x1 -= bmaporgx;
|
||||||
y1 -= bmaporgy;
|
y1 -= bmaporgy;
|
||||||
xt1 = x1>>MAPBLOCKSHIFT;
|
xt1 = GetSafeBlockX(x1);
|
||||||
yt1 = y1>>MAPBLOCKSHIFT;
|
yt1 = GetSafeBlockY(y1);
|
||||||
|
|
||||||
x2 -= bmaporgx;
|
x2 -= bmaporgx;
|
||||||
y2 -= bmaporgy;
|
y2 -= bmaporgy;
|
||||||
xt2 = x2>>MAPBLOCKSHIFT;
|
xt2 = GetSafeBlockX(x2);
|
||||||
yt2 = y2>>MAPBLOCKSHIFT;
|
yt2 = GetSafeBlockY(y2);
|
||||||
|
|
||||||
// points should never be out of bounds, but check once instead of
|
// points should never be out of bounds, but check once instead of
|
||||||
// each block
|
// each block
|
||||||
|
|
|
@ -1159,10 +1159,10 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd)
|
||||||
|
|
||||||
ld = sd->linedef;
|
ld = sd->linedef;
|
||||||
|
|
||||||
top = (ld->bbox[BOXTOP]-bmaporgy) >> MAPBLOCKSHIFT;
|
top = GetSafeBlockY(ld->bbox[BOXTOP]-bmaporgy);
|
||||||
bottom = (ld->bbox[BOXBOTTOM]-bmaporgy) >> MAPBLOCKSHIFT;
|
bottom = GetSafeBlockY(ld->bbox[BOXBOTTOM]-bmaporgy);
|
||||||
left = (ld->bbox[BOXLEFT]-bmaporgx) >> MAPBLOCKSHIFT;
|
left = GetSafeBlockX(ld->bbox[BOXLEFT]-bmaporgx);
|
||||||
right = (ld->bbox[BOXRIGHT]-bmaporgx) >> MAPBLOCKSHIFT;
|
right = GetSafeBlockX(ld->bbox[BOXRIGHT]-bmaporgx);
|
||||||
|
|
||||||
blocked = false;
|
blocked = false;
|
||||||
checker.Clear();
|
checker.Clear();
|
||||||
|
@ -1268,10 +1268,10 @@ void FPolyObj::LinkPolyobj ()
|
||||||
vt = Sidedefs[i]->linedef->v2;
|
vt = Sidedefs[i]->linedef->v2;
|
||||||
Bounds.AddToBox(vt->x, vt->y);
|
Bounds.AddToBox(vt->x, vt->y);
|
||||||
}
|
}
|
||||||
bbox[BOXRIGHT] = (Bounds.Right() - bmaporgx) >> MAPBLOCKSHIFT;
|
bbox[BOXRIGHT] = GetSafeBlockX(Bounds.Right() - bmaporgx);
|
||||||
bbox[BOXLEFT] = (Bounds.Left() - bmaporgx) >> MAPBLOCKSHIFT;
|
bbox[BOXLEFT] = GetSafeBlockX(Bounds.Left() - bmaporgx);
|
||||||
bbox[BOXTOP] = (Bounds.Top() - bmaporgy) >> MAPBLOCKSHIFT;
|
bbox[BOXTOP] = GetSafeBlockY(Bounds.Top() - bmaporgy);
|
||||||
bbox[BOXBOTTOM] = (Bounds.Bottom() - bmaporgy) >> MAPBLOCKSHIFT;
|
bbox[BOXBOTTOM] = GetSafeBlockY(Bounds.Bottom() - bmaporgy);
|
||||||
// add the polyobj to each blockmap section
|
// add the polyobj to each blockmap section
|
||||||
for(int j = bbox[BOXBOTTOM]*bmapwidth; j <= bbox[BOXTOP]*bmapwidth;
|
for(int j = bbox[BOXBOTTOM]*bmapwidth; j <= bbox[BOXTOP]*bmapwidth;
|
||||||
j += bmapwidth)
|
j += bmapwidth)
|
||||||
|
|
Loading…
Reference in a new issue