- Timestamp:
- 10/03/16 17:45:46 (9 years ago)
- Location:
- trunk/src
- Files:
-
- 6 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/library.cc
r438 r520 11 11 # include <windows.h> 12 12 # define NV_LIB_EXT ".dll" 13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryEx ( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) )13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryExA( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ) 14 14 # define NV_LIB_GET( handle, name ) reinterpret_cast<void*>( GetProcAddress( static_cast<HMODULE>( handle ), name ) ) 15 15 # define NV_LIB_CLOSE( handle ) ( FreeLibrary( static_cast<HMODULE>( handle ) ) != 0 ) -
trunk/src/curses/curses_terminal.cc
r514 r520 131 131 } 132 132 133 // if result is a typable char from the 0..9 range 134 if ( result >= 0x108 && result <= 0x108 + 12 ) 135 { 136 kevent.key.code = static_cast<nv::key_code>( nv::KEY_F1 + result - 0x108 - 1 ); 137 } 138 133 139 // other recognized codes 134 140 switch ( result ) -
trunk/src/engine/default_resource_manager.cc
r519 r520 11 11 default_resource_manager::default_resource_manager( context* context, bool clear_material_paths ) 12 12 { 13 m_images 14 m_meshes 15 m_binds 16 m_animators 17 m_materials 18 m_programs 19 m_gpu_meshes 20 m_mesh_datas 13 m_images = register_resource_handler< image_data >( new image_manager ); 14 m_meshes = register_resource_handler< data_channel_set >( new mesh_manager ); 15 m_binds = register_resource_handler< animator_bind_data >( new animator_bind_manager ); 16 m_animators = register_resource_handler< animator_data >( new animator_manager ); 17 m_materials = register_resource_handler< material >( new material_manager( clear_material_paths ) ); 18 m_programs = register_resource_handler< program >( new program_manager( context ) ); 19 m_gpu_meshes = register_resource_handler< gpu_mesh >( new gpu_mesh_manager( context, m_meshes ) ); 20 m_mesh_datas = register_resource_handler< mesh_data >( new mesh_data_manager( m_meshes ) ); 21 21 m_gpu_materials = register_resource_handler< gpu_material >( new gpu_material_manager( context, m_materials, m_images ) ); 22 m_models = register_resource_handler< model >( new model_manager( this, m_binds, m_mesh_datas ) ); 23 m_particles = register_resource_handler< particle_system_data >( new particle_manager ); 22 m_models = register_resource_handler< model >( new model_manager( this, m_binds, m_mesh_datas ) ); 23 m_particles = register_resource_handler< particle_system_data >( new particle_manager ); 24 m_ragdolls = register_resource_handler< ragdoll_data >( new ragdoll_manager( m_models ) ); 24 25 } 25 26 26 void default_resource_manager::initialize( lua::state* lua )27 void default_resource_manager::initialize( lua::state* lua, physics_world* world ) 27 28 { 28 29 m_lua = lua; … … 72 73 m_models->initialize( lua ); 73 74 m_particles->initialize( lua ); 75 m_ragdolls->initialize( lua ); 76 m_ragdolls->initialize( world ); 74 77 } 75 78 -
trunk/src/engine/particle_engine.cc
r519 r520 1 // Copyright (C) 2014-201 5ChaosForge Ltd1 // Copyright (C) 2014-2016 ChaosForge Ltd 2 2 // http://chaosforge.org/ 3 3 // … … 26 26 using namespace nv; 27 27 28 static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count )28 static void nv_particle_emitter_point( random_base*, const particle_emitter_data*, particle* p, uint32 count ) 29 29 { 30 30 for ( uint32 i = 0; i < count; ++i ) … … 34 34 } 35 35 36 static void nv_particle_emitter_box( const particle_emitter_data* pe, particle* p, uint32 count ) 37 { 38 random& r = random::get(); 39 for ( uint32 i = 0; i < count; ++i ) 40 { 41 p[i].position = 42 r.frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir + 43 r.frange( 0.0f, pe->extents[1] ) * pe->dir + 44 r.frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir; 45 } 46 } 47 48 static void nv_particle_emitter_cylinder( const particle_emitter_data* pe, particle* p, uint32 count ) 49 { 50 random& r = random::get(); 51 for ( uint32 i = 0; i < count; ++i ) 52 { 53 vec2 rellipse( r.disk_point( pe->precise ) * pe->extents[0] ); 36 static void nv_particle_emitter_box( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 37 { 38 for ( uint32 i = 0; i < count; ++i ) 39 { 40 p[i].position = 41 r->frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir + 42 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 43 r->frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir; 44 } 45 } 46 47 static void nv_particle_emitter_cylinder( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 48 { 49 for ( uint32 i = 0; i < count; ++i ) 50 { 51 vec2 rellipse( r->disk_point( pe->precise ) * pe->extents[0] ); 54 52 p[i].position = 55 53 rellipse.x * pe->cdir + 56 r .frange( 0.0f, pe->extents[1] ) * pe->dir +54 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 57 55 rellipse.y * pe->odir; 58 56 } 59 57 } 60 58 61 static void nv_particle_emitter_sphere( const particle_emitter_data* pe, particle* p, uint32 count ) 62 { 63 random& r = random::get(); 64 for ( uint32 i = 0; i < count; ++i ) 65 { 66 vec3 rsphere = r.sphere_point( pe->precise ) * pe->extents[0]; 59 static void nv_particle_emitter_sphere( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 60 { 61 for ( uint32 i = 0; i < count; ++i ) 62 { 63 vec3 rsphere = r->sphere_point( pe->precise ) * pe->extents[0]; 67 64 p[i].position = 68 65 rsphere.x * pe->cdir + … … 72 69 } 73 70 74 static void nv_particle_emitter_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count ) 75 { 76 random& r = random::get(); 77 for ( uint32 i = 0; i < count; ++i ) 78 { 79 vec2 rellipse = r.ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise ); 71 static void nv_particle_emitter_cylindroid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 72 { 73 for ( uint32 i = 0; i < count; ++i ) 74 { 75 vec2 rellipse = r->ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise ); 80 76 p[i].position = 81 77 rellipse.x * pe->cdir + 82 r .frange( 0.0f, pe->extents[1] ) * pe->dir +78 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 83 79 rellipse.y * pe->odir; 84 80 } 85 81 } 86 82 87 static void nv_particle_emitter_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count ) 88 { 89 random& r = random::get(); 90 for ( uint32 i = 0; i < count; ++i ) 91 { 92 vec3 rsphere = r.ellipsoid_point( pe->hextents, pe->precise ); 83 static void nv_particle_emitter_ellipsoid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 84 { 85 for ( uint32 i = 0; i < count; ++i ) 86 { 87 vec3 rsphere = r->ellipsoid_point( pe->hextents, pe->precise ); 93 88 p[i].position = 94 89 rsphere.x * pe->cdir + … … 98 93 } 99 94 100 static void nv_particle_emitter_hollow_cylinder( const particle_emitter_data* pe, particle* p, uint32 count ) 101 { 102 random& r = random::get(); 103 for ( uint32 i = 0; i < count; ++i ) 104 { 105 vec2 rellipse = r.hollow_disk_point( 95 static void nv_particle_emitter_hollow_cylinder( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 96 { 97 for ( uint32 i = 0; i < count; ++i ) 98 { 99 vec2 rellipse = r->hollow_disk_point( 106 100 pe->ihextents[0], 107 101 pe->hextents[0], … … 109 103 p[i].position = 110 104 rellipse.x * pe->cdir + 111 r .frange( 0.0f, pe->extents[1] ) * pe->dir +105 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 112 106 rellipse.y * pe->odir; 113 107 } 114 108 } 115 109 116 static void nv_particle_emitter_hollow_sphere( const particle_emitter_data* pe, particle* p, uint32 count ) 117 { 118 random& r = random::get(); 119 for ( uint32 i = 0; i < count; ++i ) 120 { 121 vec3 rellipse = r.hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise ); 110 static void nv_particle_emitter_hollow_sphere( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 111 { 112 for ( uint32 i = 0; i < count; ++i ) 113 { 114 vec3 rellipse = r->hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise ); 122 115 p[i].position = 123 116 rellipse.x * pe->cdir + … … 127 120 } 128 121 129 static void nv_particle_emitter_hollow_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count ) 130 { 131 random& r = random::get(); 132 for ( uint32 i = 0; i < count; ++i ) 133 { 134 vec2 rellipse = r.hollow_ellipse_point( 122 static void nv_particle_emitter_hollow_cylindroid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 123 { 124 for ( uint32 i = 0; i < count; ++i ) 125 { 126 vec2 rellipse = r->hollow_ellipse_point( 135 127 vec2( pe->ihextents[0], pe->ihextents[2] ), 136 128 vec2( pe->hextents[0], pe->hextents[2] ), … … 138 130 p[i].position = 139 131 rellipse.x * pe->cdir + 140 r .frange( 0.0f, pe->extents[1] ) * pe->dir +132 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 141 133 rellipse.y * pe->odir; 142 134 } 143 135 } 144 136 145 static void nv_particle_emitter_hollow_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count ) 146 { 147 random& r = random::get(); 148 for ( uint32 i = 0; i < count; ++i ) 149 { 150 vec3 rellipse = r.hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise ); 137 static void nv_particle_emitter_hollow_ellipsoid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 138 { 139 for ( uint32 i = 0; i < count; ++i ) 140 { 141 vec3 rellipse = r->hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise ); 151 142 p[i].position = 152 143 rellipse.x * pe->cdir + … … 278 269 } 279 270 280 nv::particle_engine::particle_engine( context* a_context, bool debug_data ) 281 { 282 m_context = a_context; 271 nv::particle_engine::particle_engine( context* a_context, random_base* rng, particle_group_manager* groups, bool debug_data ) 272 { 273 m_context = a_context; 274 m_pgm = groups; 275 m_rng = rng; 276 if ( m_rng == nullptr ) 277 m_rng = &random::get(); 278 283 279 if ( debug_data ) 284 280 { 285 281 m_debug_emitter_names = new nv::hash_map< nv::particle_emitter_func, nv::const_string >; 286 282 m_debug_affector_names = new nv::hash_map< nv::particle_affector_func, nv::const_string >; 287 m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >;288 283 m_debug_emitter_list = new nv::vector< nv::particle_emitter_func >; 289 284 m_debug_affector_list = new nv::vector< nv::particle_affector_func >; … … 294 289 } 295 290 296 nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_ system_group group )297 { 298 particle_system_group_info* ginfo = m_groups.get( group );299 if ( !ginfo )return nv::particle_system();300 291 nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_group group ) 292 { 293 if ( !m_pgm->ref( group ) ) 294 return nv::particle_system(); 295 301 296 particle_system result = m_systems.create(); 302 297 particle_system_info* info = m_systems.get( result ); … … 310 305 info->emitters[i].pause = 0; 311 306 else 312 info->emitters[i].pause = random::get().frange( data->emitters[i].duration_min, data->emitters[i].duration_max );307 info->emitters[i].pause = m_rng->frange( data->emitters[i].duration_min, data->emitters[i].duration_max ); 313 308 314 309 } … … 316 311 info->count = 0; 317 312 info->particles = new particle[data->quota]; 318 ginfo->ref_counter++;319 313 320 314 return result; 321 315 } 322 316 323 nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_ system_group group )317 nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_group group ) 324 318 { 325 319 if ( auto data = rdata.lock() ) … … 328 322 } 329 323 330 void nv::particle_engine::prepare( particle_system_group group ) 331 { 332 particle_system_group_info* info = m_groups.get( group ); 333 if ( info ) 334 { 335 info->count = 0; 336 } 337 } 338 339 nv::particle_system_group nv::particle_engine::create_group( uint32 max_particles ) 340 { 341 particle_system_group result = m_groups.create(); 342 particle_system_group_info* info = m_groups.get( result ); 343 info->local = false; 344 info->count = 0; 345 info->quota = max_particles; 346 info->vtx_buffer = m_context->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ ); 347 vertex_array_desc desc; 348 desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true ); 349 info->vtx_array = m_context->create_vertex_array( desc ); 350 info->quads = new particle_quad[info->quota]; 351 info->ref_counter = 0; 352 return result; 324 void nv::particle_engine::prepare( particle_group group ) 325 { 326 m_pgm->prepare( group ); 327 } 328 329 nv::particle_group nv::particle_engine::create_group( uint32 max_particles ) 330 { 331 return m_pgm->create_group( max_particles ); 353 332 } 354 333 … … 369 348 while ( m_systems.size() > 0 ) 370 349 release( m_systems.get_handle( 0 ) ); 371 while ( m_groups.size() > 0)372 release( m_groups.get_handle( 0 ));350 if ( m_pgm ) 351 m_pgm->reset(); 373 352 m_emitters.clear(); 374 353 m_affectors.clear(); … … 381 360 if ( info ) 382 361 { 383 particle_system_group_info* ginfo = m_groups.get( info->group ); 384 if ( ginfo ) ginfo->ref_counter--; 385 delete[] info->particles; 362 m_pgm->unref( info->group ); 363 delete[] info->particles; 386 364 m_systems.destroy( system ); 387 365 } 388 366 } 389 367 390 void nv::particle_engine::release( particle_system_group group ) 391 { 392 particle_system_group_info* info = m_groups.get( group ); 393 if ( info ) 394 { 395 delete[] info->quads; 396 m_context->release( info->vtx_array ); 397 m_groups.destroy( group ); 398 } 368 void nv::particle_engine::release( particle_group group ) 369 { 370 m_pgm->release( group ); 399 371 } 400 372 … … 403 375 particle_system_info* info = m_systems.get( system ); 404 376 if ( info ) 405 { 406 generate_data( info, s ); 407 } 377 m_pgm->generate_data( array_view< particle >( info->particles, info->count ), info->data, info->group, s ); 408 378 } 409 379 … … 440 410 info->texcoords[1] = b; 441 411 } 442 }443 444 void nv::particle_engine::generate_data( particle_system_info* info, const scene_state& s )445 {446 // void* rawptr = m_context->map_buffer( info->vtx_buffer, nv::WRITE_UNSYNCHRONIZED, offset, info->count*sizeof( particle_quad ) );447 // particle_quad* quads = reinterpret_cast<particle_quad*>( rawptr );448 449 particle_system_group_info* group = m_groups.get( info->group );450 if ( !info )451 {452 return;453 }454 455 vec2 lb = vec2( -0.5f, -0.5f );456 vec2 rt = vec2( 0.5f, 0.5f );457 458 switch ( info->data->origin )459 {460 case particle_origin::CENTER : break;461 case particle_origin::TOP_LEFT : lb = vec2(0.f,-1.f); rt = vec2(1.f,0.f); break;462 case particle_origin::TOP_CENTER : lb.y = -1.f; rt.y = 0.f; break;463 case particle_origin::TOP_RIGHT : lb = vec2(-1.f,-1.f); rt = vec2(); break;464 case particle_origin::CENTER_LEFT : lb.x = 0.f; rt.x = 1.f; break;465 case particle_origin::CENTER_RIGHT : lb.x = -1.f; rt.x = 0.f; break;466 case particle_origin::BOTTOM_LEFT : lb = vec2(); rt = vec2(1.f,1.f); break;467 case particle_origin::BOTTOM_CENTER : lb.y = 0.f; rt.y = 1.f; break;468 case particle_origin::BOTTOM_RIGHT : lb = vec2(-1.f,0.f); rt = vec2(.0f,1.f); break;469 }470 471 const vec3 sm[4] =472 {473 vec3( lb.x, lb.y, 0.0f ),474 vec3( rt.x, lb.y, 0.0f ),475 vec3( lb.x, rt.y, 0.0f ),476 vec3( rt.x, rt.y, 0.0f ),477 };478 vec3 z( 0.0f, 0.0f ,1.0f );479 480 particle_orientation orientation = info->data->orientation;481 vec3 common_up ( info->data->common_up );482 vec3 common_dir( info->data->common_dir );483 bool accurate_facing = info->data->accurate_facing;484 mat3 rot_mat;485 vec3 right;486 vec3 pdir( 0.0f, 1.0f, 0.0f );487 488 vec3 camera_pos = s.get_camera().get_position();489 vec3 inv_view_dir = math::normalize( -s.get_camera().get_direction() );490 491 for ( uint32 i = 0; i < info->count; ++i )492 {493 const particle& pdata = info->particles[i];494 // particle_quad& rdata = quads[i];495 particle_quad& rdata = group->quads[i + group->count];496 497 vec3 view_dir( inv_view_dir );498 if ( accurate_facing ) view_dir = math::normalize( camera_pos - pdata.position );499 500 switch ( orientation )501 {502 case particle_orientation::POINT :503 right = math::normalize( math::cross( view_dir, vec3( 0, 1, 0 ) ) );504 right = math::rotate( right, pdata.rotation, view_dir );505 rot_mat = mat3( right, math::cross( right, -view_dir ), -view_dir );506 break;507 case particle_orientation::ORIENTED :508 pdir = normalize_safe( pdata.velocity, pdir );509 right = math::normalize( math::cross( pdir, view_dir ) );510 rot_mat = mat3( right, pdir, math::cross( pdir, right ) );511 break;512 case particle_orientation::ORIENTED_COMMON :513 right = math::normalize( math::cross( common_dir, view_dir ) );514 rot_mat = mat3( right, common_dir, math::cross( common_dir, right ) );515 break;516 case particle_orientation::PERPENDICULAR :517 pdir = normalize_safe( pdata.velocity, pdir );518 right = math::normalize( math::cross( common_up, pdir ) );519 rot_mat = mat3( right, common_up, math::cross( common_up, right ) );520 break;521 case particle_orientation::PERPENDICULAR_COMMON :522 right = math::normalize( math::cross( common_up, common_dir ) );523 rot_mat = mat3( right, common_up, math::cross( common_up, right ) );524 break;525 }526 527 vec2 texcoords[4] =528 {529 pdata.tcoord_a,530 vec2( pdata.tcoord_b.x, pdata.tcoord_a.y ),531 vec2( pdata.tcoord_a.x, pdata.tcoord_b.y ),532 pdata.tcoord_b533 };534 535 vec3 size( pdata.size.x, pdata.size.y, 0.0f );536 vec3 s0 = rot_mat * ( ( size * sm[0] ) );537 vec3 s1 = rot_mat * ( ( size * sm[1] ) );538 vec3 s2 = rot_mat * ( ( size * sm[2] ) );539 vec3 s3 = rot_mat * ( ( size * sm[3] ) );540 541 rdata.data[0].position = pdata.position + s0;542 rdata.data[0].color = pdata.color;543 rdata.data[0].texcoord = texcoords[0];544 545 rdata.data[1].position = pdata.position + s1;546 rdata.data[1].color = pdata.color;547 rdata.data[1].texcoord = texcoords[1];548 549 rdata.data[2].position = pdata.position + s2;550 rdata.data[2].color = pdata.color;551 rdata.data[2].texcoord = texcoords[2];552 553 rdata.data[3].position = pdata.position + s3;554 rdata.data[3].color = pdata.color;555 rdata.data[3].texcoord = texcoords[3];556 557 rdata.data[4] = rdata.data[2];558 rdata.data[5] = rdata.data[1];559 }560 // m_context->unmap_buffer( info->vtx_buffer );561 562 m_context->update( group->vtx_buffer, group->quads, group->count*sizeof(particle_quad), info->count*sizeof( particle_quad ) );563 group->count += info->count;564 412 } 565 413 … … 584 432 if ( ecount == 0 ) return; 585 433 586 random& r = random::get();587 434 bool local = model.is_identity(); 588 435 // if ( !local ) … … 605 452 { 606 453 particle& pinfo = info->particles[info->count]; 607 edata.emitter_func( &(info->data->emitters[i]), &pinfo, 1 );454 edata.emitter_func( m_rng, &(info->data->emitters[i]), &pinfo, 1 ); 608 455 pinfo.position = vec3(); 609 456 pinfo.position+= edata.position; … … 611 458 pinfo.position = pinfo.position * model; 612 459 pinfo.color = edata.color_min == edata.color_max ? 613 edata.color_min : r.range( edata.color_min, edata.color_max );460 edata.color_min : m_rng->range( edata.color_min, edata.color_max ); 614 461 pinfo.size = edata.size_min == edata.size_max ? 615 edata.size_min : r.range( edata.size_min, edata.size_max );462 edata.size_min : m_rng->range( edata.size_min, edata.size_max ); 616 463 if ( edata.square ) pinfo.size.y = pinfo.size.x; 617 464 float velocity = edata.velocity_min == edata.velocity_max ? 618 edata.velocity_min : r.frange( edata.velocity_min, edata.velocity_max );465 edata.velocity_min : m_rng->frange( edata.velocity_min, edata.velocity_max ); 619 466 pinfo.lifetime = dtime + einfo.next; 620 467 pinfo.death = ( edata.lifetime_min == edata.lifetime_max ? 621 edata.lifetime_min : r.frange( edata.lifetime_min, edata.lifetime_max ) );622 pinfo.rotation = r.frand( 2* math::pi<float>() );468 edata.lifetime_min : m_rng->frange( edata.lifetime_min, edata.lifetime_max ) ); 469 pinfo.rotation = m_rng->frand( 2* math::pi<float>() ); 623 470 pinfo.tcoord_a = info->texcoords[0]; 624 471 pinfo.tcoord_b = info->texcoords[1]; … … 628 475 { 629 476 float emission_angle = math::radians( edata.angle ); 630 float cos_theta = r.frange( cos( emission_angle ), 1.0f );477 float cos_theta = m_rng->frange( cos( emission_angle ), 1.0f ); 631 478 float sin_theta = sqrt(1.0f - cos_theta * cos_theta ); 632 float phi = r.frange( 0.0f, 2* math::pi<float>() );479 float phi = m_rng->frange( 0.0f, 2* math::pi<float>() ); 633 480 pinfo.velocity = model.get_orientation() * 634 481 ( edata.odir * ( cos(phi) * sin_theta ) + … … 672 519 uint32 ecount = info->data->emitter_count; 673 520 if ( ecount == 0 ) return; 674 random& r = random::get();675 521 676 522 for ( uint32 i = 0; i < ecount; ++i ) … … 691 537 einfo.active = false; 692 538 if ( edata.repeat_min > 0.0f ) 693 einfo.pause += r.frange( edata.repeat_min, edata.repeat_max );539 einfo.pause += m_rng->frange( edata.repeat_min, edata.repeat_max ); 694 540 else 695 541 einfo.pause = 0.0f; … … 698 544 { 699 545 einfo.active = true; 700 einfo.pause += r.frange( edata.duration_min, edata.duration_max );546 einfo.pause += m_rng->frange( edata.duration_min, edata.duration_max ); 701 547 } 702 548 } … … 776 622 } 777 623 778 nv::particle_render_data nv::particle_engine::get_render_data( particle_system_group group ) 779 { 780 const particle_system_group_info* info = m_groups.get( group ); 781 if ( info ) 782 { 783 return{ info->count, info->vtx_array }; 784 } 785 return { 0, nv::vertex_array() }; 624 nv::particle_render_data nv::particle_engine::get_render_data( particle_group group ) 625 { 626 return m_pgm->get_render_data( group ); 786 627 } 787 628 … … 794 635 } 795 636 796 void nv::particle_engine::register_types( type_database* db ) 637 const nv::type_entry* nv::particle_engine::get_debug_type( particle_affector_func f ) 638 { 639 if ( m_debug_affector_types ) 640 { 641 auto it = m_debug_affector_types->find( f ); 642 if ( it != m_debug_affector_types->end() ) 643 return it->second; 644 } 645 return nullptr; 646 } 647 648 void nv::particle_engine::register_types( type_database* db, bool debug_data ) 797 649 { 798 650 db->create_type<particle_orientation>() … … 816 668 ; 817 669 818 if ( m_debug_affector_types ) 819 { 670 if ( debug_data ) 671 { 672 if ( !m_debug_affector_types ) 673 m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >; 674 820 675 int you_could_get_rid_of_the_init_function_using_these; int error; 821 676 int universal_vm_based_affector; … … 849 704 } 850 705 } 706 -
trunk/src/engine/particle_manager.cc
r518 r520 61 61 data->emitter_count = 0; 62 62 data->affector_count = 0; 63 64 const_string orientation = table.get_string( "orientation", "point" ); 65 if ( orientation == "point" ) { data->orientation = particle_orientation::POINT; } 66 else if ( orientation == "oriented" ) { data->orientation = particle_orientation::ORIENTED; } 67 else if ( orientation == "oriented_common" ) { data->orientation = particle_orientation::ORIENTED_COMMON; } 68 else if ( orientation == "perpendicular" ) { data->orientation = particle_orientation::PERPENDICULAR; } 69 else if ( orientation == "perpendicular_common" ) { data->orientation = particle_orientation::PERPENDICULAR_COMMON; } 70 else 71 { 72 NV_LOG_ERROR( "Unknown orientation type! (", orientation, ")!" ); 73 data->orientation = particle_orientation::POINT; 74 } 75 76 const_string origin = table.get_string( "origin", "center" ); 77 if ( origin == "center" ) { data->origin = particle_origin::CENTER; } 78 else if ( origin == "top_left" ) { data->origin = particle_origin::TOP_LEFT; } 79 else if ( origin == "top_center" ) { data->origin = particle_origin::TOP_CENTER; } 80 else if ( origin == "top_right" ) { data->origin = particle_origin::TOP_RIGHT; } 81 else if ( origin == "center_left" ) { data->origin = particle_origin::CENTER_LEFT; } 82 else if ( origin == "center_right" ) { data->origin = particle_origin::CENTER_RIGHT; } 83 else if ( origin == "bottom_left" ) { data->origin = particle_origin::BOTTOM_LEFT; } 84 else if ( origin == "bottom_center" ) { data->origin = particle_origin::BOTTOM_CENTER; } 85 else if ( origin == "bottom_right" ) { data->origin = particle_origin::BOTTOM_RIGHT; } 86 else 87 { 88 NV_LOG_ERROR( "Unknown particle origin! (", origin, ")!" ); 89 data->origin = particle_origin::CENTER; 90 } 63 data->orientation = particle_orientation( table.get_unsigned("orientation", 0) ); 64 data->origin = particle_origin( table.get_unsigned( "origin",0 ) ); 91 65 92 66 data->common_up = math::normalize( table.get<vec3>("common_up", vec3(1,0,0) ) ); -
trunk/src/gfx/debug_draw.cc
r509 r520 101 101 } 102 102 103 void nv::debug_data::push_wire_capsule( const transform& tr, float radius, float height ) 104 { 105 vec3 p = tr.get_position(); 106 quat o = tr.get_orientation(); 107 vec3 dir = o * vec3( 0, 1, 0 ); 108 vec3 ldir = o * vec3( 1, 0, 0 ); 109 vec3 h1dir = o * normalize( vec3( 1, -1, 0 ) ); 110 vec3 h2dir = o * normalize( vec3( 1, 1, 0 ) ); 111 vec3 sp1[12]; 112 vec3 sp2[12]; 113 vec3 hsp1[12]; 114 vec3 hsp2[12]; 115 for ( uint32 i = 0; i < 12; ++i ) 116 { 117 sp1[i] = nv::math::rotate( ldir * radius, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 118 hsp1[i] = nv::math::rotate( h1dir * radius, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 119 } 120 for ( uint32 i = 0; i < 12; ++i ) 121 { 122 sp2[i] = nv::math::rotate( ldir * radius + height * dir, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 123 hsp2[i] = nv::math::rotate( h2dir * radius + height * dir, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 124 } 125 126 for ( uint32 i = 0; i < 12; ++i ) 127 { 128 push_line( p + sp1[i], p + sp1[( i + 1 ) % 12], vec3( 1.0f, 0.0f, 0.0f ) ); 129 push_line( p + sp2[i], p + sp2[( i + 1 ) % 12], vec3( 0.0f, 1.0f, 0.0f ) ); 130 push_line( p + sp1[i], p + sp2[i], vec3( 0.0f, 0.0f, 1.0f ) ); 131 132 push_line( p + hsp1[i], p + sp1[i], vec3( 0.0f, 0.0f, 1.0f ) ); 133 push_line( p + hsp1[i], p + hsp1[( i + 1 ) % 12], vec3( 1.0f, 0.0f, 0.0f ) ); 134 push_line( p + hsp2[i], p + sp2[i], vec3( 0.0f, 0.0f, 1.0f ) ); 135 push_line( p + hsp2[i], p + hsp2[( i + 1 ) % 12], vec3( 0.0f, 1.0f, 0.0f ) ); 136 137 push_line( p + hsp1[i], p - radius * dir, vec3( 0.0f, 0.0f, 1.0f ) ); 138 push_line( p + hsp2[i], p + ( height + radius ) * dir, vec3( 0.0f, 0.0f, 1.0f ) ); 139 140 } 141 142 143 } 144 145 103 146 nv::debug_data::~debug_data() 104 147 { -
trunk/src/gfx/gfx_terminal.cc
r514 r520 84 84 fgcolor = fg.get_argb32(); 85 85 bgcolor = bg.get_argb32(); 86 gylph = uint32( ch ); 87 NV_LOG_INFO( uint32( 88 ( fgcolor & uint32( 0x00FF0000 ) ) >> 16 ), "-", uint32( ( fgcolor & uint32( 0x0000FF00 ) ) >> 8 ),"-" , uint32( fgcolor & uint32( 0x000000FF ) ) ); 86 gylph = uint32( uint8(ch) ); 89 87 } 90 88 }; … … 139 137 m_dc.p = m_context->create_program( nv_gfx_terminal_vs, nv_gfx_terminal_fs ); 140 138 141 m_data->buffer = m_context->create_buffer( nv::UNIFORM_BUFFER, nv:: DYNAMIC_DRAW, tsize.x * tsize.y * sizeof( gfx_terminal_uniform_block ), m_data->data );139 m_data->buffer = m_context->create_buffer( nv::UNIFORM_BUFFER, nv::STREAM_DRAW, tsize.x * tsize.y * sizeof( gfx_terminal_uniform_block ), m_data->data ); 142 140 m_context->bind( m_data->buffer, 7 ); 143 141 m_context->get_device()->set_opt_uniform( m_dc.p, "term_size", vec2( tsize ) ); … … 151 149 void gfx_terminal::update() 152 150 { 153 m_context->bind( m_data->buffer, 7 ); 154 m_context->update( m_data->buffer, m_data->data, 0, m_data->size.x * m_data->size.y * sizeof( gfx_terminal_uniform_block ) ); 155 m_update_needed = false; 151 if ( m_update_needed ) 152 { 153 m_context->bind( m_data->buffer, 7 ); 154 m_context->update( m_data->buffer, m_data->data, 0, m_data->size.x * m_data->size.y * sizeof( gfx_terminal_uniform_block ) ); 155 m_update_needed = false; 156 } 156 157 } 157 158 -
trunk/src/gfx/mesh_creator.cc
r503 r520 87 87 } 88 88 89 90 nv::aabb nv::mesh_data_creator::calculate_aabb() 91 { 92 NV_ASSERT_ALWAYS( m_pos_channel, "No position channel found!" ); 93 vec3 minv; 94 vec3 maxv; 95 96 if ( m_pos_channel->size() > 0 ) 97 { 98 minv = *reinterpret_cast<const vec3*>( m_pos_channel->raw_data() + m_pos_offset ); 99 maxv = minv; 100 } 101 102 for ( uint32 c = 0; c < m_pos_channel->size(); ++c ) 103 { 104 vec3 v = *reinterpret_cast<const vec3*>( m_pos_channel->raw_data() + c*m_pos_channel->element_size() + m_pos_offset ); 105 minv = nv::math::min( minv, v ); 106 maxv = nv::math::max( maxv, v ); 107 } 108 vec3 extents = maxv - minv; 109 vec3 hextents = extents * 0.5f; 110 vec3 halfv = minv + hextents; 111 return aabb( nv::transform( halfv ), hextents ); 112 } 89 113 90 114 void nv::mesh_data_creator::transform( const vec3& pos, const mat3& r33, float scale /*= 1.0f */ ) -
trunk/src/gfx/skeleton_instance.cc
r486 r520 182 182 } 183 183 184 void nv::skeleton_transforms::delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent, const array_view< bool >& mask ) 185 { 186 transform global_mat = parent; 187 bool b = mask[id]; 188 if ( !b ) 189 global_mat = m_transforms[id]; 190 else 191 { 192 global_mat *= m_transforms[id]; 193 m_transforms[id] = global_mat; 194 } 195 for ( auto child : node_data.children( id ) ) 196 { 197 delocalize_rec( node_data, child, global_mat, mask ); 198 } 199 } 200 -
trunk/src/gl/gl_context.cc
r515 r520 125 125 } 126 126 } 127 128 nv::image_data* nv::gl_context::dump_image( image_format f, image_data* reuse ) 129 { 130 NV_ASSERT_ALWAYS( f.type == nv::UBYTE, "Bad format passed to dump" ); 131 NV_ASSERT_ALWAYS( f.format == nv::RGB || f.format == nv::RGBA, "Bad format passed to dump" ); 132 glPixelStorei( GL_PACK_ALIGNMENT, 1 ); 133 image_data* result = reuse; 134 if ( !result ) result = new image_data( f, ivec2( m_viewport.z, m_viewport.w ) ); 135 glReadPixels( 0, 0, m_viewport.z, m_viewport.w, f.format == nv::RGB ? GL_RGB : GL_RGBA, datatype_to_gl_enum( f.type ), const_cast< uint8* >( result->get_data() ) ); 136 return result; 137 } 138 127 139 128 140 const framebuffer_info* nv::gl_context::get_framebuffer_info( framebuffer f ) const -
trunk/src/gui/gui_ascii_renderer.cc
r514 r520 98 98 m_terminal->print( abs.ll(), er->border_color, term_color(), er->border_chars[6] ); 99 99 m_terminal->print( abs.lr, er->border_color, term_color(), er->border_chars[7] ); 100 m_terminal->update();100 //m_terminal->update(); 101 101 } 102 102 if ( !e->m_text.empty() ) -
trunk/src/gui/gui_environment.cc
r492 r520 183 183 handle h = get_element( position( ev.mbutton.x, ev.mbutton.y ) ); 184 184 element* e = m_elements.get( h ); 185 if (e) 185 186 if ( e->m_on_click ) e->m_on_click(); 186 187 -
trunk/src/image/miniz.cc
r487 r520 2668 2668 return tinfl_decompress_mem_to_heap( source_buf, source_buf_len, out_len, parse_header ? TINFL_FLAG_PARSE_ZLIB_HEADER : 0 ); 2669 2669 } 2670 2671 int nv::miniz_compress( unsigned char *pDest, unsigned long *pDest_len, const unsigned char *pSource, unsigned long source_len, int level ) 2672 { 2673 NV_PROFILE( "compress" ); 2674 return mz_compress2( pDest, pDest_len, pSource, source_len, level ); 2675 } 2676 2677 unsigned long nv::miniz_bound( unsigned long source_len ) 2678 { 2679 return mz_compressBound( source_len ); 2680 } -
trunk/src/lib/gl.cc
r501 r520 189 189 190 190 191 HWND hWndFake = CreateWindow (TEXT("Dummy67789"), "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN,191 HWND hWndFake = CreateWindowA("Dummy67789", "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN, 192 192 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, 193 193 NULL, GetModuleHandle(nullptr), NULL); … … 213 213 wgl_makecurrent(hDC, hRCFake); 214 214 215 LoadLibrary ( "gdi32.dll" );215 LoadLibraryA( "gdi32.dll" ); 216 216 bool gl_loaded = nv::load_gl_library( path ); 217 217 bool wgl_loaded = nv::load_wgl_library( path ); -
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.