]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - mathlib.h
draw loading bar at 100% alpha again
[xonotic/darkplaces.git] / mathlib.h
index 44114aee3043613c153a2ce5952fdf312743b23b..c862564e4ceda322e3523f45c9aa7d3cc4f466f0 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -49,8 +49,14 @@ extern vec3_t vec3_origin;
 #define max(A,B) ((A) > (B) ? (A) : (B))
 #endif
 
-//#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32768.0f)) + (MIN))
-#define lhrandom(MIN,MAX) (((double)rand() / ((double)RAND_MAX + 1)) * ((MAX)-(MIN)) + (MIN))
+// LordHavoc: this function never returns exactly MIN or exactly MAX, because
+// of a QuakeC bug in id1 where the line
+// self.nextthink = self.nexthink + random() * 0.5;
+// can result in 0 (self.nextthink is 0 at this point in the code to begin
+// with), causing "stone monsters" that never spawned properly, also MAX is
+// avoided because some people use random() as an index into arrays or for
+// loop conditions, where hitting exactly MAX may be a fatal error
+#define lhrandom(MIN,MAX) (((double)(rand() + 0.5) / ((double)RAND_MAX + 1)) * ((MAX)-(MIN)) + (MIN))
 
 #define invpow(base,number) (log(number) / log(base))
 
@@ -94,6 +100,7 @@ unsigned int CeilPowerOf2(unsigned int value);
 #define VectorLength(a) (sqrt(DotProduct(a, a)))
 #define VectorLength2(a) (DotProduct(a, a))
 #define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
+#define VectorScaleCast(in, scale, outtype, out) ((out)[0] = (outtype) ((in)[0] * (scale)),(out)[1] = (outtype) ((in)[1] * (scale)),(out)[2] = (outtype) ((in)[2] * (scale)))
 #define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2]))
 #define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2])
 #define VectorM(scale1, b1, c) ((c)[0] = (scale1) * (b1)[0],(c)[1] = (scale1) * (b1)[1],(c)[2] = (scale1) * (b1)[2])