-CXXFLAGS= -O3 -g -fomit-frame-pointer -ffast-math
-override CXXFLAGS+= -Wall -fsigned-char -fno-exceptions -fno-rtti -Wno-unused-parameter
+CXXFLAGS= -O3 -fomit-frame-pointer -ffast-math
+override CXXFLAGS+= -Wall -Wextra -fsigned-char -fno-exceptions -fno-rtti -Wno-unused-parameter
PLATFORM= $(shell uname -s | tr '[:lower:]' '[:upper:]')
PLATFORM_PREFIX= native
if(isdown) fieldmode = FIELDABORT;
return true;
case SDLK_RETURN:
+ [[fallthrough]];
case SDLK_TAB:
if(e->maxy != 1) break;
+ [[fallthrough]];
case SDLK_KP_ENTER:
if(isdown) fieldmode = FIELDCOMMIT; //signal field commit (handled when drawing field)
return true;
{
case VAL_FLOAT: s = floatstr(v.f); break;
case VAL_INT: s = intstr(v.i); break;
- case VAL_STR: case VAL_MACRO: return v.s;
+ case VAL_STR:
+ [[fallthrough]];
+ case VAL_MACRO: return v.s;
}
freearg(v);
v.setstr(newstring(s));
v.setident(id);
return id;
}
- case VAL_STR:
- {
- ident *id = newident(v.s, IDF_UNKNOWN);
- delete[] v.s;
- v.setident(id);
- return id;
+ case VAL_STR:
+ {
+ ident *id = newident(v.s, IDF_UNKNOWN);
+ delete[] v.s;
+ v.setident(id);
+ return id;
}
}
freearg(v);
void clear_command()
{
- enumerate(idents, ident, i,
+ enumerate(idents, ident, i,
{
- if(i.type==ID_ALIAS)
- {
- DELETEA(i.name);
+ if(i.type==ID_ALIAS)
+ {
+ DELETEA(i.name);
i.forcenull();
DELETEA(i.code);
}
switch(i.type)
{
case ID_ALIAS:
- if(i.valtype==VAL_STR)
+ if(i.valtype==VAL_STR)
{
if(!i.val.s[0]) break;
delete[] i.val.s;
newident(argname, IDF_ARG);
}
dummyident = newident("//dummy", IDF_UNKNOWN);
- if(identinits)
+ if(identinits)
{
loopv(*identinits) addident((*identinits)[i]);
DELETEP(identinits);
}
ICOMMAND(nodebug, "e", (uint *body), { nodebug++; executeret(body, *commandret); nodebug--; });
-
+
void addident(ident *id)
{
addident(*id);
id.stack = &stack;
id.setval(v);
cleancode(id);
-}
+}
static inline void poparg(ident &id)
{
static inline void pushalias(ident &id, identstack &stack)
{
- if(id.type == ID_ALIAS && id.index >= MAXARGS)
+ if(id.type == ID_ALIAS && id.index >= MAXARGS)
{
pusharg(id, nullval, stack);
id.flags &= ~IDF_UNKNOWN;
ident *id = idents.access(name);
if(!id)
{
- if(checknumber(name))
+ if(checknumber(name))
{
debugcode("number %s is not a valid identifier name", name);
return dummyident;
return NULL;
return id;
}
-
+
void resetvar(char *name)
{
ident *id = idents.access(name);
static void setalias(const char *name, tagval &v)
{
ident *id = idents.access(name);
- if(id)
+ if(id)
{
- if(id->type == ID_ALIAS)
+ if(id->type == ID_ALIAS)
{
if(id->index < MAXARGS) setarg(*id, v); else setalias(*id, v);
}
freearg(v);
}
}
- else if(checknumber(name))
+ else if(checknumber(name))
{
debugcode("cannot alias number %s", name);
freearg(v);
}
void alias(const char *name, const char *str)
-{
+{
tagval v;
v.setstr(newstring(str));
setalias(name, v);
{
p++;
const char *end = parsestring(p);
- char *s = newstring(end - p);
+ char *s = newstring(end - p);
len = unescapestring(s, p, end);
s[len] = '\0';
p = end;
{
code.add((id->index < MAXARGS ? CODE_IDENTARG : CODE_IDENT)|(id->index<<8));
}
-
+
static inline void compileident(vector<uint> &code, const char *word = NULL)
{
compileident(code, word ? newident(word, IDF_UNKNOWN) : dummyident);
case VAL_ANY: compilestr(code, word, wordlen); break;
case VAL_FLOAT: compilefloat(code, word); break;
case VAL_INT: compileint(code, word); break;
- case VAL_CODE:
+ case VAL_CODE:
{
int start = code.length();
code.add(CODE_BLOCK);
for(const char *fmt = id->args; *fmt; fmt++) switch(*fmt)
{
case 's': compilestr(code, NULL, 0, true); numargs++; break;
- case 'i': compileint(code); numargs++; break;
+ case 'i': compileint(code); numargs++; break;
case 'b': compileint(code, INT_MIN); numargs++; break;
case 'f': compilefloat(code); numargs++; break;
case 't': compilenull(code); numargs++; break;
#endif
case 'C': comtype = CODE_COMC; numargs = 1; goto endfmt;
case 'V': comtype = CODE_COMV; numargs = 2; goto endfmt;
- case '1': case '2': case '3': case '4': break;
+ case '1': case '2': case '3': case '4': break;
}
endfmt:
code.add(comtype|(ltype < VAL_ANY ? ltype<<CODE_RET : 0)|(id->index<<8));
static bool compileblockstr(vector<uint> &code, const char *str, const char *end, bool macro)
{
int start = code.length();
- code.add(macro ? CODE_MACRO : CODE_VAL|RET_STR);
+ code.add(macro ? CODE_MACRO : CODE_VAL|RET_STR);
char *buf = (char *)code.reserve((end-str)/sizeof(uint)+1).buf;
int len = 0;
while(str < end)
else buf[len++] = *str++;
break;
case '@':
+ [[fallthrough]];
case ']':
if(str < end) { buf[len++] = *str++; break; }
+ [[fallthrough]];
case '\0': goto done;
}
}
break;
case '[': brak++; break;
case ']': brak--; break;
- case '@':
+ case '@':
{
const char *esc = p;
- while(*p == '@') p++;
+ while(*p == '@') p++;
int level = p - (esc - 1);
if(brak > level) continue;
else if(brak < level) debugcodeline(line, "too many @s");
}
}
done:
- if(p-1 > start)
+ if(p-1 > start)
{
if(!concs) switch(wordtype)
{
}
compileblockstr(code, start, p-1, concs > 0);
if(concs > 1) concs++;
- }
+ }
if(concs)
{
code.add(CODE_CONCM|(wordtype < VAL_ANY ? wordtype<<CODE_RET : RET_STR)|(concs<<8));
case VAL_STR: case VAL_NULL: case VAL_ANY:
if(!concs && p-1 <= start) compilestr(code);
break;
- default:
- if(!concs)
+ default:
+ if(!concs)
{
if(p-1 <= start) compileval(code, wordtype, NULL, 0);
else code.add(CODE_FORCE|(wordtype<<CODE_RET));
}
break;
}
-}
-
+}
+
static bool compileword(vector<uint> &code, const char *&p, int wordtype, char *&word, int &wordlen)
{
skipcomments(p);
case VAL_CODE: code.add(CODE_COMPILE); break;
case VAL_IDENT: code.add(CODE_IDENTU); break;
}
- return true;
+ return true;
case '[':
p++;
compileblock(code, p, wordtype);
int wordlen = 0;
bool more = compileword(code, p, wordtype, word, wordlen);
if(!more) return false;
- if(word)
+ if(word)
{
compileval(code, wordtype, word, wordlen);
delete[] word;
bool more = compileword(code, p, VAL_ANY, idname, idlen);
if(!more) goto endstatement;
skipcomments(p);
- if(p[0] == '=') switch(p[1])
- {
- case '/':
+ if(p[0] == '=') switch(p[1])
+ {
+ case '/':
if(p[2] != '/') break;
- case ';': case ' ': case '\t': case '\r': case '\n': case '\0':
+ [[fallthrough]];
+ case ';':
+ [[fallthrough]];
+ case ' ':
+ [[fallthrough]];
+ case '\t':
+ [[fallthrough]];
+ case '\r':
+ [[fallthrough]];
+ case '\n':
+ [[fallthrough]];
+ case '\0':
p++;
- if(idname)
+ if(idname)
{
id = newident(idname, IDF_UNKNOWN);
if(id) switch(id->type)
else
{
id = idents.access(idname);
- if(!id)
+ if(!id)
{
if(!checknumber(idname)) { compilestr(code, idname, idlen); delete[] idname; goto noid; }
char *end = idname;
int val = int(strtoul(idname, &end, 0));
if(*end) compilestr(code, idname, idlen);
- else compileint(code, val);
+ else compileint(code, val);
code.add(CODE_RESULT);
}
else switch(id->type)
bool rep = false;
for(const char *fmt = id->args; *fmt; fmt++) switch(*fmt)
{
- case 's':
+ case 's':
if(more) more = compilearg(code, p, VAL_STR);
- if(!more)
+ if(!more)
{
if(rep) break;
compilestr(code, NULL, 0, true);
break;
case 'i': if(more) more = compilearg(code, p, VAL_INT); if(!more) { if(rep) break; compileint(code); fakeargs++; } numargs++; break;
case 'b': if(more) more = compilearg(code, p, VAL_INT); if(!more) { if(rep) break; compileint(code, INT_MIN); fakeargs++; } numargs++; break;
- case 'f': if(more) more = compilearg(code, p, VAL_FLOAT); if(!more) { if(rep) break; compilefloat(code); fakeargs++; } numargs++; break;
+ case 'f': if(more) more = compilearg(code, p, VAL_FLOAT); if(!more) { if(rep) break; compilefloat(code); fakeargs++; } numargs++; break;
case 't': if(more) more = compilearg(code, p, VAL_ANY); if(!more) { if(rep) break; compilenull(code); fakeargs++; } numargs++; break;
case 'e': if(more) more = compilearg(code, p, VAL_CODE); if(!more) { if(rep) break; compileblock(code); fakeargs++; } numargs++; break;
case 'r': if(more) more = compilearg(code, p, VAL_IDENT); if(!more) { if(rep) break; compileident(code); fakeargs++; } numargs++; break;
break;
case ID_SVAR:
if(!(more = compilearg(code, p, VAL_STR))) code.add(CODE_PRINT|(id->index<<8));
- else
+ else
{
int numconc = 0;
while(numconc+1 < MAXARGS && (more = compilearg(code, p, VAL_ANY))) numconc++;
code.add(CODE_SVAR1|(id->index<<8));
}
break;
- }
+ }
endcommand:
delete[] idname;
}
endstatement:
- if(more) while(compilearg(code, p, VAL_ANY)) code.add(CODE_POP);
+ if(more) while(compilearg(code, p, VAL_ANY)) code.add(CODE_POP);
p += strcspn(p, ")];/\n\0");
int c = *p++;
switch(c)
case ')':
case ']':
if(c == brak) return;
- debugcodeline(line, "unexpected \"%c\"", c);
+ debugcodeline(line, "unexpected \"%c\"", c);
break;
case '/':
{
if(!code) return;
switch(*code&CODE_OP_MASK)
- {
+ {
case CODE_START:
*code -= 0x100;
if(int(*code) < 0x100) delete[] code;
#define MAXRUNDEPTH 255
static int rundepth = 0;
-
+
static const uint *runcode(const uint *code, tagval &result)
{
result.setnull();
case CODE_POP:
freearg(args[--numargs]);
- continue;
- case CODE_ENTER:
- code = runcode(code, args[numargs++]);
continue;
- case CODE_EXIT|RET_NULL: case CODE_EXIT|RET_STR: case CODE_EXIT|RET_INT: case CODE_EXIT|RET_FLOAT:
+ case CODE_ENTER:
+ code = runcode(code, args[numargs++]);
+ continue;
+ case CODE_EXIT|RET_NULL: case CODE_EXIT|RET_STR: case CODE_EXIT|RET_INT: case CODE_EXIT|RET_FLOAT:
forcearg(result, op&CODE_RET_MASK);
goto exit;
case CODE_PRINT:
loopi(numargs) popalias(*args[i].id);
goto exit;
}
-
+
case CODE_MACRO:
{
uint len = op>>8;
{
pusharg(*id, nullval, aliasstack->argstack[id->index]);
aliasstack->usedargs |= 1<<id->index;
- }
+ }
args[numargs++].setident(id);
continue;
}
case CODE_IDENTU:
{
tagval &arg = args[numargs-1];
- ident *id = arg.type == VAL_STR || arg.type == VAL_MACRO ? newident(arg.s, IDF_UNKNOWN) : dummyident;
+ ident *id = arg.type == VAL_STR || arg.type == VAL_MACRO ? newident(arg.s, IDF_UNKNOWN) : dummyident;
if(id->index < MAXARGS && !(aliasstack->usedargs&(1<<id->index)))
{
pusharg(*id, nullval, aliasstack->argstack[id->index]);
aliasstack->usedargs |= 1<<id->index;
- }
+ }
freearg(arg);
arg.setident(id);
continue;
nval; \
continue; \
}
- LOOKUPU(arg.setstr(newstring(id->getstr())),
+ LOOKUPU(arg.setstr(newstring(id->getstr())),
arg.setstr(newstring(*id->storage.s)),
arg.setstr(newstring(intstr(*id->storage.i))),
arg.setstr(newstring(floatstr(*id->storage.f))),
case CODE_FVAR|RET_STR: args[numargs++].setstr(newstring(floatstr(*identmap[op>>8]->storage.f))); continue;
case CODE_FVAR|RET_INT: args[numargs++].setint(int(*identmap[op>>8]->storage.f)); continue;
case CODE_FVAR1: setfvarchecked(identmap[op>>8], args[0].f); numargs = 0; continue;
-
+
case CODE_COM|RET_NULL: case CODE_COM|RET_STR: case CODE_COM|RET_FLOAT: case CODE_COM|RET_INT:
id = identmap[op>>8];
#ifndef STANDALONE
callcom:
#endif
forcenull(result);
- CALLCOM(numargs)
+ CALLCOM(numargs)
forceresult:
freeargs(args, numargs, 0);
forcearg(result, op&CODE_RET_MASK);
id = identmap[op>>8];
forcenull(result);
((comfunv)id->fun)(args, numargs);
- goto forceresult;
+ goto forceresult;
case CODE_COMC|RET_NULL: case CODE_COMC|RET_STR: case CODE_COMC|RET_FLOAT: case CODE_COMC|RET_INT:
id = identmap[op>>8];
forcenull(result);
debugcode("unknown command: %s", args[0].s);
forcenull(result);
goto forceresult;
- }
+ }
forcenull(result);
switch(id->type)
{
loopj(numargs-1) pushalias(*forceident(args[j+1]), locals[j]);
code = runcode(code, result);
loopj(numargs-1) popalias(*args[j+1].id);
- goto exit;
+ goto exit;
}
case ID_VAR:
if(numargs <= 1) printvar(id); else setvarchecked(id, &args[1], numargs-1);
goto forceresult;
case ID_SVAR:
if(numargs <= 1) printvar(id); else setsvarchecked(id, forcestr(args[1]));
- goto forceresult;
+ goto forceresult;
case ID_ALIAS:
if(id->index < MAXARGS && !(aliasstack->usedargs&(1<<id->index))) goto forceresult;
if(id->valtype==VAL_NULL) goto noid;
--rundepth;
return code;
}
-
+
void executeret(const uint *code, tagval &result)
{
- runcode(code, result);
+ runcode(code, result);
}
void executeret(const char *p, tagval &result)
char *executestr(ident *id, tagval *args, int numargs, bool lookup)
{
- tagval result;
+ tagval result;
executeret(id, args, numargs, lookup, result);
if(result.type == VAL_NULL) return NULL;
forcestr(result);
{
switch(s[0])
{
- case '+': case '-':
+ case '+': case '-':
switch(s[1])
{
case '0': break;
case VAL_STR:
if(!id.val.s[0]) break;
if(!validateblock(id.val.s)) { f->printf("%s = %s\n", escapeid(id), escapestring(id.val.s)); break; }
+ [[fallthrough]];
case VAL_FLOAT:
- case VAL_INT:
+ [[fallthrough]];
+ case VAL_INT:
f->printf("%s = [%s]\n", escapeid(id), id.getstr()); break;
}
}
enumerate(idents, ident, id, if(id.flags&IDF_OVERRIDDEN) ids.add(&id));
ids.sortname();
loopv(ids) printvar(ids[i]);
-}
+}
COMMAND(changedvars, "");
// below the commands that implement a small imperative language. thanks to the semantics of
});
void concat(tagval *v, int n)
-{
+{
commandret->setstr(conc(v, n, true));
}
COMMAND(concat, "V");
void concatword(tagval *v, int n)
-{
+{
commandret->setstr(conc(v, n, false));
-}
+}
COMMAND(concatword, "V");
void append(ident *id, tagval *v, bool space)
case '(': case '[': if(c == braktype) brak++; break;
case ')': if(braktype == '(' && --brak <= 0) goto endblock; break;
case ']': if(braktype == '[' && --brak <= 0) goto endblock; break;
- }
+ }
}
endblock:
end = s-1;
if(*s == ';') s++;
return true;
}
-
+
void explodelist(const char *s, vector<char *> &elems, int limit)
{
const char *start, *end;
{
const char *list = start;
int pos = args[i].getint();
- for(; pos > 0; pos--) if(!parselist(list)) break;
+ for(; pos > 0; pos--) if(!parselist(list)) break;
if(pos > 0 || !parselist(list, start, end)) start = end = "";
}
commandret->setstr(newstring(start, end-start));
if(len < 0) { if(offset > 0) skiplist(s); commandret->setstr(newstring(s)); return; }
const char *list = s, *start, *end, *qstart, *qend = s;
if(len > 0 && parselist(s, start, end, list, qend)) while(--len > 0 && parselist(s, start, end, qstart, qend));
- commandret->setstr(newstring(list, qend - list));
+ commandret->setstr(newstring(list, qend - list));
}
COMMAND(sublist, "siiN");
}
p.add(' ');
}
- }
+ }
p.add('\0');
result(p.getbuf());
}
return -1;
}
ICOMMAND(indexof, "ss", (char *list, char *elem), intret(listincludes(list, elem, strlen(elem))));
-
+
char *listdel(const char *s, const char *del)
{
vector<char> p;
bool redundant = false;
loopj(i) if(!strcmp(files[j], file)) { redundant = true; break; }
if(redundant) delete[] files.removeunordered(i);
- }
+ }
loopv(files)
{
char *file = files[i];
- if(i)
+ if(i)
{
if(id->valtype == VAL_STR) delete[] id->val.s;
else id->valtype = VAL_STR;
id->val.s = file;
}
- else
+ else
{
tagval t;
t.setstr(file);
});
void findfile_(char *name)
-{
+{
string fname;
copystring(fname, name);
path(fname);
{
const char *str, *quotestart, *quoteend;
};
-
+
struct sortfun
{
ident *x, *y;
return executebool(body);
}
};
-
+
void sortlist(char *list, ident *x, ident *y, uint *body)
{
if(x == y || x->type != ID_ALIAS || y->type != ID_ALIAS) return;
sortitem item = { ¯os[start - list], quotestart, quoteend };
items.add(item);
total += int(quoteend - quotestart);
- }
+ }
identstack xstack, ystack;
pusharg(*x, nullval, xstack); x->flags &= ~IDF_UNKNOWN;
poparg(*x);
poparg(*y);
-
+
char *sorted = macros;
int sortedlen = total + max(items.length() - 1, 0);
if(macrolen < sortedlen)
offset += len;
}
sorted[offset] = '\0';
-
+
commandret->setstr(sorted);
}
COMMAND(sortlist, "srre");
ICOMMAND(&&, "e1V", (tagval *args, int numargs),
{
if(!numargs) intret(1);
- else loopi(numargs)
- {
+ else loopi(numargs)
+ {
if(i) freearg(*commandret);
executeret(args[i].code, *commandret);
if(!getbool(*commandret)) break;
{
if(!numargs) intret(0);
else loopi(numargs)
- {
+ {
if(i) freearg(*commandret);
executeret(args[i].code, *commandret);
if(getbool(*commandret)) break;
ICOMMAND(strcode, "si", (char *s, int *i), intret(*i > 0 ? (memchr(s, 0, *i) ? 0 : uchar(s[*i])) : uchar(s[0])));
ICOMMAND(codestr, "i", (int *i), { char *s = newstring(1); s[0] = char(*i); s[1] = '\0'; stringret(s); });
ICOMMAND(struni, "si", (char *s, int *i), intret(*i > 0 ? (memchr(s, 0, *i) ? 0 : cube2uni(s[*i])) : cube2uni(s[0])));
-ICOMMAND(unistr, "i", (int *i), { char *s = newstring(1); s[0] = uni2cube(*i); s[1] = '\0'; stringret(s); });
+ICOMMAND(unistr, "i", (int *i), { char *s = newstring(1); s[0] = uni2cube(*i); s[1] = '\0'; stringret(s); });
int naturalsort(const char *a, const char *b)
{
int minstep = max(int(ceil(tmin/grassstep)) - tstep, 1),
maxstep = int(floor(min(tmax, t + grassdist)/grassstep)) - tstep,
numsteps = maxstep - minstep + 1;
-
+
float texscale = (grassscale*tex->ys)/float(grassheight*tex->xs), animscale = grassheight*texscale;
vec tc;
tc.cross(g.surface, w.dir).mul(texscale);
float prevdist = rightdist;
if(++rightv >= &g.v[g.numv]) rightv = g.v;
rightdist = rightv->dot(w.dir);
- if(dist <= rightdist)
+ if(dist <= rightdist)
{
prev = rightv;
prevdist = rightdist;
{
if(w.bound1.dist(p2) >= grassmargin) continue;
p1.add(vec(across).mul(leftb - grassmargin));
- }
+ }
if(rightb > grassmargin)
{
if(w.bound2.dist(p1) >= grassmargin) continue;
group->tex = tex->id;
extern bool brightengeom;
extern int fullbright;
- int lmid = brightengeom && (g.lmid < LMID_RESERVED || (fullbright && editmode)) ? LMID_BRIGHT : g.lmid;
+ int lmid = brightengeom && (g.lmid < LMID_RESERVED || (fullbright && editmode)) ? (int) LMID_BRIGHT : (int) g.lmid;
group->lmtex = lightmaptexs.inrange(lmid) ? lightmaptexs[lmid].id : notexture->id;
group->offset = grassverts.length()/4;
group->numquads = 0;
if(lastgrassanim!=lastmillis) animategrass();
}
-
+
group->numquads++;
-
+
float tcoffset = grassoffsets[offset%NUMGRASSOFFSETS],
animoffset = animscale*grassanimoffsets[offset%NUMGRASSOFFSETS],
tc1 = tc.dot(p1) + tcoffset, tc2 = tc.dot(p2) + tcoffset,
gv.bounds = w.vertbounds; \
modify; \
}
-
+
GRASSVERT(2, 0, { gv.pos.z += height; gv.tc.x += animoffset; });
GRASSVERT(1, 0, { gv.pos.z += height; gv.tc.x += animoffset; });
GRASSVERT(1, 1, );
GRASSVERT(2, 1, );
}
-}
+}
static void gengrassquads(vtxarray *va)
{
if(isfoggedsphere(g.radius, g.center)) continue;
float dist = g.center.dist(camera1->o);
if(dist - g.radius > grassdist) continue;
-
+
Slot &s = *lookupvslot(g.texture, false).slot;
- if(!s.grasstex)
+ if(!s.grasstex)
{
if(!s.autograss) continue;
s.grasstex = textureload(s.autograss, 2);
grassgroup *group = NULL;
loopi(NUMGRASSWEDGES)
{
- grasswedge &w = grasswedges[i];
+ grasswedge &w = grasswedges[i];
if(w.bound1.dist(g.center) > g.radius + grassmargin || w.bound2.dist(g.center) > g.radius + grassmargin) continue;
gengrassquads(group, w, g, s.grasstex);
}
SETSHADER(grass);
LOCALPARAMF(grassmargin, grassmargin, grassmargin ? grassmarginfade / grassmargin : 0.0f, grassmargin ? grassmarginfade : 1.0f);
-
+
gle::bindvbo(grassvbo);
const grassvert *ptr = 0;
}
void cleanupgrass()
-{
+{
if(grassvbo) { glDeleteBuffers_(1, &grassvbo); grassvbo = 0; }
grassvbosize = 0;
}
f->seek(mesh_offset + mheader.ofs_vertices, SEEK_SET);
loopj(numframes*m.numverts)
{
- md3vertex v = { 0 };
+ md3vertex v = { {0}, 0 };
f->read(&v, sizeof(md3vertex)); // read the vertices
lilswap(v.vertex, 4);
solidfaces(c);
cube &o = blockcube(x, y, 1, sel, -sel.grid);
loopi(6)
- c.texture[i] = o.children ? DEFAULT_GEOM : o.texture[i];
+ c.texture[i] = o.children ? (int) DEFAULT_GEOM : (int) o.texture[i];
}
else
emptyfaces(c);
if(filter >= 0)
{
filtermat = filter&0xFFFF;
- filtermask = filtermat&(MATF_VOLUME|MATF_INDEX) ? MATF_VOLUME|MATF_INDEX : (filtermat&MATF_CLIP ? MATF_CLIP : filtermat);
+ filtermask = filtermat&(MATF_VOLUME|MATF_INDEX) ? (int) MATF_VOLUME|MATF_INDEX : (filtermat&MATF_CLIP ? (int) MATF_CLIP : (int) filtermat);
filtergeom = filter&~0xFFFF;
}
if(matid < 0)
int type = lmtex.type&LM_TYPE;
if(k.layer==LAYER_BLEND) type += 2;
else if(k.alpha) type += 4 + 2*(k.alpha-1);
- lastlmid[type] = lmtex.unlitx>=0 ? k.lmid : LMID_AMBIENT;
+ lastlmid[type] = lmtex.unlitx>=0 ? (int) k.lmid : (int) LMID_AMBIENT;
if(firstlmid[type]==LMID_AMBIENT && lastlmid[type]!=LMID_AMBIENT)
{
firstlit[type] = i;
VSlot &vslot = lookupvslot(c.texture[i], true),
*layer = vslot.layer && !(c.material&MAT_ALPHA) ? &lookupvslot(vslot.layer, true) : NULL;
- ushort envmap = vslot.slot->shader->type&SHADER_ENVMAP ? (vslot.slot->texmask&(1<<TEX_ENVMAP) ? EMID_CUSTOM : closestenvmap(i, co, size)) : EMID_NONE,
- envmap2 = layer && layer->slot->shader->type&SHADER_ENVMAP ? (layer->slot->texmask&(1<<TEX_ENVMAP) ? EMID_CUSTOM : closestenvmap(i, co, size)) : EMID_NONE;
+ ushort envmap = vslot.slot->shader->type&SHADER_ENVMAP ? (int) (vslot.slot->texmask&(1<<TEX_ENVMAP) ? (int) EMID_CUSTOM : (int) closestenvmap(i, co, size)) : (int) EMID_NONE,
+ envmap2 = layer && layer->slot->shader->type&SHADER_ENVMAP ? (int) (layer->slot->texmask&(1<<TEX_ENVMAP) ? (int) EMID_CUSTOM : (int) closestenvmap(i, co, size)) : (int) EMID_NONE;
while(tj >= 0 && tjoints[tj].edge < i*(MAXFACEVERTS+1)) tj = tjoints[tj].next;
int hastj = tj >= 0 && tjoints[tj].edge < (i+1)*(MAXFACEVERTS+1) ? tj : -1;
int grassy = vslot.slot->autograss && i!=O_BOTTOM ? (vis!=3 || convex ? 1 : 2) : 0;
VSlot &vslot = lookupvslot(mf.tex, true),
*layer = vslot.layer && !(c.material&MAT_ALPHA) ? &lookupvslot(vslot.layer, true) : NULL;
if(vslot.slot->shader->type&SHADER_ENVMAP)
- mf.envmap = vslot.slot->texmask&(1<<TEX_ENVMAP) ? EMID_CUSTOM : closestenvmap(i, co, size);
- ushort envmap2 = layer && layer->slot->shader->type&SHADER_ENVMAP ? (layer->slot->texmask&(1<<TEX_ENVMAP) ? EMID_CUSTOM : closestenvmap(i, co, size)) : EMID_NONE;
+ mf.envmap = vslot.slot->texmask&(1<<TEX_ENVMAP) ? (int) EMID_CUSTOM : (int) closestenvmap(i, co, size);
+ ushort envmap2 = layer && layer->slot->shader->type&SHADER_ENVMAP ? (int) (layer->slot->texmask&(1<<TEX_ENVMAP) ? (int) EMID_CUSTOM : (int) closestenvmap(i, co, size)) : (int) EMID_NONE;
if(surf.numverts&LAYER_TOP) vamerges[level].add(mf);
if(surf.numverts&LAYER_BOTTOM)
int mat = c.material&MATF_VOLUME;
if(mat != fogmat)
{
- abovemat = isliquid(mat) ? c.material : MAT_AIR;
+ abovemat = isliquid(mat) ? (int) c.material : (int) MAT_AIR;
return o.z;
}
o.z = co.z + csize;
loopv(vas)
{
vtxarray &v = *vas[i];
- int prevvfc = resetocclude ? VFC_NOT_VISIBLE : v.curvfc;
+ int prevvfc = resetocclude ? (int) VFC_NOT_VISIBLE : (int) v.curvfc;
v.curvfc = isvisiblecube(v.o, v.size);
if(v.curvfc!=VFC_NOT_VISIBLE)
{
bool changed = false;
extern bool brightengeom;
extern int fullbright;
- int lmid = brightengeom && (b.es.lmid < LMID_RESERVED || (fullbright && editmode)) ? LMID_BRIGHT : b.es.lmid;
+ int lmid = brightengeom && (b.es.lmid < LMID_RESERVED || (fullbright && editmode)) ? (int) LMID_BRIGHT : (int) b.es.lmid;
if(cur.textures[1]!=lightmaptexs[lmid].id)
{
glActiveTexture_(GL_TEXTURE1);
if(normals)
{
ushort ncolor1 = color1, ncolor2 = color2;
- if(flipx)
- {
- ncolor1 = (ncolor1 & ~0xF800) | (0xF800 - (ncolor1 & 0xF800));
+ if(flipx)
+ {
+ ncolor1 = (ncolor1 & ~0xF800) | (0xF800 - (ncolor1 & 0xF800));
ncolor2 = (ncolor2 & ~0xF800) | (0xF800 - (ncolor2 & 0xF800));
}
if(flipy)
switch(s.compressed)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ [[fallthrough]];
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ [[fallthrough]];
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ [[fallthrough]];
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
{
uchar *dst = d.data, *src = s.data;
break;
}
case GL_COMPRESSED_RED_RGTC1:
+ [[fallthrough]];
case GL_COMPRESSED_RG_RGTC2:
+ [[fallthrough]];
case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
+ [[fallthrough]];
case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
{
uchar *dst = d.data, *src = s.data;
);
s.replace(d);
}
-
+
void texdup(ImageData &s, int srcchan, int dstchan)
{
if(srcchan==dstchan || max(srcchan, dstchan) >= s.bpp) return;
switch(numchans)
{
case 4: dst[3] = src[c4];
+ [[fallthrough]];
case 3: dst[2] = src[c3];
+ [[fallthrough]];
case 2: dst[1] = src[c2];
- case 1: dst[0] = src[c1];
+ [[fallthrough]];
+ case 1: dst[0] = src[c1]; break;
+ default: break;
}
);
s.replace(d);
dst[1] = src[3];
);
}
- else
+ else
{
readwritetex(d, s, dst[0] = src[0]);
}
{
switch(s.bpp)
{
- case 2:
- writetex(s,
+ case 2:
+ writetex(s,
dst[0] = uchar((uint(dst[0])*uint(dst[1]))/255);
- );
+ );
break;
- case 4:
+ case 4:
writetex(s,
uint alpha = dst[3];
dst[0] = uchar((uint(dst[0])*alpha)/255);
miny = (0 - y1) / (y2 - y1);
maxy = (1 - y1) / (y2 - y1);
}
- float dx = (maxx - minx)/max(s.w-1, 1),
+ float dx = (maxx - minx)/max(s.w-1, 1),
dy = (maxy - miny)/max(s.h-1, 1),
cury = miny;
for(uchar *dstrow = s.data + s.bpp - 1, *endrow = dstrow + s.h*s.pitch; dstrow < endrow; dstrow += s.pitch)
void uploadtexture(int tnum, GLenum target, GLenum internal, int tw, int th, GLenum format, GLenum type, void *pixels, int pw, int ph, int pitch, bool mipmap)
{
int bpp = formatsize(format), row = 0, rowalign = 0;
- if(!pitch) pitch = pw*bpp;
+ if(!pitch) pitch = pw*bpp;
uchar *buf = NULL;
- if(pw!=tw || ph!=th)
+ if(pw!=tw || ph!=th)
{
buf = new uchar[tw*th*bpp];
scaletexture((uchar *)pixels, pw, ph, bpp, pitch, buf, tw, th);
}
return NULL;
}
-
+
void setuptexparameters(int tnum, void *pixels, int clamp, int filter, GLenum format, GLenum target, bool swizzle)
{
glBindTexture(target, tnum);
if(!ph) ph = h;
int tw = w, th = h;
bool mipmap = filter > 1 && pixels;
- if(resize && pixels)
+ if(resize && pixels)
{
resizetexture(w, h, mipmap, false, target, 0, tw, th);
if(mipmap) component = compressedformat(component, tw, th);
}
- uploadtexture(tnum, subtarget, component, tw, th, format, type, pixels, pw, ph, pitch, mipmap);
+ uploadtexture(tnum, subtarget, component, tw, th, format, type, pixels, pw, ph, pitch, mipmap);
}
void createcompressedtexture(int tnum, int w, int h, uchar *data, int align, int blocksize, int levels, int clamp, int filter, GLenum format, GLenum subtarget, bool swizzle = false)
{
GLenum target = textarget(subtarget);
if(filter >= 0 && clamp >= 0) setuptexparameters(tnum, data, clamp, filter, format, target);
- uploadcompressedtexture(target, subtarget, format, w, h, data, align, blocksize, levels, filter > 1);
+ uploadcompressedtexture(target, subtarget, format, w, h, data, align, blocksize, levels, filter > 1);
}
hashnameset<Texture> textures;
if(stride&2) return 2;
return 4;
}
-
+
static Texture *newtexture(Texture *t, const char *rname, ImageData &s, int clamp = 0, bool mipit = true, bool canreduce = false, bool transient = false, int compress = 0)
{
if(!t)
t->bpp = formatsize(format);
t->type |= Texture::COMPRESSED;
}
- else
+ else
{
format = texformat(s.bpp, swizzle);
t->bpp = s.bpp;
if(swizzle && hasTRG && !hasTSW && swizzlemask(format))
{
- swizzleimage(s);
+ swizzleimage(s);
format = texformat(s.bpp, swizzle);
t->bpp = s.bpp;
}
levels--;
if(t->w > 1) t->w /= 2;
if(t->h > 1) t->h /= 2;
- }
+ }
int sizelimit = mipit && maxtexsize ? min(maxtexsize, hwtexsize) : hwtexsize;
while(t->w > sizelimit || t->h > sizelimit)
{
SDL_Surface *creatergbasurface(SDL_Surface *os)
{
SDL_Surface *ns = SDL_CreateRGBSurface(SDL_SWSURFACE, os->w, os->h, 32, RGBAMASKS);
- if(ns)
+ if(ns)
{
SDL_SetSurfaceBlendMode(os, SDL_BLENDMODE_NONE);
SDL_BlitSurface(os, NULL, ns, NULL);
{
if(!s) return NULL;
if(!s->pixels || min(s->w, s->h) <= 0 || s->format->BytesPerPixel <= 0)
- {
- SDL_FreeSurface(s);
- return NULL;
+ {
+ SDL_FreeSurface(s);
+ return NULL;
}
static const uint rgbmasks[] = { RGBMASKS }, rgbamasks[] = { RGBAMASKS };
switch(s->format->BytesPerPixel)
if(!checkgrayscale(s)) return SDL_GetColorKey(s, NULL) >= 0 ? creatergbasurface(s) : creatergbsurface(s);
break;
case 3:
- if(s->format->Rmask != rgbmasks[0] || s->format->Gmask != rgbmasks[1] || s->format->Bmask != rgbmasks[2])
+ if(s->format->Rmask != rgbmasks[0] || s->format->Gmask != rgbmasks[1] || s->format->Bmask != rgbmasks[2])
return creatergbsurface(s);
break;
case 4:
s.replace(d);
}
-void texnormal(ImageData &s, int emphasis)
+void texnormal(ImageData &s, int emphasis)
{
ImageData d(s.w, s.h, 3);
uchar *src = s.data, *dst = d.data;
dst[1] = uchar(v.y*mag + 127.5f);
dst[2] = uchar(v.z*mag + 127.5f);
}
- else
+ else
{
dst[0] = dr>>8;
dst[1] = dg>>8;
case 2: blurtexture<2, 3, true>(w, h, dst->v, src->v, margin); break;
}
}
-
+
void texblur(ImageData &s, int n, int r)
{
if(s.bpp < 3) return;
if(z)
{
SDL_RWops *rw = z->rwops();
- if(rw)
+ if(rw)
{
char *ext = (char *)strrchr(name, '.');
if(ext) ++ext;
if(!s) s = IMG_Load(findfile(name, "rb"));
return fixsurfaceformat(s);
}
-
+
static vec parsevec(const char *arg)
{
vec v(0, 0, 0);
if(!tname)
{
if(!tex) return false;
- if(tex->name[0]=='<')
+ if(tex->name[0]=='<')
{
cmds = tex->name;
file = strrchr(tex->name, '>');
file++;
}
else file = tex->name;
-
+
static string pname;
formatstring(pname, "packages/%s", file);
file = path(pname);
}
- else if(tname[0]=='<')
+ else if(tname[0]=='<')
{
cmds = tname;
file = strrchr(tname, '>');
}
if(d.data && !d.compressed && !dds && compress) *compress = scaledds;
}
-
+
if(!d.data)
{
SDL_Surface *s = NULL;
{
PARSETEXCOMMANDS(cmds);
if(d.compressed) goto compressed;
- if(matchstring(cmd, len, "mad")) texmad(d, parsevec(arg[0]), parsevec(arg[1]));
+ if(matchstring(cmd, len, "mad")) texmad(d, parsevec(arg[0]), parsevec(arg[1]));
else if(matchstring(cmd, len, "colorify")) texcolorify(d, parsevec(arg[0]), parsevec(arg[1]));
else if(matchstring(cmd, len, "colormask")) texcolormask(d, parsevec(arg[0]), *arg[1] ? parsevec(arg[1]) : vec(1, 1, 1));
- else if(matchstring(cmd, len, "normal"))
+ else if(matchstring(cmd, len, "normal"))
{
int emphasis = atoi(arg[0]);
texnormal(d, emphasis > 0 ? emphasis : 3);
}
else if(matchstring(cmd, len, "premul")) texpremul(d);
else if(matchstring(cmd, len, "agrad")) texagrad(d, atof(arg[0]), atof(arg[1]), atof(arg[2]), atof(arg[3]));
- else if(matchstring(cmd, len, "compress") || matchstring(cmd, len, "dds"))
- {
+ else if(matchstring(cmd, len, "compress") || matchstring(cmd, len, "dds"))
+ {
int scale = atoi(arg[0]);
if(scale <= 0) scale = scaledds;
if(compress) *compress = scale;
if(!(identflags&IDF_OVERRIDDEN) && !game::allowedittoggle()) return;
resetslotshader();
int limit = clamp(*n, 0, slots.length());
- for(int i = limit; i < slots.length(); i++)
+ for(int i = limit; i < slots.length(); i++)
{
Slot *s = slots[i];
for(VSlot *vs = s->variants; vs; vs = vs->next) vs->slot = &dummyslot;
{
VSlot &ds = *vslots[lastdiscard++];
if(!ds.changed && ds.index < 0) ds.index = compactedvslots++;
- }
+ }
vs.index = compactedvslots++;
}
}
VSlot &vs = *vslots[i];
if(vs.index >= 0 && vs.layer && vslots.inrange(vs.layer)) vs.layer = vslots[vs.layer]->index;
}
- loopv(vslots)
+ loopv(vslots)
{
- while(vslots[i]->index >= 0 && vslots[i]->index != i)
- swap(vslots[i], vslots[vslots[i]->index]);
+ while(vslots[i]->index >= 0 && vslots[i]->index != i)
+ swap(vslots[i], vslots[vslots[i]->index]);
}
for(int i = compactedvslots; i < vslots.length(); i++) delete vslots[i];
vslots.setsize(compactedvslots);
{
if(diff & (1<<VSLOT_SHPARAM)) loopv(src.params) dst.params.add(src.params[i]);
if(diff & (1<<VSLOT_SCALE)) dst.scale = src.scale;
- if(diff & (1<<VSLOT_ROTATION))
+ if(diff & (1<<VSLOT_ROTATION))
{
dst.rotation = src.rotation;
if(edit && !dst.offset.iszero()) clampvslotoffset(dst);
static void mergevslot(VSlot &dst, const VSlot &src, int diff, Slot *slot = NULL)
{
- if(diff & (1<<VSLOT_SHPARAM)) loopv(src.params)
+ if(diff & (1<<VSLOT_SHPARAM)) loopv(src.params)
{
const SlotShaderParam &sp = src.params[i];
loopvj(dst.params)
dst.params.add(sp);
nextparam:;
}
- if(diff & (1<<VSLOT_SCALE))
+ if(diff & (1<<VSLOT_SCALE))
{
dst.scale = clamp(dst.scale*src.scale, 1/8.0f, 8.0f);
}
- if(diff & (1<<VSLOT_ROTATION))
+ if(diff & (1<<VSLOT_ROTATION))
{
dst.rotation = clamp(dst.rotation + src.rotation, 0, 7);
if(!dst.offset.iszero()) clampvslotoffset(dst, slot);
static bool comparevslot(const VSlot &dst, const VSlot &src, int diff)
{
- if(diff & (1<<VSLOT_SHPARAM))
+ if(diff & (1<<VSLOT_SHPARAM))
{
if(src.params.length() != dst.params.length()) return false;
- loopv(src.params)
+ loopv(src.params)
{
const SlotShaderParam &sp = src.params[i], &dp = dst.params[i];
if(sp.name != dp.name || memcmp(sp.val, dp.val, sizeof(sp.val))) return false;
static void fixinsidefaces(cube *c, const ivec &o, int size, int tex)
{
- loopi(8)
+ loopi(8)
{
ivec co(i, o, size);
if(c[i].children) fixinsidefaces(c[i].children, co, size>>1, tex);
if(slots.empty()) return;
Slot &s = *slots.last();
s.variants->layer = *layer < 0 ? max(slots.length()-1+*layer, 0) : *layer;
- s.layermaskname = name[0] ? newstring(path(makerelpath("packages", name))) : NULL;
+ s.layermaskname = name[0] ? newstring(path(makerelpath("packages", name))) : NULL;
s.layermaskmode = *mode;
s.layermaskscale = *scale <= 0 ? 1 : *scale;
propagatevslot(s.variants, 1<<VSLOT_LAYER);
static void texcombine(Slot &s, int index, Slot::Tex &t, bool forceload = false)
{
- vector<char> key;
+ vector<char> key;
addname(key, s, t);
int texmask = 0;
if(!forceload) switch(t.type)
{
loopv(slots) if(slots[i]->loaded) linkslotshader(*slots[i]);
loopv(vslots) if(vslots[i]->linked) linkvslotshader(*vslots[i]);
- loopi((MATF_VOLUME|MATF_INDEX)+1) if(materialslots[i].loaded)
+ loopi((MATF_VOLUME|MATF_INDEX)+1) if(materialslots[i].loaded)
{
linkslotshader(materialslots[i]);
linkvslotshader(materialslots[i]);
addname(name, slot, slot.sts[0], false, prefix);
}
int glow = -1;
- if(slot.texmask&(1<<TEX_GLOW))
- {
- loopvj(slot.sts) if(slot.sts[j].type==TEX_GLOW) { glow = j; break; }
- if(glow >= 0)
+ if(slot.texmask&(1<<TEX_GLOW))
+ {
+ loopvj(slot.sts) if(slot.sts[j].type==TEX_GLOW) { glow = j; break; }
+ if(glow >= 0)
{
- defformatstring(prefix, "<glow:%.2f/%.2f/%.2f>", vslot.glowcolor.x, vslot.glowcolor.y, vslot.glowcolor.z);
+ defformatstring(prefix, "<glow:%.2f/%.2f/%.2f>", vslot.glowcolor.x, vslot.glowcolor.y, vslot.glowcolor.z);
addname(name, slot, slot.sts[glow], true, prefix);
}
}
VSlot *layer = vslot.layer ? &lookupvslot(vslot.layer, false) : NULL;
- if(layer)
+ if(layer)
{
if(layer->colorscale == vec(1, 1, 1)) addname(name, *layer->slot, layer->slot->sts[0], true, "<layer>");
else
if(layer->colorscale != vec(1, 1, 1)) texmad(l, layer->colorscale, vec(0, 0, 0));
if(l.w != s.w/2 || l.h != s.h/2) scaleimage(l, s.w/2, s.h/2);
forcergbimage(s);
- forcergbimage(l);
+ forcergbimage(l);
uchar *dstrow = &s.data[s.pitch*l.h + s.bpp*l.w], *srcrow = l.data;
- loop(y, l.h)
+ loop(y, l.h)
{
for(uchar *dst = dstrow, *src = srcrow, *end = &srcrow[l.w*l.bpp]; src < end; dst += s.bpp, src += l.bpp)
- loopk(3) dst[k] = src[k];
+ loopk(3) dst[k] = src[k];
dstrow += s.pitch;
srcrow += l.pitch;
}
loopv(slots)
{
Slot &slot = *slots[i];
- if(slot.loaded && slot.layermaskname && !slot.layermask)
+ if(slot.loaded && slot.layermaskname && !slot.layermask)
{
slot.layermask = new ImageData;
texturedata(*slot.layermask, slot.layermaskname);
{
copystring(tname, name);
t = textures.access(path(tname));
- if(t)
+ if(t)
{
if(!transient && t->type&Texture::TRANSIENT) t->type &= ~Texture::TRANSIENT;
return t;
t->bpp = formatsize(format);
t->type |= Texture::COMPRESSED;
}
- else
+ else
{
format = texformat(surface[0].bpp, true);
t->bpp = surface[0].bpp;
{
if(tex) { glDeleteTextures(1, &tex); tex = 0; }
}
-};
+};
static vector<envmap> envmaps;
static Texture *skyenvmap = NULL;
envmap &em = envmaps.add();
em.radius = ent.attr1 ? clamp(int(ent.attr1), 0, 10000) : envmapradius;
em.size = ent.attr2 ? clamp(int(ent.attr2), 4, 9) : 0;
- em.blur = ent.attr3 ? clamp(int(ent.attr3), 1, 2) : 0;
+ em.blur = ent.attr3 ? clamp(int(ent.attr3), 1, 2) : 0;
em.o = ent.o;
}
}
{
DELETEA(t->alphamask);
if(t->id) { glDeleteTextures(1, &t->id); t->id = 0; }
- if(t->type&Texture::TRANSIENT) textures.remove(t->name);
+ if(t->type&Texture::TRANSIENT) textures.remove(t->name);
}
void cleanuptextures()
case Texture::CUBEMAP:
if(!cubemaploadwildcard(&tex, NULL, tex.mipmap, true)) return false;
break;
- }
+ }
return true;
}
void reloadtextures()
{
int reloaded = 0;
- enumerate(textures, Texture, tex,
+ enumerate(textures, Texture, tex,
{
loadprogress = float(++reloaded)/textures.numelems;
reloadtexture(tex);
enum
{
- DDSD_CAPS = 0x00000001,
+ DDSD_CAPS = 0x00000001,
DDSD_HEIGHT = 0x00000002,
- DDSD_WIDTH = 0x00000004,
- DDSD_PITCH = 0x00000008,
- DDSD_PIXELFORMAT = 0x00001000,
- DDSD_MIPMAPCOUNT = 0x00020000,
- DDSD_LINEARSIZE = 0x00080000,
- DDSD_BACKBUFFERCOUNT = 0x00800000,
- DDPF_ALPHAPIXELS = 0x00000001,
- DDPF_FOURCC = 0x00000004,
- DDPF_INDEXED = 0x00000020,
+ DDSD_WIDTH = 0x00000004,
+ DDSD_PITCH = 0x00000008,
+ DDSD_PIXELFORMAT = 0x00001000,
+ DDSD_MIPMAPCOUNT = 0x00020000,
+ DDSD_LINEARSIZE = 0x00080000,
+ DDSD_BACKBUFFERCOUNT = 0x00800000,
+ DDPF_ALPHAPIXELS = 0x00000001,
+ DDPF_FOURCC = 0x00000004,
+ DDPF_INDEXED = 0x00000020,
DDPF_ALPHA = 0x00000002,
- DDPF_RGB = 0x00000040,
+ DDPF_RGB = 0x00000040,
DDPF_COMPRESSED = 0x00000080,
DDPF_LUMINANCE = 0x00020000,
- DDSCAPS_COMPLEX = 0x00000008,
- DDSCAPS_TEXTURE = 0x00001000,
- DDSCAPS_MIPMAP = 0x00400000,
- DDSCAPS2_CUBEMAP = 0x00000200,
- DDSCAPS2_CUBEMAP_POSITIVEX = 0x00000400,
- DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800,
- DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000,
- DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000,
- DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000,
- DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000,
+ DDSCAPS_COMPLEX = 0x00000008,
+ DDSCAPS_TEXTURE = 0x00001000,
+ DDSCAPS_MIPMAP = 0x00400000,
+ DDSCAPS2_CUBEMAP = 0x00000200,
+ DDSCAPS2_CUBEMAP_POSITIVEX = 0x00000400,
+ DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800,
+ DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000,
+ DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000,
+ DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000,
+ DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000,
DDSCAPS2_VOLUME = 0x00200000,
FOURCC_DXT1 = 0x31545844,
FOURCC_DXT2 = 0x32545844,
struct DDSCAPS2 { uint dwCaps, dwCaps2, dwCaps3, dwCaps4; };
struct DDSURFACEDESC2
{
- uint dwSize, dwFlags, dwHeight, dwWidth;
+ uint dwSize, dwFlags, dwHeight, dwWidth;
union { int lPitch; uint dwLinearSize; };
- uint dwBackBufferCount;
+ uint dwBackBufferCount;
union { uint dwMipMapCount, dwRefreshRate, dwSrcVBHandle; };
- uint dwAlphaBitDepth, dwReserved, lpSurface;
+ uint dwAlphaBitDepth, dwReserved, lpSurface;
union { DDCOLORKEY ddckCKDestOverlay; uint dwEmptyFaceColor; };
- DDCOLORKEY ddckCKDestBlt, ddckCKSrcOverlay, ddckCKSrcBlt;
+ DDCOLORKEY ddckCKDestBlt, ddckCKSrcOverlay, ddckCKSrcBlt;
union { DDPIXELFORMAT ddpfPixelFormat; uint dwFVF; };
- DDSCAPS2 ddsCaps;
- uint dwTextureStage;
+ DDSCAPS2 ddsCaps;
+ uint dwTextureStage;
};
#define DECODEDDS(name, dbpp, initblock, writeval, nextval) \
int bpp = 0;
switch(format)
{
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: bpp = 8; break;
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: bpp = 16; break;
case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
case GL_COMPRESSED_RED_RGTC1: bpp = 8; break;
if(t==notexture) { conoutf(CON_ERROR, "failed loading %s", infile); return; }
glBindTexture(GL_TEXTURE_2D, t->id);
- GLint compressed = 0, format = 0, width = 0, height = 0;
+ GLint compressed = 0, format = 0, width = 0, height = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
else concatstring(buf, ".dds");
outfile = buf;
}
-
+
stream *f = openfile(path(outfile, true), "wb");
- if(!f) { conoutf(CON_ERROR, "failed writing to %s", outfile); return; }
+ if(!f) { conoutf(CON_ERROR, "failed writing to %s", outfile); return; }
int csize = 0;
for(int lw = width, lh = height, level = 0;;)
d.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
d.ddpfPixelFormat.dwFlags = DDPF_FOURCC | (alphaformat(uncompressedformat(format)) ? DDPF_ALPHAPIXELS : 0);
d.ddpfPixelFormat.dwFourCC = fourcc;
-
+
uchar *data = new uchar[csize], *dst = data;
for(int lw = width, lh = height;;)
{
f->write(&d, sizeof(d));
f->write(data, csize);
delete f;
-
+
delete[] data;
conoutf("wrote DDS file %s", outfile);
break;
}
}
+ [[fallthrough]];
// invisible mapmodels use entselradius
default:
o = ivec(vec(e.o).sub(entselradius));
break;
}
// invisible mapmodel
+ [[fallthrough]];
default:
oe.other.add(id);
break;
oe.bbmax.min(ivec(oe.o).add(oe.size));
break;
}
+ [[fallthrough]];
// invisible mapmodel
default:
oe.other.removeobj(id);
break;
}
- if(oe.mapmodels.empty() && oe.other.empty())
+ if(oe.mapmodels.empty() && oe.other.empty())
freeoctaentities(c[i]);
}
if(c[i].ext && c[i].ext->ents) c[i].ext->ents->query = NULL;
ivec o, r;
if(!getentboundingbox(e, o, r)) return false;
- if(!insideworld(e.o))
+ if(!insideworld(e.o))
{
int idx = outsideents.find(id);
if(flags&MODOE_ADD)
loopoctabox(o, size, bo, br)
{
if(c[i].ext && c[i].ext->ents) findents(*c[i].ext->ents, low, high, notspawned, pos, invradius, found);
- if(c[i].children && size > octaentsize)
+ if(c[i].children && size > octaentsize)
{
ivec co(i, o, size);
findents(c[i].children, co, size>>1, bo, br, low, high, notspawned, pos, invradius, found);
if(a->attached) continue;
switch(e.type)
{
- case ET_SPOTLIGHT:
- if(a->type!=ET_LIGHT) continue;
+ case ET_SPOTLIGHT:
+ if(a->type!=ET_LIGHT) continue;
break;
default:
);
}
-void entselectionbox(const entity &e, vec &eo, vec &es)
+void entselectionbox(const entity &e, vec &eo, vec &es)
{
model *m = NULL;
const char *mname = entities::entmodel(e);
if(mname && (m = loadmodel(mname)))
- {
+ {
m->collisionbox(eo, es);
if(es.x > es.y) es.y = es.x; else es.x = es.y; // square
es.z = (es.z + eo.z + 1 + entselradius)/2; // enclose ent radius box and model box
eo.x += e.o.x;
eo.y += e.o.y;
eo.z = e.o.z - entselradius + es.z;
- }
+ }
else if(e.type == ET_MAPMODEL && (m = loadmapmodel(e.attr2)))
{
mmcollisionbox(e, m, eo, es);
es.max(entselradius);
eo.add(e.o);
- }
+ }
else
{
es = vec(entselradius);
eo = e.o;
- }
+ }
eo.sub(es);
es.mul(2);
}
int d = dimension(entorient),
dc= dimcoord(entorient);
- entfocus(entgroup.last(),
+ entfocus(entgroup.last(),
entselectionbox(e, eo, es);
if(!editmoveplane(e.o, ray, d, eo[d] + (dc ? es[d] : 0), handle, v, entmoving==1))
- return;
+ return;
ivec g(v);
int z = g[d]&(~(sel.grid-1));
g.add(sel.grid/2).mask(~(sel.grid-1));
g[d] = z;
-
+
r = (entselsnap ? g[R[d]] : v[R[d]]) - e.o[R[d]];
- c = (entselsnap ? g[C[d]] : v[C[d]]) - e.o[C[d]];
+ c = (entselsnap ? g[C[d]] : v[C[d]]) - e.o[C[d]];
);
if(entmoving==1) makeundoent();
vec dir = vec(e.o).sub(e.attached->o).normalize();
float angle = clamp(int(e.attr1), 1, 89);
renderentattachment(e);
- renderentcone(*e.attached, dir, radius, angle);
+ renderentcone(*e.attached, dir, radius, angle);
}
break;
}
default:
- if(e.type>=ET_GAMESPECIFIC)
+ if(e.type>=ET_GAMESPECIFIC)
{
if(color) gle::colorf(0, 1, 1);
entities::entradius(e, color);
}
void renderentselection(const vec &o, const vec &ray, bool entmoving)
-{
+{
if(noentedit()) return;
vec eo, es;
{
vec a, b;
gle::colorub(20, 20, 20);
- (a = eo).x = eo.x - fmod(eo.x, worldsize); (b = es).x = a.x + worldsize; boxs3D(a, b, 1);
- (a = eo).y = eo.y - fmod(eo.y, worldsize); (b = es).y = a.x + worldsize; boxs3D(a, b, 1);
+ (a = eo).x = eo.x - fmod(eo.x, worldsize); (b = es).x = a.x + worldsize; boxs3D(a, b, 1);
+ (a = eo).y = eo.y - fmod(eo.y, worldsize); (b = es).y = a.x + worldsize; boxs3D(a, b, 1);
(a = eo).z = eo.z - fmod(eo.z, worldsize); (b = es).z = a.x + worldsize; boxs3D(a, b, 1);
}
gle::colorub(150,0,0);
if(noentedit()) return;
int d = dimension(entorient);
int s = dimcoord(entorient) ? -*dir : *dir;
- if(entmoving)
+ if(entmoving)
{
groupeditpure(e.o[d] += float(s*sel.grid)); // editdrag supplies the undo
}
- else
+ else
groupedit(e.o[d] += float(s*sel.grid));
if(entitysurf==1)
{
}
VAR(entautoviewdist, 0, 25, 100);
-void entautoview(int *dir)
+void entautoview(int *dir)
{
if(!haveselent()) return;
static int s = 0;
if(noentedit()) return;
entcopygrid = sel.grid;
entcopybuf.shrink(0);
- loopv(entgroup)
+ loopv(entgroup)
entfocus(entgroup[i], entcopybuf.add(e).o.sub(vec(sel.o)));
}
switch(e.type)
{
case ET_PARTICLES:
- if(printparticles(e, buf, len)) return;
+ if(printparticles(e, buf, len)) return;
break;
-
+
default:
if(e.type >= ET_GAMESPECIFIC && entities::printent(e, buf, len)) return;
break;
{
if(*numargs >= 1)
{
- int typeidx = findtype(type);
+ int typeidx = findtype(type);
if(typeidx != ET_EMPTY) groupedit(e.type = typeidx);
- }
+ }
else entfocus(efocus,
{
result(entities::entname(e.type));
case 3: e.attr4 = *val; break;
case 4: e.attr5 = *val; break;
}
- );
+ );
}
else entfocus(efocus,
{
{
const vector<extentity *> &ents = entities::getents();
if(index > ents.length()) index = ents.length();
- else for(int i = index; i<ents.length(); i++)
+ else for(int i = index; i<ents.length(); i++)
{
extentity &e = *ents[i];
if(e.type==type && (attr1<0 || e.attr1==attr1) && (attr2<0 || e.attr2==attr2))
bool emptymap(int scale, bool force, const char *mname, bool usecfg) // main empty world creation routine
{
- if(!force && !editmode)
+ if(!force && !editmode)
{
conoutf(CON_ERROR, "newmap only allowed in edit mode");
return false;
setvar("mapscale", scale<10 ? 10 : (scale>16 ? 16 : scale), true, false);
setvar("mapsize", 1<<worldscale, true, false);
-
+
texmru.shrink(0);
freeocta(worldroot);
worldroot = newcubes(F_EMPTY);
cube *root = worldroot[octant].children;
worldroot[octant].children = NULL;
freeocta(worldroot);
- worldroot = root;
+ worldroot = root;
worldscale--;
- worldsize /= 2;
+ worldsize /= 2;
ivec offset(octant, ivec(0, 0, 0), worldsize);
vector<extentity *> &ents = entities::getents();
loopv(ents) ents[i]->o.sub(vec(offset));
shrinkblendmap(octant);
-
+
allchanged();
conoutf("shrunk map to size %d", worldscale);
if(mapversion < 27)
{
static const ushort matconv[] = { MAT_AIR, MAT_WATER, MAT_CLIP, MAT_GLASS|MAT_CLIP, MAT_NOCLIP, MAT_LAVA|MAT_DEATH, MAT_GAMECLIP, MAT_DEATH };
- c.material = size_t(mat) < sizeof(matconv)/sizeof(matconv[0]) ? matconv[mat] : MAT_AIR;
+ c.material = size_t(mat) < sizeof(matconv)/sizeof(matconv[0]) ? (int) matconv[mat] : (int) MAT_AIR;
}
else c.material = convertoldmaterial(mat);
}
switch(wpspot(d, d->ai->route[n], true))
{
case 2: d->ai->clear(false);
+ [[fallthrough]];
case 1: return true; // not close enough to pop it yet
- case 0:
-
default: break;
}
}
switch(i)
{
case I_SHELLS:
-
+ [[fallthrough]];
case I_BULLETS:
-
+ [[fallthrough]];
case I_ROCKETS:
-
+ [[fallthrough]];
case I_ROUNDS:
-
+ [[fallthrough]];
case I_GRENADES:
-
+ [[fallthrough]];
case I_CARTRIDGES:
if(m_noammo) continue;
break;
case I_HEALTH:
-
+ [[fallthrough]];
case I_BOOST:
-
+ [[fallthrough]];
case I_TINYHEALTH:
-
+ [[fallthrough]];
case I_TINYARMOUR:
-
+ [[fallthrough]];
case I_GREENARMOUR:
-
+ [[fallthrough]];
case I_YELLOWARMOUR:
-
+ [[fallthrough]];
case I_QUAD:
if(m_noitems) continue;
break;
{
case TELEPORT:
if(e.attr2 > 0) preloadmodel(mapmodelname(e.attr2));
+ [[fallthrough]];
case JUMPPAD:
if(e.attr4 > 0) preloadmapsound(e.attr4);
{
switch(e.type)
{
+ case TELEDEST:
+ {
+ vec dir;
+ vecfromyawpitch(e.attr1, 0, 1, 0, dir);
+ renderentarrow(e, dir, 4);
+ break;
+ }
case TELEPORT:
loopv(ents) if(ents[i]->type == TELEDEST && e.attr1==ents[i]->attr2)
{
case I_HEALTH: return health<maxhealth;
case I_TINYARMOUR:
-
+ [[fallthrough]];
case I_GREENARMOUR:
-
+ [[fallthrough]];
case I_YELLOWARMOUR: return maxarmour<is.max || armour<maxarmour;
//~case I_TINYARMOUR:
//~break;
case I_BOOST:
maxhealth = min(maxhealth+is.info, is.max);
-
+ [[fallthrough]];
case I_HEALTH: // boost also adds to health
health = min(health+is.add, maxhealth);
break;
case I_TINYARMOUR:
-
+ [[fallthrough]];
case I_GREENARMOUR:
-
+ [[fallthrough]];
case I_YELLOWARMOUR:
maxarmour = max(maxarmour, is.max);
armour = min(armour+is.add, maxarmour);
int calcpushrange()
{
ENetPeer *peer = getclientpeer(ownernum);
- return PUSHMILLIS + (peer ? peer->roundTripTime + peer->roundTripTimeVariance : ENET_PEER_DEFAULT_ROUND_TRIP_TIME);
+ return PUSHMILLIS + ((peer) ? (int) (peer->roundTripTime + peer->roundTripTimeVariance) : (int) ENET_PEER_DEFAULT_ROUND_TRIP_TIME);
}
bool checkpushed(int millis, int range)
case '!':
mode++;
if(mode[0] != '?') break;
+ [[fallthrough]];
case '?':
mode++;
loopk(NUMGAMEMODES) if(searchmodename(gamemodes[k].name, mode))
}
void operator delete(void *p) { if(p) free(p); }
-
void operator delete[](void *p) { if(p) free(p); }
+void operator delete(void *p, size_t n) { (void) n; if(p) free(p); }
+void operator delete[](void *p, size_t n) { (void) n; if(p) free(p); }
+
void *operator new(size_t size, bool err)
{
void *p = malloc(size);
////////////////////////// rnd numbers ////////////////////////////////////////
-#define N (624)
-#define M (397)
-#define K (0x9908B0DFU)
+#define N (624)
+#define M (397)
+#define K (0x9908B0DFU)
static uint state[N];
static int next = N;