diff --git a/source/src/editing.cpp b/source/src/editing.cpp index abcd58df..81d12a03 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -764,38 +764,46 @@ COMMANDF(settex, "ii", (int *texture, int *type) { settex(*texture, *type); }); void transformclipentities() // transforms all clip entities to tag clips, if they are big enough (so, that no player could be above or below them) { EDITMP; - int entsdone = 0; - loopv(ents) + int total = 0, thisrun; + do { - entity &e = ents[i]; - if((e.type == CLIP || e.type == PLCLIP) && e.attr2 && e.attr3 && e.attr4) + thisrun = 0; + loopv(ents) { - int allowedspace = e.type == CLIP ? 1 : 4; - int x1 = e.x - e.attr2, x2 = e.x + e.attr2 - 1, y1 = e.y - e.attr3, y2 = e.y + e.attr3 - 1; - int z1 = S(e.x, e.y)->floor + e.attr1, z2 = z1 + e.attr4; - bool bigenough = true; - for(int xx = x1; xx <= x2; xx++) for(int yy = y1; yy <= y2; yy++) - { - if(OUTBORD(xx,yy) || SOLID(S(xx,yy))) continue; - sqr *s[4] = { S(xx, yy), S(xx + 1, yy), S(xx, yy + 1), S(xx + 1, yy + 1) }; - int vdeltamax = 0; - loopj(4) if(s[j]->vdelta > vdeltamax) vdeltamax = s[j]->vdelta; - int floor = s[0]->floor - (s[0]->type == FHF ? (vdeltamax + 3) / 4 : 0), - ceil = s[0]->ceil - (s[0]->type == CHF ? (vdeltamax + 3) / 4 : 0); - if(z1 - floor > allowedspace || ceil - z2 > allowedspace) bigenough = false; - } - if(bigenough) + entity &e = ents[i]; + if((e.type == CLIP || e.type == PLCLIP) && e.attr2 && e.attr3 && e.attr4) { + int allowedspace = e.type == CLIP ? 1 : 4; + int clipmask = e.type == CLIP ? TAGCLIP : TAGPLCLIP; + int x1 = e.x - e.attr2, x2 = e.x + e.attr2 - 1, y1 = e.y - e.attr3, y2 = e.y + e.attr3 - 1; + int z1 = S(e.x, e.y)->floor + e.attr1, z2 = z1 + e.attr4; + bool bigenough = true; for(int xx = x1; xx <= x2; xx++) for(int yy = y1; yy <= y2; yy++) { - if(!OUTBORD(xx,yy) && !SOLID(S(xx,yy))) S(xx, yy)->tag |= e.type == CLIP ? TAGCLIP : TAGPLCLIP; + if(OUTBORD(xx,yy) || SOLID(S(xx,yy))) continue; + sqr *s[4] = { S(xx, yy), S(xx + 1, yy), S(xx, yy + 1), S(xx + 1, yy + 1) }; + int vdeltamax = 0; + loopj(4) if(s[j]->vdelta > vdeltamax) vdeltamax = s[j]->vdelta; + int floor = s[0]->floor - (s[0]->type == FHF ? (vdeltamax + 3) / 4 : 0), + ceil = s[0]->ceil - (s[0]->type == CHF ? (vdeltamax + 3) / 4 : 0); + if((z1 - floor > allowedspace || ceil - z2 > allowedspace) && !(s[0]->tag & (TAGCLIP | clipmask))) bigenough = false; + } + if(bigenough) + { + for(int xx = x1; xx <= x2; xx++) for(int yy = y1; yy <= y2; yy++) + { + if(!OUTBORD(xx,yy) && !SOLID(S(xx,yy))) S(xx, yy)->tag |= clipmask; + } + e.type = NOTUSED; + thisrun++; } - e.type = NOTUSED; - entsdone++; } } + total += thisrun; } - conoutf("changed %d clip entities to tagged clip areas", entsdone); + while(thisrun); + loopi(ssize) loopj(ssize) { sqr *s = S(i,j); if(s->tag & TAGCLIP) s->tag &= ~TAGPLCLIP; } + conoutf("changed %d clip entities to tagged clip areas", total); } COMMAND(transformclipentities, "");