From cfd5b84535b3819734cedc1f8299d83c96a01a90 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 28 Mar 2012 03:49:38 +0000 Subject: [PATCH] - Replace >>MAPBLOCKSHIFT with GetSafeBlockX/GetSafeBlockY from Mocha Doom. SVN r3486 (trunk) --- src/p_local.h | 25 +++++++++++++++++++++++++ src/p_maputl.cpp | 40 ++++++++++++++++++++-------------------- src/p_setup.cpp | 11 +++++++++-- src/p_sight.cpp | 8 ++++---- src/po_man.cpp | 16 ++++++++-------- 5 files changed, 66 insertions(+), 34 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index d738f90b69..f99cace17c 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -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, diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 91c0e1b7cf..24d4337e33 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -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) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 6c5e2d9be1..3558e5af3f 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -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]< 255 ? bmapwidth - 512 : -257; + bmapnegy = bmapheight > 255 ? bmapheight - 512 : -257; // clear out mobj chains count = bmapwidth*bmapheight; diff --git a/src/p_sight.cpp b/src/p_sight.cpp index 3e699cab1c..a914154867 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -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 diff --git a/src/po_man.cpp b/src/po_man.cpp index ec34af3d50..8ad0ba0099 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -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)