summaryrefslogtreecommitdiff
path: root/src/engine/octaedit.cpp
diff options
context:
space:
mode:
authorxolatile2025-08-05 10:40:01 +0200
committerxolatile2025-08-05 10:40:01 +0200
commita2a16b85572b1d28b0cd4901ea7348750732a740 (patch)
tree6287cdf8331e821f9fe1e0adadc664a59634a812 /src/engine/octaedit.cpp
parent6762e292d02e37a69a807e01493d4e14319cca33 (diff)
downloadxolatile-badassbug-a2a16b85572b1d28b0cd4901ea7348750732a740.tar.xz
xolatile-badassbug-a2a16b85572b1d28b0cd4901ea7348750732a740.tar.zst
Few more changes, please do not compile...
Diffstat (limited to 'src/engine/octaedit.cpp')
-rw-r--r--src/engine/octaedit.cpp402
1 files changed, 11 insertions, 391 deletions
diff --git a/src/engine/octaedit.cpp b/src/engine/octaedit.cpp
index 0b2cbe1..239c6a4 100644
--- a/src/engine/octaedit.cpp
+++ b/src/engine/octaedit.cpp
@@ -100,8 +100,6 @@ ivec cur, lastcur;
extern int entediting;
bool editmode = false;
bool havesel = false;
-bool hmapsel = false;
-int horient = 0;
extern int entmoving;
@@ -135,18 +133,14 @@ VARF(gridpower, 0, 3, 12,
VAR(passthroughsel, 0, 0, 1);
VAR(editing, 1, 0, 0);
VAR(selectcorners, 0, 0, 1);
-VARF(hmapedit, 0, 0, 1, horient = sel.orient);
void forcenextundo() { lastsel.orient = -1; }
-extern void hmapcancel();
-
void cubecancel()
{
havesel = false;
- moving = dragging = hmapedit = passthroughsel = 0;
+ moving = dragging = passthroughsel = 0;
forcenextundo();
- hmapcancel();
}
void cancelsel()
@@ -343,7 +337,6 @@ bool editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle,
return true;
}
-inline bool isheightmap(int orient, int d, bool empty, cube *c);
extern void entdrag(const vec &ray);
extern bool hoveringonent(int ent, int orient);
extern void renderentselection(const vec &o, const vec &ray, bool entmoving);
@@ -361,7 +354,6 @@ void rendereditcursor()
odc = dimcoord(orient);
bool hidecursor = g3d_windowhit(true, false) || blendpaintmode, hovering = false;
- hmapsel = false;
if(moving)
{
@@ -397,7 +389,7 @@ void rendereditcursor()
| RAY_SKIPFIRST
| (passthroughcube || passthrough ? RAY_PASS : 0), gridsize, entorient, ent);
- if((havesel || dragging) && !passthroughsel && !hmapedit) // now try selecting the selection
+ if((havesel || dragging) && !passthroughsel) // now try selecting the selection
if(rayboxintersect(vec(sel.o), vec(sel.s).mul(sel.grid), player->o, camdir, sdist, orient))
{ // and choose the nearest of the two
if(sdist < wdist)
@@ -430,7 +422,7 @@ void rendereditcursor()
}
}
cube *c = &lookupcube(ivec(w));
- if(gridlookup && !dragging && !moving && !havesel && hmapedit!=1) gridsize = lusize;
+ if(gridlookup && !dragging && !moving && !havesel) gridsize = lusize;
int mag = lusize / gridsize;
normalizelookupcube(ivec(w));
if(sdist == 0 || sdist > wdist) rayboxintersect(vec(lu), vec(gridsize), player->o, camdir, t=0, orient); // just getting orient
@@ -439,13 +431,6 @@ void rendereditcursor()
od = dimension(orient);
d = dimension(sel.orient);
- if(hmapedit==1 && dimcoord(horient) == (camdir[dimension(horient)]<0))
- {
- hmapsel = isheightmap(horient, dimension(horient), false, c);
- if(hmapsel)
- od = dimension(orient = horient);
- }
-
if(dragging)
{
updateselection();
@@ -511,10 +496,7 @@ void rendereditcursor()
if(!moving && !hovering && !hidecursor)
{
- if(hmapedit==1)
- gle::colorub(0, hmapsel ? 255 : 40, 0);
- else
- gle::colorub(120,120,120);
+ gle::colorub(120,120,120);
boxs(orient, vec(lu), vec(lusize));
}
@@ -534,10 +516,7 @@ void rendereditcursor()
cs[C[d]] = 0.5f*(sel.cys*gridsize);
cs[D[d]] *= gridsize;
boxs(sel.orient, co, cs);
- if(hmapedit==1) // 3D selection box
- gle::colorub(0,120,0);
- else
- gle::colorub(0,0,120);
+ gle::colorub(0,0,120);
boxs3D(vec(sel.o), vec(sel.s), sel.grid);
}
@@ -853,11 +832,8 @@ void swapundo(undolist &a, undolist &b, int op)
freeundo(u);
}
commitchanges();
- if(!hmapsel)
- {
- sel = l;
- reorient();
- }
+ sel = l;
+ reorient();
forcenextundo();
}
@@ -1011,7 +987,7 @@ static void unpackvslots(block3 &b, ucharbuf &buf)
VSlot &vs = *lookupslot(hdr.slot, false).variants;
VSlot ds;
if(!unpackvslot(buf, ds, false)) break;
- if(vs.index < 0 || vs.index == DEFAULT_SKY) continue;
+ if(vs.index < 0) continue;
VSlot *edit = editvslot(vs, ds);
unpackingvslots.add(vslotmap(hdr.index, edit ? edit : &vs));
}
@@ -1563,359 +1539,6 @@ void compacteditvslots()
compactvslots(u->block()->c(), u->block()->size());
}
-///////////// height maps ////////////////
-
-#define MAXBRUSH 64
-#define MAXBRUSHC 63
-#define MAXBRUSH2 32
-int brush[MAXBRUSH][MAXBRUSH];
-VAR(brushx, 0, MAXBRUSH2, MAXBRUSH);
-VAR(brushy, 0, MAXBRUSH2, MAXBRUSH);
-bool paintbrush = 0;
-int brushmaxx = 0, brushminx = MAXBRUSH;
-int brushmaxy = 0, brushminy = MAXBRUSH;
-
-void clearbrush()
-{
- memset(brush, 0, sizeof brush);
- brushmaxx = brushmaxy = 0;
- brushminx = brushminy = MAXBRUSH;
- paintbrush = false;
-}
-
-void brushvert(int *x, int *y, int *v)
-{
- *x += MAXBRUSH2 - brushx + 1; // +1 for automatic padding
- *y += MAXBRUSH2 - brushy + 1;
- if(*x<0 || *y<0 || *x>=MAXBRUSH || *y>=MAXBRUSH) return;
- brush[*x][*y] = clamp(*v, 0, 8);
- paintbrush = paintbrush || (brush[*x][*y] > 0);
- brushmaxx = min(MAXBRUSH-1, max(brushmaxx, *x+1));
- brushmaxy = min(MAXBRUSH-1, max(brushmaxy, *y+1));
- brushminx = max(0, min(brushminx, *x-1));
- brushminy = max(0, min(brushminy, *y-1));
-}
-
-vector<int> htextures;
-
-COMMAND(clearbrush, "");
-COMMAND(brushvert, "iii");
-void hmapcancel() { htextures.setsize(0); }
-COMMAND(hmapcancel, "");
-ICOMMAND(hmapselect, "", (),
- int t = lookupcube(cur).texture[orient];
- int i = htextures.find(t);
- if(i<0)
- htextures.add(t);
- else
- htextures.remove(i);
-);
-
-inline bool isheightmap(int o, int d, bool empty, cube *c)
-{
- return havesel ||
- (empty && isempty(*c)) ||
- htextures.empty() ||
- htextures.find(c->texture[o]) >= 0;
-}
-
-namespace hmap
-{
-# define PAINTED 1
-# define NOTHMAP 2
-# define MAPPED 16
- uchar flags[MAXBRUSH][MAXBRUSH];
- cube *cmap[MAXBRUSHC][MAXBRUSHC][4];
- int mapz[MAXBRUSHC][MAXBRUSHC];
- int map [MAXBRUSH][MAXBRUSH];
-
- selinfo changes;
- bool selecting;
- int d, dc, dr, dcr, biasup, br, hws, fg;
- int gx, gy, gz, mx, my, mz, nx, ny, nz, bmx, bmy, bnx, bny;
- uint fs;
- selinfo hundo;
-
- cube *getcube(ivec t, int f)
- {
- t[d] += dcr*f*gridsize;
- if(t[d] > nz || t[d] < mz) return NULL;
- cube *c = &lookupcube(t, gridsize);
- if(c->children) forcemip(*c, false);
- discardchildren(*c, true);
- if(!isheightmap(sel.orient, d, true, c)) return NULL;
- if (t.x < changes.o.x) changes.o.x = t.x;
- else if(t.x > changes.s.x) changes.s.x = t.x;
- if (t.y < changes.o.y) changes.o.y = t.y;
- else if(t.y > changes.s.y) changes.s.y = t.y;
- if (t.z < changes.o.z) changes.o.z = t.z;
- else if(t.z > changes.s.z) changes.s.z = t.z;
- return c;
- }
-
- uint getface(cube *c, int d)
- {
- return 0x0f0f0f0f & ((dc ? c->faces[d] : 0x88888888 - c->faces[d]) >> fs);
- }
-
- void pushside(cube &c, int d, int x, int y, int z)
- {
- ivec a;
- getcubevector(c, d, x, y, z, a);
- a[R[d]] = 8 - a[R[d]];
- setcubevector(c, d, x, y, z, a);
- }
-
- void addpoint(int x, int y, int z, int v)
- {
- if(!(flags[x][y] & MAPPED))
- map[x][y] = v + (z*8);
- flags[x][y] |= MAPPED;
- }
-
- void select(int x, int y, int z)
- {
- if((NOTHMAP & flags[x][y]) || (PAINTED & flags[x][y])) return;
- ivec t(d, x+gx, y+gy, dc ? z : hws-z);
- t.shl(gridpower);
-
- // selections may damage; must makeundo before
- hundo.o = t;
- hundo.o[D[d]] -= dcr*gridsize*2;
- makeundo(hundo);
-
- cube **c = cmap[x][y];
- loopk(4) c[k] = NULL;
- c[1] = getcube(t, 0);
- if(!c[1] || !isempty(*c[1]))
- { // try up
- c[2] = c[1];
- c[1] = getcube(t, 1);
- if(!c[1] || isempty(*c[1])) { c[0] = c[1]; c[1] = c[2]; c[2] = NULL; }
- else { z++; t[d]+=fg; }
- }
- else // drop down
- {
- z--;
- t[d]-= fg;
- c[0] = c[1];
- c[1] = getcube(t, 0);
- }
-
- if(!c[1] || isempty(*c[1])) { flags[x][y] |= NOTHMAP; return; }
-
- flags[x][y] |= PAINTED;
- mapz [x][y] = z;
-
- if(!c[0]) c[0] = getcube(t, 1);
- if(!c[2]) c[2] = getcube(t, -1);
- c[3] = getcube(t, -2);
- c[2] = !c[2] || isempty(*c[2]) ? NULL : c[2];
- c[3] = !c[3] || isempty(*c[3]) ? NULL : c[3];
-
- uint face = getface(c[1], d);
- if(face == 0x08080808 && (!c[0] || !isempty(*c[0]))) { flags[x][y] |= NOTHMAP; return; }
- if(c[1]->faces[R[d]] == F_SOLID) // was single
- face += 0x08080808;
- else // was pair
- face += c[2] ? getface(c[2], d) : 0x08080808;
- face += 0x08080808; // c[3]
- uchar *f = (uchar*)&face;
- addpoint(x, y, z, f[0]);
- addpoint(x+1, y, z, f[1]);
- addpoint(x, y+1, z, f[2]);
- addpoint(x+1, y+1, z, f[3]);
-
- if(selecting) // continue to adjacent cubes
- {
- if(x>bmx) select(x-1, y, z);
- if(x<bnx) select(x+1, y, z);
- if(y>bmy) select(x, y-1, z);
- if(y<bny) select(x, y+1, z);
- }
- }
-
- void ripple(int x, int y, int z, bool force)
- {
- if(force) select(x, y, z);
- if((NOTHMAP & flags[x][y]) || !(PAINTED & flags[x][y])) return;
-
- bool changed = false;
- int *o[4], best, par, q = 0;
- loopi(2) loopj(2) o[i+j*2] = &map[x+i][y+j];
- #define pullhmap(I, LT, GT, M, N, A) do { \
- best = I; \
- loopi(4) if(*o[i] LT best) best = *o[q = i] - M; \
- par = (best&(~7)) + N; \
- /* dual layer for extra smoothness */ \
- if(*o[q^3] GT par && !(*o[q^1] LT par || *o[q^2] LT par)) { \
- if(*o[q^3] GT par A 8 || *o[q^1] != par || *o[q^2] != par) { \
- *o[q^3] = (*o[q^3] GT par A 8 ? par A 8 : *o[q^3]); \
- *o[q^1] = *o[q^2] = par; \
- changed = true; \
- } \
- /* single layer */ \
- } else { \
- loopj(4) if(*o[j] GT par) { \
- *o[j] = par; \
- changed = true; \
- } \
- } \
- } while(0)
-
- if(biasup)
- pullhmap(0, >, <, 1, 0, -);
- else
- pullhmap(worldsize*8, <, >, 0, 8, +);
-
- cube **c = cmap[x][y];
- int e[2][2];
- int notempty = 0;
-
- loopk(4) if(c[k]) {
- loopi(2) loopj(2) {
- e[i][j] = min(8, map[x+i][y+j] - (mapz[x][y]+3-k)*8);
- notempty |= e[i][j] > 0;
- }
- if(notempty)
- {
- c[k]->texture[sel.orient] = c[1]->texture[sel.orient];
- solidfaces(*c[k]);
- loopi(2) loopj(2)
- {
- int f = e[i][j];
- if(f<0 || (f==0 && e[1-i][j]==0 && e[i][1-j]==0))
- {
- f=0;
- pushside(*c[k], d, i, j, 0);
- pushside(*c[k], d, i, j, 1);
- }
- edgeset(cubeedge(*c[k], d, i, j), dc, dc ? f : 8-f);
- }
- }
- else
- emptyfaces(*c[k]);
- }
-
- if(!changed) return;
- if(x>mx) ripple(x-1, y, mapz[x][y], true);
- if(x<nx) ripple(x+1, y, mapz[x][y], true);
- if(y>my) ripple(x, y-1, mapz[x][y], true);
- if(y<ny) ripple(x, y+1, mapz[x][y], true);
-
-#define DIAGONAL_RIPPLE(a,b,exp) if(exp) { \
- if(flags[x a][ y] & PAINTED) \
- ripple(x a, y b, mapz[x a][y], true); \
- else if(flags[x][y b] & PAINTED) \
- ripple(x a, y b, mapz[x][y b], true); \
- }
-
- DIAGONAL_RIPPLE(-1, -1, (x>mx && y>my)); // do diagonals because adjacents
- DIAGONAL_RIPPLE(-1, +1, (x>mx && y<ny)); // won't unless changed
- DIAGONAL_RIPPLE(+1, +1, (x<nx && y<ny));
- DIAGONAL_RIPPLE(+1, -1, (x<nx && y>my));
- }
-
-#define loopbrush(i) for(int x=bmx; x<=bnx+i; x++) for(int y=bmy; y<=bny+i; y++)
-
- void paint()
- {
- loopbrush(1)
- map[x][y] -= dr * brush[x][y];
- }
-
- void smooth()
- {
- int sum, div;
- loopbrush(-2)
- {
- sum = 0;
- div = 9;
- loopi(3) loopj(3)
- if(flags[x+i][y+j] & MAPPED)
- sum += map[x+i][y+j];
- else div--;
- if(div)
- map[x+1][y+1] = sum / div;
- }
- }
-
- void rippleandset()
- {
- loopbrush(0)
- ripple(x, y, gz, false);
- }
-
- void run(int dir, int mode)
- {
- d = dimension(sel.orient);
- dc = dimcoord(sel.orient);
- dcr= dc ? 1 : -1;
- dr = dir>0 ? 1 : -1;
- br = dir>0 ? 0x08080808 : 0;
- // biasup = mode == dir<0;
- biasup = dir<0;
- bool paintme = paintbrush;
- int cx = (sel.corner&1 ? 0 : -1);
- int cy = (sel.corner&2 ? 0 : -1);
- hws= (worldsize>>gridpower);
- gx = (cur[R[d]] >> gridpower) + cx - MAXBRUSH2;
- gy = (cur[C[d]] >> gridpower) + cy - MAXBRUSH2;
- gz = (cur[D[d]] >> gridpower);
- fs = dc ? 4 : 0;
- fg = dc ? gridsize : -gridsize;
- mx = max(0, -gx); // ripple range
- my = max(0, -gy);
- nx = min(MAXBRUSH-1, hws-gx) - 1;
- ny = min(MAXBRUSH-1, hws-gy) - 1;
- if(havesel)
- { // selection range
- bmx = mx = max(mx, (sel.o[R[d]]>>gridpower)-gx);
- bmy = my = max(my, (sel.o[C[d]]>>gridpower)-gy);
- bnx = nx = min(nx, (sel.s[R[d]]+(sel.o[R[d]]>>gridpower))-gx-1);
- bny = ny = min(ny, (sel.s[C[d]]+(sel.o[C[d]]>>gridpower))-gy-1);
- }
- if(havesel && mode<0) // -ve means smooth selection
- paintme = false;
- else
- { // brush range
- bmx = max(mx, brushminx);
- bmy = max(my, brushminy);
- bnx = min(nx, brushmaxx-1);
- bny = min(ny, brushmaxy-1);
- }
- nz = worldsize-gridsize;
- mz = 0;
- hundo.s = ivec(d,1,1,5);
- hundo.orient = sel.orient;
- hundo.grid = gridsize;
- forcenextundo();
-
- changes.grid = gridsize;
- changes.s = changes.o = cur;
- memset(map, 0, sizeof map);
- memset(flags, 0, sizeof flags);
-
- selecting = true;
- select(clamp(MAXBRUSH2-cx, bmx, bnx),
- clamp(MAXBRUSH2-cy, bmy, bny),
- dc ? gz : hws - gz);
- selecting = false;
- if(paintme)
- paint();
- else
- smooth();
- rippleandset(); // pull up points to cubify, and set
- changes.s.sub(changes.o).shr(gridpower).add(1);
- changed(changes);
- }
-}
-
-void edithmap(int dir, int mode) {
- if((nompedit && multiplayer()) || !hmapsel) return;
- hmap::run(dir, mode);
-}
-
///////////// main cube edit ////////////////
int bounded(int n) { return n<0 ? 0 : (n>8 ? 8 : n); }
@@ -2036,10 +1659,7 @@ void mpeditface(int dir, int mode, selinfo &sel, bool local)
void editface(int *dir, int *mode)
{
if(noedit(moving!=0)) return;
- if(hmapedit!=1)
- mpeditface(*dir, *mode, sel, true);
- else
- edithmap(*dir, *mode);
+ mpeditface(*dir, *mode, sel, true);
}
VAR(selectionsurf, 0, 0, 1);
@@ -2100,7 +1720,7 @@ static VSlot *remapvslot(int index, bool delta, const VSlot &ds)
{
loopv(remappedvslots) if(remappedvslots[i].index == index) return remappedvslots[i].vslot;
VSlot &vs = lookupvslot(index, false);
- if(vs.index < 0 || vs.index == DEFAULT_SKY) return NULL;
+ if(vs.index < 0) return NULL;
VSlot *edit = NULL;
if(delta)
{
@@ -2380,7 +2000,7 @@ static int unpacktex(int &tex, ucharbuf &buf, bool insert = true)
VSlot ds;
if(!unpackvslot(buf, ds, false)) return false;
VSlot &vs = *lookupslot(tex & 0xFFFF, false).variants;
- if(vs.index < 0 || vs.index == DEFAULT_SKY) return false;
+ if(vs.index < 0) return false;
VSlot *edit = insert ? editvslot(vs, ds) : findvslot(*vs.slot, vs, ds);
if(!edit) return false;
tex = edit->index;