replace a bunch of clamp/min/max with std

This commit is contained in:
Daniel Kolesa 2020-07-30 05:26:57 +02:00
parent a2081e6672
commit 6ea2cdb306
28 changed files with 324 additions and 281 deletions

View file

@ -1,5 +1,7 @@
#include "aa.hh"
#include <algorithm>
#include <shared/glemu.hh>
#include <shared/command.hh>
@ -84,7 +86,7 @@ VAR(debugtqaa, 0, 0, 2);
static void viewtqaa()
{
int w = min(hudw, hudh)*1.0f, h = (w*hudh)/hudw, tw = gw, th = gh;
int w = std::min(hudw, hudh)*1.0f, h = (w*hudh)/hudw, tw = gw, th = gh;
SETSHADER(hudrect);
gle::colorf(1, 1, 1);
switch(debugtqaa)
@ -330,7 +332,7 @@ static inline vec2 areaortho(float p1x, float p1y, float p2x, float p2y, float l
static inline void smootharea(float d, vec2 &a1, vec2 &a2)
{
vec2 b1(sqrtf(a1.x*2)*0.5f, sqrtf(a1.y*2)*0.5f), b2(sqrtf(a2.x*2)*0.5f, sqrtf(a2.y*2)*0.5f);
float p = clamp(d / 32.0f, 0.0f, 1.0f);
float p = std::clamp(d / 32.0f, 0.0f, 1.0f);
a1.lerp(b1, a1, p);
a2.lerp(b2, a2, p);
}
@ -387,9 +389,9 @@ static float areaunderdiag(const vec2 &p1, const vec2 &p2, const vec2 &p)
if(!d.x)
{
if(!d.y) return 1;
return clamp(d.y > 0 ? 1 - dp/d.y : dp/d.y, 0.0f, 1.0f);
return std::clamp(d.y > 0 ? 1 - dp/d.y : dp/d.y, 0.0f, 1.0f);
}
if(!d.y) return clamp(d.x > 0 ? 1 - dp/d.x : dp/d.x, 0.0f, 1.0f);
if(!d.y) return std::clamp(d.x > 0 ? 1 - dp/d.x : dp/d.x, 0.0f, 1.0f);
float l = dp/d.y, r = (dp-d.x)/d.y, b = dp/d.x, t = (dp-d.y)/d.x;
if(0 <= dp)
{
@ -400,25 +402,25 @@ static float areaunderdiag(const vec2 &p1, const vec2 &p2, const vec2 &p)
if(d.y+d.x <= dp) return 0;
return 0.5f*(1-r)*(1-t);
}
if(d.y+d.x > dp) return min(1-b, 1-t) + 0.5f*fabs(b-t);
if(d.y+d.x > dp) return std::min(1-b, 1-t) + 0.5f*fabs(b-t);
return 0.5f*(1-b)*r;
}
if(d.x <= dp)
{
if(d.y+d.x <= dp) return 0.5f*(1-l)*t;
return min(1-l, 1-r) + 0.5f*fabs(r-l);
return std::min(1-l, 1-r) + 0.5f*fabs(r-l);
}
return 1 - 0.5f*l*b;
}
if(d.y <= dp)
{
if(d.x <= dp) return 0.5f*l*b;
if(d.y+d.x <= dp) return min(l, r) + 0.5f*fabs(r-l);
if(d.y+d.x <= dp) return std::min(l, r) + 0.5f*fabs(r-l);
return 1 - 0.5f*(1-l)*t;
}
if(d.x <= dp)
{
if(d.y+d.x <= dp) return min(b, t) + 0.5f*fabs(b-t);
if(d.y+d.x <= dp) return std::min(b, t) + 0.5f*fabs(b-t);
return 1 - 0.5f*(1-b)*r;
}
if(d.y+d.x <= dp) return 1 - 0.5f*(1-t)*(1-r);
@ -570,7 +572,7 @@ static void setupsmaa(int w, int h)
static void viewsmaa()
{
int w = min(hudw, hudh)*1.0f, h = (w*hudh)/hudw, tw = gw, th = gh;
int w = std::min(hudw, hudh)*1.0f, h = (w*hudh)/hudw, tw = gw, th = gh;
SETSHADER(hudrect);
gle::colorf(1, 1, 1);
switch(debugsmaa)

View file

@ -42,8 +42,8 @@ struct animmodel : model
}
else
{
fr1 = min(fr1, info.range-1)+info.frame;
fr2 = min(fr1+1, info.frame+info.range-1);
fr1 = std::min(fr1, info.range-1)+info.frame;
fr2 = std::min(fr1+1, info.frame+info.range-1);
}
if(info.anim&ANIM_REVERSE)
{
@ -547,7 +547,7 @@ struct animmodel : model
virtual int totalframes() const { return 1; }
bool hasframe(int i) const { return i>=0 && i<totalframes(); }
bool hasframes(int i, int n) const { return i>=0 && i+n<=totalframes(); }
int clipframes(int i, int n) const { return min(n, totalframes() - i); }
int clipframes(int i, int n) const { return std::min(n, totalframes() - i); }
virtual void cleanup() {}
virtual void preload(part *p) {}
@ -837,7 +837,7 @@ struct animmodel : model
if(d && interp>=0)
{
animinterpinfo &ai = d->animinterp[interp];
if((info.anim&(ANIM_LOOP|ANIM_CLAMP))==ANIM_CLAMP) aitime = min(aitime, int(info.range*info.speed*0.5e-3f));
if((info.anim&(ANIM_LOOP|ANIM_CLAMP))==ANIM_CLAMP) aitime = std::min(aitime, int(info.range*info.speed*0.5e-3f));
void *ak = meshes->animkey();
if(d->ragdoll && d->ragdoll->millis != lastmillis)
{
@ -894,7 +894,7 @@ struct animmodel : model
vec oaxis, oforward, oo, oray;
matrixstack[matrixpos].transposedtransformnormal(axis, oaxis);
float pitchamount = pitchscale*pitch + pitchoffset;
if((pitchmin || pitchmax) && pitchmin <= pitchmax) pitchamount = clamp(pitchamount, pitchmin, pitchmax);
if((pitchmin || pitchmax) && 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)
@ -980,7 +980,7 @@ 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)
@ -1786,7 +1786,7 @@ template<class MDL, class MESH> struct modelcommands
static void setgloss(char *meshname, int *gloss)
{
loopskins(meshname, s, s.gloss = clamp(*gloss, 0, 2));
loopskins(meshname, s, s.gloss = std::clamp(*gloss, 0, 2));
}
static void setglow(char *meshname, float *percent, float *delta, float *pulse)
@ -1798,7 +1798,7 @@ template<class MDL, class MESH> struct modelcommands
static void setalphatest(char *meshname, float *cutoff)
{
loopskins(meshname, s, s.alphatest = max(0.0f, min(1.0f, *cutoff)));
loopskins(meshname, s, s.alphatest = std::max(0.0f, std::min(1.0f, *cutoff)));
}
static void setcullface(char *meshname, int *cullface)

View file

@ -1,3 +1,5 @@
#include <algorithm>
#include "ents.hh"
#include "physics.hh"
#include "rendermodel.hh" // loadmapmodel
@ -36,8 +38,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();
@ -71,7 +73,7 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
if(!curnode->isleaf(faridx))
{
curnode += curnode->childindex(faridx);
tmin = max(tmin, farsplit);
tmin = std::max(tmin, farsplit);
continue;
}
else if(triintersect(m, curnode->childindex(faridx), mo, mray, maxdist, dist, mode)) return true;
@ -85,7 +87,7 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
if(!curnode->isleaf(faridx))
{
curnode += curnode->childindex(faridx);
tmin = max(tmin, farsplit);
tmin = std::max(tmin, farsplit);
continue;
}
else if(triintersect(m, curnode->childindex(faridx), mo, mray, maxdist, dist, mode)) return true;
@ -101,21 +103,21 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
{
traversestate &save = stack[stacksize++];
save.node = curnode + curnode->childindex(faridx);
save.tmin = max(tmin, farsplit);
save.tmin = std::max(tmin, farsplit);
save.tmax = tmax;
}
else
{
if(traverse(m, o, ray, invray, maxdist, dist, mode, curnode + curnode->childindex(nearidx), tmin, min(tmax, nearsplit))) return true;
if(traverse(m, o, ray, invray, maxdist, dist, mode, curnode + curnode->childindex(nearidx), tmin, std::min(tmax, nearsplit))) return true;
curnode += curnode->childindex(faridx);
tmin = max(tmin, farsplit);
tmin = std::max(tmin, farsplit);
continue;
}
}
else if(triintersect(m, curnode->childindex(faridx), mo, mray, maxdist, dist, mode)) return true;
}
curnode += curnode->childindex(nearidx);
tmax = min(tmax, nearsplit);
tmax = std::min(tmax, nearsplit);
continue;
}
if(stacksize <= 0) return false;
@ -139,11 +141,11 @@ inline bool BIH::traverse(const vec &o, const vec &ray, float maxdist, float &di
if(invray.x > 0) { tmin = t1; tmax = t2; } else { tmin = t2; tmax = t1; }
t1 = (m.bbmin.y - o.y)*invray.y;
t2 = (m.bbmax.y - o.y)*invray.y;
if(invray.y > 0) { tmin = max(tmin, t1); tmax = min(tmax, t2); } else { tmin = max(tmin, t2); tmax = min(tmax, t1); }
if(invray.y > 0) { tmin = std::max(tmin, t1); tmax = std::min(tmax, t2); } else { tmin = std::max(tmin, t2); tmax = std::min(tmax, t1); }
t1 = (m.bbmin.z - o.z)*invray.z;
t2 = (m.bbmax.z - o.z)*invray.z;
if(invray.z > 0) { tmin = max(tmin, t1); tmax = min(tmax, t2); } else { tmin = max(tmin, t2); tmax = min(tmax, t1); }
tmax = min(tmax, maxdist);
if(invray.z > 0) { tmin = std::max(tmin, t1); tmax = std::min(tmax, t2); } else { tmin = std::max(tmin, t2); tmax = std::min(tmax, t1); }
tmax = std::min(tmax, maxdist);
if(tmin < tmax && traverse(m, o, ray, invray, maxdist, dist, mode, m.nodes, tmin, tmax)) return true;
}
return false;
@ -168,10 +170,10 @@ void BIH::build(mesh &m, ushort *indices, int numindices, const ivec &vmin, cons
ivec trimin = ivec(tri.center).sub(ivec(tri.radius)),
trimax = ivec(tri.center).add(ivec(tri.radius));
int amin = trimin[axis], amax = trimax[axis];
if(max(split - amin, 0) > max(amax - split, 0))
if(std::max(split - amin, 0) > std::max(amax - split, 0))
{
++left;
splitleft = max(splitleft, amax);
splitleft = std::max(splitleft, amax);
leftmin.min(trimin);
leftmax.max(trimax);
}
@ -179,7 +181,7 @@ void BIH::build(mesh &m, ushort *indices, int numindices, const ivec &vmin, cons
{
--right;
swap(indices[left], indices[right]);
splitright = min(splitright, amin);
splitright = std::min(splitright, amin);
rightmin.min(trimin);
rightmax.max(trimax);
}
@ -202,13 +204,13 @@ void BIH::build(mesh &m, ushort *indices, int numindices, const ivec &vmin, cons
trimax = ivec(tri.center).add(ivec(tri.radius));
if(i < left)
{
splitleft = max(splitleft, trimax[axis]);
splitleft = std::max(splitleft, trimax[axis]);
leftmin.min(trimin);
leftmax.max(trimax);
}
else
{
splitright = min(splitright, trimin[axis]);
splitright = std::min(splitright, trimin[axis]);
rightmin.min(trimin);
rightmax.max(trimax);
}
@ -366,7 +368,7 @@ static inline float segmentdistance(const vec &d1, const vec &d2, const vec &r)
{
if(e <= 1e-4f) return r.squaredlen();
s = 0;
t = clamp(-f / e, 0.0f, 1.0f);
t = std::clamp(-f / e, 0.0f, 1.0f);
}
else
{
@ -374,22 +376,22 @@ static inline float segmentdistance(const vec &d1, const vec &d2, const vec &r)
if(e <= 1e-4f)
{
t = 0;
s = clamp(c / a, 0.0f, 1.0f);
s = std::clamp(c / a, 0.0f, 1.0f);
}
else
{
float b = d1.dot(d2), denom = a*e - b*b;
s = denom ? clamp((c*e - b*f) / denom, 0.0f, 1.0f) : 0.0f;
s = denom ? std::clamp((c*e - b*f) / denom, 0.0f, 1.0f) : 0.0f;
t = b*s - f;
if(t < 0)
{
t = 0;
s = clamp(c / a, 0.0f, 1.0f);
s = std::clamp(c / a, 0.0f, 1.0f);
}
else if(t > e)
{
t = 1;
s = clamp((b + c) / a, 0.0f, 1.0f);
s = std::clamp((b + c) / a, 0.0f, 1.0f);
}
else t /= e;
}
@ -413,34 +415,34 @@ static inline float trisegmentdistance(const vec &a, const vec &b, const vec &c,
if(ap.dot(nab) < 0) // P outside AB
{
dist = segmentdistance(ab, pq, ap);
if(bq.dot(nbc) < 0) dist = min(dist, segmentdistance(bc, pq, bp)); // Q outside BC
else if(aq.dot(nca) < 0) dist = min(dist, segmentdistance(pq, ca, cp)); // Q outside CA
else if(aq.dot(nab) >= 0) dist = min(dist, dq*dq/n.squaredlen()); // Q inside AB
if(bq.dot(nbc) < 0) dist = std::min(dist, segmentdistance(bc, pq, bp)); // Q outside BC
else if(aq.dot(nca) < 0) dist = std::min(dist, segmentdistance(pq, ca, cp)); // Q outside CA
else if(aq.dot(nab) >= 0) dist = std::min(dist, dq*dq/n.squaredlen()); // Q inside AB
else return dist;
}
else if(bp.dot(nbc) < 0) // P outside BC
{
dist = segmentdistance(bc, pq, bp);
if(aq.dot(nca) < 0) dist = min(dist, segmentdistance(ca, pq, cp)); // Q outside CA
else if(aq.dot(nab) < 0) dist = min(dist, segmentdistance(ab, pq, ap)); // Q outside AB
else if(bq.dot(nbc) >= 0) dist = min(dist, dq*dq/n.squaredlen()); // Q inside BC
if(aq.dot(nca) < 0) dist = std::min(dist, segmentdistance(ca, pq, cp)); // Q outside CA
else if(aq.dot(nab) < 0) dist = std::min(dist, segmentdistance(ab, pq, ap)); // Q outside AB
else if(bq.dot(nbc) >= 0) dist = std::min(dist, dq*dq/n.squaredlen()); // Q inside BC
else return dist;
}
else if(cp.dot(nca) < 0) // P outside CA
{
dist = segmentdistance(ca, pq, cp);
if(aq.dot(nab) < 0) dist = min(dist, segmentdistance(ab, pq, ap)); // Q outside AB
else if(bq.dot(nbc) < 0) dist = min(dist, segmentdistance(bc, pq, bp)); // Q outside BC
else if(aq.dot(nca) >= 0) dist = min(dist, dq*dq/n.squaredlen()); // Q inside CA
if(aq.dot(nab) < 0) dist = std::min(dist, segmentdistance(ab, pq, ap)); // Q outside AB
else if(bq.dot(nbc) < 0) dist = std::min(dist, segmentdistance(bc, pq, bp)); // Q outside BC
else if(aq.dot(nca) >= 0) dist = std::min(dist, dq*dq/n.squaredlen()); // Q inside CA
else return dist;
}
else if(aq.dot(nab) < 0) dist = min(segmentdistance(ab, pq, ap), dp); // Q outside AB
else if(bq.dot(nbc) < 0) dist = min(segmentdistance(bc, pq, bp), dp); // Q outside BC
else if(aq.dot(nca) < 0) dist = min(segmentdistance(ca, pq, cp), dp); // Q outside CA
else if(aq.dot(nab) < 0) dist = std::min(segmentdistance(ab, pq, ap), dp); // Q outside AB
else if(bq.dot(nbc) < 0) dist = std::min(segmentdistance(bc, pq, bp), dp); // Q outside BC
else if(aq.dot(nca) < 0) dist = std::min(segmentdistance(ca, pq, cp), dp); // Q outside CA
else // both P and Q inside
{
if(dp > 0 ? dq <= 0 : dq >= 0) return 0; // P and Q on different sides of triangle
dist = min(dp*dp, dq*dq)/n.squaredlen();
dist = std::min(dp*dp, dq*dq)/n.squaredlen();
return dist;
}
if(dp > 0 ? dq >= 0 : dq <= 0) return dist; // both P and Q on same side of triangle
@ -480,10 +482,10 @@ static inline bool triboxoverlap(const vec &radius, const vec &a, const vec &b,
if(a.w < b.w) \
{ \
if(b.w < c.w) { if(c.w < -radius.w || a.w > radius.w) return false; } \
else if(b.w < -radius.w || min(a.w, c.w) > radius.w) return false; \
else if(b.w < -radius.w || std::min(a.w, c.w) > radius.w) return false; \
} \
else if(a.w < c.w) { if(c.w < -radius.w || b.w > radius.w) return false; } \
else if(a.w < -radius.w || min(b.w, c.w) > radius.w) return false; \
else if(a.w < -radius.w || std::min(b.w, c.w) > radius.w) return false; \
}
TESTFACE(x);
@ -551,7 +553,7 @@ inline void BIH::tricollide<COLLIDE_OBB>(const mesh &m, int tidx, physent *d, co
if(d->type==ENT_PLAYER &&
pdist < (dir.z*n.z < 0 ?
2*radius.z*(d->zmargin/(d->aboveeye+d->eyeheight)-(dir.z < 0 ? 1/3.0f : 1/4.0f)) :
(dir.x*n.x < 0 || dir.y*n.y < 0 ? -max(radius.x, radius.y) : 0)))
(dir.x*n.x < 0 || dir.y*n.y < 0 ? -std::max(radius.x, radius.y) : 0)))
return;
}

View file

@ -1,5 +1,7 @@
#include "blend.hh"
#include <algorithm>
#include <shared/command.hh>
#include <shared/igame.hh>
@ -150,9 +152,9 @@ bool setblendmaporigin(BlendMapCache *cache, const ivec &o, int size)
BlendMapBranch *bm = blendmap.branch;
int bmscale = worldscale-BM_SCALE, bmsize = 1<<bmscale,
x = o.x>>BM_SCALE, y = o.y>>BM_SCALE,
x1 = max(x-1, 0), y1 = max(y-1, 0),
x2 = min(((o.x + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
y2 = min(((o.y + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
x1 = std::max(x-1, 0), y1 = std::max(y-1, 0),
x2 = std::min(((o.x + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
y2 = std::min(((o.y + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
diff = (x1^x2)|(y1^y2);
if(diff < bmsize) while(!(diff&(1<<(bmscale-1))))
{
@ -205,7 +207,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<<cache->scale)-1), cy = clamp(ry+vy, 0, (1<<cache->scale)-1);
int cx = std::clamp(rx+vx, 0, (1<<cache->scale)-1), cy = std::clamp(ry+vy, 0, (1<<cache->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);
@ -217,7 +219,7 @@ uchar lookupblendmap(BlendMapCache *cache, const vec &pos)
static void fillblendmap(uchar &type, BlendMapNode &node, int size, uchar val, int x1, int y1, int x2, int y2)
{
if(max(x1, y1) <= 0 && min(x2, y2) >= size)
if(std::max(x1, y1) <= 0 && std::min(x2, y2) >= size)
{
node.cleanup(type);
type = BM_SOLID;
@ -231,16 +233,16 @@ static void fillblendmap(uchar &type, BlendMapNode &node, int size, uchar val, i
if(y1 < size)
{
if(x1 < size) fillblendmap(node.branch->type[0], node.branch->children[0], size, val,
x1, y1, min(x2, size), min(y2, size));
x1, y1, std::min(x2, size), std::min(y2, size));
if(x2 > size) fillblendmap(node.branch->type[1], node.branch->children[1], size, val,
max(x1-size, 0), y1, x2-size, min(y2, size));
std::max(x1-size, 0), y1, x2-size, std::min(y2, size));
}
if(y2 > size)
{
if(x1 < size) fillblendmap(node.branch->type[2], node.branch->children[2], size, val,
x1, max(y1-size, 0), min(x2, size), y2-size);
x1, std::max(y1-size, 0), std::min(x2, size), y2-size);
if(x2 > size) fillblendmap(node.branch->type[3], node.branch->children[3], size, val,
max(x1-size, 0), max(y1-size, 0), x2-size, y2-size);
std::max(x1-size, 0), std::max(y1-size, 0), x2-size, y2-size);
}
loopi(4) if(node.branch->type[i]!=BM_SOLID || node.branch->children[i].solid->val!=val) return;
node.cleanup(type);
@ -276,11 +278,11 @@ static void fillblendmap(uchar &type, BlendMapNode &node, int size, uchar val, i
static void fillblendmap(int x, int y, int w, int h, uchar val)
{
int bmsize = 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);
if(max(x1, y1) >= bmsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
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(std::max(x1, y1) >= bmsize || std::min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
fillblendmap(blendmap.type, blendmap, bmsize, val, x1, y1, x2, y2);
}
@ -292,16 +294,16 @@ static void invertblendmap(uchar &type, BlendMapNode &node, int size, int x1, in
if(y1 < size)
{
if(x1 < size) invertblendmap(node.branch->type[0], node.branch->children[0], size,
x1, y1, min(x2, size), min(y2, size));
x1, y1, std::min(x2, size), std::min(y2, size));
if(x2 > size) invertblendmap(node.branch->type[1], node.branch->children[1], size,
max(x1-size, 0), y1, x2-size, min(y2, size));
std::max(x1-size, 0), y1, x2-size, std::min(y2, size));
}
if(y2 > size)
{
if(x1 < size) invertblendmap(node.branch->type[2], node.branch->children[2], size,
x1, max(y1-size, 0), min(x2, size), y2-size);
x1, std::max(y1-size, 0), std::min(x2, size), y2-size);
if(x2 > size) invertblendmap(node.branch->type[3], node.branch->children[3], size,
max(x1-size, 0), max(y1-size, 0), x2-size, y2-size);
std::max(x1-size, 0), std::max(y1-size, 0), x2-size, y2-size);
}
return;
}
@ -323,11 +325,11 @@ static void invertblendmap(uchar &type, BlendMapNode &node, int size, int x1, in
static void invertblendmap(int x, int y, int w, int h)
{
int bmsize = 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);
if(max(x1, y1) >= bmsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
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(std::max(x1, y1) >= bmsize || std::min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
invertblendmap(blendmap.type, blendmap, bmsize, x1, y1, x2, y2);
}
@ -405,10 +407,10 @@ 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);
src += std::max(bmy - sy, 0)*sw + std::max(bmx - sx, 0);
loopi(y2-y1)
{
switch(smode)
@ -418,19 +420,19 @@ static void blitblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int
break;
case 2:
loopi(x2 - x1) dst[i] = min(dst[i], src[i]);
loopi(x2 - x1) dst[i] = std::min(dst[i], src[i]);
break;
case 3:
loopi(x2 - x1) dst[i] = max(dst[i], src[i]);
loopi(x2 - x1) dst[i] = std::max(dst[i], src[i]);
break;
case 4:
loopi(x2 - x1) dst[i] = min(dst[i], uchar(0xFF - src[i]));
loopi(x2 - x1) dst[i] = std::min(dst[i], uchar(0xFF - src[i]));
break;
case 5:
loopi(x2 - x1) dst[i] = max(dst[i], uchar(0xFF - src[i]));
loopi(x2 - x1) dst[i] = std::max(dst[i], uchar(0xFF - src[i]));
break;
}
dst += BM_IMAGE_SIZE;
@ -441,7 +443,7 @@ static void blitblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int
static void blitblendmap(uchar *src, int sx, int sy, int sw, int sh, int smode)
{
int bmsize = worldsize>>BM_SCALE;
if(max(sx, sy) >= bmsize || min(sx+sw, sy+sh) <= 0 || min(sw, sh) <= 0) return;
if(std::max(sx, sy) >= bmsize || std::min(sx+sw, sy+sh) <= 0 || std::min(sw, sh) <= 0) return;
blitblendmap(blendmap.type, blendmap, 0, 0, bmsize, src, sx, sy, sw, sh, smode);
}
@ -511,8 +513,8 @@ static int calcblendlayer(uchar &type, BlendMapNode &node, int bmx, int bmy, int
if(type == BM_SOLID) val = node.solid->val;
else
{
int x1 = clamp(cx - bmx, 0, bmsize), y1 = clamp(cy - bmy, 0, bmsize),
x2 = clamp(cx+cw - bmx, 0, bmsize), y2 = clamp(cy+ch - bmy, 0, bmsize);
int x1 = std::clamp(cx - bmx, 0, bmsize), y1 = std::clamp(cy - bmy, 0, bmsize),
x2 = std::clamp(cx+cw - bmx, 0, bmsize), y2 = std::clamp(cy+ch - bmy, 0, bmsize);
uchar *src = &node.image->data[y1*BM_IMAGE_SIZE + x1];
val = src[0];
loopi(y2-y1)
@ -532,10 +534,10 @@ static int calcblendlayer(uchar &type, BlendMapNode &node, int bmx, int bmy, int
int calcblendlayer(int x1, int y1, int x2, int y2)
{
int bmsize = worldsize>>BM_SCALE,
ux1 = max(x1, 0) >> BM_SCALE,
ux2 = (min(x2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE,
uy1 = max(y1, 0) >> BM_SCALE,
uy2 = (min(y2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE;
ux1 = std::max(x1, 0) >> BM_SCALE,
ux2 = (std::min(x2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE,
uy1 = std::max(y1, 0) >> BM_SCALE,
uy2 = (std::min(y2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE;
if(ux1 >= ux2 || uy1 >= uy2) return LAYER_TOP;
return calcblendlayer(blendmap.type, blendmap, 0, 0, bmsize, ux1, uy1, ux2-ux1, uy2-uy1);
}
@ -659,7 +661,7 @@ struct BlendTexture
bool setup(int sz)
{
if(!tex) glGenTextures(1, &tex);
sz = min(sz, maxtexsize ? min(maxtexsize, hwtexsize) : hwtexsize);
sz = std::min(sz, maxtexsize ? std::min(maxtexsize, hwtexsize) : hwtexsize);
while(sz&(sz-1)) sz &= sz-1;
if(sz == size) return false;
size = sz;
@ -722,11 +724,11 @@ static void renderblendtexture(uchar &type, BlendMapNode &node, int bmx, int bmy
return;
}
int x1 = clamp(dx - bmx, 0, bmsize), y1 = clamp(dy - bmy, 0, bmsize),
x2 = clamp(dx+dw - bmx, 0, bmsize), y2 = clamp(dy+dh - bmy, 0, bmsize),
tsize = 1<<(min(worldscale, 12)-BM_SCALE),
int x1 = std::clamp(dx - bmx, 0, bmsize), y1 = std::clamp(dy - bmy, 0, bmsize),
x2 = std::clamp(dx+dw - bmx, 0, bmsize), y2 = std::clamp(dy+dh - bmy, 0, bmsize),
tsize = 1<<(std::min(worldscale, 12)-BM_SCALE),
step = tsize/dsize, stepw = (x2 - x1)/step, steph = (y2 - y1)/step;
dst += max(bmy - dy, 0)/step*dsize + max(bmx - dx, 0)/step;
dst += std::max(bmy - dy, 0)/step*dsize + std::max(bmx - dx, 0)/step;
if(type == BM_SOLID) loopi(steph)
{
memset(dst, node.solid->val, stepw);
@ -748,7 +750,7 @@ static void renderblendtexture(uchar &type, BlendMapNode &node, int bmx, int bmy
void renderblendtexture(uchar *dst, int dsize, int dx, int dy, int dw, int dh)
{
int bmsize = worldsize>>BM_SCALE;
if(max(dx, dy) >= bmsize || min(dx+dw, dy+dh) <= 0 || min(dw, dh) <= 0) return;
if(std::max(dx, dy) >= bmsize || std::min(dx+dw, dy+dh) <= 0 || std::min(dw, dh) <= 0) return;
renderblendtexture(blendmap.type, blendmap, 0, 0, bmsize, dst, dsize, dx, dy, dw, dh);
}
@ -779,10 +781,10 @@ static bool usesblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int
bool usesblendmap(int x1, int y1, int x2, int y2)
{
int bmsize = worldsize>>BM_SCALE,
ux1 = max(x1, 0) >> BM_SCALE,
ux2 = (min(x2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE,
uy1 = max(y1, 0) >> BM_SCALE,
uy2 = (min(y2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE;
ux1 = std::max(x1, 0) >> BM_SCALE,
ux2 = (std::min(x2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE,
uy1 = std::max(y1, 0) >> BM_SCALE,
uy2 = (std::min(y2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE;
if(ux1 >= ux2 || uy1 >= uy2) return false;
return usesblendmap(blendmap.type, blendmap, 0, 0, bmsize, ux1, uy1, ux2-ux1, uy2-uy1);
}
@ -792,7 +794,7 @@ void bindblendtexture(const ivec &p)
loopv(blendtexs) if(blendtexs[i].contains(p))
{
BlendTexture &bt = blendtexs[i];
int tsize = 1<<min(worldscale, 12);
int tsize = 1<<std::min(worldscale, 12);
GLOBALPARAMF(blendmapparams, bt.x, bt.y, 1.0f/tsize, 1.0f/tsize);
glBindTexture(GL_TEXTURE_2D, bt.tex);
break;
@ -824,10 +826,10 @@ static void updateblendtextures(uchar &type, BlendMapNode &node, int bmx, int bm
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
int tx1 = max(bmx, ux)&~((0x1000>>BM_SCALE)-1),
tx2 = (min(bmx+bmsize, ux+uw) + (0x1000>>BM_SCALE)-1)&~((0x1000>>BM_SCALE)-1),
ty1 = max(bmy, uy)&~((0x1000>>BM_SCALE)-1),
ty2 = (min(bmy+bmsize, uy+uh) + (0x1000>>BM_SCALE)-1)&~((0x1000>>BM_SCALE)-1);
int tx1 = std::max(bmx, ux)&~((0x1000>>BM_SCALE)-1),
tx2 = (std::min(bmx+bmsize, ux+uw) + (0x1000>>BM_SCALE)-1)&~((0x1000>>BM_SCALE)-1),
ty1 = std::max(bmy, uy)&~((0x1000>>BM_SCALE)-1),
ty2 = (std::min(bmy+bmsize, uy+uh) + (0x1000>>BM_SCALE)-1)&~((0x1000>>BM_SCALE)-1);
for(int ty = ty1; ty < ty2; ty += 0x1000>>BM_SCALE) for(int tx = tx1; tx < tx2; tx += 0x1000>>BM_SCALE)
{
BlendTexture *bt = nullptr;
@ -838,16 +840,16 @@ static void updateblendtextures(uchar &type, BlendMapNode &node, int bmx, int bm
bt->x = tx<<BM_SCALE;
bt->y = ty<<BM_SCALE;
}
bt->setup(1<<min(worldscale-BM_SCALE, blendtexsize));
int tsize = 1<<(min(worldscale, 12)-BM_SCALE),
bt->setup(1<<std::min(worldscale-BM_SCALE, blendtexsize));
int tsize = 1<<(std::min(worldscale, 12)-BM_SCALE),
ux1 = tx, ux2 = tx + tsize, uy1 = ty, uy2 = ty + tsize,
step = tsize/bt->size;
if(!bt->valid)
{
ux1 = max(ux1, ux&~(step-1));
ux2 = min(ux2, (ux+uw+step-1)&~(step-1));
uy1 = max(uy1, uy&~(step-1));
uy2 = min(uy2, (uy+uh+step-1)&~(step-1));
ux1 = std::max(ux1, ux&~(step-1));
ux2 = std::min(ux2, (ux+uw+step-1)&~(step-1));
uy1 = std::max(uy1, uy&~(step-1));
uy2 = std::min(uy2, (uy+uh+step-1)&~(step-1));
bt->valid = true;
}
uchar *data = bt->data + (uy1-ty)/step*bt->size + (ux1-tx)/step;
@ -863,10 +865,10 @@ static void updateblendtextures(uchar &type, BlendMapNode &node, int bmx, int bm
void updateblendtextures(int x1, int y1, int x2, int y2)
{
int bmsize = worldsize>>BM_SCALE,
ux1 = max(x1, 0) >> BM_SCALE,
ux2 = (min(x2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE,
uy1 = max(y1, 0) >> BM_SCALE,
uy2 = (min(y2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE;
ux1 = std::max(x1, 0) >> BM_SCALE,
ux2 = (std::min(x2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE,
uy1 = std::max(y1, 0) >> BM_SCALE,
uy2 = (std::min(y2, worldsize) + (1<<BM_SCALE)-1) >> BM_SCALE;
if(ux1 >= ux2 || uy1 >= uy2) return;
updateblendtextures(blendmap.type, blendmap, 0, 0, bmsize, ux1, uy1, ux2-ux1, uy2-uy1);
}
@ -896,7 +898,7 @@ static 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);
}
COMMAND(delblendbrush, "s");
@ -907,7 +909,7 @@ static void addblendbrush(const char *name, const char *imgname)
ImageData s;
if(!loadimage(imgname, s)) { conoutf(CON_ERROR, "could not load blend brush image %s", imgname); return; }
if(max(s.w, s.h) > (1<<12))
if(std::max(s.w, s.h) > (1<<12))
{
conoutf(CON_ERROR, "blend brush image size exceeded %dx%d pixels: %s", 1<<12, 1<<12, imgname);
return;
@ -973,7 +975,7 @@ ICOMMAND(rotateblendbrush, "i", (int *val),
if(!canpaintblendmap()) return;
BlendBrush *brush = brushes[curbrush];
const texrotation &r = texrotations[*val < 0 ? 3 : clamp(*val, 1, 7)];
const texrotation &r = texrotations[*val < 0 ? 3 : std::clamp(*val, 1, 7)];
brush->reorient(r.flipx, r.flipy, r.swapxy);
});
@ -982,8 +984,8 @@ static void paintblendmap(bool msg)
if(!canpaintblendmap(true, false, msg)) return;
BlendBrush *brush = brushes[curbrush];
int x = (int)floor(clamp(worldpos.x, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->w),
y = (int)floor(clamp(worldpos.y, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->h);
int x = (int)floor(std::clamp(worldpos.x, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->w),
y = (int)floor(std::clamp(worldpos.y, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->h);
blitblendmap(brush->data, x, y, brush->w, brush->h, blendpaintmode);
previewblends(ivec((x-1)<<BM_SCALE, (y-1)<<BM_SCALE, 0),
ivec((x+brush->w+1)<<BM_SCALE, (y+brush->h+1)<<BM_SCALE, worldsize));
@ -1091,12 +1093,12 @@ void renderblendbrush()
if(!blendpaintmode || !brushes.inrange(curbrush)) return;
BlendBrush *brush = brushes[curbrush];
int x1 = (int)floor(clamp(worldpos.x, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->w) << BM_SCALE,
y1 = (int)floor(clamp(worldpos.y, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->h) << BM_SCALE,
int x1 = (int)floor(std::clamp(worldpos.x, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->w) << BM_SCALE,
y1 = (int)floor(std::clamp(worldpos.y, 0.0f, float(worldsize))/(1<<BM_SCALE) - 0.5f*brush->h) << BM_SCALE,
x2 = x1 + (brush->w << BM_SCALE),
y2 = y1 + (brush->h << BM_SCALE);
if(max(x1, y1) >= worldsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
if(std::max(x1, y1) >= worldsize || std::min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
if(!brush->tex) brush->gentex();
renderblendbrush(brush->tex, x1, y1, x2 - x1, y2 - y1);

View file

@ -6,6 +6,8 @@
#include <cctype>
#include <climits>
#include <algorithm>
#include <sauerlib/encoding.hh>
#include <shared/igame.hh>
@ -653,7 +655,7 @@ void setvar(const char *name, int i, bool dofunc, bool doclamp)
{
GETVAR(id, name, );
OVERRIDEVAR(return, id->overrideval.i = *id->storage.i, , )
if(doclamp) *id->storage.i = clamp(i, id->minval, id->maxval);
if(doclamp) *id->storage.i = std::clamp(i, id->minval, id->maxval);
else *id->storage.i = i;
if(dofunc) id->changed();
}
@ -661,7 +663,7 @@ void setfvar(const char *name, float f, bool dofunc, bool doclamp)
{
_GETVAR(id, ID_FVAR, name, );
OVERRIDEVAR(return, id->overrideval.f = *id->storage.f, , );
if(doclamp) *id->storage.f = clamp(f, id->minvalf, id->maxvalf);
if(doclamp) *id->storage.f = std::clamp(f, id->minvalf, id->maxvalf);
else *id->storage.f = f;
if(dofunc) id->changed();
}
@ -924,7 +926,7 @@ static char *conc(tagval *v, int n, bool space, const char *prefix, int prefixle
default: vlen[i] = 0; break;
}
overflow:
if(space) len += max(prefix ? i : i-1, 0);
if(space) len += std::max(prefix ? i : i-1, 0);
char *buf = newstring(len + numlen);
int offset = 0, numoffset = 0;
if(prefix)
@ -2210,8 +2212,8 @@ static inline void callcommand(ident *id, tagval *args, int numargs, bool lookup
#ifndef STANDALONE
case 'D': if(++i < numargs) freearg(args[i]); addreleaseaction(id, args, i); fakeargs++; break;
#endif
case 'C': { i = max(i+1, numargs); vector<char> buf; ((comfun1)id->fun)(conc(buf, args, i, true)); goto cleanup; }
case 'V': i = max(i+1, numargs); ((comfunv)id->fun)(args, i); goto cleanup;
case 'C': { i = std::max(i+1, numargs); vector<char> buf; ((comfun1)id->fun)(conc(buf, args, i, true)); goto cleanup; }
case 'V': i = std::max(i+1, numargs); ((comfunv)id->fun)(args, i); goto cleanup;
case '1': case '2': case '3': case '4': if(i+1 < numargs) { fmt -= *fmt-'0'+1; rep = true; } break;
}
++i;
@ -3520,14 +3522,14 @@ COMMAND(at, "si1V");
void substr(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(substr, "siiN");
void sublist(const char *s, int *skip, int *count, int *numargs)
{
int offset = max(*skip, 0), len = *numargs >= 3 ? max(*count, 0) : -1;
int offset = std::max(*skip, 0), len = *numargs >= 3 ? std::max(*count, 0) : -1;
loopi(offset) if(!parselist(s)) break;
if(len < 0) { if(offset > 0) skiplist(s); commandret->setstr(newstring(s)); return; }
const char *list = s, *start, *end, *qstart, *qend = s;
@ -3798,7 +3800,7 @@ LISTMERGECMD(listunion, p.put(list, strlen(list)), elems, list, <);
void listsplice(const char *s, const char *vals, int *skip, int *count)
{
int offset = max(*skip, 0), len = max(*count, 0);
int offset = std::max(*skip, 0), len = std::max(*count, 0);
const char *list = s, *start, *end, *qstart, *qend = s;
loopi(offset) if(!parselist(s, start, end, qstart, qend)) break;
vector<char> p;
@ -3942,7 +3944,7 @@ void sortlist(char *list, ident *x, ident *y, uint *body, uint *unique)
poparg(*y);
char *sorted = cstr;
int sortedlen = totalunique + max(numunique - 1, 0);
int sortedlen = totalunique + std::max(numunique - 1, 0);
if(clen < sortedlen)
{
delete[] cstr;
@ -4018,8 +4020,8 @@ MATHICMD(|, 0, );
MATHICMD(^~, 0, );
MATHICMD(&~, 0, );
MATHICMD(|~, 0, );
MATHCMD("<<", i, int, val = val2 < 32 ? val << max(val2, 0) : 0, 0, );
MATHCMD(">>", i, int, val >>= clamp(val2, 0, 31), 0, );
MATHCMD("<<", i, int, val = val2 < 32 ? val << std::max(val2, 0) : 0, 0, );
MATHCMD(">>", i, int, val >>= std::clamp(val2, 0, 31), 0, );
MATHFCMD(+, 0, );
MATHFCMD(*, 1, );
@ -4152,12 +4154,12 @@ CASECOMMAND(cases, "s", const char *, args[0].getstr(), args[i].type == VAL_NULL
ICOMMAND(rnd, "ii", (int *a, int *b), intret(*a - *b > 0 ? rnd(*a - *b) + *b : *b));
ICOMMAND(rndstr, "i", (int *len),
{
int n = clamp(*len, 0, 10000);
int n = std::clamp(*len, 0, 10000);
char *s = newstring(n);
for(int i = 0; i < n;)
{
uint r = randomMT();
for(int j = min(i + 4, n); i < j; i++)
for(int j = std::min(i + 4, n); i < j; i++)
{
s[i] = (r%255) + 1;
r /= 255;
@ -4171,7 +4173,7 @@ ICOMMAND(tohex, "ii", (int *n, int *p),
{
const int len = 20;
char *buf = newstring(len);
nformatstring(buf, len, "0x%.*X", max(*p, 1), *n);
nformatstring(buf, len, "0x%.*X", std::max(*p, 1), *n);
stringret(buf);
});
@ -4247,8 +4249,8 @@ ICOMMAND(strreplace, "ssss", (char *s, char *o, char *n, char *n2), commandret->
void strsplice(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);
@ -4271,7 +4273,7 @@ vector<sleepcmd> sleepcmds;
void addsleep(int *msec, char *cmd)
{
sleepcmd &s = sleepcmds.add();
s.delay = max(*msec, 1);
s.delay = std::max(*msec, 1);
s.millis = lastmillis;
s.command = newstring(cmd);
s.flags = identflags;

View file

@ -93,13 +93,13 @@ static int conskip = 0, miniconskip = 0;
static void setconskip(int &skip, int filter, int n)
{
int offset = abs(n), dir = n < 0 ? -1 : 1;
skip = clamp(skip, 0, conlines.length()-1);
skip = std::clamp(skip, 0, conlines.length()-1);
while(offset)
{
skip += dir;
if(!conlines.inrange(skip))
{
skip = clamp(skip, 0, conlines.length()-1);
skip = std::clamp(skip, 0, conlines.length()-1);
return;
}
if(conlines[skip].type&filter) --offset;
@ -113,7 +113,7 @@ ICOMMAND(clearconsole, "", (), { while(conlines.length()) delete[] conlines.pop(
static float drawconlines(int conskip, int confade, float conwidth, float conheight, float conoff, int filter, float y = 0, int dir = 1)
{
int numl = conlines.length(), offset = min(conskip, numl);
int numl = conlines.length(), offset = std::min(conskip, numl);
if(confade)
{
@ -164,11 +164,11 @@ float renderfullconsole(float w, float h)
float renderconsole(float w, float h, float abovehud)
{
float conpad = FONTH/2,
conheight = min(float(FONTH*consize), h - 2*conpad),
conheight = std::min(float(FONTH*consize), h - 2*conpad),
conwidth = w - 2*conpad - game::clipconsole(w, h);
float y = drawconlines(conskip, confade, conwidth, conheight, conpad, confilter);
if(miniconsize && miniconwidth)
drawconlines(miniconskip, miniconfade, (miniconwidth*(w - 2*conpad))/100, min(float(FONTH*miniconsize), abovehud - y), conpad, miniconfilter, abovehud, -1);
drawconlines(miniconskip, miniconfade, (miniconwidth*(w - 2*conpad))/100, std::min(float(FONTH*miniconsize), abovehud - y), conpad, miniconfilter, abovehud, -1);
return y;
}
@ -474,7 +474,7 @@ static bool consoleinput(const char *str, int len)
resetcomplete();
int cmdlen = (int)strlen(commandbuf), cmdspace = int(sizeof(commandbuf)) - (cmdlen+1);
len = min(len, cmdspace);
len = std::min(len, cmdspace);
if(commandpos<0)
{
memcpy(&commandbuf[cmdlen], str, len);
@ -798,7 +798,7 @@ static void complete(char *s, int maxlen, const char *cmdprefix)
DELETEA(lastcomplete);
if(nextcomplete)
{
cmdlen = min(cmdlen, maxlen-1);
cmdlen = std::min(cmdlen, maxlen-1);
if(cmdlen) memmove(s, cmdprefix, cmdlen);
copystring(&s[cmdlen], nextcomplete, maxlen-cmdlen);
lastcomplete = newstring(nextcomplete);

View file

@ -67,8 +67,8 @@ struct skelbih
Texture *tex = s[t.mesh].tex; \
if(tex->type&Texture::ALPHA && (tex->alphamask || loadalphamask(tex))) \
{ \
int si = clamp(int(tex->xs * (va.tc.x + u*(vb.tc.x - va.tc.x) + v*(vc.tc.x - va.tc.x))), 0, tex->xs-1), \
ti = clamp(int(tex->ys * (va.tc.y + u*(vb.tc.y - va.tc.y) + v*(vc.tc.y - va.tc.y))), 0, tex->ys-1); \
int si = std::clamp(int(tex->xs * (va.tc.x + u*(vb.tc.x - va.tc.x) + v*(vc.tc.x - va.tc.x))), 0, tex->xs-1), \
ti = std::clamp(int(tex->ys * (va.tc.y + u*(vb.tc.y - va.tc.y) + v*(vc.tc.y - va.tc.y))), 0, tex->ys-1); \
if(!(tex->alphamask[ti*((tex->xs+7)/8) + si/8] & (1<<(si%8)))) return false; \
} \
} \

View file

@ -1,5 +1,7 @@
#include "light.hh"
#include <algorithm>
#include <shared/command.hh>
#include <shared/igame.hh>
@ -680,7 +682,7 @@ static void lightreaching(const vec &target, vec &color, vec &dir, bool fast = f
if(e.attached && e.attached->type==ET_SPOTLIGHT)
{
vec spot = vec(e.attached->o).sub(e.o).normalize();
float spotatten = 1 - (1 - ray.dot(spot)) / (1 - cos360(clamp(int(e.attached->attr1), 1, 89)));
float spotatten = 1 - (1 - ray.dot(spot)) / (1 - cos360(std::clamp(int(e.attached->attr1), 1, 89)));
if(spotatten <= 0) continue;
intensity *= spotatten;
}

View file

@ -34,7 +34,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;
@ -44,7 +44,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;
gle::begin(GL_TRIANGLE_STRIP);
loopj(numsteps)

View file