Skip to content

Commit f8188c0

Browse files
MoonPadUServoidanix
authored andcommitted
Use STL's min and max implementation
1 parent 1eb22f4 commit f8188c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+950
-966
lines changed

src/engine/animmodel.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct animmodel : model
4040
}
4141
else
4242
{
43-
fr1 = min(fr1, info.range-1)+info.frame;
44-
fr2 = min(fr1+1, info.frame+info.range-1);
43+
fr1 = std::min(fr1, info.range - 1) + info.frame;
44+
fr2 = std::min(fr1 + 1, info.frame + info.range - 1);
4545
}
4646
if(info.anim&ANIM_REVERSE)
4747
{
@@ -139,8 +139,8 @@ struct animmodel : model
139139
gle::color(vec(lightcolor).max(mincolor), trans);
140140
}
141141

142-
if(material > 0 && lightmaterial) LOCALPARAM(lightmaterial, lightmaterial[min(material, int(MAXLIGHTMATERIALS))-1].tocolor().mul(2));
143-
if(material2 > 0 && lightmaterial) LOCALPARAM(lightmaterial2, lightmaterial[min(material2, int(MAXLIGHTMATERIALS))-1].tocolor().mul(2));
142+
if(material > 0 && lightmaterial) LOCALPARAM(lightmaterial, lightmaterial[std::min(material, int(MAXLIGHTMATERIALS)) - 1].tocolor().mul(2));
143+
if(material2 > 0 && lightmaterial) LOCALPARAM(lightmaterial2, lightmaterial[std::min(material2, int(MAXLIGHTMATERIALS)) - 1].tocolor().mul(2));
144144

145145
if(key->checkversion() && Shader::lastshader->owner == key) return;
146146
Shader::lastshader->owner = key;
@@ -153,8 +153,8 @@ struct animmodel : model
153153
}
154154
else
155155
{
156-
float bias = max(mincolor-1.0f, 0.2f), scale = 0.5f*max(0.8f-bias, 0.0f),
157-
minshade = scale*max(ambient, mincolor);
156+
float bias = std::max(mincolor - 1.0f, 0.2f), scale = 0.5f * std::max(0.8f - bias, 0.0f),
157+
minshade = scale * std::max(ambient, mincolor);
158158
LOCALPARAMF(lightscale, scale - minshade, scale, minshade + bias);
159159
}
160160
float curglow = glow;
@@ -519,7 +519,7 @@ struct animmodel : model
519519
virtual int totalframes() const { return 1; }
520520
bool hasframe(int i) const { return i>=0 && i<totalframes(); }
521521
bool hasframes(int i, int n) const { return i>=0 && i+n<=totalframes(); }
522-
int clipframes(int i, int n) const { return min(n, totalframes() - i); }
522+
int clipframes(int i, int n) const { return std::min(n, totalframes() - i); }
523523

524524
virtual void cleanup() {}
525525
virtual void preload(part *p) {}
@@ -836,7 +836,7 @@ struct animmodel : model
836836
if(d && interp>=0)
837837
{
838838
animinterpinfo &ai = d->animinterp[interp];
839-
if((info.anim&ANIM_CLAMP)==ANIM_CLAMP) aitime = min(aitime, int(info.range*info.speed*0.5e-3f));
839+
if((info.anim&ANIM_CLAMP)==ANIM_CLAMP) aitime = std::min(aitime, int(info.range * info.speed * 0.5e-3f));
840840
void *ak = meshes->animkey();
841841
if(d->ragdoll && !(anim&ANIM_RAGDOLL))
842842
{
@@ -1515,7 +1515,7 @@ template<class MDL, class MESH> struct modelcommands
15151515

15161516
static void setalphatest(char *meshname, float *cutoff)
15171517
{
1518-
loopskins(meshname, s, s.alphatest = max(0.0f, min(1.0f, *cutoff)));
1518+
loopskins(meshname, s, s.alphatest = std::max(0.0f, std::min(1.0f, *cutoff)));
15191519
}
15201520

15211521
static void setalphablend(char *meshname, int *blend)

src/engine/bih.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
6969
if(!curnode->isleaf(faridx))
7070
{
7171
curnode += curnode->childindex(faridx);
72-
tmin = max(tmin, farsplit);
72+
tmin = std::max(tmin, farsplit);
7373
continue;
7474
}
7575
else if(triintersect(m, curnode->childindex(faridx), mo, mray, maxdist, maxdist, mode))
@@ -91,7 +91,7 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
9191
if(!curnode->isleaf(faridx))
9292
{
9393
curnode += curnode->childindex(faridx);
94-
tmin = max(tmin, farsplit);
94+
tmin = std::max(tmin, farsplit);
9595
continue;
9696
}
9797
else if(triintersect(m, curnode->childindex(faridx), mo, mray, maxdist, maxdist, mode))
@@ -111,18 +111,18 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
111111
{
112112
traversestate &save = stack[stacksize++];
113113
save.node = curnode + curnode->childindex(faridx);
114-
save.tmin = max(tmin, farsplit);
114+
save.tmin = std::max(tmin, farsplit);
115115
save.tmax = tmax;
116116
}
117117
else
118118
{
119-
if(traverse(m, o, ray, invray, maxdist, maxdist, mode, curnode + curnode->childindex(nearidx), tmin, min(tmax, nearsplit)))
119+
if(traverse(m, o, ray, invray, maxdist, maxdist, mode, curnode + curnode->childindex(nearidx), tmin, std::min(tmax, nearsplit)))
120120
{
121121
if(mode&RAY_SHADOW) { dist = maxdist; return true; }
122122
hit = true;
123123
}
124124
curnode += curnode->childindex(faridx);
125-
tmin = max(tmin, farsplit);
125+
tmin = std::max(tmin, farsplit);
126126
continue;
127127
}
128128
}
@@ -133,7 +133,7 @@ inline bool BIH::traverse(const mesh &m, const vec &o, const vec &ray, const vec
133133
}
134134
}
135135
curnode += curnode->childindex(nearidx);
136-
tmax = min(tmax, nearsplit);
136+
tmax = std::min(tmax, nearsplit);
137137
continue;
138138
}
139139
if(stacksize <= 0) { if(hit) { dist = maxdist; return true; } return false; }
@@ -158,11 +158,11 @@ inline bool BIH::traverse(const vec &o, const vec &ray, float maxdist, float &di
158158
if(invray.x > 0) { tmin = t1; tmax = t2; } else { tmin = t2; tmax = t1; }
159159
t1 = (m.bbmin.y - o.y)*invray.y;
160160
t2 = (m.bbmax.y - o.y)*invray.y;
161-
if(invray.y > 0) { tmin = max(tmin, t1); tmax = min(tmax, t2); } else { tmin = max(tmin, t2); tmax = min(tmax, t1); }
161+
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); }
162162
t1 = (m.bbmin.z - o.z)*invray.z;
163163
t2 = (m.bbmax.z - o.z)*invray.z;
164-
if(invray.z > 0) { tmin = max(tmin, t1); tmax = min(tmax, t2); } else { tmin = max(tmin, t2); tmax = min(tmax, t1); }
165-
tmax = min(tmax, maxdist);
164+
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); }
165+
tmax = std::min(tmax, maxdist);
166166
if(tmin < tmax && traverse(m, o, ray, invray, maxdist, maxdist, mode, m.nodes, tmin, tmax))
167167
{
168168
if(mode&RAY_SHADOW) { dist = maxdist; return true; }
@@ -192,18 +192,18 @@ void BIH::build(mesh &m, ushort *indices, int numindices, const ivec &vmin, cons
192192
ivec trimin = ivec(tri.center).sub(ivec(tri.radius)),
193193
trimax = ivec(tri.center).add(ivec(tri.radius));
194194
int amin = trimin[axis], amax = trimax[axis];
195-
if(max(split - amin, 0) > max(amax - split, 0))
195+
if(std::max(split - amin, 0) > std::max(amax - split, 0))
196196
{
197197
++left;
198-
splitleft = max(splitleft, amax);
198+
splitleft = std::max(splitleft, amax);
199199
leftmin.min(trimin);
200200
leftmax.max(trimax);
201201
}
202202
else
203203
{
204204
--right;
205205
std::swap(indices[left], indices[right]);
206-
splitright = min(splitright, amin);
206+
splitright = std::min(splitright, amin);
207207
rightmin.min(trimin);
208208
rightmax.max(trimax);
209209
}
@@ -226,13 +226,13 @@ void BIH::build(mesh &m, ushort *indices, int numindices, const ivec &vmin, cons
226226
trimax = ivec(tri.center).add(ivec(tri.radius));
227227
if(i < left)
228228
{
229-
splitleft = max(splitleft, trimax[axis]);
229+
splitleft = std::max(splitleft, trimax[axis]);
230230
leftmin.min(trimin);
231231
leftmax.max(trimax);
232232
}
233233
else
234234
{
235-
splitright = min(splitright, trimin[axis]);
235+
splitright = std::min(splitright, trimin[axis]);
236236
rightmin.min(trimin);
237237
rightmax.max(trimax);
238238
}
@@ -306,7 +306,7 @@ BIH::BIH(vector<mesh> &buildmeshes)
306306

307307
center = vec(bbmin).add(bbmax).mul(0.5f);
308308
radius = vec(bbmax).sub(bbmin).mul(0.5f).magnitude();
309-
entradius = max(bbmin.squaredlen(), bbmax.squaredlen());
309+
entradius = std::max(bbmin.squaredlen(), bbmax.squaredlen());
310310

311311
nodes = new node[numtris];
312312
node *curnode = nodes;

src/engine/blend.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ bool setblendmaporigin(BlendMapCache *cache, const ivec &o, int size)
139139
BlendMapBranch *bm = blendmap.branch;
140140
int bmscale = worldscale-BM_SCALE, bmsize = 1<<bmscale,
141141
x = o.x>>BM_SCALE, y = o.y>>BM_SCALE,
142-
x1 = max(x-1, 0), y1 = max(y-1, 0),
143-
x2 = min(((o.x + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
144-
y2 = min(((o.y + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
142+
x1 = std::max(x - 1, 0), y1 = std::max(y - 1, 0),
143+
x2 = std::min(((o.x + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
144+
y2 = std::min(((o.y + size + (1<<BM_SCALE)-1)>>BM_SCALE) + 1, bmsize),
145145
diff = (x1^x2)|(y1^y2);
146146
if(diff < bmsize) while(!(diff&(1<<(bmscale-1))))
147147
{
@@ -206,7 +206,7 @@ uchar lookupblendmap(BlendMapCache *cache, const vec &pos)
206206

207207
static void fillblendmap(uchar &type, BlendMapNode &node, int size, uchar val, int x1, int y1, int x2, int y2)
208208
{
209-
if(max(x1, y1) <= 0 && min(x2, y2) >= size)
209+
if(std::max(x1, y1) <= 0 && std::min(x2, y2) >= size)
210210
{
211211
node.cleanup(type);
212212
type = BM_SOLID;
@@ -220,16 +220,16 @@ static void fillblendmap(uchar &type, BlendMapNode &node, int size, uchar val, i
220220
if(y1 < size)
221221
{
222222
if(x1 < size) fillblendmap(node.branch->type[0], node.branch->children[0], size, val,
223-
x1, y1, min(x2, size), min(y2, size));
223+
x1, y1, std::min(x2, size), std::min(y2, size));
224224
if(x2 > size) fillblendmap(node.branch->type[1], node.branch->children[1], size, val,
225-
max(x1-size, 0), y1, x2-size, min(y2, size));
225+
std::max(x1-size, 0), y1, x2-size, std::min(y2, size));
226226
}
227227
if(y2 > size)
228228
{
229229
if(x1 < size) fillblendmap(node.branch->type[2], node.branch->children[2], size, val,
230-
x1, max(y1-size, 0), min(x2, size), y2-size);
230+
x1, std::max(y1-size, 0), std::min(x2, size), y2-size);
231231
if(x2 > size) fillblendmap(node.branch->type[3], node.branch->children[3], size, val,
232-
max(x1-size, 0), max(y1-size, 0), x2-size, y2-size);
232+
std::max(x1-size, 0), std::max(y1-size, 0), x2-size, y2-size);
233233
}
234234
loopi(4) if(node.branch->type[i]!=BM_SOLID || node.branch->children[i].solid->val!=val) return;
235235
node.cleanup(type);
@@ -269,7 +269,7 @@ void fillblendmap(int x, int y, int w, int h, uchar val)
269269
y1 = clamp(y, 0, bmsize),
270270
x2 = clamp(x+w, 0, bmsize),
271271
y2 = clamp(y+h, 0, bmsize);
272-
if(max(x1, y1) >= bmsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
272+
if(std::max(x1, y1) >= bmsize || std::min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
273273
fillblendmap(blendmap.type, blendmap, bmsize, val, x1, y1, x2, y2);
274274
}
275275

@@ -281,16 +281,16 @@ static void invertblendmap(uchar &type, BlendMapNode &node, int size, int x1, in
281281
if(y1 < size)
282282
{
283283
if(x1 < size) invertblendmap(node.branch->type[0], node.branch->children[0], size,
284-
x1, y1, min(x2, size), min(y2, size));
284+
x1, y1, std::min(x2, size), std::min(y2, size));
285285
if(x2 > size) invertblendmap(node.branch->type[1], node.branch->children[1], size,
286-
max(x1-size, 0), y1, x2-size, min(y2, size));
286+
std::max(x1-size, 0), y1, x2-size, std::min(y2, size));
287287
}
288288
if(y2 > size)
289289
{
290290
if(x1 < size) invertblendmap(node.branch->type[2], node.branch->children[2], size,
291-
x1, max(y1-size, 0), min(x2, size), y2-size);
291+
x1, std::max(y1-size, 0), std::min(x2, size), y2-size);
292292
if(x2 > size) invertblendmap(node.branch->type[3], node.branch->children[3], size,
293-
max(x1-size, 0), max(y1-size, 0), x2-size, y2-size);
293+
std::max(x1-size, 0), std::max(y1-size, 0), x2-size, y2-size);
294294
}
295295
return;
296296
}
@@ -316,7 +316,7 @@ void invertblendmap(int x, int y, int w, int h)
316316
y1 = clamp(y, 0, bmsize),
317317
x2 = clamp(x+w, 0, bmsize),
318318
y2 = clamp(y+h, 0, bmsize);
319-
if(max(x1, y1) >= bmsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
319+
if(std::max(x1, y1) >= bmsize || std::min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
320320
invertblendmap(blendmap.type, blendmap, bmsize, x1, y1, x2, y2);
321321
}
322322

@@ -395,7 +395,7 @@ static void blitblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int
395395
int x1 = clamp(sx - bmx, 0, bmsize), y1 = clamp(sy - bmy, 0, bmsize),
396396
x2 = clamp(sx+sw - bmx, 0, bmsize), y2 = clamp(sy+sh - bmy, 0, bmsize);
397397
uchar *dst = &node.image->data[y1*BM_IMAGE_SIZE + x1];
398-
src += max(bmy - sy, 0)*sw + max(bmx - sx, 0);
398+
src += std::max(bmy - sy, 0)*sw + std::max(bmx - sx, 0);
399399
loopi(y2-y1)
400400
{
401401
switch(blendpaintmode)
@@ -405,19 +405,19 @@ static void blitblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int
405405
break;
406406

407407
case 2:
408-
loopi(x2 - x1) dst[i] = min(dst[i], src[i]);
408+
loopi(x2 - x1) dst[i] = std::min(dst[i], src[i]);
409409
break;
410410

411411
case 3:
412-
loopi(x2 - x1) dst[i] = max(dst[i], src[i]);
412+
loopi(x2 - x1) dst[i] = std::max(dst[i], src[i]);
413413
break;
414414

415415
case 4:
416-
loopi(x2 - x1) dst[i] = min(dst[i], uchar(0xFF - src[i]));
416+
loopi(x2 - x1) dst[i] = std::min(dst[i], uchar(0xFF - src[i]));
417417
break;
418418

419419
case 5:
420-
loopi(x2 - x1) dst[i] = max(dst[i], uchar(0xFF - src[i]));
420+
loopi(x2 - x1) dst[i] = std::max(dst[i], uchar(0xFF - src[i]));
421421
break;
422422
}
423423
dst += BM_IMAGE_SIZE;
@@ -428,7 +428,7 @@ static void blitblendmap(uchar &type, BlendMapNode &node, int bmx, int bmy, int
428428
void blitblendmap(uchar *src, int sx, int sy, int sw, int sh)
429429
{
430430
int bmsize = hdr.worldsize>>BM_SCALE;
431-
if(max(sx, sy) >= bmsize || min(sx+sw, sy+sh) <= 0 || min(sw, sh) <= 0) return;
431+
if(std::max(sx, sy) >= bmsize || std::min(sx+sw, sy+sh) <= 0 || std::min(sw, sh) <= 0) return;
432432
blitblendmap(blendmap.type, blendmap, 0, 0, bmsize, src, sx, sy, sw, sh);
433433
}
434434

@@ -554,7 +554,7 @@ void addblendbrush(const char *name, const char *imgname)
554554

555555
ImageData s;
556556
if(!loadimage(imgname, s)) { conoutf("\frcould not load blend brush image %s", imgname); return; }
557-
if(max(s.w, s.h) > (1<<12))
557+
if(std::max(s.w, s.h) > (1<<12))
558558
{
559559
conoutf("\frblend brush image size exceeded %dx%d pixels: %s", 1<<12, 1<<12, imgname);
560560
return;
@@ -738,7 +738,7 @@ void renderblendbrush()
738738
x2 = x1 + (brush->w << BM_SCALE),
739739
y2 = y1 + (brush->h << BM_SCALE);
740740

741-
if(max(x1, y1) >= hdr.worldsize || min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
741+
if(std::max(x1, y1) >= hdr.worldsize || std::min(x2, y2) <= 0 || x1>=x2 || y1>=y2) return;
742742

743743
if(!brush->tex) brush->gentex();
744744
renderblendbrush(brush->tex, x1, y1, x2 - x1, y2 - y1);

src/engine/blob.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct blobrenderer
123123
maxindexes = tris*3 + 3;
124124
availindexes = maxindexes - 3;
125125
indexes = new ushort[maxindexes];
126-
maxverts = min(tris*3/2 + 1, (1<<16)-1);
126+
maxverts = std::min(tris * 3 / 2 + 1, (1 << 16) - 1);
127127
availverts = maxverts - 1;
128128
verts = new blobvert[maxverts];
129129
}
@@ -282,7 +282,7 @@ struct blobrenderer
282282
dupblob();
283283
limit = maxverts - 2;
284284
}
285-
limit = min(int(end - cur), min(limit, (maxindexes - endindex)/3));
285+
limit = std::min(int(end - cur), std::min(limit, (maxindexes - endindex) / 3));
286286
while(availverts < limit+2) if(!freeblob()) return;
287287
while(availindexes < limit*3) if(!freeblob()) return;
288288

@@ -409,7 +409,7 @@ struct blobrenderer
409409
m.o[r] + m.rsize >= blobmin[r] && m.o[r] <= blobmax[r])
410410
{
411411
static cube dummy;
412-
gentris(dummy, m.orient, m.o, max(m.csize, m.rsize), &m);
412+
gentris(dummy, m.orient, m.o, std::max(m.csize, m.rsize), &m);
413413
}
414414
if(i+1 >= matsurfs) break;
415415
materialsurface &n = matbuf[i+1];

0 commit comments

Comments
 (0)