Changeset 520 for trunk/src/lua
- Timestamp:
- 10/03/16 17:45:46 (9 years ago)
- Location:
- trunk/src/lua
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_area.cc
r503 r520 8 8 9 9 #include "nv/lua/lua_raw.hh" 10 #include "nv/ core/random.hh"10 #include "nv/lua/lua_aux.hh" 11 11 12 12 using nv::lua::detail::is_coord; … … 333 333 nv::sint32 xs = ( b.x - a.x ) + 1; 334 334 nv::sint32 ys = ( b.y - a.y ) - 1; 335 nv::sint32 roll = nv:: random::get().srand( 2 * xs + 2 * ys );335 nv::sint32 roll = nv::lua::rng().srand( 2 * xs + 2 * ys ); 336 336 nv::ivec2 result; 337 337 … … 356 356 nv::sint32 xs = ( b.x - a.x ) - 1; 357 357 nv::sint32 ys = ( b.y - a.y ) - 1; 358 nv::sint32 roll = nv:: random::get().srand( 2 * xs + 2 * ys );358 nv::sint32 roll = nv::lua::rng().srand( 2 * xs + 2 * ys ); 359 359 nv::ivec2 result; 360 360 … … 375 375 { 376 376 nv::rectangle area = to_area( L, 1 ); 377 push_coord( L, nv:: random::get().range( area.ul, area.lr ) );377 push_coord( L, nv::lua::rng().range( area.ul, area.lr ) ); 378 378 return 1; 379 379 } … … 383 383 nv::rectangle area = to_area( L, 1 ); 384 384 nv::ivec2 dim = to_coord( L, 2 ); 385 nv::ivec2 start = nv:: random::get().range( area.ul, area.lr - dim );385 nv::ivec2 start = nv::lua::rng().range( area.ul, area.lr - dim ); 386 386 push_area( L, nv::rectangle( start, start + dim ) ); 387 387 return 1; -
trunk/src/lua/lua_aux.cc
r503 r520 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/core/random.hh" 11 12 static nv::random lua_rng; 11 13 12 14 static int nluaaux_table_copy( lua_State* L ) … … 94 96 if ( dice < 1 ) luaL_argerror( L, 1, "die count lower than 1!" ); 95 97 if ( sides < 1 ) luaL_argerror( L, 2, "side count lower than 1!" ); 96 lua_pushnumber( L, nv::random::get().dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) );98 lua_pushnumber( L, lua_rng.dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) ); 97 99 return 1; 98 100 } … … 102 104 if ( lua_gettop( L ) == 0 ) 103 105 { 104 lua_pushnumber( L, nv::random::get().frand(1.0f) );106 lua_pushnumber( L, lua_rng.frand(1.0f) ); 105 107 } 106 108 else … … 110 112 lua_Integer arg1 = luaL_checkinteger( L, 1 ); 111 113 if ( arg1 < 1 ) arg1 = 1; 112 nlua_pushunsigned( L, nv::random::get().urange( 1, static_cast<nv::uint32>( arg1 ) ) );114 nlua_pushunsigned( L, lua_rng.urange( 1, static_cast<nv::uint32>( arg1 ) ) ); 113 115 } 114 116 else … … 116 118 int arg1 = static_cast< int >( luaL_checkinteger( L, 1 ) ); 117 119 int arg2 = static_cast< int >( luaL_checkinteger( L, 2 ) ); 118 int result = ( arg2 >= arg1 ? nv::random::get().srange( arg1, arg2 ) : nv::random::get().srange( arg2, arg1 ) );120 int result = ( arg2 >= arg1 ? lua_rng.srange( arg1, arg2 ) : lua_rng.srange( arg2, arg1 ) ); 119 121 lua_pushinteger( L, result ); 120 122 } … … 125 127 static int nluaaux_math_randomseed( lua_State* L ) 126 128 { 127 nv::random::get().set_seed( nlua_tounsigned( L, 1 ) );129 lua_rng.set_seed( nlua_tounsigned( L, 1 ) ); 128 130 return 0; 129 131 } … … 137 139 }; 138 140 141 nv::random & nv::lua::rng() 142 { 143 return lua_rng; 144 } 145 139 146 void nv::lua::register_aux( lua::state* state ) 140 147 { -
trunk/src/lua/lua_map_tile.cc
r503 r520 11 11 #include "nv/stl/numeric.hh" 12 12 #include "nv/stl/algorithm.hh" 13 #include "nv/ core/random.hh"13 #include "nv/lua/lua_aux.hh" 14 14 #include "nv/lua/lua_area.hh" 15 15 #include "nv/lua/lua_math.hh" … … 207 207 static int nlua_map_tile_flip_random( lua_State* L ) 208 208 { 209 switch ( nv:: random::get().urand( 4 ) )209 switch ( nv::lua::rng().urand( 4 ) ) 210 210 { 211 211 case 1 : nlua_map_tile_flip_x( L ); break; -
trunk/src/lua/lua_math.cc
r512 r520 8 8 9 9 #include "nv/lua/lua_raw.hh" 10 #include "nv/ core/random.hh"10 #include "nv/lua/lua_aux.hh" 11 11 #include "nv/stl/type_traits/common.hh" 12 12 … … 126 126 int nlua_vec_random( lua_State* L ) 127 127 { 128 push_vec<T>( L, nv:: random::get().range( to_vec<T>( L, 1 ), to_vec<T>( L, 2 ) ) );128 push_vec<T>( L, nv::lua::rng().range( to_vec<T>( L, 1 ), to_vec<T>( L, 2 ) ) ); 129 129 return 1; 130 130 }
Note: See TracChangeset
for help on using the changeset viewer.