mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
love.math.random now uses a slight variant of Xorshift (Xorshift*).
This commit is contained in:
@@ -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
|
const auto drawsort = [](const DrawCommand &a, const DrawCommand &b) -> bool
|
||||||
// (using the struct's < operator).
|
{
|
||||||
std::sort(drawcommands.begin(), drawcommands.end());
|
// 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)
|
if (dx > maxwidth)
|
||||||
maxwidth = (int) dx;
|
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[] =
|
StringMap<Font::AlignMode, Font::ALIGN_MAX_ENUM>::Entry Font::alignModeEntries[] =
|
||||||
{
|
{
|
||||||
{ "left", Font::ALIGN_LEFT },
|
{ "left", ALIGN_LEFT },
|
||||||
{ "right", Font::ALIGN_RIGHT },
|
{ "right", ALIGN_RIGHT },
|
||||||
{ "center", Font::ALIGN_CENTER },
|
{ "center", ALIGN_CENTER },
|
||||||
{ "justify", Font::ALIGN_JUSTIFY },
|
{ "justify", ALIGN_JUSTIFY },
|
||||||
};
|
};
|
||||||
|
|
||||||
StringMap<Font::AlignMode, Font::ALIGN_MAX_ENUM> Font::alignModes(Font::alignModeEntries, sizeof(Font::alignModeEntries));
|
StringMap<Font::AlignMode, Font::ALIGN_MAX_ENUM> Font::alignModes(Font::alignModeEntries, sizeof(Font::alignModeEntries));
|
||||||
|
|||||||
@@ -79,16 +79,6 @@ public:
|
|||||||
GLuint texture;
|
GLuint texture;
|
||||||
int startvertex;
|
int startvertex;
|
||||||
int vertexcount;
|
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());
|
Font(love::font::Rasterizer *r, const Texture::Filter &filter = Texture::getDefaultFilter());
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ static uint64 wangHash64(uint64 key)
|
|||||||
|
|
||||||
// 64 bit Xorshift implementation taken from the end of Sec. 3 (page 4) in
|
// 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
|
// 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()
|
RandomGenerator::RandomGenerator()
|
||||||
: last_randomnormal(std::numeric_limits<double>::infinity())
|
: last_randomnormal(std::numeric_limits<double>::infinity())
|
||||||
@@ -63,10 +64,10 @@ RandomGenerator::RandomGenerator()
|
|||||||
|
|
||||||
uint64 RandomGenerator::rand()
|
uint64 RandomGenerator::rand()
|
||||||
{
|
{
|
||||||
rng_state.b64 ^= (rng_state.b64 << 13);
|
rng_state.b64 ^= (rng_state.b64 >> 12);
|
||||||
rng_state.b64 ^= (rng_state.b64 >> 7);
|
rng_state.b64 ^= (rng_state.b64 << 25);
|
||||||
rng_state.b64 ^= (rng_state.b64 << 17);
|
rng_state.b64 ^= (rng_state.b64 >> 27);
|
||||||
return rng_state.b64;
|
return rng_state.b64 * 2685821657736338717ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Box–Muller transform
|
// Box–Muller transform
|
||||||
|
|||||||
Reference in New Issue
Block a user