mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-16 09:21:36 +00:00
Clean up astub.c:CheckMapCorruption() and some build.c code a little.
There are no intended changes of functionality, it's readability tweaks only. git-svn-id: https://svn.eduke32.com/eduke32@4568 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
1486a2937b
commit
21b852cd0d
2 changed files with 91 additions and 74 deletions
|
@ -7111,7 +7111,8 @@ check_next_sector: ;
|
|||
|
||||
if (doSectorSplit && k==loopnum)
|
||||
continue;
|
||||
if (!doSectorSplit && (k == loopnumofsector(ovh.splitsect,ovh.splitstartwall) || k == loopnumofsector(ovh.splitsect,splitendwall)))
|
||||
if (!doSectorSplit && (k == loopnumofsector(ovh.splitsect,ovh.splitstartwall) ||
|
||||
k == loopnumofsector(ovh.splitsect,splitendwall)))
|
||||
continue;
|
||||
|
||||
i = k;
|
||||
|
@ -7180,7 +7181,7 @@ check_next_sector: ;
|
|||
|
||||
numsectors += 1 + doSectorSplit;
|
||||
|
||||
k = danumwalls-numwalls; //Back of number of walls of new sector for later
|
||||
k = danumwalls-numwalls; //Back up number of walls of new sector for later
|
||||
numwalls = danumwalls;
|
||||
|
||||
//clear out old sector's next pointers for clean deletesector
|
||||
|
@ -8444,21 +8445,22 @@ static int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls)
|
|||
if ((x1 <= dax && dax <= x2) || (x2 <= dax && dax <= x1))
|
||||
if ((y1 <= day && day <= y2) || (y2 <= day && day <= y1))
|
||||
if ((dax-x1)*(y2-y1) == (day-y1)*(x2-x1))
|
||||
return(1); //insertpoint((short)i,dax,day,NULL);
|
||||
return 1; //insertpoint((short)i,dax,day,NULL);
|
||||
}
|
||||
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// wallstart has to be the starting wall of a loop!
|
||||
static int32_t clockdir(int16_t wallstart) //Returns: 0 is CW, 1 is CCW
|
||||
// <wallstart> has to be the starting (i.e. least index) wall of a loop!
|
||||
// Returns: CLOCKDIR_CW or CLOCKDIR_CCW.
|
||||
static int32_t clockdir(int32_t wallstart)
|
||||
{
|
||||
int16_t i, themin;
|
||||
int32_t minx, tempint, x0, x1, x2, y0, y1, y2;
|
||||
int32_t tempint, x0, x1, x2, y0, y1, y2;
|
||||
|
||||
int32_t minx = 0x7fffffff;
|
||||
int32_t themin = -1;
|
||||
int32_t i = wallstart-1;
|
||||
|
||||
minx = 0x7fffffff;
|
||||
themin = -1;
|
||||
i = wallstart-1;
|
||||
do
|
||||
{
|
||||
i++;
|
||||
|
@ -8468,7 +8470,11 @@ static int32_t clockdir(int16_t wallstart) //Returns: 0 is CW, 1 is CCW
|
|||
themin = i;
|
||||
}
|
||||
}
|
||||
while ((wall[i].point2 != wallstart) && (i < MAXWALLS));
|
||||
while (wall[i].point2 != wallstart && i < MAXWALLS-1);
|
||||
// NOTE: the i < MAXWALLS-1 check is really only safety against either
|
||||
// - a really corrupt map, or
|
||||
// - misuse of clockdir() where <wallstart> is not the starting wall of
|
||||
// the very last loop
|
||||
|
||||
x0 = wall[themin].x;
|
||||
y0 = wall[themin].y;
|
||||
|
@ -8477,14 +8483,16 @@ static int32_t clockdir(int16_t wallstart) //Returns: 0 is CW, 1 is CCW
|
|||
x2 = POINT2(wall[themin].point2).x;
|
||||
y2 = POINT2(wall[themin].point2).y;
|
||||
|
||||
if (y1 >= y2 && y1 <= y0) return(0);
|
||||
if (y1 >= y0 && y1 <= y2) return(1);
|
||||
if (y1 >= y2 && y1 <= y0)
|
||||
return CLOCKDIR_CW;
|
||||
if (y1 >= y0 && y1 <= y2)
|
||||
return CLOCKDIR_CCW;
|
||||
|
||||
tempint = (x0-x1)*(y2-y1) - (x2-x1)*(y0-y1);
|
||||
if (tempint < 0)
|
||||
return(0);
|
||||
return CLOCKDIR_CW;
|
||||
else
|
||||
return(1);
|
||||
return CLOCKDIR_CCW;
|
||||
}
|
||||
|
||||
static void flipwalls(int16_t numwalls, int16_t newnumwalls)
|
||||
|
@ -8822,38 +8830,44 @@ static void clearministatbar16(void)
|
|||
enddrawing();
|
||||
}
|
||||
|
||||
// startwall has to be the starting wall of a loop!
|
||||
static int16_t loopinside(int32_t x, int32_t y, int16_t startwall)
|
||||
// <startwall> has to be the starting wall of a loop!
|
||||
//
|
||||
// Assuming that <startwall> indicates a CW (outer) loop, the return value can
|
||||
// be seen as a boolean of whether (x,y) is inside it.
|
||||
//
|
||||
// XXX: this function suffers from asymmetry issues in degenerate cases,
|
||||
// similar to how inside() did before r3898.
|
||||
static int32_t loopinside(int32_t x, int32_t y, int16_t startwall)
|
||||
{
|
||||
int32_t x1, y1, x2, y2;
|
||||
int16_t i, cnt;
|
||||
int32_t cnt = clockdir(startwall);
|
||||
int32_t i = startwall;
|
||||
|
||||
cnt = clockdir(startwall);
|
||||
i = startwall;
|
||||
do
|
||||
{
|
||||
x1 = wall[i].x;
|
||||
x2 = POINT2(i).x;
|
||||
int32_t x1 = wall[i].x;
|
||||
int32_t x2 = POINT2(i).x;
|
||||
|
||||
if (x1 >= x || x2 >= x)
|
||||
if (x <= x1 || x <= x2)
|
||||
{
|
||||
y1 = wall[i].y;
|
||||
y2 = POINT2(i).y;
|
||||
int32_t y1 = wall[i].y;
|
||||
int32_t y2 = POINT2(i).y;
|
||||
|
||||
if (y1 > y2)
|
||||
{
|
||||
swaplong(&x1, &x2);
|
||||
swaplong(&y1, &y2);
|
||||
}
|
||||
if (y1 <= y && y2 > y)
|
||||
|
||||
if (y1 <= y && y < y2)
|
||||
if (x1*(y-y2)+x2*(y1-y) <= x*(y1-y2))
|
||||
cnt ^= 1;
|
||||
}
|
||||
|
||||
i = wall[i].point2;
|
||||
}
|
||||
while (i != startwall);
|
||||
|
||||
return(cnt);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -577,16 +577,11 @@ int32_t map_undoredo(int32_t dir)
|
|||
#define CCHK_CORRECTED OSDTEXT_GREEN " -> "
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define CORRUPTCHK_PRINT(errlev, what, fmt, ...) do \
|
||||
{ \
|
||||
bad = max(bad, errlev); \
|
||||
if (numcorruptthings>=MAXCORRUPTTHINGS) \
|
||||
goto too_many_errors; \
|
||||
corruptthings[numcorruptthings++] = (what); \
|
||||
if (errlev >= printfromlev) \
|
||||
OSD_Printf("#%d: " fmt "\n", numcorruptthings, ## __VA_ARGS__); \
|
||||
} while (0)
|
||||
# define OSD_Printf_CChk OSD_Printf
|
||||
#else
|
||||
# define OSD_Printf_CChk OSD_Printf_nowarn
|
||||
#endif
|
||||
|
||||
#define CORRUPTCHK_PRINT(errlev, what, fmt, ...) do \
|
||||
{ \
|
||||
bad = max(bad, errlev); \
|
||||
|
@ -594,9 +589,9 @@ int32_t map_undoredo(int32_t dir)
|
|||
goto too_many_errors; \
|
||||
corruptthings[numcorruptthings++] = (what); \
|
||||
if (errlev >= printfromlev) \
|
||||
OSD_Printf_nowarn("#%d: " fmt "\n", numcorruptthings, ## __VA_ARGS__); \
|
||||
OSD_Printf_CChk("#%d: " fmt "\n", numcorruptthings, ## __VA_ARGS__); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef YAX_ENABLE
|
||||
static int32_t walls_have_equal_endpoints(int32_t w1, int32_t w2)
|
||||
{
|
||||
|
@ -852,7 +847,7 @@ static int32_t check_spritelist_consistency()
|
|||
|
||||
int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
||||
{
|
||||
int32_t i, j, w0, numw, endwall, ns, nw;
|
||||
int32_t i, j;
|
||||
int32_t ewall=0; // expected wall index
|
||||
|
||||
int32_t errlevel=0, bad=0;
|
||||
|
@ -892,10 +887,11 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
|
||||
for (i=0; i<numsectors; i++)
|
||||
{
|
||||
bad = 0;
|
||||
const int32_t w0 = sector[i].wallptr;
|
||||
const int32_t numw = sector[i].wallnum;
|
||||
const int32_t endwall = w0 + numw - 1; // inclusive
|
||||
|
||||
w0 = sector[i].wallptr;
|
||||
numw = sector[i].wallnum;
|
||||
bad = 0;
|
||||
|
||||
if (w0 < 0 || w0 > numwalls)
|
||||
{
|
||||
|
@ -915,8 +911,7 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
|
||||
ewall += numw;
|
||||
|
||||
endwall = w0 + numw;
|
||||
if (endwall > numwalls)
|
||||
if (endwall >= numwalls)
|
||||
CORRUPTCHK_PRINT(5, CORRUPT_SECTOR|i, "SECTOR[%d]: wallptr+wallnum=%d out of range: numwalls=%d", i, endwall, numwalls);
|
||||
|
||||
// inconsistent cstat&2 and heinum checker
|
||||
|
@ -952,14 +947,17 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
|
||||
errlevel = max(errlevel, bad);
|
||||
|
||||
if (bad<4)
|
||||
if (bad < 4)
|
||||
{
|
||||
endwall--;
|
||||
|
||||
for (j=w0; j<=endwall; j++)
|
||||
{
|
||||
const int32_t nw = wall[j].nextwall;
|
||||
const int32_t ns = wall[j].nextsector;
|
||||
|
||||
bad = 0;
|
||||
|
||||
// First, some basic wall sanity checks.
|
||||
|
||||
if (wall[j].point2 < w0 || wall[j].point2 > endwall)
|
||||
{
|
||||
if (wall[j].point2 < 0 || wall[j].point2 >= MAXWALLS)
|
||||
|
@ -970,11 +968,9 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
j, TrackerCast(wall[j].point2), w0, endwall);
|
||||
}
|
||||
|
||||
nw = wall[j].nextwall;
|
||||
|
||||
if (nw >= numwalls)
|
||||
{
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int32_t onumct = numcorruptthings;
|
||||
|
||||
if (TRYFIX_NONE())
|
||||
{
|
||||
|
@ -993,11 +989,9 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
}
|
||||
}
|
||||
|
||||
ns = wall[j].nextsector;
|
||||
|
||||
if (ns >= numsectors)
|
||||
{
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int32_t onumct = numcorruptthings;
|
||||
|
||||
if (TRYFIX_NONE())
|
||||
{
|
||||
|
@ -1023,12 +1017,14 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
CORRUPTCHK_PRINT(3, CORRUPT_WALL|j, "WALL[%d] has length 0", j);
|
||||
|
||||
#ifdef YAX_ENABLE
|
||||
// Various TROR checks.
|
||||
{
|
||||
int32_t cf, ynw, ynwp2;
|
||||
int32_t cf;
|
||||
|
||||
for (cf=0; cf<2; cf++)
|
||||
{
|
||||
ynw = yax_getnextwall(j, cf);
|
||||
const int32_t ynw = yax_getnextwall(j, cf);
|
||||
|
||||
if (ynw >= 0)
|
||||
{
|
||||
if (ynw >= numwalls)
|
||||
|
@ -1052,8 +1048,8 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
}
|
||||
|
||||
{
|
||||
int16_t bunchnum = yax_getbunch(i, cf);
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int16_t bunchnum = yax_getbunch(i, cf);
|
||||
const int32_t onumct = numcorruptthings;
|
||||
|
||||
if (bunchnum < 0 || bunchnum >= numyaxbunches)
|
||||
{
|
||||
|
@ -1083,9 +1079,9 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
|
||||
if (ynextwallok)
|
||||
{
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int32_t onumct = numcorruptthings;
|
||||
const int32_t ynwp2 = yax_getnextwall(ynw, !cf);
|
||||
|
||||
ynwp2 = yax_getnextwall(ynw, !cf);
|
||||
if (ynwp2 != j)
|
||||
{
|
||||
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL %d's %s=%d's reverse link wrong"
|
||||
|
@ -1105,18 +1101,19 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
}
|
||||
}
|
||||
}
|
||||
} // woot!
|
||||
} // brace woot!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Check for ".nextsector is its own sector"
|
||||
if (ns == i)
|
||||
{
|
||||
if (!bad)
|
||||
{
|
||||
int32_t onumct = numcorruptthings;
|
||||
int32_t safetoclear = (nw==j || (wall[nw].nextwall==-1 && wall[nw].nextsector==-1));
|
||||
const int32_t onumct = numcorruptthings;
|
||||
const int32_t safetoclear = (nw==j || (wall[nw].nextwall==-1 && wall[nw].nextsector==-1));
|
||||
|
||||
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL[%d].NEXTSECTOR is its own sector", j);
|
||||
if (onumct < MAXCORRUPTTHINGS)
|
||||
|
@ -1143,20 +1140,23 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
}
|
||||
}
|
||||
|
||||
// Check for ".nextwall already referenced from wall ..."
|
||||
if (!corruptcheck_noalreadyrefd && nw>=0 && nw<numwalls)
|
||||
{
|
||||
if (seen_nextwalls[nw>>3]&(1<<(nw&7)))
|
||||
{
|
||||
int16_t nwnw, lnws;
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int32_t onumct = numcorruptthings;
|
||||
|
||||
const int16_t lnws = lastnextwallsource[nw];
|
||||
const int16_t nwnw = wall[nw].nextwall;
|
||||
|
||||
lnws = lastnextwallsource[nw];
|
||||
CORRUPTCHK_PRINT(3, CORRUPT_WALL|j, "WALL[%d].NEXTWALL=%d already referenced from wall %d",
|
||||
j, nw, lnws);
|
||||
nwnw = wall[nw].nextwall;
|
||||
|
||||
if (onumct < MAXCORRUPTTHINGS && (nwnw==j || nwnw==lnws))
|
||||
{
|
||||
int32_t walltoclear = nwnw==j ? lnws : j;
|
||||
const int32_t walltoclear = nwnw==j ? lnws : j;
|
||||
|
||||
if (tryfixing & (1ull<<onumct))
|
||||
{
|
||||
wall[walltoclear].nextsector = wall[walltoclear].nextwall = -1;
|
||||
|
@ -1175,9 +1175,11 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
}
|
||||
}
|
||||
|
||||
if (bad<4)
|
||||
// Various checks of .nextsector and .nextwall
|
||||
if (bad < 4)
|
||||
{
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int32_t onumct = numcorruptthings;
|
||||
|
||||
if ((ns^nw)<0)
|
||||
{
|
||||
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL[%d].NEXTSECTOR=%d and .NEXTWALL=%d inconsistent:"
|
||||
|
@ -1240,18 +1242,19 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
|
|||
|
||||
if (klabs(sprite[i].x) > BXY_MAX || klabs(sprite[i].y) > BXY_MAX)
|
||||
{
|
||||
int32_t onumct = numcorruptthings;
|
||||
const int32_t onumct = numcorruptthings;
|
||||
|
||||
CORRUPTCHK_PRINT(3, CORRUPT_SPRITE|i, "SPRITE %d at [%d, %d] is outside the maximal grid range [%d, %d]",
|
||||
i, TrackerCast(sprite[i].x), TrackerCast(sprite[i].y), -BXY_MAX, BXY_MAX);
|
||||
|
||||
if (onumct < MAXCORRUPTTHINGS)
|
||||
{
|
||||
int32_t x=0, y=0, sect=sprite[i].sectnum, ok=0;
|
||||
int32_t x=0, y=0, ok=0;
|
||||
const int32_t sect = sprite[i].sectnum;
|
||||
|
||||
if ((unsigned)sect < (unsigned)numsectors)
|
||||
{
|
||||
int32_t firstwall = sector[sect].wallptr;
|
||||
const int32_t firstwall = sector[sect].wallptr;
|
||||
|
||||
if ((unsigned)firstwall < (unsigned)numwalls)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue