mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
engine.c: apply "usual readability transformations" on inside() and comment it.
The main thing to note is the "half-open" nature of the x/y range checks. git-svn-id: https://svn.eduke32.com/eduke32@3897 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
a3adf3508e
commit
8b4a87925b
2 changed files with 45 additions and 28 deletions
|
@ -1782,9 +1782,12 @@ static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal)
|
|||
// insert sprites
|
||||
for (i=0; i<mapinfo->numsprites; i++)
|
||||
{
|
||||
int32_t sect = onumsectors+mapinfo->sprite[i].sectnum;
|
||||
j = insertsprite(sect, mapinfo->sprite[i].statnum);
|
||||
Bmemcpy(&sprite[j], &mapinfo->sprite[i], sizeof(spritetype));
|
||||
const spritetype *srcspr = &mapinfo->sprite[i];
|
||||
int32_t sect = onumsectors + srcspr->sectnum;
|
||||
|
||||
j = insertsprite(sect, srcspr->statnum);
|
||||
Bassert(j >= 0);
|
||||
Bmemcpy(&sprite[j], srcspr, sizeof(spritetype));
|
||||
sprite[j].sectnum = sect;
|
||||
}
|
||||
|
||||
|
@ -8579,15 +8582,10 @@ int32_t fixspritesectors(void)
|
|||
|
||||
for (j=0; j<numsectors; j++)
|
||||
{
|
||||
if (inside(dax,day, j) != 1)
|
||||
continue;
|
||||
|
||||
if (cz <= sprite[i].z && sprite[i].z <= fz)
|
||||
if (cz <= sprite[i].z && sprite[i].z <= fz && inside(dax,day, j) == 1)
|
||||
{
|
||||
if (fixmaponsave_sprites || (sprite[i].sectnum < 0 || sprite[i].sectnum >= numsectors))
|
||||
if (fixmaponsave_sprites || (unsigned)sprite[i].sectnum >= numsectors+0u)
|
||||
{
|
||||
numfixedsprites++;
|
||||
|
||||
if (printfirsttime == 0)
|
||||
{
|
||||
initprintf("--------------------\n");
|
||||
|
@ -8595,7 +8593,9 @@ int32_t fixspritesectors(void)
|
|||
}
|
||||
initprintf_nowarn("Changed sectnum of sprite #%d from %d to %d\n",
|
||||
i, TrackerCast(sprite[i].sectnum), j);
|
||||
|
||||
changespritesect(i, j);
|
||||
numfixedsprites++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11385,28 +11385,45 @@ int32_t clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1, int32_t
|
|||
//
|
||||
int32_t inside(int32_t x, int32_t y, int16_t sectnum)
|
||||
{
|
||||
walltype *wal;
|
||||
int32_t i, x1, y1, x2, y2;
|
||||
uint32_t cnt;
|
||||
|
||||
if (sectnum < 0 || sectnum >= numsectors)
|
||||
return -1;
|
||||
|
||||
cnt = 0;
|
||||
wal = &wall[sector[sectnum].wallptr];
|
||||
i = sector[sectnum].wallnum;
|
||||
do
|
||||
if (sectnum >= 0 && sectnum < numsectors)
|
||||
{
|
||||
y1 = wal->y-y; y2 = wall[wal->point2].y-y;
|
||||
if ((y1^y2) < 0)
|
||||
uint32_t cnt = 0;
|
||||
walltype *wal = &wall[sector[sectnum].wallptr];
|
||||
int32_t i = sector[sectnum].wallnum;
|
||||
|
||||
do
|
||||
{
|
||||
x1 = wal->x-x; x2 = wall[wal->point2].x-x;
|
||||
if ((x1^x2) >= 0) cnt ^= x1; else cnt ^= (x1*y2-x2*y1)^y2;
|
||||
// Get the y components of the [tested point]-->[wall point{1,2}]
|
||||
// vectors.
|
||||
const int32_t y1 = wal->y - y;
|
||||
const int32_t y2 = wall[wal->point2].y - y;
|
||||
|
||||
// If their signs differ[*], ...
|
||||
//
|
||||
// [*] where '-' corresponds to <0 and '+' corresponds to >=0.
|
||||
// Equivalently, the branch is taken iff
|
||||
// y1 != y2 AND y_m <= wal->y < y_M,
|
||||
// where y_m := min(y1, y2) and y_M := max(y1, y2).
|
||||
if ((y1^y2) < 0)
|
||||
{
|
||||
// ... get the x components.
|
||||
const int32_t x1 = wal->x - x;
|
||||
const int32_t x2 = wall[wal->point2].x - x;
|
||||
|
||||
if ((x1^x2) >= 0)
|
||||
cnt ^= x1;
|
||||
else
|
||||
cnt ^= (x1*y2-x2*y1)^y2;
|
||||
}
|
||||
|
||||
wal++; i--;
|
||||
}
|
||||
wal++; i--;
|
||||
while (i);
|
||||
|
||||
return cnt>>31;
|
||||
}
|
||||
while (i);
|
||||
return(cnt>>31);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t __fastcall getangle(int32_t xvect, int32_t yvect)
|
||||
|
|
Loading…
Reference in a new issue