Changeset 520 for trunk/src/engine


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/engine
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/engine/default_resource_manager.cc

    r519 r520  
    1111default_resource_manager::default_resource_manager( context* context, bool clear_material_paths )
    1212{
    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 ) );
     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 ) );
    2121        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 ) );
    2425}
    2526
    26 void default_resource_manager::initialize( lua::state* lua )
     27void default_resource_manager::initialize( lua::state* lua, physics_world* world )
    2728{
    2829        m_lua = lua;
     
    7273        m_models->initialize( lua );
    7374        m_particles->initialize( lua );
     75        m_ragdolls->initialize( lua );
     76        m_ragdolls->initialize( world );
    7477}
    7578
  • trunk/src/engine/particle_engine.cc

    r519 r520  
    1 // Copyright (C) 2014-2015 ChaosForge Ltd
     1// Copyright (C) 2014-2016 ChaosForge Ltd
    22// http://chaosforge.org/
    33//
     
    2626using namespace nv;
    2727
    28 static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count )
     28static void nv_particle_emitter_point( random_base*, const particle_emitter_data*, particle* p, uint32 count )
    2929{
    3030        for ( uint32 i = 0; i < count; ++i )
     
    3434}
    3535
    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] );
     36static 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
     47static 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] );
    5452                p[i].position =
    5553                        rellipse.x * pe->cdir +
    56                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     54                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    5755                        rellipse.y * pe->odir;
    5856        }
    5957}
    6058
    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];
     59static 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];
    6764                p[i].position =
    6865                        rsphere.x * pe->cdir +
     
    7269}
    7370
    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 );
     71static 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 );
    8076                p[i].position =
    8177                        rellipse.x * pe->cdir +
    82                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     78                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    8379                        rellipse.y * pe->odir;
    8480        }
    8581}
    8682
    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 );
     83static 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 );
    9388                p[i].position =
    9489                        rsphere.x * pe->cdir +
     
    9893}
    9994
    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(
     95static 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(
    106100                        pe->ihextents[0],
    107101                        pe->hextents[0],
     
    109103                p[i].position =
    110104                        rellipse.x * pe->cdir +
    111                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     105                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    112106                        rellipse.y * pe->odir;
    113107        }
    114108}
    115109
    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 );
     110static 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 );
    122115                p[i].position =
    123116                        rellipse.x * pe->cdir +
     
    127120}
    128121
    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(
     122static 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(
    135127                        vec2( pe->ihextents[0], pe->ihextents[2] ),
    136128                        vec2( pe->hextents[0], pe->hextents[2] ),
     
    138130                p[i].position =
    139131                        rellipse.x * pe->cdir +
    140                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     132                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    141133                        rellipse.y * pe->odir;
    142134        }
    143135}
    144136
    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 );
     137static 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 );
    151142                p[i].position =
    152143                        rellipse.x * pe->cdir +
     
    278269}
    279270
    280 nv::particle_engine::particle_engine( context* a_context, bool debug_data )
    281 {
    282         m_context       = a_context;
     271nv::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
    283279        if ( debug_data )
    284280        {
    285281                m_debug_emitter_names  = new nv::hash_map< nv::particle_emitter_func,  nv::const_string >;
    286282                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* >;
    288283                m_debug_emitter_list   = new nv::vector< nv::particle_emitter_func >;
    289284                m_debug_affector_list  = new nv::vector< nv::particle_affector_func >;
     
    294289}
    295290
    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 
     291nv::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       
    301296        particle_system result = m_systems.create();
    302297        particle_system_info* info = m_systems.get( result );
     
    310305                        info->emitters[i].pause = 0;
    311306                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 );
    313308
    314309        }
     
    316311        info->count = 0;
    317312        info->particles = new particle[data->quota];
    318         ginfo->ref_counter++;
    319313
    320314        return result;
    321315}
    322316
    323 nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_system_group group )
     317nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_group group )
    324318{
    325319        if ( auto data = rdata.lock() )
     
    328322}
    329323
    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;
     324void nv::particle_engine::prepare( particle_group group )
     325{
     326        m_pgm->prepare( group );
     327}
     328
     329nv::particle_group nv::particle_engine::create_group( uint32 max_particles )
     330{
     331        return m_pgm->create_group( max_particles );
    353332}
    354333
     
    369348        while ( m_systems.size() > 0 )
    370349                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();
    373352        m_emitters.clear();
    374353        m_affectors.clear();
     
    381360        if ( info )
    382361        {
    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;
    386364                m_systems.destroy( system );
    387365        }
    388366}
    389367
    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         }
     368void nv::particle_engine::release( particle_group group )
     369{
     370        m_pgm->release( group );
    399371}
    400372
     
    403375        particle_system_info* info = m_systems.get( system );
    404376        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 );
    408378}
    409379
     
    440410                info->texcoords[1] = b;
    441411        }
    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_b
    533                 };
    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;
    564412}
    565413
     
    584432        if ( ecount == 0 ) return;
    585433
    586         random& r = random::get();
    587434        bool local = model.is_identity();
    588435//      if ( !local )
     
    605452                                {
    606453                                        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 );
    608455                                        pinfo.position = vec3();
    609456                                        pinfo.position+= edata.position;
     
    611458                                                pinfo.position = pinfo.position * model;
    612459                                        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 );
    614461                                        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 );
    616463                                        if ( edata.square ) pinfo.size.y = pinfo.size.x;
    617464                                        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 );
    619466                                        pinfo.lifetime = dtime + einfo.next;
    620467                                        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>() );
    623470                                        pinfo.tcoord_a = info->texcoords[0];
    624471                                        pinfo.tcoord_b = info->texcoords[1];
     
    628475                                        {
    629476                                                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 );
    631478                                                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>() );
    633480                                                pinfo.velocity  = model.get_orientation() *
    634481                                                        ( edata.odir * ( cos(phi) * sin_theta ) +
     
    672519        uint32 ecount = info->data->emitter_count;
    673520        if ( ecount == 0 ) return;
    674         random& r = random::get();
    675521
    676522        for ( uint32 i = 0; i < ecount; ++i )
     
    691537                                einfo.active = false;
    692538                                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 );
    694540                                else
    695541                                        einfo.pause = 0.0f;
     
    698544                        {
    699545                                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 );
    701547                        }
    702548                }
     
    776622}
    777623
    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() };
     624nv::particle_render_data nv::particle_engine::get_render_data( particle_group group )
     625{
     626        return m_pgm->get_render_data( group );
    786627}
    787628
     
    794635}
    795636
    796 void nv::particle_engine::register_types( type_database* db )
     637const 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
     648void nv::particle_engine::register_types( type_database* db, bool debug_data )
    797649{
    798650        db->create_type<particle_orientation>()
     
    816668                ;
    817669
    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
    820675                int you_could_get_rid_of_the_init_function_using_these; int error;
    821676                int universal_vm_based_affector;
     
    849704        }
    850705}
     706
  • trunk/src/engine/particle_manager.cc

    r518 r520  
    6161        data->emitter_count   = 0;
    6262        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  ) );
    9165
    9266        data->common_up  = math::normalize( table.get<vec3>("common_up",  vec3(1,0,0) ) );
Note: See TracChangeset for help on using the changeset viewer.