tweak point deleting for less checksectorpointer calls

git-svn-id: https://svn.eduke32.com/eduke32@1875 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-05-02 16:58:11 +00:00
parent 9c3889e59b
commit 367afadf39
3 changed files with 191 additions and 60 deletions

View file

@ -200,7 +200,7 @@ void keytimerstuff(void);
static int32_t clockdir(int16_t wallstart);
static void flipwalls(int16_t numwalls, int16_t newnumwalls);
static void insertpoint(int16_t linehighlight, int32_t dax, int32_t day);
static void deletepoint(int16_t point);
static const char *deletepoint(int16_t point, int32_t runi);
static int32_t deletesector(int16_t sucksect);
void fixrepeats(int16_t i);
static int16_t loopinside(int32_t x, int32_t y, int16_t startwall);
@ -341,19 +341,27 @@ static void M32_drawdebug(void)
#endif
#ifdef YAX_ENABLE
static void yax_fixreverselinks(int16_t oldwall, int16_t newwall)
{
int32_t cf, ynw;
for (cf=0; cf<2; cf++)
{
ynw = yax_getnextwall(oldwall, cf);
if (ynw >= 0)
yax_setnextwall(ynw, !cf, newwall);
}
}
static void yax_tweakwalls(int16_t start, int16_t offs)
{
int32_t i, nw;
int32_t i, nw, cf;
for (i=0; i<numwalls; i++)
{
nw = yax_getnextwall(i, YAX_CEILING);
if (nw >= start)
yax_setnextwall(i, YAX_CEILING, nw+offs);
nw = yax_getnextwall(i, YAX_FLOOR);
if (nw >= start)
yax_setnextwall(i, YAX_FLOOR, nw+offs);
}
for (cf=0; cf<2; cf++)
{
nw = yax_getnextwall(i, cf);
if (nw >= start)
yax_setnextwall(i, cf, nw+offs);
}
}
static void yax_resetbunchnums(void)
@ -3547,6 +3555,7 @@ end_yax: ;
if (((bstatus&1) < (oldmousebstatus&1)) && highlightsectorcnt < 0) //after dragging
{
int32_t runi, numdelpoints=0;
const char *errmsg;
if (backup_drawn_walls(0))
goto end_after_dragging;
@ -3582,47 +3591,51 @@ end_yax: ;
day = sprite[pointhighlight&16383].y;
}
for (runi=0; runi<2; runi++)
for (runi=0; runi<3; runi++)
for (i=numwalls-1; i>=0; i--) //delete points
{
if (runi==0)
wall[i].cstat &= ~(1<<14);
if (wall[i].x == POINT2(i).x && wall[i].y == POINT2(i).y
&& sector[sectorofwall(i)].wallnum > 3)
{
int32_t b = (wall[i].nextwall == -1 ||
sector[sectorofwall(wall[i].nextwall)].wallnum > 3);
if (runi==0 && !b)
errmsg = deletepoint(i, runi);
if (errmsg)
{
printmessage16("Invalid operation, delete or join sector instead.");
message("%s", errmsg);
goto end_after_dragging;
}
else if (runi==1 && b)
{
deletepoint(i);
else if (runi==2)
numdelpoints++;
}
}
}
if (numdelpoints)
{
if (numdelpoints > 1)
printmessage16("Deleted %d points.", numdelpoints);
message("Deleted %d points.", numdelpoints);
else
printmessage16("Point deleted.");
asksave = 1;
}
for (i=0; i<numwalls; i++) //make new red lines?
else
{
if ((wall[i].x == dax && wall[i].y == day)
|| (POINT2(i).x == dax && POINT2(i).y == day))
for (i=0; i<numwalls; i++) //make new red lines?
{
checksectorpointer(i, sectorofwall(i));
if ((wall[i].x == dax && wall[i].y == day)
|| (POINT2(i).x == dax && POINT2(i).y == day))
{
checksectorpointer(i, sectorofwall(i));
// fixrepeats(i);
asksave = 1;
asksave = 1;
}
}
}
#ifdef YAX_ENABLE
yax_update(0);
yax_updategrays(pos.z);
#endif
end_after_dragging:
backup_drawn_walls(1);
}
@ -4019,12 +4032,15 @@ end_point_dragging:
{
joinsector[0] = -1;
for (i=0; i<numsectors; i++)
{
YAX_SKIPSECTOR(i);
if (inside_editor_curpos(i) == 1)
{
joinsector[0] = i;
printmessage16("Join sector - press J again on sector to join with.");
break;
}
}
goto end_join_sectors;
}
else
@ -4037,6 +4053,8 @@ end_point_dragging:
for (i=0; i<numsectors; i++)
{
YAX_SKIPSECTOR(i);
if (inside_editor_curpos(i) == 1)
{
startwall = sector[i].wallptr;
@ -4055,15 +4073,17 @@ end_point_dragging:
if (j == endwall && i != joinsector[0])
{
#ifdef YAX_ENABLE
if (cb0>=0 || fb0>=0 || cb1>=0 || fb0>=0)
if (cb0>=0 || fb0>=0 || cb1>=0 || fb1>=0)
{
printmessage16("Joining non-adjacent extended sectors not allowed!");
message("Joining non-adjacent extended sectors not allowed!");
joinsector[0] = joinsector[1] = -1;
goto end_join_sectors;
}
#endif
{
fade_editor_screen(-1);
fillsector(i, editorcolors[9]);
fillsector(joinsector[0], editorcolors[9]);
fade_editor_screen(editorcolors[9]);
if (!ask_if_sure("Join non-adjacent sectors? (Y/N)", 0))
joinsector[1] = joinsector[0];
@ -4072,7 +4092,7 @@ end_point_dragging:
#ifdef YAX_ENABLE
if (cb0!=cb1 || fb0!=fb1)
{
printmessage16("Joining of extended sectors with different bunches not allowed!");
message("Joining of extended sectors with different bunches not allowed!");
joinsector[0] = joinsector[1] = -1;
goto end_join_sectors;
}
@ -4127,6 +4147,9 @@ end_point_dragging:
}
Bmemcpy(&wall[newnumwalls], &wall[i], sizeof(walltype));
#ifdef YAX_ENABLE
yax_fixreverselinks(newnumwalls, newnumwalls);
#endif
wall[newnumwalls].point2 = newnumwalls+1;
newnumwalls++;
@ -4148,7 +4171,7 @@ end_point_dragging:
if (loopnum==0)
{
printmessage16("internal error while joining sectors: infloop!");
message("internal error while joining sectors: infloop!");
newnumwalls = -1;
}
}
@ -4255,11 +4278,14 @@ end_join_sectors:
sucksect = -1;
for (i=0; i<numsectors; i++)
{
YAX_SKIPSECTOR(i);
if (inside_editor_curpos(i) == 1)
{
sucksect = i;
break;
}
}
if (sucksect >= 0)
{
@ -4710,6 +4736,15 @@ check_next_sector: ;
if (clockdir(numwalls) == 1)
flipwalls(numwalls,newnumwalls);
for (i=numwalls; i<newnumwalls; i++)
{
copy_some_wall_members(i, suckwall);
if (checksectorpointer(i, numsectors) > 0)
{
// if new red line, prefer the other-side wall as base
suckwall = wall[i].nextwall;
}
}
sucksect = sectorofwall(suckwall);
if (numsectors != sucksect)
@ -4725,12 +4760,6 @@ check_next_sector: ;
sector[numsectors].floorstat &= ~2;
sector[numsectors].ceilingheinum = sector[numsectors].floorheinum = 0;
sector[numsectors].ceilingpal = sector[numsectors].floorpal = 0;
for (i=numwalls; i<newnumwalls; i++)
{
copy_some_wall_members(i, suckwall);
checksectorpointer(i, numsectors);
}
#ifdef YAX_ENABLE
yax_setbunches(numsectors, -1, -1);
#endif
@ -4740,7 +4769,7 @@ check_next_sector: ;
numwalls = newnumwalls;
newnumwalls = -1;
printmessage16("Created new sector %d based on sector %d", numsectors-1, sucksect);
message("Created new sector %d based on sector %d", numsectors-1, sucksect);
}
asksave = 1;
@ -4838,6 +4867,10 @@ check_next_sector: ;
wall[danumwalls].nextwall = -1;
wall[danumwalls].nextsector = -1;
wall[danumwalls].point2 = danumwalls+1;
#ifdef YAX_ENABLE
yax_setnextwall(danumwalls,YAX_CEILING, -1);
yax_setnextwall(danumwalls,YAX_FLOOR, -1);
#endif
danumwalls++;
}
@ -4881,6 +4914,9 @@ check_next_sector: ;
//fix all next pointers on old sector line
for (j=numwalls; j<danumwalls; j++)
{
#ifdef YAX_ENABLE
yax_fixreverselinks(j, j);
#endif
if (wall[j].nextwall >= 0)
{
NEXTWALL(j).nextwall = j;
@ -6080,6 +6116,8 @@ static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls)
for (i=0; i<danumwalls; i++)
{
YAX_SKIPWALL(i);
dst = klabs((*xplc)-wall[i].x) + klabs((*yplc)-wall[i].y);
if (dst < dist)
{
@ -6107,6 +6145,8 @@ static int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls)
for (i=0; i<danumwalls; i++) // Check if a point should be inserted
{
YAX_SKIPWALL(i);
x1 = wall[i].x;
y1 = wall[i].y;
x2 = POINT2(i).x;
@ -6229,9 +6269,31 @@ static void insertpoint(int16_t linehighlight, int32_t dax, int32_t day)
}
}
static void deletepoint(int16_t point)
// runi: 0=check, 1=prepare, 2=do!
// if runi==0, returns error message on fail, in all other cases NULL
static const char *deletepoint(int16_t point, int32_t runi)
{
int32_t i, j, k, sucksect;
int32_t i, j, sucksect;
if (runi==0) // consistency check -- return !=0 on fail
{
i = wall[point].nextsector;
if (i >= 0 && sector[i].wallnum <= 3)
return "Invalid operation, delete or join sector instead.";
return NULL;
}
else if (runi==1)
{
i = wall[point].nextwall;
if (i >= 0)
{
NEXTWALL(i).nextwall = NEXTWALL(i).nextsector = -1;
wall[i].nextwall = wall[i].nextsector = -1;
}
return NULL;
}
sucksect = sectorofwall(point);
@ -6240,9 +6302,9 @@ static void deletepoint(int16_t point)
sector[i].wallptr--;
j = lastwall(point);
k = wall[point].point2;
wall[j].point2 = k;
wall[j].point2 = wall[point].point2;
#if 0
if (wall[j].nextwall >= 0)
{
NEXTWALL(j).nextwall = -1;
@ -6253,10 +6315,12 @@ static void deletepoint(int16_t point)
NEXTWALL(point).nextwall = -1;
NEXTWALL(point).nextsector = -1;
}
#endif
movewalls(point, -1);
checksectorpointer(j, sucksect);
// checksectorpointer(j, sucksect);
return NULL;
}
static int32_t deletesector(int16_t sucksect)

View file

@ -535,8 +535,8 @@ void yax_drawrooms(void (*ExtAnalyzeSprites)(void), int32_t horiz, int16_t sectn
}
}
if (allgotsector[k>>3]&(1<<(k&7)))
continue;
// if (allgotsector[k>>3]&(1<<(k&7)))
// continue;
drawrooms(globalposx,globalposy,globalposz,globalang,horiz,k+MAXSECTORS); // +MAXSECTORS: force
ExtAnalyzeSprites();
@ -1170,6 +1170,9 @@ int32_t checksectorpointer(int16_t i, int16_t sectnum)
for (j=0; j<numsectors; j++)
{
if (j == sectnum)
continue;
YAX_SKIPSECTOR(j);
startwall = sector[j].wallptr;
@ -1182,9 +1185,6 @@ int32_t checksectorpointer(int16_t i, int16_t sectnum)
if (wall[wall[k].point2].x != x1 || wall[wall[k].point2].y != y1)
continue;
if (j == sectnum)
continue;
// Don't create link if the other side is connected to another wall.
// The nextwall relation should be definitely one-to-one at all times!
if (wall[k].nextwall>=0 && wall[k].nextwall != i)
@ -3928,7 +3928,27 @@ static void drawalls(int32_t bunch)
if (gotswall == 0) { gotswall = 1; prepwall(z,wal); }
wallscan(x1,x2,uplc,dplc,swall,lwall);
#ifdef YAX_ENABLE
if ((wal->cstat&YAX_NEXTWALLBIT(YAX_FLOOR)) && globalposz > sec->floorz)
{
for (x=x1; x<=x2; x++)
if (dplc[x] > umost[x] && umost[x] <= dmost[x])
{
umost[x] = dplc[x];
if (umost[x] > dmost[x]) numhits--;
}
}
else if ((wal->cstat&YAX_NEXTWALLBIT(YAX_CEILING)) && globalposz < sec->ceilingz)
{
for (x=x1; x<=x2; x++)
if (uplc[x] < dmost[x] && umost[x] <= dmost[x])
{
dmost[x] = uplc[x];
if (umost[x] > dmost[x]) numhits--;
}
}
else
#endif
for (x=x1; x<=x2; x++)
if (umost[x] <= dmost[x])
{ umost[x] = 1; dmost[x] = 0; numhits--; }
@ -7170,7 +7190,8 @@ int32_t wallvisible(int32_t x, int32_t y, int16_t wallnum)
return (1);
return (0);
}
/*
#if 0
// returns the intersection point between two lines
_point2d intersection(_equation eq1, _equation eq2)
{
@ -7236,7 +7257,7 @@ static inline void drawmaskleaf(_maskleaf* wall)
//OSD_Printf("Drawing mask %i\n", wall->index);
drawmaskwall(wall->index);
}
*/
#endif
static inline int32_t sameside(_equation *eq, _point2d *p1, _point2d *p2)
{

View file

@ -7398,6 +7398,7 @@ static void Keys2d(void)
tcursectornum = -1;
for (i=0; i<numsectors; i++)
{
YAX_SKIPSECTOR(i);
if (inside_editor(&pos, searchx,searchy, zoom, mousxplc,mousyplc,i) == 1)
{
tcursectornum = i;
@ -7488,7 +7489,7 @@ static void Keys2d(void)
///__bigcomment__
#ifdef YAX_ENABLE
if (!m32_sideview && numyaxbunches>0)
if (/*!m32_sideview &&*/ numyaxbunches>0)
{
int32_t zsign=0, bestzdiff=INT32_MAX, hiz=0, loz=0, bottomp=0;
@ -7513,8 +7514,13 @@ static void Keys2d(void)
bestzdiff = j;
}
if (zsign==1 && bestzdiff==INT_MAX)
bottomp=1, bestzdiff = (hiz+1024 - pos.z);
if (bestzdiff==INT_MAX)
{
if (zsign == 1)
bottomp=1, bestzdiff = (hiz+(1024<<4) - pos.z);
else
bestzdiff = pos.z - loz;
}
if (bestzdiff != INT32_MAX)
{
@ -7824,14 +7830,14 @@ static void Keys2d(void)
j = 0;
x = wall[sector[i].wallptr].x;
y = wall[sector[i].wallptr].y;
z = pos.z;
z = sector[i].floorz;
break;
case CORRUPT_WALL:
i = k&(MAXWALLS-1);
j = 1;
x = wall[i].x;
y = wall[i].y;
z = pos.z;
z = sector[sectorofwall(i)].floorz;
break;
case CORRUPT_SPRITE:
i = k&(MAXSPRITES-1);
@ -7855,6 +7861,9 @@ static void Keys2d(void)
pos.x = x;
pos.y = y;
pos.z = z;
#ifdef YAX_ENABLE
yax_updategrays(pos.z);
#endif
}
else x=editorgridextent+1;
@ -8010,6 +8019,7 @@ static void Keys2d(void)
break;
pos.x = wall[sector[j].wallptr].x;
pos.y = wall[sector[j].wallptr].y;
pos.z = sector[j].floorz;
printmessage16("Current pos now on sector %d's first wall-point", j);
}
break;
@ -8021,6 +8031,7 @@ static void Keys2d(void)
break;
pos.x = wall[j].x;
pos.y = wall[j].y;
pos.z = sector[sectorofwall(j)].floorz;
printmessage16("Current pos now on wall %d's point", j);
}
break;
@ -8030,6 +8041,7 @@ static void Keys2d(void)
break;
pos.x = sprite[j].x;
pos.y = sprite[j].y;
pos.z = sprite[j].z;
printmessage16("Current pos now on sprite %d", j);
break;
@ -8039,6 +8051,9 @@ static void Keys2d(void)
printmessage16("Current pos now (%d, %d)", pos.x, pos.y);
break;
}
#ifdef YAX_ENABLE
yax_updategrays(pos.z);
#endif
}
}// end key2d
@ -10980,7 +10995,38 @@ int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing)
if (nw>=w0 && nw<=endwall)
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL[%d].NEXTWALL is its own sector's wall", j);
#ifdef YAX_ENABLE
{
int32_t cf, ynw, jp2, ynwp2;
for (cf=0; cf<1; cf++)
{
ynw = yax_getnextwall(j, cf);
if (ynw >= 0)
{
if (ynw >= numwalls)
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL %d's YAX-NEXTWALL(%d)=%d out of range: numwalls=%d",
j, cf, ynw, numwalls);
else
{
if (j == ynw)
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL %d's YAX-NEXTWALL(%d) is itself",
j, cf);
else if (wall[j].x != wall[ynw].x || wall[j].y != wall[ynw].y)
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL %d's and its YAX-NEXTWALL(%d)=%d's coordinates not equal",
j, cf, ynw);
else
{
jp2 = wall[j].point2;
ynwp2 = wall[ynw].point2;
if (wall[jp2].x != wall[ynwp2].x || wall[jp2].y != wall[ynwp2].y)
CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL %d's and its YAX-NEXTWALL(%d)=%d's p2-coordinates not equal",
j, cf, ynw);
}
}
}
}
}
#endif
if (ns == i)
{
if (!bad)