Changeset 518 for trunk/src


Ignore:
Timestamp:
08/24/16 21:37:04 (9 years ago)
Author:
epyon
Message:
  • refactoring of the particle_engine
  • particle_manager added
  • cleanups
Location:
trunk/src/engine
Files:
1 added
3 edited

Legend:

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

    r512 r518  
    2121        m_gpu_materials = register_resource_handler< gpu_material >( new gpu_material_manager( context, m_materials, m_images ) );
    2222        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 );
    2324}
    2425
     
    2627{
    2728        m_lua = lua;
     29
     30        particle_engine::register_types( const_cast< type_database* >( lua->get_type_data()->get_type_database() ) );
    2831
    2932        int below_already_registered;
     
    7073        m_animators->initialize( lua );
    7174        m_models->initialize( lua );
     75        m_particles->initialize( lua );
    7276}
    7377
  • trunk/src/engine/particle_engine.cc

    r515 r518  
    1313#include <nv/core/logging.hh>
    1414
    15 static const char *nv_particle_engine_vertex_shader_world =
    16         "#version 120\n"
    17         "attribute vec3 nv_position;\n"
    18         "attribute vec2 nv_texcoord;\n"
    19         "attribute vec4 nv_color;\n"
    20         "varying vec4 v_color;\n"
    21         "varying vec2 v_texcoord;\n"
    22         "varying vec3 v_position;\n"
    23         "uniform mat4 nv_m_view;\n"
    24         "uniform mat4 nv_m_projection;\n"
    25         "void main(void)\n"
    26         "{\n"
    27         "       v_position    = nv_position;\n"
    28         "       v_texcoord    = nv_texcoord;\n"
    29         "       v_color       = nv_color;\n"
    30         "       gl_Position   = nv_m_projection * nv_m_view * vec4 (nv_position, 1.0);\n"
    31         "}\n";
    32 static const char *nv_particle_engine_vertex_shader_local =
    33         "#version 120\n"
    34         "attribute vec3 nv_position;\n"
    35         "attribute vec2 nv_texcoord;\n"
    36         "attribute vec4 nv_color;\n"
    37         "varying vec4 v_color;\n"
    38         "varying vec2 v_texcoord;\n"
    39         "varying vec3 v_position;\n"
    40         "uniform mat4 nv_m_mvp;\n"
    41         "void main(void)\n"
    42         "{\n"
    43         "       v_position    = nv_position;\n"
    44         "       v_texcoord    = nv_texcoord;\n"
    45         "       v_color       = nv_color;\n"
    46         "       gl_Position   = nv_m_mvp * vec4 (nv_position, 1.0);\n"
    47         "}\n";
    48 static const char *nv_particle_engine_fragment_shader =
    49         "#version 120\n"
    50         "uniform sampler2D nv_t_diffuse;\n"
    51         "varying vec4 v_color;\n"
    52         "varying vec2 v_texcoord;\n"
    53         "varying vec3 v_position;\n"
    54         "void main(void)\n"
    55         "{\n"
    56         "       vec4 tex_color = texture2D( nv_t_diffuse, v_texcoord );\n"
    57         "       float edge = smoothstep( 0.0, 0.1, v_position.y );\n"
    58         "       gl_FragColor   = v_color * tex_color * edge;\n"
    59         "}\n";
     15nv::hash_store< nv::shash64, nv::particle_emitter_func >   nv::particle_engine::m_emitters;
     16nv::hash_store< nv::shash64, nv::particle_affector_funcs > nv::particle_engine::m_affectors;
     17
     18nv::hash_map< nv::particle_emitter_func,  nv::const_string >* nv::particle_engine::m_debug_emitter_names  = nullptr;
     19nv::hash_map< nv::particle_affector_func, nv::const_string >* nv::particle_engine::m_debug_affector_names = nullptr;
     20nv::hash_map< nv::particle_affector_func, nv::type_entry* >*  nv::particle_engine::m_debug_affector_types = nullptr;
    6021
    6122using namespace nv;
    6223
    63 static void nv_particle_emmiter_point( const particle_emmiter_data*, particle* p, uint32 count )
     24static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count )
    6425{
    6526        for ( uint32 i = 0; i < count; ++i )
     
    6728                p[i].position = vec3();
    6829        }
    69 
    70 }
    71 
    72 static void nv_particle_emmiter_box( const particle_emmiter_data* pe, particle* p, uint32 count )
     30}
     31
     32static void nv_particle_emitter_box( const particle_emitter_data* pe, particle* p, uint32 count )
    7333{
    7434        random& r = random::get();
     
    8242}
    8343
    84 static void nv_particle_emmiter_cylinder( const particle_emmiter_data* pe, particle* p, uint32 count )
     44static void nv_particle_emitter_cylinder( const particle_emitter_data* pe, particle* p, uint32 count )
    8545{
    8646        random& r = random::get();
     
    9555}
    9656
    97 static void nv_particle_emmiter_sphere( const particle_emmiter_data* pe, particle* p, uint32 count )
     57static void nv_particle_emitter_sphere( const particle_emitter_data* pe, particle* p, uint32 count )
    9858{
    9959        random& r = random::get();
     
    10868}
    10969
    110 static void nv_particle_emmiter_cylindroid( const particle_emmiter_data* pe, particle* p, uint32 count )
     70static void nv_particle_emitter_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count )
    11171{
    11272        random& r = random::get();
     
    12181}
    12282
    123 static void nv_particle_emmiter_ellipsoid( const particle_emmiter_data* pe, particle* p, uint32 count )
     83static void nv_particle_emitter_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count )
    12484{
    12585        random& r = random::get();
     
    13494}
    13595
    136 static void nv_particle_emmiter_hollow_cylinder( const particle_emmiter_data* pe, particle* p, uint32 count )
     96static void nv_particle_emitter_hollow_cylinder( const particle_emitter_data* pe, particle* p, uint32 count )
    13797{
    13898        random& r = random::get();
     
    150110}
    151111
    152 static void nv_particle_emmiter_hollow_sphere( const particle_emmiter_data* pe, particle* p, uint32 count )
     112static void nv_particle_emitter_hollow_sphere( const particle_emitter_data* pe, particle* p, uint32 count )
    153113{
    154114        random& r = random::get();
     
    163123}
    164124
    165 static void nv_particle_emmiter_hollow_cylindroid( const particle_emmiter_data* pe, particle* p, uint32 count )
     125static void nv_particle_emitter_hollow_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count )
    166126{
    167127        random& r = random::get();
     
    179139}
    180140
    181 static void nv_particle_emmiter_hollow_ellipsoid( const particle_emmiter_data* pe, particle* p, uint32 count )
     141static void nv_particle_emitter_hollow_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count )
    182142{
    183143        random& r = random::get();
     
    306266}
    307267
    308 void nv::particle_engine::load( lua::table_guard& table )
    309 {
    310         shash64 id = table.get_string_hash_64( "id" );
    311         if ( !id )
    312         {
    313                 NV_LOG_ERROR( "Bad table passed to particle_engine!" )
    314         }
    315         // TODO : overwrite check
    316         m_names[ id ] = m_data.size();
    317 
    318         m_data.emplace_back();
    319         auto& data = m_data.back();
    320 
    321         data.quota   = table.get<uint32>("quota", 1024 );
    322 //      data.local   = table.get<bool>("local_space", false );
    323         data.accurate_facing = table.get<bool>("accurate_facing", false );
    324         data.emmiter_count   = 0;
    325         data.affector_count  = 0;
    326 
    327         const_string orientation = table.get_string( "orientation", "point" );
    328         if ( orientation == "point" )                     { data.orientation = particle_orientation::POINT; }
    329         else if ( orientation == "oriented" )             { data.orientation = particle_orientation::ORIENTED; }
    330         else if ( orientation == "oriented_common" )      { data.orientation = particle_orientation::ORIENTED_COMMON; }
    331         else if ( orientation == "perpendicular" )        { data.orientation = particle_orientation::PERPENDICULAR; }
    332         else if ( orientation == "perpendicular_common" ) { data.orientation = particle_orientation::PERPENDICULAR_COMMON; }
    333         else
    334         {
    335                 NV_LOG_ERROR( "Unknown orientation type! (", orientation, ")!" );
    336                 data.orientation = particle_orientation::POINT;
    337         }
    338 
    339         const_string origin = table.get_string( "origin", "center" );
    340         if      ( origin == "center" )        { data.origin = particle_origin::CENTER; }
    341         else if ( origin == "top_left" )      { data.origin = particle_origin::TOP_LEFT; }
    342         else if ( origin == "top_center" )    { data.origin = particle_origin::TOP_CENTER; }
    343         else if ( origin == "top_right" )     { data.origin = particle_origin::TOP_RIGHT; }
    344         else if ( origin == "center_left" )   { data.origin = particle_origin::CENTER_LEFT; }
    345         else if ( origin == "center_right" )  { data.origin = particle_origin::CENTER_RIGHT; }
    346         else if ( origin == "bottom_left" )   { data.origin = particle_origin::BOTTOM_LEFT; }
    347         else if ( origin == "bottom_center" ) { data.origin = particle_origin::BOTTOM_CENTER; }
    348         else if ( origin == "bottom_right" )  { data.origin = particle_origin::BOTTOM_RIGHT; }
    349         else
    350         {
    351                 NV_LOG_ERROR( "Unknown particle origin! (", origin, ")!" );
    352                 data.origin = particle_origin::CENTER;
    353         }
    354 
    355         data.common_up  = math::normalize( table.get<vec3>("common_up",  vec3(1,0,0) ) );
    356         data.common_dir = math::normalize( table.get<vec3>("common_dir", vec3(0,1,0) ) );
    357 
    358         vec2 def_size        = table.get<vec2>("size", vec2(0.1,0.1) );
    359         uint32 elements = table.get_size();
    360         for ( uint32 i = 0; i < elements; ++i )
    361         {
    362                 lua::table_guard element( table, i+1 );
    363                 const_string type     = element.get_string( "type" );
    364                 const_string sub_type = element.get_string( "sub_type" );
    365                 if ( type == "emmiter" )
    366                 {
    367                         if ( data.emmiter_count < MAX_PARTICLE_EMMITERS )
    368                         {
    369                                 particle_emmiter_data& edata = data.emmiters[ data.emmiter_count ];
    370                                 auto emmiter_iter = m_emmiters.find( sub_type );
    371                                 if ( emmiter_iter != m_emmiters.end() )
    372                                 {
    373                                         edata.emmiter_func = emmiter_iter->second;
    374                                 }
    375                                 else
    376                                 {
    377                                         edata.emmiter_func = nv_particle_emmiter_point;
    378                                         NV_LOG_WARNING( "Unknown emmiter type in particle system! (", sub_type, ")" );
    379                                 }
    380 
    381                                 edata.position     = element.get<vec3>("position", vec3() );
    382                                 edata.extents      = element.get<vec3>("extents", vec3(1,1,1) );
    383                                 edata.extents[0]   = element.get<float>("width",  edata.extents[0] );
    384                                 edata.extents[1]   = element.get<float>("depth",  edata.extents[1] );
    385                                 edata.extents[2]   = element.get<float>("height", edata.extents[2] );
    386                                 edata.extents[0]   = element.get<float>("radius",  edata.extents[0] );
    387                                 edata.iextents     = element.get<vec3>("inner_extents", vec3() );
    388                                 edata.iextents[0]  = element.get<float>("inner_width",  edata.iextents[0] );
    389                                 edata.iextents[1]  = element.get<float>("inner_depth",  edata.iextents[1] );
    390                                 edata.iextents[2]  = element.get<float>("inner_height", edata.iextents[2] );
    391                                 edata.iextents[0]  = element.get<float>("inner_radius",  edata.iextents[0] );
    392                                 edata.hextents     = 0.5f * edata.extents;
    393                                 edata.ihextents    = 0.5f * edata.iextents;
    394                                 edata.precise      = element.get<bool>("precise", false );
    395                                 edata.square       = element.get<bool>("square", true );
    396                                 vec4 color         = element.get<vec4>("color", vec4(1,1,1,1) );
    397                                 edata.color_min    = element.get<vec4>("color_min", color );
    398                                 edata.color_max    = element.get<vec4>("color_max", color );
    399                                 vec2 size          = element.get<vec2>("size", def_size );
    400                                 edata.size_min     = element.get<vec2>("size_min", size );
    401                                 edata.size_max     = element.get<vec2>("size_max", size );
    402                                 edata.angle        = element.get<float>("angle", 0.0f );
    403                                 float velocity     = element.get<float>("velocity", 0.0f );
    404                                 edata.velocity_min = element.get<float>("velocity_min", velocity );
    405                                 edata.velocity_max = element.get<float>("velocity_max", velocity );
    406                                 float lifetime     = element.get<float>("lifetime", 1.0f );
    407                                 edata.lifetime_min = element.get<float>("lifetime_min", lifetime );
    408                                 edata.lifetime_max = element.get<float>("lifetime_max", lifetime );
    409                                 float duration     = element.get<float>("duration", 0.0f );
    410                                 edata.duration_min = element.get<float>("duration_min", duration );
    411                                 edata.duration_max = element.get<float>("duration_max", duration );
    412                                 float repeat       = element.get<float>("repeat_delay", 0.0f );
    413                                 edata.repeat_min   = element.get<float>("repeat_delay_min", repeat );
    414                                 edata.repeat_max   = element.get<float>("repeat_delay_max", repeat );
    415 
    416                                 edata.rate         = element.get<float>("rate", 1.0f );
    417                                 edata.dir          = math::normalize( element.get<vec3>("direction", vec3(0,1,0) ) );
    418                                
    419                                 edata.odir = vec3( 0, 0, 1 );
    420                                 if ( edata.dir != vec3( 0, 1, 0 ) && edata.dir != vec3( 0, -1, 0 ) )
    421                                         edata.odir = math::normalize( math::cross( edata.dir, vec3( 0, 1, 0 ) ) );
    422                                 edata.cdir = math::cross( edata.dir, edata.odir );
    423 
    424                                 data.emmiter_count++;
    425                         }
    426                         else
    427                         {
    428                                 NV_LOG_ERROR( "Too many emmiters (", MAX_PARTICLE_EMMITERS, " is MAX)!" );
    429                         }
    430                 }
    431                 else if ( type == "affector" )
    432                 {
    433                         if ( data.affector_count < MAX_PARTICLE_AFFECTORS )
    434                         {
    435                                 particle_affector_data& adata = data.affectors[ data.affector_count ];
    436                                 data.affector_count++;
    437                                 auto affector_iter = m_affectors.find( sub_type );
    438                                 if ( affector_iter != m_affectors.end() )
    439                                 {
    440                                         adata.process = affector_iter->second.process;
    441                                         if ( !affector_iter->second.init( &element, &adata ) )
    442                                         {
    443                                                 data.affector_count--;
    444                                                 NV_LOG_WARNING( "Bad data passed to ", sub_type, " affector in particle system!" );
    445                                         }
    446                                 }
    447                                 else
    448                                 {
    449                                         data.affector_count--;
    450                                         NV_LOG_WARNING( "Unknown affector type in particle system! (", sub_type, ")" );
    451                                 }
    452                         }
    453                         else
    454                         {
    455                                 NV_LOG_ERROR( "Too many affectors (", MAX_PARTICLE_AFFECTORS, " is MAX)!" );
    456                         }
    457                 }
    458                 else
    459                 {
    460                         NV_LOG_WARNING( "Unknown element in particle system! (", type, ")" );
    461                 }
    462         }
    463 
    464 }
    465 
    466 nv::particle_engine::particle_engine( context* a_context )
     268nv::particle_engine::particle_engine( context* a_context, bool debug_data )
    467269{
    468270        m_context       = a_context;
    469         m_program_local = m_context->create_program( nv_particle_engine_vertex_shader_local, nv_particle_engine_fragment_shader );
    470         m_program_world = m_context->create_program( nv_particle_engine_vertex_shader_world, nv_particle_engine_fragment_shader );
    471 
    472         register_standard_emmiters();
     271        if ( debug_data )
     272        {
     273                m_debug_emitter_names  = new nv::hash_map< nv::particle_emitter_func,  nv::const_string >;
     274                m_debug_affector_names = new nv::hash_map< nv::particle_affector_func, nv::const_string >;
     275                m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >;
     276        }
     277
     278        register_standard_emitters();
    473279        register_standard_affectors();
    474280}
    475281
    476 nv::particle_system nv::particle_engine::create_system( const string_view& id, particle_system_group group )
     282nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_system_group group )
    477283{
    478284        particle_system_group_info* ginfo = m_groups.get( group );
    479285        if ( !ginfo ) return nv::particle_system();
    480286
    481         auto it = m_names.find( id );
    482         if ( it == m_names.end() )
    483         {
    484                 return particle_system();
    485         }
    486         const particle_system_data* data = &(m_data[it->second]);
    487287        particle_system result = m_systems.create();
    488288        particle_system_info* info = m_systems.get( result );
    489289        info->group = group;
    490         info->data     = data;
    491         uint32 ecount = data->emmiter_count;
     290        info->data = data;
     291        uint32 ecount = data->emitter_count;
    492292        for ( uint32 i = 0; i < ecount; ++i )
    493293        {
    494                 info->emmiters[i].active      = true;
    495                 if ( data->emmiters[i].duration_max == 0.0f )
    496                         info->emmiters[i].pause = 0;
     294                info->emitters[i].active = true;
     295                if ( data->emitters[i].duration_max == 0.0f )
     296                        info->emitters[i].pause = 0;
    497297                else
    498                         info->emmiters[i].pause = random::get().frange( data->emmiters[i].duration_min, data->emmiters[i].duration_max );
     298                        info->emitters[i].pause = random::get().frange( data->emitters[i].duration_min, data->emitters[i].duration_max );
    499299
    500300        }
    501301
    502302        info->count = 0;
    503         info->particles = new particle[ data->quota ];
     303        info->particles = new particle[data->quota];
    504304        ginfo->ref_counter++;
    505305
    506306        return result;
     307}
     308
     309nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_system_group group )
     310{
     311        if ( auto data = rdata.lock() )
     312                return create_system( &*data, group );
     313        return {};
    507314}
    508315
     
    513320        {
    514321                info->count = 0;
    515         }
    516 }
    517 
    518 void nv::particle_engine::draw( particle_system_group group, const render_state& rs, const scene_state& ss )
    519 {
    520         particle_system_group_info* info = m_groups.get( group );
    521         if ( info )
    522         {
    523                 m_context->draw( nv::TRIANGLES, rs, ss, info->local ? m_program_local : m_program_world, info->vtx_array, info->count * 6, 0 );
    524322        }
    525323}
     
    544342{
    545343        clear();
    546         m_context->release( m_program_world );
    547         m_context->release( m_program_local );
    548344}
    549345
     
    551347{
    552348        clear();
    553         register_standard_emmiters();
     349        register_standard_emitters( );
    554350        register_standard_affectors();
    555 }
    556 
    557 bool nv::particle_engine::loaded( const string_view& system_id )
    558 {
    559         return m_names.find( system_id ) != m_names.end();
    560351}
    561352
     
    566357        while ( m_groups.size() > 0 )
    567358                release( m_groups.get_handle( 0 ) );
    568         m_emmiters.clear();
     359        m_emitters.clear();
    569360        m_affectors.clear();
    570         m_names.clear();
    571         m_data.clear();
    572361}
    573362
     
    612401//              while ( dtime > 0.2 )
    613402//              {
    614 //                      update_emmiters( info, 0.2 );
     403//                      update_emitters( info, 0.2 );
    615404//                      destroy_particles( info, 0.2 );
    616405//                      create_particles( info, 0.2 );
     
    619408//              }
    620409
    621                 update_emmiters( info, dtime );
     410                update_emitters( info, dtime );
    622411                destroy_particles( info, dtime );
    623412                create_particles( info, model, dtime );
     
    778567void nv::particle_engine::create_particles( particle_system_info* info, transform model, float dtime )
    779568{
    780         uint32 ecount = info->data->emmiter_count;
     569        uint32 ecount = info->data->emitter_count;
    781570        if ( ecount == 0 ) return;
    782571
     
    791580        for ( uint32 i = 0; i < ecount; ++i )
    792581        {
    793                 const auto& edata = info->data->emmiters[i];
    794                 auto& einfo = info->emmiters[i];
     582                const auto& edata = info->data->emitters[i];
     583                auto& einfo = info->emitters[i];
    795584                if ( einfo.active )
    796585                {
     
    802591                                {
    803592                                        particle& pinfo = info->particles[info->count];
    804                                         edata.emmiter_func( &(info->data->emmiters[i]), &pinfo, 1 );
     593                                        edata.emitter_func( &(info->data->emitters[i]), &pinfo, 1 );
    805594                                        pinfo.position = vec3();
    806595                                        pinfo.position+= edata.position;
    807                                         if ( !local )
     596//                                      if ( !local )
    808597                                                pinfo.position = pinfo.position * model;
    809598                                        pinfo.color    = edata.color_min == edata.color_max ?
     
    865654}
    866655
    867 void nv::particle_engine::update_emmiters( particle_system_info* info, float dtime )
    868 {
    869         uint32 ecount = info->data->emmiter_count;
     656void nv::particle_engine::update_emitters( particle_system_info* info, float dtime )
     657{
     658        uint32 ecount = info->data->emitter_count;
    870659        if ( ecount == 0 ) return;
    871660        random& r = random::get();
     
    873662        for ( uint32 i = 0; i < ecount; ++i )
    874663        {
    875                 const auto& edata = info->data->emmiters[i];
    876                 auto& einfo = info->emmiters[i];
     664                const auto& edata = info->data->emitters[i];
     665                auto& einfo = info->emitters[i];
    877666
    878667                if ( einfo.pause > 0.0f )
     
    902691}
    903692
    904 void nv::particle_engine::register_emmiter_type( const string_view& name, particle_emmiter_func func )
    905 {
    906         m_emmiters[ name ] = func;
    907 }
    908 
    909 void nv::particle_engine::register_standard_emmiters()
    910 {
    911         register_emmiter_type( "point",             nv_particle_emmiter_point );
    912         register_emmiter_type( "box",               nv_particle_emmiter_box );
    913         register_emmiter_type( "cylinder",          nv_particle_emmiter_cylinder );
    914         register_emmiter_type( "sphere",            nv_particle_emmiter_sphere );
    915         register_emmiter_type( "cylindroid",        nv_particle_emmiter_cylindroid );
    916         register_emmiter_type( "ellipsoid",         nv_particle_emmiter_ellipsoid );
    917         register_emmiter_type( "hollow_cylinder",   nv_particle_emmiter_hollow_cylinder );
    918         register_emmiter_type( "hollow_sphere",     nv_particle_emmiter_hollow_sphere );
    919         register_emmiter_type( "hollow_cylindroid", nv_particle_emmiter_hollow_cylindroid );
    920         register_emmiter_type( "hollow_ellipsoid",  nv_particle_emmiter_hollow_ellipsoid );
     693void nv::particle_engine::register_emitter_type( const string_view& name, particle_emitter_func func )
     694{
     695        if ( m_debug_emitter_names )
     696                ( *m_debug_emitter_names )[func] = name;
     697        m_emitters[ name ] = func;
     698}
     699
     700void nv::particle_engine::register_standard_emitters()
     701{
     702        register_emitter_type( "point",             nv_particle_emitter_point );
     703        register_emitter_type( "box",               nv_particle_emitter_box );
     704        register_emitter_type( "cylinder",          nv_particle_emitter_cylinder );
     705        register_emitter_type( "sphere",            nv_particle_emitter_sphere );
     706        register_emitter_type( "cylindroid",        nv_particle_emitter_cylindroid );
     707        register_emitter_type( "ellipsoid",         nv_particle_emitter_ellipsoid );
     708        register_emitter_type( "hollow_cylinder",   nv_particle_emitter_hollow_cylinder );
     709        register_emitter_type( "hollow_sphere",     nv_particle_emitter_hollow_sphere );
     710        register_emitter_type( "hollow_cylindroid", nv_particle_emitter_hollow_cylindroid );
     711        register_emitter_type( "hollow_ellipsoid",  nv_particle_emitter_hollow_ellipsoid );
    921712}
    922713
    923714void nv::particle_engine::register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process )
    924715{
     716        if ( m_debug_affector_names )
     717                ( *m_debug_affector_names )[process] = name;
     718
    925719        m_affectors[ name ].init    = init;
    926720        m_affectors[ name ].process = process;
     721}
     722
     723nv::particle_emitter_func nv::particle_engine::get_emitter( shash64 emitter )
     724{
     725        auto emitter_iter = m_emitters.find( emitter );
     726        if ( emitter_iter != m_emitters.end() )
     727        {
     728                return emitter_iter->second;
     729        }
     730        return nullptr;
     731}
     732
     733nv::particle_affector_funcs nv::particle_engine::get_affector( shash64 affector )
     734{
     735        auto affector_iter = m_affectors.find( affector );
     736        if ( affector_iter != m_affectors.end() )
     737        {
     738                return affector_iter->second;
     739        }
     740        return { nullptr, nullptr };
     741}
     742
     743nv::string_view nv::particle_engine::get_debug_name( particle_emitter_func f )
     744{
     745        auto i = m_debug_emitter_names->find( f );
     746        if ( i != m_debug_emitter_names->end() )
     747                return i->second;
     748        return {};
     749}
     750
     751nv::string_view nv::particle_engine::get_debug_name( particle_affector_func f )
     752{
     753        auto i = m_debug_affector_names->find( f );
     754        if ( i != m_debug_affector_names->end() )
     755                return i->second;
     756        return {};
    927757}
    928758
     
    945775}
    946776
     777void nv::particle_engine::register_types( type_database* db )
     778{
     779        db->create_type<nv::particle_orientation>()
     780                .value( "PS_POINT",                sint32( particle_orientation::POINT ),                "Point" )
     781                .value( "PS_ORIENTED",             sint32( particle_orientation::ORIENTED ),             "Oriented" )
     782                .value( "PS_ORIENTED_COMMON",      sint32( particle_orientation::ORIENTED_COMMON ),      "Oriented Common" )
     783                .value( "PS_PERPENDICULAR",        sint32( particle_orientation::PERPENDICULAR ),        "Perpendicular" )
     784                .value( "PS_PERPENDICULAR_COMMON", sint32( particle_orientation::PERPENDICULAR_COMMON ), "Perpendicular Common" )
     785                ;
     786
     787        db->create_type<nv::particle_origin>()
     788                .value( "PS_CENTER",        sint32( particle_origin::CENTER ),        "Center" )
     789                .value( "PS_TOP_LEFT",      sint32( particle_origin::TOP_LEFT ),      "Top left" )
     790                .value( "PS_TOP_CENTER",    sint32( particle_origin::TOP_CENTER ),    "Top center" )
     791                .value( "PS_TOP_RIGHT",     sint32( particle_origin::TOP_RIGHT ),     "Top right" )
     792                .value( "PS_CENTER_LEFT",   sint32( particle_origin::CENTER_LEFT ),   "Center left" )
     793                .value( "PS_CENTER_RIGHT",  sint32( particle_origin::CENTER_RIGHT ),  "Center right" )
     794                .value( "PS_BOTTOM_LEFT",   sint32( particle_origin::BOTTOM_LEFT ),   "Bottom left" )
     795                .value( "PS_BOTTOM_CENTER", sint32( particle_origin::BOTTOM_CENTER ), "Bottom center" )
     796                .value( "PS_BOTTOM_RIGHT",  sint32( particle_origin::BOTTOM_RIGHT ),  "Bottom right" )
     797                ;
     798
     799        if ( m_debug_affector_types )
     800        {
     801                int you_could_get_rid_of_the_init_function_using_these; int error;
     802
     803                (*m_debug_affector_types)[ nv_particle_affector_linear_force ]
     804                        = db->create_type<nvpe_linear_force_data>( "linear force" )
     805                        .field( "force_vector", &nvpe_linear_force_data::force_vector )
     806                        .field( "average",      &nvpe_linear_force_data::average )
     807                        .get();
     808
     809                ( *m_debug_affector_types )[nv_particle_affector_deflector_plane]
     810                        = db->create_type<nvpe_deflector_plane_data>( "deflector plane" )
     811                        .field( "plane_point",  &nvpe_deflector_plane_data::plane_point )
     812                        .field( "plane_normal", &nvpe_deflector_plane_data::plane_normal )
     813                        .field( "bounce",       &nvpe_deflector_plane_data::bounce )
     814                        .field( "distance",     &nvpe_deflector_plane_data::distance )
     815                        .get();
     816
     817                ( *m_debug_affector_types )[nv_particle_affector_color_fader]
     818                        = db->create_type<nvpe_linear_force_data>( "color fader" )
     819                        .field( "adjustment", & nvpe_color_fader_data::adjustment )
     820                        .get();
     821
     822                ( *m_debug_affector_types )[nv_particle_affector_scaler]
     823                        = db->create_type<nvpe_scaler_data>( "scaler" )
     824                        .field( "adjustment", & nvpe_scaler_data::adjustment )
     825                        .get();
     826        }
     827}
  • trunk/src/engine/renderer.cc

    r508 r518  
    121121        m_context->set_viewport( ss.get_viewport() );
    122122
     123
    123124        if ( pass.cstate.buffers != buffer_mask::NO_BUFFER )
    124125                m_context->clear( pass.cstate );
Note: See TracChangeset for help on using the changeset viewer.