From c03ce3a9abd9c51ca11a8880528bf6c327519538 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 26 Oct 2015 20:47:56 -0300 Subject: [PATCH] love.math.random now uses a slight variant of Xorshift (Xorshift*). --- src/modules/graphics/opengl/Font.cpp | 21 ++++++++++++++------- src/modules/graphics/opengl/Font.h | 10 ---------- src/modules/math/RandomGenerator.cpp | 9 +++++---- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index b497adccb..58572b8c3 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -434,9 +434,16 @@ std::vector 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::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::alignModes(Font::alignModeEntries, sizeof(Font::alignModeEntries)); diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index 6677c560e..fb94b7e53 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/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()); diff --git a/src/modules/math/RandomGenerator.cpp b/src/modules/math/RandomGenerator.cpp index 6bd215434..e1900e8b4 100644 --- a/src/modules/math/RandomGenerator.cpp +++ b/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::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