diff options
Diffstat (limited to 'src/engine/material.cpp')
| -rw-r--r-- | src/engine/material.cpp | 72 |
1 files changed, 29 insertions, 43 deletions
diff --git a/src/engine/material.cpp b/src/engine/material.cpp index 59f47f8..d56c7e2 100644 --- a/src/engine/material.cpp +++ b/src/engine/material.cpp @@ -1,35 +1,25 @@ #include "engine.h" -struct QuadNode -{ +struct QuadNode { int x, y, size; uint filled; QuadNode *child[4]; QuadNode(int x, int y, int size) : x(x), y(y), size(size), filled(0) { loopi(4) child[i] = 0; } - void clear() - { - loopi(4) DELETEP(child[i]); - } - - ~QuadNode() - { - clear(); - } + void clear() { loopi(4) DELETEP(child[i]); } - void insert(int mx, int my, int msize) - { - if(size == msize) - { + ~QuadNode() { clear(); } + + void insert(int mx, int my, int msize) { + if(size == msize) { filled = 0xF; return; } int csize = size>>1, i = 0; if(mx >= x+csize) i |= 1; if(my >= y+csize) i |= 2; - if(csize == msize) - { + if(csize == msize) { filled |= (1 << i); return; } @@ -37,16 +27,14 @@ struct QuadNode child[i]->insert(mx, my, msize); loopj(4) if(child[j]) { - if(child[j]->filled == 0xF) - { + if(child[j]->filled == 0xF) { DELETEP(child[j]); filled |= (1 << j); } } } - void genmatsurf(ushort mat, uchar orient, uchar visible, int x, int y, int z, int size, materialsurface *&matbuf) - { + void genmatsurf(ushort mat, uchar orient, uchar visible, int x, int y, int z, int size, materialsurface *&matbuf) { materialsurface &m = *matbuf++; m.material = mat; m.orient = orient; @@ -59,8 +47,7 @@ struct QuadNode m.o[dim] = z; } - void genmatsurfs(ushort mat, uchar orient, uchar flags, int z, materialsurface *&matbuf) - { + void genmatsurfs(ushort mat, uchar orient, uchar flags, int z, materialsurface *&matbuf) { if(filled == 0xF) genmatsurf(mat, orient, flags, x, y, z, size, matbuf); else if(filled) { @@ -74,8 +61,7 @@ struct QuadNode static float wfwave; -static const bvec4 matnormals[6] = -{ +static const bvec4 matnormals[6] = { bvec4(0x80, 0, 0), bvec4(0x7F, 0, 0), bvec4(0, 0x80, 0), @@ -139,7 +125,7 @@ const struct material { const char *name; ushort id; -} materials[] = +} materials[] = { {"air", MAT_AIR}, {"water", MAT_WATER}, {"water1", MAT_WATER}, {"water2", MAT_WATER+1}, {"water3", MAT_WATER+2}, {"water4", MAT_WATER+3}, @@ -157,16 +143,16 @@ int findmaterial(const char *name) loopi(sizeof(materials)/sizeof(material)) { if(!strcmp(materials[i].name, name)) return materials[i].id; - } + } return -1; -} +} const char *findmaterialname(int mat) { loopi(sizeof(materials)/sizeof(materials[0])) if(materials[i].id == mat) return materials[i].name; return NULL; } - + const char *getmaterialdesc(int mat, const char *prefix) { static const ushort matmasks[] = { MATF_VOLUME|MATF_INDEX, MATF_CLIP, MAT_DEATH, MAT_ALPHA }; @@ -175,7 +161,7 @@ const char *getmaterialdesc(int mat, const char *prefix) loopi(sizeof(matmasks)/sizeof(matmasks[0])) if(mat&matmasks[i]) { const char *matname = findmaterialname(mat&matmasks[i]); - if(matname) + if(matname) { concatstring(desc, desc[0] ? ", " : prefix); concatstring(desc, matname); @@ -183,9 +169,9 @@ const char *getmaterialdesc(int mat, const char *prefix) } return desc; } - + int visiblematerial(const cube &c, int orient, const ivec &co, int size, ushort matmask) -{ +{ ushort mat = c.material&matmask; switch(mat) { @@ -220,7 +206,7 @@ void genmatsurfs(const cube &c, const ivec &co, int size, vector<materialsurface { int matmask = matmasks[j]; int vis = visiblematerial(c, i, co, size, matmask&~MATF_INDEX); - if(vis != MATSURF_NOT_VISIBLE) + if(vis != MATSURF_NOT_VISIBLE) { materialsurface m; m.material = c.material&matmask; @@ -322,7 +308,7 @@ int optimizematsurfs(materialsurface *matbuf, int matsurfs) while(cur < end && cur->material == start->material && cur->orient == start->orient && - cur->visible == start->visible && + cur->visible == start->visible && cur->o[dim] == start->o[dim]) ++cur; if(!isliquid(start->material&MATF_VOLUME) || start->orient != O_TOP || !vertwater) @@ -357,7 +343,7 @@ void setupmaterials(int start, int len) vector<waterinfo> water; unionfind uf; if(!len) len = valist.length(); - for(int i = start; i < len; i++) + for(int i = start; i < len; i++) { vtxarray *va = valist[i]; materialsurface *skip = NULL; @@ -387,7 +373,7 @@ void setupmaterials(int start, int len) m.light = brightestlight(center, vec(0, 0, 1)); float depth = raycube(center, vec(0, 0, -1), 10000); wi.depth = double(depth)*m.rsize*m.csize; - wi.area = m.rsize*m.csize; + wi.area = m.rsize*m.csize; } else if(isliquid(matvol) && m.orient!=O_BOTTOM && m.orient!=O_TOP) { @@ -427,7 +413,7 @@ void setupmaterials(int start, int len) m.skip = 0; if(skip && m.material == skip->material && m.orient == skip->orient && skip->skip < 0xFFFF) skip->skip++; - else + else skip = &m; } } @@ -452,7 +438,7 @@ void setupmaterials(int start, int len) preloadwatershaders(true); loopi(4) if(hasmat&(1<<(MAT_WATER+i))) lookupmaterialslot(MAT_WATER+i); } - if(hasmat&(0xF<<MAT_LAVA)) + if(hasmat&(0xF<<MAT_LAVA)) { useshaderbyname("lava"); useshaderbyname("lavaglare"); @@ -715,12 +701,12 @@ void rendermaterials() if(waterfallrefract && wfog && !reflecting && !refracting) { - if(waterfallenv) SETSHADER(waterfallenvrefract); + if(waterfallenv) SETSHADER(waterfallenvrefract); else SETSHADER(waterfallrefract); if(blended) { glDisable(GL_BLEND); blended = false; } if(!depth) { glDepthMask(GL_TRUE); depth = true; } } - else + else { SETSHADER(waterfallenv); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -762,7 +748,7 @@ void rendermaterials() usedwaterfall = m.material; } } - float angle = fmod(float(lastmillis/600.0f/(2*M_PI)), 1.0f), + float angle = fmod(float(lastmillis/600.0f/(2*M_PI)), 1.0f), s = angle - int(angle) - 0.5f; s *= 8 - fabs(s)*16; wfwave = vertwater ? WATER_AMPLITUDE*s-WATER_OFFSET : -WATER_OFFSET; @@ -824,7 +810,7 @@ void rendermaterials() { if(!blended) { glEnable(GL_BLEND); blended = true; } if(depth) { glDepthMask(GL_FALSE); depth = false; } - const bvec &gcol = getglasscolor(m.material); + const bvec &gcol = getglasscolor(m.material); if(m.envmap!=EMID_NONE && glassenv) { glBlendFunc(GL_ONE, GL_SRC_ALPHA); @@ -840,7 +826,7 @@ void rendermaterials() } } break; - + default: continue; } lastmat = m.material; |
