Changeset 520 for trunk/src/lua


Ignore:
Timestamp:
10/03/16 17:45:46 (9 years ago)
Author:
epyon
Message:
  • ecs updates
  • animation updates
  • ragdoll manager
  • lua has own random engine
  • several minor fixes
  • particle engine/particle group
  • shitload of other stuff
  • bullet world
Location:
trunk/src/lua
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lua/lua_area.cc

    r503 r520  
    88
    99#include "nv/lua/lua_raw.hh"
    10 #include "nv/core/random.hh"
     10#include "nv/lua/lua_aux.hh"
    1111
    1212using nv::lua::detail::is_coord;
     
    333333        nv::sint32 xs = ( b.x - a.x ) + 1;
    334334        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 );
    336336        nv::ivec2 result;
    337337
     
    356356        nv::sint32 xs = ( b.x - a.x ) - 1;
    357357        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 );
    359359        nv::ivec2 result;
    360360
     
    375375{
    376376        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 ) );
    378378        return 1;
    379379}
     
    383383        nv::rectangle area  = to_area( L, 1 );
    384384        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 );
    386386        push_area( L, nv::rectangle( start, start + dim ) );
    387387        return 1;
  • trunk/src/lua/lua_aux.cc

    r503 r520  
    99#include "nv/lua/lua_raw.hh"
    1010#include "nv/core/random.hh"
     11
     12static nv::random lua_rng;
    1113
    1214static int nluaaux_table_copy( lua_State* L )
     
    9496        if ( dice < 1 )  luaL_argerror( L, 1, "die count lower than 1!" );
    9597        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 ) ) );
    9799        return 1;
    98100}
     
    102104        if ( lua_gettop( L ) == 0 )
    103105        {
    104                 lua_pushnumber( L, nv::random::get().frand(1.0f) );
     106                lua_pushnumber( L, lua_rng.frand(1.0f) );
    105107        }
    106108        else
     
    110112                        lua_Integer arg1 = luaL_checkinteger( L, 1 );
    111113                        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 ) ) );
    113115                }
    114116                else
     
    116118                        int arg1 = static_cast< int >( luaL_checkinteger( L, 1 ) );
    117119                        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 ) );
    119121                        lua_pushinteger( L, result );
    120122                }
     
    125127static int nluaaux_math_randomseed( lua_State* L )
    126128{
    127         nv::random::get().set_seed( nlua_tounsigned( L, 1 ) );
     129        lua_rng.set_seed( nlua_tounsigned( L, 1 ) );
    128130        return 0;
    129131}
     
    137139};
    138140
     141nv::random & nv::lua::rng()
     142{
     143        return lua_rng;
     144}
     145
    139146void nv::lua::register_aux( lua::state* state )
    140147{
  • trunk/src/lua/lua_map_tile.cc

    r503 r520  
    1111#include "nv/stl/numeric.hh"
    1212#include "nv/stl/algorithm.hh"
    13 #include "nv/core/random.hh"
     13#include "nv/lua/lua_aux.hh"
    1414#include "nv/lua/lua_area.hh"
    1515#include "nv/lua/lua_math.hh"
     
    207207static int nlua_map_tile_flip_random( lua_State* L )
    208208{
    209         switch ( nv::random::get().urand( 4 ) )
     209        switch ( nv::lua::rng().urand( 4 ) )
    210210        {
    211211        case 1 : nlua_map_tile_flip_x( L ); break;
  • trunk/src/lua/lua_math.cc

    r512 r520  
    88
    99#include "nv/lua/lua_raw.hh"
    10 #include "nv/core/random.hh"
     10#include "nv/lua/lua_aux.hh"
    1111#include "nv/stl/type_traits/common.hh"
    1212
     
    126126int nlua_vec_random( lua_State* L )
    127127{
    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 ) ) );
    129129        return 1;
    130130}
Note: See TracChangeset for help on using the changeset viewer.