From 8b4a87925b83af65ba8ebfe36949378d0d4ac81a Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 22 Jun 2013 11:31:15 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/src/build.c | 20 +++++------ polymer/eduke32/build/src/engine.c | 53 ++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 215491834..c171054bd 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -1782,9 +1782,12 @@ static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal) // insert sprites for (i=0; inumsprites; 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)) + 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; } diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index a664e1f95..f16a9bd91 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -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)