- Timestamp:
- 06/28/16 21:09:19 (9 years ago)
- Location:
- trunk/src
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/random.cc
r487 r503 19 19 #define NV_MT_TWIST(u, v) ( (NV_MT_MIXBITS(u, v) >> 1) ^ ( (v) & 1UL ? mt_matrix_a : 0UL) ) 20 20 21 void random::mt_init( uint32 seed ) 21 nv::random& random::get() 22 { 23 static random default_rng; 24 return default_rng; 25 } 26 27 void random_mersenne::mt_init( uint32 seed ) 22 28 { 23 29 m_state[0] = static_cast<uint32>( seed & mt_full_mask ); … … 34 40 35 41 36 void random ::mt_update()42 void random_mersenne::mt_update() 37 43 { 38 44 uint32 *p = m_state; … … 51 57 52 58 53 uint32 random ::mt_uint32()59 uint32 random_mersenne::mt_uint32() 54 60 { 55 61 uint32 r; … … 70 76 } 71 77 72 random ::random( random::seed_type seed /*= 0 */ )78 random_mersenne::random_mersenne( random_mersenne::seed_type seed /*= 0 */ ) 73 79 : m_next( nullptr ), m_remaining( 0 ), m_seeded( 0 ) 74 80 { 75 mt_init( seed == 0 ? randomized_seed() : seed ); 76 } 77 78 random::seed_type random::set_seed( random::seed_type seed /*= 0 */ ) 79 { 80 if ( seed == 0 ) seed = randomized_seed(); 81 mt_init( seed ); 82 } 83 84 random_mersenne::seed_type random_mersenne::set_seed( random_mersenne::seed_type seed /*= 0 */ ) 85 { 81 86 mt_init( seed ); 82 87 return seed; 83 88 } 84 89 85 nv::random& random::get() 86 { 87 static random default_rng; 88 return default_rng; 89 } 90 91 random::result_type random::rand() 90 random_mersenne::result_type random_mersenne::rand() 92 91 { 93 92 return mt_uint32(); 94 93 } 95 94 96 uint32 random::urand( uint32 val ) 97 { 98 uint32 x, max = mt_full_mask - ( mt_full_mask % val ); 99 while ( ( x = rand() ) >= max ); 100 return x / ( max / val ); 101 } 102 103 random::seed_type random::randomized_seed() 95 random_base::seed_type random_base::randomized_seed() 104 96 { 105 97 // TODO: this seems off, as it might often seed the same, use general time … … 108 100 } 109 101 110 nv::vec2 nv::random ::precise_unit_vec2()102 nv::vec2 nv::random_base::precise_unit_vec2() 111 103 { 112 104 f32 angle = frand( math::pi<f32>() * 2.f ); … … 114 106 } 115 107 116 nv::vec3 nv::random ::precise_unit_vec3()108 nv::vec3 nv::random_base::precise_unit_vec3() 117 109 { 118 110 f32 cos_theta = frange( -1.0f, 1.0f ); … … 126 118 } 127 119 128 nv::vec2 nv::random ::fast_disk_point()120 nv::vec2 nv::random_base::fast_disk_point() 129 121 { 130 122 f32 r1 = frand(); … … 135 127 } 136 128 137 nv::vec2 nv::random ::precise_disk_point()129 nv::vec2 nv::random_base::precise_disk_point() 138 130 { 139 131 f32 r = sqrt( frand() ); … … 142 134 } 143 135 144 nv::vec3 nv::random ::fast_sphere_point()136 nv::vec3 nv::random_base::fast_sphere_point() 145 137 { 146 138 f32 rad = frand(); … … 156 148 } 157 149 158 nv::vec3 nv::random ::precise_sphere_point()150 nv::vec3 nv::random_base::precise_sphere_point() 159 151 { 160 152 f32 radius = pow( frand(), 1.f/3.f ); … … 169 161 } 170 162 171 nv::vec2 nv::random ::precise_ellipse_point( const vec2& radii )163 nv::vec2 nv::random_base::precise_ellipse_point( const vec2& radii ) 172 164 { 173 165 vec2 p = range( -radii, radii ); … … 184 176 } 185 177 186 nv::vec3 nv::random ::precise_ellipsoid_point( const vec3& radii )178 nv::vec3 nv::random_base::precise_ellipsoid_point( const vec3& radii ) 187 179 { 188 180 vec3 p = range( -radii, radii ); … … 199 191 } 200 192 201 nv::vec2 nv::random ::fast_hollow_disk_point( f32 iradius, f32 oradius )193 nv::vec2 nv::random_base::fast_hollow_disk_point( f32 iradius, f32 oradius ) 202 194 { 203 195 f32 idist2 = iradius * iradius; … … 207 199 } 208 200 209 nv::vec2 nv::random ::precise_hollow_disk_point( f32 iradius, f32 oradius )201 nv::vec2 nv::random_base::precise_hollow_disk_point( f32 iradius, f32 oradius ) 210 202 { 211 203 return fast_hollow_disk_point( iradius, oradius ); 212 204 } 213 205 214 nv::vec3 nv::random ::fast_hollow_sphere_point( f32 iradius, f32 oradius )206 nv::vec3 nv::random_base::fast_hollow_sphere_point( f32 iradius, f32 oradius ) 215 207 { 216 208 f32 idist3 = iradius * iradius * iradius; … … 220 212 } 221 213 222 nv::vec3 nv::random ::precise_hollow_sphere_point( f32 iradius, f32 oradius )214 nv::vec3 nv::random_base::precise_hollow_sphere_point( f32 iradius, f32 oradius ) 223 215 { 224 216 return fast_hollow_sphere_point( iradius, oradius ); … … 226 218 227 219 228 nv::vec2 nv::random ::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )220 nv::vec2 nv::random_base::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii ) 229 221 { 230 222 vec2 iradii2 = iradii * iradii; … … 241 233 } 242 234 243 nv::vec2 nv::random ::precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )235 nv::vec2 nv::random_base::precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii ) 244 236 { 245 237 return fast_hollow_ellipse_point( iradii, oradii ); 246 238 } 247 239 248 nv::vec3 nv::random ::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )240 nv::vec3 nv::random_base::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii ) 249 241 { 250 242 vec3 iradii2 = iradii * iradii; … … 267 259 } 268 260 269 nv::vec3 nv::random ::precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )261 nv::vec3 nv::random_base::precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii ) 270 262 { 271 263 return fast_hollow_ellipsoid_point( iradii, oradii ); 272 264 } 273 265 266 nv::random_xor128::random_xor128( seed_type seed /*= randomized_seed() */ ) 267 { 268 set_seed( seed ); 269 } 270 271 nv::random_base::seed_type nv::random_xor128::set_seed( seed_type seed /*= 0 */ ) 272 { 273 uint32 s = 4294967296 - seed; 274 m_state[0] = 123456789 * s; 275 m_state[1] = 362436069 * s; 276 m_state[2] = 521288629 * s; 277 m_state[3] = 88675123 * s; 278 return seed; 279 } 280 281 nv::random_base::result_type nv::random_xor128::rand() 282 { 283 uint32 t = m_state[0]; 284 t ^= t << 11; 285 t ^= t >> 8; 286 m_state[0] = m_state[1]; m_state[1] = m_state[2]; m_state[2] = m_state[3]; 287 m_state[3] ^= m_state[3] >> 19; 288 m_state[3] ^= t; 289 return m_state[3]; 290 } -
trunk/src/gfx/mesh_creator.cc
r491 r503 88 88 89 89 90 void nv::mesh_data_creator::transform( float scale, const mat3& r33)91 { 92 vec3 vertex_offset = vec3();93 mat3 vertex_transform 94 mat3 normal_transform 90 void nv::mesh_data_creator::transform( const vec3& pos, const mat3& r33, float scale /*= 1.0f */ ) 91 { 92 vec3 vertex_offset = pos; 93 mat3 vertex_transform = scale * r33; 94 mat3 normal_transform = r33; 95 95 96 96 for ( uint32 c = 0; c < m_data->size(); ++c ) 97 97 { 98 98 raw_data_channel_access channel( m_data, c ); 99 const data_descriptor& desc 99 const data_descriptor& desc = channel.descriptor(); 100 100 uint8* raw_data = channel.raw_data(); 101 101 uint32 vtx_size = desc.element_size(); … … 103 103 int n_offset = -1; 104 104 int t_offset = -1; 105 for ( const auto& cslot : desc 105 for ( const auto& cslot : desc ) 106 106 switch ( cslot.vslot ) 107 107 { 108 case slot::POSITION: if ( cslot.etype == FLOAT_VECTOR_3 ) p_offset = int( cslot.offset ); break;109 case slot::NORMAL: if ( cslot.etype == FLOAT_VECTOR_3 ) n_offset = int( cslot.offset ); break;110 case slot::TANGENT: if ( cslot.etype == FLOAT_VECTOR_4 ) t_offset = int( cslot.offset ); break;111 default: break;108 case slot::POSITION: if ( cslot.etype == FLOAT_VECTOR_3 ) p_offset = int( cslot.offset ); break; 109 case slot::NORMAL: if ( cslot.etype == FLOAT_VECTOR_3 ) n_offset = int( cslot.offset ); break; 110 case slot::TANGENT: if ( cslot.etype == FLOAT_VECTOR_4 ) t_offset = int( cslot.offset ); break; 111 default: break; 112 112 } 113 113 114 114 if ( p_offset != -1 ) 115 for ( uint32 i = 0; i < channel.size(); i++ )115 for ( uint32 i = 0; i < channel.size(); i++ ) 116 116 { 117 117 vec3& p = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + p_offset ); … … 120 120 121 121 if ( n_offset != -1 ) 122 for ( uint32 i = 0; i < channel.size(); i++ )122 for ( uint32 i = 0; i < channel.size(); i++ ) 123 123 { 124 124 vec3& n = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + n_offset ); … … 126 126 } 127 127 if ( t_offset != -1 ) 128 for ( uint32 i = 0; i < channel.size(); i++) 129 { 130 vec4& t = *reinterpret_cast<vec4*>(raw_data + vtx_size*i + t_offset ); 131 t = vec4( math::normalize( normal_transform * vec3(t) ), t[3] ); 132 } 133 } 134 } 128 for ( uint32 i = 0; i < channel.size(); i++ ) 129 { 130 vec4& t = *reinterpret_cast<vec4*>( raw_data + vtx_size*i + t_offset ); 131 t = vec4( math::normalize( normal_transform * vec3( t ) ), t[3] ); 132 } 133 } 134 } 135 135 136 136 137 struct vertex_g -
trunk/src/gl/gl_context.cc
r502 r503 201 201 } 202 202 203 void nv::gl_context::blit( framebuffer f, clear_state::buffers_typemask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )203 void nv::gl_context::blit( framebuffer f, buffer_mask mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 ) 204 204 { 205 205 gl_framebuffer_info* info = m_framebuffers.get( f ); … … 207 207 { 208 208 glBindFramebuffer( GL_FRAMEBUFFER, info->glid ); 209 unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;209 unsigned filter = mask == buffer_mask::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST; 210 210 glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter ); 211 211 } … … 213 213 214 214 215 void nv::gl_context::blit( framebuffer from, framebuffer to, clear_state::buffers_typemask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )215 void nv::gl_context::blit( framebuffer from, framebuffer to, buffer_mask mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 ) 216 216 { 217 217 gl_framebuffer_info* finfo = m_framebuffers.get( from ); … … 221 221 glBindFramebuffer( GL_READ_FRAMEBUFFER, finfo->glid ); 222 222 glBindFramebuffer( GL_DRAW_FRAMEBUFFER, tinfo ? tinfo->glid : 0 ); 223 unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;223 unsigned filter = mask == buffer_mask::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST; 224 224 glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter ); 225 225 glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); -
trunk/src/gl/gl_enum.cc
r500 r503 28 28 } 29 29 30 unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_typetype )30 unsigned int nv::clear_state_buffers_to_mask( buffer_mask type ) 31 31 { 32 32 unsigned int mask = 0; 33 if ( (type & clear_state::COLOR_BUFFER) != 0 ) mask |= GL_COLOR_BUFFER_BIT;34 if ( (type & clear_state::DEPTH_BUFFER) != 0 ) mask |= GL_DEPTH_BUFFER_BIT;35 if ( (type & clear_state::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;33 if ( (type & buffer_mask::COLOR_BUFFER) != 0 ) mask |= GL_COLOR_BUFFER_BIT; 34 if ( (type & buffer_mask::DEPTH_BUFFER) != 0 ) mask |= GL_DEPTH_BUFFER_BIT; 35 if ( (type & buffer_mask::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT; 36 36 return mask; 37 37 } -
trunk/src/lua/lua_area.cc
r491 r503 459 459 } 460 460 461 void nv::lua::register_area( lua _State* L)462 { 463 int stack = lua_gettop( L);464 nlua_requiref( L, "area", luaopen_area, 1);465 lua_settop( L, stack );466 } 467 461 void nv::lua::register_area( lua::state* state ) 462 { 463 int stack = lua_gettop( state->get_raw() ); 464 nlua_requiref( state->get_raw(), "area", luaopen_area, 1); 465 lua_settop( state->get_raw(), stack ); 466 } 467 -
trunk/src/lua/lua_aux.cc
r490 r503 137 137 }; 138 138 139 void nv::lua::register_aux( lua _State* L)139 void nv::lua::register_aux( lua::state* state ) 140 140 { 141 nlua_register( L, "table", nluaaux_table_aux_f );142 nlua_register( L, "math", nluaaux_math_aux_f );141 nlua_register( state->get_raw(), "table", nluaaux_table_aux_f ); 142 nlua_register( state->get_raw(), "math", nluaaux_math_aux_f ); 143 143 } 144 144 -
trunk/src/lua/lua_map_area.cc
r490 r503 223 223 } 224 224 225 void nv::lua::register_map_area_interface( lua_State* L, int index ) 226 { 227 nlua_register( L, nlua_map_area_f, index ); 228 } 229 230 void nv::lua::register_map_area( lua_State* L ) 231 { 232 luaopen_map_area(L); 233 } 234 235 void nv::lua::register_map_area_instance( lua_State* L, ref object_index, map_area* area ) 236 { 225 void nv::lua::register_map_area_interface( lua::state* state, int index ) 226 { 227 nlua_register( state->get_raw(), nlua_map_area_f, index ); 228 } 229 230 void nv::lua::register_map_area( lua::state* state ) 231 { 232 luaopen_map_area( state->get_raw() ); 233 } 234 235 void nv::lua::register_map_area_instance( lua::state* state, ref object_index, map_area* area ) 236 { 237 lua_State* L = state->get_raw(); 237 238 lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() ); 238 239 lua_pushliteral( L, "__map_area_ptr" ); -
trunk/src/lua/lua_map_tile.cc
r490 r503 366 366 }; 367 367 368 void nv::lua::register_map_tile( lua _State * L)368 void nv::lua::register_map_tile( lua::state* state ) 369 369 { 370 370 // TODO: check if __gc is used! 371 lua_State* L = state->get_raw(); 371 372 luaL_newmetatable( L, NLUA_MAP_TILE_METATABLE ); 372 373 lua_pushvalue( L, -1 ); -
trunk/src/lua/lua_math.cc
r490 r503 359 359 } 360 360 361 void nv::lua::register_math( lua_State* L ) 361 template < typename T > 362 void nlua_rtti_vec_push( nv::lua::state* state, const nv::type_entry*, void* object ) 363 { 364 T* value = reinterpret_cast<T*>( object ); 365 push_vec<T>( state->get_raw(), *value ); 366 } 367 368 template < typename T > 369 bool nlua_rtti_vec_read( nv::lua::state* state, const nv::type_entry*, void* object, int index ) 370 { 371 T* value = reinterpret_cast<T*>( object ); 372 int type = lua_type( state->get_raw(), index ); 373 if ( type == LUA_TUSERDATA ) 374 { 375 T* from = to_pvec<T>( state->get_raw(), index ); 376 if ( !from ) return false; 377 *value = *from; 378 } 379 // else if ( type == LUA_TTABLE ) 380 // { 381 // 382 // } 383 else 384 return false; 385 int todo; int table_constructor; 386 return true; 387 } 388 389 void nv::lua::register_math( lua::state* state ) 362 390 { 363 391 for (size_t i = 0; i < 256; ++i ) nlua_swizzel_lookup[i] = 255; … … 379 407 nlua_swizzel_lookup[uchar8( 'v' )] = 0; 380 408 nlua_swizzel_lookup[uchar8( '3' )] = 3; 409 410 lua_State* L = state->get_raw(); 381 411 int stack = lua_gettop( L ); 382 412 … … 389 419 nlua_requiref(L, "vec4", luaopen_vec<nv::vec4>, 1); 390 420 lua_settop( L, stack ); 391 } 392 421 422 state->register_rtti_type< nv::ivec2 >( nlua_rtti_vec_push<nv::ivec2>, nlua_rtti_vec_read<nv::ivec2> ); 423 state->register_rtti_type< nv::ivec3 >( nlua_rtti_vec_push<nv::ivec3>, nlua_rtti_vec_read<nv::ivec3> ); 424 state->register_rtti_type< nv::ivec4 >( nlua_rtti_vec_push<nv::ivec4>, nlua_rtti_vec_read<nv::ivec4> ); 425 state->register_rtti_type< nv::vec2 > ( nlua_rtti_vec_push<nv::vec2>, nlua_rtti_vec_read<nv::vec2> ); 426 state->register_rtti_type< nv::vec3 > ( nlua_rtti_vec_push<nv::vec3>, nlua_rtti_vec_read<nv::vec3> ); 427 state->register_rtti_type< nv::vec4 > ( nlua_rtti_vec_push<nv::vec4>, nlua_rtti_vec_read<nv::vec4> ); 428 } 429 -
trunk/src/lua/lua_state.cc
r490 r503 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/lua/lua_nova.hh" 11 #include "nv/lua/lua_types.hh" 11 12 #include "nv/core/logging.hh" 12 13 #include "nv/stl/string.hh" … … 143 144 144 145 lua::table_guard::table_guard( lua::state* lstate, const path& p, bool global ) 145 : state_wrapper( lstate->get_raw(), false ), m_level(0)146 : state_wrapper( lstate->get_raw(), lstate->m_lua_types, false ), m_parent( lstate ), m_level(0) 146 147 { 147 148 m_global = false; … … 155 156 156 157 lua::table_guard::table_guard( const table_guard& parent, const path& p ) 157 : state_wrapper( parent.m_state, false), m_level(0)158 : state_wrapper( parent.m_state, parent.m_lua_types, false ), m_parent( parent.m_parent ), m_level(0) 158 159 { 159 160 m_global = false; … … 350 351 351 352 353 bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object ) 354 { 355 NV_ASSERT_ALWAYS( m_lua_types->get_type_database() == entry->type_db, "Type database mismatch between Lua and entry!" ); 356 lua_getfield( m_state, -1, element.data() ); 357 if ( lua_type( m_state, -1 ) != LUA_TTABLE ) 358 { 359 lua_pop( m_state, 1 ); 360 return false; 361 } 362 if ( !nv::lua::read_rtti_type( m_parent, entry, object, -1 ) ) 363 { 364 lua_pop( m_state, 1 ); 365 return false; 366 } 367 lua_pop( m_state, 1 ); 368 return true; 369 } 370 352 371 // state 353 372 354 lua::state::state( lua_State* state ) : state_wrapper( state, false ) 355 { 356 357 } 358 359 lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true ) 373 lua::state::state( lua_State* state, type_database* types ) 374 : state_wrapper( state, new type_data( types ), false ) 375 { 376 377 } 378 379 lua::state::state( bool load_libs /*= false*/, type_database* types ) 380 : state_wrapper( nullptr, new type_data( types ), true ) 360 381 { 361 382 load_lua_library(); … … 575 596 } 576 597 598 void nv::lua::state::register_rtti_type( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r ) 599 { 600 m_lua_types->insert( tid, p, r ); 601 } 602 577 603 nv::lua::ref nv::lua::state::register_handle_component_impl( string_view id, bool empty ) 578 604 { … … 626 652 } 627 653 654 nv::lua::state::~state() 655 { 656 delete m_lua_types; 657 m_lua_types = nullptr; 658 } 659 660 template < typename T > 661 void nlua_rtti_signed_push( nv::lua::state* state, const type_entry*, void* object ) 662 { 663 T* value = reinterpret_cast<T*>( object ); 664 lua_pushinteger( state->get_raw(), lua_Integer( *value ) ); 665 } 666 667 template < typename T > 668 void nlua_rtti_unsigned_push( nv::lua::state* state, const type_entry*, void* object ) 669 { 670 T* value = reinterpret_cast<T*>( object ); 671 lua_pushinteger( state->get_raw(), lua_Unsigned( *value ) ); 672 } 673 674 template < typename T > 675 void nlua_rtti_floating_push( nv::lua::state* state, const type_entry*, void* object ) 676 { 677 T* value = reinterpret_cast< T* >( object ); 678 lua_pushnumber( state->get_raw(), lua_Number( *value ) ); 679 } 680 681 static void nlua_rtti_boolean_push( nv::lua::state* state, const type_entry*, void* object ) 682 { 683 bool* value = reinterpret_cast<bool*>( object ); 684 lua_pushboolean( state->get_raw(), *value ); 685 } 686 687 template < typename T > 688 bool nlua_rtti_signed_read( nv::lua::state* state, const type_entry*, void* object, int index ) 689 { 690 T* value = reinterpret_cast<T*>( object ); 691 if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER ) 692 { 693 *value = T( lua_tointeger( state->get_raw(), index ) ); 694 return true; 695 } 696 return false; 697 } 698 699 template < typename T > 700 bool nlua_rtti_unsigned_read( nv::lua::state* state, const type_entry*, void* object, int index ) 701 { 702 T* value = reinterpret_cast<T*>( object ); 703 if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER ) 704 { 705 *value = T( lua_tointeger( state->get_raw(), index ) ); 706 return true; 707 } 708 return false; 709 } 710 711 template < typename T > 712 bool nlua_rtti_floating_read( nv::lua::state* state, const type_entry*, void* object, int index ) 713 { 714 T* value = reinterpret_cast<T*>( object ); 715 if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER ) 716 { 717 *value = T( lua_tonumber( state->get_raw(), index ) ); 718 return true; 719 } 720 return false; 721 } 722 723 static bool nlua_rtti_boolean_read( nv::lua::state* state, const type_entry*, void* object, int index ) 724 { 725 bool* value = reinterpret_cast<bool*>( object ); 726 if ( lua_type( state->get_raw(), index ) == LUA_TBOOLEAN ) 727 { 728 *value = bool( lua_toboolean( state->get_raw(), index ) ); 729 return true; 730 } 731 return false; 732 } 733 734 735 void nv::lua::type_data::insert( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r ) 736 { 737 m_type_read.assign( tid, r ); 738 m_type_push.assign( tid, p ); 739 } 740 741 void nv::lua::type_data::register_standard_types() 742 { 743 insert<bool>( nlua_rtti_boolean_push, nlua_rtti_boolean_read ); 744 insert<nv::sint8> ( nlua_rtti_signed_push<nv::sint8>, nlua_rtti_signed_read<nv::sint8> ); 745 insert<nv::sint16>( nlua_rtti_signed_push<nv::sint16>, nlua_rtti_signed_read<nv::sint16> ); 746 insert<nv::sint32>( nlua_rtti_signed_push<nv::sint32>, nlua_rtti_signed_read<nv::sint32> ); 747 insert<nv::uint8> ( nlua_rtti_unsigned_push<nv::uint8>, nlua_rtti_unsigned_read<nv::uint8> ); 748 insert<nv::uint16>( nlua_rtti_unsigned_push<nv::uint16>, nlua_rtti_unsigned_read<nv::uint16> ); 749 insert<nv::uint32>( nlua_rtti_unsigned_push<nv::uint32>, nlua_rtti_unsigned_read<nv::uint32> ); 750 insert<nv::f32> ( nlua_rtti_floating_push<nv::f32>, nlua_rtti_floating_read<nv::f32> ); 751 insert<nv::f64> ( nlua_rtti_floating_push<nv::f64>, nlua_rtti_floating_read<nv::f64> ); 752 // insert<nv::sint64>( nlua_rtti_floating_push<nv::sint64>, nlua_rtti_floating_read<nv::sint64> ); 753 // insert<nv::uint64>( nlua_rtti_floating_push<nv::uint64>, nlua_rtti_floating_read<nv::uint64> ); 754 }
Note: See TracChangeset
for help on using the changeset viewer.