Replace manual search of clipsectorlist[] in clipmove() and friends with a bitmap

git-svn-id: https://svn.eduke32.com/eduke32@7574 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-04-10 09:31:12 +00:00 committed by Christoph Oelckers
parent 74944c9ed0
commit 9af816af52

View file

@ -18,6 +18,7 @@ static int32_t clipsectnum, origclipsectnum, clipspritenum;
int16_t clipsectorlist[MAXCLIPSECTORS]; int16_t clipsectorlist[MAXCLIPSECTORS];
static int16_t origclipsectorlist[MAXCLIPSECTORS]; static int16_t origclipsectorlist[MAXCLIPSECTORS];
static uint8_t clipsectormap[MAXCLIPSECTORS >> 3]; static uint8_t clipsectormap[MAXCLIPSECTORS >> 3];
static uint8_t origclipsectormap[MAXCLIPSECTORS >> 3];
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
static int16_t clipspritelist[MAXCLIPNUM]; // sector-like sprite clipping static int16_t clipspritelist[MAXCLIPNUM]; // sector-like sprite clipping
#endif #endif
@ -658,7 +659,10 @@ static int32_t clipmove_warned;
static inline void addclipsect(int const sectnum) static inline void addclipsect(int const sectnum)
{ {
if (EDUKE32_PREDICT_TRUE(clipsectnum < MAXCLIPSECTORS)) if (EDUKE32_PREDICT_TRUE(clipsectnum < MAXCLIPSECTORS))
{
bitmap_set(clipsectormap, sectnum);
clipsectorlist[clipsectnum++] = sectnum; clipsectorlist[clipsectnum++] = sectnum;
}
else clipmove_warned |= 1; else clipmove_warned |= 1;
} }
@ -937,15 +941,8 @@ static void clipupdatesector(int32_t const x, int32_t const y, int16_t * const s
int const endwall = sec->wallptr + sec->wallnum; int const endwall = sec->wallptr + sec->wallnum;
for (int j = startwall; j < endwall; j++) for (int j = startwall; j < endwall; j++)
if (wall[j].nextsector >= 0) if (wall[j].nextsector >= 0 && bitmap_test(clipsectormap, wall[j].nextsector))
{
for (int k = 0; k < clipsectnum; k++)
if (clipsectorlist[k] == wall[j].nextsector)
{
bfirst_search_try(sectlist, sectbitmap, &nsecs, wall[j].nextsector); bfirst_search_try(sectlist, sectbitmap, &nsecs, wall[j].nextsector);
break;
}
}
} }
bfirst_search_init(sectlist, sectbitmap, &nsecs, numsectors, *sectnum); bfirst_search_init(sectlist, sectbitmap, &nsecs, numsectors, *sectnum);
@ -1009,6 +1006,8 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int
clipmove_warned = 0; clipmove_warned = 0;
Bmemset(clipsectormap, 0, (numsectors+7)>>3);
do do
{ {
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
@ -1023,6 +1022,7 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int
// init sector-like sprites for clipping // init sector-like sprites for clipping
origclipsectnum = clipsectnum; origclipsectnum = clipsectnum;
Bmemcpy(origclipsectorlist, clipsectorlist, clipsectnum*sizeof(clipsectorlist[0])); Bmemcpy(origclipsectorlist, clipsectorlist, clipsectnum*sizeof(clipsectorlist[0]));
Bmemcpy(origclipsectormap, clipsectormap, (numsectors+7)>>3);
// replace sector and wall with clip map // replace sector and wall with clip map
engineSetClipMap(&origmapinfo, &clipmapinfo); engineSetClipMap(&origmapinfo, &clipmapinfo);
@ -1163,11 +1163,8 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int
else if (wal->nextsector>=0) else if (wal->nextsector>=0)
{ {
if (!curspr && inside(pos->x, pos->y, wal->nextsector) == 1) continue; if (!curspr && inside(pos->x, pos->y, wal->nextsector) == 1) continue;
if (bitmap_test(clipsectormap, wal->nextsector) == 0)
int i; addclipsect(wal->nextsector);
for (i=clipsectnum-1; i>=0; i--)
if (wal->nextsector == clipsectorlist[i]) break;
if (i < 0) addclipsect(wal->nextsector);
} }
} }
@ -1306,6 +1303,7 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int
clipsectnum = origclipsectnum; clipsectnum = origclipsectnum;
Bmemcpy(clipsectorlist, origclipsectorlist, clipsectnum*sizeof(clipsectorlist[0])); Bmemcpy(clipsectorlist, origclipsectorlist, clipsectnum*sizeof(clipsectorlist[0]));
Bmemcpy(clipsectormap, origclipsectormap, (numsectors+7)>>3);
} }
#endif #endif
@ -1396,7 +1394,11 @@ int32_t pushmove(vec3_t * const vect, int16_t * const sectnum,
bad = 0; bad = 0;
clipsectorlist[0] = *sectnum; clipsectorlist[0] = *sectnum;
clipsectcnt = 0; clipsectnum = 1; clipsectcnt = 0;
clipsectnum = 1;
Bmemset(clipsectormap, 0, (numsectors+7)>>3);
do do
{ {
const uwalltype *wal; const uwalltype *wal;
@ -1494,12 +1496,8 @@ int32_t pushmove(vec3_t * const vect, int16_t * const sectnum,
clipupdatesector(vect->x, vect->y, sectnum); clipupdatesector(vect->x, vect->y, sectnum);
if (*sectnum < 0) return -1; if (*sectnum < 0) return -1;
} }
else else if (bitmap_test(clipsectormap, wal->nextsector) == 0)
{ addclipsect(wal->nextsector);
for (j=clipsectnum-1; j>=0; j--)
if (wal->nextsector == clipsectorlist[j]) break;
if (j < 0) addclipsect(wal->nextsector);
}
} }
clipsectcnt++; clipsectcnt++;
@ -1552,6 +1550,7 @@ void getzrange(const vec3_t *pos, int16_t sectnum,
clipsectorlist[0] = sectnum; clipsectorlist[0] = sectnum;
clipsectnum = 1; clipsectnum = 1;
clipspritenum = 0; clipspritenum = 0;
Bmemset(clipsectormap, 0, (numsectors+7)>>3);
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
if (0) if (0)
@ -1658,11 +1657,8 @@ restart_grand:
if (((sec->floorstat&1) == 0) && (pos->z >= sec->floorz-(3<<8))) continue; if (((sec->floorstat&1) == 0) && (pos->z >= sec->floorz-(3<<8))) continue;
} }
int i; if (bitmap_test(clipsectormap, k) == 0)
for (i=clipsectnum-1; i>=0; --i) addclipsect(k);
if (clipsectorlist[i] == k) break;
if (i < 0) addclipsect(k);
if (((v1.x < xmin + MAXCLIPDIST) && (v2.x < xmin + MAXCLIPDIST)) || if (((v1.x < xmin + MAXCLIPDIST) && (v2.x < xmin + MAXCLIPDIST)) ||
((v1.x > xmax - MAXCLIPDIST) && (v2.x > xmax - MAXCLIPDIST)) || ((v1.x > xmax - MAXCLIPDIST) && (v2.x > xmax - MAXCLIPDIST)) ||
@ -2101,8 +2097,10 @@ restart_grand:
*(vec2_t *)&hit->pos = hitscangoal; *(vec2_t *)&hit->pos = hitscangoal;
clipsectorlist[0] = sectnum; clipsectorlist[0] = sectnum;
tempshortcnt = 0; tempshortnum = 1; tempshortcnt = 0;
tempshortnum = 1;
clipspritecnt = clipspritenum = 0; clipspritecnt = clipspritenum = 0;
do do
{ {
int32_t dasector, z, startwall, endwall; int32_t dasector, z, startwall, endwall;
@ -2164,8 +2162,6 @@ restart_grand:
if (curspr && nextsector<0) continue; if (curspr && nextsector<0) continue;
int32_t daz2, zz;
x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y; x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y;
if ((coord_t)(x1-sv->x)*(y2-sv->y) < (coord_t)(x2-sv->x)*(y1-sv->y)) continue; if ((coord_t)(x1-sv->x)*(y2-sv->y) < (coord_t)(x2-sv->x)*(y1-sv->y)) continue;
@ -2182,6 +2178,7 @@ restart_grand:
continue; continue;
} }
int32_t daz2;
getzsofslope(nextsector,intx,inty,&daz,&daz2); getzsofslope(nextsector,intx,inty,&daz,&daz2);
if (intz <= daz || intz >= daz2) if (intz <= daz || intz >= daz2)
{ {
@ -2192,14 +2189,13 @@ restart_grand:
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
else else
{ {
int32_t cz,fz;
if (wal->cstat&dawalclipmask) if (wal->cstat&dawalclipmask)
{ {
hit_set(hit, curspr->sectnum, -1, curspr-(uspritetype *)sprite, intx, inty, intz); hit_set(hit, curspr->sectnum, -1, curspr-(uspritetype *)sprite, intx, inty, intz);
continue; continue;
} }
int32_t cz, fz, daz2;
getzsofslope(nextsector,intx,inty,&daz,&daz2); getzsofslope(nextsector,intx,inty,&daz,&daz2);
getzsofslope(sectq[clipinfo[curidx].qend],intx,inty,&cz,&fz); getzsofslope(sectq[clipinfo[curidx].qend],intx,inty,&cz,&fz);
// ceil cz daz daz2 fz floor // ceil cz daz daz2 fz floor
@ -2210,7 +2206,8 @@ restart_grand:
} }
} }
#endif #endif
for (zz=tempshortnum-1; zz>=0; zz--) int zz;
for (zz = tempshortnum - 1; zz >= 0; zz--)
if (clipsectorlist[zz] == nextsector) break; if (clipsectorlist[zz] == nextsector) break;
if (zz < 0) clipsectorlist[tempshortnum++] = nextsector; if (zz < 0) clipsectorlist[tempshortnum++] = nextsector;
} }