aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/numeric.cpp11
-rw-r--r--src/util/numeric.h23
-rw-r--r--src/util/pointer.h13
3 files changed, 41 insertions, 6 deletions
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp
index 702ddce95..aa3bb843d 100644
--- a/src/util/numeric.cpp
+++ b/src/util/numeric.cpp
@@ -46,11 +46,22 @@ void myrand_bytes(void *out, size_t len)
g_pcgrand.bytes(out, len);
}
+float myrand_float()
+{
+ u32 uv = g_pcgrand.next();
+ return (float)uv / (float)U32_MAX;
+}
+
int myrand_range(int min, int max)
{
return g_pcgrand.range(min, max);
}
+float myrand_range(float min, float max)
+{
+ return (max-min) * myrand_float() + min;
+}
+
/*
64-bit unaligned version of MurmurHash
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 32a6f4312..265046a63 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -223,6 +223,8 @@ u32 myrand();
void mysrand(unsigned int seed);
void myrand_bytes(void *out, size_t len);
int myrand_range(int min, int max);
+float myrand_range(float min, float max);
+float myrand_float();
/*
Miscellaneous functions
@@ -446,3 +448,24 @@ inline irr::video::SColor multiplyColorValue(const irr::video::SColor &color, fl
core::clamp<u32>(color.getGreen() * mod, 0, 255),
core::clamp<u32>(color.getBlue() * mod, 0, 255));
}
+
+template <typename T> inline T numericAbsolute(T v) { return v < 0 ? T(-v) : v; }
+template <typename T> inline T numericSign(T v) { return T(v < 0 ? -1 : (v == 0 ? 0 : 1)); }
+
+inline v3f vecAbsolute(v3f v)
+{
+ return v3f(
+ numericAbsolute(v.X),
+ numericAbsolute(v.Y),
+ numericAbsolute(v.Z)
+ );
+}
+
+inline v3f vecSign(v3f v)
+{
+ return v3f(
+ numericSign(v.X),
+ numericSign(v.Y),
+ numericSign(v.Z)
+ );
+}
diff --git a/src/util/pointer.h b/src/util/pointer.h
index 245ac85bf..b659cea0e 100644
--- a/src/util/pointer.h
+++ b/src/util/pointer.h
@@ -45,7 +45,7 @@ public:
Buffer()
{
m_size = 0;
- data = NULL;
+ data = nullptr;
}
Buffer(unsigned int size)
{
@@ -53,7 +53,7 @@ public:
if(size != 0)
data = new T[size];
else
- data = NULL;
+ data = nullptr;
}
// Disable class copy
@@ -82,7 +82,7 @@ public:
memcpy(data, t, size);
}
else
- data = NULL;
+ data = nullptr;
}
~Buffer()
@@ -166,7 +166,7 @@ public:
if(m_size != 0)
data = new T[m_size];
else
- data = NULL;
+ data = nullptr;
refcount = new unsigned int;
memset(data,0,sizeof(T)*m_size);
(*refcount) = 1;
@@ -201,7 +201,7 @@ public:
memcpy(data, t, m_size);
}
else
- data = NULL;
+ data = nullptr;
refcount = new unsigned int;
(*refcount) = 1;
}
@@ -216,7 +216,7 @@ public:
memcpy(data, *buffer, buffer.getSize());
}
else
- data = NULL;
+ data = nullptr;
refcount = new unsigned int;
(*refcount) = 1;
}
@@ -256,3 +256,4 @@ private:
unsigned int m_size;
unsigned int *refcount;
};
+