diff --git a/CMakeLists.txt b/CMakeLists.txt index 54329de1..9ebe875c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,10 @@ endif() project("Blue Nebula" C CXX) -# require at least C++14 and C11 +# require at least C++20 and C11 set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(src) diff --git a/src/engine/animmodel.h b/src/engine/animmodel.h index 835220bb..57a9bd33 100644 --- a/src/engine/animmodel.h +++ b/src/engine/animmodel.h @@ -891,14 +891,14 @@ struct animmodel : model vec oaxis, oforward; matrixstack[matrixpos].transposedtransformnormal(axis, oaxis); float pitchamount = pitchscale*pitch + pitchoffset; - if(pitchmin || pitchmax) pitchamount = clamp(pitchamount, pitchmin, pitchmax); + if(pitchmin || pitchmax) pitchamount = std::clamp(pitchamount, pitchmin, pitchmax); if(as->cur.anim&ANIM_NOPITCH || (as->interp < 1 && as->prev.anim&ANIM_NOPITCH)) pitchamount *= (as->cur.anim&ANIM_NOPITCH ? 0 : as->interp) + (as->interp < 1 && as->prev.anim&ANIM_NOPITCH ? 0 : 1-as->interp); if(pitchamount) { ++matrixpos; matrixstack[matrixpos] = matrixstack[matrixpos-1]; - matrixstack[matrixpos].rotate(pitchamount*RAD, oaxis); + matrixstack[matrixpos].rotate(pitchamount*rad, oaxis); } matrixstack[matrixpos].transposedtransformnormal(forward, oforward); @@ -933,9 +933,9 @@ struct animmodel : model { linkedpart &link = links[i]; link.matrix.translate(link.translate, resize); - if(link.rotate.x) link.matrix.rotate_around_z(link.rotate.x*RAD); - if(link.rotate.z) link.matrix.rotate_around_x(-link.rotate.z*RAD); - if(link.rotate.y) link.matrix.rotate_around_y(link.rotate.y*RAD); + if(link.rotate.x) link.matrix.rotate_around_z(link.rotate.x*rad); + if(link.rotate.z) link.matrix.rotate_around_x(-link.rotate.z*rad); + if(link.rotate.y) link.matrix.rotate_around_y(link.rotate.y*rad); matrixpos++; matrixstack[matrixpos].mul(matrixstack[matrixpos-1], link.matrix); @@ -1073,14 +1073,14 @@ struct animmodel : model if(!d || !d->ragdoll || anim&ANIM_RAGDOLL) { matrixstack[0].settranslation(o); - if(yaw) matrixstack[0].rotate_around_z(yaw*RAD); - if(roll) matrixstack[0].rotate_around_x(-roll*RAD); + if(yaw) matrixstack[0].rotate_around_z(yaw*rad); + if(roll) matrixstack[0].rotate_around_x(-roll*rad); matrixstack[0].transformnormal(vec(axis), axis); matrixstack[0].transformnormal(vec(forward), forward); - if(offsetyaw) matrixstack[0].rotate_around_z(offsetyaw*RAD); - if(offsetroll) matrixstack[0].rotate_around_x(-offsetroll*RAD); - if(syaw) matrixstack[0].rotate_around_z(syaw*RAD); - if(sroll) matrixstack[0].rotate_around_x(-sroll*RAD); + if(offsetyaw) matrixstack[0].rotate_around_z(offsetyaw*rad); + if(offsetroll) matrixstack[0].rotate_around_x(-offsetroll*rad); + if(syaw) matrixstack[0].rotate_around_z(syaw*rad); + if(sroll) matrixstack[0].rotate_around_x(-sroll*rad); } else { @@ -1164,9 +1164,9 @@ struct animmodel : model void initmatrix(matrix4x3 &m) { m.identity(); - if(offsetyaw) m.rotate_around_z(offsetyaw*RAD); - if(offsetroll) m.rotate_around_x(-offsetroll*RAD); - if(offsetpitch) m.rotate_around_y(offsetpitch*RAD); + if(offsetyaw) m.rotate_around_z(offsetyaw*rad); + if(offsetroll) m.rotate_around_x(-offsetroll*rad); + if(offsetpitch) m.rotate_around_y(offsetpitch*rad); } void genBIH(vector &bih) @@ -1562,7 +1562,7 @@ template struct modelcommands static void setmaterial(char *meshname, int *material, int *material2) { - loopskins(meshname, s, { s.material = clamp(*material, 0, int(MAXLIGHTMATERIALS)); s.material2 = clamp(*material2, 0, int(MAXLIGHTMATERIALS)); }); + loopskins(meshname, s, { s.material = std::clamp(*material, 0, int(MAXLIGHTMATERIALS)); s.material2 = std::clamp(*material2, 0, int(MAXLIGHTMATERIALS)); }); } static void setlink(int *parent, int *child, char *tagname, float *x, float *y, float *z, float *yaw, float *pitch, float *roll) diff --git a/src/engine/bih.cpp b/src/engine/bih.cpp index 9acc79ce..cf819337 100644 --- a/src/engine/bih.cpp +++ b/src/engine/bih.cpp @@ -33,8 +33,8 @@ bool BIH::triintersect(const mesh &m, int tidx, const vec &mo, const vec &mray, { vec2 at = m.gettc(t.vert[0]), bt = m.gettc(t.vert[1]).sub(at).mul(v*invdet), ct = m.gettc(t.vert[2]).sub(at).mul(w*invdet); at.add(bt).add(ct); - int si = clamp(int(m.tex->xs * at.x), 0, m.tex->xs-1), - ti = clamp(int(m.tex->ys * at.y), 0, m.tex->ys-1); + int si = std::clamp(int(m.tex->xs * at.x), 0, m.tex->xs-1), + ti = std::clamp(int(m.tex->ys * at.y), 0, m.tex->ys-1); if(!(m.tex->alphamask[ti*((m.tex->xs+7)/8) + si/8] & (1<<(si%8)))) return false; } if(!(mode&RAY_SHADOW)) hitsurface = m.xformnorm.transform(n).normalize(); diff --git a/src/engine/blend.cpp b/src/engine/blend.cpp index 691325ee..82f3b8af 100644 --- a/src/engine/blend.cpp +++ b/src/engine/blend.cpp @@ -194,7 +194,7 @@ uchar lookupblendmap(BlendMapCache *cache, const vec &pos) rx = ix-cache->origin.x, ry = iy-cache->origin.y; loop(vy, 2) loop(vx, 2) { - int cx = clamp(rx+vx, 0, (1<scale)-1), cy = clamp(ry+vy, 0, (1<scale)-1); + int cx = std::clamp(rx+vx, 0, (1<scale)-1), cy = std::clamp(ry+vy, 0, (1<scale)-1); if(cache->node.type==BM_IMAGE) *val++ = cache->node.image->data[cy*BM_IMAGE_SIZE + cx]; else *val++ = lookupblendmap(cx, cy, cache->node.branch, cache->scale); @@ -265,10 +265,10 @@ static void fillblendmap(uchar &type, BlendMapNode &node, int size, uchar val, i void fillblendmap(int x, int y, int w, int h, uchar val) { int bmsize = hdr.worldsize>>BM_SCALE, - x1 = clamp(x, 0, bmsize), - y1 = clamp(y, 0, bmsize), - x2 = clamp(x+w, 0, bmsize), - y2 = clamp(y+h, 0, bmsize); + x1 = std::clamp(x, 0, bmsize), + y1 = std::clamp(y, 0, bmsize), + x2 = std::clamp(x+w, 0, bmsize), + y2 = std::clamp(y+h, 0, bmsize); if(max(x1, y1) >= bmsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return; fillblendmap(blendmap.type, blendmap, bmsize, val, x1, y1, x2, y2); } @@ -312,10 +312,10 @@ static void invertblendmap(uchar &type, BlendMapNode &node, int size, int x1, in void invertblendmap(int x, int y, int w, int h) { int bmsize = hdr.worldsize>>BM_SCALE, - x1 = clamp(x, 0, bmsize), - y1 = clamp(y, 0, bmsize), - x2 = clamp(x+w, 0, bmsize), - y2 = clamp(y+h, 0, bmsize); + x1 = std::clamp(x, 0, bmsize), + y1 = std::clamp(y, 0, bmsize), + x2 = std::clamp(x+w, 0, bmsize), + y2 = std::clamp(y+h, 0, bmsize); if(max(x1, y1) >= bmsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return; invertblendmap(blendmap.type, blendmap, bmsize, x1, y1, x2, y2); } @@ -392,8 +392,8 @@ static void blitblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int memset(node.image->data, val, sizeof(node.image->data)); } - int x1 = clamp(sx - bmx, 0, bmsize), y1 = clamp(sy - bmy, 0, bmsize), - x2 = clamp(sx+sw - bmx, 0, bmsize), y2 = clamp(sy+sh - bmy, 0, bmsize); + int x1 = std::clamp(sx - bmx, 0, bmsize), y1 = std::clamp(sy - bmy, 0, bmsize), + x2 = std::clamp(sx+sw - bmx, 0, bmsize), y2 = std::clamp(sy+sh - bmy, 0, bmsize); uchar *dst = &node.image->data[y1*BM_IMAGE_SIZE + x1]; src += max(bmy - sy, 0)*sw + max(bmx - sx, 0); loopi(y2-y1) @@ -545,7 +545,7 @@ void delblendbrush(const char *name) delete brushes[i]; brushes.remove(i--); } - curbrush = brushes.empty() ? -1 : clamp(curbrush, 0, brushes.length()-1); + curbrush = brushes.empty() ? -1 : std::clamp(curbrush, 0, brushes.length()-1); } void addblendbrush(const char *name, const char *imgname) @@ -626,7 +626,7 @@ void rotateblendbrush(int *val) { if(!canpaintblendmap()) return; - int numrots = *val < 0 ? 3 : clamp(*val, 1, 5); + int numrots = *val < 0 ? 3 : std::clamp(*val, 1, 5); BlendBrush *brush = brushes[curbrush]; brush->reorient(numrots>=2 && numrots<=4, numrots<=2 || numrots==5, (numrots&5)==1); } @@ -638,8 +638,8 @@ void paintblendmap(bool msg) if(!canpaintblendmap(true, false, msg)) return; BlendBrush *brush = brushes[curbrush]; - int x = (int)floor(clamp(worldpos.x, 0.0f, float(hdr.worldsize))/(1<w), - y = (int)floor(clamp(worldpos.y, 0.0f, float(hdr.worldsize))/(1<h); + int x = (int)floor(std::clamp(worldpos.x, 0.0f, float(hdr.worldsize))/(1<w), + y = (int)floor(std::clamp(worldpos.y, 0.0f, float(hdr.worldsize))/(1<h); blitblendmap(brush->data, x, y, brush->w, brush->h); previewblends(ivec((x-1)<w+1)<h+1)<w) << BM_SCALE, - y1 = (int)floor(clamp(worldpos.y, 0.0f, float(hdr.worldsize))/(1<h) << BM_SCALE, + int x1 = (int)floor(std::clamp(worldpos.x, 0.0f, float(hdr.worldsize))/(1<w) << BM_SCALE, + y1 = (int)floor(std::clamp(worldpos.y, 0.0f, float(hdr.worldsize))/(1<h) << BM_SCALE, x2 = x1 + (brush->w << BM_SCALE), y2 = y1 + (brush->h << BM_SCALE); diff --git a/src/engine/command.cpp b/src/engine/command.cpp index 2cc00002..2bb59dd2 100644 --- a/src/engine/command.cpp +++ b/src/engine/command.cpp @@ -540,7 +540,7 @@ char *svariable(const char *name, const char *cur, char **storage, identfun fun, void setvar(const char *name, int i, bool dofunc, bool def) { GETVAR(id, ID_VAR, name, ); - *id->storage.i = clamp(i, id->minval, id->maxval); + *id->storage.i = std::clamp(i, id->minval, id->maxval); if(def || versioning) { id->def.i = i; @@ -554,7 +554,7 @@ void setvar(const char *name, int i, bool dofunc, bool def) void setfvar(const char *name, float f, bool dofunc, bool def) { GETVAR(id, ID_FVAR, name, ); - *id->storage.f = clamp(f, id->minvalf, id->maxvalf); + *id->storage.f = std::clamp(f, id->minvalf, id->maxvalf); if(def || versioning) { id->def.f = f; @@ -1559,10 +1559,13 @@ static void compilestatements(vector &code, const char *&p, int rettype, i bool more = compileword(code, p, VAL_ANY, idname, idlen); if(!more) goto endstatement; skipcomments(p); - if(p[0] == '=') switch(p[1]) - { + if (p[0] == '=') { + switch(p[1]) { case '/': - if(p[2] != '/') break; + if (p[2] != '/') { + break; + } + [[fallthrough]]; case ';': case ' ': case '\t': case '\r': case '\n': case '\0': p++; if(idname) @@ -1574,6 +1577,8 @@ static void compilestatements(vector &code, const char *&p, int rettype, i if(!(more = compilearg(code, p, VAL_ANY))) compilestr(code); code.add(id && idname ? (id->index < MAXARGS ? CODE_ALIASARG : CODE_ALIAS)|(id->index<<8) : CODE_ALIASU); goto endstatement; + break; + } } numargs = 0; if(!idname) @@ -2797,8 +2802,10 @@ void explodelist(const char *s, vector &elems, int limit) void explodelist(const char *s, std::vector &elems, int limit) { const char *start, *end; - while((limit < 0 || elems.size() < limit) && parselist(s, start, end)) + + while ((limit < 0 || elems.size() < static_cast(limit)) && parselist(s, start, end)) { elems.emplace_back(std::string(start, end-start)); + } } char *indexlist(const char *s, int pos) @@ -2842,8 +2849,8 @@ COMMAND(0, at, "si1V"); void substring(char *s, int *start, int *count, int *numargs) { - int len = strlen(s), offset = clamp(*start, 0, len); - commandret->setstr(newstring(&s[offset], *numargs >= 3 ? clamp(*count, 0, len - offset) : len - offset)); + int len = strlen(s), offset = std::clamp(*start, 0, len); + commandret->setstr(newstring(&s[offset], *numargs >= 3 ? std::clamp(*count, 0, len - offset) : len - offset)); } COMMAND(0, substring, "siiN"); @@ -3273,7 +3280,7 @@ ICOMMAND(0, ^~, "ii", (int *a, int *b), intret(*a ^ ~*b)); ICOMMAND(0, &~, "ii", (int *a, int *b), intret(*a & ~*b)); ICOMMAND(0, |~, "ii", (int *a, int *b), intret(*a | ~*b)); ICOMMAND(0, <<, "ii", (int *a, int *b), intret(*b < 32 ? *a << max(*b, 0) : 0)); -ICOMMAND(0, >>, "ii", (int *a, int *b), intret(*a >> clamp(*b, 0, 31))); +ICOMMAND(0, >>, "ii", (int *a, int *b), intret(*a >> std::clamp(*b, 0, 31))); ICOMMAND(0, &&, "e1V", (tagval *args, int numargs), { if(!numargs) intret(1); @@ -3297,17 +3304,17 @@ ICOMMAND(0, ||, "e1V", (tagval *args, int numargs), ICOMMAND(0, mod, "ii", (int *a, int *b), intret(*b ? *a % *b : 0)); ICOMMAND(0, modf, "ff", (float *a, float *b), floatret(*b ? fmod(*a, *b) : 0)); -ICOMMAND(0, sin, "f", (float *a), floatret(sin(*a*RAD))); -ICOMMAND(0, cos, "f", (float *a), floatret(cos(*a*RAD))); -ICOMMAND(0, tan, "f", (float *a), floatret(tan(*a*RAD))); -ICOMMAND(0, asin, "f", (float *a), floatret(asin(*a)/RAD)); -ICOMMAND(0, acos, "f", (float *a), floatret(acos(*a)/RAD)); -ICOMMAND(0, atan, "f", (float *a), floatret(atan(*a)/RAD)); -ICOMMAND(0, atan2, "ff", (float *y, float *x), floatret(atan2(*y, *x)/RAD)); +ICOMMAND(0, sin, "f", (float *a), floatret(sin(*a*rad))); +ICOMMAND(0, cos, "f", (float *a), floatret(cos(*a*rad))); +ICOMMAND(0, tan, "f", (float *a), floatret(tan(*a*rad))); +ICOMMAND(0, asin, "f", (float *a), floatret(asin(*a)/rad)); +ICOMMAND(0, acos, "f", (float *a), floatret(acos(*a)/rad)); +ICOMMAND(0, atan, "f", (float *a), floatret(atan(*a)/rad)); +ICOMMAND(0, atan2, "ff", (float *y, float *x), floatret(atan2(*y, *x)/rad)); ICOMMAND(0, sqrt, "f", (float *a), floatret(sqrt(*a))); ICOMMAND(0, pow, "ff", (float *a, float *b), floatret(pow(*a, *b))); ICOMMAND(0, loge, "f", (float *a), floatret(log(*a))); -ICOMMAND(0, log2, "f", (float *a), floatret(log(*a)/M_LN2)); +ICOMMAND(0, log2, "f", (float *a), floatret(log(*a)/ln2)); ICOMMAND(0, log10, "f", (float *a), floatret(log10(*a))); ICOMMAND(0, exp, "f", (float *a), floatret(exp(*a))); ICOMMAND(0, min, "V", (tagval *args, int numargs), @@ -3509,8 +3516,8 @@ ICOMMAND(0, stringreplace, "sss", (char *s, char *o, char *n), commandret->setst void stringsplice(const char *s, const char *vals, int *skip, int *count) { int slen = strlen(s), vlen = strlen(vals), - offset = clamp(*skip, 0, slen), - len = clamp(*count, 0, slen - offset); + offset = std::clamp(*skip, 0, slen), + len = std::clamp(*count, 0, slen - offset); char *p = newstring(slen - len + vlen); if(offset) memcpy(p, s, offset); if(vlen) memcpy(&p[offset], vals, vlen); @@ -3658,4 +3665,4 @@ char *limitstring(const char *str, size_t len) copystring(limitstrtext, str, len); return limitstrtext; } -ICOMMAND(0, limitstring, "si", (char *s, int *n), result(limitstring(s, *n))); +ICOMMAND(0, limitstring, "si", (char *s, int *n), result(limitstring(s, *n))); \ No newline at end of file diff --git a/src/engine/decal.cpp b/src/engine/decal.cpp index 1a296118..24e04e11 100644 --- a/src/engine/decal.cpp +++ b/src/engine/decal.cpp @@ -324,7 +324,7 @@ struct decalrenderer decaltangent = vec(dir.z, -dir.x, dir.y); decaltangent.sub(vec(dir).mul(decaltangent.dot(dir))); #endif - if(flags&DF_ROTATE) decaltangent.rotate(rnd(360)*RAD, dir); + if(flags&DF_ROTATE) decaltangent.rotate(rnd(360)*rad, dir); decaltangent.normalize(); decalbitangent.cross(decaltangent, dir); if(flags&DF_RND4) diff --git a/src/engine/dynlight.cpp b/src/engine/dynlight.cpp index 40595408..06b25832 100644 --- a/src/engine/dynlight.cpp +++ b/src/engine/dynlight.cpp @@ -230,7 +230,7 @@ void makelightfx(extentity &e, extentity &f) millis -= interval; e.emit[2] = lastmillis-millis; } if(millis >= e.emit[0]) loopi(LFX_MAX-1) if(e.attrs[4]&(1<<(LFX_S_MAX+i))) { effect = i+1; break; } - #define lightskew float skew = clamp(millis < e.emit[0] ? 1.f-(float(millis)/float(e.emit[0])) : float(millis-e.emit[0])/float(e.emit[1]), 0.f, 1.f); + #define lightskew float skew = std::clamp(millis < e.emit[0] ? 1.f-(float(millis)/float(e.emit[0])) : float(millis-e.emit[0])/float(e.emit[1]), 0.f, 1.f); switch(effect) { case LFX_FLICKER: diff --git a/src/engine/explosion.h b/src/engine/explosion.h index d8fb0ecd..c660311a 100644 --- a/src/engine/explosion.h +++ b/src/engine/explosion.h @@ -18,10 +18,10 @@ namespace sphere float ds = 1.0f/slices, dt = 1.0f/stacks, t = 1.0f; loopi(stacks+1) { - float rho = M_PI*(1-t), s = 0.0f, sinrho = i && i < stacks ? sin(rho) : 0, cosrho = !i ? 1 : (i < stacks ? cos(rho) : -1); + float rho = pi*(1-t), s = 0.0f, sinrho = i && i < stacks ? sin(rho) : 0, cosrho = !i ? 1 : (i < stacks ? cos(rho) : -1); loopj(slices+1) { - float theta = j==slices ? 0 : 2*M_PI*s; + float theta = j==slices ? 0 : 2*pi*s; vert &v = verts[i*(slices+1) + j]; v.pos = vec(-sin(theta)*sinrho, cos(theta)*sinrho, cosrho); v.s = ushort(s*0xFFFF); @@ -216,7 +216,7 @@ struct explosionrenderer : sharedlistrenderer t = vec(dir.x*dir.z, dir.y*dir.z, -mag2/dist); } - matrix3 rot(lastmillis/1000.0f*143*RAD, vec(1/SQRT3, 1/SQRT3, 1/SQRT3)); + matrix3 rot(lastmillis/1000.0f*143*rad, vec(1/sqrt3, 1/sqrt3, 1/sqrt3)); LOCALPARAM(texgenS, rot.transposedtransform(s)); LOCALPARAM(texgenT, rot.transposedtransform(t)); diff --git a/src/engine/grass.cpp b/src/engine/grass.cpp index 3eb4861f..c3c21d1b 100644 --- a/src/engine/grass.cpp +++ b/src/engine/grass.cpp @@ -15,12 +15,12 @@ struct grasswedge void init(int i, int n) { - dir = vec(2*M_PI*(i+0.5f)/float(n), 0); - across = vec(2*M_PI*((i+0.5f)/float(n) + 0.25f), 0); - edge1 = vec(2*M_PI*i/float(n), 0).div(cos(M_PI/n)); - edge2 = vec(2*M_PI*(i+1)/float(n), 0).div(cos(M_PI/n)); - bound1 = plane(vec(2*M_PI*(i/float(n) - 0.25f), 0), 0); - bound2 = plane(vec(2*M_PI*((i+1)/float(n) + 0.25f), 0), 0); + dir = vec(2*pi*(i+0.5f)/float(n), 0); + across = vec(2*pi*((i+0.5f)/float(n) + 0.25f), 0); + edge1 = vec(2*pi*i/float(n), 0).div(cos(pi/n)); + edge2 = vec(2*pi*(i+1)/float(n), 0).div(cos(pi/n)); + bound1 = plane(vec(2*pi*(i/float(n) - 0.25f), 0), 0); + bound2 = plane(vec(2*pi*((i+1)/float(n) + 0.25f), 0), 0); across.div(-across.dot(bound1)); } }; @@ -77,7 +77,7 @@ FVAR(IDF_WORLD, grassanimscale, 0, 0.03f, 1); static void animategrass() { - loopi(numgrassoffsets) grassanimoffsets[i] = grassanimscale*sinf(2*M_PI*(grassoffsets[i] + lastmillis/float(grassanimmillis))); + loopi(numgrassoffsets) grassanimoffsets[i] = grassanimscale*sinf(2*pi*(grassoffsets[i] + lastmillis/float(grassanimmillis))); lastgrassanim = lastmillis; } diff --git a/src/engine/irc.cpp b/src/engine/irc.cpp index e06927f1..ca98e6eb 100644 --- a/src/engine/irc.cpp +++ b/src/engine/irc.cpp @@ -357,19 +357,19 @@ ICOMMAND(0, ircbind, "ss", (const char *name, const char *s), { ICOMMAND(0, ircpass, "ss", (const char *name, const char *s), { ircnet *n = ircfind(name); if(!n) { conoutf("no such ircnet: %s", name); return; } - if(!s || !*s) { ircprintf(n, 4, NULL, "current password is: %s", n->passkey && *n->passkey ? "" : ""); return; } + if(!s || !*s) { ircprintf(n, 4, NULL, "current password is: %s", *n->passkey ? "" : ""); return; } copystring(n->passkey, s); }); ICOMMAND(0, ircauthcommand, "ss", (const char *name, const char *s), { ircnet *n = ircfind(name); if(!n) { conoutf("no such ircnet: %s", name); return; } - if(!s || !*s) { ircprintf(n, 4, NULL, "current auth command is: %s", n->authcommand && *n->authcommand ? "" : ""); return; } + if(!s || !*s) { ircprintf(n, 4, NULL, "current auth command is: %s", *n->authcommand ? "" : ""); return; } copystring(n->authcommand, s); }); ICOMMAND(0, ircauth, "sss", (const char *name, const char *s, const char *t), { ircnet *n = ircfind(name); if(!n) { conoutf("no such ircnet: %s", name); return; } - if(!s || !*s || !t || !*t) { ircprintf(n, 4, NULL, "current auth details are: %s (%s)", n->authname, n->authpass && *n->authpass ? "" : ""); return; } + if(!s || !*s || !t || !*t) { ircprintf(n, 4, NULL, "current auth details are: %s (%s)", n->authname, *n->authpass ? "" : ""); return; } copystring(n->authname, s); copystring(n->authpass, t); }); @@ -462,7 +462,7 @@ ICOMMAND(0, ircpasschan, "sss", (const char *name, const char *chan, const char if(!n) { conoutf("no such ircnet: %s", name); return; } ircchan *c = ircfindchan(n, chan); if(!c) { ircprintf(n, 4, NULL, "no such channel: %s", chan); return; } - if(!s || !*s) { ircprintf(n, 4, NULL, "channel %s current password is: %s", c->name, c->passkey && *c->passkey ? "" : ""); return; } + if(!s || !*s) { ircprintf(n, 4, NULL, "channel %s current password is: %s", c->name, *c->passkey ? "" : ""); return; } copystring(c->passkey, s); }); ICOMMAND(0, ircrelaychan, "sss", (const char *name, const char *chan, const char *s), { @@ -820,16 +820,19 @@ bool ircaddsockets(ENetSocket &maxsock, ENetSocketSet &readset, ENetSocketSet &w loopv(ircnets) { ircnet *n = ircnets[i]; - if(n->sock != ENET_SOCKET_NULL && n->state > IRC_DISC) switch(n->state) - { + if (n->sock != ENET_SOCKET_NULL && n->state > IRC_DISC) { + switch (n->state) { case IRC_WAIT: ENET_SOCKETSET_ADD(writeset, n->sock); - // fall-through - case IRC_ONLINE: case IRC_CONN: case IRC_QUIT: + [[fallthrough]]; + case IRC_ONLINE: + case IRC_CONN: + case IRC_QUIT: maxsock = maxsock == ENET_SOCKET_NULL ? n->sock : max(maxsock, n->sock); ENET_SOCKETSET_ADD(readset, n->sock); numsocks++; break; + } } } return numsocks > 0; @@ -934,15 +937,15 @@ void ircslice() break; } case IRC_ONLINE: - { - loopvj(n->channels) - { + loopvj(n->channels) { ircchan *c = &n->channels[j]; - if(c->type == IRCCT_AUTO && c->state != IRCC_JOINED && (!c->lastjoin || clocktime-c->lastjoin >= (c->state != IRCC_BANNED ? 5 : ircautorejoin))) - ircjoin(n, c); + if (c->type == IRCCT_AUTO && c->state != IRCC_JOINED && + (!c->lastjoin || + clocktime - c->lastjoin >= (c->state != IRCC_BANNED ? 5 : ircautorejoin))) { + ircjoin(n, c); + } } - // fall through - } + [[fallthrough]]; case IRC_CONN: { if(n->state == IRC_CONN && (!n->lastattempt || clocktime-n->lastattempt >= irctimeout)) diff --git a/src/engine/lensflare.h b/src/engine/lensflare.h index ba6a24fd..84242cb3 100644 --- a/src/engine/lensflare.h +++ b/src/engine/lensflare.h @@ -142,7 +142,7 @@ struct flarerenderer : partrenderer r = e.attrs[2]; g = e.attrs[3]; b = e.attrs[4]; - o = vec(camera1->o).add(vec(e.attrs[0]*RAD, (e.attrs[1]+90)*RAD).mul(getworldsize()*2)); + o = vec(camera1->o).add(vec(e.attrs[0]*rad, (e.attrs[1]+90)*rad).mul(getworldsize()*2)); project = true; if(e.attrs[7] > 0) scale = e.attrs[7]/100.f; break; diff --git a/src/engine/lightmap.cpp b/src/engine/lightmap.cpp index a575e74b..bcddffd3 100644 --- a/src/engine/lightmap.cpp +++ b/src/engine/lightmap.cpp @@ -525,7 +525,7 @@ static uint generatelumel(lightmapworker *w, const float tolerance, uint lightma { extentity &spotlight = *ents[slight]; vec spot = vec(spotlight.o).sub(light.o).normalize(); - float maxatten = sincos360[clamp(int(spotlight.attrs[1]), 1, 89)].x, spotatten = (ray.dot(spot) - maxatten) / (1 - maxatten); + float maxatten = sincos360[std::clamp(int(spotlight.attrs[1]), 1, 89)].x, spotatten = (ray.dot(spot) - maxatten) / (1 - maxatten); if(spotatten <= 0) continue; attenuation *= spotatten; } @@ -593,27 +593,27 @@ static void calcskylight(lightmapworker *w, const vec &o, const vec &normal, flo { static const vec rays[17] = { - vec(cosf(21*RAD)*cosf(50*RAD), sinf(21*RAD)*cosf(50*RAD), sinf(50*RAD)), - vec(cosf(111*RAD)*cosf(50*RAD), sinf(111*RAD)*cosf(50*RAD), sinf(50*RAD)), - vec(cosf(201*RAD)*cosf(50*RAD), sinf(201*RAD)*cosf(50*RAD), sinf(50*RAD)), - vec(cosf(291*RAD)*cosf(50*RAD), sinf(291*RAD)*cosf(50*RAD), sinf(50*RAD)), + vec(cosf(21*rad)*cosf(50*rad), sinf(21*rad)*cosf(50*rad), sinf(50*rad)), + vec(cosf(111*rad)*cosf(50*rad), sinf(111*rad)*cosf(50*rad), sinf(50*rad)), + vec(cosf(201*rad)*cosf(50*rad), sinf(201*rad)*cosf(50*rad), sinf(50*rad)), + vec(cosf(291*rad)*cosf(50*rad), sinf(291*rad)*cosf(50*rad), sinf(50*rad)), - vec(cosf(66*RAD)*cosf(70*RAD), sinf(66*RAD)*cosf(70*RAD), sinf(70*RAD)), - vec(cosf(156*RAD)*cosf(70*RAD), sinf(156*RAD)*cosf(70*RAD), sinf(70*RAD)), - vec(cosf(246*RAD)*cosf(70*RAD), sinf(246*RAD)*cosf(70*RAD), sinf(70*RAD)), - vec(cosf(336*RAD)*cosf(70*RAD), sinf(336*RAD)*cosf(70*RAD), sinf(70*RAD)), + vec(cosf(66*rad)*cosf(70*rad), sinf(66*rad)*cosf(70*rad), sinf(70*rad)), + vec(cosf(156*rad)*cosf(70*rad), sinf(156*rad)*cosf(70*rad), sinf(70*rad)), + vec(cosf(246*rad)*cosf(70*rad), sinf(246*rad)*cosf(70*rad), sinf(70*rad)), + vec(cosf(336*rad)*cosf(70*rad), sinf(336*rad)*cosf(70*rad), sinf(70*rad)), vec(0, 0, 1), - vec(cosf(43*RAD)*cosf(60*RAD), sinf(43*RAD)*cosf(60*RAD), sinf(60*RAD)), - vec(cosf(133*RAD)*cosf(60*RAD), sinf(133*RAD)*cosf(60*RAD), sinf(60*RAD)), - vec(cosf(223*RAD)*cosf(60*RAD), sinf(223*RAD)*cosf(60*RAD), sinf(60*RAD)), - vec(cosf(313*RAD)*cosf(60*RAD), sinf(313*RAD)*cosf(60*RAD), sinf(60*RAD)), + vec(cosf(43*rad)*cosf(60*rad), sinf(43*rad)*cosf(60*rad), sinf(60*rad)), + vec(cosf(133*rad)*cosf(60*rad), sinf(133*rad)*cosf(60*rad), sinf(60*rad)), + vec(cosf(223*rad)*cosf(60*rad), sinf(223*rad)*cosf(60*rad), sinf(60*rad)), + vec(cosf(313*rad)*cosf(60*rad), sinf(313*rad)*cosf(60*rad), sinf(60*rad)), - vec(cosf(88*RAD)*cosf(80*RAD), sinf(88*RAD)*cosf(80*RAD), sinf(80*RAD)), - vec(cosf(178*RAD)*cosf(80*RAD), sinf(178*RAD)*cosf(80*RAD), sinf(80*RAD)), - vec(cosf(268*RAD)*cosf(80*RAD), sinf(268*RAD)*cosf(80*RAD), sinf(80*RAD)), - vec(cosf(358*RAD)*cosf(80*RAD), sinf(358*RAD)*cosf(80*RAD), sinf(80*RAD)), + vec(cosf(88*rad)*cosf(80*rad), sinf(88*rad)*cosf(80*rad), sinf(80*rad)), + vec(cosf(178*rad)*cosf(80*rad), sinf(178*rad)*cosf(80*rad), sinf(80*rad)), + vec(cosf(268*rad)*cosf(80*rad), sinf(268*rad)*cosf(80*rad), sinf(80*rad)), + vec(cosf(358*rad)*cosf(80*rad), sinf(358*rad)*cosf(80*rad), sinf(80*rad)), }; flags |= RAY_SHADOW; @@ -641,16 +641,16 @@ void calcsunlight(lightmapworker *w, const vec &o, const vec &normal, float tole if(light.attrs.length() < 5 || (slight[0] >= light.attrs[2] && slight[1] >= light.attrs[3] && slight[2] >= light.attrs[4])) continue; int yaw = light.attrs[0], pitch = light.attrs[1]+90, offset = light.attrs.inrange(5) && light.attrs[5] ? (light.attrs[5] > 0 ? light.attrs[5] : 0) : 10, hit = 0; - vec dir(yaw*RAD, pitch*RAD); + vec dir(yaw*rad, pitch*rad); if(normal.dot(dir) >= 0 && (w ? shadowray(w->shadowraycache, vec(dir).mul(tolerance).add(o), dir, 1e16f, flags, t) > 1e15f : shadowray(vec(dir).mul(tolerance).add(o), dir, 1e16f, flags, t) > 1e15f)) hit++; if(offset) { - matrix3 rot(90*RAD, dir); - vec spoke(yaw*RAD, (pitch + offset)*RAD); - spoke.rotate(21*RAD, dir); + matrix3 rot(90*rad, dir); + vec spoke(yaw*rad, (pitch + offset)*rad); + spoke.rotate(21*rad, dir); loopk(4) { if(normal.dot(spoke) >= 0 && @@ -659,7 +659,7 @@ void calcsunlight(lightmapworker *w, const vec &o, const vec &normal, float tole hit++; spoke = rot.transform(spoke); } - spoke = vec(yaw*RAD, (pitch + 0.5f*offset)*RAD).rotate((66-21)*RAD, dir); + spoke = vec(yaw*rad, (pitch + 0.5f*offset)*rad).rotate((66-21)*rad, dir); loopk(4) { if(normal.dot(spoke) >= 0 && @@ -1378,7 +1378,7 @@ static int setupsurface(lightmapworker *w, plane planes[2], int numplanes, const int scale = int(min(cmax.x - cmin.x, cmax.y - cmin.y)); float lpu = 16.0f / float(lightlod && scale < (1 << lightlod) ? max(curlightprecision / 2, 1) : curlightprecision); - int lw = clamp(int(ceil((cmax.x - cmin.x + 1)*lpu)), LM_MINW, LM_MAXW), lh = clamp(int(ceil((cmax.y - cmin.y + 1)*lpu)), LM_MINH, LM_MAXH); + int lw = std::clamp(int(ceil((cmax.x - cmin.x + 1)*lpu)), LM_MINW, LM_MAXW), lh = std::clamp(int(ceil((cmax.y - cmin.y + 1)*lpu)), LM_MINH, LM_MAXH); w->w = lw; w->h = lh; if(!preview) @@ -1432,8 +1432,8 @@ static int setupsurface(lightmapworker *w, plane planes[2], int numplanes, const if(lh != w->h) texscale.y *= float(w->h - 1) / (lh - 1); loopk(numverts) { - litverts[k].u = ushort(floor(clamp(c[k].x*texscale.x, 0.0f, float(USHRT_MAX)))); - litverts[k].v = ushort(floor(clamp(c[k].y*texscale.y, 0.0f, float(USHRT_MAX)))); + litverts[k].u = ushort(floor(std::clamp(c[k].x*texscale.x, 0.0f, float(USHRT_MAX)))); + litverts[k].v = ushort(floor(std::clamp(c[k].y*texscale.y, 0.0f, float(USHRT_MAX)))); } return surftype; } @@ -2616,10 +2616,10 @@ static inline void fastskylight(const vec &o, float tolerance, uchar *skylight, { static const vec rays[5] = { - vec(cosf(66*RAD)*cosf(65*RAD), sinf(66*RAD)*cosf(65*RAD), sinf(65*RAD)), - vec(cosf(156*RAD)*cosf(65*RAD), sinf(156*RAD)*cosf(65*RAD), sinf(65*RAD)), - vec(cosf(246*RAD)*cosf(65*RAD), sinf(246*RAD)*cosf(65*RAD), sinf(65*RAD)), - vec(cosf(336*RAD)*cosf(65*RAD), sinf(336*RAD)*cosf(65*RAD), sinf(65*RAD)), + vec(cosf(66*rad)*cosf(65*rad), sinf(66*rad)*cosf(65*rad), sinf(65*rad)), + vec(cosf(156*rad)*cosf(65*rad), sinf(156*rad)*cosf(65*rad), sinf(65*rad)), + vec(cosf(246*rad)*cosf(65*rad), sinf(246*rad)*cosf(65*rad), sinf(65*rad)), + vec(cosf(336*rad)*cosf(65*rad), sinf(336*rad)*cosf(65*rad), sinf(65*rad)), vec(0, 0, 1), }; int hit = 0; @@ -2637,7 +2637,7 @@ static inline void fastsunlight(const vec &o, float tolerance, uchar *slight, in const extentity &light = *sunlights[i]; if(light.attrs.length() < 5 || (slight[0] >= light.attrs[2] && slight[1] >= light.attrs[3] && slight[2] >= light.attrs[4])) continue; int yaw = light.attrs[0], pitch = light.attrs[1]+90; - vec dir(yaw*RAD, pitch*RAD); + vec dir(yaw*rad, pitch*rad); if(shadowray(vec(dir).mul(tolerance).add(o), dir, 1e16f, flags, t) > 1e15f) { loopk(3) slight[k] = max(uchar(light.attrs[2+k]), slight[k]); @@ -2697,7 +2697,7 @@ void lightreaching(const vec &target, vec &color, vec &dir, bool fast, extentity { extentity &spotlight = *ents[slight]; vec spot = vec(spotlight.o).sub(e.o).normalize(); - float maxatten = sincos360[clamp(int(spotlight.attrs[1]), 1, 89)].x, spotatten = (ray.dot(spot) - maxatten) / (1 - maxatten); + float maxatten = sincos360[std::clamp(int(spotlight.attrs[1]), 1, 89)].x, spotatten = (ray.dot(spot) - maxatten) / (1 - maxatten); if(spotatten <= 0) continue; intensity *= spotatten; } @@ -2726,7 +2726,7 @@ void lightreaching(const vec &target, vec &color, vec &dir, bool fast, extentity else fastsunlight(target, 0.5f, col, RAY_POLY, t); loopk(3) slight[k] = max(slight[k], col[k]/255.0f); } - loopk(3) color[k] = clamp(color[k], slight[k], 1.5f); + loopk(3) color[k] = std::clamp(color[k], slight[k], 1.5f); if(dir.iszero()) dir = vec(0, 0, 1); else dir.normalize(); } @@ -2772,7 +2772,7 @@ const extentity *brightestlight(const vec &target, const vec &dir) { const extentity &spotlight = *ents[slight]; vec spot = vec(spotlight.o).sub(e.o).normalize(); - float maxatten = sincos360[clamp(int(spotlight.attrs[1]), 1, 89)].x, spotatten = (ray.dot(spot) - maxatten) / (1 - maxatten); + float maxatten = sincos360[std::clamp(int(spotlight.attrs[1]), 1, 89)].x, spotatten = (ray.dot(spot) - maxatten) / (1 - maxatten); if(spotatten <= 0) continue; intensity *= spotatten; } diff --git a/src/engine/lightning.h b/src/engine/lightning.h index 4e40e507..442a0a52 100644 --- a/src/engine/lightning.h +++ b/src/engine/lightning.h @@ -36,7 +36,7 @@ static void renderlightning(Texture *tex, const vec &o, const vec &d, float sz, vec step(d); step.sub(o); float len = step.magnitude(); - int numsteps = clamp(int(ceil(len/LIGHTNINGSTEP)), 2, MAXLIGHTNINGSTEPS); + int numsteps = std::clamp(int(ceil(len/LIGHTNINGSTEP)), 2, MAXLIGHTNINGSTEPS); step.div(numsteps+1); int jitteroffset = detrnd(int(d.x+d.y+d.z), MAXLIGHTNINGSTEPS); vec cur(o), up, right; @@ -46,7 +46,7 @@ static void renderlightning(Texture *tex, const vec &o, const vec &d, float sz, right.normalize(); float scroll = -float(lastmillis%lnscrollmillis)/lnscrollmillis, scrollscale = lnscrollscale*(LIGHTNINGSTEP*tex->ys)/(sz*tex->xs), - blend = pow(clamp(float(lastmillis - lastlnjitter)/lnjittermillis, 0.0f, 1.0f), lnblendpower), + blend = pow(std::clamp(float(lastmillis - lastlnjitter)/lnjittermillis, 0.0f, 1.0f), lnblendpower), jitter0 = (1-blend)*lnjitterscale*sz/lnjitterradius, jitter1 = blend*lnjitterscale*sz/lnjitterradius, fadescale = sz/step.magnitude(); gle::begin(GL_TRIANGLE_STRIP); diff --git a/src/engine/main.cpp b/src/engine/main.cpp index 2ff311bd..c4da5e42 100644 --- a/src/engine/main.cpp +++ b/src/engine/main.cpp @@ -1,5 +1,6 @@ // main.cpp: initialisation & main loop #include "engine.h" +#include #include string caption = ""; @@ -115,7 +116,7 @@ void quit() // normal exit exit(EXIT_SUCCESS); } -volatile int errors = 0; +std::atomic errors {0}; void fatal(const char *s, ...) // failure exit { if(++errors <= 2) // print up to one extra recursive error @@ -245,8 +246,8 @@ VARF(0, fullscreendesktop, 0, 0, 1, if(!(identflags&IDF_WORLD) && fullscreen) re void screenres(int w, int h) { - scr_w = clamp(w, SCR_MINW, SCR_MAXW); - scr_h = clamp(h, SCR_MINH, SCR_MAXH); + scr_w = std::clamp(w, SCR_MINW, SCR_MAXW); + scr_h = std::clamp(h, SCR_MINH, SCR_MAXH); if(screen) { if(fullscreendesktop) @@ -326,8 +327,8 @@ void setupscreen() if(scr_h < 0) scr_h = fullscreen ? desktoph : SCR_DEFAULTH; if(scr_w < 0) scr_w = (scr_h*desktopw)/desktoph; - scr_w = clamp(scr_w, SCR_MINW, SCR_MAXW); - scr_h = clamp(scr_h, SCR_MINH, SCR_MAXH); + scr_w = std::clamp(scr_w, SCR_MINW, SCR_MAXW); + scr_h = std::clamp(scr_h, SCR_MINH, SCR_MAXH); if(fullscreendesktop) { scr_w = min(scr_w, desktopw); @@ -505,8 +506,10 @@ bool interceptkey(int sym, int mod) while(pollevent(event)) switch(event.type) { case SDL_KEYDOWN: - if(event.key.keysym.sym == sym && (!mod || SDL_GetModState()&mod)) + if (event.key.keysym.sym == sym && (!mod || SDL_GetModState()&mod)) { return true; + } + [[fallthrough]]; default: pushevent(event); break; @@ -624,8 +627,8 @@ void checkinput() SDL_GetWindowSize(screen, &screenw, &screenh); if(!fullscreendesktop || !(SDL_GetWindowFlags(screen) & SDL_WINDOW_FULLSCREEN)) { - scr_w = clamp(screenw, SCR_MINW, SCR_MAXW); - scr_h = clamp(screenh, SCR_MINH, SCR_MAXH); + scr_w = std::clamp(screenw, SCR_MINW, SCR_MAXW); + scr_h = std::clamp(screenh, SCR_MINH, SCR_MAXH); } gl_resize(); break; @@ -957,8 +960,8 @@ int main(int argc, char **argv) { switch(argv[i][2]) { - case 'w': scr_w = clamp(atoi(&argv[i][3]), SCR_MINW, SCR_MAXW); if(!findarg(argc, argv, "-dh")) scr_h = -1; break; - case 'h': scr_h = clamp(atoi(&argv[i][3]), SCR_MINH, SCR_MAXH); if(!findarg(argc, argv, "-dw")) scr_w = -1; break; + case 'w': scr_w = std::clamp(atoi(&argv[i][3]), SCR_MINW, SCR_MAXW); if(!findarg(argc, argv, "-dh")) scr_h = -1; break; + case 'h': scr_h = std::clamp(atoi(&argv[i][3]), SCR_MINH, SCR_MAXH); if(!findarg(argc, argv, "-dw")) scr_w = -1; break; case 'd': depthbits = atoi(&argv[i][3]); break; case 'c': /* compat, ignore */ break; case 'a': fsaa = atoi(&argv[i][3]); break; @@ -1012,7 +1015,7 @@ int main(int argc, char **argv) initing = NOT_INITING; - numcpus = clamp(SDL_GetCPUCount(), 1, 16); + numcpus = std::clamp(SDL_GetCPUCount(), 1, 16); conoutf("loading enet.."); if(enet_initialize()<0) fatal("Unable to initialise network module"); diff --git a/src/engine/master.cpp b/src/engine/master.cpp index a00fe407..59d2ea76 100644 --- a/src/engine/master.cpp +++ b/src/engine/master.cpp @@ -438,7 +438,7 @@ bool checkmasterclientinput(masterclient &c) } else { - if(w[1] && *w[1]) c.port = clamp(atoi(w[1]), 1, VAR_MAX); + if(w[1] && *w[1]) c.port = std::clamp(atoi(w[1]), 1, VAR_MAX); ENetAddress address = { ENET_HOST_ANY, enet_uint16(c.port) }; c.version = w[3] && *w[3] ? atoi(w[3]) : (w[2] && *w[2] ? 150 : 0); if(w[4] && *w[4]) copystring(c.desc, w[4], MAXSDESCLEN+1); diff --git a/src/engine/material.cpp b/src/engine/material.cpp index 3a857c6b..e8abd63c 100644 --- a/src/engine/material.cpp +++ b/src/engine/material.cpp @@ -507,7 +507,7 @@ void sortmaterials(vector &vismats) { sortorigin = ivec(camera1->o); if(reflecting) sortorigin.z = int(reflectz - (camera1->o.z - reflectz)); - vec dir(camera1->yaw*RAD, reflecting ? -camera1->pitch : camera1->pitch); + vec dir(camera1->yaw*rad, reflecting ? -camera1->pitch : camera1->pitch); loopi(3) { dir[i] = fabs(dir[i]); sortdim[i] = i; } if(dir[sortdim[2]] > dir[sortdim[1]]) std::swap(sortdim[2], sortdim[1]); if(dir[sortdim[1]] > dir[sortdim[0]]) std::swap(sortdim[1], sortdim[0]); @@ -702,7 +702,7 @@ void rendermaterials() { xtraverts += gle::end(); glBindTexture(GL_TEXTURE_2D, mslot->sts[1].t->id); - float angle = fmod(float(lastmillis/600.0f/(2*M_PI)), 1.0f), + float angle = fmod(float(lastmillis/600.0f/(2*pi)), 1.0f), s = angle - int(angle) - 0.5f; s *= 8 - fabs(s)*16; wfwave = vertwater ? WATER_AMPLITUDE*s-WATER_OFFSET : -WATER_OFFSET; @@ -800,7 +800,7 @@ void rendermaterials() } if(m.orient!=O_TOP) { - float angle = fmod(float(lastmillis/2000.0f/(2*M_PI)), 1.0f), + float angle = fmod(float(lastmillis/2000.0f/(2*pi)), 1.0f), s = angle - int(angle) - 0.5f; s *= 8 - fabs(s)*16; wfwave = vertwater ? WATER_AMPLITUDE*s-WATER_OFFSET : -WATER_OFFSET; diff --git a/src/engine/md3.h b/src/engine/md3.h index 0b0b73a8..f472fa55 100644 --- a/src/engine/md3.h +++ b/src/engine/md3.h @@ -93,7 +93,7 @@ struct md3 : vertmodel, vertloader f->seek(mesh_offset + mheader.ofs_triangles, SEEK_SET); loopj(m.numtris) { - md3triangle tri; + md3triangle tri{}; f->read(&tri, sizeof(md3triangle)); // read the triangles lilswap(tri.vertexindices, 3); loopk(3) m.tris[j].vert[k] = (ushort)tri.vertexindices[k]; @@ -109,7 +109,7 @@ struct md3 : vertmodel, vertloader f->seek(mesh_offset + mheader.ofs_vertices, SEEK_SET); loopj(numframes*m.numverts) { - md3vertex v; + md3vertex v{}; f->read(&v, sizeof(md3vertex)); // read the vertices lilswap(v.vertex, 4); @@ -117,8 +117,8 @@ struct md3 : vertmodel, vertloader m.verts[j].pos.y = -v.vertex[1]/64.0f; m.verts[j].pos.z = v.vertex[2]/64.0f; - float lng = (v.normal&0xFF)*PI2/255.0f; // decode vertex normals - float lat = ((v.normal>>8)&0xFF)*PI2/255.0f; + float lng = (v.normal&0xFF)*(pi*2)/255.0f; // decode vertex normals + float lat = ((v.normal>>8)&0xFF)*(pi*2)/255.0f; m.verts[j].norm.x = cosf(lat)*sinf(lng); m.verts[j].norm.y = -sinf(lat)*sinf(lng); m.verts[j].norm.z = cosf(lng); diff --git a/src/engine/mpr.h b/src/engine/mpr.h index 6c757792..ce26c042 100644 --- a/src/engine/mpr.h +++ b/src/engine/mpr.h @@ -61,7 +61,7 @@ namespace mpr EntOBB(physent *ent) : Ent(ent) { - orient.setyaw(ent->yaw*RAD); + orient.setyaw(ent->yaw*rad); } vec contactface(const vec &wn, const vec &wdir) const diff --git a/src/engine/normal.cpp b/src/engine/normal.cpp index c5328ce0..22773a89 100644 --- a/src/engine/normal.cpp +++ b/src/engine/normal.cpp @@ -234,7 +234,7 @@ void calcnormals(bool lerptjoints) if(!lerpangle) return; usetnormals = lerptjoints; if(usetnormals) findtjoints(); - lerpthreshold = cos(lerpangle*RAD) - 1e-5f; + lerpthreshold = cos(lerpangle*rad) - 1e-5f; nmprog = 1; loopi(8) addnormals(worldroot[i], ivec(i, ivec(0, 0, 0), hdr.worldsize/2), hdr.worldsize/2); } diff --git a/src/engine/octa.cpp b/src/engine/octa.cpp index 4b80c1e7..278c58c0 100644 --- a/src/engine/octa.cpp +++ b/src/engine/octa.cpp @@ -219,9 +219,9 @@ ivec lu; int lusize; cube &lookupcube(const ivec &to, int tsize, ivec &ro, int &rsize) { - int tx = clamp(to.x, 0, hdr.worldsize-1), - ty = clamp(to.y, 0, hdr.worldsize-1), - tz = clamp(to.z, 0, hdr.worldsize-1); + int tx = std::clamp(to.x, 0, hdr.worldsize-1), + ty = std::clamp(to.y, 0, hdr.worldsize-1), + tz = std::clamp(to.z, 0, hdr.worldsize-1); int scale = worldscale-1, csize = abs(tsize); cube *c = &worldroot[octastep(tx, ty, tz, scale)]; if(!(csize>>scale)) do @@ -422,10 +422,10 @@ bool subdividecube(cube &c, bool fullcheck, bool brighten) { ch[i].texture[j] = c.texture[j]; int rd = (i>>R[d])&1, cd = (i>>C[d])&1, dd = (i>>D[d])&1; - edgeset(cubeedge(ch[i], d, 0, 0), z, clamp(e[rd][cd] - dd*8, 0, 8)); - edgeset(cubeedge(ch[i], d, 1, 0), z, clamp(e[1+rd][cd] - dd*8, 0, 8)); - edgeset(cubeedge(ch[i], d, 0, 1), z, clamp(e[rd][1+cd] - dd*8, 0, 8)); - edgeset(cubeedge(ch[i], d, 1, 1), z, clamp(e[1+rd][1+cd] - dd*8, 0, 8)); + edgeset(cubeedge(ch[i], d, 0, 0), z, std::clamp(e[rd][cd] - dd*8, 0, 8)); + edgeset(cubeedge(ch[i], d, 1, 0), z, std::clamp(e[1+rd][cd] - dd*8, 0, 8)); + edgeset(cubeedge(ch[i], d, 0, 1), z, std::clamp(e[rd][1+cd] - dd*8, 0, 8)); + edgeset(cubeedge(ch[i], d, 1, 1), z, std::clamp(e[1+rd][1+cd] - dd*8, 0, 8)); } } diff --git a/src/engine/octaedit.cpp b/src/engine/octaedit.cpp index e084818a..e279c71c 100644 --- a/src/engine/octaedit.cpp +++ b/src/engine/octaedit.cpp @@ -393,7 +393,7 @@ void rendereditcursor() if(!insideworld(w)) { wdist = 0; - loopi(3) w[i] = clamp(player->o[i], 0.0f, float(hdr.worldsize)); + loopi(3) w[i] = std::clamp(player->o[i], 0.0f, float(hdr.worldsize)); } } cube *c = &lookupcube(ivec(w)); @@ -1451,9 +1451,9 @@ static void renderprefab(prefab &p, const vec &o, float yaw, float pitch, float matrix4 m; m.identity(); m.settranslation(o); - if(yaw) m.rotate_around_z(yaw*RAD); - if(pitch) m.rotate_around_x(pitch*RAD); - if(roll) m.rotate_around_y(-roll*RAD); + if(yaw) m.rotate_around_z(yaw*rad); + if(pitch) m.rotate_around_x(pitch*rad); + if(roll) m.rotate_around_y(-roll*rad); matrix3 w(m); if(size > 0 && size != 1) m.scale(size); m.translate(vec(b.s).mul(-b.grid*0.5f)); @@ -1610,7 +1610,7 @@ void brushvert(int *x, int *y, int *v) *x += MAXBRUSH2 - brushx + 1; // +1 for automatic padding *y += MAXBRUSH2 - brushy + 1; if(*x<0 || *y<0 || *x>=MAXBRUSH || *y>=MAXBRUSH) return; - brush[*x][*y] = clamp(*v, 0, 8); + brush[*x][*y] = std::clamp(*v, 0, 8); paintbrush = paintbrush || (brush[*x][*y] > 0); brushmaxx = min(MAXBRUSH-1, max(brushmaxx, *x+1)); brushmaxy = min(MAXBRUSH-1, max(brushmaxy, *y+1)); @@ -1958,8 +1958,8 @@ namespace hmap memset(flags, 0, sizeof flags); selecting = true; - select(clamp(MAXBRUSH2-cx, bmx, bnx), - clamp(MAXBRUSH2-cy, bmy, bny), + select(std::clamp(MAXBRUSH2-cx, bmx, bnx), + std::clamp(MAXBRUSH2-cy, bmy, bny), dc ? gz : hws - gz); selecting = false; if(paintme) @@ -2278,7 +2278,7 @@ void vrotate(int *n) if(noedit()) return; VSlot ds; ds.changed = 1<sts.empty() ? "" : v.slot->sts[0].name); g.textf(" - scale: \fa%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.scale); - g.textf(" - rotation: \fa%d (%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.rotation, rotations[clamp(v.rotation, 0, 5)]); + g.textf(" - rotation: \fa%d (%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.rotation, rotations[std::clamp(v.rotation, 0, 5)]); g.textf(" - offset: \fa%d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.offset.x, v.offset.y); g.textf(" - scroll: \fa%f %f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.scroll.x, v.scroll.y); g.textf(" - alpha: \fa%f \fAfront \fa%f \fAback", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.alphafront, v.alphaback); @@ -2937,7 +2937,7 @@ struct texturegui : guicb { if(!texmru.inrange(menutex = !isempty(c) ? texmru.find(c.texture[sel.orient]) : texmru.find(lasttex))) menutex = 0; - menupage = clamp(menutex, 0, texmru.length()-1)/(thumbwidth*thumbheight); + menupage = std::clamp(menutex, 0, texmru.length()-1)/(thumbwidth*thumbheight); } else menutex = menupage = 0; } diff --git a/src/engine/octarender.cpp b/src/engine/octarender.cpp index adc18e34..44394917 100644 --- a/src/engine/octarender.cpp +++ b/src/engine/octarender.cpp @@ -767,8 +767,8 @@ static inline void calctexgen(VSlot &vslot, int dim, vec4 &sgen, vec4 &tgen) ushort encodenormal(const vec &n) { if(n.iszero()) return 0; - int yaw = int(-atan2(n.x, n.y)/RAD), pitch = int(asin(n.z)/RAD); - return ushort(clamp(pitch + 90, 0, 180)*360 + (yaw < 0 ? yaw%360 + 360 : yaw%360) + 1); + int yaw = int(-atan2(n.x, n.y)/rad), pitch = int(asin(n.z)/rad); + return ushort(std::clamp(pitch + 90, 0, 180)*360 + (yaw < 0 ? yaw%360 + 360 : yaw%360) + 1); } vec decodenormal(ushort norm) @@ -1620,7 +1620,7 @@ int updateva(cube *c, const ivec &co, int size, int csi) int tcount = count + (csi <= MAXMERGELEVEL ? vamerges[csi].length() : 0); if(tcount > vafacemax || (tcount >= vafacemin && size >= vacubesize) || size == min(0x1000, hdr.worldsize/2)) { - loadprogress = clamp(recalcocprog/float(allocnodes), 0.0f, 1.0f); + loadprogress = std::clamp(recalcocprog/float(allocnodes), 0.0f, 1.0f); setva(c[i], o, size, csi); if(c[i].ext && c[i].ext->va) { diff --git a/src/engine/physics.cpp b/src/engine/physics.cpp index 6ececcd6..cf7670f6 100644 --- a/src/engine/physics.cpp +++ b/src/engine/physics.cpp @@ -26,7 +26,7 @@ void resetclipplanes() clipcacheversion += 2; if(!clipcacheversion) { - memset(clipcache, 0, sizeof(clipcache)); + *clipcache = {}; clipcacheversion = 2; } } @@ -404,7 +404,7 @@ void resetshadowraycache(ShadowRayCache *cache) cache->version++; if(!cache->version) { - memset(cache->clipcache, 0, sizeof(cache->clipcache)); + *cache->clipcache = {}; cache->version = 1; } } @@ -502,10 +502,10 @@ bool ellipseboxcollide(physent *d, const vec &dir, const vec &o, const vec ¢ vec yo(d->o); yo.sub(o); - yo.rotate_around_z(-yaw*RAD); + yo.rotate_around_z(-yaw*rad); yo.sub(center); - float dx = clamp(yo.x, -xr, xr) - yo.x, dy = clamp(yo.y, -yr, yr) - yo.y, + float dx = std::clamp(yo.x, -xr, xr) - yo.x, dy = std::clamp(yo.y, -yr, yr) - yo.y, dist = sqrtf(dx*dx + dy*dy) - d->radius; if(dist < 0) { @@ -514,20 +514,20 @@ bool ellipseboxcollide(physent *d, const vec &dir, const vec &o, const vec ¢ if(dist > (yo.z < 0 ? below : above) && (sx || sy)) { vec ydir(dir); - ydir.rotate_around_z(-yaw*RAD); + ydir.rotate_around_z(-yaw*rad); if(sx*yo.x - xr > sy*yo.y - yr) { if(dir.iszero() || sx*ydir.x < -1e-6f) { collidewall = vec(sx, 0, 0); - collidewall.rotate_around_z(yaw*RAD); + collidewall.rotate_around_z(yaw*rad); return true; } } else if(dir.iszero() || sy*ydir.y < -1e-6f) { collidewall = vec(0, sy, 0); - collidewall.rotate_around_z(yaw*RAD); + collidewall.rotate_around_z(yaw*rad); return true; } } @@ -555,10 +555,10 @@ bool ellipsecollide(physent *d, const vec &dir, const vec &o, const vec ¢er, above = (d->o.z-d->height) - (o.z+center.z+hi); if(below>=0 || above>=0) return false; vec yo(center); - yo.rotate_around_z(yaw*RAD); + yo.rotate_around_z(yaw*rad); yo.add(o); float x = yo.x - d->o.x, y = yo.y - d->o.y; - float angle = atan2f(y, x), dangle = angle-(d->yaw+90)*RAD, eangle = angle-(yaw+90)*RAD; + float angle = atan2f(y, x), dangle = angle-(d->yaw+90)*rad, eangle = angle-(yaw+90)*rad; float dx = d->xradius*cosf(dangle), dy = d->yradius*sinf(dangle); float ex = xr*cosf(eangle), ey = yr*sinf(eangle); float dist = sqrtf(x*x + y*y) - sqrtf(dx*dx + dy*dy) - sqrtf(ex*ex + ey*ey); @@ -1267,8 +1267,8 @@ bool getsight(vec &o, float yaw, float pitch, vec &q, vec &v, float mdist, float if(dist <= mdist) { - float x = fmod(fabs(asin((q.z-o.z)/dist)/RAD-pitch), 360); - float y = fmod(fabs(-atan2(q.x-o.x, q.y-o.y)/RAD-yaw), 360); + float x = fmod(fabs(asin((q.z-o.z)/dist)/rad-pitch), 360); + float y = fmod(fabs(-atan2(q.x-o.x, q.y-o.y)/rad-yaw), 360); if(min(x, 360-x) <= fovx && min(y, 360-y) <= fovy) return raycubelos(o, q, v); } return false; diff --git a/src/engine/ragdoll.h b/src/engine/ragdoll.h index 6fbb643d..6c745857 100644 --- a/src/engine/ragdoll.h +++ b/src/engine/ragdoll.h @@ -354,7 +354,7 @@ void ragdolldata::calcrotfriction() void ragdolldata::applyrotfriction(float ts) { calctris(); - float stopangle = 2*M_PI*ts*ragdollrotfricstop, rotfric = 1.0f - pow(ragdollrotfric, ts*1000.0f/ragdolltimestepmin); + float stopangle = 2*pi*ts*ragdollrotfricstop, rotfric = 1.0f - pow(ragdollrotfric, ts*1000.0f/ragdolltimestepmin); loopv(skel->rotfrictions) { ragdollskel::rotfriction &r = skel->rotfrictions[i]; @@ -495,7 +495,7 @@ void ragdolldata::move(dynent *pl, float ts) vert &v = verts[i]; vec dpos = vec(v.pos).sub(v.oldpos); dpos.z -= gravity*ts*ts; - if(liquid) dpos.z += 0.25f*sinf(detrnd(size_t(this)+i, 360)*RAD + lastmillis/10000.0f*M_PI)*ts*pl->submerged; + if(liquid) dpos.z += 0.25f*sinf(detrnd(size_t(this)+i, 360)*rad + lastmillis/10000.0f*pi)*ts*pl->submerged; dpos.mul(pow((liquid ? physics::liquidmerge(pl, 1.f, ragdollliquidfric) : 1.f) * (v.collided ? ragdollgroundfric : airfric), ts*1000.0f/ragdolltimestepmin)*tsfric); v.oldpos = v.pos; v.pos.add(dpos); diff --git a/src/engine/rendergl.cpp b/src/engine/rendergl.cpp index 61a48e9c..1ce154bf 100644 --- a/src/engine/rendergl.cpp +++ b/src/engine/rendergl.cpp @@ -631,7 +631,7 @@ vec worldpos, camdir, camright, camup; void findorientation(vec &o, float yaw, float pitch, vec &pos) { - vec dir(yaw*RAD, pitch*RAD); + vec dir(yaw*rad, pitch*rad); if(raycubepos(o, dir, pos, 0, RAY_CLIPMAT|RAY_SKIPFIRST) == -1) pos = dir.mul(2*hdr.worldsize).add(o); //otherwise gui won't work when outside of map } @@ -640,9 +640,9 @@ void setcammatrix() { // move from RH to Z-up LH quake style worldspace cammatrix = viewmatrix; - cammatrix.rotate_around_y(camera1->roll*RAD); - cammatrix.rotate_around_x(camera1->pitch*-RAD); - cammatrix.rotate_around_z(camera1->yaw*-RAD); + cammatrix.rotate_around_y(camera1->roll*rad); + cammatrix.rotate_around_x(camera1->pitch*-rad); + cammatrix.rotate_around_z(camera1->yaw*-rad); cammatrix.translate(vec(camera1->o).neg()); cammatrix.transposedtransformnormal(vec(viewmatrix.b), camdir); @@ -830,7 +830,7 @@ void calcspherescissor(const vec ¢er, float size, float &sx1, float &sy1, fl if(e.z > 2*size) { sx1 = sy1 = 1; sx2 = sy2 = -1; return; } float zzrr = e.z*e.z - size*size, dx = e.x*e.x + zzrr, dy = e.y*e.y + zzrr, - focaldist = 1.0f/tan(fovy*0.5f*RAD); + focaldist = 1.0f/tan(fovy*0.5f*rad); sx1 = sy1 = -1; sx2 = sy2 = 1; #define CHECKPLANE(c, dir, focaldist, low, high) \ @@ -1567,7 +1567,7 @@ namespace modelpreview aspect = w/float(h); fovy = modelpreviewfov; - curfov = 2*atan2(tan(fovy/2*RAD), 1/aspect)/RAD; + curfov = 2*atan2(tan(fovy/2*rad), 1/aspect)/rad; farplane = 1024; clearfogdist(); @@ -1608,8 +1608,8 @@ namespace modelpreview vec calcmodelpreviewpos(const vec &radius, float &yaw) { yaw = fmod(lastmillis/10000.0f*360.0f, 360.0f); - float dist = 1.05f*max(radius.magnitude2()/aspect, radius.magnitude())/sinf(fovy/2*RAD); - return vec(0, dist, 0).rotate_around_x(camera1->pitch*RAD); + float dist = 1.05f*max(radius.magnitude2()/aspect, radius.magnitude())/sinf(fovy/2*rad); + return vec(0, dist, 0).rotate_around_x(camera1->pitch*rad); } GLuint minimaptex = 0; @@ -1787,8 +1787,8 @@ void gettextres(int &w, int &h) void drawslice(float start, float length, float x, float y, float size) { float end = start + length, - sx = cosf((start + 0.25f)*2*M_PI), sy = -sinf((start + 0.25f)*2*M_PI), - ex = cosf((end + 0.25f)*2*M_PI), ey = -sinf((end + 0.25f)*2*M_PI); + sx = cosf((start + 0.25f)*2*pi), sy = -sinf((start + 0.25f)*2*pi), + ex = cosf((end + 0.25f)*2*pi), ey = -sinf((end + 0.25f)*2*pi); #define SLICEVERT(ox, oy) do { \ gle::attribf(x + (ox)*size, y + (oy)*size); \ @@ -1820,8 +1820,8 @@ void drawslice(float start, float length, float x, float y, float size) void drawfadedslice(float start, float length, float x, float y, float size, float alpha, float r, float g, float b, float minsize) { float end = start + length, - sx = cosf((start + 0.25f)*2*M_PI), sy = -sinf((start + 0.25f)*2*M_PI), - ex = cosf((end + 0.25f)*2*M_PI), ey = -sinf((end + 0.25f)*2*M_PI); + sx = cosf((start + 0.25f)*2*pi), sy = -sinf((start + 0.25f)*2*pi), + ex = cosf((end + 0.25f)*2*pi), ey = -sinf((end + 0.25f)*2*pi); #define SLICESPOKE(ox, oy) do { \ SLICEVERT((ox)*minsize, (oy)*minsize); \ @@ -1968,7 +1968,7 @@ void viewproject(int targtype = VP_CAMERA) if(targtype != VP_LEFT && targtype != VP_RIGHT) projmatrix.perspective(fovy, aspect, nearplane, farplane); else { - float top = stereonear*tan(fovy/2*RAD), right = aspect*top, iod = stereodist/2; + float top = stereonear*tan(fovy/2*rad), right = aspect*top, iod = stereodist/2; if(targtype == VP_RIGHT) iod = -iod; float fs = iod*stereonear/stereoplane; projmatrix.frustum(-right+fs, right+fs, -top, top, stereonear, farplane); @@ -2253,7 +2253,7 @@ void gl_drawframe() float blend = abovemat == MAT_AIR ? fogblend : 1.0f; fovy += blend*sinf(lastmillis/1000.0)*2.0f; - aspect += blend*sinf(lastmillis/1000.0+PI)*0.1f; + aspect += blend*sinf(lastmillis/1000.0+pi)*0.1f; } else fogmat = MAT_AIR; diff --git a/src/engine/rendermodel.cpp b/src/engine/rendermodel.cpp index 453471d3..0d4b3300 100644 --- a/src/engine/rendermodel.cpp +++ b/src/engine/rendermodel.cpp @@ -42,7 +42,7 @@ MODELTYPE(MDL_IQM, iqm); void mdlmaterial(int *material, int *material2) { checkmdl; - loadingmodel->setmaterial(clamp(*material, 0, int(MAXLIGHTMATERIALS)), clamp(*material2, 0, int(MAXLIGHTMATERIALS))); + loadingmodel->setmaterial(std::clamp(*material, 0, int(MAXLIGHTMATERIALS)), std::clamp(*material2, 0, int(MAXLIGHTMATERIALS))); } COMMAND(0, mdlmaterial, "ii"); @@ -331,7 +331,7 @@ void rdlimitrot(int *t1, int *t2, float *maxangle, float *qx, float *qy, float * ragdollskel::rotlimit &r = ragdoll->rotlimits.add(); r.tri[0] = *t1; r.tri[1] = *t2; - r.maxangle = *maxangle * RAD; + r.maxangle = *maxangle * rad; r.middle = matrix3(quat(*qx, *qy, *qz, *qw)); } COMMAND(0, rdlimitrot, "iifffff"); @@ -538,7 +538,7 @@ void renderellipse(vec &o, float xradius, float yradius, float yaw) loopi(15) { const vec2 &sc = sincos360[i*(360/15)]; - gle::attrib(vec(xradius*sc.x, yradius*sc.y, 0).rotate_around_z((yaw+90)*RAD).add(o)); + gle::attrib(vec(xradius*sc.x, yradius*sc.y, 0).rotate_around_z((yaw+90)*rad).add(o)); } xtraverts += gle::end(); } @@ -820,13 +820,13 @@ void renderradius(const vec &o, float radius) switch(k) { case 0: - d.add(vec(radius*cosf(2*M_PI*i/16.0f), radius*sinf(2*M_PI*i/16.0f), 0).rotate_around_x(90*RAD)); + d.add(vec(radius*cosf(2*pi*i/16.0f), radius*sinf(2*pi*i/16.0f), 0).rotate_around_x(90*rad)); break; case 1: - d.add(vec(radius*cosf(2*M_PI*i/16.0f), radius*sinf(2*M_PI*i/16.0f), 0).rotate_around_y(-90*RAD)); + d.add(vec(radius*cosf(2*pi*i/16.0f), radius*sinf(2*pi*i/16.0f), 0).rotate_around_y(-90*rad)); break; case 2: default: - d.add(vec(radius*cosf(2*M_PI*i/16.0f), radius*sinf(2*M_PI*i/16.0f), 0).rotate_around_z(90*RAD)); + d.add(vec(radius*cosf(2*pi*i/16.0f), radius*sinf(2*pi*i/16.0f), 0).rotate_around_z(90*rad)); break; } gle::attrib(d); @@ -861,8 +861,8 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl else { center.mul(size); - center.rotate_around_x(-roll*RAD); - center.rotate_around_z(yaw*RAD); + center.rotate_around_x(-roll*rad); + center.rotate_around_z(yaw*rad); center.add(o); } radius *= size; @@ -917,9 +917,9 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl matrix4x3 m; m.identity(); m.settranslation(o); - m.rotate_around_z(yaw*RAD); - m.rotate_around_x(roll*-RAD); - m.rotate_around_y(pitch*-RAD); + m.rotate_around_z(yaw*rad); + m.rotate_around_x(roll*-rad); + m.rotate_around_y(pitch*-rad); render3dbox(center, radius.z, radius.z, radius.x, radius.y, &m); } diff --git a/src/engine/renderparticles.cpp b/src/engine/renderparticles.cpp index c62927f4..344830e2 100644 --- a/src/engine/renderparticles.cpp +++ b/src/engine/renderparticles.cpp @@ -85,7 +85,7 @@ struct partrenderer int weight = p->grav; if((type&PT_SHRINK || type&PT_GROW) && p->fade >= 50) { - float amt = clamp(ts/float(p->fade), 0.f, 1.f); + float amt = std::clamp(ts/float(p->fade), 0.f, 1.f); if(type&PT_SHRINK) { if(type&PT_GROW) { if((amt *= 2) > 1) amt = 2-amt; amt *= amt; } @@ -379,8 +379,8 @@ struct portalrenderer : listrenderer void renderpart(portal *p, int blend, int ts, float size) { matrix4x3 m(vec(size, 0, 0), vec(0, size, 0), vec(0, 0, size), p->o); - m.rotate_around_z(p->yaw*RAD); - m.rotate_around_x(p->pitch*RAD); + m.rotate_around_z(p->yaw*rad); + m.rotate_around_x(p->pitch*rad); bvec4 color(p->color.r, p->color.g, p->color.b, uchar(p->blend*blend)); gle::attrib(m.transform(vec(-1, 0, 1))); gle::attribf(1, 0); gle::color(color); @@ -451,8 +451,8 @@ struct iconrenderer : listrenderer bvec4 color(p->color.r, p->color.g, p->color.b, uchar(p->blend*blend)); if(p->start > 0 || p->length < 1) { - float sx = cosf((p->start + 0.25f)*2*M_PI), sy = -sinf((p->start + 0.25f)*2*M_PI), - ex = cosf((p->end + 0.25f)*2*M_PI), ey = -sinf((p->end + 0.25f)*2*M_PI); + float sx = cosf((p->start + 0.25f)*2*pi), sy = -sinf((p->start + 0.25f)*2*pi), + ex = cosf((p->end + 0.25f)*2*pi), ey = -sinf((p->end + 0.25f)*2*pi); gle::end(); gle::begin(GL_TRIANGLE_FAN); iconvert(0, 0); @@ -539,10 +539,10 @@ static inline void genrotpos(const vec &o, const vec &d, float size, int grav, i } #define ROTCOEFFS(n) { \ - vec(-1, 1, 0).rotate_around_z(n*2*M_PI/32.0f), \ - vec( 1, 1, 0).rotate_around_z(n*2*M_PI/32.0f), \ - vec( 1, -1, 0).rotate_around_z(n*2*M_PI/32.0f), \ - vec(-1, -1, 0).rotate_around_z(n*2*M_PI/32.0f) \ + vec(-1, 1, 0).rotate_around_z(n*2*pi/32.0f), \ + vec( 1, 1, 0).rotate_around_z(n*2*pi/32.0f), \ + vec( 1, -1, 0).rotate_around_z(n*2*pi/32.0f), \ + vec(-1, -1, 0).rotate_around_z(n*2*pi/32.0f) \ } static const vec rotcoeffs[32][4] = { @@ -769,7 +769,7 @@ struct softquadrenderer : quadrenderer int blend = 255, ts = 1; float size = 1; calc(&p, blend, ts, size, false); - float radius = size*SQRT2; + float radius = size*sqrt2; if(!isfoggedsphere(radius, p.o) && (depthfxscissor!=2 || depthfxtex.addscissorbox(p.o, radius))) { numsoft++; @@ -1006,9 +1006,9 @@ struct coneprimitiverenderer : listrenderer p->radius = radius; p->angle = angle; p->fill = fill; - p->spot = vec(p->dir).mul(p->radius*cosf(p->angle*RAD)); + p->spot = vec(p->dir).mul(p->radius*cosf(p->angle*rad)); p->spoke.orthogonal(p->dir); - p->spoke.normalize().mul(p->radius*sinf(p->angle*RAD)); + p->spoke.normalize().mul(p->radius*sinf(p->angle*rad)); return p; } @@ -1306,7 +1306,7 @@ void part_trail(int ptype, int fade, const vec &s, const vec &e, int color, floa if(!canaddparticles()) return; vec v; float d = e.dist(s, v); - int steps = clamp(int(d*2), 1, maxparticletrail); + int steps = std::clamp(int(d*2), 1, maxparticletrail); v.div(steps); vec p = s; loopi(steps) @@ -1412,7 +1412,7 @@ void part_dir(const vec &o, float yaw, float pitch, float length, float size, fl { if(!canaddparticles()) return; - vec v(yaw*RAD, pitch*RAD); + vec v(yaw*rad, pitch*rad); part_line(o, vec(v).mul(length).add(o), size, blend, fade, color); if(interval) { @@ -1546,7 +1546,7 @@ static inline vec offsetvec(vec o, int dir, int dist) } else if(dir < 24) //sphere { - to = vec(PI2*float(rnd(1000))/1000.0, PI*float(rnd(1000)-500)/1000.0).mul(radius); + to = vec((pi*2)*float(rnd(1000))/1000.0, pi*float(rnd(1000)-500)/1000.0).mul(radius); to.add(p); from = p; } @@ -1564,7 +1564,7 @@ static inline vec offsetvec(vec o, int dir, int dist) if(taper) { - float dist = clamp(from.dist2(camera1->o) / maxparticledistance, 0.0f, 1.0f); + float dist = std::clamp(from.dist2(camera1->o) / maxparticledistance, 0.0f, 1.0f); if(dist > 0.2f) { dist = 1 - (dist - 0.2f)/0.8f; @@ -1638,7 +1638,7 @@ void makeparticle(const vec &o, attrvector &attr) break; case 2: //water fountain - { - int mat = MAT_WATER + clamp(-attr[2], 0, 3); + int mat = MAT_WATER + std::clamp(-attr[2], 0, 3); const bvec &wfcol = getwaterfallcol(mat); int color = (int(wfcol[0])<<16) | (int(wfcol[1])<<8) | int(wfcol[2]); if(!color) @@ -1688,19 +1688,19 @@ void makeparticle(const vec &o, attrvector &attr) regularflame(type, o, float(attr[1])/100.0f, float(attr[2])/100.0f, attr[3], density, attr[4] > 0 ? attr[4] : fademap[attr[0]-14], attr[5] != 0 ? attr[5]/100.f : sizemap[attr[0]-14], 1, attr[6] != 0 ? attr[6] : gravmap[attr[0]-14], 0, attr[7] != 0 ? attr[7] : velmap[attr[0]-14]); break; } - case 6: //meter, metervs - - { - float length = clamp(attr[1], 0, 100)/100.f; - part_icon(o, textureload(hud::progresstex, 3), 2, 1, 0, 0, 1, partcolour(attr[3], attr[6], attr[7]), length, 1-length); // fall through + case 6 : {// meter, metervs - + float length = std::clamp(attr[1], 0, 100) / 100.f; + part_icon(o, textureload(hud::progresstex, 3), 2, 1, 0, 0, 1, partcolour(attr[3], attr[6], attr[7]), length, + 1 - length); + [[fallthrough]]; } - case 5: - { - float length = clamp(attr[1], 0, 100)/100.f; + case 5: { + float length = std::clamp(attr[1], 0, 100) / 100.f; int colour = partcolour(attr[2], attr[4], attr[5]); - part_icon(o, textureload(hud::progringtex, 3), 3, 1, 0, 0, 1, colour, (totalmillis%1000)/1000.f, 0.1f); + part_icon(o, textureload(hud::progringtex, 3), 3, 1, 0, 0, 1, colour, (totalmillis % 1000) / 1000.f, 0.1f); part_icon(o, textureload(hud::progresstex, 3), 3, 1, 0, 0, 1, colour, 0, length); - break; } + break; case 32: //lens flares - plain/sparkle/sun/sparklesun case 33: case 34: diff --git a/src/engine/rendersky.cpp b/src/engine/rendersky.cpp index b2a53637..ddd7b6af 100644 --- a/src/engine/rendersky.cpp +++ b/src/engine/rendersky.cpp @@ -188,7 +188,7 @@ void drawenvoverlay(int w, float height, int subdiv, float fade, float scale, Te loopi(subdiv+1) { vec p(1, 1, 0); - p.rotate_around_z((-2.0f*M_PI*i)/subdiv); + p.rotate_around_z((-2.0f*pi*i)/subdiv); gle::attribf(p.x*psz, p.y*psz, z); gle::attribf(tx + p.x*tsz, ty + p.y*tsz); } @@ -201,7 +201,7 @@ void drawenvoverlay(int w, float height, int subdiv, float fade, float scale, Te loopi(subdiv+1) { vec p(1, 1, 0); - p.rotate_around_z((-2.0f*M_PI*i)/subdiv); + p.rotate_around_z((-2.0f*pi*i)/subdiv); gle::attribf(p.x*psz, p.y*psz, z); gle::attribf(tx + p.x*tsz, ty + p.y*tsz); gle::attrib(color, a); @@ -540,7 +540,7 @@ void drawskybox(int farplane, bool limited) matrix4 skymatrix = cammatrix, skyprojmatrix; skymatrix.settranslation(0, 0, 0); - skymatrix.rotate_around_z((spinsky*lastmillis/1000.0f+yawsky)*-RAD); + skymatrix.rotate_around_z((spinsky*lastmillis/1000.0f+yawsky)*-rad); skyprojmatrix.mul(projmatrix, skymatrix); LOCALPARAM(skymatrix, skyprojmatrix); @@ -566,7 +566,7 @@ void drawskybox(int farplane, bool limited) matrix4 skymatrix = cammatrix, skyprojmatrix; skymatrix.settranslation(0, 0, 0); - skymatrix.rotate_around_z((spinclouds*lastmillis/1000.0f+yawclouds)*-RAD); + skymatrix.rotate_around_z((spinclouds*lastmillis/1000.0f+yawclouds)*-rad); skyprojmatrix.mul(projmatrix, skymatrix); LOCALPARAM(skymatrix, skyprojmatrix); @@ -587,7 +587,7 @@ void drawskybox(int farplane, bool limited) matrix4 skymatrix = cammatrix, skyprojmatrix; skymatrix.settranslation(0, 0, 0); - skymatrix.rotate_around_z((spincloudlayer*lastmillis/1000.0f+yawcloudlayer)*-RAD); + skymatrix.rotate_around_z((spincloudlayer*lastmillis/1000.0f+yawcloudlayer)*-rad); skyprojmatrix.mul(projmatrix, skymatrix); LOCALPARAM(skymatrix, skyprojmatrix); @@ -609,7 +609,7 @@ void drawskybox(int farplane, bool limited) matrix4 skymatrix = cammatrix, skyprojmatrix; skymatrix.settranslation(0, 0, 0); - skymatrix.rotate_around_z((spinenvlayer*lastmillis/1000.0f+yawenvlayer)*-RAD); + skymatrix.rotate_around_z((spinenvlayer*lastmillis/1000.0f+yawenvlayer)*-rad); skyprojmatrix.mul(projmatrix, skymatrix); LOCALPARAM(skymatrix, skyprojmatrix); diff --git a/src/engine/rendertext.cpp b/src/engine/rendertext.cpp index 678961f9..95fcd391 100644 --- a/src/engine/rendertext.cpp +++ b/src/engine/rendertext.cpp @@ -703,7 +703,7 @@ static const char *gettklp(const char *str) return t->blist.search(str, type, "", "", " ", " ", 5); } -#define defformatkey(dest, key) defformatbigstring((dest), "\fs\fa[\fS\fs\f[%d]%s\fS\fs\fa]\fS", textkeycolour, (key)) +#define defformatkey(dest, key) defformatbigstring(dest, "\fs\fa[\fS\fs\f[%d]%s\fS\fs\fa]\fS", textkeycolour, key) float key_widthf(const char *str) { @@ -823,7 +823,7 @@ int draw_text(const char *str, int rleft, int rtop, int r, int g, int b, int a, xtraverts += gle::end(); if(cursor >= 0) { - gle::colorub(255, 255, 255, int(clamp(1.f-(float(totalmillis%500)/500.f), 0.5f, 1.f)*255)); + gle::colorub(255, 255, 255, int(std::clamp(1.f-(float(totalmillis%500)/500.f), 0.5f, 1.f)*255)); draw_char(tex, '_', left+cx, top+cy, scale); xtraverts += gle::end(); } diff --git a/src/engine/renderva.cpp b/src/engine/renderva.cpp index a2bb531c..3145035f 100644 --- a/src/engine/renderva.cpp +++ b/src/engine/renderva.cpp @@ -90,7 +90,7 @@ static vtxarray *vasort[VASORTSIZE]; void addvisibleva(vtxarray *va) { float dist = vadist(va, camera1->o); - va->distance = int(dist); /*cv.dist(camera1->o) - va->size*SQRT3/2*/ + va->distance = int(dist); /*cv.dist(camera1->o) - va->size*sqrt3/2*/ int hash = min(int(dist*VASORTSIZE/hdr.worldsize), VASORTSIZE-1); vtxarray **prev = &vasort[hash], *cur = vasort[hash]; @@ -193,7 +193,8 @@ void visiblecubes(bool cull) } else { - memset(vfcP, 0, sizeof(vfcP)); + *vfcP = {}; + vfcDfog = 1000000; memset(vfcDnear, 0, sizeof(vfcDnear)); memset(vfcDfar, 0, sizeof(vfcDfar)); @@ -1338,11 +1339,10 @@ void renderzpass(renderstate &cur, vtxarray *va) if(cur.vbuf!=va->vbuf) changevbuf(cur, RENDERPASS_Z, va); if(!cur.depthmask) { cur.depthmask = true; glDepthMask(GL_TRUE); } if(cur.colormask) { cur.colormask = false; glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); } - int firsttex = 0, numtris = va->tris; + int numtris = va->tris; ushort *edata = va->edata; if(cur.alphaing) { - firsttex += va->texs + va->blends; edata += 3*(va->tris + va->blendtris); numtris = va->alphabacktris + va->alphafronttris; xtravertsva += 3*numtris; diff --git a/src/engine/scale.h b/src/engine/scale.h index e5566eda..736e7b37 100644 --- a/src/engine/scale.h +++ b/src/engine/scale.h @@ -50,8 +50,8 @@ static void FUNCNAME(scaletexture)(uchar * RESTRICT src, uint sw, uint sh, uint int over, under; for(over = 0; (darea>>over) > sarea; over++); for(under = 0; (darea< #include #ifdef WIN32 @@ -134,7 +135,7 @@ void addipinfo(vector &info, int type, const char *name, const char *rea ipinfo &p = info.add(); p.ip = ip.i; p.mask = mask.i; - p.type = clamp(type, 0, int(ipinfo::MAXTYPES)-1); + p.type = std::clamp(type, 0, int(ipinfo::MAXTYPES)-1); p.flag = ipinfo::LOCAL; p.time = totalmillis ? totalmillis : 1; #ifdef STANDALONE @@ -157,7 +158,7 @@ char *printipinfo(const ipinfo &info, char *buf) ip.i = info.ip; mask.i = info.mask; int lastdigit = -1; - str += sprintf(str, "[%s] ", ipinfotypes[clamp(info.type, 0, int(ipinfo::MAXTYPES)-1)]); + str += sprintf(str, "[%s] ", ipinfotypes[std::clamp(info.type, 0, int(ipinfo::MAXTYPES)-1)]); loopi(4) if(mask.b[i]) { if(lastdigit >= 0) *str++ = '.'; @@ -1884,7 +1885,7 @@ void shutdownsignal(int signum) } #ifdef STANDALONE -volatile int errors = 0; +std::atomic errors {0}; void fatal(const char *s, ...) // failure exit { if(++errors <= 2) // print up to one extra recursive error diff --git a/src/engine/serverbrowser.cpp b/src/engine/serverbrowser.cpp index 4e9bcfd8..51d3797b 100755 --- a/src/engine/serverbrowser.cpp +++ b/src/engine/serverbrowser.cpp @@ -355,7 +355,7 @@ void checkpings() if(!si && searchlan) si = newserver(NULL, addr.port-1, 1, NULL, NULL, NULL, NULL, addr.host); if(!si) continue; ucharbuf p(ping, len); - int millis = getint(p), rtt = clamp(totalmillis - millis, 0, min(serverdecay*1000, totalmillis)); + int millis = getint(p), rtt = std::clamp(totalmillis - millis, 0, min(serverdecay*1000, totalmillis)); if(millis >= lastreset && rtt < serverdecay*1000) si->addping(rtt, millis); si->lastinfo = totalmillis; si->numplayers = getint(p); diff --git a/src/engine/shader.cpp b/src/engine/shader.cpp index d49ef7a4..78e70afc 100644 --- a/src/engine/shader.cpp +++ b/src/engine/shader.cpp @@ -330,7 +330,7 @@ static void allocglslactiveuniforms(Shader &s) name[0] = '\0'; glGetActiveUniform_(s.program, i, sizeof(name)-1, &namelen, &size, &format, name); if(namelen <= 0 || size <= 0) continue; - name[clamp(int(namelen), 0, (int)sizeof(name)-2)] = '\0'; + name[std::clamp(int(namelen), 0, (int)sizeof(name)-2)] = '\0'; char *brak = strchr(name, '['); if(brak) *brak = '\0'; setglsluniformformat(s, name, format, size); @@ -1428,7 +1428,7 @@ ICOMMAND(0, addpostfx, "siisffff", (char *name, int *bind, int *scale, char *inp else if(*inputs=='-') freeinputs = true; inputmask &= (1<yaw*RAD); + skewdir.rotate_around_z(-camera1->yaw*rad); vec dir; vecfromyawpitch(camera1->yaw, camera1->pitch, 1, 0, dir); @@ -141,7 +141,7 @@ static struct shadowmaptexture : rendertarget shadowmatrix.ortho(-shadowmapradius, shadowmapradius, -shadowmapradius, shadowmapradius, -shadowmapdist, shadowmapdist); shadowmatrix.mul(matrix3(vec(1, 0, 0), vec(0, 1, 0), vec(skewdir.x, skewdir.y, 1))); shadowmatrix.translate(skewdir.x*shadowmapheight + shadowoffset.x, skewdir.y*shadowmapheight + shadowoffset.y + dir.magnitude(), -shadowmapheight); - shadowmatrix.rotate_around_z((camera1->yaw+180)*-RAD); + shadowmatrix.rotate_around_z((camera1->yaw+180)*-rad); shadowmatrix.translate(vec(camera1->o).neg()); GLOBALPARAM(shadowmatrix, shadowmatrix); @@ -203,13 +203,13 @@ void cleanshadowmap() void calcshadowmapbb(const vec &o, float xyrad, float zrad, float &x1, float &y1, float &x2, float &y2) { vec skewdir(shadowdir); - skewdir.rotate_around_z(-camera1->yaw*RAD); + skewdir.rotate_around_z(-camera1->yaw*rad); vec ro(o); ro.sub(camera1->o); - ro.rotate_around_z(-(camera1->yaw+180)*RAD); + ro.rotate_around_z(-(camera1->yaw+180)*rad); ro.x += ro.z * skewdir.x + shadowoffset.x; - ro.y += ro.z * skewdir.y + shadowmapradius * cosf(camera1->pitch*RAD) + shadowoffset.y; + ro.y += ro.z * skewdir.y + shadowmapradius * cosf(camera1->pitch*rad) + shadowoffset.y; vec high(ro), low(ro); high.x += zrad * skewdir.x; @@ -244,7 +244,7 @@ bool isshadowmapreceiver(vtxarray *va) if(va->shadowmapmax.z <= shadowfocus.z - shadowmapdist || va->shadowmapmin.z >= shadowmapmaxz) return false; - float xyrad = SQRT2*0.5f*max(va->shadowmapmax.x-va->shadowmapmin.x, va->shadowmapmax.y-va->shadowmapmin.y), + float xyrad = sqrt2*0.5f*max(va->shadowmapmax.x-va->shadowmapmin.x, va->shadowmapmax.y-va->shadowmapmin.y), zrad = 0.5f*(va->shadowmapmax.z-va->shadowmapmin.z), x1, y1, x2, y2; if(xyrad<0 || zrad<0) return false; diff --git a/src/engine/skelmodel.h b/src/engine/skelmodel.h index 2d27535f..10a085dc 100644 --- a/src/engine/skelmodel.h +++ b/src/engine/skelmodel.h @@ -813,9 +813,9 @@ struct skelmodel : animmodel vec forward1 = pose1.transformnormal(forward).project(axis).normalize(), forward2 = pose2.transformnormal(forward).project(axis).normalize(), daxis = vec().cross(forward1, forward2); - float dx = clamp(forward1.dot(forward2), -1.0f, 1.0f), dy = clamp(daxis.magnitude(), -1.0f, 1.0f); + float dx = std::clamp(forward1.dot(forward2), -1.0f, 1.0f), dy = std::clamp(daxis.magnitude(), -1.0f, 1.0f); if(daxis.dot(axis) < 0) dy = -dy; - return atan2f(dy, dx)/RAD; + return atan2f(dy, dx)/rad; } void calcpitchcorrects(float pitch, const vec &axis, const vec &forward) @@ -836,7 +836,7 @@ struct skelmodel : animmodel float tpitch = pitch - t.deviated; for(int parent = t.corrects; parent >= 0; parent = pitchcorrects[parent].parent) tpitch -= pitchcorrects[parent].pitchangle; - if(t.pitchmin || t.pitchmax) tpitch = clamp(tpitch, t.pitchmin, t.pitchmax); + if(t.pitchmin || t.pitchmax) tpitch = std::clamp(tpitch, t.pitchmin, t.pitchmax); loopv(pitchcorrects) { pitchcorrect &c = pitchcorrects[i]; @@ -846,11 +846,11 @@ struct skelmodel : animmodel used = tpitch*c.pitchscale; if(c.pitchmin || c.pitchmax) { - if(used < 0) used = clamp(c.pitchmin, used, 0.0f); - else used = clamp(c.pitchmax, 0.0f, used); + if(used < 0) used = std::clamp(c.pitchmin, used, 0.0f); + else used = std::clamp(c.pitchmax, 0.0f, used); } - if(used < 0) used = clamp(avail, used, 0.0f); - else used = clamp(avail, 0.0f, used); + if(used < 0) used = std::clamp(avail, used, 0.0f); + else used = std::clamp(avail, 0.0f, used); c.pitchangle = used; c.pitchtotal = used + total; } @@ -904,12 +904,12 @@ struct skelmodel : animmodel if(b.interpparent<0) sc.bdata[b.interpindex] = d; else sc.bdata[b.interpindex].mul(sc.bdata[b.interpparent], d); float angle; - if(b.pitchscale) { angle = b.pitchscale*pitch + b.pitchoffset; if(b.pitchmin || b.pitchmax) angle = clamp(angle, b.pitchmin, b.pitchmax); } + if(b.pitchscale) { angle = b.pitchscale*pitch + b.pitchoffset; if(b.pitchmin || b.pitchmax) angle = std::clamp(angle, b.pitchmin, b.pitchmax); } else if(b.correctindex >= 0) angle = pitchcorrects[b.correctindex].pitchangle; else continue; if(as->cur.anim&ANIM_NOPITCH || (as->interp < 1 && as->prev.anim&ANIM_NOPITCH)) angle *= (as->cur.anim&ANIM_NOPITCH ? 0 : as->interp) + (as->interp < 1 && as->prev.anim&ANIM_NOPITCH ? 0 : 1-as->interp); - sc.bdata[b.interpindex].mulorient(quat(axis, angle*RAD), b.base); + sc.bdata[b.interpindex].mulorient(quat(axis, angle*rad), b.base); } loopv(antipodes) sc.bdata[antipodes[i].child].fixantipodal(sc.bdata[antipodes[i].parent]); } @@ -1619,9 +1619,9 @@ struct skeladjustment void adjust(dualquat &dq) { - if(yaw) dq.mulorient(quat(vec(0, 0, 1), yaw*RAD)); - if(pitch) dq.mulorient(quat(vec(0, -1, 0), pitch*RAD)); - if(roll) dq.mulorient(quat(vec(-1, 0, 0), roll*RAD)); + if(yaw) dq.mulorient(quat(vec(0, 0, 1), yaw*rad)); + if(pitch) dq.mulorient(quat(vec(0, -1, 0), pitch*rad)); + if(roll) dq.mulorient(quat(vec(-1, 0, 0), roll*rad)); if(!translate.iszero()) dq.translate(translate); } }; @@ -1653,7 +1653,7 @@ template struct skelcommands : modelcommandsaddpart(); mdl.pitchscale = mdl.pitchoffset = mdl.pitchmin = mdl.pitchmax = 0; MDL::adjustments.setsize(0); - mdl.meshes = MDL::loading->sharemeshes(path(filename), skelname[0] ? skelname : NULL, double(*smooth > 0 ? cos(clamp(*smooth, 0.0f, 180.0f)*RAD) : 2)); + mdl.meshes = MDL::loading->sharemeshes(path(filename), skelname[0] ? skelname : NULL, double(*smooth > 0 ? cos(std::clamp(*smooth, 0.0f, 180.0f)*rad) : 2)); if(!mdl.meshes) conoutf("\frcould not load %s", filename); else { @@ -1669,9 +1669,9 @@ template struct skelcommands : modelcommandsskel->findbone(name) : -1; if(i >= 0) { - float cx = *rx ? cosf(*rx/2*RAD) : 1, sx = *rx ? sinf(*rx/2*RAD) : 0, - cy = *ry ? cosf(*ry/2*RAD) : 1, sy = *ry ? sinf(*ry/2*RAD) : 0, - cz = *rz ? cosf(*rz/2*RAD) : 1, sz = *rz ? sinf(*rz/2*RAD) : 0; + float cx = *rx ? cosf(*rx/2*rad) : 1, sx = *rx ? sinf(*rx/2*rad) : 0, + cy = *ry ? cosf(*ry/2*rad) : 1, sy = *ry ? sinf(*ry/2*rad) : 0, + cz = *rz ? cosf(*rz/2*rad) : 1, sz = *rz ? sinf(*rz/2*rad) : 0; matrix4x3 m(matrix3(quat(sx*cy*cz - cx*sy*sz, cx*sy*cz + sx*cy*sz, cx*cy*sz - sx*sy*cz, cx*cy*cz + sx*sy*sz)), vec(*tx, *ty, *tz)); ((meshgroup *)mdl.meshes)->skel->addtag(tagname, i, m); @@ -1741,7 +1741,7 @@ template struct skelcommands : modelcommandspitchtargets) if(skel->pitchtargets[i].bone == bone) return; pitchtarget &t = skel->pitchtargets.add(); t.bone = bone; - t.frame = sa->frame + clamp(*frameoffset, 0, sa->range-1); + t.frame = sa->frame + std::clamp(*frameoffset, 0, sa->range-1); t.pitchmin = *pitchmin; t.pitchmax = *pitchmax; } diff --git a/src/engine/sound.cpp b/src/engine/sound.cpp index acf17bf4..6f5f5ec7 100644 --- a/src/engine/sound.cpp +++ b/src/engine/sound.cpp @@ -399,12 +399,12 @@ void calcvol(int flags, int vol, int slotvol, int maxrad, int minrad, const vec { vec v; float dist = pos.dist(camera1->o, v); - int svol = flags&SND_CLAMPED ? 255 : clamp(vol, 0, 255), span = 127; + int svol = flags&SND_CLAMPED ? 255 : std::clamp(vol, 0, 255), span = 127; if(!(flags&SND_NOATTEN) && dist > 0) { if(!(flags&SND_NOPAN) && !soundmono && (v.x != 0 || v.y != 0)) { - v.rotate_around_z(-camera1->yaw*RAD); + v.rotate_around_z(-camera1->yaw*rad); span = int(255.9f*(0.5f - 0.5f*v.x/v.magnitude2())); // range is from 0 (left) to 255 (right) } if(!(flags&SND_NODIST)) @@ -419,8 +419,8 @@ void calcvol(int flags, int vol, int slotvol, int maxrad, int minrad, const vec } } if(!(flags&SND_NOQUIET) && svol > 0 && liquid) svol = int(svol*0.65f); - if(flags&SND_CLAMPED) svol = max(svol, clamp(vol, 0, 255)); - *curvol = clamp(int((mastervol/255.f)*(soundvol/255.f)*(slotvol/255.f)*(svol/255.f)*MIX_MAX_VOLUME*(flags&SND_MAP ? soundenvvol : soundevtvol)), 0, MIX_MAX_VOLUME); + if(flags&SND_CLAMPED) svol = max(svol, std::clamp(vol, 0, 255)); + *curvol = std::clamp(int((mastervol/255.f)*(soundvol/255.f)*(slotvol/255.f)*(svol/255.f)*MIX_MAX_VOLUME*(flags&SND_MAP ? soundenvvol : soundevtvol)), 0, MIX_MAX_VOLUME); *curpan = span; } @@ -560,7 +560,7 @@ int playsound(int n, const vec &pos, physent *d, int flags, int vol, int maxrad, oldhook = NULL; vec o = d ? game::camerapos(d) : pos; - int cvol = 0, cpan = 0, v = clamp(vol >= 0 ? vol : 255, flags&SND_CLAMPED ? 64 : 0, 255), + int cvol = 0, cpan = 0, v = std::clamp(vol >= 0 ? vol : 255, flags&SND_CLAMPED ? 64 : 0, 255), x = maxrad > 0 ? maxrad : (flags&SND_CLAMPED ? getworldsize() : (slot->maxrad > 0 ? slot->maxrad : soundmaxrad)), y = minrad >= 0 ? minrad : (flags&SND_CLAMPED ? 32 : (slot->minrad >= 0 ? slot->minrad : soundminrad)), mat = lookupmaterial(o); @@ -791,8 +791,8 @@ void updatemumble() mumbleinfo->timestamp = ++timestamp; mumbleinfo->pos = mumblevec(camera1->o, true); - mumbleinfo->front = mumblevec(vec(RAD*camera1->yaw, RAD*camera1->pitch)); - mumbleinfo->top = mumblevec(vec(RAD*camera1->yaw, RAD*(camera1->pitch+90))); + mumbleinfo->front = mumblevec(vec(rad*camera1->yaw, rad*camera1->pitch)); + mumbleinfo->top = mumblevec(vec(rad*camera1->yaw, rad*(camera1->pitch+90))); #endif } diff --git a/src/engine/textedit.h b/src/engine/textedit.h index 3a133ea4..046a1cc2 100755 --- a/src/engine/textedit.h +++ b/src/engine/textedit.h @@ -113,14 +113,14 @@ struct editline void chop(int newlen) { if(!text) return; - len = clamp(newlen, 0, len); + len = std::clamp(newlen, 0, len); text[len] = '\0'; } void insert(char *str, int start, int count = 0) { if(count <= 0) count = strlen(str); - start = clamp(start, 0, len); + start = std::clamp(start, 0, len); grow(len + count, "%s", text ? text : ""); memmove(&text[start + count], &text[start], len - start + 1); memcpy(&text[start], str, count); diff --git a/src/engine/texture.cpp b/src/engine/texture.cpp index aa900143..287f4a70 100644 --- a/src/engine/texture.cpp +++ b/src/engine/texture.cpp @@ -444,7 +444,7 @@ void texmad(ImageData &s, const vec &mul, const vec &add) swizzleimage(s); int maxk = min(int(s.bpp), 3); writetex(s, - loopk(maxk) dst[k] = uchar(clamp(dst[k]*mul[k] + 255*add[k], 0.0f, 255.0f)); + loopk(maxk) dst[k] = uchar(std::clamp(dst[k]*mul[k] + 255*add[k], 0.0f, 255.0f)); ); } @@ -454,7 +454,7 @@ void texcolorify(ImageData &s, const vec &color, vec weights) if(weights.iszero()) weights = vec(0.21f, 0.72f, 0.07f); writetex(s, float lum = dst[0]*weights.x + dst[1]*weights.y + dst[2]*weights.z; - loopk(3) dst[k] = uchar(clamp(lum*color[k], 0.0f, 255.0f)); + loopk(3) dst[k] = uchar(std::clamp(lum*color[k], 0.0f, 255.0f)); ); } @@ -465,7 +465,7 @@ void texcolormask(ImageData &s, const vec &color1, const vec &color2) readwritetex(d, s, vec color; color.lerp(color2, color1, src[3]/255.0f); - loopk(3) dst[k] = uchar(clamp(color[k]*src[k], 0.0f, 255.0f)); + loopk(3) dst[k] = uchar(std::clamp(color[k]*src[k], 0.0f, 255.0f)); ); s.replace(d); } @@ -481,15 +481,21 @@ void texmix(ImageData &s, int c1, int c2, int c3, int c4) int numchans = c1 < 0 ? 0 : (c2 < 0 ? 1 : (c3 < 0 ? 2 : (c4 < 0 ? 3 : 4))); if(numchans <= 0) return; ImageData d(s.w, s.h, numchans); - readwritetex(d, s, - switch(numchans) - { - case 4: dst[3] = src[c4]; - case 3: dst[2] = src[c3]; - case 2: dst[1] = src[c2]; - case 1: dst[0] = src[c1]; - } - ); + readwritetex( + d, s, switch (numchans) { + case 4: + dst[3] = src[c4]; + [[fallthrough]]; + case 3: + dst[2] = src[c3]; + [[fallthrough]]; + case 2: + dst[1] = src[c2]; + [[fallthrough]]; + case 1: + dst[0] = src[c1]; + break; + }); s.replace(d); } @@ -555,7 +561,7 @@ void texagrad(ImageData &s, float x2, float y2, float x1, float y1) float curx = minx; for(uchar *dst = dstrow, *end = &dstrow[s.w*s.bpp]; dst < end; dst += s.bpp) { - dst[0] = uchar(dst[0]*clamp(curx, 0.0f, 1.0f)*clamp(cury, 0.0f, 1.0f)); + dst[0] = uchar(dst[0]*std::clamp(curx, 0.0f, 1.0f)*std::clamp(cury, 0.0f, 1.0f)); curx += dx; } cury += dy; @@ -1282,7 +1288,7 @@ static void blurtexture(int w, int h, uchar *dst, const uchar *src, int margin) void blurtexture(int n, int bpp, int w, int h, uchar *dst, const uchar *src, int margin) { - switch((clamp(n, 1, 2)<<4) | bpp) + switch((std::clamp(n, 1, 2)<<4) | bpp) { case 0x13: blurtexture<1, 3, false>(w, h, dst, src, margin); break; case 0x23: blurtexture<2, 3, false>(w, h, dst, src, margin); break; @@ -1293,7 +1299,7 @@ void blurtexture(int n, int bpp, int w, int h, uchar *dst, const uchar *src, int void blurnormals(int n, int w, int h, bvec *dst, const bvec *src, int margin) { - switch(clamp(n, 1, 2)) + switch(std::clamp(n, 1, 2)) { case 1: blurtexture<1, 3, true>(w, h, dst->v, src->v, margin); break; case 2: blurtexture<2, 3, true>(w, h, dst->v, src->v, margin); break; @@ -1418,7 +1424,7 @@ static bool texturedata(ImageData &d, const char *tname, Slot::Tex *tex = NULL, else if(matchstring(cmd, len, "blur")) { int emphasis = atoi(arg[0]), repeat = atoi(arg[1]); - texblur(d, emphasis > 0 ? clamp(emphasis, 1, 2) : 1, repeat > 0 ? repeat : 1); + texblur(d, emphasis > 0 ? std::clamp(emphasis, 1, 2) : 1, repeat > 0 ? repeat : 1); } 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])); @@ -1530,7 +1536,7 @@ VSlot dummyvslot(&dummyslot); void resettextures(int n) { resetslotshader(); - int limit = clamp(n, 0, slots.length()); + int limit = std::clamp(n, 0, slots.length()); for(int i = limit; i < slots.length(); i++) { Slot *s = slots[i]; @@ -1786,11 +1792,11 @@ static void mergevslot(VSlot &dst, const VSlot &src, int diff, Slot *slot = NULL } if(diff & (1<= 0 ? materialslots[matslot] : *emptyvslot(s); vs.reset(); - vs.rotation = clamp(*rot, 0, 5); + vs.rotation = std::clamp(*rot, 0, 5); vs.offset = ivec2(*xoffset, *yoffset).max(0); vs.scale = *scale <= 0 ? 1 : *scale; propagatevslot(&vs, (1<rotation = clamp(*rot, 0, 5); + s.variants->rotation = std::clamp(*rot, 0, 5); propagatevslot(s.variants, 1<alphafront = clamp(*front, 0.0f, 1.0f); - s.variants->alphaback = clamp(*back, 0.0f, 1.0f); + s.variants->alphafront = std::clamp(*front, 0.0f, 1.0f); + s.variants->alphaback = std::clamp(*back, 0.0f, 1.0f); propagatevslot(s.variants, 1<coastscale = clamp(*value, 0.f, 1000.f); + s.variants->coastscale = std::clamp(*value, 0.f, 1000.f); propagatevslot(s.variants, 1< key; addname(key, s, t); - int texmask = 0; if(!forceload) switch(t.type) { case TEX_DIFFUSE: @@ -2346,7 +2351,6 @@ static void texcombine(Slot &s, int index, Slot::Tex &t, bool forceload = false) { int i = findtextype(s, t.type==TEX_DIFFUSE ? (1<mode == EDITORREADONLY) return false; @@ -1357,7 +1371,10 @@ namespace UI return e->mode != EDITORFOREVER; case SDLK_RETURN: case SDLK_TAB: - if(e->maxy != 1) break; + if(e->maxy != 1) { + break; + } + [[fallthrough]]; case SDLK_KP_ENTER: if(isdown) fieldmode = FIELDCOMMIT; //signal field commit (handled when drawing field) return true; diff --git a/src/engine/vertmodel.h b/src/engine/vertmodel.h index e759978c..aedc267a 100644 --- a/src/engine/vertmodel.h +++ b/src/engine/vertmodel.h @@ -445,7 +445,7 @@ template struct vertcommands : modelcommandsaddpart(); if(mdl.index) mdl.pitchscale = mdl.pitchoffset = mdl.pitchmin = mdl.pitchmax = 0; - mdl.meshes = MDL::loading->sharemeshes(path(filename), double(*smooth > 0 ? cos(clamp(*smooth, 0.0f, 180.0f)*RAD) : 2)); + mdl.meshes = MDL::loading->sharemeshes(path(filename), double(*smooth > 0 ? cos(std::clamp(*smooth, 0.0f, 180.0f)*rad) : 2)); if(!mdl.meshes) conoutf("\frcould not load %s", filename); else mdl.initskins(); } diff --git a/src/engine/water.cpp b/src/engine/water.cpp index 0e34e401..b59506a8 100644 --- a/src/engine/water.cpp +++ b/src/engine/water.cpp @@ -95,7 +95,7 @@ void rendervertwater(int subdiv, int xo, int yo, int z, int size, int mat) wx2 = wx1 + size, wy2 = wy1 + size; wsize = size; - whscale = 59.0f/(23.0f*wsize*wsize)/(2*M_PI); + whscale = 59.0f/(23.0f*wsize*wsize)/(2*pi); ASSERT((wx1 & (subdiv - 1)) == 0); ASSERT((wy1 & (subdiv - 1)) == 0); @@ -104,14 +104,14 @@ void rendervertwater(int subdiv, int xo, int yo, int z, int size, int mat) { case MAT_WATER: { - whoffset = fmod(float(lastmillis/600.0f/(2*M_PI)), 1.0f); + whoffset = fmod(float(lastmillis/600.0f/(2*pi)), 1.0f); renderwaterstrips(vertwt, z); break; } case MAT_LAVA: { - whoffset = fmod(float(lastmillis/2000.0f/(2*M_PI)), 1.0f); + whoffset = fmod(float(lastmillis/2000.0f/(2*pi)), 1.0f); renderwaterstrips(vertl, z); break; } @@ -885,10 +885,10 @@ static bool calcscissorbox(Reflection &ref, int size, vec &clipmin, vec &clipmax sy2 = min(sy2, 1.0f); if(reflectvfc) { - clipmin.x = clamp(clipmin.x, sx1, sx2); - clipmin.y = clamp(clipmin.y, sy1, sy2); - clipmax.x = clamp(clipmax.x, sx1, sx2); - clipmax.y = clamp(clipmax.y, sy1, sy2); + clipmin.x = std::clamp(clipmin.x, sx1, sx2); + clipmin.y = std::clamp(clipmin.y, sy1, sy2); + clipmax.x = std::clamp(clipmax.x, sx1, sx2); + clipmax.y = std::clamp(clipmax.y, sy1, sy2); } sx = int(floor((sx1+1)*0.5f*size)); sy = int(floor((sy1+1)*0.5f*size)); diff --git a/src/engine/world.cpp b/src/engine/world.cpp index 59b26e17..83d818d6 100644 --- a/src/engine/world.cpp +++ b/src/engine/world.cpp @@ -51,8 +51,8 @@ bool getentboundingbox(const extentity &e, ivec &o, ivec &r) radius.max(entselradius); o = ivec(vec(center).sub(radius)); r = ivec(vec(center).add(radius).add(1)); - break; } + break; } // invisible mapmodels use entselradius default: @@ -85,8 +85,7 @@ void modifyoctaentity(int flags, int id, extentity &e, cube *c, const ivec &cor, switch(e.type) { case ET_MAPMODEL: - if(loadmapmodel(e.attrs[0])) - { + if (loadmapmodel(e.attrs[0])) { if(va) { va->bbmin.x = -1; @@ -95,8 +94,8 @@ void modifyoctaentity(int flags, int id, extentity &e, cube *c, const ivec &cor, oe.mapmodels.add(id); oe.bbmin.min(bo).max(oe.o); oe.bbmax.max(br).min(ivec(oe.o).add(oe.size)); - break; } + break; // invisible mapmodel default: oe.other.add(id); @@ -110,8 +109,7 @@ void modifyoctaentity(int flags, int id, extentity &e, cube *c, const ivec &cor, switch(e.type) { case ET_MAPMODEL: - if(loadmapmodel(e.attrs[0])) - { + if (loadmapmodel(e.attrs[0])) { oe.mapmodels.removeobj(id); if(va) { @@ -132,8 +130,8 @@ void modifyoctaentity(int flags, int id, extentity &e, cube *c, const ivec &cor, } oe.bbmin.max(oe.o); oe.bbmax.min(ivec(oe.o).add(oe.size)); - break; } + break; // invisible mapmodel default: oe.other.removeobj(id); @@ -542,7 +540,7 @@ void renderentselection(const vec &o, const vec &ray, bool entmoving) } gle::colorub(150,0,0); boxs(entorient, eo, es); - boxs(entorient, eo, es, clamp(0.015f*camera1->o.dist(eo)*tan(fovy*0.5f*RAD), 0.1f, 1.0f)); + boxs(entorient, eo, es, std::clamp(0.015f*camera1->o.dist(eo)*tan(fovy*0.5f*rad), 0.1f, 1.0f)); } } @@ -872,7 +870,7 @@ void entset(char *what, char *attr) entattrs(attr, attrs); groupedit({ e.type = type; - e.attrs.add(0, clamp(attrs.length(), entities::numattrs(e.type), MAXENTATTRS) - e.attrs.length()); + e.attrs.add(0, std::clamp(attrs.length(), entities::numattrs(e.type), MAXENTATTRS) - e.attrs.length()); loopk(min(attrs.length(), e.attrs.length())) e.attrs[k] = attrs[k]; }); } diff --git a/src/engine/worldio.cpp b/src/engine/worldio.cpp index b89a93af..e0d32d4b 100644 --- a/src/engine/worldio.cpp +++ b/src/engine/worldio.cpp @@ -347,8 +347,8 @@ void convertoldsurfaces(cube &c, const ivec &co, int size, surfacecompat *srcsur { float u = src->x + (src->texcoords[k*2] / 255.0f) * (src->w - 1), v = src->y + (src->texcoords[k*2+1] / 255.0f) * (src->h - 1); - dv.u = ushort(floor(clamp((u) * float(USHRT_MAX+1)/LM_PACKW + 0.5f, 0.0f, float(USHRT_MAX)))); - dv.v = ushort(floor(clamp((v) * float(USHRT_MAX+1)/LM_PACKH + 0.5f, 0.0f, float(USHRT_MAX)))); + dv.u = ushort(floor(std::clamp((u) * float(USHRT_MAX+1)/LM_PACKW + 0.5f, 0.0f, float(USHRT_MAX)))); + dv.v = ushort(floor(std::clamp((v) * float(USHRT_MAX+1)/LM_PACKH + 0.5f, 0.0f, float(USHRT_MAX)))); } else dv.u = dv.v = 0; dv.norm = usenorms && normals[i].normals[k] != bvec(128, 128, 128) ? encodenormal(normals[i].normals[k].tonormal().normalize()) : 0; @@ -361,8 +361,8 @@ void convertoldsurfaces(cube &c, const ivec &co, int size, surfacecompat *srcsur if(k > 0 && (pos[k] == pos[0] || pos[k] == pos[k-1])) continue; vertinfo &bv = verts[totalverts++]; bv.setxyz(pos[k]); - bv.u = ushort(floor(clamp((blend->x + (blend->texcoords[k*2] / 255.0f) * (blend->w - 1)) * float(USHRT_MAX+1)/LM_PACKW, 0.0f, float(USHRT_MAX)))); - bv.v = ushort(floor(clamp((blend->y + (blend->texcoords[k*2+1] / 255.0f) * (blend->h - 1)) * float(USHRT_MAX+1)/LM_PACKH, 0.0f, float(USHRT_MAX)))); + bv.u = ushort(floor(std::clamp((blend->x + (blend->texcoords[k*2] / 255.0f) * (blend->w - 1)) * float(USHRT_MAX+1)/LM_PACKW, 0.0f, float(USHRT_MAX)))); + bv.v = ushort(floor(std::clamp((blend->y + (blend->texcoords[k*2+1] / 255.0f) * (blend->h - 1)) * float(USHRT_MAX+1)/LM_PACKH, 0.0f, float(USHRT_MAX)))); bv.norm = usenorms && normals[i].normals[k] != bvec(128, 128, 128) ? encodenormal(normals[i].normals[k].tonormal().normalize()) : 0; } } @@ -1607,7 +1607,7 @@ bool load_world(const char *mname, int crc) // still supports all map form f->read(&e, sizeof(entbase)); lilswap(&e.o.x, 3); int numattr = f->getlil(); - e.attrs.add(0, clamp(numattr, entities::numattrs(e.type), MAXENTATTRS)); + e.attrs.add(0, std::clamp(numattr, entities::numattrs(e.type), MAXENTATTRS)); loopk(numattr) { int val = f->getlil(); diff --git a/src/game/ai.cpp b/src/game/ai.cpp index 17b63e83..69190d7e 100644 --- a/src/game/ai.cpp +++ b/src/game/ai.cpp @@ -30,8 +30,8 @@ namespace ai showwaypoints = dropwaypoints = 0; } - float viewdist(int x) { return x <= 100 ? clamp((SIGHTMIN+(SIGHTMAX-SIGHTMIN))/100.f*float(x), float(SIGHTMIN), max(float(fog), SIGHTMIN)) : max(float(fog), SIGHTMIN); } - float viewfieldx(int x) { return x <= 100 ? clamp((VIEWMIN+(VIEWMAX-VIEWMIN))/100.f*float(x), float(VIEWMIN), float(VIEWMAX)) : float(VIEWMAX); } + float viewdist(int x) { return x <= 100 ? std::clamp((SIGHTMIN+(SIGHTMAX-SIGHTMIN))/100.f*float(x), float(SIGHTMIN), max(float(fog), SIGHTMIN)) : max(float(fog), SIGHTMIN); } + float viewfieldx(int x) { return x <= 100 ? std::clamp((VIEWMIN+(VIEWMAX-VIEWMIN))/100.f*float(x), float(VIEWMIN), float(VIEWMAX)) : float(VIEWMAX); } float viewfieldy(int x) { return viewfieldx(x)*3.f/4.f; } float weapmindist(int weap, bool alt) @@ -121,7 +121,7 @@ namespace ai if(insight && weaprange(d, d->weapselect, alt, e->o.squaredist(d->o))) { if(W2(d->weapselect, aidist, alt) < CLOSEDIST) return true; - float skew = clamp(float(lastmillis-d->ai->enemymillis)/float((d->skill*W(d->weapselect, delayreload)/5000.f)+(d->skill*W2(d->weapselect, delayattack, alt)/500.f)), 0.f, weaptype[d->weapselect].thrown[0] ? 0.25f : 1e16f), + float skew = std::clamp(float(lastmillis-d->ai->enemymillis)/float((d->skill*W(d->weapselect, delayreload)/5000.f)+(d->skill*W2(d->weapselect, delayattack, alt)/500.f)), 0.f, weaptype[d->weapselect].thrown[0] ? 0.25f : 1e16f), offy = yaw-d->yaw, offp = pitch-d->pitch; if(offy > 180) offy -= 360; else if(offy < -180) offy += 360; @@ -138,7 +138,7 @@ namespace ai if(lastmillis >= d->ai->lastaimrnd) { int radius = ceilf(e->radius*W2(d->weapselect, aiskew, alt)); - float speed = clamp(e->vel.magnitude()/movespeed, 0.f, 1.f), scale = speed+((1-speed)*((101-d->skill)/100.f)); + float speed = std::clamp(e->vel.magnitude()/movespeed, 0.f, 1.f), scale = speed+((1-speed)*((101-d->skill)/100.f)); loopk(3) d->ai->aimrnd[k] = (rnd((radius*2)+1)-radius)*scale; int dur = (d->skill+10)*10; d->ai->lastaimrnd = lastmillis+dur+rnd(dur); @@ -150,7 +150,10 @@ namespace ai int weappref(gameent *d) { - if(d->loadweap.length()) return d->loadweap[0]; + if (!d->loadweap.empty()) { + return d->loadweap.front(); + } + return m_weapon(d->actortype, game::gamemode, game::mutators); } @@ -229,8 +232,8 @@ namespace ai if((d->actortype = at) >= A_ENEMY) d->type = ENT_AI; else { - d->loadweap.shrink(0); - loopv(lweaps) d->loadweap.add(lweaps[i]); + d->loadweap.clear(); + loopv(lweaps) d->loadweap.emplace_back(lweaps[i]); } d->setname(name); d->spawnpoint = et; @@ -992,12 +995,16 @@ namespace ai { if(!n) { - switch(wpspot(d, d->ai->route[n], true)) - { - case 2: d->ai->clear(false); - case 1: return true; // not close enough to pop it yet - case 0: default: break; - } + switch (wpspot(d, d->ai->route[n], true)) { + case 2: + d->ai->clear(false); + break; + case 1: + return true; // not close enough to pop it yet + break; + default: + break; + } } else { @@ -1218,7 +1225,7 @@ namespace ai float yaw = d->ai->targyaw-d->yaw; while(yaw < 0.0f) yaw += 360.0f; while(yaw >= 360.0f) yaw -= 360.0f; - const aimdir &ad = aimdirs[clamp(((int)floor((yaw+22.5f)/45.0f))&7, 0, 7)]; + const aimdir &ad = aimdirs[std::clamp(((int)floor((yaw+22.5f)/45.0f))&7, 0, 7)]; d->move = ad.move; d->strafe = ad.strafe; } diff --git a/src/game/aiman.h b/src/game/aiman.h index 3b219639..12f66425 100644 --- a/src/game/aiman.h +++ b/src/game/aiman.h @@ -141,9 +141,9 @@ namespace aiman int s = skill, n = 1, m = 100; getskillrange(type, n, m); if(skill > m || skill < n) s = (m != n ? botrnd(ci, 2, m-n) + n + 1 : m); - ci->skill = clamp(s, 1, 101); + ci->skill = std::clamp(s, 1, 101); copystring(ci->name, AA(ci->actortype, vname), MAXNAMELEN); - ci->loadweap.shrink(0); + ci->loadweap.clear(); if(ci->actortype == A_BOT) { const char *list = ci->model ? G(botfemalenames) : G(botmalenames); @@ -159,7 +159,7 @@ namespace aiman } } ci->setvanity(ci->model ? G(botfemalevanities) : G(botmalevanities)); - ci->loadweap.add(botrnd(ci, 8, W_LOADOUT)+W_OFFSET); + ci->loadweap.emplace_back(botrnd(ci, 8, W_LOADOUT)+W_OFFSET); } ci->state = CS_DEAD; ci->team = type == A_BOT ? T_NEUTRAL : T_ENEMY; @@ -214,7 +214,7 @@ namespace aiman else if(ci->aireinit >= 1) { if(ci->aireinit == 2) loopk(W_MAX) loopj(2) ci->weapshots[k][j].reset(); - sendf(-1, 1, "ri6si3siv", N_INITAI, ci->clientnum, ci->ownernum, ci->actortype, ci->spawnpoint, ci->skill, ci->name, ci->team, ci->colour, ci->model, ci->vanity, ci->loadweap.length(), ci->loadweap.length(), ci->loadweap.getbuf()); + sendf(-1, 1, "ri6si3siv", N_INITAI, ci->clientnum, ci->ownernum, ci->actortype, ci->spawnpoint, ci->skill, ci->name, ci->team, ci->colour, ci->model, ci->vanity, ci->loadweap.size(), ci->loadweap.size(), ci->loadweap.data()); if(ci->aireinit == 2) { waiting(ci, DROP_RESET); diff --git a/src/game/bomber.cpp b/src/game/bomber.cpp index 6f897e14..85e0f064 100644 --- a/src/game/bomber.cpp +++ b/src/game/bomber.cpp @@ -80,7 +80,7 @@ namespace bomber if(carryaffinity(d) && (d->action[AC_AFFINITY] || d->actiontime[AC_AFFINITY] > 0)) { if(d->action[AC_AFFINITY]) return true; - vec o = d->headpos(), inertia = vec(d->yaw*RAD, d->pitch*RAD).mul(bomberspeed).add(vec(d->vel).add(d->falling).mul(bomberrelativity)); + vec o = d->headpos(), inertia = vec(d->yaw*rad, d->pitch*rad).mul(bomberspeed).add(vec(d->vel).add(d->falling).mul(bomberrelativity)); bool guided = m_team(game::gamemode, game::mutators) && bomberlockondelay && lastmillis-d->actiontime[AC_AFFINITY] >= bomberlockondelay; client::addmsg(N_DROPAFFIN, "ri8", d->clientnum, guided ? findtarget(d) : -1, int(o.x*DMF), int(o.y*DMF), int(o.z*DMF), int(inertia.x*DMF), int(inertia.y*DMF), int(inertia.z*DMF)); d->action[AC_AFFINITY] = false; @@ -117,7 +117,7 @@ namespace bomber if(!f.owner && !f.droptime) { int millis = lastmillis-f.displaytime; - if(millis < 1000) size *= 1.f+(1-clamp(float(millis)/1000.f, 0.f, 1.f)); + if(millis < 1000) size *= 1.f+(1-std::clamp(float(millis)/1000.f, 0.f, 1.f)); } } else if(!m_bb_hold(game::gamemode, game::mutators)) @@ -196,7 +196,7 @@ namespace bomber bomberstate::flag &f = st.flags[i]; if(f.owner == game::focus) { - ty -= draw_textf("You are holding the \fs\f[%d]\f(%s)bomb\fS", tx, ty, int(FONTW*hud::eventpadx), int(FONTH*hud::eventpady), tr, tg, tb, int(255*blend), TEXT_SKIN|TEXT_CENTERED, -1, -1, 1, pulsecols[PULSE_DISCO][clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)], hud::bombtex); + ty -= draw_textf("You are holding the \fs\f[%d]\f(%s)bomb\fS", tx, ty, int(FONTW*hud::eventpadx), int(FONTH*hud::eventpady), tr, tg, tb, int(255*blend), TEXT_SKIN|TEXT_CENTERED, -1, -1, 1, pulsecols[PULSE_DISCO][std::clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)], hud::bombtex); ty -= FONTH/4; break; } @@ -215,7 +215,7 @@ namespace bomber if(!f.enabled) continue; int millis = lastmillis-f.displaytime; vec colour = pulsecolour(); - float skew = hud::inventoryskew, wait = f.droptime ? clamp((lastmillis-f.droptime)/float(bomberresetdelay), 0.f, 1.f) : (f.owner ? clamp((lastmillis-f.taketime)/float(carrytime), 0.f, 1.f) : 1.f); + float skew = hud::inventoryskew, wait = f.droptime ? std::clamp((lastmillis-f.droptime)/float(bomberresetdelay), 0.f, 1.f) : (f.owner ? std::clamp((lastmillis-f.taketime)/float(carrytime), 0.f, 1.f) : 1.f); if(gs_playing(game::gamestate) && (f.droptime || (f.owner && carrytime)) && wait > 0.5f) { int delay = wait > 0.7f ? (wait > 0.85f ? 150 : 300) : 600, millis = lastmillis%(delay*2); @@ -226,13 +226,13 @@ namespace bomber { if(f.owner == game::focus) { - if(millis <= 1000) skew += (1.f-skew)*clamp(float(millis)/1000.f, 0.f, 1.f); + if(millis <= 1000) skew += (1.f-skew)*std::clamp(float(millis)/1000.f, 0.f, 1.f); else skew = 1; // override it } - else if(millis <= 1000) skew += ((1.f-skew)*clamp(float(millis)/1000.f, 0.f, 1.f)); + else if(millis <= 1000) skew += ((1.f-skew)*std::clamp(float(millis)/1000.f, 0.f, 1.f)); else skew = 1; } - else if(millis <= 1000) skew += ((1.f-skew)-(clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew))); + else if(millis <= 1000) skew += ((1.f-skew)-(std::clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew))); int oldy = y-sy; if(gs_playing(game::gamestate) && (f.owner || f.droptime)) sy += hud::drawitem(hud::bombtex, x, oldy, size, 0, true, false, colour.x, colour.y, colour.z, blend, skew, "super", "%d%%", int(wait*100.f)); @@ -327,7 +327,7 @@ namespace bomber float blend = camera1->o.distrange(above, bomberhintfadeat, bomberhintfadecut); if(!f.owner && !f.droptime) above.z += enttype[AFFINITY].radius/4*trans; float size = trans, yaw = !f.owner && f.proj ? f.proj->yaw : (lastmillis/4)%360, pitch = !f.owner && f.proj ? f.proj->pitch : 0, roll = !f.owner && f.proj ? f.proj->roll : 0, - wait = f.droptime ? clamp((lastmillis-f.droptime)/float(bomberresetdelay), 0.f, 1.f) : ((f.owner && carrytime) ? clamp((lastmillis-f.taketime)/float(carrytime), 0.f, 1.f) : 0.f); + wait = f.droptime ? std::clamp((lastmillis-f.droptime)/float(bomberresetdelay), 0.f, 1.f) : ((f.owner && carrytime) ? std::clamp((lastmillis-f.taketime)/float(carrytime), 0.f, 1.f) : 0.f); int interval = lastmillis%1000; vec effect = pulsecolour(); if(wait > 0.5f) diff --git a/src/game/bomber.h b/src/game/bomber.h index ea423189..09a183ab 100644 --- a/src/game/bomber.h +++ b/src/game/bomber.h @@ -61,7 +61,7 @@ struct bomberstate if(totalmillis != rendertime) { float yaw = 360-((lastmillis/2)%360), off = (lastmillis%1000)/500.f; - renderpos = vec(yaw*RAD, 0.f).mul(owner->radius+4).add(owner->center()); + renderpos = vec(yaw*rad, 0.f).mul(owner->radius+4).add(owner->center()); renderpos.z += owner->height*(off > 1 ? 2-off : off); rendertime = totalmillis; } diff --git a/src/game/capture.cpp b/src/game/capture.cpp index c5d7edff..85c99955 100644 --- a/src/game/capture.cpp +++ b/src/game/capture.cpp @@ -61,7 +61,7 @@ namespace capture bool arrow = false; float fade = blend*hud::radaraffinityblend, size = hud::radaraffinitysize; int millis = lastmillis-f.displaytime; - if(millis < 1000) size *= 1.f+(1-clamp(float(millis)/1000.f, 0.f, 1.f)); + if(millis < 1000) size *= 1.f+(1-std::clamp(float(millis)/1000.f, 0.f, 1.f)); if(f.owner) size *= 0.75f; if(k) { @@ -69,7 +69,7 @@ namespace capture pos = f.pos(true); int interval = lastmillis%500; if(interval >= 300 || interval <= 200) - fade *= clamp(interval >= 300 ? 1.f-((interval-300)/200.f) : interval/200.f, 0.f, 1.f); + fade *= std::clamp(interval >= 300 ? 1.f-((interval-300)/200.f) : interval/200.f, 0.f, 1.f); } else { @@ -209,17 +209,17 @@ namespace capture { if(f.owner == game::focus) { - if(millis <= 1000) skew += (1.f-skew)*clamp(float(millis)/1000.f, 0.f, 1.f); + if(millis <= 1000) skew += (1.f-skew)*std::clamp(float(millis)/1000.f, 0.f, 1.f); else skew = 1; // override it } - else if(millis <= 1000) skew += (1.f-skew)*clamp(float(millis)/1000.f, 0.f, 1.f); + else if(millis <= 1000) skew += (1.f-skew)*std::clamp(float(millis)/1000.f, 0.f, 1.f); else skew = 1; } - else if(millis <= 1000) skew += (1.f-skew)-(clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew)); + else if(millis <= 1000) skew += (1.f-skew)-(std::clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew)); int oldy = y-sy; if(gs_playing(game::gamestate) && (f.droptime || (m_ctf_protect(game::gamemode, game::mutators) && f.taketime && f.owner && f.owner->team != f.team))) { - float wait = f.droptime ? clamp(f.dropleft(lastmillis, capturestore)/float(capturedelay), 0.f, 1.f) : clamp((lastmillis-f.taketime)/float(captureprotectdelay), 0.f, 1.f); + float wait = f.droptime ? std::clamp(f.dropleft(lastmillis, capturestore)/float(capturedelay), 0.f, 1.f) : std::clamp((lastmillis-f.taketime)/float(captureprotectdelay), 0.f, 1.f); if(wait > 0.5f) { int delay = wait > 0.7f ? (wait > 0.85f ? 150 : 300) : 600, millis = lastmillis%(delay*2); @@ -303,7 +303,7 @@ namespace capture { capturestate::flag &f = st.flags[i]; vec pos = f.pos(true); - float wait = f.droptime ? clamp(f.dropleft(lastmillis, capturestore)/float(capturedelay), 0.f, 1.f) : ((m_ctf_protect(game::gamemode, game::mutators) && f.taketime && f.owner && f.owner->team != f.team) ? clamp((lastmillis-f.taketime)/float(captureprotectdelay), 0.f, 1.f) : 0.f), + float wait = f.droptime ? std::clamp(f.dropleft(lastmillis, capturestore)/float(capturedelay), 0.f, 1.f) : ((m_ctf_protect(game::gamemode, game::mutators) && f.taketime && f.owner && f.owner->team != f.team) ? std::clamp((lastmillis-f.taketime)/float(captureprotectdelay), 0.f, 1.f) : 0.f), blend = (!f.owner && (!f.droptime || m_ctf_defend(game::gamemode, game::mutators)) && f.team == game::focus->team ? camera1->o.distrange(pos, enttype[AFFINITY].radius, enttype[AFFINITY].radius/8) : 1.f)*(f.owner && f.owner == game::focus ? (game::thirdpersonview(true) ? (f.owner != &game::player1 ? followflagblend : thirdflagblend) : firstflagblend) : freeflagblend); vec effect = vec::hexcolor(TEAM(f.team, colour)); int colour = effect.tohexcolor(); @@ -343,7 +343,7 @@ namespace capture } if(gs_playing(game::gamestate) && (f.droptime || (m_ctf_protect(game::gamemode, game::mutators) && f.taketime && f.owner && f.owner->team != f.team))) { - float wait = f.droptime ? clamp(f.dropleft(lastmillis, capturestore)/float(capturedelay), 0.f, 1.f) : clamp((lastmillis-f.taketime)/float(captureprotectdelay), 0.f, 1.f); + float wait = f.droptime ? std::clamp(f.dropleft(lastmillis, capturestore)/float(capturedelay), 0.f, 1.f) : std::clamp((lastmillis-f.taketime)/float(captureprotectdelay), 0.f, 1.f); part_icon(flagpos, textureload(hud::progringtex, 3), 5, blend, 0, 0, 1, colour, (lastmillis%1000)/1000.f, 0.1f); part_icon(flagpos, textureload(hud::progresstex, 3), 5, 0.25f*blend, 0, 0, 1, colour); part_icon(flagpos, textureload(hud::progresstex, 3), 5, blend, 0, 0, 1, colour, 0, wait); diff --git a/src/game/capturemode.h b/src/game/capturemode.h index f0a5c219..5597ba09 100644 --- a/src/game/capturemode.h +++ b/src/game/capturemode.h @@ -20,8 +20,8 @@ struct captureservmode : capturestate, servmode vec dir = inertia, olddir = dir; if(numflags > 1 && dir.iszero()) { - dir.x = -sinf(RAD*ci->yaw); - dir.y = cosf(RAD*ci->yaw); + dir.x = -sinf(rad*ci->yaw); + dir.y = cosf(rad*ci->yaw); dir.z = 0; olddir = dir.normalize().mul(max(dir.magnitude(), 1.f)); } @@ -30,7 +30,7 @@ struct captureservmode : capturestate, servmode if(numflags > 1) { float yaw = -45.f+(90/float(numflags+1)*(iterflags+1)); - dir = vec(olddir).rotate_around_z(yaw*RAD); + dir = vec(olddir).rotate_around_z(yaw*rad); iterflags++; } ivec p(vec(o).mul(DMF)), q(vec(dir).mul(DMF)); diff --git a/src/game/client.cpp b/src/game/client.cpp index 27c07d1d..916d3ca5 100644 --- a/src/game/client.cpp +++ b/src/game/client.cpp @@ -465,7 +465,7 @@ namespace client void setloadweap(const char *list) { - vector items; + std::vector items; if(list && *list) { std::vector chunk; @@ -477,11 +477,18 @@ namespace client items.emplace_back(v >= W_OFFSET && v < W_ITEM ? v : 0); } } - game::player1.loadweap.shrink(0); - loopv(items) if(game::player1.loadweap.find(items[i]) < 0) - { - game::player1.loadweap.add(items[i]); - if(game::player1.loadweap.length() >= W_LOADOUT) break; + game::player1.loadweap.clear(); + for (const auto i : items) { + bool no_weap = std::none_of(game::player1.loadweap.begin(), + game::player1.loadweap.end(), [=](auto d) { return d == i; }); + + if (no_weap) { + game::player1.loadweap.emplace_back(i); + + if (game::player1.loadweap.size() >= W_LOADOUT) { + break; + } + } } sendplayerinfo = true; } @@ -501,18 +508,21 @@ namespace client items.emplace_back(v != 0 ? 1 : 0); } } - game::player1.randweap.shrink(0); + game::player1.randweap.clear(); loopv(items) { - game::player1.randweap.add(items[i]); - if(game::player1.randweap.length() >= W_LOADOUT) break; + game::player1.randweap.emplace_back(items[i]); + + if (game::player1.randweap.size() >= W_LOADOUT) { + break; + } } sendplayerinfo = true; } SVARF(IDF_PERSIST, playerrandweap, "", setrandweap(playerrandweap)); - ICOMMAND(0, getrandweap, "i", (int *n), intret(game::player1.randweap.inrange(*n) ? game::player1.randweap[*n] : 1)); - ICOMMAND(0, getloadweap, "i", (int *n), intret(game::player1.loadweap.inrange(*n) ? game::player1.loadweap[*n] : -1)); + ICOMMAND(0, getrandweap, "i", (int *n), intret(inrange(game::player1.randweap, *n) ? game::player1.randweap[*n] : 1)); + ICOMMAND(0, getloadweap, "i", (int *n), intret(inrange(game::player1.loadweap, *n) ? game::player1.loadweap[*n] : -1)); ICOMMAND(0, allowedweap, "i", (int *n), intret(isweap(*n) && m_check(W(*n, modes), W(*n, muts), game::gamemode, game::mutators) && !W(*n, disabled) ? 1 : 0)); ICOMMAND(0, hasloadweap, "bb", (int *g, int *m), intret(m_loadout(m_game(*g) ? *g : game::gamemode, *m >= 0 ? *m : game::mutators) ? 1 : 0)); @@ -673,7 +683,7 @@ namespace client const char *getmodelname(int mdl, int idx) { - return mdl >= 0 ? playertypes[mdl%PLAYERTYPES][clamp(idx, 0, 5)] : ""; + return mdl >= 0 ? playertypes[mdl%PLAYERTYPES][std::clamp(idx, 0, 5)] : ""; } ICOMMAND(0, getmodelname, "iiN", (int *mdl, int *idx, int *numargs), result(getmodelname(*mdl, *numargs >= 2 ? *idx : 5))); @@ -722,7 +732,7 @@ namespace client int getclientloadweap(int cn, int n) { gameent *d = game::getclient(cn); - return d ? (d->loadweap.inrange(n) ? d->loadweap[n] : 0) : -1; + return d ? (inrange(d->loadweap, n) ? d->loadweap[n] : 0) : -1; } ICOMMAND(0, getclientloadweap, "si", (char *who, int *n), intret(getclientloadweap(parsewho(who), *n))); @@ -775,8 +785,9 @@ namespace client defformatstring(str, "%d.%d.%d-%s%d-%s", d->version.major, d->version.minor, d->version.patch, plat_name(d->version.platform), d->version.arch, d->version.branch); result(str); } + break; case -2: result(plat_name(d->version.platform)); break; - case -1: intret(14); + case -1: intret(14); break; case 0: intret(d->version.major); break; case 1: intret(d->version.minor); break; case 2: intret(d->version.patch); break; @@ -1318,6 +1329,7 @@ namespace client break; case -2: conoutf("waiting for server to request the map.."); + [[fallthrough]]; default: emptymap(0, true, name); needsmap = totalmillis; @@ -1668,9 +1680,9 @@ namespace client putint(p, game::player1.colour); putint(p, game::player1.model); sendstring(game::player1.vanity, p); - putint(p, game::player1.loadweap.length()); + putint(p, game::player1.loadweap.size()); loopv(game::player1.loadweap) putint(p, game::player1.loadweap[i]); - putint(p, game::player1.randweap.length()); + putint(p, game::player1.randweap.size()); loopv(game::player1.randweap) putint(p, game::player1.randweap[i]); string hash = ""; @@ -1738,15 +1750,15 @@ namespace client vectoyawpitch(vec(worldpos).sub(d->headpos()).normalize(), yaw, pitch); game::fixrange(yaw, pitch); } - uint dir = (yaw < 0 ? 360 + int(yaw)%360 : int(yaw)%360) + clamp(int(pitch+90), 0, 180)*360; + uint dir = (yaw < 0 ? 360 + int(yaw)%360 : int(yaw)%360) + std::clamp(int(pitch+90), 0, 180)*360; q.put(dir&0xFF); q.put((dir>>8)&0xFF); - q.put(clamp(int(d->roll+90), 0, 180)); + q.put(std::clamp(int(d->roll+90), 0, 180)); q.put(vel&0xFF); if(vel > 0xFF) q.put((vel>>8)&0xFF); float velyaw, velpitch; vectoyawpitch(d->vel, velyaw, velpitch); - uint veldir = (velyaw < 0 ? 360 + int(velyaw)%360 : int(velyaw)%360) + clamp(int(velpitch+90), 0, 180)*360; + uint veldir = (velyaw < 0 ? 360 + int(velyaw)%360 : int(velyaw)%360) + std::clamp(int(velpitch+90), 0, 180)*360; q.put(veldir&0xFF); q.put((veldir>>8)&0xFF); if(fall > 0) @@ -1757,7 +1769,7 @@ namespace client { float fallyaw, fallpitch; vectoyawpitch(d->falling, fallyaw, fallpitch); - uint falldir = (fallyaw < 0 ? 360 + int(fallyaw)%360 : int(fallyaw)%360) + clamp(int(fallpitch+90), 0, 180)*360; + uint falldir = (fallyaw < 0 ? 360 + int(fallyaw)%360 : int(fallyaw)%360) + std::clamp(int(fallpitch+90), 0, 180)*360; q.put(falldir&0xFF); q.put((falldir>>8)&0xFF); } @@ -1802,9 +1814,9 @@ namespace client putint(p, game::player1.model); putint(p, game::player1.checkpointspawn); sendstring(game::player1.vanity, p); - putint(p, game::player1.loadweap.length()); + putint(p, game::player1.loadweap.size()); loopv(game::player1.loadweap) putint(p, game::player1.loadweap[i]); - putint(p, game::player1.randweap.length()); + putint(p, game::player1.randweap.size()); loopv(game::player1.randweap) putint(p, game::player1.randweap[i]); } if(sendcrcinfo) @@ -1977,13 +1989,13 @@ namespace client int dir = p.get(); dir |= p.get()<<8; yaw = dir%360; - pitch = clamp(dir/360, 0, 180)-90; - roll = clamp(int(p.get()), 0, 180)-90; + pitch = std::clamp(dir/360, 0, 180)-90; + roll = std::clamp(int(p.get()), 0, 180)-90; int mag = p.get(); if(flags&(1<<6)) mag |= p.get()<<8; dir = p.get(); dir |= p.get()<<8; - vecfromyawpitch(dir%360, clamp(dir/360, 0, 180)-90, 1, 0, vel); + vecfromyawpitch(dir%360, std::clamp(dir/360, 0, 180)-90, 1, 0, vel); vel.mul(mag/DVELF); if(flags&(1<<7)) { @@ -1993,7 +2005,7 @@ namespace client { dir = p.get(); dir |= p.get()<<8; - vecfromyawpitch(dir%360, clamp(dir/360, 0, 180)-90, 1, 0, falling); + vecfromyawpitch(dir%360, std::clamp(dir/360, 0, 180)-90, 1, 0, falling); } else falling = vec(0, 0, -1); falling.mul(mag/DVELF); @@ -2279,7 +2291,7 @@ namespace client dummy.get(p); break; } - int colour = getint(p), model = getint(p), cps = getint(p), team = clamp(getint(p), int(T_NEUTRAL), int(T_ENEMY)), priv = getint(p); + int colour = getint(p), model = getint(p), cps = getint(p), team = std::clamp(getint(p), int(T_NEUTRAL), int(T_ENEMY)), priv = getint(p); getstring(text, p); string namestr = ""; filterstring(namestr, text, true, true, true, true, MAXNAMELEN); @@ -3061,6 +3073,7 @@ namespace client t->checkpoint = -1; t->cpmillis = ent == -2 ? lastmillis : 0; } + break; } case N_SCORE: @@ -3178,7 +3191,7 @@ namespace client case N_INITAI: { - int bn = getint(p), on = getint(p), at = getint(p), et = getint(p), sk = clamp(getint(p), 1, 101); + int bn = getint(p), on = getint(p), at = getint(p), et = getint(p), sk = std::clamp(getint(p), 1, 101); getstring(text, p); int tm = getint(p), cl = getint(p), md = getint(p); string vanity; @@ -3260,9 +3273,9 @@ namespace client { int ac = 0, bc = 0; if(a->address.host == ENET_HOST_ANY || a->ping >= serverinfo::WAITING || a->attr.empty()) ac = -1; - else ac = a->attr[0] == VERSION_GAME ? 0x7FFF : clamp(a->attr[0], 0, 0x7FFF-1); + else ac = a->attr[0] == VERSION_GAME ? 0x7FFF : std::clamp(a->attr[0], 0, 0x7FFF-1); if(b->address.host == ENET_HOST_ANY || b->ping >= serverinfo::WAITING || b->attr.empty()) bc = -1; - else bc = b->attr[0] == VERSION_GAME ? 0x7FFF : clamp(b->attr[0], 0, 0x7FFF-1); + else bc = b->attr[0] == VERSION_GAME ? 0x7FFF : std::clamp(b->attr[0], 0, 0x7FFF-1); if(ac > bc) return -1; if(ac < bc) return 1; @@ -3309,6 +3322,7 @@ namespace client else bc = 0; retsw(ac, bc, true); + break; } case SINFO_MUTS: { diff --git a/src/game/compass.h b/src/game/compass.h index 038f262b..6eb84bad 100644 --- a/src/game/compass.h +++ b/src/game/compass.h @@ -159,7 +159,7 @@ int cmenuhit() if(sqrtf(cx*cx+cy*cy) <= compasssize*0.5f) return -1; else { - float yaw = -(float)atan2(cx, cy)/RAD+202.5f; if(yaw >= 360) yaw -= 360; + float yaw = -(float)atan2(cx, cy)/rad+202.5f; if(yaw >= 360) yaw -= 360; loopi(min(curcompass->actions.length(), 8)) if(yaw > i*45 && yaw <= (i+1)*45) return i; } diff --git a/src/game/defend.cpp b/src/game/defend.cpp index 97dc5cf3..d84acf99 100644 --- a/src/game/defend.cpp +++ b/src/game/defend.cpp @@ -20,7 +20,7 @@ namespace defend { int team = owner && enemy && !m_dac_quick(game::gamemode, game::mutators) ? T_NEUTRAL : enemy; int timestep = totalmillis%1000; - float amt = clamp((timestep <= 500 ? timestep/500.f : (1000-timestep)/500.f)*occupy, 0.f, 1.f); + float amt = std::clamp((timestep <= 500 ? timestep/500.f : (1000-timestep)/500.f)*occupy, 0.f, 1.f); colour.lerp(vec::hexcolor(TEAM(team, colour)), amt); } return colour; @@ -144,7 +144,7 @@ namespace defend loopv(st.flags) if(insideaffinity(st.flags[i], game::focus) && (st.flags[i].owner == game::focus->team || st.flags[i].enemy == game::focus->team)) { defendstate::flag &f = st.flags[i]; - float occupy = !f.owner || f.enemy ? clamp(f.converted/float(defendcount), 0.f, 1.f) : 1.f; + float occupy = !f.owner || f.enemy ? std::clamp(f.converted/float(defendcount), 0.f, 1.f) : 1.f; bool overthrow = f.owner && f.enemy == game::focus->team; ty -= draw_textf("You are %s: %s \fs\f[%d]\f(%s)\f(%s)\fS \fs%s%d%%\fS", tx, ty, int(FONTW*hud::eventpadx), int(FONTH*hud::eventpady), tr, tg, tb, int(255*blend), TEXT_SKIN|TEXT_CENTERED, -1, -1, 1, overthrow ? "overthrowing" : "securing", f.name, TEAM(f.owner, colour), hud::teamtexname(f.owner), hud::pointtex, overthrow ? "\fy" : (occupy < 1.f ? "\fc" : "\fg"), int(occupy*100.f))+FONTH/4; break; @@ -167,7 +167,7 @@ namespace defend if(headsup || f.hasflag || millis <= 1000) { float skew = headsup ? hud::inventoryskew : 0.f, - occupy = f.enemy ? clamp(f.converted/float(defendcount), 0.f, 1.f) : (f.owner ? 1.f : 0.f); + occupy = f.enemy ? std::clamp(f.converted/float(defendcount), 0.f, 1.f) : (f.owner ? 1.f : 0.f); vec c = vec::hexcolor(TEAM(f.owner, colour)), c1 = c; if(f.enemy) { @@ -175,8 +175,8 @@ namespace defend if(amt > 1.f) amt = 2.f-amt; c.lerp(vec::hexcolor(TEAM(f.enemy, colour)), amt); } - if(f.hasflag) skew += (millis <= 1000 ? clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew) : 1.f-skew); - else if(millis <= 1000) skew += (1.f-skew)-(clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew)); + if(f.hasflag) skew += (millis <= 1000 ? std::clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew) : 1.f-skew); + else if(millis <= 1000) skew += (1.f-skew)-(std::clamp(float(millis)/1000.f, 0.f, 1.f)*(1.f-skew)); int oldy = y-sy; if(hasflag || f.enemy) sy += hud::drawitem(hud::pointtex, x, oldy, size, 0, true, false, c.r, c.g, c.b, blend, skew, "super", "%s%d%%", hasflag ? (f.owner && f.enemy == game::focus->team ? "\fy" : (occupy < 1.f ? "\fc" : "\fg")) : "\fw", int(occupy*100.f)); diff --git a/src/game/defend.h b/src/game/defend.h index e300fc45..3c6c74bd 100644 --- a/src/game/defend.h +++ b/src/game/defend.h @@ -115,7 +115,7 @@ struct defendstate float occupied(bool instant, float amt) { - return (enemy ? enemy : owner) ? (!owner || enemy ? clamp(converted/amt, 0.f, 1.f) : 1.f) : 0.f; + return (enemy ? enemy : owner) ? (!owner || enemy ? std::clamp(converted/amt, 0.f, 1.f) : 1.f) : 0.f; } }; diff --git a/src/game/entities.cpp b/src/game/entities.cpp index d0828599..270845c5 100644 --- a/src/game/entities.cpp +++ b/src/game/entities.cpp @@ -33,8 +33,8 @@ namespace entities VAR(0, routemaxdist, 0, 64, VAR_MAX); vector &getents() { return ents; } - int lastent(int type) { return type >= 0 && type < MAXENTTYPES ? clamp(lastenttype[type], 0, ents.length()) : 0; } - int lastuse(int type) { return type >= 0 && type < MAXENTTYPES ? clamp(lastusetype[type], 0, ents.length()) : 0; } + int lastent(int type) { return type >= 0 && type < MAXENTTYPES ? std::clamp(lastenttype[type], 0, ents.length()) : 0; } + int lastuse(int type) { return type >= 0 && type < MAXENTTYPES ? std::clamp(lastusetype[type], 0, ents.length()) : 0; } int numattrs(int type) { return type >= 0 && type < MAXENTTYPES ? enttype[type].numattrs : 0; } ICOMMAND(0, entityattrs, "b", (int *n), intret(numattrs(*n))); @@ -186,7 +186,6 @@ namespace entities switch(attr[0]) { case 4: case 7: case 8: case 9: case 10: case 11: case 12: case 13: - { if(attr[1] >= 256) { bool hasval = true; @@ -212,8 +211,7 @@ namespace entities if(val%64 >= 32) addentinfo("inverted"); break; } - // fall through - } + [[fallthrough]]; case 1: case 2: { switch(attr[1]%3) @@ -377,7 +375,7 @@ namespace entities int weap = w_attr(game::gamemode, game::mutators, type, attr[0], m_weapon(game::focus->actortype, game::gamemode, game::mutators)); return isweap(weap) && *weaptype[weap].item ? weaptype[weap].item : "projectiles/cartridge"; } - case ACTOR: return actor[clamp(attr[0]+A_ENEMY, int(A_ENEMY), int(A_MAX-1))].playermodel[1]; + case ACTOR: return actor[std::clamp(attr[0]+A_ENEMY, int(A_ENEMY), int(A_MAX-1))].playermodel[1]; default: break; } return ""; @@ -578,27 +576,34 @@ namespace entities { e.lastemit = lastmillis; d->setused(n, lastmillis); - switch(e.attrs[1]) - { - case TR_EXIT: if(d->actortype >= A_BOT) break; - case TR_TOGGLE: case TR_LINK: case TR_ONCE: - { - client::addmsg(N_TRIGGER, "ri2", d->clientnum, n); - if(!e.spawned() || e.attrs[1] == TR_TOGGLE) setspawn(n, e.spawned() ? 0 : 1); + switch (e.attrs[1]) { + case TR_EXIT: + if (d->actortype >= A_BOT) { break; } - case TR_SCRIPT: - { - if(d == &game::player1) - { + [[fallthrough]]; + case TR_TOGGLE: + case TR_LINK: + case TR_ONCE: + client::addmsg(N_TRIGGER, "ri2", d->clientnum, n); + if (!e.spawned() || e.attrs[1] == TR_TOGGLE) { + setspawn(n, e.spawned() ? 0 : 1); + } + break; + case TR_SCRIPT: + if (d == &game::player1) { defformatstring(s, "on_trigger_%d", e.attrs[0]); - trigger = d; RUNWORLD(s); trigger = NULL; + trigger = d; + RUNWORLD(s); + trigger = NULL; } break; - } - default: break; + default: + break; + } + if (act && e.attrs[2] == TA_ACTION) { + d->action[AC_USE] = false; } - if(act && e.attrs[2] == TA_ACTION) d->action[AC_USE] = false; } } @@ -675,7 +680,7 @@ namespace entities float mag = f.attrs[2] < 0 ? 0.f : max(vec(d->vel).add(d->falling).magnitude(), f.attrs[2] ? float(f.attrs[2]) : 50.f), yaw = f.attrs[0] < 0 ? (lastmillis/5)%360 : f.attrs[0], pitch = f.attrs[1]; game::fixrange(yaw, pitch); - if(mag > 0 && f.attrs[5] < 6) d->vel = vec(yaw*RAD, pitch*RAD).mul(mag); + if(mag > 0 && f.attrs[5] < 6) d->vel = vec(yaw*rad, pitch*rad).mul(mag); switch(f.attrs[5]%3) { case 2: break; // keep @@ -696,7 +701,7 @@ namespace entities } game::fixrange(d->yaw, d->pitch); if(mag <= 0) d->vel = vec(0, 0, 0); - else if(f.attrs[5] >= 6) d->vel = vec(d->yaw*RAD, d->pitch*RAD).mul(mag); + else if(f.attrs[5] >= 6) d->vel = vec(d->yaw*rad, d->pitch*rad).mul(mag); if(physics::entinmap(d, gameent::is(d))) // entinmap first for getting position { f.lastemit = lastmillis; @@ -741,15 +746,19 @@ namespace entities switch(g->projtype) { case PRJ_ENT: case PRJ_AFFINITY: - { if(!g->beenused) { g->beenused = 1; g->lifetime = min(g->lifetime, g->fadetime); } - if(g->lifetime > 0) break; - } - default: g->state = CS_DEAD; g->escaped = true; break; + if (g->lifetime > 0) { + break; + } + [[fallthrough]]; + default: + g->state = CS_DEAD; + g->escaped = true; + break; } } else d->state = CS_DEAD; @@ -762,8 +771,8 @@ namespace entities d->setused(n, lastmillis); float mag = max(e.attrs[2], 1), maxrad = e.attrs[3] ? e.attrs[3] : enttype[PUSHER].radius, minrad = e.attrs[4]; if(dist > 0 && minrad > 0 && maxrad > minrad && dist > minrad && maxrad >= dist) - mag *= 1.f-clamp((dist-minrad)/float(maxrad-minrad), 0.f, 1.f); - vec dir(e.attrs[0]*RAD, e.attrs[1]*RAD), rel = vec(dir).mul(mag); + mag *= 1.f-std::clamp((dist-minrad)/float(maxrad-minrad), 0.f, 1.f); + vec dir(e.attrs[0]*rad, e.attrs[1]*rad), rel = vec(dir).mul(mag); switch(e.attrs[5]) { case 0: @@ -997,11 +1006,13 @@ namespace entities while(e.attrs[3] > 180) e.attrs[3] -= 360; // roll while(e.attrs[4] < 0) e.attrs[4] += 101; while(e.attrs[4] > 100) e.attrs[4] -= 101; // blend - if(e.attrs[5] < 0) e.attrs[5] = 0; + if (e.attrs[5] < 0) { + e.attrs[5] = 0; + } + break; case PARTICLES: case MAPSOUND: case LIGHTFX: - { e.nextemit = 0; loopv(e.links) if(ents.inrange(e.links[i])) { @@ -1012,7 +1023,6 @@ namespace entities break; } break; - } case LIGHT: { if(e.attrs[0] < 0) e.attrs[0] = 0; @@ -1751,13 +1761,24 @@ namespace entities { switch(e.attrs[0]) { - case 0: if(e.attrs[3] <= 0) break; + case 0: + if (e.attrs[3] <= 0) { + break; + } + [[fallthrough]]; case 4: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 5: case 6: e.attrs[3] = (((e.attrs[3]&0xF)<<4)|((e.attrs[3]&0xF0)<<8)|((e.attrs[3]&0xF00)<<12))+0x0F0F0F; - if(e.attrs[0] != 5 && e.attrs[0] != 6) break; + if (e.attrs[0] != 5 && e.attrs[0] != 6) { + break; + } + [[fallthrough]]; case 3: - e.attrs[2] = (((e.attrs[2]&0xF)<<4)|((e.attrs[2]&0xF0)<<8)|((e.attrs[2]&0xF00)<<12))+0x0F0F0F; break; - default: break; + e.attrs[2] = (((e.attrs[2] & 0xF) << 4) | ((e.attrs[2] & 0xF0) << 8) | + ((e.attrs[2] & 0xF00) << 12)) + + 0x0F0F0F; + break; + default: + break; } } break; @@ -1774,7 +1795,7 @@ namespace entities { int material = lookupmaterial(e.o), clipmat = material&MATF_CLIP; if(clipmat == MAT_CLIP || (material&MAT_DEATH) || (material&MATF_VOLUME) == MAT_LAVA) - e.o.add(vec(e.attrs[0]*RAD, e.attrs[1]*RAD)); + e.o.add(vec(e.attrs[0]*rad, e.attrs[1]*rad)); } } if(e.attrs[0] >= 0) checkyawmode(e, mtype, mver, gver, 0, -1); @@ -1968,6 +1989,7 @@ namespace entities break; case WEAPON: loopj(3) e.attrs[j+3] = ents[i]->attrs[j+2]; // mode, muts, id + break; default: e.attrs[1] = (i%8)*45; break; @@ -2068,7 +2090,7 @@ namespace entities } case ENVMAP: { - int s = e.attrs[0] ? clamp(e.attrs[0], 0, 10000) : envmapradius; + int s = e.attrs[0] ? std::clamp(e.attrs[0], 0, 10000) : envmapradius; part_radius(e.o, vec(s, s, s), showentsize, 1, 1, 0x00FFFF); break; } @@ -2087,7 +2109,7 @@ namespace entities float radius = f.attrs[0]; if(!radius) radius = 2*e.o.dist(f.o); vec dir = vec(e.o).sub(f.o).normalize(); - float angle = clamp(int(e.attrs[1]), 1, 89); + float angle = std::clamp(int(e.attrs[1]), 1, 89); int colour = ((f.attrs[1]/2)<<16)|((f.attrs[2]/2)<<8)|(f.attrs[3]/2); part_cone(f.o, dir, radius, angle, showentsize, 1, 1, colour); break; @@ -2098,12 +2120,12 @@ namespace entities { int colour = ((e.attrs[2]/2)<<16)|((e.attrs[3]/2)<<8)|(e.attrs[4]/2), offset = e.attrs[5] ? (e.attrs[5] > 0 ? e.attrs[5] : 0) : 10, yaw = e.attrs[0], pitch = e.attrs[1]+90; - vec dir(yaw*RAD, pitch*RAD); + vec dir(yaw*rad, pitch*rad); static const float offsets[9][2] = { { 0, 0 }, { 0, 1 }, { 90, 1 }, { 180, 1 }, { 270, 1 }, { 45, 0.5f }, { 135, 0.5f }, { 225, 0.5f }, { 315, 0.5f } }; loopk(offset ? 9 : 1) { - vec spoke(yaw*RAD, (pitch + offset*offsets[k][1])*RAD); - spoke.rotate(offsets[k][0]*RAD, dir); + vec spoke(yaw*rad, (pitch + offset*offsets[k][1])*rad); + spoke.rotate(offsets[k][0]*rad, dir); float syaw, spitch; vectoyawpitch(spoke, syaw, spitch); entdirpart(e.o, syaw, spitch, getworldsize()*2, 1, colour); diff --git a/src/game/game.cpp b/src/game/game.cpp index cd512227..428bf1cf 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -546,7 +546,7 @@ namespace game if (cookzoom > 0) { // Calculate the ratio of the zoom state change and clamp it in the interval [0, 1] since progress beyond either point is redundant. - ratio = clamp(frame / static_cast(cookzoom), 0.f, 1.f); + ratio = std::clamp(frame / static_cast(cookzoom), 0.f, 1.f); } // Return the zoom state chage ratio converted to the zoom in ratio. @@ -700,14 +700,23 @@ namespace game bool tvmode(bool check, bool force) { - if(!m_edit(gamemode) && (!check || !cameras.empty())) - { - if(!gs_playing(gamestate) && intermmode) return true; - else switch(player1.state) - { - case CS_SPECTATOR: if(specmode || (force && focus != &player1 && followmode && followaim())) return true; break; - case CS_WAITING: if((waitmode && (!player1.lastdeath || lastmillis-player1.lastdeath >= 500)) || (force && focus != &player1 && followmode && followaim())) return true; break; - default: break; + if (!m_edit(gamemode) && (!check || !cameras.empty())) { + if (!gs_playing(gamestate) && intermmode) { + return true; + } else switch(player1.state) { + case CS_SPECTATOR: + if (specmode || (force && focus != &player1 && followmode && followaim())) { + return true; + } + break; + case CS_WAITING: + if ((waitmode && (!player1.lastdeath || lastmillis-player1.lastdeath >= 500)) || + (force && focus != &player1 && followmode && followaim())) { + return true; + } + break; + default: + break; } } return false; @@ -745,11 +754,11 @@ namespace game else if(*f < -1) *f = players.length()-1; #define addfollow \ { \ - *f += clamp(n, -1, 1); \ + *f += std::clamp(n, -1, 1); \ checkfollow; \ if(*f == -1) \ { \ - if(other) *f += clamp(n, -1, 1); \ + if(other) *f += std::clamp(n, -1, 1); \ else \ { \ specreset(); \ @@ -839,7 +848,7 @@ namespace game vec pulsecolour(physent *d, int i, int cycle) { size_t seed = size_t(d) + (lastmillis/cycle); - int n = detrnd(seed, PULSECOLOURS), n2 = detrnd(seed + 1, PULSECOLOURS), q = clamp(i, 0, int(PULSE_LAST)); + int n = detrnd(seed, PULSECOLOURS), n2 = detrnd(seed + 1, PULSECOLOURS), q = std::clamp(i, 0, int(PULSE_LAST)); return vec::hexcolor(pulsecols[q][n]).lerp(vec::hexcolor(pulsecols[q][n2]), (lastmillis%cycle)/float(cycle)); } @@ -859,7 +868,7 @@ namespace game { case 0: break; // off case 1: case 2: case 3: case 4: - return vec::hexcolor(pulsecols[index-1][clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)]); + return vec::hexcolor(pulsecols[index-1][std::clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)]); break; default: break; } @@ -915,7 +924,7 @@ namespace game powering = last && d->weapstate[d->weapselect] == W_S_POWER, reloading = last && d->weapstate[d->weapselect] == W_S_RELOAD, secondary = physics::secondaryweap(d); - float amt = last ? clamp(float(lastmillis-d->weaptime[d->weapselect])/d->weapwait[d->weapselect], 0.f, 1.f) : 0.f; + float amt = last ? std::clamp(float(lastmillis-d->weaptime[d->weapselect])/d->weapwait[d->weapselect], 0.f, 1.f) : 0.f; vec col = WPCOL(d, d->weapselect, lightcol, secondary); if(d->weapselect == W_FLAMER && (!reloading || amt > 0.5f) && !physics::liquidcheck(d)) { @@ -979,9 +988,13 @@ namespace game int num = int((effect ? 3 : 10)*impulsescale); switch(effect) { - case 0: playsound(S_IMPULSE, d->o, d); // fail through - case 1: if(num > 0 && impulsefade > 0) loopi(3) boosteffect(d, d->jet[i], num, impulsefade, effect==0); - break; + case 0: + playsound(S_IMPULSE, d->o, d); + [[fallthrough]]; + case 1: + if (num > 0 && impulsefade > 0) + loopi(3) boosteffect(d, d->jet[i], num, impulsefade, effect == 0); + break; } } @@ -1019,7 +1032,7 @@ namespace game minscale = minresizescale; if(amtscale < 1) amtscale = (amtscale*(1-minscale))+minscale; } - total *= clamp(amtscale, minscale, maxresizescale); + total *= std::clamp(amtscale, minscale, maxresizescale); } if(deathscale && (d->state == CS_DEAD || d->state == CS_WAITING)) total *= spawnfade(d); } @@ -1057,9 +1070,9 @@ namespace game { if(curfoot < 0) curfoot = d->lastfoot; vec pos = d->footpos(curfoot); - float amt = clamp(mag/n, 0.f, 1.f)*(d != focus ? footstepsoundlevel : footstepsoundfocus); + float amt = std::clamp(mag/n, 0.f, 1.f)*(d != focus ? footstepsoundlevel : footstepsoundfocus); if(onfloor && !d->running(moveslow)) amt *= footstepsoundlight; - int vol = clamp(int(amt*footstepsoundmaxvol), footstepsoundminvol, footstepsoundmaxvol); + int vol = std::clamp(int(amt*footstepsoundmaxvol), footstepsoundminvol, footstepsoundmaxvol); playsound(liquid && (!onfloor || rnd(4)) ? S_SWIMSTEP : S_FOOTSTEP, pos, NULL, d != focus ? 0 : SND_NOCULL, vol, footstepsoundmaxrad, footstepsoundminrad, &d->sschan[curfoot]); } } @@ -1395,9 +1408,9 @@ namespace game { vec p = d->headpos(-d->height/4); if(!nogore && bloodscale > 0) - part_splash(PART_BLOOD, int(clamp(damage/20, 1, 5)*bloodscale)*(bleeding || material ? 2 : 1), bloodfade, p, 0x229999, (rnd(bloodsize/2)+(bloodsize/2))/10.f, 1, 100, DECAL_BLOOD, int(d->radius), 10); + part_splash(PART_BLOOD, int(std::clamp(damage/20, 1, 5)*bloodscale)*(bleeding || material ? 2 : 1), bloodfade, p, 0x229999, (rnd(bloodsize/2)+(bloodsize/2))/10.f, 1, 100, DECAL_BLOOD, int(d->radius), 10); if(nogore != 2 && (bloodscale <= 0 || bloodsparks)) - part_splash(PART_PLASMA, int(clamp(damage/20, 1, 5))*(bleeding || material ? 2: 1), bloodfade, p, 0x882222, 1, 0.5f, 50, DECAL_STAIN, int(d->radius)); + part_splash(PART_PLASMA, int(std::clamp(damage/20, 1, 5))*(bleeding || material ? 2: 1), bloodfade, p, 0x882222, 1, 0.5f, 50, DECAL_STAIN, int(d->radius)); } if(d != v) { @@ -1412,7 +1425,7 @@ namespace game } if(d->actortype < A_ENEMY && !issound(d->vschan)) playsound(S_PAIN, d->o, d, 0, -1, -1, -1, &d->vschan); d->lastpain = lastmillis; - if(!WK(flags)) playsound(WSND2(weap, WS(flags), S_W_IMPACT), vec(d->center()).add(vec(dir).mul(dist)), NULL, 0, clamp(int(255*scale), 64, 255)); + if(!WK(flags)) playsound(WSND2(weap, WS(flags), S_W_IMPACT), vec(d->center()).add(vec(dir).mul(dist)), NULL, 0, std::clamp(int(255*scale), 64, 255)); } if(AA(d->actortype, abilities)&(1<addstun(weap, lastmillis, G(shockstuntime), shockstun&W_N_STADD ? s : 0.f, shockstun&W_N_GRADD ? g : 0.f); - if(shockstun&W_N_STIMM && s > 0) d->vel.mul(1.f-clamp(s, 0.f, 1.f)); - if(shockstun&W_N_GRIMM && g > 0) d->falling.mul(1.f-clamp(g, 0.f, 1.f)); + if(shockstun&W_N_STIMM && s > 0) d->vel.mul(1.f-std::clamp(s, 0.f, 1.f)); + if(shockstun&W_N_GRIMM && g > 0) d->falling.mul(1.f-std::clamp(g, 0.f, 1.f)); if(shockstun&W_N_SLIDE) d->impulse[IM_SLIP] = lastmillis; } else if(isweap(weap) && !burning && !bleeding && !material && !shocking && WF(WK(flags), weap, damage, WS(flags)) != 0) @@ -1443,8 +1456,8 @@ namespace game } float s = WF(WK(flags), weap, stunscale, WS(flags))*amt, g = WF(WK(flags), weap, stunfall, WS(flags))*amt; d->addstun(weap, lastmillis, int(scale*WF(WK(flags), weap, stuntime, WS(flags))), stun&W_N_STADD ? s : 0.f, stun&W_N_GRADD ? g : 0.f); - if(stun&W_N_STIMM && s > 0) d->vel.mul(1.f-clamp(s, 0.f, 1.f)); - if(stun&W_N_GRIMM && g > 0) d->falling.mul(1.f-clamp(g, 0.f, 1.f)); + if(stun&W_N_STIMM && s > 0) d->vel.mul(1.f-std::clamp(s, 0.f, 1.f)); + if(stun&W_N_GRIMM && g > 0) d->falling.mul(1.f-std::clamp(g, 0.f, 1.f)); if(stun&W_N_SLIDE) d->impulse[IM_SLIP] = lastmillis; } if(WF(WK(flags), weap, hitpush, WS(flags)) != 0 || WF(WK(flags), weap, hitvel, WS(flags)) != 0) @@ -1778,7 +1791,7 @@ namespace game if(actor[d->actortype].living && nogore != 2 && gibscale > 0 && !(flags&HIT_LOST)) { - int gib = clamp(max(damage, 10)/20, 1, 10), amt = int((rnd(gib)+gib)*gibscale); + int gib = std::clamp(max(damage, 10)/20, 1, 10), amt = int((rnd(gib)+gib)*gibscale); if(d->obliterated) amt *= 2; loopi(amt) projs::create(pos, pos, true, d, nogore ? PRJ_DEBRIS : PRJ_GIBS, -1, HIT_NONE, rnd(gibfade)+gibfade, 0, rnd(500)+1, rnd(50)+10); } @@ -1980,7 +1993,7 @@ namespace game int levelcolour(int colour, float level) { - return (clamp(int((colour>>16)*level), 0, 255)<<16)|(clamp(int(((colour>>8)&0xFF)*level), 0, 255)<<8)|(clamp(int((colour&0xFF)*level), 0, 255)); + return (std::clamp(int((colour>>16)*level), 0, 255)<<16)|(std::clamp(int(((colour>>8)&0xFF)*level), 0, 255)<<8)|(std::clamp(int((colour&0xFF)*level), 0, 255)); } int findcolour(gameent *d, bool tone, bool mix, float level) @@ -1997,9 +2010,9 @@ namespace game float amt = (lastmillis-d->weaptime[d->weapselect])/float(d->weapwait[d->weapselect]); int r2 = (col>>16), g2 = ((col>>8)&0xFF), b2 = (col&0xFF), c = W(lastweap, colour), r1 = (c>>16), g1 = ((c>>8)&0xFF), b1 = (c&0xFF), - r3 = clamp(int((r1*(1-amt))+(r2*amt)), 0, 255), - g3 = clamp(int((g1*(1-amt))+(g2*amt)), 0, 255), - b3 = clamp(int((b1*(1-amt))+(b2*amt)), 0, 255); + r3 = std::clamp(int((r1*(1-amt))+(r2*amt)), 0, 255), + g3 = std::clamp(int((g1*(1-amt))+(g2*amt)), 0, 255), + b3 = std::clamp(int((b1*(1-amt))+(b2*amt)), 0, 255); col = (r3<<16)|(g3<<8)|b3; } } @@ -2009,9 +2022,9 @@ namespace game { int r1 = (col>>16), g1 = ((col>>8)&0xFF), b1 = (col&0xFF), c = TEAM(d->team, colour), r2 = (c>>16), g2 = ((c>>8)&0xFF), b2 = (c&0xFF), - r3 = clamp(int((r1*(1-playertonemix))+(r2*playertonemix)), 0, 255), - g3 = clamp(int((g1*(1-playertonemix))+(g2*playertonemix)), 0, 255), - b3 = clamp(int((b1*(1-playertonemix))+(b2*playertonemix)), 0, 255); + r3 = std::clamp(int((r1*(1-playertonemix))+(r2*playertonemix)), 0, 255), + g3 = std::clamp(int((g1*(1-playertonemix))+(g2*playertonemix)), 0, 255), + b3 = std::clamp(int((b1*(1-playertonemix))+(b2*playertonemix)), 0, 255); col = (r3<<16)|(g3<<8)|b3; } return levelcolour(col, level); @@ -2068,7 +2081,7 @@ namespace game const char *teamtexnamex(int team) { const char *teamtexs[T_MAX] = { "teamtex", "teamalphatex", "teamomegatex", "teamkappatex", "teamsigmatex", "teamtex" }; - return teamtexs[clamp(team, 0, T_MAX-1)]; + return teamtexs[std::clamp(team, 0, T_MAX-1)]; } const char *colourteam(int team, const char *icon) @@ -2125,7 +2138,7 @@ namespace game { float dist = p->o.dist(p->d); p->d = p->o = d->muzzlepos(d->weapselect); - p->d.add(vec(d->yaw*RAD, d->pitch*RAD).mul(dist)); + p->d.add(vec(d->yaw*rad, d->pitch*rad).mul(dist)); break; } case PT_PART: case PT_FIREBALL: case PT_FLARE: @@ -2187,8 +2200,8 @@ namespace game #define mousesens(a,b,c) ((float(a)/float(b))*c) if(hud::hasinput(true)) { - cursorx = clamp(cursorx+mousesens(dx, w, mousesensitivity), 0.f, 1.f); - cursory = clamp(cursory+mousesens(dy, h, mousesensitivity), 0.f, 1.f); + cursorx = std::clamp(cursorx+mousesens(dx, w, mousesensitivity), 0.f, 1.f); + cursory = std::clamp(cursory+mousesens(dy, h, mousesensitivity), 0.f, 1.f); return true; } else if(!tvmode()) @@ -2230,8 +2243,8 @@ namespace game if(vectocursor(pos, loc.x, loc.y, loc.z)) { float amt = curtime/float(thirdpersoninterp); - cursorx = clamp(cursorx+((loc.x-cursorx)*amt), 0.f, 1.f); - cursory = clamp(cursory+((loc.y-cursory)*amt), 0.f, 1.f); + cursorx = std::clamp(cursorx+((loc.x-cursorx)*amt), 0.f, 1.f); + cursory = std::clamp(cursory+((loc.y-cursory)*amt), 0.f, 1.f); } break; } @@ -2249,8 +2262,8 @@ namespace game void getyawpitch(const vec &from, const vec &pos, float &yaw, float &pitch) { float dist = from.dist(pos); - yaw = -atan2(pos.x-from.x, pos.y-from.y)/RAD; - pitch = asin((pos.z-from.z)/dist)/RAD; + yaw = -atan2(pos.x-from.x, pos.y-from.y)/rad; + pitch = asin((pos.z-from.z)/dist)/rad; } void scaleyawpitch(float &yaw, float &pitch, float targyaw, float targpitch, float yawspeed, float pitchspeed, float rotate) @@ -2327,9 +2340,9 @@ namespace game { float spineoff = firstpersonspine*d->zradius*0.5f; to.z -= spineoff; - float lean = clamp(pitch, -firstpersonpitchmin, firstpersonpitchmax); + float lean = std::clamp(pitch, -firstpersonpitchmin, firstpersonpitchmax); if(firstpersonpitchscale >= 0) lean *= firstpersonpitchscale; - to.add(vec(yaw*RAD, (lean+90)*RAD).mul(spineoff)); + to.add(vec(yaw*rad, (lean+90)*rad).mul(spineoff)); } if(firstpersonbob && gs_playing(gamestate) && d->state == CS_ALIVE) { @@ -2338,11 +2351,11 @@ namespace game { scale *= 1.f - zoom_ratio(); } - if(firstpersonbobtopspeed) scale *= clamp(d->vel.magnitude()/firstpersonbobtopspeed, firstpersonbobmin, 1.f); + if(firstpersonbobtopspeed) scale *= std::clamp(d->vel.magnitude()/firstpersonbobtopspeed, firstpersonbobmin, 1.f); if(scale > 0) { - float steps = bobdist/firstpersonbobstep*M_PI; - vec dir = vec(yaw*RAD, 0.f).mul(firstpersonbobside*cosf(steps)*scale); + float steps = bobdist/firstpersonbobstep*pi; + vec dir = vec(yaw*rad, 0.f).mul(firstpersonbobside*cosf(steps)*scale); dir.z = firstpersonbobup*(fabs(sinf(steps)) - 1)*scale; to.add(dir); } @@ -2505,7 +2518,7 @@ namespace game yaw = c->player ? c->player->yaw : float(rnd(360)); pitch = c->player ? c->player->pitch : float(rnd(91)-45); fixrange(yaw, pitch); - c->dir = vec(yaw*RAD, pitch*RAD); + c->dir = vec(yaw*rad, pitch*rad); if(force) return true; } return false; @@ -2543,7 +2556,7 @@ namespace game static const int sphereyawchecks[8] = { 180, 135, 225, 90, 270, 45, 315 }, spherepitchchecks[5] = { 0, 45, -45, 89, -89 }; loopi(5) loopj(5) loopk(8) { - c.o = vec(pos).add(vec(sphereyawchecks[k]*RAD, spherepitchchecks[j]*RAD).mul((i+1)*2)); + c.o = vec(pos).add(vec(sphereyawchecks[k]*rad, spherepitchchecks[j]*rad).mul((i+1)*2)); if(!collide(&c, vec(0, 0, 0), 0, false)) { pos = c.o; @@ -2788,11 +2801,11 @@ namespace game { scale *= 1.f - zoom_ratio(); } - if(firstpersonbobtopspeed) scale *= clamp(d->vel.magnitude()/firstpersonbobtopspeed, firstpersonbobmin, 1.f); + if(firstpersonbobtopspeed) scale *= std::clamp(d->vel.magnitude()/firstpersonbobtopspeed, firstpersonbobmin, 1.f); if(scale > 0) { vec dir(c->yaw, c->pitch); - float steps = bobdist/firstpersonbobstep*M_PI, dist = raycube(c->o, dir, firstpersonbobfocusmaxdist, RAY_CLIPMAT|RAY_POLY), yaw, pitch; + float steps = bobdist/firstpersonbobstep*pi, dist = raycube(c->o, dir, firstpersonbobfocusmaxdist, RAY_CLIPMAT|RAY_POLY), yaw, pitch; if(dist < 0 || dist > firstpersonbobfocusmaxdist) dist = firstpersonbobfocusmaxdist; else if(dist < firstpersonbobfocusmindist) dist = firstpersonbobfocusmindist; vectoyawpitch(vec(firstpersonbobside*cosf(steps), dist, firstpersonbobup*(fabs(sinf(steps)) - 1)), yaw, pitch); @@ -3027,8 +3040,8 @@ namespace game vec o = third ? d->feetpos() : camerapos(d); if(third == 2) { - o.sub(vec(yaw*RAD, 0.f).mul(firstpersonbodydist+firstpersonspineoffset)); - o.sub(vec(yaw*RAD, 0.f).rotate_around_z(90*RAD).mul(firstpersonbodyside)); + o.sub(vec(yaw*rad, 0.f).mul(firstpersonbodydist+firstpersonspineoffset)); + o.sub(vec(yaw*rad, 0.f).rotate_around_z(90*rad).mul(firstpersonbodyside)); if(firstpersonbodyfeet >= 0 && d->wantshitbox()) { float minz = max(d->toe[0].z, d->toe[1].z)+(firstpersonbodyfeet*size); @@ -3041,8 +3054,8 @@ namespace game vectoyawpitch(vec(worldpos).sub(d->headpos()).normalize(), yaw, pitch); else if(!third && firstpersonsway) { - float steps = swaydist/(firstpersonbob ? firstpersonbobstep : firstpersonswaystep)*M_PI; - vec dir = vec(d->yaw*RAD, 0.f).mul(firstpersonswayside*cosf(steps)); + float steps = swaydist/(firstpersonbob ? firstpersonbobstep : firstpersonswaystep)*pi; + vec dir = vec(d->yaw*rad, 0.f).mul(firstpersonswayside*cosf(steps)); dir.z = firstpersonswayup*(fabs(sinf(steps)) - 1); o.add(dir).add(swaydir).add(swaypush); } @@ -3154,7 +3167,7 @@ namespace game e->light.material[2] = bvec::fromcolor(W(d->weapselect, colour)); if(lastmillis-d->weaptime[d->weapselect] > 0 && d->weapstate[d->weapselect] == W_S_POWER) { - float amt = clamp(float(lastmillis-d->weaptime[d->weapselect])/d->weapwait[d->weapselect], 0.f, 1.f); + float amt = std::clamp(float(lastmillis-d->weaptime[d->weapselect])/d->weapwait[d->weapselect], 0.f, 1.f); e->light.material[2].r += int((255-e->light.material[2].r)*amt); e->light.material[2].g -= int(e->light.material[2].g*amt); e->light.material[2].b -= int(e->light.material[2].b*amt); @@ -3244,7 +3257,7 @@ namespace game { t = textureload(hud::dominatingtex, 3); } - colour = pulsecols[PULSE_DISCO][clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)]; + colour = pulsecols[PULSE_DISCO][std::clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)]; } else if(d->dominated.find(focus) >= 0) { @@ -3252,7 +3265,7 @@ namespace game { t = textureload(hud::dominatedtex, 3); } - colour = pulsecols[PULSE_DISCO][clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)]; + colour = pulsecols[PULSE_DISCO][std::clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)]; } } } @@ -3328,7 +3341,11 @@ namespace game if(t > 1000) animflags = ANIM_DEAD|ANIM_LOOP|ANIM_NOPITCH; break; } - case 3: if(m_duke(gamemode, mutators)) return; + case 3: + if (m_duke(gamemode, mutators)) { + return; + } + break; case 2: { if(!validragdoll(d, lastaction)) animflags |= ANIM_RAGDOLL; @@ -3485,7 +3502,7 @@ namespace game { if(hashint || haslight || haspower || hasdom) { - vec c = vec::hexcolor(hasdom ? pulsecols[PULSE_DISCO][clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)] : (haslight ? WHCOL(d, d->weapselect, lightcol, physics::secondaryweap(d)) : getcolour(d, playerhinttone, playerhinttonelevel))); + vec c = vec::hexcolor(hasdom ? pulsecols[PULSE_DISCO][std::clamp((lastmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)] : (haslight ? WHCOL(d, d->weapselect, lightcol, physics::secondaryweap(d)) : getcolour(d, playerhinttone, playerhinttonelevel))); float height = d->height, fade = blend; if(hasdom) fade *= playerhintdom; else if(haslight || haspower) @@ -3520,7 +3537,7 @@ namespace game vec o = d->center(), offset = vec(o).sub(camera1->o).rescale(d->radius/2); offset.z = max(offset.z, -1.0f); offset.add(o); - part_create(PART_HINT_VERT_SOFT, 1, offset, c.tohexcolor(), clamp(height*playerhintsize, 1.f, playerhintmaxsize), fade*camera1->o.distrange(o, playerhintfadeat, playerhintfadecut)); + part_create(PART_HINT_VERT_SOFT, 1, offset, c.tohexcolor(), std::clamp(height*playerhintsize, 1.f, playerhintmaxsize), fade*camera1->o.distrange(o, playerhintfadeat, playerhintfadecut)); } if(useth) { @@ -3691,8 +3708,8 @@ namespace game previewent.o = calcmodelpreviewpos(vec(xyrad, zrad), previewent.yaw).addz(previewent.height - zrad); previewent.colour = color; previewent.model = model; - previewent.team = clamp(team, 0, int(T_MULTI)); - previewent.weapselect = clamp(weap, 0, W_ALL-1); + previewent.team = std::clamp(team, 0, int(T_MULTI)); + previewent.weapselect = std::clamp(weap, 0, W_ALL-1); previewent.setvanity(vanity); previewent.light.millis = -1; renderplayer(&previewent, 1, blend, scale); diff --git a/src/game/game.h b/src/game/game.h index bb5c81c5..1d9f6dd8 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -552,7 +552,7 @@ struct clientstate int actortype, spawnpoint, ownernum, skill, points, frags, deaths, totalpoints, totalfrags, totaldeaths, spree, lasttimeplayed, timeplayed, cpmillis, cptime, queuepos; bool quarantine; string vanity; - vector loadweap, lastweap, randweap; + std::vector loadweap, lastweap, randweap; verinfo version; clientstate() : colour(0), model(0), checkpointspawn(1), weapselect(W_CLAW), lastdeath(0), lastspawn(0), lastpain(0), lastregen(0), lastregenamt(0), lastbuff(0), lastshoot(0), @@ -560,9 +560,7 @@ struct clientstate cpmillis(0), cptime(0), queuepos(-1), quarantine(false) { vanity[0] = '\0'; - loadweap.shrink(0); - lastweap.shrink(0); - randweap.shrink(0); + resetresidual(); } ~clientstate() {} @@ -608,8 +606,11 @@ struct clientstate void addlastweap(int weap) { - lastweap.add(weap); - if(lastweap.length() >= W_ALL) lastweap.remove(0); + lastweap.emplace_back(weap); + + if (lastweap.size() >= W_ALL) { + lastweap.erase(lastweap.begin()); + } } int getlastweap(int sweap, int exclude = -1) @@ -659,7 +660,9 @@ struct clientstate weapwait[i] = weaptime[i] = weapload[i] = weapshot[i] = prevtime[0] = 0; if(full) ammo[i] = entid[i] = -1; } - if(full) lastweap.shrink(0); + if (full) { + lastweap.clear(); + } } void setweapstate(int weap, int state, int delay, int millis, int offtime = 0, bool blank = false) @@ -685,7 +688,7 @@ struct clientstate { if(isweap(weapselect)) { - lastweap.add(weapselect); + lastweap.emplace_back(weapselect); setweapstate(weapselect, W_S_SWITCH, delay, millis); } weapselect = weap; @@ -755,7 +758,7 @@ struct clientstate if(type != WEAPON || !isweap(attr)) return; int prev = max(ammo[attr], 0), ammoval = ammoamt >= 0 ? ammoamt : WUSE(attr); weapswitch(attr, millis, delay, W_S_USE); - ammo[attr] = clamp(prev+ammoval, 0, W(attr, ammomax)); + ammo[attr] = std::clamp(prev+ammoval, 0, W(attr, ammomax)); weapload[attr] = ammo[attr]-prev; entid[attr] = id; } @@ -830,7 +833,10 @@ struct clientstate bool canrandweap(int weap) { int cweap = weap-W_OFFSET; - if(!randweap.inrange(cweap)) return true; + if (!inrange(randweap, cweap)) { + return true; + } + return randweap[cweap]; } @@ -862,7 +868,7 @@ struct clientstate if(AA(actortype, maxcarry) && m_loadout(gamemode, mutators)) { vector aweap; - loopj(AA(actortype, maxcarry)) aweap.add(loadweap.inrange(j) ? loadweap[j] : 0); + loopj(AA(actortype, maxcarry)) aweap.add(inrange(loadweap, j) ? loadweap[j] : 0); vector rand, forcerand; for(int t = W_OFFSET; t < W_ITEM; t++) if(!hasweap(t, sweap) && m_check(W(t, modes), W(t, muts), gamemode, mutators) && !W(t, disabled) && aweap.find(t) < 0) @@ -1050,7 +1056,7 @@ struct gameent : dynent, clientstate void setparams(bool reset) { - int type = clamp(actortype, 0, int(A_MAX-1)); + int type = std::clamp(actortype, 0, int(A_MAX-1)); xradius = actor[type].xradius*curscale; yradius = actor[type].yradius*curscale; zradius = actor[type].height*curscale; @@ -1180,7 +1186,7 @@ struct gameent : dynent, clientstate { if(!isweap(weap)) weap = weapselect; if(origin == vec(-1, -1, -1)) - origin = vec(weap == W_MELEE ? feetpos() : center()).add(vec(yaw*RAD, pitch*RAD)); + origin = vec(weap == W_MELEE ? feetpos() : center()).add(vec(yaw*rad, pitch*rad)); return origin; } @@ -1206,11 +1212,11 @@ struct gameent : dynent, clientstate if(px >= 180) px -= 360; if(px < -180) px += 360; } - muzzle = vec(originpos(weap)).add(vec(yx*RAD, px*RAD).mul(8)); + muzzle = vec(originpos(weap)).add(vec(yx*rad, px*rad).mul(8)); } else { - vec dir(yaw*RAD, pitch*RAD); + vec dir(yaw*rad, pitch*rad); if(weap != W_CLAW) { vec right; @@ -1373,10 +1379,10 @@ struct gameent : dynent, clientstate colour = c; model = m; setvanity(v); - loadweap.shrink(0); - loopv(w) loadweap.add(w[i]); - randweap.shrink(0); - loopv(r) randweap.add(r[i]); + loadweap.clear(); + loopv(w) loadweap.emplace_back(w[i]); + randweap.clear(); + loopv(r) randweap.emplace_back(r[i]); } void addstun(int weap, int millis, int delay, float scale, float gravity) diff --git a/src/game/hud.cpp b/src/game/hud.cpp index e3ee8a62..efdc2fda 100644 --- a/src/game/hud.cpp +++ b/src/game/hud.cpp @@ -17,7 +17,7 @@ namespace hud vector damagelocs, hitlocs; VAR(IDF_PERSIST, damageresiduefade, 0, 500, VAR_MAX); - ICOMMAND(0, conout, "is", (int *n, char *s), conoutft(clamp(*n, 0, CON_MAX-1), "%s", s)); + ICOMMAND(0, conout, "is", (int *n, char *s), conoutft(std::clamp(*n, 0, CON_MAX-1), "%s", s)); VAR(IDF_PERSIST, showhud, 0, 1, 1); VAR(IDF_PERSIST, hudsize, 0, 2048, VAR_MAX); @@ -771,13 +771,13 @@ namespace hud case 2: amt = motionbluramt; break; default: break; } - return clamp(amt, motionblurmin, motionblurmax)*scale; + return std::clamp(amt, motionblurmin, motionblurmax)*scale; } void damage(int n, const vec &loc, gameent *v, int weap, int flags) { if(!n) return; - damageresidue = clamp(damageresidue+(n*(flags&HIT_BLEED ? 3 : 1)), 0, 200); + damageresidue = std::clamp(damageresidue+(n*(flags&HIT_BLEED ? 3 : 1)), 0, 200); int colour = radardamagecolour; if(game::nogore || game::bloodscale <= 0) colour = 0xFF44FF; else if(wr_burns(weap, flags)) colour = radardamageburncolour; @@ -957,21 +957,21 @@ namespace hud { case W_S_POWER: case W_S_ZOOM: { - amt = clamp(float(millis)/float(game::focus->weapwait[weap]), 0.f, 1.f); + amt = std::clamp(float(millis)/float(game::focus->weapwait[weap]), 0.f, 1.f); colourskew(r, g, b, amt); break; } case W_S_RELOAD: { if(showindicator < (W(weap, ammoadd) < W(weap, ammomax) ? 3 : 2)) return; - amt = 1.f-clamp(float(millis)/float(game::focus->weapwait[weap]), 0.f, 1.f); + amt = 1.f-std::clamp(float(millis)/float(game::focus->weapwait[weap]), 0.f, 1.f); colourskew(r, g, b, 1.f-amt); break; } case W_S_PRIMARY: case W_S_SECONDARY: { if(showindicator < 4 || game::focus->weapwait[weap] < indicatorminattack) return; - amt = 1.f-clamp(float(millis)/float(game::focus->weapwait[weap]), 0.f, 1.f); + amt = 1.f-std::clamp(float(millis)/float(game::focus->weapwait[weap]), 0.f, 1.f); colourskew(r, g, b, 1.f-amt); break; } @@ -985,21 +985,21 @@ namespace hud gle::colorf(val*4.f, val*4.f, val*4.f, indicatorblend*hudblend*val); drawsized(x-s, y-s, s*2); gle::colorf(r, g, b, indicatorblend*hudblend); - drawslice(0, clamp(amt, 0.f, 1.f), x, y, s); + drawslice(0, std::clamp(amt, 0.f, 1.f), x, y, s); } void vecfromyaw(float yaw, int move, int strafe, vec2 &m) { if(move) { - m.x = move*-sinf(RAD*yaw); - m.y = move*cosf(RAD*yaw); + m.x = move*-sinf(rad*yaw); + m.y = move*cosf(rad*yaw); } else m.x = m.y = 0; if(strafe) { - m.x += strafe*cosf(RAD*yaw); - m.y += strafe*sinf(RAD*yaw); + m.x += strafe*cosf(rad*yaw); + m.y += strafe*sinf(rad*yaw); } } @@ -1018,7 +1018,7 @@ namespace hud if(rotate&1) flipx = angle >= 180.f; while(rot < 0.0f) rot += 360.0f; while(rot >= 360.0f) rot -= 360.0f; - vec2 loc(x+offset*sinf(RAD*angle), y+offset*-cosf(RAD*angle)); + vec2 loc(x+offset*sinf(rad*angle), y+offset*-cosf(rad*angle)); gle::color(colour, blend); glBindTexture(GL_TEXTURE_2D, t->id); gle::defvertex(2); @@ -1077,8 +1077,8 @@ namespace hud bool simple = showclips == 1 || maxammo > 360; float fade = clipblend*hudblend, size = s*clipsize*(simple ? 1.f : clipskew[weap]), offset = s*clipoffset, amt = 0, spin = 0, slice = 360/float(maxammo), angle = (simple || maxammo > (cliprots[weap]&4 ? 4 : 3) || maxammo%2 ? 360.f : 360.f-slice*0.5f)-((maxammo-ammo)*slice), - area = 1-clamp(clipoffs[weap]*2, 1e-3f, 1.f), need = s*clipsize*clipskew[weap]*area*maxammo, have = 2*M_PI*s*clipoffset, - scale = clamp(have/need, clipminscale, clipmaxscale); + area = 1-std::clamp(clipoffs[weap]*2, 1e-3f, 1.f), need = s*clipsize*clipskew[weap]*area*maxammo, have = 2*pi*s*clipoffset, + scale = std::clamp(have/need, clipminscale, clipmaxscale); vec c(1, 1, 1); if(clipstone) skewcolour(c.r, c.g, c.b, clipstone); if(clipcolour) skewcolour(c.r, c.g, c.b, W(weap, colour)); @@ -1086,7 +1086,7 @@ namespace hud { case W_S_PRIMARY: case W_S_SECONDARY: { - amt = 1.f-clamp(interval/float(game::focus->weapwait[weap]), 0.f, 1.f); + amt = 1.f-std::clamp(interval/float(game::focus->weapwait[weap]), 0.f, 1.f); fade *= amt; if(clipanims) { @@ -1114,7 +1114,7 @@ namespace hud int check = game::focus->weapwait[weap]/2; if(interval >= check) { - amt = clamp((interval-check)/float(check), 0.f, 1.f); + amt = std::clamp((interval-check)/float(check), 0.f, 1.f); fade *= amt; if(clipanims) { @@ -1146,11 +1146,11 @@ namespace hud spin = 0; break; } - // falls through + [[fallthrough]]; } case W_S_SWITCH: { - amt = clamp(interval/float(game::focus->weapwait[weap]), 0.f, 1.f); + amt = std::clamp(interval/float(game::focus->weapwait[weap]), 0.f, 1.f); fade *= amt; if(clipanims && game::focus->weapstate[weap] != W_S_RELOAD) { @@ -1195,7 +1195,7 @@ namespace hud break; case 1: if(!m_impulsemeter(game::gamemode, game::mutators)) continue; - val = 1-clamp(float(game::focus->impulse[IM_METER])/float(impulsemeter), 0.f, 1.f); + val = 1-std::clamp(float(game::focus->impulse[IM_METER])/float(impulsemeter), 0.f, 1.f); if(circlebarimpulsetone) skewcolour(c.r, c.g, c.b, circlebarimpulsetone); break; case 2: @@ -1211,11 +1211,13 @@ namespace hud { val -= game::focus->weapload[weap]/float(W(weap, ammomax)); break; + } else if (game::focus->weapstate[weap] == W_S_RELOAD) { + break; } - else if(game::focus->weapstate[weap] == W_S_RELOAD) break; + [[fallthrough]]; case W_S_SWITCH: { - float amt = clamp(float(interval)/float(game::focus->weapwait[weap]), 0.f, 1.f); + float amt = std::clamp(float(interval)/float(game::focus->weapwait[weap]), 0.f, 1.f); fade *= amt; val *= amt; break; @@ -1244,7 +1246,7 @@ namespace hud { case W_S_PRIMARY: case W_S_SECONDARY: { - float amt = 1.f-clamp(float(interval)/float(game::focus->weapwait[weap]), 0.f, 1.f); + float amt = 1.f-std::clamp(float(interval)/float(game::focus->weapwait[weap]), 0.f, 1.f); fade *= amt; val = (game::focus->weapshot[weap] ? game::focus->weapshot[weap] : 1)/float(W(weap, ammomax))*amt; break; @@ -1256,7 +1258,7 @@ namespace hud int check = game::focus->weapwait[weap]/2; if(interval >= check) { - float amt = clamp(float(interval-check)/float(check), 0.f, 1.f); + float amt = std::clamp(float(interval-check)/float(check), 0.f, 1.f); fade *= amt; val = game::focus->weapload[weap]/float(W(weap, ammomax))*amt; } @@ -1335,12 +1337,12 @@ namespace hud if(crosshairflash && game::focus->state == CS_ALIVE && game::focus->health < heal) { int millis = lastmillis%1000; - float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); + float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*std::clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); flashcolour(c.r, c.g, c.b, 1.f, 0.f, 0.f, amt); } if(crosshairthrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime) { - float skew = clamp((lastmillis-game::focus->lastregen)/float(regentime/2), 0.f, 2.f); + float skew = std::clamp((lastmillis-game::focus->lastregen)/float(regentime/2), 0.f, 2.f); cs += int(cs*(skew > 1.f ? 1.f-skew : skew)*(crosshairthrob*(game::focus->lastregenamt >= 0 ? 1 : -1))); } if(showcrosshair >= 2) @@ -1725,7 +1727,7 @@ namespace hud switch(game::focus->icons[i].type) { case eventicon::WEAPON: colour = W(game::focus->icons[i].value, colour); break; - case eventicon::AFFINITY: colour = m_bomber(game::gamemode) ? pulsecols[PULSE_DISCO][clamp((totalmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)] : TEAM(game::focus->icons[i].value, colour); break; + case eventicon::AFFINITY: colour = m_bomber(game::gamemode) ? pulsecols[PULSE_DISCO][std::clamp((totalmillis/100)%PULSECOLOURS, 0, PULSECOLOURS-1)] : TEAM(game::focus->icons[i].value, colour); break; default: break; } glBindTexture(GL_TEXTURE_2D, t->id); @@ -1804,7 +1806,7 @@ namespace hud loopvj(refs) { int len = !full && conlines[refs[j]].type > CON_CHAT ? chatcontime/2 : chatcontime; - float f = full || !chatconfade ? 1.f : clamp(((len+chatconfade)-(totalmillis-conlines[refs[j]].reftime))/float(chatconfade), 0.f, 1.f), + float f = full || !chatconfade ? 1.f : std::clamp(((len+chatconfade)-(totalmillis-conlines[refs[j]].reftime))/float(chatconfade), 0.f, 1.f), g = conlines[refs[j]].type > CON_CHAT ? conblend : chatconblend; if(chatcondate && *chatcondateformat) tz += draw_textf("%s %s", tr, ty-tz, 0, 0, 255, 255, 255, int(fade*f*g*255), TEXT_LEFT_UP, -1, ts, 1, gettime(conlines[refs[j]].realtime, chatcondateformat), conlines[refs[j]].cref)*f; @@ -1854,7 +1856,7 @@ namespace hud loopvrev(refs) { int len = !full && conlines[refs[i]].type < CON_IMPORTANT ? contime/2 : contime; - float f = full || !confade ? 1.f : clamp(((len+confade)-(totalmillis-conlines[refs[i]].reftime))/float(confade), 0.f, 1.f), + float f = full || !confade ? 1.f : std::clamp(((len+confade)-(totalmillis-conlines[refs[i]].reftime))/float(confade), 0.f, 1.f), g = full ? fullconblend : (conlines[refs[i]].type >= CON_IMPORTANT ? selfconblend : conblend); if(condate && *condateformat) tz += draw_textf("%s %s", tr, ty+tz, 0, 0, 255, 255, 255, int(fade*f*g*255), concenter ? TEXT_CENTERED : TEXT_LEFT_JUSTIFY, -1, ts, 1, gettime(conlines[refs[i]].realtime, condateformat), conlines[refs[i]].cref)*f; @@ -2040,8 +2042,8 @@ namespace hud { if(style < 0) style = radartype(); vec dir = vec(pos).sub(camera1->o); - float dist = clamp(dir.magnitude()/float(radarrange()), 0.f, 1.f); - dir.rotate_around_z(-camera1->yaw*RAD).normalize(); + float dist = std::clamp(dir.magnitude()/float(radarrange()), 0.f, 1.f); + dir.rotate_around_z(-camera1->yaw*rad).normalize(); vec loc(0, 0, 0); if(style == 2) { @@ -2052,7 +2054,7 @@ namespace hud } else return; // can't render things we can't point at } - float yaw = -atan2(dir.x, dir.y)/RAD, x = sinf(RAD*yaw), y = -cosf(RAD*yaw), size = max(w, h)/2, + float yaw = -atan2(dir.x, dir.y)/rad, x = sinf(rad*yaw), y = -cosf(rad*yaw), size = max(w, h)/2, ts = size*(style != 3 ? radarsize : radarcornersize), tp = ts*s, tq = tp*0.5f; if(style != 2) { @@ -2206,14 +2208,14 @@ namespace hud tex = chattex; } - float fade = (force || killer || self || dominated ? 1.f : clamp(1.f-(dist/float(radarrange())), isdominated ? 0.25f : 0.f, 1.f))*blend, size = killer || self ? 1.5f : (isdominated ? 1.25f : 1.f); + float fade = (force || killer || self || dominated ? 1.f : std::clamp(1.f-(dist/float(radarrange())), isdominated ? 0.25f : 0.f, 1.f))*blend, size = killer || self ? 1.5f : (isdominated ? 1.25f : 1.f); if(!self && (d->state == CS_DEAD || d->state == CS_WAITING)) { int millis = d->lastdeath ? lastmillis-d->lastdeath : 0; if(millis > 0) { int len = min(m_delay(d->actortype, game::gamemode, game::mutators, d->team), 2500); - if(len > 0) fade *= clamp(float(len-millis)/float(len), 0.f, 1.f); + if(len > 0) fade *= std::clamp(float(len-millis)/float(len), 0.f, 1.f); else return; } else return; @@ -2222,9 +2224,9 @@ namespace hud else if(d->state == CS_ALIVE) { int len = m_protect(game::gamemode, game::mutators), millis = d->protect(lastmillis, len); - if(millis > 0) fade *= clamp(float(len-millis)/float(len), 0.f, 1.f); + if(millis > 0) fade *= std::clamp(float(len-millis)/float(len), 0.f, 1.f); if(!force && !killer && !self && !dominated) - fade *= clamp(vec(d->vel).add(d->falling).magnitude()/movespeed, 0.f, 1.f); + fade *= std::clamp(vec(d->vel).add(d->falling).magnitude()/movespeed, 0.f, 1.f); } loopi(2) { @@ -2261,7 +2263,7 @@ namespace hud } const char *tex = bliptex; vec colour(1, 1, 1); - float fade = insel ? 1.f : clamp(1.f-(dist/float(radarrange())), 0.1f, 1.f), size = radarblipsize; + float fade = insel ? 1.f : std::clamp(1.f-(dist/float(radarrange())), 0.1f, 1.f), size = radarblipsize; if(type == WEAPON) { int attr1 = w_attr(game::gamemode, game::mutators, type, attr[0], m_weapon(game::focus->actortype, game::gamemode, game::mutators)); @@ -2332,11 +2334,11 @@ namespace hud gameent *e = game::getclient(d.clientnum); if(!radardamageself && e == game::focus) continue; float amt = millis >= radardamagetime ? 1.f-(float(millis-radardamagetime)/float(radardamagefade)) : float(millis)/float(radardamagetime), - range = clamp(max(d.damage, radardamagemin)/float(max(radardamagemax-radardamagemin, 1)), radardamagemin/100.f, 1.f), - fade = clamp(radardamageblend*blend, min(radardamageblend*radardamagemin/100.f, 1.f), radardamageblend)*amt, - size = clamp(range*radardamagesize, min(radardamagesize*radardamagemin/100.f, 1.f), radardamagesize)*amt; + range = std::clamp(max(d.damage, radardamagemin)/float(max(radardamagemax-radardamagemin, 1)), radardamagemin/100.f, 1.f), + fade = std::clamp(radardamageblend*blend, min(radardamageblend*radardamagemin/100.f, 1.f), radardamageblend)*amt, + size = std::clamp(range*radardamagesize, min(radardamagesize*radardamagemin/100.f, 1.f), radardamagesize)*amt; vec dir = d.dir, colour = d.colour < 0 ? game::rescolour(game::focus, INVPULSE(d.colour)) : vec::hexcolor(d.colour); - if(e == game::focus) d.dir = vec(e->yaw*RAD, 0.f).neg(); + if(e == game::focus) d.dir = vec(e->yaw*rad, 0.f).neg(); vec o = vec(camera1->o).add(vec(dir).mul(radarrange())); if(radardamage >= 5) drawblip(hurttex, 2+size/3, w, h, size, fade, 0, o, colour, "tiny", true, "%s +%d", e ? game::colourname(e) : "?", d.damage); else drawblip(hurttex, 2+size/3, w, h, size, fade, 0, o, colour, nullptr, true); @@ -2399,7 +2401,7 @@ namespace hud { if(radartype() == 3) // right-corner radar { - vec pos = vec(camera1->o).sub(minimapcenter).mul(minimapscale).add(0.5f), dir(camera1->yaw*RAD, 0.f); + vec pos = vec(camera1->o).sub(minimapcenter).mul(minimapscale).add(0.5f), dir(camera1->yaw*rad, 0.f); float scale = radarrange(), size = max(w, h)/2, s = size*radarcorner, x = w-s*2, y = 0, q = s*2*radarcorneroffset, r = s-q; bindminimap(); gle::colorf(radarcornerbright, radarcornerbright, radarcornerbright, radarcornerblend); @@ -2408,9 +2410,9 @@ namespace hud gle::begin(GL_TRIANGLE_FAN); loopi(16) { - vec v = vec(0, -1, 0).rotate_around_z(i/16.0f*2*M_PI); + vec v = vec(0, -1, 0).rotate_around_z(i/16.0f*2*pi); gle::attribf(x + q + r*(1.0f + v.x), y + q + r*(1.0f + v.y)); - vec tc = vec(dir).rotate_around_z(i/16.0f*2*M_PI); + vec tc = vec(dir).rotate_around_z(i/16.0f*2*pi); gle::attribf(pos.x + tc.x*scale*minimapscale.x, pos.y + tc.y*scale*minimapscale.y); } gle::end(); @@ -2457,7 +2459,7 @@ namespace hud int drawprogress(int x, int y, float start, float length, float size, bool left, float r, float g, float b, float fade, float skew, const char *font, const char *text, ...) { if(skew <= 0.f) return 0; - float q = clamp(skew, 0.f, 1.f), cr = r*q, cg = g*q, cb = b*q, s = size*skew, cs = s/2, cx = left ? x+cs : x-cs, cy = y-cs; + float q = std::clamp(skew, 0.f, 1.f), cr = r*q, cg = g*q, cb = b*q, s = size*skew, cs = s/2, cx = left ? x+cs : x-cs, cy = y-cs; gle::colorf(cr, cg, cb, fade); settexture(progringtex, 3); drawslice((SDL_GetTicks()%1000)/1000.f, 0.1f, cx, cy, cs); @@ -2491,7 +2493,7 @@ namespace hud int drawbar(int x, int y, int w, int h, int type, float top, float bottom, float fade, float amt, const char *tex, const char *bgtex, int tone, float bgglow, float blend, float pulse, float throb, float throbscale, int throbcolour = -1, int throbreverse = false) { - int offset = int(w*(throb >= 0 ? throb*throbscale : 0.f)), id = clamp(type, 0, 3); + int offset = int(w*(throb >= 0 ? throb*throbscale : 0.f)), id = std::clamp(type, 0, 3); if(bgtex && *bgtex) { int glow = 0; @@ -2559,9 +2561,9 @@ namespace hud { if(skew <= 0.f || amt <= 0.f) return 0; Texture *t = textureload(inventorybartex, 3); - float q = clamp(skew, 0.f, 1.f), cr = left ? r : r*q, cg = left ? g : g*q, cb = left ? b : b*q, s = size*skew, + float q = std::clamp(skew, 0.f, 1.f), cr = left ? r : r*q, cg = left ? g : g*q, cb = left ? b : b*q, s = size*skew, w = float(t->w)/float(t->h)*s, btoff = 1-inventorybarbottom, middle = btoff-inventorybartop; - int sx = int(w), sy = int(s), so = int(sx*inventorybaroffset), cx = left ? x-so : x-sx+so, cy = y-sy+int(sy*inventorybartop), cw = sx, ch = int(sy*middle), id = clamp(type, 0, 3); + int sx = int(w), sy = int(s), so = int(sx*inventorybaroffset), cx = left ? x-so : x-sx+so, cy = y-sy+int(sy*inventorybartop), cw = sx, ch = int(sy*middle), id = std::clamp(type, 0, 3); glBindTexture(GL_TEXTURE_2D, t->id); gle::defvertex(2); gle::deftexcoord0(); @@ -2607,7 +2609,7 @@ namespace hud if(skew <= 0.f) return 0; Texture *t = tex && *tex ? textureload(tex, 3, true, false) : NULL; if(t == notexture) t = NULL; - float q = clamp(skew, 0.f, 1.f), cr = left ? r : r*q, cg = left ? g : g*q, cb = left ? b : b*q, s = size*skew, w = t ? float(t->w)/float(t->h)*s : s; + float q = std::clamp(skew, 0.f, 1.f), cr = left ? r : r*q, cg = left ? g : g*q, cb = left ? b : b*q, s = size*skew, w = t ? float(t->w)/float(t->h)*s : s; int heal = m_health(game::gamemode, game::mutators, game::focus->actortype), sy = int(s), cx = x, cy = y, cs = int(s), cw = int(w); bool pulse = inventoryflash && game::focus->state == CS_ALIVE && game::focus->health < heal; if(bg && sub == 0 && inventorybg) @@ -2619,7 +2621,7 @@ namespace hud if(pulse) { int millis = lastmillis%1000; - float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); + float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*std::clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); flashcolourf(gr, gg, gb, gf, 1.f, 0.f, 0.f, 1.f, amt); glow += int(s*inventoryglow*amt); } @@ -2712,7 +2714,7 @@ namespace hud const char *teamtexname(int team) { const char *teamtexs[T_MAX] = { teamtex, teamalphatex, teamomegatex, teamkappatex, teamsigmatex, teamtex }; - return teamtexs[clamp(team, 0, T_MAX-1)]; + return teamtexs[std::clamp(team, 0, T_MAX-1)]; } const char *privtex(int priv, int actortype) @@ -2722,7 +2724,7 @@ namespace hud { privnonetex, privplayertex, privsupportertex, privmoderatortex, privoperatortex, privadministratortex, privdevelopertex, privfoundertex }, { privnonetex, privplayertex, privlocalsupportertex, privlocalmoderatortex, privlocaloperatortex, privlocaladministratortex, privnonetex, privnonetex } }; - return privtexs[priv&PRIV_LOCAL ? 1 : 0][clamp(priv&PRIV_TYPE, 0, int(priv&PRIV_LOCAL ? PRIV_ADMINISTRATOR : PRIV_LAST))]; + return privtexs[priv&PRIV_LOCAL ? 1 : 0][std::clamp(priv&PRIV_TYPE, 0, int(priv&PRIV_LOCAL ? PRIV_ADMINISTRATOR : PRIV_LAST))]; } const char *itemtex(int type, int stype) @@ -2820,7 +2822,7 @@ namespace hud float size = s, skew = 0.f; if(game::focus->weapstate[i] == W_S_SWITCH || game::focus->weapstate[i] == W_S_USE)// && (i != game::focus->weapselect || i != lastweap)) { - float amt = clamp(float(lastmillis-game::focus->weaptime[i])/float(game::focus->weapwait[i]), 0.f, 1.f); + float amt = std::clamp(float(lastmillis-game::focus->weaptime[i])/float(game::focus->weapwait[i]), 0.f, 1.f); if(i != game::focus->weapselect) skew = game::focus->hasweap(i, sweap) ? 1.f-(amt*(1.f-inventoryskew)) : 1.f-amt; else skew = game::focus->weapstate[i] == W_S_USE ? amt : inventoryskew+(amt*(1.f-inventoryskew)); } @@ -2831,7 +2833,7 @@ namespace hud int oldy = y-sy, curammo = game::focus->ammo[i]; if(inventoryammostyle && (game::focus->weapstate[i] == W_S_RELOAD || game::focus->weapstate[i] == W_S_USE) && game::focus->weapload[i] > 0) { - int reloaded = int(curammo*clamp(float(lastmillis-game::focus->weaptime[i])/float(game::focus->weapwait[i]), 0.f, 1.f)); + int reloaded = int(curammo*std::clamp(float(lastmillis-game::focus->weaptime[i])/float(game::focus->weapwait[i]), 0.f, 1.f)); curammo = max(curammo-game::focus->weapload[i], 0); if(reloaded > curammo) curammo = reloaded; } @@ -2885,10 +2887,10 @@ namespace hud { float fade = blend*inventoryhealthblend; int heal = m_health(game::gamemode, game::mutators, game::focus->actortype); - float pulse = inventoryhealthflash ? clamp((heal-game::focus->health)/float(heal), 0.f, 1.f) : 0.f, - throb = inventoryhealththrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime ? clamp((lastmillis-game::focus->lastregen)/float(regentime), 0.f, 1.f) : -1.f; + float pulse = inventoryhealthflash ? std::clamp((heal-game::focus->health)/float(heal), 0.f, 1.f) : 0.f, + throb = inventoryhealththrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime ? std::clamp((lastmillis-game::focus->lastregen)/float(regentime), 0.f, 1.f) : -1.f; if(inventoryhealth&2) - sy += drawbar(x, y, s, size, 1, inventoryhealthbartop, inventoryhealthbarbottom, fade, clamp(game::focus->health/float(heal), 0.f, 1.f), healthtex, healthbgtex, inventorytone, inventoryhealthbgglow, inventoryhealthbgblend, pulse, throb, inventoryhealththrob, inventoryhealthflash >= 2 ? (game::focus->lastregenamt <= 0 ? 0xFF0000 : 0x00FF00) : -1, game::focus->lastregenamt <= 0); + sy += drawbar(x, y, s, size, 1, inventoryhealthbartop, inventoryhealthbarbottom, fade, std::clamp(game::focus->health/float(heal), 0.f, 1.f), healthtex, healthbgtex, inventorytone, inventoryhealthbgglow, inventoryhealthbgblend, pulse, throb, inventoryhealththrob, inventoryhealthflash >= 2 ? (game::focus->lastregenamt <= 0 ? 0xFF0000 : 0x00FF00) : -1, game::focus->lastregenamt <= 0); if(inventoryhealth&1) { float gr = 1, gg = 1, gb = 1; @@ -2913,12 +2915,12 @@ namespace hud } if(game::focus->actortype < A_ENEMY && physics::allowimpulse(game::focus) && m_impulsemeter(game::gamemode, game::mutators) && inventoryimpulse) { - float fade = blend*inventoryimpulseblend, span = 1-clamp(float(game::focus->impulse[IM_METER])/float(impulsemeter), 0.f, 1.f), + float fade = blend*inventoryimpulseblend, span = 1-std::clamp(float(game::focus->impulse[IM_METER])/float(impulsemeter), 0.f, 1.f), pulse = inventoryimpulseflash && game::focus->impulse[IM_METER] ? 1-span : 0.f, - throb = game::canregenimpulse(game::focus) && game::focus->impulse[IM_METER] > 0 && game::focus->lastimpulsecollect ? clamp(((lastmillis-game::focus->lastimpulsecollect)%1000)/1000.f, 0.f, 1.f) : -1.f, + throb = game::canregenimpulse(game::focus) && game::focus->impulse[IM_METER] > 0 && game::focus->lastimpulsecollect ? std::clamp(((lastmillis-game::focus->lastimpulsecollect)%1000)/1000.f, 0.f, 1.f) : -1.f, gr = 1, gg = 1, gb = 1; flashcolour(gr, gg, gb, 0.25f, 0.25f, 0.25f, 1-span); - if(pulse > 0 && impulsemeter-game::focus->impulse[IM_METER] < impulsecost) flashcolour(gr, gg, gb, 1.f, 0.f, 0.f, clamp(lastmillis%1000/1000.f, 0.f, 1.f)); + if(pulse > 0 && impulsemeter-game::focus->impulse[IM_METER] < impulsecost) flashcolour(gr, gg, gb, 1.f, 0.f, 0.f, std::clamp(lastmillis%1000/1000.f, 0.f, 1.f)); if(inventoryimpulse&2) sy += drawbar(x, y-sy, s, size, 2, inventoryimpulsebartop, inventoryimpulsebarbottom, fade, span, impulsetex, impulsebgtex, inventorytone, inventoryimpulsebgglow, inventoryimpulsebgblend, pulse, throb, inventoryimpulsethrob, inventoryimpulseflash >= 2 ? 0xFFFFFF : -1); if(inventoryimpulse&1) @@ -3170,9 +3172,12 @@ namespace hud { case 3: cy[1] -= draw_textf("%d max", cx[1], cy[1], 0, 0, 255, 255, 255, bf, TEXT_RIGHT_UP, -1, bs, 1, maxfps); + break; case 2: cy[1] -= draw_textf("+%d-%d range", cx[1], cy[1], 0, 0, 255, 255, 255, bf, TEXT_RIGHT_UP, -1, bs, 1, maxfps, curstats[9], curstats[10]); - default: break; + break; + default: + break; } } @@ -3622,7 +3627,7 @@ namespace hud void update(int w, int h) { aspect = forceaspect ? forceaspect : w/float(h); - fovy = 2*atan2(tan(curfov/2*RAD), aspect)/RAD; + fovy = 2*atan2(tan(curfov/2*rad), aspect)/rad; if(aspect > 1) { hudheight = hudsize; diff --git a/src/game/physics.cpp b/src/game/physics.cpp index 7f7231ad..d244a984 100644 --- a/src/game/physics.cpp +++ b/src/game/physics.cpp @@ -241,7 +241,7 @@ namespace physics if(gameent::is(d)) { gameent *e = (gameent *)d; - vel *= 1.f-clamp(e->stunned(lastmillis), 0.f, 1.f); + vel *= 1.f-std::clamp(e->stunned(lastmillis), 0.f, 1.f); } return vel; } @@ -252,7 +252,7 @@ namespace physics if(gameent::is(d)) { gameent *e = (gameent *)d; - vel *= 1.f-clamp(e->stunned(lastmillis, true), 0.f, 1.f); + vel *= 1.f-std::clamp(e->stunned(lastmillis, true), 0.f, 1.f); } return vel; } @@ -299,7 +299,7 @@ namespace physics if(gameent::is(pl)) { gameent *e = (gameent *)pl; - vel *= movespeed/100.f*(1.f-clamp(e->stunned(lastmillis), 0.f, 1.f)); + vel *= movespeed/100.f*(1.f-std::clamp(e->stunned(lastmillis), 0.f, 1.f)); if((d->physstate >= PHYS_SLOPE || d->onladder) && !e->sliding(true) && e->crouching()) vel *= movecrawl; else if(isweap(e->weapselect) && e->weapstate[e->weapselect] == W_S_ZOOM) vel *= movecrawl; if(e->move >= 0) vel *= e->strafe ? movestrafe : movestraight; @@ -327,7 +327,7 @@ namespace physics if(gameent::is(d)) { gameent *e = (gameent *)d; - scale *= 1.f-clamp(e->stunned(lastmillis), 0.f, 1.f); + scale *= 1.f-std::clamp(e->stunned(lastmillis), 0.f, 1.f); if(carryaffinity(e)) { if(m_capture(game::gamemode)) scale *= capturecarryspeed; @@ -816,7 +816,7 @@ namespace physics } if(d->hasmelee(lastmillis, true, d->sliding(true), onfloor)) { - vec oldpos = d->o, dir(d->yaw*RAD, 0.f); + vec oldpos = d->o, dir(d->yaw*rad, 0.f); d->o.add(dir); bool collided = collide(d, dir); d->o = oldpos; @@ -1032,7 +1032,7 @@ namespace physics if(liquid || pl->physstate >= PHYS_SLOPE) { float coast = liquid ? liquidmerge(pl, PHYS(aircoast), PHYS(liquidcoast)) : PHYS(floorcoast)*coastscale(pl->feetpos(-1)), - c = liquid ? 1.0f : clamp((pl->floor.z - slopez)/(floorz-slopez), 0.0f, 1.0f); + c = liquid ? 1.0f : std::clamp((pl->floor.z - slopez)/(floorz-slopez), 0.0f, 1.0f); pl->falling.mul(pow(max(1.0f - c/coast, 0.0f), curtime/20.0f)); } } @@ -1050,7 +1050,7 @@ namespace physics { \ int col = (int(mcol[2]*mq) + (int(mcol[1]*mq) << 8) + (int(mcol[0]*mq) << 16)); \ regularshape(mp, mt, col, 21, 20, mz, mo, ms, 1, 10, 0, 20); \ - if(mw >= 0) playsound(mw, mo, pl); \ + if((mw) >= 0) playsound(mw, mo, pl); \ } if(curmat == MAT_WATER || oldmat == MAT_WATER) { @@ -1429,12 +1429,12 @@ namespace physics doposchk; if(gameent::is(d)) loopk(18) { - vec dir = vec(d->yaw*RAD, d->pitch*RAD).rotate_around_z(k*20.f*RAD); + vec dir = vec(d->yaw*rad, d->pitch*rad).rotate_around_z(k*20.f*rad); if(!dir.iszero()) inmapchk(100, d->o.add(vec(dir).mul(n/10.f+maxrad))); } if(!d->vel.iszero()) loopk(18) { - vec dir = vec(d->vel).normalize().rotate_around_z(k*20.f*RAD); + vec dir = vec(d->vel).normalize().rotate_around_z(k*20.f*rad); inmapchk(100, d->o.add(vec(dir).mul(n/10.f+maxrad))); } inmapchk(100, d->o.add(vec((rnd(21)-10)/10.f, (rnd(21)-10)/10.f, (rnd(21)-10)/10.f).normalize().mul(vec(n/10.f+maxrad, n/10.f+maxrad, n/25.f+maxrad)))); diff --git a/src/game/projs.cpp b/src/game/projs.cpp index 2d72c1ef..f8a335eb 100644 --- a/src/game/projs.cpp +++ b/src/game/projs.cpp @@ -80,7 +80,7 @@ namespace projs flags |= HIT_WAVE; } - float skew = clamp(scale, 0.f, 1.f)*damagescale; + float skew = std::clamp(scale, 0.f, 1.f)*damagescale; if(flags&HIT_WHIPLASH) skew *= WF(WK(flags), weap, damagewhiplash, WS(flags)); else if(flags&HIT_HEAD) skew *= WF(WK(flags), weap, damagehead, WS(flags)); @@ -88,9 +88,9 @@ namespace projs else if(flags&HIT_LEGS) skew *= WF(WK(flags), weap, damagelegs, WS(flags)); else return 0; - if(radial > 0) skew *= clamp(1.f-dist/size, 1e-6f, 1.f); + if(radial > 0) skew *= std::clamp(1.f-dist/size, 1e-6f, 1.f); else if(WF(WK(flags), weap, taper, WS(flags))) - skew *= clamp(dist, WF(WK(flags), weap, tapermin, WS(flags)), WF(WK(flags), weap, tapermax, WS(flags))); + skew *= std::clamp(dist, WF(WK(flags), weap, tapermin, WS(flags)), WF(WK(flags), weap, tapermax, WS(flags))); if(!m_insta(game::gamemode, game::mutators)) { @@ -375,10 +375,10 @@ namespace projs else { proj.o = proj.stickpos; - proj.o.rotate_around_z(proj.stick->yaw*RAD); + proj.o.rotate_around_z(proj.stick->yaw*rad); proj.o.add(proj.stick->center()); proj.norm = proj.sticknrm; - proj.norm.rotate_around_z(proj.stick->yaw*RAD); + proj.norm.rotate_around_z(proj.stick->yaw*rad); proj.vel = vec(proj.stick->vel).add(proj.stick->falling); updatenormal(proj); return true; @@ -412,8 +412,8 @@ namespace projs if(proj.stick) { proj.stickpos.sub(proj.stick->center()).normalize().mul(vec(proj.stick->xradius*1.1f, proj.stick->yradius*1.1f, proj.stick->height*0.6f)); - proj.stickpos.rotate_around_z(-proj.stick->yaw*RAD); - proj.sticknrm.rotate_around_z(-proj.stick->yaw*RAD); + proj.stickpos.rotate_around_z(-proj.stick->yaw*rad); + proj.sticknrm.rotate_around_z(-proj.stick->yaw*rad); } if(updatesticky(proj, true) && proj.projtype == PRJ_SHOT) client::addmsg(N_STICKY, "ri9i3", @@ -621,7 +621,7 @@ namespace projs } if(ricochet && !proj.limited && !WK(proj.flags)) { - int vol = clamp(int(proj.vel.magnitude()*proj.curscale)*2, 0, 255); + int vol = std::clamp(int(proj.vel.magnitude()*proj.curscale)*2, 0, 255); if(vol > 0) playsound(WSND2(proj.weap, WS(proj.flags), S_W_BOUNCE), proj.o, NULL, 0, vol); } break; @@ -631,15 +631,16 @@ namespace projs if(game::nogore == 2) break; if(game::nogore || game::bloodscale > 0) { - adddecal(DECAL_BLOOD, proj.o, proj.norm, proj.radius*clamp(proj.vel.magnitude()/2, 1.f, 4.f), bvec(125, 255, 255)); - int vol = clamp(int(proj.vel.magnitude()*proj.curscale)*2, 0, 255); + adddecal(DECAL_BLOOD, proj.o, proj.norm, proj.radius*std::clamp(proj.vel.magnitude()/2, 1.f, 4.f), bvec(125, 255, 255)); + int vol = std::clamp(int(proj.vel.magnitude()*proj.curscale)*2, 0, 255); if(vol > 0) playsound(S_SPLOSH, proj.o, NULL, 0, vol); break; - } // otherwise fall through + } + [[fallthrough]]; } case PRJ_DEBRIS: case PRJ_VANITY: { - int vol = clamp(int(proj.vel.magnitude()*proj.curscale)*2, 0, 255); + int vol = std::clamp(int(proj.vel.magnitude()*proj.curscale)*2, 0, 255); if(vol > 0) { if(proj.projtype == PRJ_VANITY) vol /= 2; @@ -649,7 +650,7 @@ namespace projs } case PRJ_EJECT: case PRJ_AFFINITY: { - int vol = clamp(int(proj.vel.magnitude()*proj.curscale)*3, proj.projtype == PRJ_AFFINITY ? 32 : 0, 255); + int vol = std::clamp(int(proj.vel.magnitude()*proj.curscale)*3, proj.projtype == PRJ_AFFINITY ? 32 : 0, 255); if(vol > 0) playsound(proj.projtype == PRJ_EJECT ? int(S_SHELL) : int(S_BOUNCE), proj.o, NULL, 0, vol); break; } @@ -709,7 +710,7 @@ namespace projs static const int sphereyawchecks[8] = { 180, 135, 225, 90, 270, 45, 315 }, spherepitchchecks[5] = { 0, 45, -45, 89, -89 }; loopi(2) loopj(5) loopk(8) { - proj.o.add(vec((int(yaw+sphereyawchecks[k])%360)*RAD, spherepitchchecks[j]*RAD).mul(proj.radius*(i+1)*2)); + proj.o.add(vec((int(yaw+sphereyawchecks[k])%360)*rad, spherepitchchecks[j]*rad).mul(proj.radius*(i+1)*2)); if(!collide(&proj, dir, 1e-6f, false) && !collideinside) { if(rev) @@ -732,22 +733,29 @@ namespace projs float size = 1; switch(proj.projtype) { - case PRJ_AFFINITY: break; - case PRJ_GIBS: case PRJ_DEBRIS: case PRJ_EJECT: case PRJ_VANITY: size = proj.lifesize; - case PRJ_ENT: - if(init) break; - else if(proj.lifemillis && proj.fadetime) - { - int interval = min(proj.lifemillis, proj.fadetime); - if(proj.lifetime < interval) - { - size *= float(proj.lifetime)/float(interval); - break; - } - } // all falls through to .. - default: return false; + case PRJ_AFFINITY: + break; + case PRJ_GIBS: + case PRJ_DEBRIS: + case PRJ_EJECT: + case PRJ_VANITY: + size = proj.lifesize; + [[fallthrough]]; + case PRJ_ENT: + if (init) + break; + else if (proj.lifemillis && proj.fadetime) { + int interval = min(proj.lifemillis, proj.fadetime); + if (proj.lifetime < interval) { + size *= float(proj.lifetime) / float(interval); + break; + } + } + [[fallthrough]]; + default: + return false; } - size = clamp(size*proj.curscale, 0.1f, 1.f); + size = std::clamp(size*proj.curscale, 0.1f, 1.f); model *m = NULL; if(proj.mdl && *proj.mdl && ((m = loadmodel(proj.mdl)) != NULL)) { @@ -787,7 +795,7 @@ namespace projs proj.from = proj.to = proj.owner->center(); if(proj.target && proj.target->state == CS_ALIVE) proj.to.add(vec(proj.target->center()).sub(proj.from).normalize().mul(proj.owner->radius*2.f)); - else proj.to.add(vec(proj.owner->yaw*RAD, proj.owner->pitch*RAD).mul(proj.owner->radius*2.f)); + else proj.to.add(vec(proj.owner->yaw*rad, proj.owner->pitch*rad).mul(proj.owner->radius*2.f)); } else { @@ -883,7 +891,8 @@ namespace projs proj.extinguish = 6; proj.interacts = 3; break; - } // otherwise fall through + } + [[fallthrough]]; } case PRJ_DEBRIS: { @@ -956,7 +965,7 @@ namespace projs float mag = proj.inertia.magnitude(); if(mag <= 50) { - if(mag <= 0) proj.inertia = vec(proj.yaw*RAD, proj.pitch*RAD); + if(mag <= 0) proj.inertia = vec(proj.yaw*rad, proj.pitch*rad); proj.inertia.normalize().mul(50); } proj.to.add(proj.inertia); @@ -1075,7 +1084,7 @@ namespace projs proj.yaw = proj.owner->yaw; proj.pitch = proj.owner->pitch; } - dir = vec(proj.yaw*RAD, proj.pitch*RAD); + dir = vec(proj.yaw*rad, proj.pitch*rad); } vec rel = vec(proj.vel).add(dir).add(proj.inertia.mul(proj.relativity)); proj.vel = vec(rel).add(vec(dir).mul(physics::movevelocity(&proj))); @@ -1171,7 +1180,7 @@ namespace projs if(weaptype[weap].sound >= 0 && (weap != W_MELEE || !(WS(flags)))) { - int slot = WSNDF(weap, WS(flags)), vol = clamp(int(ceilf(255*skew)), 0, 255); + int slot = WSNDF(weap, WS(flags)), vol = std::clamp(int(ceilf(255*skew)), 0, 255); if(slot >= 0 && vol > 0) { if(weap == W_FLAMER && !(WS(flags))) @@ -1230,7 +1239,7 @@ namespace projs } loopv(shots) create(from, vec(shots[i].pos).div(DMF), local, d, PRJ_SHOT, weap, flags, max(life, 1), W2(weap, time, WS(flags)), delay+(iter*i), speed, shots[i].id, weap, -1, flags, skew); - if(ejectfade && weaptype[weap].eject && *weaptype[weap].eprj) loopi(clamp(sub, 1, W2(weap, ammosub, WS(flags)))) + if(ejectfade && weaptype[weap].eject && *weaptype[weap].eprj) loopi(std::clamp(sub, 1, W2(weap, ammosub, WS(flags)))) create(from, from, local, d, PRJ_EJECT, -1, HIT_NONE, rnd(ejectfade)+ejectfade, 0, delay, rnd(weaptype[weap].espeed)+weaptype[weap].espeed, 0, weap, -1, flags); d->setweapstate(weap, WS(flags) ? W_S_SECONDARY : W_S_PRIMARY, delayattack, lastmillis); @@ -1240,7 +1249,7 @@ namespace projs d->lastshoot = lastmillis; if(AA(d->actortype, abilities)&(1<yaw*RAD, d->pitch*RAD).mul(-W2(weap, kickpush, WS(flags))*skew); + vec kick = vec(d->yaw*rad, d->pitch*rad).mul(-W2(weap, kickpush, WS(flags))*skew); if(!kick.iszero()) { if(d == game::focus) game::swaypush.add(vec(kick).mul(kickpushsway)); @@ -1273,14 +1282,14 @@ namespace projs if(type%2 || !proj.stuck) { float dist = 1-((distance-WF(WK(proj.flags), proj.weap, taperin, WS(proj.flags)))/WF(WK(proj.flags), proj.weap, taperout, WS(proj.flags))); - proj.lifesize = clamp(dist, WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); + proj.lifesize = std::clamp(dist, WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); } break; } } if(WF(WK(proj.flags), proj.weap, taperin, WS(proj.flags)) > 0 && distance < WF(WK(proj.flags), proj.weap, taperin, WS(proj.flags))) { - proj.lifesize = clamp(distance/WF(WK(proj.flags), proj.weap, taperin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); + proj.lifesize = std::clamp(distance/WF(WK(proj.flags), proj.weap, taperin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); break; } proj.lifesize = WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags)); @@ -1312,13 +1321,13 @@ namespace projs } if(proj.lifespan < spanin) { - proj.lifesize = clamp(proj.lifespan/spanin, WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); + proj.lifesize = std::clamp(proj.lifespan/spanin, WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); break; } else if(proj.lifespan >= (1-spanout)) { if(type%2 || !proj.stuck) - proj.lifesize = clamp(1-((proj.lifespan-(1-spanout))/spanout), WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); + proj.lifesize = std::clamp(1-((proj.lifespan-(1-spanout))/spanout), WF(WK(proj.flags), proj.weap, tapermin, WS(proj.flags)), WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags))); break; } proj.lifesize = WF(WK(proj.flags), proj.weap, tapermax, WS(proj.flags)); @@ -1330,7 +1339,7 @@ namespace projs void iter(projent &proj) { - proj.lifespan = clamp((proj.lifemillis-proj.lifetime)/float(max(proj.lifemillis, 1)), 0.f, 1.f); + proj.lifespan = std::clamp((proj.lifemillis-proj.lifetime)/float(max(proj.lifemillis, 1)), 0.f, 1.f); if(proj.target && proj.target->state != CS_ALIVE) proj.target = NULL; updatesticky(proj); if(proj.projtype == PRJ_SHOT) @@ -1358,11 +1367,11 @@ namespace projs float trans = fadeweap(proj)*WF(WK(proj.flags), proj.weap, partblend, WS(proj.flags)); if(!proj.limited && !WK(proj.flags) && proj.weap != W_MELEE) { - int vol = clamp(int(ceilf(255*proj.curscale)), 0, 255); + int vol = std::clamp(int(ceilf(255*proj.curscale)), 0, 255); if(W2(proj.weap, cooktime, WS(proj.flags))) switch(W2(proj.weap, cooked, WS(proj.flags))) { - case 4: case 5: vol = clamp(10+int(245*(1.f-proj.lifespan)*proj.lifesize*proj.curscale), 0, 255); break; // longer - case 1: case 2: case 3: default: vol = clamp(10+int(245*proj.lifespan*proj.lifesize*proj.curscale), 0, 255); break; // shorter + case 4: case 5: vol = std::clamp(10+int(245*(1.f-proj.lifespan)*proj.lifesize*proj.curscale), 0, 255); break; // longer + case 1: case 2: case 3: default: vol = std::clamp(10+int(245*proj.lifespan*proj.lifesize*proj.curscale), 0, 255); break; // shorter } if(issound(proj.schan)) sounds[proj.schan].vol = vol; else if(vol > 0) playsound(WSND2(proj.weap, WS(proj.flags), S_W_TRANSIT), proj.o, &proj, SND_LOOP, vol, -1, -1, &proj.schan); @@ -1395,24 +1404,24 @@ namespace projs } case W_PISTOL: { - float size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); + float size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); if(proj.lastbounce) size = min(size, max(proj.movement, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale)); if(size > 0) { proj.to = vec(proj.o).sub(vec(proj.vel).normalize().mul(size)); - part_flare(proj.to, proj.o, 1, PART_MUZZLE_FLARE, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*trans); + part_flare(proj.to, proj.o, 1, PART_MUZZLE_FLARE, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*trans); if(projhints) { - part_flare(proj.to, proj.o, 1, PART_MUZZLE_FLARE, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*projhintsize*proj.curscale, clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*projhintblend*trans); - part_create(PART_HINT_SOFT, 1, proj.o, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*projhintsize*proj.curscale, clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*projhintblend*trans); + part_flare(proj.to, proj.o, 1, PART_MUZZLE_FLARE, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*projhintsize*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*projhintblend*trans); + part_create(PART_HINT_SOFT, 1, proj.o, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*projhintsize*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*projhintblend*trans); } } break; } case W_FLAMER: { - float blend = clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*(0.6f+(rnd(40)/100.f))*trans, - size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); + float blend = std::clamp(1.25f-proj.lifespan, 0.35f, 0.85f)*(0.6f+(rnd(40)/100.f))*trans, + size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); if(proj.lastbounce) size = min(size, max(proj.movement, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale)); if(projfirehint) part_create(PART_HINT_SOFT, 1, proj.o, projhint(proj.owner, 0x120228), size*projfirehintsize, blend*projhintblend); if(projtrails && lastmillis-proj.lasteffect >= projtraildelay) @@ -1469,28 +1478,28 @@ namespace projs } else { - float size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); + float size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); if(proj.lastbounce) size = min(size, max(proj.movement, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale)); if(size > 0) { proj.to = vec(proj.o).sub(vec(proj.vel).normalize().mul(size)); - part_flare(proj.to, proj.o, 1, PART_FLARE, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, clamp(1.25f-proj.lifespan, 0.5f, 1.f)*trans); - if(projhints) part_flare(proj.to, proj.o, 1, PART_FLARE, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*projhintsize*proj.curscale, clamp(1.25f-proj.lifespan, 0.5f, 1.f)*projhintblend*trans); + part_flare(proj.to, proj.o, 1, PART_FLARE, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.5f, 1.f)*trans); + if(projhints) part_flare(proj.to, proj.o, 1, PART_FLARE, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*projhintsize*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.5f, 1.f)*projhintblend*trans); } } break; } case W_SMG: { - float size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); + float size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(proj.from))); if(proj.lastbounce) size = min(size, max(proj.movement, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale)); if(size > 0) { proj.to = vec(proj.o).sub(vec(proj.vel).normalize().mul(size)); if(!proj.stuck) { - part_flare(proj.to, proj.o, 1, PART_FLARE, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, clamp(1.25f-proj.lifespan, 0.5f, 1.f)*trans); - if(projhints) part_flare(proj.to, proj.o, 1, PART_FLARE, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*projhintsize*proj.curscale, clamp(1.25f-proj.lifespan, 0.5f, 1.f)*projhintblend*trans); + part_flare(proj.to, proj.o, 1, PART_FLARE, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.5f, 1.f)*trans); + if(projhints) part_flare(proj.to, proj.o, 1, PART_FLARE, projhint(proj.owner, FWCOL(H, partcol, proj)), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*(1.f-proj.lifespan)*projhintsize*proj.curscale, std::clamp(1.25f-proj.lifespan, 0.5f, 1.f)*projhintblend*trans); } if(proj.stuck || (!WK(proj.flags) && W2(proj.weap, fragweap, WS(proj.flags)) >= 0)) { @@ -1523,7 +1532,7 @@ namespace projs case W_RIFLE: case W_ZAPPER: { vec from = type != W_ZAPPER || !proj.owner || proj.owner->weapselect != proj.weap || WK(proj.flags) ? proj.from : proj.owner->muzzlepos(proj.weap); - float size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(from))); + float size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(from))); if(proj.lastbounce) size = min(size, max(proj.movement, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale)); if(size > 0) { @@ -1576,7 +1585,7 @@ namespace projs if(!proj.limited) { bool effect = false; - float radius = (proj.radius+0.5f)*(clamp(1.f-proj.lifespan, 0.1f, 1.f)+0.25f), blend = clamp(1.25f-proj.lifespan, 0.25f, 1.f)*(0.75f+(rnd(25)/100.f)); // gets smaller as it gets older + float radius = (proj.radius+0.5f)*(std::clamp(1.f-proj.lifespan, 0.1f, 1.f)+0.25f), blend = std::clamp(1.25f-proj.lifespan, 0.25f, 1.f)*(0.75f+(rnd(25)/100.f)); // gets smaller as it gets older if(projtrails && lastmillis-proj.lasteffect >= projtraildelay) { effect = true; proj.lasteffect = lastmillis - (lastmillis%projtraildelay); } int len = effect ? max(int(projtraillength*0.5f*max(1.f-proj.lifespan, 0.1f)), 1) : 1, colour = !proj.id && isweap(proj.weap) ? FWCOL(H, explcol, proj) : pulsecols[PULSE_FIRE][rnd(PULSECOLOURS)]; @@ -1587,13 +1596,14 @@ namespace projs case PRJ_EJECT: { if(isweap(proj.weap) && ejecthint) - part_create(PART_HINT_SOFT, 1, proj.o, W(proj.weap, colour), max(proj.xradius, proj.yradius)*1.25f, clamp(1.f-proj.lifespan, 0.1f, 1.f)*0.35f); + part_create(PART_HINT_SOFT, 1, proj.o, W(proj.weap, colour), max(proj.xradius, proj.yradius)*1.25f, std::clamp(1.f-proj.lifespan, 0.1f, 1.f)*0.35f); bool moving = proj.movement >= 1; if(moving && lastmillis-proj.lasteffect >= 100) { - part_create(PART_SMOKE, 75, proj.o, 0x222222, max(proj.xradius, proj.yradius), clamp(1.f-proj.lifespan, 0.1f, 1.f)*0.35f, -3); + part_create(PART_SMOKE, 75, proj.o, 0x222222, max(proj.xradius, proj.yradius), std::clamp(1.f-proj.lifespan, 0.1f, 1.f)*0.35f, -3); proj.lasteffect = lastmillis - (lastmillis%100); } + break; } case PRJ_AFFINITY: { @@ -1614,7 +1624,7 @@ namespace projs void destroy(projent &proj) { - proj.lifespan = clamp((proj.lifemillis-proj.lifetime)/float(max(proj.lifemillis, 1)), 0.f, 1.f); + proj.lifespan = std::clamp((proj.lifemillis-proj.lifetime)/float(max(proj.lifemillis, 1)), 0.f, 1.f); if(proj.projcollide&COLLIDE_PROJ) { collideprojs.removeobj(&proj); @@ -1625,12 +1635,12 @@ namespace projs case PRJ_SHOT: { updatetargets(proj, 2); - int vol = clamp(int(255*proj.curscale), 0, 255), type = WF(WK(proj.flags), proj.weap, parttype, WS(proj.flags)), len = W2(proj.weap, partfade, WS(proj.flags)); + int vol = std::clamp(int(255*proj.curscale), 0, 255), type = WF(WK(proj.flags), proj.weap, parttype, WS(proj.flags)), len = W2(proj.weap, partfade, WS(proj.flags)); if(!proj.limited) switch(type) { case W_PISTOL: { - vol = clamp(int(vol*(1.f-proj.lifespan)), 0, 255); + vol = std::clamp(int(vol*(1.f-proj.lifespan)), 0, 255); part_create(PART_SMOKE_LERP, len*2, proj.o, 0x999999, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, 0.5f*WF(WK(proj.flags), proj.weap, partblend, WS(proj.flags)), -20); float expl = WX(WK(proj.flags), proj.weap, explode, WS(proj.flags), game::gamemode, game::mutators, proj.curscale*proj.lifesize); if(expl > 0) @@ -1676,7 +1686,7 @@ namespace projs } case W_SHOTGUN: case W_SMG: { - vol = clamp(int(vol*(1.f-proj.lifespan)), 0, 255); + vol = std::clamp(int(vol*(1.f-proj.lifespan)), 0, 255); part_splash(PART_SPARK, type == W_SHOTGUN ? 5 : 3, len*2, proj.o, FWCOL(H, partcol, proj), WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale*0.5f, WF(WK(proj.flags), proj.weap, partblend, WS(proj.flags)), 1, 0, 16, 15); float expl = WX(WK(proj.flags), proj.weap, explode, WS(proj.flags), game::gamemode, game::mutators, proj.curscale*proj.lifesize); if(expl > 0) @@ -1712,7 +1722,7 @@ namespace projs { vec from = type != W_ZAPPER || !proj.owner || proj.owner->weapselect != proj.weap || WK(proj.flags) ? proj.from : proj.owner->muzzlepos(proj.weap); float expl = WX(WK(proj.flags), proj.weap, explode, WS(proj.flags), game::gamemode, game::mutators, proj.curscale*proj.lifesize), - size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(from))); + size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale, min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.o.dist(from))); if(proj.lastbounce) size = min(size, max(proj.movement, WF(WK(proj.flags), proj.weap, partsize, WS(proj.flags))*proj.curscale)); if(size > 0) { @@ -1803,12 +1813,12 @@ namespace projs { if(chk&1 && !proj.limited && !WK(proj.flags) && proj.weap != W_MELEE) { - int vol = clamp(int(ceilf(48*proj.curscale)), 0, 255), snd = S_EXTINGUISH; + int vol = std::clamp(int(ceilf(48*proj.curscale)), 0, 255), snd = S_EXTINGUISH; float size = max(proj.radius, 1.f); if(proj.projtype == PRJ_SHOT && isweap(proj.weap)) { snd = WSND2(proj.weap, WS(proj.flags), S_W_EXTINGUISH); - vol = clamp(10+int(245*proj.lifespan*proj.lifesize*proj.curscale), 0, 255); + vol = std::clamp(10+int(245*proj.lifespan*proj.lifesize*proj.curscale), 0, 255); float expl = WX(WK(proj.flags), proj.weap, explode, WS(proj.flags), game::gamemode, game::mutators, proj.curscale*proj.lifesize); if(expl > 0) size *= expl*1.5f; else size *= 2.5f; @@ -1883,7 +1893,7 @@ namespace projs } default: break; } - e->vel = vec(yaw*RAD, pitch*RAD).mul(mag).add(keepvel); + e->vel = vec(yaw*rad, pitch*rad).mul(mag).add(keepvel); e->doimpulse(cost, IM_T_GRAB, lastmillis); client::addmsg(N_SPHY, "ri2", e->clientnum, SPHY_GRAB); game::impulseeffect(e); @@ -2015,19 +2025,22 @@ namespace projs } } - float dist = proj.o.dist(pos), diff = dist/float(4*RAD); + float dist = proj.o.dist(pos), diff = dist/float(4*rad); if(!blocked) proj.movement += dist; proj.distance += dist; switch(proj.projtype) { case PRJ_SHOT: { - if(proj.stuck) break; - if(proj.weap == W_MINE) + if(proj.stuck) { + break; + } + + if (proj.weap == W_MINE) { if(!proj.lastbounce || proj.movement >= 1) { - vec axis(sinf(proj.yaw*RAD), -cosf(proj.yaw*RAD), 0); + vec axis(sinf(proj.yaw*rad), -cosf(proj.yaw*rad), 0); if(proj.vel.dot2(axis) >= 0) { proj.pitch -= diff; if(proj.pitch < -180) proj.pitch = 180 - fmod(180 - proj.pitch, 360); } else { proj.pitch += diff; if(proj.pitch > 180) proj.pitch = fmod(proj.pitch + 180, 360) - 180; } break; @@ -2044,7 +2057,10 @@ namespace projs vectoyawpitch(vec(proj.vel).normalize(), proj.yaw, proj.pitch); break; } - if(proj.weap != W_GRENADE) break; + if (proj.weap != W_GRENADE) { + break; + } + [[fallthrough]]; } case PRJ_DEBRIS: case PRJ_GIBS: case PRJ_AFFINITY: case PRJ_VANITY: { @@ -2053,20 +2069,23 @@ namespace projs float yaw = proj.yaw, pitch = proj.pitch, speed = diff*secs; vectoyawpitch(vec(proj.vel).normalize(), yaw, pitch); game::scaleyawpitch(proj.yaw, proj.pitch, yaw, pitch, speed, speed); - vec axis(sinf(proj.yaw*RAD), -cosf(proj.yaw*RAD), 0); + vec axis(sinf(proj.yaw*rad), -cosf(proj.yaw*rad), 0); if(proj.vel.dot2(axis) >= 0) { proj.roll -= diff; if(proj.roll < -180) proj.roll = 180 - fmod(180 - proj.roll, 360); } else { proj.roll += diff; if(proj.roll > 180) proj.roll = fmod(proj.roll + 180, 360) - 180; } } - if(proj.projtype != PRJ_VANITY) break; + if (proj.projtype != PRJ_VANITY) + break; + + [[fallthrough]]; } case PRJ_EJECT: if(!proj.lastbounce || proj.movement >= 1) { - vec axis(sinf(proj.yaw*RAD), -cosf(proj.yaw*RAD), 0); + vec axis(sinf(proj.yaw*rad), -cosf(proj.yaw*rad), 0); if(proj.vel.dot2(axis) >= 0) { proj.pitch -= diff; if(proj.pitch < -180) proj.pitch = 180 - fmod(180 - proj.pitch, 360); } else { proj.pitch += diff; if(proj.pitch > 180) proj.pitch = fmod(proj.pitch + 180, 360) - 180; } - break; } + break; case PRJ_ENT: { if(proj.pitch != 0) @@ -2095,7 +2114,7 @@ namespace projs if(!targ.iszero()) { vec dir = vec(proj.vel).normalize(); - float amt = clamp(bomberspeeddelta*secs, 1e-8f, 1.f), mag = max(proj.vel.magnitude(), bomberspeedmin); + float amt = std::clamp(bomberspeeddelta*secs, 1e-8f, 1.f), mag = max(proj.vel.magnitude(), bomberspeedmin); if(bomberspeedmax > 0) mag = min(mag, bomberspeedmax); dir.mul(1.f-amt).add(targ.mul(amt)).normalize(); if(!dir.iszero()) (proj.vel = dir).mul(mag); @@ -2112,26 +2131,23 @@ namespace projs if(WF(WK(proj.flags), proj.weap, guided, WS(proj.flags))%2 && proj.target && proj.target->state == CS_ALIVE) proj.dest = proj.target->center(); gameent *t = NULL; - switch(WF(WK(proj.flags), proj.weap, guided, WS(proj.flags))) - { - case 2: case 3: default: - { - if(proj.owner && proj.owner->state == CS_ALIVE) - { - vec dest; - findorientation(proj.owner->o, proj.owner->yaw, proj.owner->pitch, dest); - t = game::intersectclosest(proj.owner->o, dest, proj.owner); - break; - } // otherwise.. - } - case 4: case 5: - { - float yaw, pitch; - vectoyawpitch(dir, yaw, pitch); - vec dest; findorientation(proj.o, yaw, pitch, dest); - t = game::intersectclosest(proj.o, dest, proj.owner); + switch (WF(WK(proj.flags), proj.weap, guided, WS(proj.flags))) { + default: + if (proj.owner && proj.owner->state == CS_ALIVE) { + vec dest; + findorientation(proj.owner->o, proj.owner->yaw, proj.owner->pitch, dest); + t = game::intersectclosest(proj.owner->o, dest, proj.owner); break; } + [[fallthrough]]; + case 4: + case 5: + float yaw, pitch; + vectoyawpitch(dir, yaw, pitch); + vec dest; + findorientation(proj.o, yaw, pitch, dest); + t = game::intersectclosest(proj.o, dest, proj.owner); + break; } if(t && (!m_team(game::gamemode, game::mutators) || (t->type != ENT_PLAYER && t->type != ENT_AI) || ((gameent *)t)->team != proj.owner->team)) { @@ -2150,7 +2166,7 @@ namespace projs } if(!proj.dest.iszero()) { - float amt = clamp(WF(WK(proj.flags), proj.weap, speeddelta, WS(proj.flags))*secs, 1e-8f, 1.f), + float amt = std::clamp(WF(WK(proj.flags), proj.weap, speeddelta, WS(proj.flags))*secs, 1e-8f, 1.f), mag = max(proj.vel.magnitude(), physics::movevelocity(&proj)); dir.mul(1.f-amt).add(vec(proj.dest).sub(proj.o).safenormalize().mul(amt)).normalize(); if(!dir.iszero()) (proj.vel = dir).mul(mag); @@ -2282,15 +2298,16 @@ namespace projs { if(proj.projtype == PRJ_SHOT && WF(WK(proj.flags), proj.weap, collide, WS(proj.flags))&COLLIDE_HITSCAN ? !raymove(proj) : !move(proj)) switch(proj.projtype) { - case PRJ_ENT: case PRJ_AFFINITY: - { - if(!proj.beenused) - { - proj.beenused = 1; - proj.lifetime = min(proj.lifetime, proj.fadetime); - } - if(proj.lifetime > 0) break; - } + case PRJ_ENT: + case PRJ_AFFINITY: + if (!proj.beenused) { + proj.beenused = 1; + proj.lifetime = min(proj.lifetime, proj.fadetime); + } + if (proj.lifetime > 0) { + break; + } + [[fallthrough]]; default: proj.state = CS_DEAD; proj.escaped = true; break; } } @@ -2435,7 +2452,7 @@ namespace projs { flags |= MDL_LIGHTFX; vec burncol = !proj.id && isweap(proj.weap) ? FWCOL(P, explcol, proj) : game::rescolour(&proj, PULSE_BURN); - burncol.lerp(proj.light.effect, clamp((proj.lifespan - 0.3f)/0.5f, 0.0f, 1.0f)); + burncol.lerp(proj.light.effect, std::clamp((proj.lifespan - 0.3f)/0.5f, 0.0f, 1.0f)); proj.light.effect.max(burncol); } break; @@ -2468,7 +2485,7 @@ namespace projs trans *= fadeweap(proj); if(proj.weap == W_GRENADE) { - float amt = clamp(proj.lifespan, 0.f, 1.f); + float amt = std::clamp(proj.lifespan, 0.f, 1.f); proj.light.material[0] = bvec::fromcolor(W(proj.weap, colour)); proj.light.material[0].r += int((255-proj.light.material[0].r)*amt); proj.light.material[0].g -= int(proj.light.material[0].g*amt); @@ -2528,10 +2545,10 @@ namespace projs float expl = WX(WK(proj.flags), proj.weap, explode, WS(proj.flags), game::gamemode, game::mutators, proj.curscale*proj.lifesize); if(type != W_ZAPPER || expl <= 0) { - float size = clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, proj.curscale, min(16.f, min(min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.movement), proj.o.dist(proj.from)))); + float size = std::clamp(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags))*(1.f-proj.lifespan)*proj.curscale, proj.curscale, min(16.f, min(min(WF(WK(proj.flags), proj.weap, partlen, WS(proj.flags)), proj.movement), proj.o.dist(proj.from)))); adddynlight(proj.o, 1.25f*size*trans, FWCOL(P, partcol, proj)); - break; } + break; } case W_FLAMER: case W_PLASMA: case W_GRENADE: case W_ROCKET: { diff --git a/src/game/server.cpp b/src/game/server.cpp index 7ebeca26..0328335d 100644 --- a/src/game/server.cpp +++ b/src/game/server.cpp @@ -949,7 +949,7 @@ namespace server ident *id = getident(#a); \ if(id && id->type == ID_VAR && id->flags&IDF_SERVER) \ { \ - *id->storage.i = clamp(b, id->minval, id->maxval); \ + *id->storage.i = std::clamp(b, id->minval, id->maxval); \ id->changed(); \ const char *sval = intstr(id); \ sendf(-1, 1, "ri2sis", N_COMMAND, -1, &id->name[3], strlen(sval), sval); \ @@ -963,7 +963,7 @@ namespace server ident *id = getident(#a); \ if(id && id->type == ID_FVAR && id->flags&IDF_SERVER) \ { \ - *id->storage.f = clamp(b, id->minvalf, id->maxvalf); \ + *id->storage.f = std::clamp(b, id->minvalf, id->maxvalf); \ id->changed(); \ const char *sval = floatstr(id); \ if(sval) sendf(-1, 1, "ri2sis", N_COMMAND, -1, &id->name[3], strlen(sval), sval); \ @@ -1164,8 +1164,8 @@ namespace server void deleteinfo(void *ci) { delete (clientinfo *)ci; } int numchannels() { return 3; } - int spectatorslots() { return clamp(G(serverspectators) > 0 ? G(serverspectators) : G(serverclients), 1, MAXCLIENTS); } - int maxslots() { return clamp(G(serverclients)+spectatorslots(), 1, MAXCLIENTS); } + int spectatorslots() { return std::clamp(G(serverspectators) > 0 ? G(serverspectators) : G(serverclients), 1, MAXCLIENTS); } + int maxslots() { return std::clamp(G(serverclients)+spectatorslots(), 1, MAXCLIENTS); } int reserveclients() { return maxslots()+4; } int dupclients() { return G(serverdupclients); } @@ -1235,7 +1235,7 @@ namespace server { "none", "player account", "global supporter", "global moderator", "global operator", "global administrator", "project developer", "project founder" }, { "none", "player account", "local supporter", "local moderator", "local operator", "local administrator", "none", "none" } }; - return privnames[priv&PRIV_LOCAL ? 1 : 0][clamp(priv&PRIV_TYPE, 0, int(priv&PRIV_LOCAL ? PRIV_ADMINISTRATOR : PRIV_LAST))]; + return privnames[priv&PRIV_LOCAL ? 1 : 0][std::clamp(priv&PRIV_TYPE, 0, int(priv&PRIV_LOCAL ? PRIV_ADMINISTRATOR : PRIV_LAST))]; } const char *privnamex(int priv, int actortype, bool local) @@ -1245,7 +1245,7 @@ namespace server { "none", "player", "supporter", "moderator", "operator", "administrator", "developer", "founder" }, { "none", "player", "localsupporter", "localmoderator", "localoperator", "localadministrator", "developer", "founder" } }; - return privnames[local && priv&PRIV_LOCAL ? 1 : 0][clamp(priv&PRIV_TYPE, 0, int(priv&PRIV_LOCAL ? PRIV_ADMINISTRATOR : PRIV_LAST))]; + return privnames[local && priv&PRIV_LOCAL ? 1 : 0][std::clamp(priv&PRIV_TYPE, 0, int(priv&PRIV_LOCAL ? PRIV_ADMINISTRATOR : PRIV_LAST))]; } const char *colourname(clientinfo *ci, char *name = NULL, bool icon = true, bool dupname = true, int colour = 3) @@ -1281,7 +1281,7 @@ namespace server const char *teamtexnamex(int team) { const char *teamtexs[T_MAX] = { "teamtex", "teamalphatex", "teamomegatex", "teamkappatex", "teamsigmatex", "teamtex" }; - return teamtexs[clamp(team, 0, T_MAX-1)]; + return teamtexs[std::clamp(team, 0, T_MAX-1)]; } const char *colourteam(int team, const char *icon = "") @@ -1340,7 +1340,7 @@ namespace server if(!m_game(mode)) mode = G_DEATHMATCH; if(gametype[mode].implied) muts |= gametype[mode].implied; static string gname; gname[0] = '\0'; - int start = clamp(compact, 0, 3), lps = clamp(4-start, 1, 4); + int start = std::clamp(compact, 0, 3), lps = std::clamp(4-start, 1, 4); loopk(lps) { int iter = start+k; @@ -2168,8 +2168,7 @@ namespace server else if(m_play(gamemode) && m_team(gamemode, mutators) && (!m_race(gamemode) || m_ra_gauntlet(gamemode, mutators)) && !spawns[ci->team].ents.empty()) team = ci->team; else switch(rotate) { - case 2: - { // random + case 2: // random static vector lowest; lowest.setsize(0); loopv(spawns[team].cycle) if(lowest.empty() || spawns[team].cycle[i] <= spawns[team].cycle[lowest[0]]) @@ -2183,8 +2182,7 @@ namespace server spawns[team].current = lowest[lowest.length() >= 2 ? rnd(lowest.length()) : 0]; break; } - // fall through if this fails.. - } + [[fallthrough]]; case 1: { // sequential if(++spawns[team].current >= spawns[team].ents.length()) spawns[team].current = 0; @@ -2421,7 +2419,7 @@ namespace server void prunedemos(int extra = 0) { - int n = clamp(demos.length()+extra-G(democount), 0, demos.length()); + int n = std::clamp(demos.length()+extra-G(democount), 0, demos.length()); if(n <= 0) return; loopi(n) delete[] demos[i].data; demos.remove(0, n); @@ -3293,7 +3291,11 @@ namespace server break; } case ALST_SPEC: return ci->actortype == A_PLAYER; // spec - case ALST_WALK: if(ci->state != CS_EDITING) return false; + case ALST_WALK: + if (ci->state != CS_EDITING) { + return false; + } + break; case ALST_EDIT: // edit on/off { if(ci->quarantine || (ci->state == CS_SPECTATOR && numclients(ci->clientnum, true) >= G(serverclients)) || ci->actortype != A_PLAYER || !m_edit(gamemode)) return false; @@ -3380,12 +3382,10 @@ namespace server { std::vector prev; explodelist(sv_previousmaps, prev); - loopvrev(prev) if(prev[i] == smapname) - { + loopvrev(prev) if (prev[i] == smapname) { prev.erase( prev.begin() + i ); } - while(prev.size() >= G(maphistory)) - { + while (prev.size() >= static_cast(G(maphistory))) { prev.pop_back(); } loopv(prev) @@ -3395,7 +3395,10 @@ namespace server } prev.clear(); } - if(!buf.empty()) setmods(sv_previousmaps, buf.c_str()); + + if (!buf.empty()) { + setmods(sv_previousmaps, buf.c_str()); + } } else setmods(sv_previousmaps, ""); @@ -3777,7 +3780,7 @@ namespace server putint(p, ci->colour); putint(p, ci->model); sendstring(ci->vanity, p); - putint(p, ci->loadweap.length()); + putint(p, ci->loadweap.size()); loopv(ci->loadweap) putint(p, ci->loadweap[i]); } } @@ -3792,9 +3795,9 @@ namespace server putint(p, ci->privilege); sendstring(ci->name, p); sendstring(ci->vanity, p); - putint(p, ci->loadweap.length()); + putint(p, ci->loadweap.size()); loopv(ci->loadweap) putint(p, ci->loadweap[i]); - putint(p, ci->randweap.length()); + putint(p, ci->randweap.size()); loopv(ci->randweap) putint(p, ci->randweap[i]); sendstring(ci->handle, p); sendstring(allow ? gethostip(ci->clientnum) : "*", p); // TODO proto 231 @@ -4243,7 +4246,7 @@ namespace server logs++; if(logs >= 2) { - int offset = clamp(logs-2, 0, 2), type = 1<<(FRAG_MKILL+offset); // double, triple, multi.. + int offset = std::clamp(logs-2, 0, 2), type = 1<<(FRAG_MKILL+offset); // double, triple, multi.. if(!(v->rewards[0]&type)) { style |= type; @@ -4260,7 +4263,7 @@ namespace server } if(v->spree <= G(spreecount)*FRAG_SPREES && !(v->spree%G(spreecount))) { - int offset = clamp((v->spree/G(spreecount)), 1, int(FRAG_SPREES))-1, type = 1<<(FRAG_SPREE+offset); + int offset = std::clamp((v->spree/G(spreecount)), 1, int(FRAG_SPREES))-1, type = 1<<(FRAG_SPREE+offset); if(!(v->rewards[0]&type)) { style |= type; @@ -4452,7 +4455,7 @@ namespace server flags |= HIT_WAVE; } - float skew = clamp(scale, 0.f, 1.f)*G(damagescale); + float skew = std::clamp(scale, 0.f, 1.f)*G(damagescale); if(flags&HIT_WHIPLASH) skew *= WF(WK(flags), weap, damagewhiplash, WS(flags)); else if(flags&HIT_HEAD) skew *= WF(WK(flags), weap, damagehead, WS(flags)); @@ -4460,9 +4463,9 @@ namespace server else if(flags&HIT_LEGS) skew *= WF(WK(flags), weap, damagelegs, WS(flags)); else return 0; - if(radial > 0) skew *= clamp(1.f-dist/size, 1e-6f, 1.f); + if(radial > 0) skew *= std::clamp(1.f-dist/size, 1e-6f, 1.f); else if(WF(WK(flags), weap, taper, WS(flags)) != 0) - skew *= clamp(dist, WF(WK(flags), weap, tapermin, WS(flags)), WF(WK(flags), weap, tapermax, WS(flags))); + skew *= std::clamp(dist, WF(WK(flags), weap, tapermin, WS(flags)), WF(WK(flags), weap, tapermax, WS(flags))); if(!m_insta(gamemode, mutators)) { @@ -4577,7 +4580,7 @@ namespace server else { int hflags = flags|h.flags; - float skew = float(scale)/DNF, rad = radial > 0 ? clamp(radial/DNF, 0.f, WX(WK(flags), weap, explode, WS(flags), gamemode, mutators, skew)) : 0.f, + float skew = float(scale)/DNF, rad = radial > 0 ? std::clamp(radial/DNF, 0.f, WX(WK(flags), weap, explode, WS(flags), gamemode, mutators, skew)) : 0.f, size = rad > 0 ? (hflags&HIT_WAVE ? rad*WF(WK(flags), weap, wavepush, WS(flags)) : rad) : 0.f, dist = float(h.dist)/DNF; if(m->state == CS_ALIVE && !m->protect(gamemillis, m_protect(gamemode, mutators))) { @@ -4990,7 +4993,7 @@ namespace server total = ci->health; low = m_health(gamemode, mutators, ci->actortype); } - int heal = clamp(ci->health+amt, low, total), eff = heal-ci->health; + int heal = std::clamp(ci->health+amt, low, total), eff = heal-ci->health; if(eff) { ci->health = heal; @@ -5104,7 +5107,6 @@ namespace server switch(gamestate) { case G_S_WAITING: // start check - { if(!G(waitforplayermaps)) { gamewaittime = totalmillis+G(waitforplayertime); @@ -5134,8 +5136,7 @@ namespace server sendtick(); break; } - // fall through - } + [[fallthrough]]; case G_S_GETMAP: // waiting for server { if(!gamewaittime) @@ -5158,7 +5159,6 @@ namespace server break; } case G_S_SENDMAP: // waiting for players - { if(!gamewaittime) { gamewaittime = totalmillis+G(waitforplayermaps); @@ -5168,8 +5168,7 @@ namespace server gamewaittime = totalmillis+G(waitforplayertime); gamestate = G_S_READYING; sendtick(); - // fall through - } + [[fallthrough]]; case G_S_READYING: // waiting for ready { if(!gamewaittime) @@ -5203,7 +5202,6 @@ namespace server break; } case G_S_GAMEINFO: - { if(!gamewaittime) { gamewaittime = totalmillis+G(waitforplayerinfo); @@ -5224,9 +5222,9 @@ namespace server sendf(cs->clientnum, 1, "ri", N_GETGAMEINFO); asked++; } - if(!asked) srvoutf(4, "\fyno game information response, and nobody to ask, giving up.."); - else - { + if (!asked) { + srvoutf(4, "\fyno game information response, and nobody to ask, giving up.."); + } else { srvoutf(4, "\fyno game information response, broadcasting.."); gamewaittime = totalmillis+G(waitforplayerinfo); sendtick(); @@ -5236,8 +5234,10 @@ namespace server else srvoutf(4, "\fyno broadcast game information response, giving up.."); } mapgameinfo = -1; - } - default: gamestate = G_S_PLAYING; break; + [[fallthrough]]; + default: + gamestate = G_S_PLAYING; + break; } if(gamestate == G_S_PLAYING) { @@ -5729,18 +5729,24 @@ namespace server getstring(text, p); ci->setvanity(text); int lw = getint(p); - ci->loadweap.shrink(0); + ci->loadweap.clear(); loopk(lw) { - if(k >= W_LOADOUT) getint(p); - else ci->loadweap.add(getint(p)); + if (k >= W_LOADOUT) { + getint(p); + } else { + ci->loadweap.emplace_back(getint(p)); + } } int rw = getint(p); - ci->randweap.shrink(0); + ci->randweap.clear(); loopk(rw) { - if(k >= W_LOADOUT) getint(p); - else ci->randweap.add(getint(p)); + if (k >= W_LOADOUT) { + getint(p); + } else { + ci->randweap.emplace_back(getint(p)); + } } string password = "", authname = ""; @@ -5872,13 +5878,13 @@ namespace server int dir = p.get(); dir |= p.get()<<8; yaw = dir%360; - pitch = clamp(dir/360, 0, 180)-90; - roll = clamp(int(p.get()), 0, 180)-90; + pitch = std::clamp(dir/360, 0, 180)-90; + roll = std::clamp(int(p.get()), 0, 180)-90; int mag = p.get(); if(flags&(1<<6)) mag |= p.get()<<8; dir = p.get(); dir |= p.get()<<8; - vecfromyawpitch(dir%360, clamp(dir/360, 0, 180)-90, 1, 0, vel); + vecfromyawpitch(dir%360, std::clamp(dir/360, 0, 180)-90, 1, 0, vel); vel.mul(mag/DVELF); if(flags&(1<<7)) { @@ -5888,7 +5894,7 @@ namespace server { dir = p.get(); dir |= p.get()<<8; - vecfromyawpitch(dir%360, clamp(dir/360, 0, 180)-90, 1, 0, falling); + vecfromyawpitch(dir%360, std::clamp(dir/360, 0, 180)-90, 1, 0, falling); } else falling = vec(0, 0, -1); falling.mul(mag/DVELF); @@ -6119,7 +6125,7 @@ namespace server if(!isweap(ev->weap)) havecn = false; else { - ev->scale = clamp(ev->scale, 0, W2(ev->weap, cooktime, WS(ev->flags))); + ev->scale = std::clamp(ev->scale, 0, W2(ev->weap, cooktime, WS(ev->flags))); if(havecn) ev->millis = cp->getmillis(gamemillis, ev->id); } loopk(3) ev->from[k] = getint(p); @@ -6340,7 +6346,11 @@ namespace server commit = kin = true; break; } - case TR_ONCE: if(sents[ent].spawned) break; + case TR_ONCE: + if (sents[ent].spawned) { + break; + } + [[fallthrough]]; case TR_LINK: { sents[ent].millis = gamemillis+(triggertime(ent)*2); @@ -6518,20 +6528,23 @@ namespace server ci->checkpointspawn = max(getint(p), 0); getstring(text, p); ci->setvanity(text); - ci->loadweap.shrink(0); + ci->loadweap.clear(); int lw = getint(p); vector lweaps; loopk(lw) { if(k >= W_LOADOUT) getint(p); - else ci->loadweap.add(getint(p)); + else ci->loadweap.emplace_back(getint(p)); } - ci->randweap.shrink(0); + ci->randweap.clear(); int rw = getint(p); loopk(rw) { - if(k >= W_LOADOUT) getint(p); - else ci->randweap.add(getint(p)); + if (k >= W_LOADOUT) { + getint(p); + } else { + ci->randweap.emplace_back(getint(p)); + } } ci->lastplayerinfo = totalmillis ? totalmillis : 1; QUEUE_STR(ci->name); @@ -6539,9 +6552,9 @@ namespace server QUEUE_INT(ci->model); QUEUE_INT(ci->checkpointspawn); QUEUE_STR(ci->vanity); - QUEUE_INT(ci->loadweap.length()); + QUEUE_INT(ci->loadweap.size()); loopvk(ci->loadweap) QUEUE_INT(ci->loadweap[k]); - QUEUE_INT(ci->randweap.length()); + QUEUE_INT(ci->randweap.size()); loopvk(ci->randweap) QUEUE_INT(ci->randweap[k]); break; } @@ -6662,7 +6675,7 @@ namespace server sents[n].type = type; sents[n].spawned = false; // wait a bit then load 'em up sents[n].millis = gamemillis; - sents[n].attrs.add(0, clamp(numattr, type >= 0 && type < MAXENTTYPES ? enttype[type].numattrs : 0, MAXENTATTRS)); + sents[n].attrs.add(0, std::clamp(numattr, type >= 0 && type < MAXENTTYPES ? enttype[type].numattrs : 0, MAXENTATTRS)); loopk(numattr) { if(p.overread()) break; @@ -6677,7 +6690,7 @@ namespace server if(enttype[type].synckin) { int numkin = getint(p); - sents[n].kin.add(0, clamp(numkin, 0, MAXENTKIN)); + sents[n].kin.add(0, std::clamp(numkin, 0, MAXENTKIN)); loopk(numkin) { if(p.overread()) break; diff --git a/src/game/waypoint.cpp b/src/game/waypoint.cpp index de67dca0..2e5e478e 100644 --- a/src/game/waypoint.cpp +++ b/src/game/waypoint.cpp @@ -25,7 +25,7 @@ namespace ai if(dist >= 0) { pull = int(dist/JUMPMIN); - pos.z -= clamp(dist-8.0f, 0.0f, pos.z); + pos.z -= std::clamp(dist-8.0f, 0.0f, pos.z); int trgmat = lookupmaterial(pos); if(trgmat&MAT_DEATH || trgmat&MAT_HURT || (trgmat&MATF_VOLUME) == MAT_LAVA) pull *= 100; else if(isliquid(trgmat&MATF_VOLUME)) pull *= 2; diff --git a/src/game/weapons.cpp b/src/game/weapons.cpp index a17740d8..1055311f 100644 --- a/src/game/weapons.cpp +++ b/src/game/weapons.cpp @@ -324,7 +324,7 @@ namespace weapons } else return false; } - cooked = len ? clamp(lastmillis-d->weaptime[weap], 1, len) : 1; + cooked = len ? std::clamp(lastmillis-d->weaptime[weap], 1, len) : 1; if(zooming) { if(pressed && wassecond) return false; @@ -352,7 +352,7 @@ namespace weapons if(weap == W_MELEE) { from = d->center(); - to = vec(from).add(vec(d->yaw*RAD, d->pitch*RAD).mul(d->radius*2.f)); + to = vec(from).add(vec(d->yaw*rad, d->pitch*rad).mul(d->radius*2.f)); } else { diff --git a/src/game/weapons.h b/src/game/weapons.h index 82111f76..7528a1b7 100644 --- a/src/game/weapons.h +++ b/src/game/weapons.h @@ -28,6 +28,7 @@ enum { W_S_EXCLUDE = (1< 0 ? W2(a, spreadmax, b) : FVAR_MAX) : 0.f) +#define WSP(a,b,c,d,e) (!m_insta(c, d) || (a) != W_RIFLE ? std::clamp(W2(a, spread, b)*(e), W2(a, spreadmin, b), W2(a, spreadmax, b) > 0 ? W2(a, spreadmax, b) : FVAR_MAX) : 0.f) #define WSND(a,b) (weaptype[a].sound+(b)) #define WSNDF(a,b) (weaptype[a].sound+((b) ? S_W_SECONDARY : S_W_PRIMARY)) #define WSND2(a,b,c) (weaptype[a].sound+((b) ? (c)+1 : (c))) #define WUSE(a) (a < W_ITEM ? W(a, ammomax) : W(a, ammoadd)) -#define WHCOL(d,a,b,c) (W2(a, b, c) >= 0 ? W2(a, b, c) : game::hexpulsecolour(d, clamp(INVPULSE(W2(a, b, c)), 0, int(PULSE_LAST)), 50)) -#define WPCOL(d,a,b,c) (W2(a, b, c) >= 0 ? vec::hexcolor(W2(a, b, c)) : game::pulsecolour(d, clamp(INVPULSE(W2(a, b, c)), 0, int(PULSE_LAST)), 50)) +#define WHCOL(d,a,b,c) (W2(a, b, c) >= 0 ? W2(a, b, c) : game::hexpulsecolour(d, std::clamp(INVPULSE(W2(a, b, c)), 0, int(PULSE_LAST)), 50)) +#define WPCOL(d,a,b,c) (W2(a, b, c) >= 0 ? vec::hexcolor(W2(a, b, c)) : game::pulsecolour(d, std::clamp(INVPULSE(W2(a, b, c)), 0, int(PULSE_LAST)), 50)) struct weaptypes { diff --git a/src/shared/ents.h b/src/shared/ents.h index f785e3f5..4ffa3acb 100644 --- a/src/shared/ents.h +++ b/src/shared/ents.h @@ -100,27 +100,22 @@ struct baseent struct physent : baseent // can be affected by physics { vec deltapos, newpos; - float speed, weight; + float speed = 100, weight = 100; int airmillis, floormillis; - float radius, height, aboveeye; // bounding box size - float xradius, yradius, zradius, zmargin; + float radius = 3, height = 14, aboveeye = 1; // bounding box size + float xradius = 3, yradius = 3, zradius = height, zmargin = 0; vec floor; // the normal of floor the dynent is on bool blocked, inliquid, onladder, forcepos; - float curscale, speedscale; + float curscale = 1, speedscale = 1; char move, strafe; uchar physstate; // one of PHYS_* above - uchar type; // one of ENT_* above - uchar collidetype; // one of COLLIDE_* above + uchar type = ENT_INANIMATE; // one of ENT_* above + uchar collidetype = COLLIDE_ELLIPSE; // one of COLLIDE_* above - physent() : speed(100), weight(100), radius(3), aboveeye(1), - xradius(3), yradius(3), zradius(14), zmargin(0), curscale(1), speedscale(1), - type(ENT_INANIMATE), - collidetype(COLLIDE_ELLIPSE) - { + physent() { reset(); - height = zradius; } void resetinterp(bool force = false) diff --git a/src/shared/geom.cpp b/src/shared/geom.cpp index 41afa7d1..948b0c19 100644 --- a/src/shared/geom.cpp +++ b/src/shared/geom.cpp @@ -4,23 +4,23 @@ void vecfromyawpitch(float yaw, float pitch, int move, int strafe, vec &m) { if(move) { - m.x = move*-sinf(RAD*yaw); - m.y = move*cosf(RAD*yaw); + m.x = move*-sinf(rad*yaw); + m.y = move*cosf(rad*yaw); } else m.x = m.y = 0; if(pitch) { - m.x *= cosf(RAD*pitch); - m.y *= cosf(RAD*pitch); - m.z = move*sinf(RAD*pitch); + m.x *= cosf(rad*pitch); + m.y *= cosf(rad*pitch); + m.z = move*sinf(rad*pitch); } else m.z = 0; if(strafe) { - m.x += strafe*cosf(RAD*yaw); - m.y += strafe*sinf(RAD*yaw); + m.x += strafe*cosf(rad*yaw); + m.y += strafe*sinf(rad*yaw); } if(!m.iszero()) m.normalize(); @@ -31,8 +31,8 @@ void vectoyawpitch(const vec &v, float &yaw, float &pitch) if(v.iszero()) yaw = pitch = 0; else { - yaw = -atan2(v.x, v.y)/RAD; - pitch = asin(v.z/v.magnitude())/RAD; + yaw = -atan2(v.x, v.y)/rad; + pitch = asin(v.z/v.magnitude())/rad; } } @@ -172,7 +172,7 @@ vec closestpointcylinder(const vec ¢er, const vec &start, const vec &end, fl vec raddir = vec(relcenter).sub(vec(dir).mul(height)); float radlen = raddir.magnitude(); if(radlen > radius) raddir.mul(radius/radlen); - return dir.mul(clamp(height, 0.0f, 1.0f)).add(start).add(raddir); + return dir.mul(std::clamp(height, 0.0f, 1.0f)).add(start).add(raddir); } extern const vec2 sincos360[721] = diff --git a/src/shared/geom.h b/src/shared/geom.h index 2183664f..b6273b4d 100644 --- a/src/shared/geom.h +++ b/src/shared/geom.h @@ -44,7 +44,7 @@ struct vec2 vec2 &min(float f) { x = ::min(x, f); y = ::min(y, f); return *this; } vec2 &max(float f) { x = ::max(x, f); y = ::max(y, f); return *this; } vec2 &abs() { x = fabs(x); y = fabs(y); return *this; } - vec2 &clamp(float l, float h) { x = ::clamp(x, l, h); y = ::clamp(y, l, h); return *this; } + vec2 &clamp(float l, float h) { x = std::clamp(x, l, h); y = std::clamp(y, l, h); return *this; } vec2 &reflect(const vec2 &n) { float k = 2*dot(n); x -= k*n.x; y -= k*n.y; return *this; } vec2 &lerp(const vec2 &b, float t) { x += (b.x-x)*t; y += (b.y-y)*t; return *this; } vec2 &lerp(const vec2 &a, const vec2 &b, float t) { x = a.x + (b.x-a.x)*t; y = a.y + (b.y-a.y)*t; return *this; } @@ -72,7 +72,7 @@ struct vec { union { - struct { float x, y, z; }; + struct { float x = 0, y = 0, z = 0; }; struct { float r, g, b; }; float v[3]; }; @@ -121,7 +121,7 @@ struct vec vec &min(float f) { x = ::min(x, f); y = ::min(y, f); z = ::min(z, f); return *this; } vec &max(float f) { x = ::max(x, f); y = ::max(y, f); z = ::max(z, f); return *this; } vec &abs() { x = fabs(x); y = fabs(y); z = fabs(z); return *this; } - vec &clamp(float l, float h) { x = ::clamp(x, l, h); y = ::clamp(y, l, h); z = ::clamp(z, l, h); return *this; } + vec &clamp(float l, float h) { x = std::clamp(x, l, h); y = std::clamp(y, l, h); z = std::clamp(z, l, h); return *this; } float magnitude2() const { return sqrtf(dot2(*this)); } float magnitude() const { return sqrtf(squaredlen()); } vec &normalize() { div(magnitude()); return *this; } @@ -235,13 +235,13 @@ struct vec return vec(((color>>16)&0xFF)*(1.0f/255.0f), ((color>>8)&0xFF)*(1.0f/255.0f), (color&0xFF)*(1.0f/255.0f)); } - int tohexcolor() { return (int(::clamp(r, 0.0f, 1.0f)*255)<<16)|(int(::clamp(g, 0.0f, 1.0f)*255)<<8)|int(::clamp(b, 0.0f, 1.0f)*255); } + int tohexcolor() { return (int(std::clamp(r, 0.0f, 1.0f)*255)<<16)|(int(std::clamp(g, 0.0f, 1.0f)*255)<<8)|int(std::clamp(b, 0.0f, 1.0f)*255); } vec &minbounds(float rx, float ry, float rz) { - x = ::clamp(x, -rx, rx); - y = ::clamp(y, -ry, ry); - z = ::clamp(z, -rz, rz); + x = std::clamp(x, -rx, rx); + y = std::clamp(y, -ry, ry); + z = std::clamp(z, -rz, rz); return *this; } vec &minbounds(const vec &n) { return minbounds(n.x, n.y, n.z); } @@ -712,7 +712,7 @@ struct matrix3 axis.x = c.x/r; axis.y = c.y/r; } - angle = M_PI; + angle = pi; } else if(tr >= 3) { @@ -1182,7 +1182,7 @@ struct ivec ivec &min(int n) { x = ::min(x, n); y = ::min(y, n); z = ::min(z, n); return *this; } ivec &max(int n) { x = ::max(x, n); y = ::max(y, n); z = ::max(z, n); return *this; } ivec &abs() { x = ::abs(x); y = ::abs(y); z = ::abs(z); return *this; } - ivec &clamp(int l, int h) { x = ::clamp(x, l, h); y = ::clamp(y, l, h); z = ::clamp(z, l, h); return *this; } + ivec &clamp(int l, int h) { x = std::clamp(x, l, h); y = std::clamp(y, l, h); z = std::clamp(z, l, h); return *this; } ivec &cross(const ivec &a, const ivec &b) { x = a.y*b.z-a.z*b.y; y = a.z*b.x-a.x*b.z; z = a.x*b.y-a.y*b.x; return *this; } int dot(const ivec &o) const { return x*o.x + y*o.y + z*o.z; } float dist(const plane &p) const { return x*p.x + y*p.y + z*p.z + p.offset; } @@ -1325,7 +1325,7 @@ struct bvec bvec &min(int f) { x = ::min(int(x), f); y = ::min(int(y), f); z = ::min(int(z), f); return *this; } bvec &max(int f) { x = ::max(int(x), f); y = ::max(int(y), f); z = ::max(int(z), f); return *this; } bvec &abs() { return *this; } - bvec &clamp(int l, int h) { x = ::clamp(int(x), l, h); y = ::clamp(int(y), l, h); z = ::clamp(int(z), l, h); return *this; } + bvec &clamp(int l, int h) { x = std::clamp(int(x), l, h); y = std::clamp(int(y), l, h); z = std::clamp(int(z), l, h); return *this; } vec tonormal() const { return vec(x*(2.0f/255.0f)-1.0f, y*(2.0f/255.0f)-1.0f, z*(2.0f/255.0f)-1.0f); } @@ -1358,7 +1358,7 @@ struct bvec static bvec from565(ushort c) { return bvec((((c>>11)&0x1F)*527 + 15) >> 6, (((c>>5)&0x3F)*259 + 35) >> 6, ((c&0x1F)*527 + 15) >> 6); } - int tohexcolor() { return ((::clamp(int(r), 0, 255))<<16)|((::clamp(int(g), 0, 255))<<8)|(::clamp(int(b), 0, 255)); } + int tohexcolor() { return ((std::clamp(int(r), 0, 255))<<16)|((std::clamp(int(g), 0, 255))<<8)|(std::clamp(int(b), 0, 255)); } }; struct bvec4 @@ -1671,7 +1671,7 @@ struct matrix4 void perspective(float fovy, float aspect, float znear, float zfar) { - float ydist = znear * tan(fovy/2*RAD), xdist = ydist * aspect; + float ydist = znear * tan(fovy/2*rad), xdist = ydist * aspect; frustum(-xdist, xdist, -ydist, ydist, znear, zfar); } diff --git a/src/shared/iengine.h b/src/shared/iengine.h index b9b475b3..0e2d5590 100644 --- a/src/shared/iengine.h +++ b/src/shared/iengine.h @@ -80,9 +80,9 @@ struct selinfo if(o.x < 0) { s.x -= (grid - 1 - o.x)/grid; o.x = 0; } if(o.y < 0) { s.y -= (grid - 1 - o.y)/grid; o.y = 0; } if(o.z < 0) { s.z -= (grid - 1 - o.z)/grid; o.z = 0; } - s.x = clamp(s.x, 0, (worldsize - o.x)/grid); - s.y = clamp(s.y, 0, (worldsize - o.y)/grid); - s.z = clamp(s.z, 0, (worldsize - o.z)/grid); + s.x = std::clamp(s.x, 0, (worldsize - o.x)/grid); + s.y = std::clamp(s.y, 0, (worldsize - o.y)/grid); + s.z = std::clamp(s.z, 0, (worldsize - o.z)/grid); return s.x > 0 && s.y > 0 && s.z > 0; } }; diff --git a/src/shared/tools.cpp b/src/shared/tools.cpp index d52f8ed7..d842159f 100644 --- a/src/shared/tools.cpp +++ b/src/shared/tools.cpp @@ -95,7 +95,7 @@ int getuint(ucharbuf &p) n += (p.get() << 7) - 0x80; if(n & (1<<14)) n += (p.get() << 14) - (1<<14); if(n & (1<<21)) n += (p.get() << 21) - (1<<21); - if(n & (1<<28)) n |= -1<<28; + if(n & (1<<28)) n |= 0xF0000000; } return n; } diff --git a/src/shared/tools.h b/src/shared/tools.h index 9d2d04ab..9b47e94d 100644 --- a/src/shared/tools.h +++ b/src/shared/tools.h @@ -4,11 +4,9 @@ #define _TOOLS_H #include #include - -#ifdef NULL -#undef NULL -#endif -#define NULL 0 +#include +#include +#include typedef unsigned char uchar; typedef unsigned short ushort; @@ -51,11 +49,6 @@ static inline T min(T a, T b) { return a < b ? a : b; } -template -static inline T clamp(T a, U b, U c) -{ - return max(T(b), min(a, T(c))); -} #ifdef __GNUC__ #define bitscan(mask) (__builtin_ffs(mask)-1) @@ -100,20 +93,13 @@ static inline int bitscan(uint mask) #define DELETEP(p) if(p) { delete p; p = 0; } #define DELETEA(p) if(p) { delete[] p; p = 0; } -#define PI (3.1415927f) -#define PI2 (2*PI) -#define SQRT2 (1.4142136f) -#define SQRT3 (1.7320508f) -#define RAD (PI / 180.0f) +constexpr float pi{ std::numbers::pi_v }; +constexpr float sqrt2{ std::numbers::sqrt2_v }; +constexpr float sqrt3{ std::numbers::sqrt3_v }; +constexpr float rad{ pi / 180.0f }; +constexpr float ln2{ std::numbers::ln2_v }; #ifdef WIN32 -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_LN2 -#define M_LN2 0.693147180559945309417 -#endif - #ifdef _MSC_VER #pragma warning (3: 4189) // local variable is initialized but not referenced #pragma warning (disable: 4244) // conversion from 'int' to 'float', possible loss of data @@ -140,6 +126,13 @@ static inline int bitscan(uint mask) #define PRINTFARGS(fmt, args) #endif +template +constexpr bool inrange(const std::vector &vec, U val) +{ + static_assert(std::is_integral::value, "Second argument is not an integral, could not safely cast to size_t"); + return static_cast(val) < vec.size(); +} + // easy safe strings #define MAXSTRLEN 512 // must be at least 512 bytes to comply with rfc1459 @@ -290,7 +283,7 @@ struct databuf databuf subbuf(int sz) { - sz = clamp(sz, 0, maxlen-len); + sz = std::clamp(sz, 0, maxlen-len); len += sz; return databuf(&buf[len-sz], sz); } diff --git a/src/shared/zip.cpp b/src/shared/zip.cpp index 178e3b7a..5c44ccbd 100644 --- a/src/shared/zip.cpp +++ b/src/shared/zip.cpp @@ -425,7 +425,7 @@ struct zipstream : stream case SEEK_SET: pos += info->offset; break; default: return false; } - pos = clamp(pos, offset(info->offset), offset(info->offset + info->size)); + pos = std::clamp(pos, offset(info->offset), offset(info->offset + info->size)); arch->owner = NULL; if(fseek(arch->data, int(pos), SEEK_SET) < 0) return false; arch->owner = this;