- cleaned up dragpoint

This still contained some code for EDuke32's TROR and used a shared static global array.
It now uses the BFSSearch class to manage its bit array to unlimit the size of its working set and to avoid reallocation.
This commit is contained in:
Christoph Oelckers 2021-11-18 01:15:18 +01:00
parent 7126aa22f4
commit 4e31360fe4
11 changed files with 82 additions and 90 deletions

View file

@ -428,10 +428,10 @@ void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange
int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1,
int32_t x2, int32_t y2, int32_t z2, int16_t sect2); int32_t x2, int32_t y2, int32_t z2, int16_t sect2);
int32_t inside(int32_t x, int32_t y, int sectnum); int32_t inside(int32_t x, int32_t y, int sectnum);
void dragpoint(int pointhighlight, int32_t dax, int32_t day, uint8_t flags = 0); void dragpoint(int pointhighlight, int32_t dax, int32_t day);
inline void dragpoint(walltype* pointhighlight, int32_t dax, int32_t day, uint8_t flags = 0) inline void dragpoint(walltype* pointhighlight, int32_t dax, int32_t day)
{ {
dragpoint(int(pointhighlight - wall), dax, day, 0); dragpoint(int(pointhighlight - wall), dax, day);
} }
int32_t try_facespr_intersect(uspriteptr_t const spr, vec3_t const in, int32_t try_facespr_intersect(uspriteptr_t const spr, vec3_t const in,
int32_t vx, int32_t vy, int32_t vz, int32_t vx, int32_t vy, int32_t vz,

View file

@ -62,8 +62,6 @@ int16_t pskybits_override = -1;
static int32_t beforedrawrooms = 1; static int32_t beforedrawrooms = 1;
static int8_t tempbuf[MAXWALLS];
static int32_t no_radarang2 = 0; static int32_t no_radarang2 = 0;
static int16_t radarang[1280]; static int16_t radarang[1280];
@ -1075,34 +1073,19 @@ void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange,
// //
// dragpoint // dragpoint
// //
// flags: void dragpoint(int w, int32_t dax, int32_t day)
// 1: don't reset walbitmap[] (the bitmap of already dragged vertices)
// 2: In the editor, do wall[].cstat |= (1<<14) also for the lastwall().
void dragpoint(int pointhighlight, int32_t dax, int32_t day, uint8_t flags)
{ {
int32_t i, numyaxwalls=0; BFSSearch walbitmap(numwalls);
static int16_t yaxwalls[MAXWALLS]; int clockwise = 0;
const int tmpstartwall = w;
uint8_t *const walbitmap = (uint8_t *)tempbuf; int cnt = 16384; // limit the number of iterations.
if ((flags&1)==0)
memset(walbitmap, 0, (numwalls+7)>>3);
yaxwalls[numyaxwalls++] = pointhighlight;
for (i=0; i<numyaxwalls; i++)
{
int32_t clockwise = 0;
int32_t w = yaxwalls[i];
const int32_t tmpstartwall = w;
bssize_t cnt = MAXWALLS;
while (1) while (1)
{ {
sector[wall[w].sector].dirty = 255; sector[wall[w].sector].dirty = 255;
wall[w].x = dax; wall[w].x = dax;
wall[w].y = day; wall[w].y = day;
walbitmap[w>>3] |= (1<<(w&7)); walbitmap.Set(w);
if (!clockwise) //search points CCW if (!clockwise) //search points CCW
{ {
@ -1118,8 +1101,7 @@ void dragpoint(int pointhighlight, int32_t dax, int32_t day, uint8_t flags)
cnt--; cnt--;
if (cnt==0) if (cnt==0)
{ {
Printf("dragpoint %d: infloop!\n", pointhighlight); Printf("dragpoint %d: infinite loop!\n", w);
i = numyaxwalls;
break; break;
} }
@ -1132,7 +1114,7 @@ void dragpoint(int pointhighlight, int32_t dax, int32_t day, uint8_t flags)
break; break;
} }
if ((walbitmap[w>>3] & (1<<(w&7)))) if (walbitmap.Check(w))
{ {
if (clockwise) if (clockwise)
break; break;
@ -1143,7 +1125,6 @@ void dragpoint(int pointhighlight, int32_t dax, int32_t day, uint8_t flags)
} }
} }
} }
}
// //
// lastwall // lastwall

View file

@ -30,6 +30,16 @@ public:
store.Push(startnode); store.Push(startnode);
} }
// This allows this object to just work as a bit array
// which is useful for using its shared storage.
BFSSearch(unsigned datasize)
{
bitpos = store.Size();
unsigned bitsize = (datasize + 31) >> 5;
store.Reserve(bitsize);
memset(&store[bitpos], 0, bitsize * 4);
}
~BFSSearch() ~BFSSearch()
{ {
store.Clamp(bitpos); store.Clamp(bitpos);
@ -40,12 +50,13 @@ public:
return !!(store[bitpos + (index >> 5)] & (1 << (index & 31))); return !!(store[bitpos + (index >> 5)] & (1 << (index & 31)));
} }
private:
void Set(unsigned index) void Set(unsigned index)
{ {
store[bitpos + (index >> 5)] |= (1 << (index & 31)); store[bitpos + (index >> 5)] |= (1 << (index & 31));
} }
private:
public: public:
unsigned GetNext() unsigned GetNext()
{ {

View file

@ -260,7 +260,7 @@ void SnapSectors(int nSectorA, int nSectorB, int b)
nCount2++; nCount2++;
} }
dragpoint(bestwall, bestwall->x + bestx, bestwall->y + besty, 0); dragpoint(bestwall, bestwall->x + bestx, bestwall->y + besty);
nCount++; nCount++;
nWallA++; nWallA++;

View file

@ -1058,7 +1058,7 @@ void MoveSector(int nSector, int nAngle, int *nXVel, int *nYVel)
for (int i = 0; i < nWalls; i++) for (int i = 0; i < nWalls; i++)
{ {
dragpoint(startwall, xvect + pStartWall->x, yvect + pStartWall->y, 0); dragpoint(startwall, xvect + pStartWall->x, yvect + pStartWall->y);
pStartWall++; pStartWall++;
startwall++; startwall++;
} }

View file

@ -1129,7 +1129,7 @@ void AISlide::Tick(RunListEvent* ev)
int var_2C = nSeekB; int var_2C = nSeekB;
int var_24 = nSeekB; int var_24 = nSeekB;
dragpoint(SlideData[nSlide].field_4, x, y, 0); dragpoint(SlideData[nSlide].field_4, x, y);
movesprite(SlideData[nSlide].pActor, var_34 << 14, var_2C << 14, 0, 0, 0, CLIPMASK1); movesprite(SlideData[nSlide].pActor, var_34 << 14, var_2C << 14, 0, 0, 0, CLIPMASK1);
if (var_34 == 0) if (var_34 == 0)
@ -1145,7 +1145,7 @@ void AISlide::Tick(RunListEvent* ev)
y = wall[nWall].y + var_24; y = wall[nWall].y + var_24;
x = wall[nWall].x + var_20; x = wall[nWall].x + var_20;
dragpoint(SlideData[nSlide].field_0, x, y, 0); dragpoint(SlideData[nSlide].field_0, x, y);
nWall = SlideData[nSlide].field_C; nWall = SlideData[nSlide].field_C;
@ -1160,7 +1160,7 @@ void AISlide::Tick(RunListEvent* ev)
int edi = nSeekD; int edi = nSeekD;
var_24 = nSeekD; var_24 = nSeekD;
dragpoint(SlideData[nSlide].field_C, x, y, 0); dragpoint(SlideData[nSlide].field_C, x, y);
if (var_30 == 0 && edi == 0) { if (var_30 == 0 && edi == 0) {
ebp++; ebp++;
@ -1171,7 +1171,7 @@ void AISlide::Tick(RunListEvent* ev)
x = wall[nWall].x + var_20; x = wall[nWall].x + var_20;
y = wall[nWall].y + var_24; y = wall[nWall].y + var_24;
dragpoint(SlideData[nSlide].field_8, x, y, 0); dragpoint(SlideData[nSlide].field_8, x, y);
} }
else if (cx == 0) // right branch else if (cx == 0) // right branch
{ {
@ -1187,7 +1187,7 @@ void AISlide::Tick(RunListEvent* ev)
int ecx = nSeekB; int ecx = nSeekB;
int var_28 = nSeekB; int var_28 = nSeekB;
dragpoint(SlideData[nSlide].field_0, x, y, 0); dragpoint(SlideData[nSlide].field_0, x, y);
if (edi == 0 && ecx == 0) { if (edi == 0 && ecx == 0) {
ebp = clipmask; ebp = clipmask;
@ -1198,7 +1198,7 @@ void AISlide::Tick(RunListEvent* ev)
y = wall[nWall].y + var_28; y = wall[nWall].y + var_28;
x = wall[nWall].x + var_1C; x = wall[nWall].x + var_1C;
dragpoint(SlideData[nSlide].field_4, x, y, 0); dragpoint(SlideData[nSlide].field_4, x, y);
nWall = SlideData[nSlide].field_8; nWall = SlideData[nSlide].field_8;
@ -1213,7 +1213,7 @@ void AISlide::Tick(RunListEvent* ev)
ecx = nSeekD; ecx = nSeekD;
var_28 = nSeekD; var_28 = nSeekD;
dragpoint(SlideData[nSlide].field_8, x, y, 0); dragpoint(SlideData[nSlide].field_8, x, y);
if (edi == 0 && ecx == 0) { if (edi == 0 && ecx == 0) {
ebp++; ebp++;
@ -1224,7 +1224,7 @@ void AISlide::Tick(RunListEvent* ev)
y = wall[nWall].y + var_28; y = wall[nWall].y + var_28;
x = wall[nWall].x + var_1C; x = wall[nWall].x + var_1C;
dragpoint(SlideData[nSlide].field_C, x, y, 0); dragpoint(SlideData[nSlide].field_C, x, y);
} }
// loc_21A51: // loc_21A51:

View file

@ -349,7 +349,7 @@ MorphTornado(SECTOR_OBJECTp sop)
sop->morph_ang = RANDOM_P2(2048); sop->morph_ang = RANDOM_P2(2048);
// move it x,y // move it x,y
dragpoint(sop->morph_wall_point, mx, my, 0); dragpoint(sop->morph_wall_point, mx, my);
// bound the Z // bound the Z
ceilingz = sector[sop->op_main_sector].ceilingz; ceilingz = sector[sop->op_main_sector].ceilingz;
@ -428,7 +428,7 @@ MorphFloor(SECTOR_OBJECTp sop)
sop->morph_ang = RANDOM_P2(2048); sop->morph_ang = RANDOM_P2(2048);
// move x,y point "just like in build" // move x,y point "just like in build"
dragpoint(sop->morph_wall_point, mx, my, 0); dragpoint(sop->morph_wall_point, mx, my);
// bound the Z // bound the Z
floorz = sector[sop->op_main_sector].floorz; floorz = sector[sop->op_main_sector].floorz;

View file

@ -390,7 +390,7 @@ int DoRotator(DSWActor* actor)
vec2_t const orig = { r->origX[ndx], r->origY[ndx] }; vec2_t const orig = { r->origX[ndx], r->origY[ndx] };
rotatepoint(pivot->pos.vec2, orig, r->pos, &nxy); rotatepoint(pivot->pos.vec2, orig, r->pos, &nxy);
dragpoint(w, nxy.x, nxy.y, 0); dragpoint(w, nxy.x, nxy.y);
ndx++; ndx++;
} }

View file

@ -2576,13 +2576,13 @@ void DoSineWaveWall(void)
{ {
New = sw->orig_xy + MulScale(sw->range, bsin(sw->sintable_ndx), 14); New = sw->orig_xy + MulScale(sw->range, bsin(sw->sintable_ndx), 14);
// wall[sw->wall].y = New; // wall[sw->wall].y = New;
dragpoint(sw->wall, wall[sw->wall].x, New, 0); dragpoint(sw->wall, wall[sw->wall].x, New);
} }
else else
{ {
New = sw->orig_xy + MulScale(sw->range, bsin(sw->sintable_ndx), 14); New = sw->orig_xy + MulScale(sw->range, bsin(sw->sintable_ndx), 14);
// wall[sw->wall].x = New; // wall[sw->wall].x = New;
dragpoint(sw->wall, New, wall[sw->wall].y, 0); dragpoint(sw->wall, New, wall[sw->wall].y);
} }
} }
} }

View file

@ -380,8 +380,8 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)
else else
{ {
// red wall - move 2 points // red wall - move 2 points
dragpoint(w, wall[w].x - amt, wall[w].y, 0); dragpoint(w, wall[w].x - amt, wall[w].y);
dragpoint(wall[w].point2, wall[wall[w].point2].x - amt, wall[wall[w].point2].y, 0); dragpoint(wall[w].point2, wall[wall[w].point2].x - amt, wall[wall[w].point2].y);
} }
break; break;
@ -404,8 +404,8 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)
else else
{ {
// red wall - move 2 points // red wall - move 2 points
dragpoint(w, wall[w].x + amt, wall[w].y, 0); dragpoint(w, wall[w].x + amt, wall[w].y);
dragpoint(wall[w].point2, wall[wall[w].point2].x + amt, wall[wall[w].point2].y, 0); dragpoint(wall[w].point2, wall[wall[w].point2].x + amt, wall[wall[w].point2].y);
} }
break; break;
@ -426,8 +426,8 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)
} }
else else
{ {
dragpoint(w, wall[w].x, wall[w].y - amt, 0); dragpoint(w, wall[w].x, wall[w].y - amt);
dragpoint(wall[w].point2, wall[wall[w].point2].x, wall[wall[w].point2].y - amt, 0); dragpoint(wall[w].point2, wall[wall[w].point2].x, wall[wall[w].point2].y - amt);
} }
break; break;
@ -448,8 +448,8 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt)
} }
else else
{ {
dragpoint(w, wall[w].x, wall[w].y + amt, 0); dragpoint(w, wall[w].x, wall[w].y + amt);
dragpoint(wall[w].point2, wall[wall[w].point2].x, wall[wall[w].point2].y + amt, 0); dragpoint(wall[w].point2, wall[wall[w].point2].x, wall[wall[w].point2].y + amt);
} }

View file

@ -1708,7 +1708,7 @@ void MovePoints(SECTOR_OBJECTp sop, short delta_ang, int nx, int ny)
if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER)) if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER))
{ {
dragpoint(k, wp->x += nx, wp->y += ny, 0); dragpoint(k, wp->x += nx, wp->y += ny);
} }
else else
{ {
@ -1731,7 +1731,7 @@ void MovePoints(SECTOR_OBJECTp sop, short delta_ang, int nx, int ny)
if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER)) if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER))
{ {
dragpoint(k, rxy.x, rxy.y, 0); dragpoint(k, rxy.x, rxy.y);
} }
else else
{ {
@ -1957,7 +1957,7 @@ void RefreshPoints(SECTOR_OBJECTp sop, int nx, int ny, bool dynamic)
if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER)) if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER))
{ {
dragpoint(k, dx, dy, 0); dragpoint(k, dx, dy);
} }
else else
{ {
@ -2119,7 +2119,7 @@ void CollapseSectorObject(SECTOR_OBJECTp sop, int nx, int ny)
if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER)) if (wp->extra && TEST(wp->extra, WALLFX_LOOP_OUTER))
{ {
dragpoint(k, nx, ny, 0); dragpoint(k, nx, ny);
} }
else else
{ {