diff options
author | kwolekr <kwolekr@minetest.net> | 2015-03-22 00:01:46 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-03-22 00:48:08 -0400 |
commit | 3993093f51544d4eb44efb57c973e29107ea2f7a (patch) | |
tree | 0533167edce0dbd2cb8f03c37b880e57cfd7916d /src/script/lua_api/l_noise.h | |
parent | 7679396ebbb38115eedbfb8e9636dff50cdf2075 (diff) | |
download | minetest-3993093f51544d4eb44efb57c973e29107ea2f7a.tar.gz minetest-3993093f51544d4eb44efb57c973e29107ea2f7a.tar.bz2 minetest-3993093f51544d4eb44efb57c973e29107ea2f7a.zip |
Add support for the PCG32 PRNG algo (and associated script APIs)
Diffstat (limited to 'src/script/lua_api/l_noise.h')
-rw-r--r-- | src/script/lua_api/l_noise.h | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index 3e22ac7a0..56d2d59f8 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -64,6 +64,9 @@ class LuaPerlinNoiseMap : public ModApiBase { static const char className[]; static const luaL_reg methods[]; + // Exported functions + + // garbage collector static int gc_object(lua_State *L); static int l_get2dMap(lua_State *L); @@ -104,18 +107,51 @@ private: static int l_next(lua_State *L); public: - LuaPseudoRandom(int seed); - - ~LuaPseudoRandom(); - - const PseudoRandom& getItem() const; - PseudoRandom& getItem(); + LuaPseudoRandom(int seed) : + m_pseudo(seed) {} // LuaPseudoRandom(seed) // Creates an LuaPseudoRandom and leaves it on top of stack static int create_object(lua_State *L); - static LuaPseudoRandom* checkobject(lua_State *L, int narg); + static LuaPseudoRandom *checkobject(lua_State *L, int narg); + + static void Register(lua_State *L); +}; + +/* + LuaPcgRandom +*/ +class LuaPcgRandom : public ModApiBase { +private: + PcgRandom m_rnd; + + static const char className[]; + static const luaL_reg methods[]; + + // Exported functions + + // garbage collector + static int gc_object(lua_State *L); + + // next(self, min=-2147483648, max=2147483647) -> get next value + static int l_next(lua_State *L); + + // rand_normal_dist(self, min=-2147483648, max=2147483647, num_trials=6) -> + // get next normally distributed random value + static int l_rand_normal_dist(lua_State *L); + +public: + LuaPcgRandom(u64 seed) : + m_rnd(seed) {} + LuaPcgRandom(u64 seed, u64 seq) : + m_rnd(seed, seq) {} + + // LuaPcgRandom(seed) + // Creates an LuaPcgRandom and leaves it on top of stack + static int create_object(lua_State *L); + + static LuaPcgRandom *checkobject(lua_State *L, int narg); static void Register(lua_State *L); }; |