Changeset 520 for trunk/nv/engine/particle_engine.hh
- Timestamp:
- 10/03/16 17:45:46 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/engine/particle_engine.hh
r519 r520 1 // Copyright (C) 2014-201 5ChaosForge Ltd1 // Copyright (C) 2014-2016 ChaosForge Ltd 2 2 // http://chaosforge.org/ 3 3 // … … 16 16 #include <nv/gfx/texture_atlas.hh> 17 17 #include <nv/core/resource.hh> 18 #include <nv/core/random.hh> 18 19 #include <nv/interface/scene_node.hh> 19 20 #include <nv/interface/context.hh> 21 #include <nv/engine/particle_group.hh> 20 22 21 23 namespace nv … … 27 29 struct particle_emitter_data; 28 30 struct particle_affector_data; 29 struct particle;30 31 31 typedef void( *particle_emitter_func )( const particle_emitter_data*, particle*, uint32 count );32 typedef void( *particle_emitter_func )( random_base* r, const particle_emitter_data*, particle*, uint32 count ); 32 33 typedef void( *particle_affector_func )( const particle_affector_data*, particle*, float factor, uint32 count ); 33 34 typedef bool( *particle_affector_init_func )( lua::table_guard* table, particle_affector_data* data ); … … 37 38 particle_affector_func process; 38 39 particle_affector_init_func init; 39 };40 41 enum class particle_orientation42 {43 POINT,44 ORIENTED,45 ORIENTED_COMMON,46 PERPENDICULAR,47 PERPENDICULAR_COMMON,48 };49 enum class particle_origin50 {51 CENTER,52 TOP_LEFT,53 TOP_CENTER,54 TOP_RIGHT,55 CENTER_LEFT,56 CENTER_RIGHT,57 BOTTOM_LEFT,58 BOTTOM_CENTER,59 BOTTOM_RIGHT,60 };61 62 struct particle_vtx63 {64 vec3 position;65 vec2 texcoord;66 vec4 color;67 };68 69 struct particle_quad70 {71 particle_vtx data[6];72 };73 74 struct particle75 {76 vec3 position;77 vec4 color;78 vec3 velocity;79 vec2 size;80 vec2 tcoord_a;81 vec2 tcoord_b;82 float rotation;83 float lifetime;84 float death;85 40 }; 86 41 … … 127 82 }; 128 83 129 struct particle_system_data 84 struct particle_system_data : particle_group_settings 130 85 { 131 86 uint32 quota; 132 vec3 common_up;133 vec3 common_dir;134 bool accurate_facing;135 particle_orientation orientation;136 particle_origin origin;137 87 uint32 emitter_count; 138 88 particle_emitter_data emitters[MAX_PARTICLE_EMITTERS]; … … 141 91 }; 142 92 143 struct particle_system_group_tag {};144 typedef handle< uint32, 16, 16, particle_system_group_tag > particle_system_group;145 93 struct particle_system_tag {}; 146 94 typedef handle< uint32, 16, 16, particle_system_tag > particle_system; … … 151 99 particle_emitter_info emitters[MAX_PARTICLE_EMITTERS]; 152 100 153 uint32 154 vec2 155 particle_ system_group group;101 uint32 count; 102 vec2 texcoords[2]; 103 particle_group group; 156 104 157 105 const particle_system_data* data; 158 };159 160 struct particle_system_group_info161 {162 uint32 count;163 uint32 quota;164 vertex_array vtx_array;165 buffer vtx_buffer;166 bool local;167 particle_quad* quads;168 uint32 ref_counter;169 };170 171 struct particle_render_data172 {173 uint32 count;174 vertex_array vtx_array;175 106 }; 176 107 … … 178 109 179 110 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 111 183 namespace nv { 112 namespace nv 113 { 184 114 185 115 class particle_engine 186 116 { 187 117 public: 188 particle_engine( context* a_context, bool debug_data = false );118 particle_engine( context* a_context, random_base* rng, particle_group_manager* groups, bool debug_data = false ); 189 119 void reset(); 190 void prepare( particle_ system_group group );191 particle_ system_group create_group( uint32 max_particles );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 );194 void release( particle_ system_group group );120 void prepare( particle_group group ); 121 particle_group create_group( uint32 max_particles ); 122 particle_system create_system( resource< particle_system_data > rdata, particle_group group ); 123 particle_system create_system( const particle_system_data* data, particle_group group ); 124 void release( particle_group group ); 195 125 void release( particle_system system ); 196 126 void update( particle_system system, transform model, float dtime ); … … 205 135 static const vector< particle_emitter_func >* get_debug_emitter_list() { return m_debug_emitter_list; } 206 136 static const vector< particle_affector_func >* get_debug_affector_list() { return m_debug_affector_list; } 207 static const type_entry* get_debug_type( particle_affector_init_func f ); 208 static void register_types( type_database* db ); 209 particle_render_data get_render_data( particle_system_group group ); 137 static const type_entry* get_debug_type( particle_affector_func f ); 138 static void register_types( type_database* db, bool debug_data = false ); 139 particle_render_data get_render_data( particle_group group ); 140 particle_group_manager* get_particle_manager() { return m_pgm; } 210 141 ~particle_engine(); 211 142 private: … … 213 144 void register_standard_emitters(); 214 145 void register_standard_affectors(); 215 void generate_data( particle_system_info* info, const scene_state& s );216 146 void destroy_particles( particle_system_info* info, float dtime ); 217 147 void create_particles( particle_system_info* info, transform tr, float dtime ); … … 219 149 void update_emitters( particle_system_info* info, float dtime ); 220 150 151 particle_group_manager* m_pgm; 221 152 context* m_context; 153 random_base* m_rng; 222 154 223 155 handle_store< particle_system_info, particle_system > m_systems; 224 handle_store< particle_system_group_info, particle_system_group > m_groups;225 156 226 157 static hash_store< shash64, particle_emitter_func > m_emitters;
Note: See TracChangeset
for help on using the changeset viewer.