From ef5897b22c48c3e7dbe6188aa2d30007167c28b4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 23 Jul 2017 19:45:49 -0300 Subject: [PATCH] Seed love.math.random when the math module is loaded, instead of in love.run. --HG-- branch : minor --- src/modules/math/MathModule.cpp | 7 +++++++ src/scripts/boot.lua | 5 ----- src/scripts/boot.lua.h | 4 ---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/modules/math/MathModule.cpp b/src/modules/math/MathModule.cpp index b153d4452..fbfd51f26 100644 --- a/src/modules/math/MathModule.cpp +++ b/src/modules/math/MathModule.cpp @@ -32,6 +32,9 @@ #include #include +// C +#include + using std::list; using love::Vector2; @@ -359,6 +362,10 @@ Math::Math() { // prevent the runtime from free()-ing this retain(); + + RandomGenerator::Seed seed; + seed.b64 = (uint64) time(nullptr); + rng.setSeed(seed); } Math::~Math() diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 7b924eeb7..ca8156b5e 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -511,11 +511,6 @@ function love.init() end function love.run() - - if love.math then - love.math.setRandomSeed(os.time()) - end - if love.load then love.load(arg) end -- We don't want the first frame's dt to include time taken by love.load. diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 3a4498522..daa9d6da3 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -952,10 +952,6 @@ const unsigned char boot_lua[] = 0x65, 0x6e, 0x64, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x72, 0x75, 0x6e, 0x28, 0x29, 0x0a, - 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x73, 0x65, 0x74, 0x52, 0x61, 0x6e, - 0x64, 0x6f, 0x6d, 0x53, 0x65, 0x65, 0x64, 0x28, 0x6f, 0x73, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x28, 0x29, 0x29, 0x0a, - 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6c, 0x6f, 0x61, 0x64, 0x28, 0x61, 0x72, 0x67, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,