Browse Source

love.math.random now uses a slight variant of Xorshift (Xorshift*).

Alex Szpakowski 9 years ago
parent
commit
c03ce3a9ab

+ 14 - 7
src/modules/graphics/opengl/Font.cpp

@@ -434,9 +434,16 @@ std::vector<Font::DrawCommand> Font::generateVertices(const Codepoints &codepoin
 
 	}
 
-	// Sort draw commands by texture first, and quad position in memory second
-	// (using the struct's < operator).
-	std::sort(drawcommands.begin(), drawcommands.end());
+	const auto drawsort = [](const DrawCommand &a, const DrawCommand &b) -> bool
+	{
+		// Texture binds are expensive, so we should sort by that first.
+		if (a.texture != b.texture)
+			return a.texture < b.texture;
+		else
+			return a.startvertex < b.startvertex;
+	};
+
+	std::sort(drawcommands.begin(), drawcommands.end(), drawsort);
 
 	if (dx > maxwidth)
 		maxwidth = (int) dx;
@@ -929,10 +936,10 @@ bool Font::getConstant(AlignMode in, const char  *&out)
 
 StringMap<Font::AlignMode, Font::ALIGN_MAX_ENUM>::Entry Font::alignModeEntries[] =
 {
-	{ "left", Font::ALIGN_LEFT },
-	{ "right", Font::ALIGN_RIGHT },
-	{ "center", Font::ALIGN_CENTER },
-	{ "justify", Font::ALIGN_JUSTIFY },
+	{ "left", ALIGN_LEFT },
+	{ "right", ALIGN_RIGHT },
+	{ "center", ALIGN_CENTER },
+	{ "justify", ALIGN_JUSTIFY },
 };
 
 StringMap<Font::AlignMode, Font::ALIGN_MAX_ENUM> Font::alignModes(Font::alignModeEntries, sizeof(Font::alignModeEntries));

+ 0 - 10
src/modules/graphics/opengl/Font.h

@@ -79,16 +79,6 @@ public:
 		GLuint texture;
 		int startvertex;
 		int vertexcount;
-
-		// used when sorting with std::sort.
-		bool operator < (const DrawCommand &other) const
-		{
-			// Texture binds are expensive, so we should sort by that first.
-			if (texture != other.texture)
-				return texture < other.texture;
-			else
-				return startvertex < other.startvertex;
-		}
 	};
 
 	Font(love::font::Rasterizer *r, const Texture::Filter &filter = Texture::getDefaultFilter());

+ 5 - 4
src/modules/math/RandomGenerator.cpp

@@ -49,6 +49,7 @@ static uint64 wangHash64(uint64 key)
 
 // 64 bit Xorshift implementation taken from the end of Sec. 3 (page 4) in
 // George Marsaglia, "Xorshift RNGs", Journal of Statistical Software, Vol.8 (Issue 14), 2003
+// Use an 'Xorshift*' variant, as shown here: http://xorshift.di.unimi.it
 
 RandomGenerator::RandomGenerator()
 	: last_randomnormal(std::numeric_limits<double>::infinity())
@@ -63,10 +64,10 @@ RandomGenerator::RandomGenerator()
 
 uint64 RandomGenerator::rand()
 {
-	rng_state.b64 ^= (rng_state.b64 << 13);
-	rng_state.b64 ^= (rng_state.b64 >> 7);
-	rng_state.b64 ^= (rng_state.b64 << 17);
-	return rng_state.b64;
+	rng_state.b64 ^= (rng_state.b64 >> 12);
+	rng_state.b64 ^= (rng_state.b64 << 25);
+	rng_state.b64 ^= (rng_state.b64 >> 27);
+	return rng_state.b64 * 2685821657736338717ULL;
 }
 
 // Box–Muller transform