Skip to content

Commit

Permalink
Remove old implementation of min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonPadUSer committed Aug 2, 2020
1 parent e711d84 commit 179fd05
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/engine/dynlight.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "engine.h"

VAR(IDF_PERSIST, maxdynlights, 0, min(3, MAXDYNLIGHTS), MAXDYNLIGHTS);
VAR(IDF_PERSIST, maxdynlights, 0, std::min(3, MAXDYNLIGHTS), MAXDYNLIGHTS);
VAR(IDF_PERSIST, dynlightdist, 128, 1024, 10000);

struct dynlight
Expand Down
2 changes: 1 addition & 1 deletion src/engine/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ void shrinkmap()
conoutf("shrunk map to size %d", worldscale);
}

ICOMMAND(0, newmap, "is", (int *i, char *n), if(emptymap(*i, false, n)) game::newmap(::max(*i, 0), n));
ICOMMAND(0, newmap, "is", (int *i, char *n), if(emptymap(*i, false, n)) game::newmap(std::max(*i, 0), n));
ICOMMAND(0, mapenlarge, "i", (int *n), if(enlargemap(*n!=0, false)) game::newmap(*n!=0 ? -2 : -1));
COMMAND(0, shrinkmap, "");
ICOMMAND(0, mapsize, "", (void),
Expand Down
46 changes: 23 additions & 23 deletions src/shared/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ struct vec2
vec2 &sub(float f) { x -= f; y -= f; return *this; }
vec2 &sub(const vec2 &o) { x -= o.x; y -= o.y; return *this; }
vec2 &neg() { x = -x; y = -y; return *this; }
vec2 &min(const vec2 &o) { x = ::min(x, o.x); y = ::min(y, o.y); return *this; }
vec2 &max(const vec2 &o) { x = ::max(x, o.x); y = ::max(y, o.y); return *this; }
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 &min(const vec2 &o) { x = std::min(x, o.x); y = std::min(y, o.y); return *this; }
vec2 &max(const vec2 &o) { x = std::max(x, o.x); y = std::max(y, o.y); return *this; }
vec2 &min(float f) { x = std::min(x, f); y = std::min(y, f); return *this; }
vec2 &max(float f) { x = std::max(x, f); y = std::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 &reflect(const vec2 &n) { float k = 2*dot(n); x -= k*n.x; y -= k*n.y; return *this; }
Expand Down Expand Up @@ -116,10 +116,10 @@ struct vec
vec &subz(float f) { z -= f; return *this; }
vec &neg2() { x = -x; y = -y; return *this; }
vec &neg() { x = -x; y = -y; z = -z; return *this; }
vec &min(const vec &o) { x = ::min(x, o.x); y = ::min(y, o.y); z = ::min(z, o.z); return *this; }
vec &max(const vec &o) { x = ::max(x, o.x); y = ::max(y, o.y); z = ::max(z, o.z); return *this; }
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 &min(const vec &o) { x = std::min(x, o.x); y = std::min(y, o.y); z = std::min(z, o.z); return *this; }
vec &max(const vec &o) { x = std::max(x, o.x); y = std::max(y, o.y); z = std::max(z, o.z); return *this; }
vec &min(float f) { x = std::min(x, f); y = std::min(y, f); z = std::min(z, f); return *this; }
vec &max(float f) { x = std::max(x, f); y = std::max(y, f); z = std::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; }
float magnitude2() const { return sqrtf(dot2(*this)); }
Expand All @@ -146,14 +146,14 @@ struct vec
{
float m = squaredlen(), k = dot(n);
projectxydir(n);
rescale(sqrtf(::max(m - k*k, 0.0f)));
rescale(sqrtf(std::max(m - k*k, 0.0f)));
return *this;
}
vec &projectxy(const vec &n, float threshold)
{
float m = squaredlen(), k = ::min(dot(n), threshold);
float m = squaredlen(), k = std::min(dot(n), threshold);
projectxydir(n);
rescale(sqrtf(::max(m - k*k, 0.0f)));
rescale(sqrtf(std::max(m - k*k, 0.0f)));
return *this;
}
vec &lerp(const vec &b, float t) { x += (b.x-x)*t; y += (b.y-y)*t; z += (b.z-z)*t; return *this; }
Expand Down Expand Up @@ -1177,10 +1177,10 @@ struct ivec
ivec &sub(const ivec &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
ivec &mask(int n) { x &= n; y &= n; z &= n; return *this; }
ivec &neg() { return mul(-1); }
ivec &min(const ivec &o) { x = ::min(x, o.x); y = ::min(y, o.y); z = ::min(z, o.z); return *this; }
ivec &max(const ivec &o) { x = ::max(x, o.x); y = ::max(y, o.y); z = ::max(z, o.z); return *this; }
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 &min(const ivec &o) { x = std::min(x, o.x); y = std::min(y, o.y); z = std::min(z, o.z); return *this; }
ivec &max(const ivec &o) { x = std::max(x, o.x); y = std::max(y, o.y); z = std::max(z, o.z); return *this; }
ivec &min(int n) { x = std::min(x, n); y = std::min(y, n); z = std::min(z, n); return *this; }
ivec &max(int n) { x = std::max(x, n); y = std::max(y, n); z = std::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 &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; }
Expand Down Expand Up @@ -1236,10 +1236,10 @@ struct ivec2
ivec2 &sub(const ivec2 &v) { x -= v.x; y -= v.y; return *this; }
ivec2 &mask(int n) { x &= n; y &= n; return *this; }
ivec2 &neg() { x = -x; y = -y; return *this; }
ivec2 &min(const ivec2 &o) { x = ::min(x, o.x); y = ::min(y, o.y); return *this; }
ivec2 &max(const ivec2 &o) { x = ::max(x, o.x); y = ::max(y, o.y); return *this; }
ivec2 &min(int n) { x = ::min(x, n); y = ::min(y, n); return *this; }
ivec2 &max(int n) { x = ::max(x, n); y = ::max(y, n); return *this; }
ivec2 &min(const ivec2 &o) { x = std::min(x, o.x); y = std::min(y, o.y); return *this; }
ivec2 &max(const ivec2 &o) { x = std::max(x, o.x); y = std::max(y, o.y); return *this; }
ivec2 &min(int n) { x = std::min(x, n); y = std::min(y, n); return *this; }
ivec2 &max(int n) { x = std::max(x, n); y = std::max(y, n); return *this; }
ivec2 &abs() { x = ::abs(x); y = ::abs(y); return *this; }
int dot(const ivec2 &o) const { return x*o.x + y*o.y; }
int cross(const ivec2 &o) const { return x*o.y - y*o.x; }
Expand Down Expand Up @@ -1320,10 +1320,10 @@ struct bvec
bvec &sub(int n) { x -= n; y -= n; z -= n; return *this; }
bvec &add(const bvec &v) { x += v.x; y += v.y; z += v.z; return *this; }
bvec &sub(const bvec &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
bvec &min(const bvec &o) { x = ::min(x, o.x); y = ::min(y, o.y); z = ::min(z, o.z); return *this; }
bvec &max(const bvec &o) { x = ::max(x, o.x); y = ::max(y, o.y); z = ::max(z, o.z); return *this; }
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 &min(const bvec &o) { x = std::min(x, o.x); y = std::min(y, o.y); z = std::min(z, o.z); return *this; }
bvec &max(const bvec &o) { x = std::max(x, o.x); y = std::max(y, o.y); z = std::max(z, o.z); return *this; }
bvec &min(int f) { x = std::min(int(x), f); y = std::min(int(y), f); z = std::min(int(z), f); return *this; }
bvec &max(int f) { x = std::max(int(x), f); y = std::max(int(y), f); z = std::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; }

Expand Down
46 changes: 15 additions & 31 deletions src/shared/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,10 @@ typedef unsigned long long int ullong;
#define UNUSED
#endif

#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
template<class T>
static inline T max(T a, T b)
{
return a > b ? a : b;
}
template<class T>
static inline T min(T a, T b)
{
return a < b ? a : b;
}
template<class T, class U>
static inline T clamp(T a, U b, U c)
{
return max(T(b), min(a, T(c)));
return std::max(T(b), std::min(a, T(c)));
}

#ifdef __GNUC__
Expand Down Expand Up @@ -153,7 +137,7 @@ template<size_t N> inline void vformatstring(char (&d)[N], const char *fmt, va_l

inline char *copystring(char *d, const char *s, size_t len)
{
size_t slen = min(strlen(s), len-1);
size_t slen = std::min(strlen(s), len-1);
memcpy(d, s, slen);
d[slen] = 0;
return d;
Expand All @@ -165,8 +149,8 @@ template<size_t N> inline char *concatstring(char (&d)[N], const char *s) { retu

inline char *prependstring(char *d, const char *s, size_t len)
{
size_t slen = min(strlen(s), len);
memmove(&d[slen], d, min(len - slen, strlen(d) + 1));
size_t slen = std::min(strlen(s), len);
memmove(&d[slen], d, std::min(len - slen, strlen(d) + 1));
memcpy(d, s, slen);
d[len-1] = 0;
return d;
Expand Down Expand Up @@ -297,7 +281,7 @@ struct databuf
T *pad(int numvals)
{
T *vals = &buf[len];
len += min(numvals, maxlen-len);
len += std::min(numvals, maxlen-len);
return vals;
}

Expand All @@ -310,13 +294,13 @@ struct databuf
void put(const T *vals, int numvals)
{
if(maxlen-len<numvals) flags |= OVERWROTE;
memcpy(&buf[len], (const void *)vals, min(maxlen-len, numvals)*sizeof(T));
len += min(maxlen-len, numvals);
memcpy(&buf[len], (const void *)vals, std::min(maxlen-len, numvals)*sizeof(T));
len += std::min(maxlen-len, numvals);
}

int get(T *vals, int numvals)
{
int read = min(maxlen-len, numvals);
int read = std::min(maxlen-len, numvals);
if(read<numvals) flags |= OVERREAD;
memcpy(vals, (void *)&buf[len], read*sizeof(T));
len += read;
Expand All @@ -325,10 +309,10 @@ struct databuf

void offset(int n)
{
n = min(n, maxlen);
n = std::min(n, maxlen);
buf += n;
maxlen -= n;
len = max(len-n, 0);
len = std::max(len-n, 0);
}

T *getbuf() const { return buf; }
Expand Down Expand Up @@ -375,7 +359,7 @@ struct packetbuf : ucharbuf

void checkspace(int n)
{
if(len + n > maxlen && packet && growth > 0) resize(max(len + n, maxlen + growth));
if(len + n > maxlen && packet && growth > 0) resize(std::max(len + n, maxlen + growth));
}

ucharbuf subbuf(int sz)
Expand Down Expand Up @@ -547,7 +531,7 @@ inline int stringlen(const stringslice &s) { return s.len; }

inline char *copystring(char *d, const stringslice &s, size_t len)
{
size_t slen = min(size_t(s.len), len-1);
size_t slen = std::min(size_t(s.len), len-1);
memcpy(d, s.str, slen);
d[slen] = 0;
return d;
Expand Down Expand Up @@ -790,7 +774,7 @@ template <class T> struct vector
void growbuf(int sz)
{
int olen = alen;
if(!alen) alen = max(MINSIZE, sz);
if(!alen) alen = std::max(int(MINSIZE), sz);
else while(alen < sz) alen += alen/2;
if(alen <= olen) return;
uchar *newbuf = new uchar[alen*sizeof(T)];
Expand Down Expand Up @@ -1025,7 +1009,7 @@ template <class T> struct smallvector

void growbuf(int sz)
{
len = max(sz, 0);
len = std::max(sz, 0);
if(len)
{
buf = (T *)realloc(buf, len*sizeof(T));
Expand Down Expand Up @@ -1398,7 +1382,7 @@ struct unionfind

void unite (int x, int y)
{
while(ufvals.length() <= max(x, y)) ufvals.add();
while(ufvals.length() <= std::max(x, y)) ufvals.add();
x = compressfind(x);
y = compressfind(y);
if(x==y) return;
Expand Down

0 comments on commit 179fd05

Please sign in to comment.