summaryrefslogtreecommitdiff
path: root/src/engine/octaedit.cpp
diff options
context:
space:
mode:
authorxolatile2025-08-06 22:54:55 +0200
committerxolatile2025-08-06 22:54:55 +0200
commit0a1172b75f571685c264a8b9d8ee224bbf11381f (patch)
treed041fdc68a60f0ebb48a3852bbcce6d9432f83d5 /src/engine/octaedit.cpp
parentaffde05dc07a94643f1fd2751b2b441f57f73d7d (diff)
downloadxolatile-badassbug-0a1172b75f571685c264a8b9d8ee224bbf11381f.tar.xz
xolatile-badassbug-0a1172b75f571685c264a8b9d8ee224bbf11381f.tar.zst
Please do not hate me, it makes sense...
Diffstat (limited to 'src/engine/octaedit.cpp')
-rw-r--r--src/engine/octaedit.cpp1033
1 files changed, 320 insertions, 713 deletions
diff --git a/src/engine/octaedit.cpp b/src/engine/octaedit.cpp
index fb37088..0da305d 100644
--- a/src/engine/octaedit.cpp
+++ b/src/engine/octaedit.cpp
@@ -4,21 +4,16 @@ extern int outline;
bool boxoutline = false;
-void boxs(int orient, vec o, const vec &s, float size)
-{
+void boxs(int orient, vec o, const vec &s, float size) {
int d = dimension(orient), dc = dimcoord(orient);
float f = boxoutline ? (dc>0 ? 0.2f : -0.2f) : 0;
o[D[d]] += dc * s[D[d]] + f;
-
vec r(0, 0, 0), c(0, 0, 0);
r[R[d]] = s[R[d]];
c[C[d]] = s[C[d]];
-
vec v1 = o, v2 = vec(o).add(r), v3 = vec(o).add(r).add(c), v4 = vec(o).add(c);
-
r[R[d]] = 0.5f*size;
c[C[d]] = 0.5f*size;
-
gle::defvertex();
gle::begin(GL_TRIANGLE_STRIP);
gle::attrib(vec(v1).sub(r).sub(c));
@@ -34,53 +29,43 @@ void boxs(int orient, vec o, const vec &s, float size)
xtraverts += gle::end();
}
-void boxs(int orient, vec o, const vec &s)
-{
+void boxs(int orient, vec o, const vec &s) {
int d = dimension(orient), dc = dimcoord(orient);
float f = boxoutline ? (dc>0 ? 0.2f : -0.2f) : 0;
o[D[d]] += dc * s[D[d]] + f;
-
gle::defvertex();
gle::begin(GL_LINE_LOOP);
-
gle::attrib(o); o[R[d]] += s[R[d]];
gle::attrib(o); o[C[d]] += s[C[d]];
gle::attrib(o); o[R[d]] -= s[R[d]];
gle::attrib(o);
-
xtraverts += gle::end();
}
-void boxs3D(const vec &o, vec s, int g)
-{
+void boxs3D(const vec &o, vec s, int g) {
s.mul(g);
loopi(6)
boxs(i, o, s);
}
-void boxsgrid(int orient, vec o, vec s, int g)
-{
+void boxsgrid(int orient, vec o, vec s, int g) {
int d = dimension(orient), dc = dimcoord(orient);
float ox = o[R[d]],
oy = o[C[d]],
xs = s[R[d]],
ys = s[C[d]],
f = boxoutline ? (dc>0 ? 0.2f : -0.2f) : 0;
-
o[D[d]] += dc * s[D[d]]*g + f;
-
gle::defvertex();
gle::begin(GL_LINES);
- loop(x, xs)
- {
+ loop(x, xs) {
o[R[d]] += g;
gle::attrib(o);
o[C[d]] += ys*g;
gle::attrib(o);
o[C[d]] = oy;
}
- loop(y, ys)
- {
+ loop(y, ys) {
o[C[d]] += g;
o[R[d]] = ox;
gle::attrib(o);
@@ -112,18 +97,15 @@ VARF(dragging, 0, 0, 1,
);
int moving = 0;
-ICOMMAND(moving, "b", (int *n),
-{
- if(*n >= 0)
- {
+ICOMMAND(moving, "b", (int *n), {
+ if(*n >= 0) {
if(!*n || (moving<=1 && !pointinsel(sel, vec(cur).add(1)))) moving = 0;
else if(!moving) moving = 1;
}
intret(moving);
});
-VARF(gridpower, 0, 3, 12,
-{
+VARF(gridpower, 0, 3, 12, {
if(dragging) return;
gridsize = 1<<gridpower;
if(gridsize>=worldsize) gridsize = worldsize/2;
@@ -136,35 +118,29 @@ VAR(selectcorners, 0, 0, 1);
void forcenextundo() { lastsel.orient = -1; }
-void cubecancel()
-{
+void cubecancel() {
havesel = false;
moving = dragging = passthroughsel = 0;
forcenextundo();
}
-void cancelsel()
-{
+void cancelsel() {
cubecancel();
entcancel();
}
-void toggleedit(bool force)
-{
- if(!force)
- {
+void toggleedit(bool force) {
+ if(!force) {
if(!isconnected()) return;
if(player->state!=CS_ALIVE && player->state!=CS_DEAD && player->state!=CS_EDITING) return; // do not allow dead players to edit to avoid state confusion
if(!game::allowedittoggle()) return; // not in most multiplayer modes
}
- if(!(editmode = !editmode))
- {
+ if(!(editmode = !editmode)) {
player->state = player->editstate;
player->o.z -= player->eyeheight; // entinmap wants feet pos
entinmap(player); // find spawn closest to current floating pos
}
- else
- {
+ else {
game::resetgamestate();
player->editstate = player->state;
player->state = CS_EDITING;
@@ -179,8 +155,7 @@ void toggleedit(bool force)
VARP(editinview, 0, 1, 1);
-bool noedit(bool view, bool msg)
-{
+bool noedit(bool view, bool msg) {
if(!editmode) { if(msg) conoutf(CON_ERROR, "operation only allowed in edit mode"); return true; }
if(view || haveselent()) return false;
float r = 1.0f;
@@ -194,8 +169,7 @@ bool noedit(bool view, bool msg)
return true;
}
-void reorient()
-{
+void reorient() {
sel.cx = 0;
sel.cy = 0;
sel.cxs = sel.s[R[dimension(orient)]]*2;
@@ -203,18 +177,14 @@ void reorient()
sel.orient = orient;
}
-void selextend()
-{
+void selextend() {
if(noedit(true)) return;
- loopi(3)
- {
- if(cur[i]<sel.o[i])
- {
+ loopi(3) {
+ if(cur[i]<sel.o[i]) {
sel.s[i] += (sel.o[i]-cur[i])/sel.grid;
sel.o[i] = cur[i];
}
- else if(cur[i]>=sel.o[i]+sel.s[i]*sel.grid)
- {
+ else if(cur[i]>=sel.o[i]+sel.s[i]*sel.grid) {
sel.s[i] = (cur[i]-sel.o[i])/sel.grid+1;
}
}
@@ -232,23 +202,20 @@ ICOMMAND(selsave, "", (), { if(noedit(true)) return; savedsel = sel; });
ICOMMAND(selrestore, "", (), { if(noedit(true)) return; sel = savedsel; });
ICOMMAND(selswap, "", (), { if(noedit(true)) return; swap(sel, savedsel); });
-ICOMMAND(getselpos, "", (),
-{
+ICOMMAND(getselpos, "", (), {
if(noedit(true)) return;
defformatstring(pos, "%s %s %s", floatstr(sel.o.x), floatstr(sel.o.y), floatstr(sel.o.z));
result(pos);
});
-void setselpos(int *x, int *y, int *z)
-{
+void setselpos(int *x, int *y, int *z) {
if(noedit(moving!=0)) return;
havesel = true;
sel.o = ivec(*x, *y, *z).mask(~(gridsize-1));
}
COMMAND(setselpos, "iii");
-void movesel(int *dir, int *dim)
-{
+void movesel(int *dir, int *dim) {
if(noedit(moving!=0)) return;
if(*dim < 0 || *dim > 2) return;
sel.o[*dim] += *dir * sel.grid;
@@ -257,8 +224,7 @@ COMMAND(movesel, "ii");
///////// selection support /////////////
-cube &blockcube(int x, int y, int z, const block3 &b, int rgrid) // looks up a world cube, based on coordinates mapped by the block
-{
+cube &blockcube(int x, int y, int z, const block3 &b, int rgrid) { // looks up a world cube, based on coordinates mapped by the block {
int dim = dimension(b.orient), dc = dimcoord(b.orient);
ivec s(dim, x*b.grid, y*b.grid, dc*(b.s[dim]-1)*b.grid);
s.add(b.o);
@@ -277,18 +243,14 @@ int selchildcount = 0, selchildmat = -1;
ICOMMAND(havesel, "", (), intret(havesel ? selchildcount : 0));
-void countselchild(cube *c, const ivec &cor, int size)
-{
+void countselchild(cube *c, const ivec &cor, int size) {
ivec ss = ivec(sel.s).mul(sel.grid);
- loopoctaboxsize(cor, size, sel.o, ss)
- {
+ loopoctaboxsize(cor, size, sel.o, ss) {
ivec o(i, cor, size);
if(c[i].children) countselchild(c[i].children, o, size/2);
- else
- {
+ else {
selchildcount++;
- if(c[i].material != MAT_AIR && selchildmat != MAT_AIR)
- {
+ if(c[i].material != MAT_AIR && selchildmat != MAT_AIR) {
if(selchildmat < 0) selchildmat = c[i].material;
else if(selchildmat != c[i].material) selchildmat = MAT_AIR;
}
@@ -296,16 +258,13 @@ void countselchild(cube *c, const ivec &cor, int size)
}
}
-void normalizelookupcube(const ivec &o)
-{
- if(lusize>gridsize)
- {
+void normalizelookupcube(const ivec &o) {
+ if(lusize>gridsize) {
lu.x += (o.x-lu.x)/gridsize*gridsize;
lu.y += (o.y-lu.y)/gridsize*gridsize;
lu.z += (o.z-lu.z)/gridsize*gridsize;
}
- else if(gridsize>lusize)
- {
+ else if(gridsize>lusize) {
lu.x &= ~(gridsize-1);
lu.y &= ~(gridsize-1);
lu.z &= ~(gridsize-1);
@@ -313,8 +272,7 @@ void normalizelookupcube(const ivec &o)
lusize = gridsize;
}
-void updateselection()
-{
+void updateselection() {
sel.o.x = min(lastcur.x, cur.x);
sel.o.y = min(lastcur.y, cur.y);
sel.o.z = min(lastcur.z, cur.z);
@@ -323,13 +281,11 @@ void updateselection()
sel.s.z = abs(lastcur.z-cur.z)/sel.grid+1;
}
-bool editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle, vec &dest, bool first)
-{
+bool editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle, vec &dest, bool first) {
plane pl(d, off);
float dist = 0.0f;
if(!pl.rayintersect(player->o, ray, dist))
return false;
-
dest = vec(ray).mul(dist).add(player->o);
if(first) handle = vec(dest).sub(o);
dest.sub(handle);
@@ -338,7 +294,7 @@ bool editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle,
extern void entdrag(const vec &ray);
extern bool hoveringonent(int ent, int orient);
-extern void renderentselection(const vec &o, const vec &ray, bool entmoving);
+extern void renderentselection(const vec &o, bool entmoving);
extern float rayent(const vec &o, const vec &ray, float radius, int mode, int size, int &orient, int &ent);
VAR(gridlookup, 0, 0, 1);
@@ -346,21 +302,15 @@ VAR(passthroughcube, 0, 1, 1);
VAR(passthroughent, 0, 1, 1);
VARF(passthrough, 0, 0, 1, { passthroughsel = passthrough; entcancel(); });
-void rendereditcursor()
-{
+void rendereditcursor() {
int d = dimension(sel.orient),
od = dimension(orient),
odc = dimcoord(orient);
-
bool hidecursor = g3d_windowhit(true, false), hovering = false;
-
- if(moving)
- {
+ if(moving) {
static vec dest, handle;
- if(editmoveplane(vec(sel.o), camdir, od, sel.o[D[od]]+odc*sel.grid*sel.s[D[od]], handle, dest, moving==1))
- {
- if(moving==1)
- {
+ if(editmoveplane(vec(sel.o), camdir, od, sel.o[D[od]]+odc*sel.grid*sel.s[D[od]], handle, dest, moving==1)) {
+ if(moving==1) {
dest.add(handle);
handle = vec(ivec(handle).mask(~(sel.grid-1)));
dest.sub(handle);
@@ -372,50 +322,40 @@ void rendereditcursor()
}
}
else
- if(entmoving)
- {
+ if(entmoving) {
entdrag(camdir);
}
- else
- {
+ else {
ivec w;
float sdist = 0, wdist = 0, t;
int entorient = 0, ent = -1;
-
wdist = rayent(player->o, camdir, 1e16f,
(editmode && showmat ? RAY_EDITMAT : 0) // select cubes first
| (!dragging && entediting && (!passthrough || !passthroughent) ? RAY_ENTS : 0)
| RAY_SKIPFIRST
| (passthroughcube || passthrough ? RAY_PASS : 0), gridsize, entorient, ent);
-
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)
- {
+ 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) {
wdist = sdist;
ent = -1;
}
}
-
- if((hovering = hoveringonent(hidecursor ? -1 : ent, entorient)))
- {
+ if((hovering = hoveringonent(hidecursor ? -1 : ent, entorient))) {
if(!havesel)
- {
+ {
selchildcount = 0;
selchildmat = -1;
sel.s = ivec(0, 0, 0);
}
}
- else
- {
+ else {
vec w = vec(camdir).mul(wdist+0.05f).add(player->o);
- if(!insideworld(w))
- {
+ if(!insideworld(w)) {
loopi(3) wdist = min(wdist, ((camdir[i] > 0 ? worldsize : 0) - player->o[i]) / camdir[i]);
w = vec(camdir).mul(wdist-0.05f).add(player->o);
- if(!insideworld(w))
- {
+ if(!insideworld(w)) {
wdist = 0;
loopi(3) w[i] = clamp(player->o[i], 0.0f, float(worldsize));
}
@@ -429,17 +369,13 @@ void rendereditcursor()
cor = ivec(vec(w).mul(2).div(gridsize));
od = dimension(orient);
d = dimension(sel.orient);
-
- if(dragging)
- {
+ if(dragging) {
updateselection();
sel.cx = min(cor[R[d]], lastcor[R[d]]);
sel.cy = min(cor[C[d]], lastcor[C[d]]);
sel.cxs = max(cor[R[d]], lastcor[R[d]]);
sel.cys = max(cor[C[d]], lastcor[C[d]]);
-
- if(!selectcorners)
- {
+ if(!selectcorners) {
sel.cx &= ~1;
sel.cy &= ~1;
sel.cxs &= ~1;
@@ -447,18 +383,15 @@ void rendereditcursor()
sel.cxs -= sel.cx-2;
sel.cys -= sel.cy-2;
}
- else
- {
+ else {
sel.cxs -= sel.cx-1;
sel.cys -= sel.cy-1;
}
-
sel.cx &= 1;
sel.cy &= 1;
havesel = true;
}
- else if(!havesel)
- {
+ else if(!havesel) {
sel.o = lu;
sel.s.x = sel.s.y = sel.s.z = 1;
sel.cx = sel.cy = 0;
@@ -467,41 +400,29 @@ void rendereditcursor()
sel.orient = orient;
d = od;
}
-
sel.corner = (cor[R[d]]-(lu[R[d]]*2)/gridsize)+(cor[C[d]]-(lu[C[d]]*2)/gridsize)*2;
selchildcount = 0;
selchildmat = -1;
countselchild(worldroot, ivec(0, 0, 0), worldsize/2);
- if(mag>=1 && selchildcount==1)
- {
+ if(mag>=1 && selchildcount==1) {
selchildmat = c->material;
if(mag>1) selchildcount = -mag;
}
}
}
-
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
-
// cursors
-
notextureshader->set();
-
- renderentselection(player->o, camdir, entmoving!=0);
-
+ renderentselection(player->o, entmoving!=0);
boxoutline = outline!=0;
-
enablepolygonoffset(GL_POLYGON_OFFSET_LINE);
-
- if(!moving && !hovering && !hidecursor)
- {
+ if(!moving && !hovering && !hidecursor) {
gle::colorub(120,120,120);
boxs(orient, vec(lu), vec(lusize));
}
-
// selections
- if(havesel || moving)
- {
+ if(havesel || moving) {
d = dimension(sel.orient);
gle::colorub(50,50,50); // grid
boxsgrid(sel.orient, vec(sel.o), vec(sel.s), sel.grid);
@@ -518,16 +439,12 @@ void rendereditcursor()
gle::colorub(0,0,120);
boxs3D(vec(sel.o), vec(sel.s), sel.grid);
}
-
disablepolygonoffset(GL_POLYGON_OFFSET_LINE);
-
boxoutline = false;
-
glDisable(GL_BLEND);
}
-void tryedit()
-{
+void tryedit() {
extern int hidehud;
if(!editmode || hidehud || mainmenu) return;
}
@@ -536,15 +453,11 @@ void tryedit()
static bool haschanged = false;
-void readychanges(const ivec &bbmin, const ivec &bbmax, cube *c, const ivec &cor, int size)
-{
- loopoctabox(cor, size, bbmin, bbmax)
- {
+void readychanges(const ivec &bbmin, const ivec &bbmax, cube *c, const ivec &cor, int size) {
+ loopoctabox(cor, size, bbmin, bbmax) {
ivec o(i, cor, size);
- if(c[i].ext)
- {
- if(c[i].ext->va) // removes va s so that octarender will recreate
- {
+ if(c[i].ext) {
+ if(c[i].ext->va) { // removes va s so that octarender will recreate {
int hasmerges = c[i].ext->va->hasmerges;
destroyva(c[i].ext->va);
c[i].ext->va = NULL;
@@ -553,10 +466,8 @@ void readychanges(const ivec &bbmin, const ivec &bbmax, cube *c, const ivec &cor
freeoctaentities(c[i]);
c[i].ext->tjoints = -1;
}
- if(c[i].children)
- {
- if(size<=1)
- {
+ if(c[i].children) {
+ if(size<=1) {
solidfaces(c[i]);
discardchildren(c[i], true);
brightencube(c[i]);
@@ -567,11 +478,9 @@ void readychanges(const ivec &bbmin, const ivec &bbmax, cube *c, const ivec &cor
}
}
-void commitchanges(bool force)
-{
+void commitchanges(bool force) {
if(!force && !haschanged) return;
haschanged = false;
-
int oldlen = valist.length();
resetclipplanes();
entitiesinoctanodes();
@@ -582,44 +491,37 @@ void commitchanges(bool force)
updatevabbs();
}
-void changed(const block3 &sel, bool commit = true)
-{
+void changed(const block3 &sel, bool commit = true) {
if(sel.s.iszero()) return;
readychanges(ivec(sel.o).sub(1), ivec(sel.s).mul(sel.grid).add(sel.o).add(1), worldroot, ivec(0, 0, 0), worldsize/2);
haschanged = true;
-
if(commit) commitchanges();
}
//////////// copy and undo /////////////
-static inline void copycube(const cube &src, cube &dst)
-{
+static inline void copycube(const cube &src, cube &dst) {
dst = src;
dst.visible = 0;
dst.merged = 0;
dst.ext = NULL; // src cube is responsible for va destruction
- if(src.children)
- {
+ if(src.children) {
dst.children = newcubes(F_EMPTY);
loopi(8) copycube(src.children[i], dst.children[i]);
}
}
-static inline void pastecube(const cube &src, cube &dst)
-{
+static inline void pastecube(const cube &src, cube &dst) {
discardchildren(dst);
copycube(src, dst);
}
-void blockcopy(const block3 &s, int rgrid, block3 *b)
-{
+void blockcopy(const block3 &s, int rgrid, block3 *b) {
*b = s;
cube *q = b->c();
loopxyz(s, rgrid, copycube(c, *q++));
}
-block3 *blockcopy(const block3 &s, int rgrid)
-{
+block3 *blockcopy(const block3 &s, int rgrid) {
int bsize = sizeof(block3)+sizeof(cube)*s.size();
if(bsize <= 0 || bsize > (100<<20)) return NULL;
block3 *b = (block3 *)new (false) uchar[bsize];
@@ -627,41 +529,34 @@ block3 *blockcopy(const block3 &s, int rgrid)
return b;
}
-void freeblock(block3 *b, bool alloced = true)
-{
+void freeblock(block3 *b, bool alloced = true) {
cube *q = b->c();
loopi(b->size()) discardchildren(*q++);
if(alloced) delete[] b;
}
-void selgridmap(selinfo &sel, uchar *g) // generates a map of the cube sizes at each grid point
-{
+void selgridmap(selinfo &sel, uchar *g) { // generates a map of the cube sizes at each grid point {
loopxyz(sel, -sel.grid, (*g++ = bitscan(lusize), (void)c));
}
-void freeundo(undoblock *u)
-{
+void freeundo(undoblock *u) {
if(!u->numents) freeblock(u->block(), false);
delete[] (uchar *)u;
}
-void pasteundoblock(block3 *b, uchar *g)
-{
+void pasteundoblock(block3 *b, uchar *g) {
cube *s = b->c();
loopxyz(*b, 1<<min(int(*g++), worldscale-1), pastecube(*s++, c));
}
-void pasteundo(undoblock *u)
-{
+void pasteundo(undoblock *u) {
if(u->numents) pasteundoents(u);
else pasteundoblock(u->block(), u->gridmap());
}
-static inline int undosize(undoblock *u)
-{
+static inline int undosize(undoblock *u) {
if(u->numents) return u->numents*sizeof(undoent);
- else
- {
+ else {
block3 *b = u->block();
cube *q = b->c();
int size = b->size(), total = size;
@@ -670,37 +565,27 @@ static inline int undosize(undoblock *u)
}
}
-struct undolist
-{
+struct undolist {
undoblock *first, *last;
-
undolist() : first(NULL), last(NULL) {}
-
bool empty() { return !first; }
-
- void add(undoblock *u)
- {
+ void add(undoblock *u) {
u->next = NULL;
u->prev = last;
if(!first) first = last = u;
- else
- {
+ else {
last->next = u;
last = u;
}
}
-
- undoblock *popfirst()
- {
+ undoblock *popfirst() {
undoblock *u = first;
first = first->next;
if(first) first->prev = NULL;
else last = NULL;
return u;
}
-
- undoblock *poplast()
- {
+ undoblock *poplast() {
undoblock *u = last;
last = last->prev;
if(last) last->next = NULL;
@@ -713,17 +598,14 @@ undolist undos, redos;
VARP(undomegs, 0, 8, 100); // bounded by n megs
int totalundos = 0;
-void pruneundos(int maxremain) // bound memory
-{
- while(totalundos > maxremain && !undos.empty())
- {
+void pruneundos(int maxremain) { // bound memory {
+ while(totalundos > maxremain && !undos.empty()) {
undoblock *u = undos.popfirst();
totalundos -= u->size;
freeundo(u);
}
//conoutf(CON_DEBUG, "undo: %d of %d(%%%d)", totalundos, undomegs<<20, totalundos*100/(undomegs<<20));
- while(!redos.empty())
- {
+ while(!redos.empty()) {
undoblock *u = redos.popfirst();
totalundos -= u->size;
freeundo(u);
@@ -734,8 +616,7 @@ void clearundos() { pruneundos(0); }
COMMAND(clearundos, "");
-undoblock *newundocube(selinfo &s)
-{
+undoblock *newundocube(selinfo &s) {
int ssize = s.size(),
selgridsize = ssize,
blocksize = sizeof(block3)+ssize*sizeof(cube);
@@ -750,8 +631,7 @@ undoblock *newundocube(selinfo &s)
return u;
}
-void addundo(undoblock *u)
-{
+void addundo(undoblock *u) {
u->size = undosize(u);
u->timestamp = totalmillis;
undos.add(u);
@@ -761,21 +641,18 @@ void addundo(undoblock *u)
VARP(nompedit, 0, 1, 1);
-void makeundo(selinfo &s)
-{
+void makeundo(selinfo &s) {
undoblock *u = newundocube(s);
if(u) addundo(u);
}
-void makeundo() // stores state of selected cubes before editing
-{
+void makeundo() { // stores state of selected cubes before editing {
if(lastsel==sel || sel.s.iszero()) return;
lastsel=sel;
makeundo(sel);
}
-static inline int countblock(cube *c, int n = 8)
-{
+static inline int countblock(cube *c, int n = 8) {
int r = 0;
loopi(n) if(c[i].children) r += countblock(c[i].children); else ++r;
return r;
@@ -783,20 +660,16 @@ static inline int countblock(cube *c, int n = 8)
static int countblock(block3 *b) { return countblock(b->c(), b->size()); }
-void swapundo(undolist &a, undolist &b, int op)
-{
+void swapundo(undolist &a, undolist &b, int op) {
if(noedit()) return;
if(a.empty()) { conoutf(CON_WARN, "nothing more to %s", op == EDIT_REDO ? "redo" : "undo"); return; }
int ts = a.last->timestamp;
- if(multiplayer(false))
- {
+ if(multiplayer(false)) {
int n = 0, ops = 0;
- for(undoblock *u = a.last; u && ts==u->timestamp; u = u->prev)
- {
+ for(undoblock *u = a.last; u && ts==u->timestamp; u = u->prev) {
++ops;
n += u->numents ? u->numents : countblock(u->block());
- if(ops > 10 || n > 2500)
- {
+ if(ops > 10 || n > 2500) {
conoutf(CON_WARN, "undo too big for multiplayer");
if(nompedit) { multiplayer(); return; }
op = -1;
@@ -805,13 +678,11 @@ void swapundo(undolist &a, undolist &b, int op)
}
}
selinfo l = sel;
- while(!a.empty() && ts==a.last->timestamp)
- {
+ while(!a.empty() && ts==a.last->timestamp) {
if(op >= 0) game::edittrigger(sel, op);
undoblock *u = a.poplast(), *r;
if(u->numents) r = copyundoents(u);
- else
- {
+ else {
block3 *ub = u->block();
l.o = ub->o;
l.s = ub->s;
@@ -819,8 +690,7 @@ void swapundo(undolist &a, undolist &b, int op)
l.orient = ub->orient;
r = newundocube(l);
}
- if(r)
- {
+ if(r) {
r->size = u->size;
r->timestamp = totalmillis;
b.add(r);
@@ -845,15 +715,12 @@ vector<editinfo *> editinfos;
editinfo *localedit = NULL;
template<class B>
-static void packcube(cube &c, B &buf)
-{
- if(c.children)
- {
+static void packcube(cube &c, B &buf) {
+ if(c.children) {
buf.put(0xFF);
loopi(8) packcube(c.children[i], buf);
}
- else
- {
+ else {
cube data = c;
lilswap(data.texture, 6);
buf.put(c.material&0xFF);
@@ -864,8 +731,7 @@ static void packcube(cube &c, B &buf)
}
template<class B>
-static bool packblock(block3 &b, B &buf)
-{
+static bool packblock(block3 &b, B &buf) {
if(b.size() <= 0 || b.size() > (1<<20)) return false;
block3 hdr = b;
lilswap(hdr.o.v, 3);
@@ -878,23 +744,18 @@ static bool packblock(block3 &b, B &buf)
return true;
}
-struct vslothdr
-{
+struct vslothdr {
ushort index;
ushort slot;
};
-static void packvslots(cube &c, vector<uchar> &buf, vector<ushort> &used)
-{
- if(c.children)
- {
+static void packvslots(cube &c, vector<uchar> &buf, vector<ushort> &used) {
+ if(c.children) {
loopi(8) packvslots(c.children[i], buf, used);
}
- else loopi(6)
- {
+ else loopi(6) {
ushort index = c.texture[i];
- if(vslots.inrange(index) && vslots[index]->changed && used.find(index) < 0)
- {
+ if(vslots.inrange(index) && vslots[index]->changed && used.find(index) < 0) {
used.add(index);
VSlot &vs = *vslots[index];
vslothdr &hdr = *(vslothdr *)buf.pad(sizeof(vslothdr));
@@ -906,8 +767,7 @@ static void packvslots(cube &c, vector<uchar> &buf, vector<ushort> &used)
}
}
-static void packvslots(block3 &b, vector<uchar> &buf)
-{
+static void packvslots(block3 &b, vector<uchar> &buf) {
vector<ushort> used;
cube *c = b.c();
loopi(b.size()) packvslots(c[i], buf, used);
@@ -915,16 +775,13 @@ static void packvslots(block3 &b, vector<uchar> &buf)
}
template<class B>
-static void unpackcube(cube &c, B &buf)
-{
+static void unpackcube(cube &c, B &buf) {
int mat = buf.get();
- if(mat == 0xFF)
- {
+ if(mat == 0xFF) {
c.children = newcubes(F_EMPTY);
loopi(8) unpackcube(c.children[i], buf);
}
- else
- {
+ else {
c.material = mat | (buf.get()<<8);
buf.get(c.edges, sizeof(c.edges));
buf.get((uchar *)c.texture, sizeof(c.texture));
@@ -933,8 +790,7 @@ static void unpackcube(cube &c, B &buf)
}
template<class B>
-static bool unpackblock(block3 *&b, B &buf)
-{
+static bool unpackblock(block3 *&b, B &buf) {
if(b) { freeblock(b); b = NULL; }
block3 hdr;
if(buf.get((uchar *)&hdr, sizeof(hdr)) < int(sizeof(hdr))) return false;
@@ -952,33 +808,26 @@ static bool unpackblock(block3 *&b, B &buf)
return true;
}
-struct vslotmap
-{
+struct vslotmap {
int index;
VSlot *vslot;
-
vslotmap() {}
vslotmap(int index, VSlot *vslot) : index(index), vslot(vslot) {}
};
static vector<vslotmap> unpackingvslots;
-static void unpackvslots(cube &c, ucharbuf &buf)
-{
- if(c.children)
- {
+static void unpackvslots(cube &c, ucharbuf &buf) {
+ if(c.children) {
loopi(8) unpackvslots(c.children[i], buf);
}
- else loopi(6)
- {
+ else loopi(6) {
ushort tex = c.texture[i];
loopvj(unpackingvslots) if(unpackingvslots[j].index == tex) { c.texture[i] = unpackingvslots[j].vslot->index; break; }
}
}
-static void unpackvslots(block3 &b, ucharbuf &buf)
-{
- while(buf.remaining() >= int(sizeof(vslothdr)))
- {
+static void unpackvslots(block3 &b, ucharbuf &buf) {
+ while(buf.remaining() >= int(sizeof(vslothdr))) {
vslothdr &hdr = *(vslothdr *)buf.pad(sizeof(vslothdr));
lilswap(&hdr.index, 2);
if(!hdr.index) break;
@@ -989,20 +838,16 @@ static void unpackvslots(block3 &b, ucharbuf &buf)
VSlot *edit = editvslot(vs, ds);
unpackingvslots.add(vslotmap(hdr.index, edit ? edit : &vs));
}
-
cube *c = b.c();
loopi(b.size()) unpackvslots(c[i], buf);
-
unpackingvslots.setsize(0);
}
-static bool compresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int &outlen)
-{
+static bool compresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int &outlen) {
uLongf len = compressBound(inlen);
if(len > (1<<20)) return false;
outbuf = new (false) uchar[len];
- if(!outbuf || compress2((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen, Z_BEST_COMPRESSION) != Z_OK || len > (1<<16))
- {
+ if(!outbuf || compress2((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen, Z_BEST_COMPRESSION) != Z_OK || len > (1<<16)) {
delete[] outbuf;
outbuf = NULL;
return false;
@@ -1011,13 +856,11 @@ static bool compresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int
return true;
}
-static bool uncompresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int &outlen)
-{
+static bool uncompresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int &outlen) {
if(compressBound(outlen) > (1<<20)) return false;
uLongf len = outlen;
outbuf = new (false) uchar[len];
- if(!outbuf || uncompress((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen) != Z_OK)
- {
+ if(!outbuf || uncompress((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen) != Z_OK) {
delete[] outbuf;
outbuf = NULL;
return false;
@@ -1026,8 +869,7 @@ static bool uncompresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, in
return true;
}
-bool packeditinfo(editinfo *e, int &inlen, uchar *&outbuf, int &outlen)
-{
+bool packeditinfo(editinfo *e, int &inlen, uchar *&outbuf, int &outlen) {
vector<uchar> buf;
if(!e || !e->copy || !packblock(*e->copy, buf)) return false;
packvslots(*e->copy, buf);
@@ -1035,15 +877,13 @@ bool packeditinfo(editinfo *e, int &inlen, uchar *&outbuf, int &outlen)
return compresseditinfo(buf.getbuf(), buf.length(), outbuf, outlen);
}
-bool unpackeditinfo(editinfo *&e, const uchar *inbuf, int inlen, int outlen)
-{
+bool unpackeditinfo(editinfo *&e, const uchar *inbuf, int inlen, int outlen) {
if(e && e->copy) { freeblock(e->copy); e->copy = NULL; }
uchar *outbuf = NULL;
if(!uncompresseditinfo(inbuf, inlen, outbuf, outlen)) return false;
ucharbuf buf(outbuf, outlen);
if(!e) e = editinfos.add(new editinfo);
- if(!unpackblock(e->copy, buf))
- {
+ if(!unpackblock(e->copy, buf)) {
delete[] outbuf;
return false;
}
@@ -1052,8 +892,7 @@ bool unpackeditinfo(editinfo *&e, const uchar *inbuf, int inlen, int outlen)
return true;
}
-void freeeditinfo(editinfo *&e)
-{
+void freeeditinfo(editinfo *&e) {
if(!e) return;
editinfos.removeobj(e);
if(e->copy) freeblock(e->copy);
@@ -1061,16 +900,13 @@ void freeeditinfo(editinfo *&e)
e = NULL;
}
-bool packundo(undoblock *u, int &inlen, uchar *&outbuf, int &outlen)
-{
+bool packundo(undoblock *u, int &inlen, uchar *&outbuf, int &outlen) {
vector<uchar> buf;
buf.reserve(512);
*(ushort *)buf.pad(2) = lilswap(ushort(u->numents));
- if(u->numents)
- {
+ if(u->numents) {
undoent *ue = u->ents();
- loopi(u->numents)
- {
+ loopi(u->numents) {
*(ushort *)buf.pad(2) = lilswap(ushort(ue[i].i));
entity &e = *(entity *)buf.pad(sizeof(entity));
e = ue[i].e;
@@ -1078,8 +914,7 @@ bool packundo(undoblock *u, int &inlen, uchar *&outbuf, int &outlen)
lilswap(&e.attr1, 5);
}
}
- else
- {
+ else {
block3 &b = *u->block();
if(!packblock(b, buf)) return false;
buf.put(u->gridmap(), b.size());
@@ -1089,26 +924,21 @@ bool packundo(undoblock *u, int &inlen, uchar *&outbuf, int &outlen)
return compresseditinfo(buf.getbuf(), buf.length(), outbuf, outlen);
}
-bool unpackundo(const uchar *inbuf, int inlen, int outlen)
-{
+bool unpackundo(const uchar *inbuf, int inlen, int outlen) {
uchar *outbuf = NULL;
if(!uncompresseditinfo(inbuf, inlen, outbuf, outlen)) return false;
ucharbuf buf(outbuf, outlen);
- if(buf.remaining() < 2)
- {
+ if(buf.remaining() < 2) {
delete[] outbuf;
return false;
}
int numents = lilswap(*(const ushort *)buf.pad(2));
- if(numents)
- {
- if(buf.remaining() < numents*int(2 + sizeof(entity)))
- {
+ if(numents) {
+ if(buf.remaining() < numents*int(2 + sizeof(entity))) {
delete[] outbuf;
return false;
}
- loopi(numents)
- {
+ loopi(numents) {
int idx = lilswap(*(const ushort *)buf.pad(2));
entity &e = *(entity *)buf.pad(sizeof(entity));
lilswap(&e.o.x, 3);
@@ -1116,11 +946,9 @@ bool unpackundo(const uchar *inbuf, int inlen, int outlen)
pasteundoent(idx, e);
}
}
- else
- {
+ else {
block3 *b = NULL;
- if(!unpackblock(b, buf) || b->grid >= worldsize || buf.remaining() < b->size())
- {
+ if(!unpackblock(b, buf) || b->grid >= worldsize || buf.remaining() < b->size()) {
freeblock(b);
delete[] outbuf;
return false;
@@ -1136,33 +964,26 @@ bool unpackundo(const uchar *inbuf, int inlen, int outlen)
return true;
}
-bool packundo(int op, int &inlen, uchar *&outbuf, int &outlen)
-{
- switch(op)
- {
+bool packundo(int op, int &inlen, uchar *&outbuf, int &outlen) {
+ switch(op) {
case EDIT_UNDO: return !undos.empty() && packundo(undos.last, inlen, outbuf, outlen);
case EDIT_REDO: return !redos.empty() && packundo(redos.last, inlen, outbuf, outlen);
default: return false;
}
}
-struct prefabheader
-{
+struct prefabheader {
char magic[4];
int version;
};
-struct prefab : editinfo
-{
+struct prefab : editinfo {
char *name;
GLuint ebo, vbo;
int numtris, numverts;
-
prefab() : name(NULL), ebo(0), vbo(0), numtris(0), numverts(0) {}
~prefab() { DELETEA(name); if(copy) freeblock(copy); }
-
- void cleanup()
- {
+ void cleanup() {
if(ebo) { glDeleteBuffers_(1, &ebo); ebo = 0; }
if(vbo) { glDeleteBuffers_(1, &vbo); vbo = 0; }
numtris = numverts = 0;
@@ -1171,16 +992,13 @@ struct prefab : editinfo
static hashnameset<prefab> prefabs;
-void cleanupprefabs()
-{
+void cleanupprefabs() {
enumerate(prefabs, prefab, p, p.cleanup());
}
-void delprefab(char *name)
-{
+void delprefab(char *name) {
prefab *p = prefabs.access(name);
- if(p)
- {
+ if(p) {
p->cleanup();
prefabs.remove(name);
conoutf("deleted prefab %s", name);
@@ -1188,12 +1006,10 @@ void delprefab(char *name)
}
COMMAND(delprefab, "s");
-void saveprefab(char *name)
-{
+void saveprefab(char *name) {
if(!name[0] || noedit(true) || (nompedit && multiplayer())) return;
prefab *b = prefabs.access(name);
- if(!b)
- {
+ if(!b) {
b = &prefabs[name];
b->name = newstring(name);
}
@@ -1216,8 +1032,7 @@ void saveprefab(char *name)
}
COMMAND(saveprefab, "s");
-void pasteblock(block3 &b, selinfo &sel, bool local)
-{
+void pasteblock(block3 &b, selinfo &sel, bool local) {
sel.s = b.s;
int o = sel.orient;
sel.orient = b.orient;
@@ -1226,13 +1041,11 @@ void pasteblock(block3 &b, selinfo &sel, bool local)
sel.orient = o;
}
-bool prefabloaded(const char *name)
-{
+bool prefabloaded(const char *name) {
return prefabs.access(name) != NULL;
}
-prefab *loadprefab(const char *name, bool msg = true)
-{
+prefab *loadprefab(const char *name, bool msg = true) {
prefab *b = prefabs.access(name);
if(b) return b;
@@ -1256,31 +1069,24 @@ prefab *loadprefab(const char *name, bool msg = true)
return b;
}
-void pasteprefab(char *name)
-{
+void pasteprefab(char *name) {
if(!name[0] || noedit() || (nompedit && multiplayer())) return;
prefab *b = loadprefab(name, true);
if(b) pasteblock(*b->copy, sel, true);
}
COMMAND(pasteprefab, "s");
-struct prefabmesh
-{
+struct prefabmesh {
struct vertex { vec pos; bvec4 norm; };
-
static const int SIZE = 1<<9;
int table[SIZE];
vector<vertex> verts;
vector<int> chain;
vector<ushort> tris;
-
prefabmesh() { memset(table, -1, sizeof(table)); }
-
- int addvert(const vertex &v)
- {
+ int addvert(const vertex &v) {
uint h = hthash(v.pos)&(SIZE-1);
- for(int i = table[h]; i>=0; i = chain[i])
- {
+ for(int i = table[h]; i>=0; i = chain[i]) {
const vertex &c = verts[i];
if(c.pos==v.pos && c.norm==v.norm) return i;
}
@@ -1289,28 +1095,21 @@ struct prefabmesh
chain.add(table[h]);
return table[h] = verts.length()-1;
}
-
- int addvert(const vec &pos, const bvec &norm)
- {
+ int addvert(const vec &pos, const bvec &norm) {
vertex vtx;
vtx.pos = pos;
vtx.norm = norm;
return addvert(vtx);
}
-
- void setup(prefab &p)
- {
+ void setup(prefab &p) {
if(tris.empty()) return;
-
p.cleanup();
-
loopv(verts) verts[i].norm.flip();
if(!p.vbo) glGenBuffers_(1, &p.vbo);
gle::bindvbo(p.vbo);
glBufferData_(GL_ARRAY_BUFFER, verts.length()*sizeof(vertex), verts.getbuf(), GL_STATIC_DRAW);
gle::clearvbo();
p.numverts = verts.length();
-
if(!p.ebo) glGenBuffers_(1, &p.ebo);
gle::bindebo(p.ebo);
glBufferData_(GL_ELEMENT_ARRAY_BUFFER, tris.length()*sizeof(ushort), tris.getbuf(), GL_STATIC_DRAW);
@@ -1320,23 +1119,18 @@ struct prefabmesh
};
-static void genprefabmesh(prefabmesh &r, cube &c, const ivec &co, int size)
-{
- if(c.children)
- {
+static void genprefabmesh(prefabmesh &r, cube &c, const ivec &co, int size) {
+ if(c.children) {
neighbourstack[++neighbourdepth] = c.children;
- loopi(8)
- {
+ loopi(8) {
ivec o(i, co, size/2);
genprefabmesh(r, c.children[i], o, size/2);
}
--neighbourdepth;
}
- else if(!isempty(c))
- {
+ else if(!isempty(c)) {
int vis;
- loopi(6) if((vis = visibletris(c, i, co, size)))
- {
+ loopi(6) if((vis = visibletris(c, i, co, size))) {
ivec v[4];
genfaceverts(c, i, v);
int convex = 0;
@@ -1350,8 +1144,7 @@ static void genprefabmesh(prefabmesh &r, cube &c, const ivec &co, int size)
guessnormals(pos, numverts, norm);
int index[4];
loopj(numverts) index[j] = r.addvert(pos[j], bvec(norm[j]));
- loopj(numverts-2) if(index[0]!=index[j+1] && index[j+1]!=index[j+2] && index[j+2]!=index[0])
- {
+ loopj(numverts-2) if(index[0]!=index[j+1] && index[j+1]!=index[j+2] && index[j+2]!=index[0]) {
r.tris.add(index[0]);
r.tris.add(index[j+1]);
r.tris.add(index[j+2]);
@@ -1360,53 +1153,40 @@ static void genprefabmesh(prefabmesh &r, cube &c, const ivec &co, int size)
}
}
-void genprefabmesh(prefab &p)
-{
+void genprefabmesh(prefab &p) {
block3 b = *p.copy;
b.o = ivec(0, 0, 0);
-
cube *oldworldroot = worldroot;
int oldworldscale = worldscale, oldworldsize = worldsize;
-
worldroot = newcubes();
worldscale = 1;
worldsize = 2;
- while(worldsize < max(max(b.s.x, b.s.y), b.s.z)*b.grid)
- {
+ while(worldsize < max(max(b.s.x, b.s.y), b.s.z)*b.grid) {
worldscale++;
worldsize *= 2;
}
-
cube *s = p.copy->c();
loopxyz(b, b.grid, if(!isempty(*s) || s->children) pastecube(*s, c); s++);
-
prefabmesh r;
neighbourstack[++neighbourdepth] = worldroot;
loopi(8) genprefabmesh(r, worldroot[i], ivec(i, ivec(0, 0, 0), worldsize/2), worldsize/2);
--neighbourdepth;
r.setup(p);
-
freeocta(worldroot);
-
worldroot = oldworldroot;
worldscale = oldworldscale;
worldsize = oldworldsize;
-
useshaderbyname("prefab");
}
extern int outlinecolour;
-static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float roll, float size, const vec &color)
-{
- if(!p.numtris)
- {
+static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float roll, float size, const vec &color) {
+ if(!p.numtris) {
genprefabmesh(p);
if(!p.numtris) return;
}
-
block3 &b = *p.copy;
-
matrix4 m;
m.identity();
m.settranslation(o);
@@ -1416,7 +1196,6 @@ static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float
matrix3 w(m);
if(size > 0 && size != 1) m.scale(size);
m.translate(vec(b.s).mul(-b.grid*0.5f));
-
gle::bindvbo(p.vbo);
gle::bindebo(p.ebo);
gle::enablevertex();
@@ -1424,7 +1203,6 @@ static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float
prefabmesh::vertex *v = (prefabmesh::vertex *)0;
gle::vertexpointer(sizeof(prefabmesh::vertex), v->pos.v);
gle::normalpointer(sizeof(prefabmesh::vertex), v->norm.v, GL_BYTE);
-
matrix4 pm;
pm.mul(camprojmatrix, m);
GLOBALPARAM(prefabmatrix, pm);
@@ -1432,36 +1210,29 @@ static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float
SETSHADER(prefab);
gle::color(color);
glDrawRangeElements_(GL_TRIANGLES, 0, p.numverts-1, p.numtris*3, GL_UNSIGNED_SHORT, (ushort *)0);
-
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
enablepolygonoffset(GL_POLYGON_OFFSET_LINE);
-
pm.mul(camprojmatrix, m);
GLOBALPARAM(prefabmatrix, pm);
SETSHADER(prefab);
gle::color(vec::hexcolor(outlinecolour));
glDrawRangeElements_(GL_TRIANGLES, 0, p.numverts-1, p.numtris*3, GL_UNSIGNED_SHORT, (ushort *)0);
-
disablepolygonoffset(GL_POLYGON_OFFSET_LINE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
gle::disablevertex();
gle::disablenormal();
gle::clearebo();
gle::clearvbo();
}
-void renderprefab(const char *name, const vec &o, float yaw, float pitch, float roll, float size, const vec &color)
-{
+void renderprefab(const char *name, const vec &o, float yaw, float pitch, float roll, float size, const vec &color) {
prefab *p = loadprefab(name, false);
if(p) renderprefab(*p, o, yaw, pitch, roll, size, color);
}
-void previewprefab(const char *name, const vec &color)
-{
+void previewprefab(const char *name, const vec &color) {
prefab *p = loadprefab(name, false);
- if(p)
- {
+ if(p) {
block3 &b = *p->copy;
float yaw;
vec o = calcmodelpreviewpos(vec(b.s).mul(b.grid*0.5f), yaw);
@@ -1469,8 +1240,7 @@ void previewprefab(const char *name, const vec &color)
}
}
-void mpcopy(editinfo *&e, selinfo &sel, bool local)
-{
+void mpcopy(editinfo *&e, selinfo &sel, bool local) {
if(local) game::edittrigger(sel, EDIT_COPY);
if(e==NULL) e = editinfos.add(new editinfo);
if(e->copy) freeblock(e->copy);
@@ -1479,29 +1249,25 @@ void mpcopy(editinfo *&e, selinfo &sel, bool local)
changed(sel);
}
-void mppaste(editinfo *&e, selinfo &sel, bool local)
-{
+void mppaste(editinfo *&e, selinfo &sel, bool local) {
if(e==NULL) return;
if(local) game::edittrigger(sel, EDIT_PASTE);
if(e->copy) pasteblock(*e->copy, sel, local);
}
-void copy()
-{
+void copy() {
if(noedit(true)) return;
mpcopy(localedit, sel, true);
}
-void pastehilite()
-{
+void pastehilite() {
if(!localedit) return;
sel.s = localedit->copy->s;
reorient();
havesel = true;
}
-void paste()
-{
+void paste() {
if(noedit(true)) return;
mppaste(localedit, sel, true);
}
@@ -1513,19 +1279,16 @@ COMMANDN(undo, editundo, "");
COMMANDN(redo, editredo, "");
static vector<int *> editingvslots;
-struct vslotref
-{
+struct vslotref {
vslotref(int &index) { editingvslots.add(&index); }
~vslotref() { editingvslots.pop(); }
};
#define editingvslot(...) vslotref vslotrefs[] = { __VA_ARGS__ }; (void)vslotrefs;
-void compacteditvslots()
-{
+void compacteditvslots() {
loopv(editingvslots) if(*editingvslots[i]) compactvslot(*editingvslots[i]);
loopv(unpackingvslots) compactvslot(*unpackingvslots[i].vslot);
- loopv(editinfos)
- {
+ loopv(editinfos) {
editinfo *e = editinfos[i];
compactvslots(e->copy->c(), e->copy->size());
}
@@ -1541,31 +1304,25 @@ void compacteditvslots()
int bounded(int n) { return n<0 ? 0 : (n>8 ? 8 : n); }
-void pushedge(uchar &edge, int dir, int dc)
-{
+void pushedge(uchar &edge, int dir, int dc) {
int ne = bounded(edgeget(edge, dc)+dir);
edgeset(edge, dc, ne);
int oe = edgeget(edge, 1-dc);
if((dir<0 && dc && oe>ne) || (dir>0 && dc==0 && oe<ne)) edgeset(edge, 1-dc, ne);
}
-void linkedpush(cube &c, int d, int x, int y, int dc, int dir)
-{
+void linkedpush(cube &c, int d, int x, int y, int dc, int dir) {
ivec v, p;
getcubevector(c, d, x, y, dc, v);
-
- loopi(2) loopj(2)
- {
+ loopi(2) loopj(2) {
getcubevector(c, d, i, j, dc, p);
if(v==p)
pushedge(cubeedge(c, d, i, j), dir, dc);
}
}
-static ushort getmaterial(cube &c)
-{
- if(c.children)
- {
+static ushort getmaterial(cube &c) {
+ if(c.children) {
ushort mat = getmaterial(c.children[7]);
loopi(7) if(mat != getmaterial(c.children[i])) return MAT_AIR;
return mat;
@@ -1575,35 +1332,27 @@ static ushort getmaterial(cube &c)
VAR(invalidcubeguard, 0, 1, 1);
-void mpeditface(int dir, int mode, selinfo &sel, bool local)
-{
+void mpeditface(int dir, int mode, selinfo &sel, bool local) {
if(mode==1 && (sel.cx || sel.cy || sel.cxs&1 || sel.cys&1)) mode = 0;
int d = dimension(sel.orient);
int dc = dimcoord(sel.orient);
int seldir = dc ? -dir : dir;
-
if(local)
game::edittrigger(sel, EDIT_FACE, dir, mode);
-
- if(mode==1)
- {
+ if(mode==1) {
int h = sel.o[d]+dc*sel.grid;
if(((dir>0) == dc && h<=0) || ((dir<0) == dc && h>=worldsize)) return;
if(dir<0) sel.o[d] += sel.grid * seldir;
}
-
if(dc) sel.o[d] += sel.us(d)-sel.grid;
sel.s[d] = 1;
-
loopselxyz(
if(c.children) solidfaces(c);
ushort mat = getmaterial(c);
discardchildren(c, true);
c.material = mat;
- if(mode==1) // fill command
- {
- if(dir<0)
- {
+ if(mode==1) { // fill command {
+ if(dir<0) {
solidfaces(c);
cube &o = blockcube(x, y, 1, sel, -sel.grid);
loopi(6)
@@ -1612,35 +1361,27 @@ void mpeditface(int dir, int mode, selinfo &sel, bool local)
else
emptyfaces(c);
}
- else
- {
+ else {
uint bak = c.faces[d];
uchar *p = (uchar *)&c.faces[d];
-
if(mode==2)
linkedpush(c, d, sel.corner&1, sel.corner>>1, dc, seldir); // corner command
- else
- {
- loop(mx,2) loop(my,2) // pull/push edges command
- {
+ else {
+ loop(mx,2) loop(my,2) { // pull/push edges command {
if(x==0 && mx==0 && sel.cx) continue;
if(y==0 && my==0 && sel.cy) continue;
if(x==sel.s[R[d]]-1 && mx==1 && (sel.cx+sel.cxs)&1) continue;
if(y==sel.s[C[d]]-1 && my==1 && (sel.cy+sel.cys)&1) continue;
if(p[mx+my*2] != ((uchar *)&bak)[mx+my*2]) continue;
-
linkedpush(c, d, mx, my, dc, seldir);
}
}
-
optiface(p, c);
- if(invalidcubeguard==1 && !isvalidcube(c))
- {
+ if(invalidcubeguard==1 && !isvalidcube(c)) {
uint newbak = c.faces[d];
uchar *m = (uchar *)&bak;
uchar *n = (uchar *)&newbak;
- loopk(4) if(n[k] != m[k]) // tries to find partial edit that is valid
- {
+ loopk(4) if(n[k] != m[k]) { // tries to find partial edit that is valid {
c.faces[d] = bak;
c.edges[d*4+k] = n[k];
if(isvalidcube(c))
@@ -1654,35 +1395,30 @@ void mpeditface(int dir, int mode, selinfo &sel, bool local)
sel.o[d] += sel.grid * seldir;
}
-void editface(int *dir, int *mode)
-{
+void editface(int *dir, int *mode) {
if(noedit(moving!=0)) return;
mpeditface(*dir, *mode, sel, true);
}
VAR(selectionsurf, 0, 0, 1);
-void pushsel(int *dir)
-{
+void pushsel(int *dir) {
if(noedit(moving!=0)) return;
int d = dimension(orient);
int s = dimcoord(orient) ? -*dir : *dir;
sel.o[d] += s*sel.grid;
- if(selectionsurf==1)
- {
+ if(selectionsurf==1) {
player->o[d] += s*sel.grid;
player->resetinterp();
}
}
-void mpdelcube(selinfo &sel, bool local)
-{
+void mpdelcube(selinfo &sel, bool local) {
if(local) game::edittrigger(sel, EDIT_DELCUBE);
loopselxyz(discardchildren(c, true); emptyfaces(c));
}
-void delcube()
-{
+void delcube() {
if(noedit(true)) return;
mpdelcube(sel, true);
}
@@ -1697,11 +1433,9 @@ int curtexindex = -1, lasttex = 0, lasttexmillis = -1;
int texpaneltimer = 0;
vector<ushort> texmru;
-void tofronttex() // maintain most recently used of the texture lists when applying texture
-{
+void tofronttex() { // maintain most recently used of the texture lists when applying texture {
int c = curtexindex;
- if(texmru.inrange(c))
- {
+ if(texmru.inrange(c)) {
texmru.insert(0, texmru.remove(c));
curtexindex = -1;
}
@@ -1714,14 +1448,12 @@ static vector<vslotmap> remappedvslots;
VAR(usevdelta, 1, 0, 0);
-static VSlot *remapvslot(int index, bool delta, const VSlot &ds)
-{
+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) return NULL;
VSlot *edit = NULL;
- if(delta)
- {
+ if(delta) {
VSlot ms;
mergevslot(ms, vs, ds);
edit = ms.changed ? editvslot(vs, ms) : vs.slot->variants;
@@ -1732,31 +1464,24 @@ static VSlot *remapvslot(int index, bool delta, const VSlot &ds)
return edit;
}
-static void remapvslots(cube &c, bool delta, const VSlot &ds, int orient, bool &findrep, VSlot *&findedit)
-{
- if(c.children)
- {
+static void remapvslots(cube &c, bool delta, const VSlot &ds, int orient, bool &findrep, VSlot *&findedit) {
+ if(c.children) {
loopi(8) remapvslots(c.children[i], delta, ds, orient, findrep, findedit);
return;
}
static VSlot ms;
- if(orient<0) loopi(6)
- {
+ if(orient<0) loopi(6) {
VSlot *edit = remapvslot(c.texture[i], delta, ds);
- if(edit)
- {
+ if(edit) {
c.texture[i] = edit->index;
if(!findedit) findedit = edit;
}
}
- else
- {
+ else {
int i = visibleorient(c, orient);
VSlot *edit = remapvslot(c.texture[i], delta, ds);
- if(edit)
- {
- if(findrep)
- {
+ if(edit) {
+ if(findrep) {
if(reptex < 0) reptex = c.texture[i];
else if(reptex != c.texture[i]) findrep = false;
}
@@ -1766,14 +1491,11 @@ static void remapvslots(cube &c, bool delta, const VSlot &ds, int orient, bool &
}
}
-void edittexcube(cube &c, int tex, int orient, bool &findrep)
-{
+void edittexcube(cube &c, int tex, int orient, bool &findrep) {
if(orient<0) loopi(6) c.texture[i] = tex;
- else
- {
+ else {
int i = visibleorient(c, orient);
- if(findrep)
- {
+ if(findrep) {
if(reptex < 0) reptex = c.texture[i];
else if(reptex != c.texture[i]) findrep = false;
}
@@ -1784,10 +1506,8 @@ void edittexcube(cube &c, int tex, int orient, bool &findrep)
VAR(allfaces, 0, 0, 1);
-void mpeditvslot(int delta, VSlot &ds, int allfaces, selinfo &sel, bool local)
-{
- if(local)
- {
+void mpeditvslot(int delta, VSlot &ds, int allfaces, selinfo &sel, bool local) {
+ if(local) {
game::edittrigger(sel, EDIT_VSLOT, delta, allfaces, 0, &ds);
if(!(lastsel==sel)) tofronttex();
if(allfaces || !(repsel == sel)) reptex = -1;
@@ -1797,21 +1517,18 @@ void mpeditvslot(int delta, VSlot &ds, int allfaces, selinfo &sel, bool local)
VSlot *findedit = NULL;
loopselxyz(remapvslots(c, delta != 0, ds, allfaces ? -1 : sel.orient, findrep, findedit));
remappedvslots.setsize(0);
- if(local && findedit)
- {
+ if(local && findedit) {
lasttex = findedit->index;
lasttexmillis = totalmillis;
curtexindex = texmru.find(lasttex);
- if(curtexindex < 0)
- {
+ if(curtexindex < 0) {
curtexindex = texmru.length();
texmru.add(lasttex);
}
}
}
-bool mpeditvslot(int delta, int allfaces, selinfo &sel, ucharbuf &buf)
-{
+bool mpeditvslot(int delta, int allfaces, selinfo &sel, ucharbuf &buf) {
VSlot ds;
if(!unpackvslot(buf, ds, delta != 0)) return false;
editingvslot(ds.layer);
@@ -1819,8 +1536,7 @@ bool mpeditvslot(int delta, int allfaces, selinfo &sel, ucharbuf &buf)
return true;
}
-void vdelta(char *body)
-{
+void vdelta(char *body) {
if(noedit()) return;
usevdelta++;
execute(body);
@@ -1828,8 +1544,7 @@ void vdelta(char *body)
}
COMMAND(vdelta, "s");
-void vrotate(int *n)
-{
+void vrotate(int *n) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_ROTATION;
@@ -1839,8 +1554,7 @@ void vrotate(int *n)
COMMAND(vrotate, "i");
ICOMMAND(getvrotate, "i", (int *tex), intret(lookupvslot(*tex, false).rotation));
-void voffset(int *x, int *y)
-{
+void voffset(int *x, int *y) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_OFFSET;
@@ -1848,15 +1562,13 @@ void voffset(int *x, int *y)
mpeditvslot(usevdelta, ds, allfaces, sel, true);
}
COMMAND(voffset, "ii");
-ICOMMAND(getvoffset, "i", (int *tex),
-{
+ICOMMAND(getvoffset, "i", (int *tex), {
VSlot &vslot = lookupvslot(*tex, false);
defformatstring(str, "%d %d", vslot.offset.x, vslot.offset.y);
result(str);
});
-void vscroll(float *s, float *t)
-{
+void vscroll(float *s, float *t) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_SCROLL;
@@ -1864,15 +1576,13 @@ void vscroll(float *s, float *t)
mpeditvslot(usevdelta, ds, allfaces, sel, true);
}
COMMAND(vscroll, "ff");
-ICOMMAND(getvscroll, "i", (int *tex),
-{
+ICOMMAND(getvscroll, "i", (int *tex), {
VSlot &vslot = lookupvslot(*tex, false);
defformatstring(str, "%s %s", floatstr(vslot.scroll.x), floatstr(vslot.scroll.y));
result(str);
});
-void vscale(float *scale)
-{
+void vscale(float *scale) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_SCALE;
@@ -1882,13 +1592,11 @@ void vscale(float *scale)
COMMAND(vscale, "f");
ICOMMAND(getvscale, "i", (int *tex), floatret(lookupvslot(*tex, false).scale));
-void vlayer(int *n)
-{
+void vlayer(int *n) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_LAYER;
- if(vslots.inrange(*n))
- {
+ if(vslots.inrange(*n)) {
ds.layer = *n;
if(vslots[ds.layer]->changed && nompedit && multiplayer()) return;
}
@@ -1898,8 +1606,7 @@ void vlayer(int *n)
COMMAND(vlayer, "i");
ICOMMAND(getvlayer, "i", (int *tex), intret(lookupvslot(*tex, false).layer));
-void valpha(float *front, float *back)
-{
+void valpha(float *front, float *back) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_ALPHA;
@@ -1908,15 +1615,13 @@ void valpha(float *front, float *back)
mpeditvslot(usevdelta, ds, allfaces, sel, true);
}
COMMAND(valpha, "ff");
-ICOMMAND(getvalpha, "i", (int *tex),
-{
+ICOMMAND(getvalpha, "i", (int *tex), {
VSlot &vslot = lookupvslot(*tex, false);
defformatstring(str, "%s %s", floatstr(vslot.alphafront), floatstr(vslot.alphaback));
result(str);
});
-void vcolor(float *r, float *g, float *b)
-{
+void vcolor(float *r, float *g, float *b) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_COLOR;
@@ -1924,54 +1629,45 @@ void vcolor(float *r, float *g, float *b)
mpeditvslot(usevdelta, ds, allfaces, sel, true);
}
COMMAND(vcolor, "fff");
-ICOMMAND(getvcolor, "i", (int *tex),
-{
+ICOMMAND(getvcolor, "i", (int *tex), {
VSlot &vslot = lookupvslot(*tex, false);
defformatstring(str, "%s %s %s", floatstr(vslot.colorscale.r), floatstr(vslot.colorscale.g), floatstr(vslot.colorscale.b));
result(str);
});
-void vreset()
-{
+void vreset() {
if(noedit()) return;
VSlot ds;
mpeditvslot(usevdelta, ds, allfaces, sel, true);
}
COMMAND(vreset, "");
-void vshaderparam(const char *name, float *x, float *y, float *z, float *w)
-{
+void vshaderparam(const char *name, float *x, float *y, float *z, float *w) {
if(noedit()) return;
VSlot ds;
ds.changed = 1<<VSLOT_SHPARAM;
- if(name[0])
- {
+ if(name[0]) {
SlotShaderParam p = { getshaderparamname(name), -1, {*x, *y, *z, *w} };
ds.params.add(p);
}
mpeditvslot(usevdelta, ds, allfaces, sel, true);
}
COMMAND(vshaderparam, "sffff");
-ICOMMAND(getvshaderparam, "is", (int *tex, const char *name),
-{
+ICOMMAND(getvshaderparam, "is", (int *tex, const char *name), {
VSlot &vslot = lookupvslot(*tex, false);
- loopv(vslot.params)
- {
+ loopv(vslot.params) {
SlotShaderParam &p = vslot.params[i];
- if(!strcmp(p.name, name))
- {
+ if(!strcmp(p.name, name)) {
defformatstring(str, "%s %s %s %s", floatstr(p.val[0]), floatstr(p.val[1]), floatstr(p.val[2]), floatstr(p.val[3]));
result(str);
return;
}
}
});
-ICOMMAND(getvshaderparamnames, "i", (int *tex),
-{
+ICOMMAND(getvshaderparamnames, "i", (int *tex), {
VSlot &vslot = lookupvslot(*tex, false);
vector<char> str;
- loopv(vslot.params)
- {
+ loopv(vslot.params) {
SlotShaderParam &p = vslot.params[i];
if(i) str.put(' ');
str.put(p.name, strlen(p.name));
@@ -1980,10 +1676,8 @@ ICOMMAND(getvshaderparamnames, "i", (int *tex),
stringret(newstring(str.getbuf(), str.length()-1));
});
-void mpedittex(int tex, int allfaces, selinfo &sel, bool local)
-{
- if(local)
- {
+void mpedittex(int tex, int allfaces, selinfo &sel, bool local) {
+ if(local) {
game::edittrigger(sel, EDIT_TEX, tex, allfaces);
if(allfaces || !(repsel == sel)) reptex = -1;
repsel = sel;
@@ -1992,8 +1686,7 @@ void mpedittex(int tex, int allfaces, selinfo &sel, bool local)
loopselxyz(edittexcube(c, tex, allfaces ? -1 : sel.orient, findrep));
}
-static int unpacktex(int &tex, ucharbuf &buf, bool insert = true)
-{
+static int unpacktex(int &tex, ucharbuf &buf, bool insert = true) {
if(tex < 0x10000) return true;
VSlot ds;
if(!unpackvslot(buf, ds, false)) return false;
@@ -2005,10 +1698,8 @@ static int unpacktex(int &tex, ucharbuf &buf, bool insert = true)
return true;
}
-int shouldpacktex(int index)
-{
- if(vslots.inrange(index))
- {
+int shouldpacktex(int index) {
+ if(vslots.inrange(index)) {
VSlot &vs = *vslots[index];
if(vs.changed) return 0x10000 + vs.slot->index;
}
@@ -2016,19 +1707,15 @@ int shouldpacktex(int index)
}
-bool mpedittex(int tex, int allfaces, selinfo &sel, ucharbuf &buf)
-{
+bool mpedittex(int tex, int allfaces, selinfo &sel, ucharbuf &buf) {
if(!unpacktex(tex, buf)) return false;
mpedittex(tex, allfaces, sel, false);
return true;
}
-void filltexlist()
-{
- if(texmru.length()!=vslots.length())
- {
- loopvrev(texmru) if(texmru[i]>=vslots.length())
- {
+void filltexlist() {
+ if(texmru.length()!=vslots.length()) {
+ loopvrev(texmru) if(texmru[i]>=vslots.length()) {
if(curtexindex > i) curtexindex--;
else if(curtexindex == i) curtexindex = -1;
texmru.remove(i);
@@ -2037,16 +1724,12 @@ void filltexlist()
}
}
-void compactmruvslots()
-{
+void compactmruvslots() {
remappedvslots.setsize(0);
- loopvrev(texmru)
- {
- if(vslots.inrange(texmru[i]))
- {
+ loopvrev(texmru) {
+ if(vslots.inrange(texmru[i])) {
VSlot &vs = *vslots[texmru[i]];
- if(vs.index >= 0)
- {
+ if(vs.index >= 0) {
texmru[i] = vs.index;
continue;
}
@@ -2055,8 +1738,7 @@ void compactmruvslots()
else if(curtexindex == i) curtexindex = -1;
texmru.remove(i);
}
- if(vslots.inrange(lasttex))
- {
+ if(vslots.inrange(lasttex)) {
VSlot &vs = *vslots[lasttex];
lasttex = vs.index >= 0 ? vs.index : 0;
}
@@ -2064,19 +1746,16 @@ void compactmruvslots()
reptex = vslots.inrange(reptex) ? vslots[reptex]->index : -1;
}
-void edittex(int i, bool save = true)
-{
+void edittex(int i, bool save = true) {
lasttex = i;
lasttexmillis = totalmillis;
- if(save)
- {
+ if(save) {
loopvj(texmru) if(texmru[j]==lasttex) { curtexindex = j; break; }
}
mpedittex(i, allfaces, sel, true);
}
-void edittex_(int *dir)
-{
+void edittex_(int *dir) {
if(noedit()) return;
filltexlist();
if(texmru.empty()) return;
@@ -2086,22 +1765,19 @@ void edittex_(int *dir)
edittex(texmru[curtexindex], false);
}
-void gettex()
-{
+void gettex() {
if(noedit(true)) return;
filltexlist();
int tex = -1;
loopxyz(sel, sel.grid, tex = c.texture[sel.orient]);
- loopv(texmru) if(texmru[i]==tex)
- {
+ loopv(texmru) if(texmru[i]==tex) {
curtexindex = i;
tofronttex();
return;
}
}
-void getcurtex()
-{
+void getcurtex() {
if(noedit(true)) return;
filltexlist();
int index = curtexindex < 0 ? 0 : curtexindex;
@@ -2109,16 +1785,14 @@ void getcurtex()
intret(texmru[index]);
}
-void getseltex()
-{
+void getseltex() {
if(noedit(true)) return;
cube &c = lookupcube(sel.o, -sel.grid);
if(c.children || isempty(c)) return;
intret(c.texture[sel.orient]);
}
-void gettexname(int *tex, int *subslot)
-{
+void gettexname(int *tex, int *subslot) {
if(noedit(true) || *tex<0) return;
VSlot &vslot = lookupvslot(*tex, false);
Slot &slot = *vslot.slot;
@@ -2126,8 +1800,7 @@ void gettexname(int *tex, int *subslot)
result(slot.sts[*subslot].name);
}
-void getslottex(int *idx)
-{
+void getslottex(int *idx) {
if(*idx < 0 || !slots.inrange(*idx)) { intret(-1); return; }
Slot &slot = lookupslot(*idx, false);
intret(slot.variants->index);
@@ -2144,28 +1817,23 @@ ICOMMAND(numslots, "", (), intret(slots.length()));
COMMAND(getslottex, "i");
ICOMMAND(texloaded, "i", (int *tex), intret(slots.inrange(*tex) && slots[*tex]->loaded ? 1 : 0));
-void replacetexcube(cube &c, int oldtex, int newtex)
-{
+void replacetexcube(cube &c, int oldtex, int newtex) {
loopi(6) if(c.texture[i] == oldtex) c.texture[i] = newtex;
if(c.children) loopi(8) replacetexcube(c.children[i], oldtex, newtex);
}
-void mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, bool local)
-{
+void mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, bool local) {
if(local) game::edittrigger(sel, EDIT_REPLACE, oldtex, newtex, insel ? 1 : 0);
- if(insel)
- {
+ if(insel) {
loopselxyz(replacetexcube(c, oldtex, newtex));
}
- else
- {
+ else {
loopi(8) replacetexcube(worldroot[i], oldtex, newtex);
}
allchanged();
}
-bool mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, ucharbuf &buf)
-{
+bool mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, ucharbuf &buf) {
if(!unpacktex(oldtex, buf, false)) return false;
editingvslot(oldtex);
if(!unpacktex(newtex, buf)) return false;
@@ -2173,8 +1841,7 @@ bool mpreplacetex(int oldtex, int newtex, bool insel, selinfo &sel, ucharbuf &bu
return true;
}
-void replace(bool insel)
-{
+void replace(bool insel) {
if(noedit()) return;
if(reptex < 0) { conoutf(CON_ERROR, "can only replace after a texture edit"); return; }
mpreplacetex(reptex, lasttex, insel, sel, true);
@@ -2189,37 +1856,30 @@ uint cflip(uint face) { return ((face&0xFF00FF00)>>8) | ((face&0x00FF00FF)<<8);
uint rflip(uint face) { return ((face&0xFFFF0000)>>16)| ((face&0x0000FFFF)<<16); }
uint mflip(uint face) { return (face&0xFF0000FF) | ((face&0x00FF0000)>>8) | ((face&0x0000FF00)<<8); }
-void flipcube(cube &c, int d)
-{
+void flipcube(cube &c, int d) {
swap(c.texture[d*2], c.texture[d*2+1]);
c.faces[D[d]] = dflip(c.faces[D[d]]);
c.faces[C[d]] = cflip(c.faces[C[d]]);
c.faces[R[d]] = rflip(c.faces[R[d]]);
- if(c.children)
- {
+ if(c.children) {
loopi(8) if(i&octadim(d)) swap(c.children[i], c.children[i-octadim(d)]);
loopi(8) flipcube(c.children[i], d);
}
}
-void rotatequad(cube &a, cube &b, cube &c, cube &d)
-{
+void rotatequad(cube &a, cube &b, cube &c, cube &d) {
cube t = a; a = b; b = c; c = d; d = t;
}
-void rotatecube(cube &c, int d) // rotates cube clockwise. see pics in cvs for help.
-{
+void rotatecube(cube &c, int d) { // rotates cube clockwise. see pics in cvs for help. {
c.faces[D[d]] = cflip (mflip(c.faces[D[d]]));
c.faces[C[d]] = dflip (mflip(c.faces[C[d]]));
c.faces[R[d]] = rflip (mflip(c.faces[R[d]]));
swap(c.faces[R[d]], c.faces[C[d]]);
-
swap(c.texture[2*R[d]], c.texture[2*C[d]+1]);
swap(c.texture[2*C[d]], c.texture[2*R[d]+1]);
swap(c.texture[2*C[d]], c.texture[2*C[d]+1]);
-
- if(c.children)
- {
+ if(c.children) {
int row = octadim(R[d]);
int col = octadim(C[d]);
for(int i=0; i<=octadim(d); i+=octadim(d)) rotatequad
@@ -2233,19 +1893,15 @@ void rotatecube(cube &c, int d) // rotates cube clockwise. see pics in cvs for
}
}
-void mpflip(selinfo &sel, bool local)
-{
- if(local)
- {
+void mpflip(selinfo &sel, bool local) {
+ if(local) {
game::edittrigger(sel, EDIT_FLIP);
makeundo();
}
int zs = sel.s[dimension(sel.orient)];
- loopxy(sel)
- {
+ loopxy(sel) {
loop(z,zs) flipcube(selcube(x, y, z), dimension(sel.orient));
- loop(z,zs/2)
- {
+ loop(z,zs/2) {
cube &a = selcube(x, y, z);
cube &b = selcube(x, y, zs-z-1);
swap(a, b);
@@ -2254,22 +1910,19 @@ void mpflip(selinfo &sel, bool local)
changed(sel);
}
-void flip()
-{
+void flip() {
if(noedit()) return;
mpflip(sel, true);
}
-void mprotate(int cw, selinfo &sel, bool local)
-{
+void mprotate(int cw, selinfo &sel, bool local) {
if(local) game::edittrigger(sel, EDIT_ROTATE, cw);
int d = dimension(sel.orient);
if(!dimcoord(sel.orient)) cw = -cw;
int m = sel.s[C[d]] < sel.s[R[d]] ? C[d] : R[d];
int ss = sel.s[m] = max(sel.s[R[d]], sel.s[C[d]]);
if(local) makeundo();
- loop(z,sel.s[D[d]]) loopi(cw>0 ? 1 : 3)
- {
+ loop(z,sel.s[D[d]]) loopi(cw>0 ? 1 : 3) {
loopxy(sel) rotatecube(selcube(x,y,z), d);
loop(y,ss/2) loop(x,ss-1-y*2) rotatequad
(
@@ -2282,8 +1935,7 @@ void mprotate(int cw, selinfo &sel, bool local)
changed(sel);
}
-void rotate(int *cw)
-{
+void rotate(int *cw) {
if(noedit()) return;
mprotate(*cw, sel, true);
}
@@ -2292,29 +1944,25 @@ COMMAND(flip, "");
COMMAND(rotate, "i");
enum { EDITMATF_EMPTY = 0x10000, EDITMATF_NOTEMPTY = 0x20000, EDITMATF_SOLID = 0x30000, EDITMATF_NOTSOLID = 0x40000 };
-static const struct { const char *name; int filter; } editmatfilters[] =
-{
- { "empty", EDITMATF_EMPTY },
- { "notempty", EDITMATF_NOTEMPTY },
- { "solid", EDITMATF_SOLID },
- { "notsolid", EDITMATF_NOTSOLID }
+static const struct { const char *name; int filter; } editmatfilters[] = {
+ {
+ "empty", EDITMATF_EMPTY }, {
+ "notempty", EDITMATF_NOTEMPTY }, {
+ "solid", EDITMATF_SOLID }, {
+ "notsolid", EDITMATF_NOTSOLID }
};
-void setmat(cube &c, ushort mat, ushort matmask, ushort filtermat, ushort filtermask, int filtergeom)
-{
+void setmat(cube &c, ushort mat, ushort matmask, ushort filtermat, ushort filtermask, int filtergeom) {
if(c.children)
loopi(8) setmat(c.children[i], mat, matmask, filtermat, filtermask, filtergeom);
- else if((c.material&filtermask) == filtermat)
- {
- switch(filtergeom)
- {
+ else if((c.material&filtermask) == filtermat) {
+ switch(filtergeom) {
case EDITMATF_EMPTY: if(isempty(c)) break; return;
case EDITMATF_NOTEMPTY: if(!isempty(c)) break; return;
case EDITMATF_SOLID: if(isentirelysolid(c)) break; return;
case EDITMATF_NOTSOLID: if(!isentirelysolid(c)) break; return;
}
- if(mat!=MAT_AIR)
- {
+ if(mat!=MAT_AIR) {
c.material &= matmask;
c.material |= mat;
}
@@ -2322,47 +1970,38 @@ void setmat(cube &c, ushort mat, ushort matmask, ushort filtermat, ushort filter
}
}
-void mpeditmat(int matid, int filter, selinfo &sel, bool local)
-{
+void mpeditmat(int matid, int filter, selinfo &sel, bool local) {
if(local) game::edittrigger(sel, EDIT_MAT, matid, filter);
-
ushort filtermat = 0, filtermask = 0, matmask;
int filtergeom = 0;
- if(filter >= 0)
- {
+ if(filter >= 0) {
filtermat = filter&0xFFFF;
filtermask = filtermat&(MATF_INDEX) ? (int) MATF_INDEX : (filtermat&MATF_CLIP ? (int) MATF_CLIP : (int) filtermat);
filtergeom = filter&~0xFFFF;
}
- if(matid < 0)
- {
+ if(matid < 0) {
matid = 0;
matmask = filtermask;
}
- else
- {
+ else {
matmask = matid&MATF_INDEX ? 0 : (matid&MATF_CLIP ? ~MATF_CLIP : ~matid);
}
loopselxyz(setmat(c, matid, matmask, filtermat, filtermask, filtergeom));
}
-void editmat(char *name, char *filtername)
-{
+void editmat(char *name, char *filtername) {
if(noedit()) return;
int filter = -1;
- if(filtername[0])
- {
+ if(filtername[0]) {
loopi(sizeof(editmatfilters)/sizeof(editmatfilters[0])) if(!strcmp(editmatfilters[i].name, filtername)) { filter = editmatfilters[i].filter; break; }
if(filter < 0) filter = findmaterial(filtername);
- if(filter < 0)
- {
+ if(filter < 0) {
conoutf(CON_ERROR, "unknown material \"%s\"", filtername);
return;
}
}
int id = -1;
- if(name[0] || filter < 0)
- {
+ if(name[0] || filter < 0) {
id = findmaterial(name);
if(id<0) { conoutf(CON_ERROR, "unknown material \"%s\"", name); return; }
}
@@ -2384,39 +2023,30 @@ static int lastthumbnail = 0;
VARP(texgui2d, 0, 1, 1);
VAR(texguinum, 1, -1, 0);
-struct texturegui : g3d_callback
-{
+struct texturegui : g3d_callback {
bool menuon;
vec menupos;
int menustart, menutab;
-
texturegui() : menustart(-1) {}
-
- void gui(g3d_gui &g, bool firstpass)
- {
+ void gui(g3d_gui &g, bool firstpass) {
int origtab = menutab, numtabs = max((slots.length() + texguiwidth*texguiheight - 1)/(texguiwidth*texguiheight), 1);
if(!firstpass) texguinum = -1;
g.start(menustart, 0.04f, &menutab);
bool oldautotab = g.allowautotab(false);
- loopi(numtabs)
- {
+ loopi(numtabs) {
g.tab(!i ? "Textures" : NULL, 0xFFDD88);
if(i+1 != origtab) continue; //don't load textures on non-visible tabs!
Slot *rollover = NULL;
- loop(h, texguiheight)
- {
+ loop(h, texguiheight) {
g.pushlist();
- loop(w, texguiwidth)
- {
+ loop(w, texguiwidth) {
extern VSlot dummyvslot;
int ti = (i*texguiheight+h)*texguiwidth+w;
- if(ti<slots.length())
- {
+ if(ti<slots.length()) {
Slot &slot = lookupslot(ti, false);
VSlot &vslot = *slot.variants;
if(slot.sts.empty()) continue;
- else if(!slot.loaded && !slot.thumbnail)
- {
+ else if(!slot.loaded && !slot.thumbnail) {
if(totalmillis-lastthumbnail<texguitime)
{
g.texture(dummyvslot, texguiscale, false); //create an empty space
@@ -2427,23 +2057,19 @@ struct texturegui : g3d_callback
}
int ret = g.texture(vslot, texguiscale, true);
if(ret&G3D_ROLLOVER) { rollover = &slot; texguinum = ti; }
- if(ret&G3D_UP && (slot.loaded || slot.thumbnail!=notexture))
- {
+ if(ret&G3D_UP && (slot.loaded || slot.thumbnail!=notexture)) {
edittex(vslot.index);
hudshader->set();
}
}
- else
- {
+ else {
g.texture(dummyvslot, texguiscale, false); //create an empty space
}
}
g.poplist();
}
- if(texguiname)
- {
- if(rollover)
- {
+ if(texguiname) {
+ if(rollover) {
defformatstring(name, "%d \f7:\fc %s", texguinum, rollover->sts[0].name);
g.title(name, 0xFFDD88);
}
@@ -2453,12 +2079,9 @@ struct texturegui : g3d_callback
g.allowautotab(oldautotab);
g.end();
}
-
- void showtextures(bool on)
- {
+ void showtextures(bool on) {
if(on == menuon) return;
- if((menuon = on))
- {
+ if((menuon = on)) {
if(menustart <= lasttexmillis)
menutab = 1+clamp(lookupvslot(lasttex, false).slot->index, 0, slots.length()-1)/(texguiwidth*texguiheight);
menupos = menuinfrontofplayer();
@@ -2466,9 +2089,7 @@ struct texturegui : g3d_callback
}
else texguinum = -1;
}
-
- void show()
- {
+ void show() {
if(!menuon) return;
filltexlist();
extern int usegui2d;
@@ -2477,13 +2098,11 @@ struct texturegui : g3d_callback
}
} gui;
-void g3d_texturemenu()
-{
+void g3d_texturemenu() {
gui.show();
}
-void showtexgui(int *n)
-{
+void showtexgui(int *n) {
if(!editmode) { conoutf(CON_ERROR, "operation only allowed in edit mode"); return; }
gui.showtextures(*n==0 ? !gui.menuon : *n==1);
}
@@ -2491,47 +2110,36 @@ void showtexgui(int *n)
// 0/noargs = toggle, 1 = on, other = off - will autoclose if too far away or exit editmode
COMMAND(showtexgui, "i");
-bool cleartexgui()
-{
+bool cleartexgui() {
if(!gui.menuon) return false;
gui.showtextures(false);
return true;
}
ICOMMAND(cleartexgui, "", (), intret(cleartexgui() ? 1 : 0));
-void rendertexturepanel(int w, int h)
-{
- if((texpaneltimer -= curtime)>0 && editmode)
- {
+void rendertexturepanel(int w, int h) {
+ if((texpaneltimer -= curtime)>0 && editmode) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
pushhudmatrix();
hudmatrix.scale(h/1800.0f, h/1800.0f, 1);
flushhudmatrix(false);
SETSHADER(hudrgb);
-
int y = 50, gap = 10;
-
gle::defvertex(2);
gle::deftexcoord0();
-
- loopi(7)
- {
+ loopi(7) {
int s = (i == 3 ? 285 : 220), ti = curtexindex+i-3;
- if(texmru.inrange(ti))
- {
- VSlot &vslot = lookupvslot(texmru[ti]), *layer = NULL;
+ if(texmru.inrange(ti)) {
+ VSlot &vslot = lookupvslot(texmru[ti]), *layer = NULL; (void) layer;
Slot &slot = *vslot.slot;
Texture *tex = slot.sts.empty() ? notexture : slot.sts[0].t;
- if(vslot.layer)
- {
+ if(vslot.layer) {
layer = &lookupvslot(vslot.layer);
}
float sx = min(1.0f, tex->xs/(float)tex->ys), sy = min(1.0f, tex->ys/(float)tex->xs);
vec2 tc[4] = { vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1) };
float xoff = vslot.offset.x, yoff = vslot.offset.y;
- if(vslot.rotation)
- {
+ if(vslot.rotation) {
const texrotation &r = texrotations[vslot.rotation];
if(r.swapxy) { swap(xoff, yoff); loopk(4) swap(tc[k].x, tc[k].y); }
if(r.flipx) { xoff *= -1; loopk(4) tc[k].x *= -1; }
@@ -2542,7 +2150,6 @@ void rendertexturepanel(int w, int h)
}
y += s+gap;
}
-
pophudmatrix(true, false);
hudshader->set();
}