- Timestamp:
- 08/24/16 21:37:04 (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/types.hh
r511 r518 126 126 127 127 type_creator value( const string_view& aname, sint32 value, const string_view& desc = string_view() ); 128 129 type_entry* get() { return m_entry; } 128 130 private: 129 131 type_database* m_database; … … 148 150 type_entry* i_type = new type_entry; 149 151 i_type->type_db = this; 150 i_type->hash = thash64 ::create< TYPE >();152 i_type->hash = thash64( shash64( name ).value() ); 151 153 i_type->name = m_names.insert( name ); 152 154 i_type->size = sizeof( TYPE ); -
trunk/nv/engine/default_resource_manager.hh
r512 r518 25 25 #include <nv/engine/material_manager.hh> 26 26 #include <nv/engine/model_manager.hh> 27 #include <nv/engine/particle_manager.hh> 27 28 28 29 namespace nv … … 71 72 mesh_data_manager* m_mesh_datas; 72 73 model_manager* m_models; 74 particle_manager* m_particles; 73 75 }; 74 76 -
trunk/nv/engine/particle_engine.hh
r515 r518 15 15 #include <nv/lua/lua_state.hh> 16 16 #include <nv/gfx/texture_atlas.hh> 17 #include <nv/core/resource.hh> 17 18 #include <nv/interface/scene_node.hh> 18 19 #include <nv/interface/context.hh> … … 20 21 namespace nv 21 22 { 22 static const unsigned MAX_PARTICLE_EMMITERS = 8; 23 24 static const unsigned MAX_PARTICLE_EMITTERS = 8; 23 25 static const unsigned MAX_PARTICLE_AFFECTORS = 8; 24 26 25 struct particle_em miter_data;27 struct particle_emitter_data; 26 28 struct particle_affector_data; 27 29 struct particle; 28 30 29 typedef void (*particle_emmiter_func)( const particle_emmiter_data*, particle*, uint32 count );30 typedef void (*particle_affector_func)( const particle_affector_data*, particle*, float factor, uint32 count );31 typedef bool (*particle_affector_init_func)( lua::table_guard* table, particle_affector_data* data );31 typedef void( *particle_emitter_func )( const particle_emitter_data*, particle*, uint32 count ); 32 typedef void( *particle_affector_func )( const particle_affector_data*, particle*, float factor, uint32 count ); 33 typedef bool( *particle_affector_init_func )( lua::table_guard* table, particle_affector_data* data ); 32 34 33 35 struct particle_affector_funcs … … 86 88 { 87 89 particle_affector_func process; 88 uint8 paramters[4 *8*16];89 }; 90 91 struct particle_em miter_data92 { 93 particle_em miter_func emmiter_func;90 uint8 paramters[4 * 8 * 16]; 91 }; 92 93 struct particle_emitter_data 94 { 95 particle_emitter_func emitter_func; 94 96 vec3 position; 95 97 vec3 extents; … … 118 120 }; 119 121 120 struct particle_em miter_info122 struct particle_emitter_info 121 123 { 122 124 bool active; … … 128 130 { 129 131 uint32 quota; 130 // bool local;131 132 vec3 common_up; 132 133 vec3 common_dir; … … 134 135 particle_orientation orientation; 135 136 particle_origin origin; 136 uint32 em miter_count;137 particle_em miter_data emmiters[MAX_PARTICLE_EMMITERS];137 uint32 emitter_count; 138 particle_emitter_data emitters[MAX_PARTICLE_EMITTERS]; 138 139 uint32 affector_count; 139 particle_affector_data affectors[MAX_PARTICLE_AFFECTORS]; 140 particle_affector_data affectors[MAX_PARTICLE_AFFECTORS]; 140 141 }; 141 142 … … 148 149 { 149 150 particle* particles; 150 particle_em miter_info emmiters[MAX_PARTICLE_EMMITERS];151 particle_emitter_info emitters[MAX_PARTICLE_EMITTERS]; 151 152 152 153 uint32 count; … … 174 175 }; 175 176 177 } 178 179 NV_RTTI_DECLARE_NAME( nv::particle_system_data, "particle_system_data" ) 180 NV_RTTI_DECLARE_NAME( nv::particle_orientation, "particle_orientation" ) 181 NV_RTTI_DECLARE_NAME( nv::particle_origin, "particle_origin" ) 182 183 namespace nv { 184 176 185 class particle_engine 177 186 { 178 187 public: 179 particle_engine( context* a_context );188 particle_engine( context* a_context, bool debug_data = false ); 180 189 void reset(); 181 bool loaded( const string_view& system_id );182 void load( lua::table_guard& table );183 void draw( particle_system_group group, const render_state& rs, const scene_state& ss );184 190 void prepare( particle_system_group group ); 185 191 particle_system_group create_group( uint32 max_particles ); 186 particle_system create_system( const string_view& id, particle_system_group group ); 192 particle_system create_system( resource< particle_system_data > rdata, particle_system_group group ); 193 particle_system create_system( const particle_system_data* data, particle_system_group group ); 187 194 void release( particle_system_group group ); 188 195 void release( particle_system system ); … … 190 197 void render( particle_system system, const scene_state& s ); 191 198 void set_texcoords( particle_system system, vec2 a, vec2 b ); 192 void register_emmiter_type( const string_view& name, particle_emmiter_func func ); 193 void register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process ); 199 static void register_emitter_type( const string_view& name, particle_emitter_func func ); 200 static void register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process ); 201 static particle_emitter_func get_emitter( shash64 emitter ); 202 static particle_affector_funcs get_affector( shash64 affector ); 203 static string_view get_debug_name( particle_emitter_func f ); 204 static string_view get_debug_name( particle_affector_func f ); 205 static const type_entry* get_debug_type( particle_affector_init_func f ); 206 static void register_types( type_database* db ); 194 207 particle_render_data get_render_data( particle_system_group group ); 195 208 ~particle_engine(); 196 209 private: 197 210 void clear(); 198 void register_standard_em miters();211 void register_standard_emitters(); 199 212 void register_standard_affectors(); 200 213 void generate_data( particle_system_info* info, const scene_state& s ); … … 202 215 void create_particles( particle_system_info* info, transform tr, float dtime ); 203 216 void update_particles( particle_system_info* info, float dtime ); 204 void update_em miters( particle_system_info* info, float dtime );217 void update_emitters( particle_system_info* info, float dtime ); 205 218 206 219 context* m_context; 207 208 program m_program_local;209 program m_program_world;210 220 211 221 handle_store< particle_system_info, particle_system > m_systems; 212 222 handle_store< particle_system_group_info, particle_system_group > m_groups; 213 223 214 hash_store< shash64, uint32 > m_names; 215 vector< particle_system_data > m_data; 216 hash_store< shash64, particle_emmiter_func > m_emmiters; 217 hash_store< shash64, particle_affector_funcs > m_affectors; 224 static hash_store< shash64, particle_emitter_func > m_emitters; 225 static hash_store< shash64, particle_affector_funcs > m_affectors; 226 227 static hash_map< particle_emitter_func, const_string >* m_debug_emitter_names; 228 static hash_map< particle_affector_func, const_string >* m_debug_affector_names; 229 static hash_map< particle_affector_func, type_entry* >* m_debug_affector_types; 230 218 231 }; 219 232 -
trunk/nv/engine/resource_system.hh
r509 r518 53 53 public: 54 54 lua_resource_manager_base( resource_type_id id ) : resource_handler( id ), m_lua( nullptr ) {} 55 v oid initialize( lua::state* state );55 virtual void initialize( lua::state* state ); 56 56 virtual string_view get_storage_name() const = 0; 57 57 virtual string_view get_resource_name() const = 0; -
trunk/nv/stl/functional/hash.hh
r489 r518 90 90 { 91 91 inline uintptr_t operator()( T* value ) const { return reinterpret_cast<uintptr_t>( value ); } 92 static constexpr uintptr_t get( T value ) { return reinterpret_cast<uintptr_t>( value ); } 92 93 }; 93 94 … … 110 111 NV_TRIVIAL_HASH( uint64 ) 111 112 112 #undef NV_TRIVIAL_HASH113 114 113 // TODO: hash is not compile-time, probably not needed, but doable? 115 114 template < typename H > -
trunk/src/engine/default_resource_manager.cc
r512 r518 21 21 m_gpu_materials = register_resource_handler< gpu_material >( new gpu_material_manager( context, m_materials, m_images ) ); 22 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 ); 23 24 } 24 25 … … 26 27 { 27 28 m_lua = lua; 29 30 particle_engine::register_types( const_cast< type_database* >( lua->get_type_data()->get_type_database() ) ); 28 31 29 32 int below_already_registered; … … 70 73 m_animators->initialize( lua ); 71 74 m_models->initialize( lua ); 75 m_particles->initialize( lua ); 72 76 } 73 77 -
trunk/src/engine/particle_engine.cc
r515 r518 13 13 #include <nv/core/logging.hh> 14 14 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"; 15 nv::hash_store< nv::shash64, nv::particle_emitter_func > nv::particle_engine::m_emitters; 16 nv::hash_store< nv::shash64, nv::particle_affector_funcs > nv::particle_engine::m_affectors; 17 18 nv::hash_map< nv::particle_emitter_func, nv::const_string >* nv::particle_engine::m_debug_emitter_names = nullptr; 19 nv::hash_map< nv::particle_affector_func, nv::const_string >* nv::particle_engine::m_debug_affector_names = nullptr; 20 nv::hash_map< nv::particle_affector_func, nv::type_entry* >* nv::particle_engine::m_debug_affector_types = nullptr; 60 21 61 22 using namespace nv; 62 23 63 static void nv_particle_em miter_point( const particle_emmiter_data*, particle* p, uint32 count )24 static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count ) 64 25 { 65 26 for ( uint32 i = 0; i < count; ++i ) … … 67 28 p[i].position = vec3(); 68 29 } 69 70 } 71 72 static void nv_particle_emmiter_box( const particle_emmiter_data* pe, particle* p, uint32 count ) 30 } 31 32 static void nv_particle_emitter_box( const particle_emitter_data* pe, particle* p, uint32 count ) 73 33 { 74 34 random& r = random::get(); … … 82 42 } 83 43 84 static void nv_particle_em miter_cylinder( const particle_emmiter_data* pe, particle* p, uint32 count )44 static void nv_particle_emitter_cylinder( const particle_emitter_data* pe, particle* p, uint32 count ) 85 45 { 86 46 random& r = random::get(); … … 95 55 } 96 56 97 static void nv_particle_em miter_sphere( const particle_emmiter_data* pe, particle* p, uint32 count )57 static void nv_particle_emitter_sphere( const particle_emitter_data* pe, particle* p, uint32 count ) 98 58 { 99 59 random& r = random::get(); … … 108 68 } 109 69 110 static void nv_particle_em miter_cylindroid( const particle_emmiter_data* pe, particle* p, uint32 count )70 static void nv_particle_emitter_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count ) 111 71 { 112 72 random& r = random::get(); … … 121 81 } 122 82 123 static void nv_particle_em miter_ellipsoid( const particle_emmiter_data* pe, particle* p, uint32 count )83 static void nv_particle_emitter_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count ) 124 84 { 125 85 random& r = random::get(); … … 134 94 } 135 95 136 static void nv_particle_em miter_hollow_cylinder( const particle_emmiter_data* pe, particle* p, uint32 count )96 static void nv_particle_emitter_hollow_cylinder( const particle_emitter_data* pe, particle* p, uint32 count ) 137 97 { 138 98 random& r = random::get(); … … 150 110 } 151 111 152 static void nv_particle_em miter_hollow_sphere( const particle_emmiter_data* pe, particle* p, uint32 count )112 static void nv_particle_emitter_hollow_sphere( const particle_emitter_data* pe, particle* p, uint32 count ) 153 113 { 154 114 random& r = random::get(); … … 163 123 } 164 124 165 static void nv_particle_em miter_hollow_cylindroid( const particle_emmiter_data* pe, particle* p, uint32 count )125 static void nv_particle_emitter_hollow_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count ) 166 126 { 167 127 random& r = random::get(); … … 179 139 } 180 140 181 static void nv_particle_em miter_hollow_ellipsoid( const particle_emmiter_data* pe, particle* p, uint32 count )141 static void nv_particle_emitter_hollow_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count ) 182 142 { 183 143 random& r = random::get(); … … 306 266 } 307 267 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 ) 268 nv::particle_engine::particle_engine( context* a_context, bool debug_data ) 467 269 { 468 270 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(); 473 279 register_standard_affectors(); 474 280 } 475 281 476 nv::particle_system nv::particle_engine::create_system( const string_view& id, particle_system_group group )282 nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_system_group group ) 477 283 { 478 284 particle_system_group_info* ginfo = m_groups.get( group ); 479 285 if ( !ginfo ) return nv::particle_system(); 480 286 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]);487 287 particle_system result = m_systems.create(); 488 288 particle_system_info* info = m_systems.get( result ); 489 289 info->group = group; 490 info->data 491 uint32 ecount = data->em miter_count;290 info->data = data; 291 uint32 ecount = data->emitter_count; 492 292 for ( uint32 i = 0; i < ecount; ++i ) 493 293 { 494 info->em miters[i].active= true;495 if ( data->em miters[i].duration_max == 0.0f )496 info->em miters[i].pause = 0;294 info->emitters[i].active = true; 295 if ( data->emitters[i].duration_max == 0.0f ) 296 info->emitters[i].pause = 0; 497 297 else 498 info->em miters[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 ); 499 299 500 300 } 501 301 502 302 info->count = 0; 503 info->particles = new particle[ data->quota];303 info->particles = new particle[data->quota]; 504 304 ginfo->ref_counter++; 505 305 506 306 return result; 307 } 308 309 nv::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 {}; 507 314 } 508 315 … … 513 320 { 514 321 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 );524 322 } 525 323 } … … 544 342 { 545 343 clear(); 546 m_context->release( m_program_world );547 m_context->release( m_program_local );548 344 } 549 345 … … 551 347 { 552 348 clear(); 553 register_standard_em miters();349 register_standard_emitters( ); 554 350 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();560 351 } 561 352 … … 566 357 while ( m_groups.size() > 0 ) 567 358 release( m_groups.get_handle( 0 ) ); 568 m_em miters.clear();359 m_emitters.clear(); 569 360 m_affectors.clear(); 570 m_names.clear();571 m_data.clear();572 361 } 573 362 … … 612 401 // while ( dtime > 0.2 ) 613 402 // { 614 // update_em miters( info, 0.2 );403 // update_emitters( info, 0.2 ); 615 404 // destroy_particles( info, 0.2 ); 616 405 // create_particles( info, 0.2 ); … … 619 408 // } 620 409 621 update_em miters( info, dtime );410 update_emitters( info, dtime ); 622 411 destroy_particles( info, dtime ); 623 412 create_particles( info, model, dtime ); … … 778 567 void nv::particle_engine::create_particles( particle_system_info* info, transform model, float dtime ) 779 568 { 780 uint32 ecount = info->data->em miter_count;569 uint32 ecount = info->data->emitter_count; 781 570 if ( ecount == 0 ) return; 782 571 … … 791 580 for ( uint32 i = 0; i < ecount; ++i ) 792 581 { 793 const auto& edata = info->data->em miters[i];794 auto& einfo = info->em miters[i];582 const auto& edata = info->data->emitters[i]; 583 auto& einfo = info->emitters[i]; 795 584 if ( einfo.active ) 796 585 { … … 802 591 { 803 592 particle& pinfo = info->particles[info->count]; 804 edata.em miter_func( &(info->data->emmiters[i]), &pinfo, 1 );593 edata.emitter_func( &(info->data->emitters[i]), &pinfo, 1 ); 805 594 pinfo.position = vec3(); 806 595 pinfo.position+= edata.position; 807 if ( !local )596 // if ( !local ) 808 597 pinfo.position = pinfo.position * model; 809 598 pinfo.color = edata.color_min == edata.color_max ? … … 865 654 } 866 655 867 void nv::particle_engine::update_em miters( particle_system_info* info, float dtime )868 { 869 uint32 ecount = info->data->em miter_count;656 void nv::particle_engine::update_emitters( particle_system_info* info, float dtime ) 657 { 658 uint32 ecount = info->data->emitter_count; 870 659 if ( ecount == 0 ) return; 871 660 random& r = random::get(); … … 873 662 for ( uint32 i = 0; i < ecount; ++i ) 874 663 { 875 const auto& edata = info->data->em miters[i];876 auto& einfo = info->em miters[i];664 const auto& edata = info->data->emitters[i]; 665 auto& einfo = info->emitters[i]; 877 666 878 667 if ( einfo.pause > 0.0f ) … … 902 691 } 903 692 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 ); 693 void 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 700 void 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 ); 921 712 } 922 713 923 714 void nv::particle_engine::register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process ) 924 715 { 716 if ( m_debug_affector_names ) 717 ( *m_debug_affector_names )[process] = name; 718 925 719 m_affectors[ name ].init = init; 926 720 m_affectors[ name ].process = process; 721 } 722 723 nv::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 733 nv::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 743 nv::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 751 nv::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 {}; 927 757 } 928 758 … … 945 775 } 946 776 777 void 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 121 121 m_context->set_viewport( ss.get_viewport() ); 122 122 123 123 124 if ( pass.cstate.buffers != buffer_mask::NO_BUFFER ) 124 125 m_context->clear( pass.cstate );
Note: See TracChangeset
for help on using the changeset viewer.