- Timestamp:
- 10/03/16 17:45:46 (9 years ago)
- Location:
- trunk
- Files:
-
- 16 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/ecs/ecs.hh
r499 r520 17 17 #include <nv/stl/string.hh> 18 18 #include <nv/stl/handle.hh> 19 #include <nv/core/types.hh> 19 20 20 21 namespace nv … … 122 123 123 124 124 template < typename H ANDLE = handle<>>125 template < typename Handle = handle<>, typename Time = f32 > 125 126 class ecs 126 127 { 127 128 public: 128 typedef HANDLE handle_type; 129 typedef Time time_type; 130 typedef Handle handle_type; 129 131 130 132 typedef uint32 message_type; … … 134 136 message_type type; 135 137 handle_type entity; 136 uint8 payload[128 - sizeof( uint32 ) - sizeof( handle_type )]; 138 time_type time; 139 uint8 payload[128 - sizeof( uint32 ) - sizeof( handle_type ) - sizeof( time_type )]; 137 140 }; 138 141 139 class component_interface 142 struct message_compare_type 143 { 144 bool operator()( const message& l, const message& r ) 145 { 146 return l.time > r.time; 147 } 148 }; 149 150 class receiver_interface 140 151 { 141 152 public: 153 virtual void update( time_type dtime ) = 0; 142 154 virtual bool handle_message( const message& ) = 0; 143 155 virtual void clear() = 0; 156 }; 157 158 class component_interface : public receiver_interface 159 { 160 public: 144 161 virtual void remove( handle_type h ) = 0; 162 virtual void* get_raw( handle_type h ) = 0; 163 virtual const void* get_raw( handle_type h ) const = 0; 145 164 }; 146 165 … … 153 172 } 154 173 155 template < typename COMPONENT > 156 void register_component( string_view /*name*/, component_interface* c ) 174 void register_receiver( string_view /*name*/, receiver_interface* c ) 175 { 176 m_receivers.push_back( c ); 177 } 178 179 template < typename Component > 180 void register_component( string_view name, component_interface* c ) 157 181 { 158 182 m_components.push_back( c ); 183 register_receiver( name, c ); 184 m_component_map[thash64::create<Component>()] = c; 159 185 } 160 186 161 187 bool dispatch( const message& m ) 162 188 { 163 for ( auto c : m_ components )189 for ( auto c : m_receivers ) 164 190 c->handle_message( m ); 165 191 return true; … … 169 195 bool dispatch( handle_type h, Args&&... args ) 170 196 { 171 message m{ Payload::message_id, h };197 message m{ Payload::message_id, h, time_type(0) }; 172 198 new( &m.payload ) Payload{ nv::forward<Args>( args )... }; 173 199 return dispatch( m ); 174 200 } 175 201 202 bool queue( const message& m ) 203 { 204 push_event( m ); 205 return true; 206 } 207 208 template < typename Payload, typename ...Args > 209 bool queue( handle_type h, time_type delay, Args&&... args ) 210 { 211 message m{ Payload::message_id, h, m_time + delay }; 212 new( &m.payload ) Payload{ nv::forward<Args>( args )... }; 213 return queue( m ); 214 } 215 216 176 217 handle_type create() 177 218 { … … 179 220 } 180 221 222 void update( time_type dtime ) 223 { 224 if ( dtime == time_type(0) ) return; 225 m_time += dtime; 226 while ( !m_queue.empty() && m_queue.front().time <= m_time ) 227 { 228 message msg = m_queue.front(); 229 pop_event(); 230 dispatch( msg ); 231 } 232 233 for ( auto c : m_receivers ) 234 c->update( dtime ); 235 } 236 237 time_type update_step() 238 { 239 time_type before = m_time; 240 if ( !m_queue.empty() ) 241 { 242 message msg = m_queue.front(); 243 m_time = msg.time; 244 pop_event(); 245 dispatch( msg ); 246 if ( before != m_time ) 247 for ( auto c : m_receivers ) 248 c->update( m_time - before ); 249 } 250 return m_time; 251 } 252 253 time_type get_time() const { return m_time; } 254 255 bool events_pending() const 256 { 257 return !m_queue.empty(); 258 } 259 260 const message& top_event() const 261 { 262 return m_queue.front(); 263 } 264 265 void reset_events() 266 { 267 m_queue.clear(); 268 m_time = time_type(0); 269 } 270 181 271 void clear() 182 272 { 183 for ( auto c : m_components ) 273 reset_events(); 274 for ( auto c : m_receivers ) 184 275 c->clear(); 185 276 m_handles.clear(); … … 198 289 } 199 290 291 template < typename Component > 292 Component* get( handle_type h ) 293 { 294 return static_cast< Component* >( m_component_map[thash64::create< Component >()]->get_raw( h ) ); 295 } 296 297 template < typename Component > 298 const Component* get( handle_type h ) const 299 { 300 return static_cast<const Component*>( m_component_map[thash64::create< Component >()]->get_raw( h ) ); 301 } 302 200 303 protected: 201 handle_manager< handle_type > m_handles; 202 vector< component_interface* > m_components; 304 void push_event( const message& msg ) 305 { 306 m_queue.push_back( msg ); 307 push_heap( m_queue.begin(), m_queue.end(), m_compare ); 308 } 309 310 void pop_event() 311 { 312 pop_heap( m_queue.begin(), m_queue.end(), m_compare ); 313 m_queue.pop_back(); 314 } 315 316 handle_manager< handle_type > m_handles; 317 vector< component_interface* > m_components; 318 vector< receiver_interface* > m_receivers; 319 hash_store< thash64, component_interface* > m_component_map; 320 time_type m_time = time_type(0); 321 vector< message > m_queue; 322 message_compare_type m_compare; 203 323 }; 204 324 … … 210 330 typedef typename ecs_type::message message_type; 211 331 typedef typename ecs_type::handle_type handle_type; 332 typedef typename ecs_type::time_type time_type; 212 333 typedef index_table< handle_type > index_table_type; 213 334 typedef COMPONENT value_type; … … 252 373 } 253 374 375 virtual void update( time_type /*dtime*/ ) 376 { 377 // no-op 378 } 379 254 380 virtual void clear() 255 381 { 382 for ( uint32 i = 0; i < m_index.size(); ++i ) 383 destroy( &m_data[i] ); 256 384 m_index.clear(); 257 385 m_data.clear(); … … 270 398 } 271 399 400 void* get_raw( handle_type h ) 401 { 402 index_type i = m_index.get( h ); 403 return i >= 0 ? &( m_data[unsigned( i )] ) : nullptr; 404 } 405 406 const void* get_raw( handle_type h ) const 407 { 408 index_type i = m_index.get( h ); 409 return i >= 0 ? &( m_data[unsigned( i )] ) : nullptr; 410 } 411 412 272 413 virtual void remove( handle_type h ) 273 414 { 415 value_type* v = get( h ); 416 if ( v == nullptr ) return; 417 destroy( v ); 274 418 index_type dead_eindex = m_index.remove_swap( h ); 275 419 if ( dead_eindex == -1 ) return; … … 281 425 } 282 426 283 virtual void remove( index_type i ) 284 { 285 index_type dead_eindex = m_index.remove_swap( i ); 286 if ( dead_eindex == -1 ) return; 287 if ( dead_eindex != static_cast<index_type>( m_data.size() - 1 ) ) 288 { 289 m_data[unsigned( dead_eindex )] = move( m_data.back() ); 290 } 291 m_data.pop_back(); 427 virtual void destroy( value_type* ) 428 { 429 // cleanup 292 430 } 293 431 … … 295 433 { 296 434 return true; 435 } 436 437 ~component() 438 { 439 clear(); 297 440 } 298 441 … … 318 461 }; 319 462 320 template < typename COMPONENTS >321 class system463 template < typename ECS > 464 class receiver : public ECS::receiver_interface 322 465 { 323 466 public: 467 typedef ECS ecs_type; 468 typedef typename ecs_type::message message_type; 469 typedef typename ecs_type::handle_type handle_type; 470 typedef typename ecs_type::time_type time_type; 471 472 receiver( ecs_type& a_ecs, string_view a_name ) : m_ecs( a_ecs ) 473 { 474 m_ecs.register_receiver( a_name, this ); 475 } 476 virtual void update( time_type /*dtime*/ ) 477 { 478 // no-op 479 } 480 481 virtual void clear() 482 { 483 // no-op 484 } 485 virtual bool handle_message( const message_type& ) 486 { 487 return false; 488 } 489 protected: 490 ecs_type& m_ecs; 324 491 }; 325 326 492 } 327 493 -
trunk/nv/engine/animation.hh
r509 r520 109 109 return m_current_state; 110 110 } 111 void add_transition( const animator_transition_data& data, uint32 source ) 112 { 111 float add_transition( const animator_transition_data& data, uint32 source ) 112 { 113 float duration = 0.0f; 113 114 if ( m_transitions.size() > 0 ) 114 115 { 116 for ( const auto& t : m_transitions ) 117 duration += t.duration - t.time; 115 118 auto& last = m_transitions.back(); 116 119 if ( last.target == source && data.target == last.source ) … … 118 121 nv::swap( last.target, last.source ); 119 122 last.time = last.duration - last.time; 120 return; 123 /* this duration might be inaccurate? */ 124 return duration; 121 125 } 122 126 } 123 127 m_transitions.push_back( animator_transition_instance( data, source ) ); 128 return duration + m_transitions.back().duration; 124 129 } 125 130 void reset() … … 198 203 } 199 204 200 void queue_event( const animator_data* data, shash64 name ) 201 { 205 float queue_event( const animator_data* data, shash64 name ) 206 { 207 float duration = 0.0f; 202 208 for ( uint32 i = 0; i < m_layers.size(); ++i ) 203 209 // what about activating nonactive layers? … … 209 215 if ( it != state.transitions.end() ) 210 216 { 211 m_layers[i].add_transition( it->second, uint32( last_state ) ); 217 float d = m_layers[i].add_transition( it->second, uint32( last_state ) ); 218 duration = nv::max( d, duration ); 212 219 } 213 220 } 214 } 215 216 void update( const animator_data* data, float dtime ) 221 return duration; 222 } 223 224 void update( const animator_data* data, float dtime, bool do_delocalize = true ) 217 225 { 218 226 for ( uint32 i = 0; i < m_layers.size(); ++i ) … … 235 243 } 236 244 245 if ( do_delocalize ) 246 m_transforms.delocalize( data->poses->get_tree() ); 247 } 248 void delocalize( const animator_data* data ) 249 { 237 250 m_transforms.delocalize( data->poses->get_tree() ); 238 251 } … … 275 288 } 276 289 277 protected: 290 const skeleton_transforms& stored() 291 { 292 return m_stored; 293 } 294 295 void store() 296 { 297 m_stored.assign( m_transforms ); 298 } 299 300 301 // protected: 278 302 279 303 void animate_layer( const animator_layer_data& layer, const animator_transition_instance& transition, pose_data_set* pose_data, float t ) … … 349 373 } 350 374 375 351 376 vector< animator_layer_instance > m_layers; 352 377 skeleton_transforms m_transforms; 353 354 378 skeleton_transforms m_stored; 355 379 }; 356 380 -
trunk/nv/engine/default_resource_manager.hh
r518 r520 26 26 #include <nv/engine/model_manager.hh> 27 27 #include <nv/engine/particle_manager.hh> 28 #include <nv/engine/ragdoll_manager.hh> 28 29 29 30 namespace nv … … 58 59 const type_database* get_type_db() { return m_lua->get_type_data()->get_type_database(); } 59 60 60 virtual void initialize( lua::state* lua );61 virtual void initialize( lua::state* lua, physics_world* world ); 61 62 virtual void reload_data(); 62 63 protected: … … 73 74 model_manager* m_models; 74 75 particle_manager* m_particles; 76 ragdoll_manager* m_ragdolls; 75 77 }; 76 78 -
trunk/nv/engine/light.hh
r508 r520 33 33 { 34 34 vec3 position; 35 vec 3color;35 vec4 color; 36 36 vec4 direction; 37 37 float angle; … … 43 43 light_data() : color( 1.0 ), direction( 0.0f, -1.0f, 0.0f, 1.0f ), angle( 0.6f ), umbra_angle( 0.2f ), range( 4.0 ), smooth( 0 ), shadow( shadow_type::ACTIVE ) {} 44 44 light_data( const vec3& a_position, const vec3& a_color, shadow_type type ) 45 : position( a_position ), color( a_color )45 : position( a_position ), color( a_color, 1.0f ) 46 46 , direction( 0.0f, -1.0f, 0.0f, 1.0f ), angle( 0.6f ), umbra_angle( 0.2f ), range( 4.0 ), smooth( 0 ), shadow( type ) {} 47 47 light_data( const light_data& ) = default; 48 48 }; 49 50 NV_RTTI_DECLARE( nv::light_data ) 49 51 50 52 struct light_data_distance_compare … … 89 91 90 92 m_blocks[i].position = vec4( lights[i]->position, 1.0f ); 91 m_blocks[i].color = vec4( lights[i]->color, 1.0f );93 m_blocks[i].color = vec4( vec3( lights[i]->color ) * lights[i]->color.w, 1.0f ); 92 94 m_blocks[i].direction = lights[i]->direction; 93 95 m_blocks[i].params = vec4( lights[i]->angle, lights[i]->umbra_angle, lights[i]->range, 1.0f ); -
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; -
trunk/nv/gfx/debug_draw.hh
r509 r520 37 37 void push_aabox( const vec3& a, const vec3& b, const vec3& color ); 38 38 void push_gizmo( const nv::transform& tr, float length ); 39 void push_wire_capsule( const transform& tr, float radius, float height ); 39 40 ~debug_data(); 40 41 private: -
trunk/nv/gfx/mesh_creator.hh
r503 r520 10 10 #include <nv/common.hh> 11 11 #include <nv/stl/math.hh> 12 #include <nv/core/aabb.hh> 12 13 #include <nv/interface/mesh_data.hh> 13 14 … … 22 23 initialize(); 23 24 } 25 26 aabb calculate_aabb(); 24 27 25 28 // assumes that position and normal is vec3, tangent is vec4 -
trunk/nv/gfx/skeleton_instance.hh
r491 r520 10 10 #include <nv/common.hh> 11 11 #include <nv/stl/array.hh> 12 #include <nv/core/logging.hh> 12 13 #include <nv/interface/context.hh> 13 14 #include <nv/interface/mesh_data.hh> … … 126 127 } 127 128 129 void delocalize( const data_node_tree& node_data, const array_view< bool >& mask ) 130 { 131 for ( uint32 n = 0; n < node_data.size(); ++n ) 132 if ( node_data[n].parent_id == -1 ) 133 delocalize_rec( node_data, n, transform(), mask ); 134 } 135 128 136 void delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent ); 137 void delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent, const array_view< bool >& mask ); 129 138 130 139 // protected: … … 194 203 195 204 196 protected:205 // protected: 197 206 198 207 dynamic_array< mat4 > m_matrix; -
trunk/nv/gl/gl_context.hh
r503 r520 41 41 virtual void release( vertex_array va ); 42 42 virtual void release( framebuffer f ); 43 virtual image_data* dump_image( image_format f, image_data* reuse ); 43 44 virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const; 44 45 -
trunk/nv/image/miniz.hh
r484 r520 17 17 18 18 void *miniz_decompress( const void *source_buf, size_t source_buf_len, size_t *out_len, bool parse_header ); 19 19 int miniz_compress( unsigned char *pDest, unsigned long *pDest_len, const unsigned char *pSource, unsigned long source_len, int level ); 20 unsigned long miniz_bound( unsigned long source_len ); 20 21 21 22 } -
trunk/nv/interface/context.hh
r506 r520 159 159 virtual void release( texture t ) { m_device->release( t ); } 160 160 virtual void release( buffer b ) { m_device->release( b ); } 161 162 virtual image_data* dump_image( image_format f, image_data* reuse ) = 0; 161 163 162 164 virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr ) = 0; -
trunk/nv/lua/lua_aux.hh
r503 r520 9 9 10 10 #include <nv/lua/lua_state.hh> 11 #include <nv/core/random.hh> 11 12 12 13 namespace nv … … 14 15 namespace lua 15 16 { 17 random& rng(); 16 18 void register_aux( lua::state* state ); 17 19 } -
trunk/nv/stl/container/random_access.hh
r435 r520 99 99 inline void fill( const value_type& value ) 100 100 { 101 fill_n( iterator( Super::data() ), iterator( Super::data() + this->size() ), value );101 ::nv::fill( iterator( Super::data() ), iterator( Super::data() + this->size() ), value ); 102 102 } 103 103 -
trunk/nv_wx.lua
r466 r520 1 1 assert( NV_RUNTIME == "dcrt" ) 2 3 project "*" 4 includedirs { 5 "D:/Libraries/wxwidgets/include/msvc/", 6 "D:/Libraries/wxwidgets/include/", 7 } 8 libdirs { "D:/Libraries/wxwidgets/lib/vc140_dll" } 9 defines { "__WXMSW__", "_UNICODE", "WXUSINGDLL", "wxMSVC_VERSION_AUTO" } 2 10 3 11 project "nv-wx" … … 11 19 links { "nv-core", "nv-gl", "nv-formats", "nv-lua", "nv-lib", "nv-io", "nv-gfx", "nv-sdl" } 12 20 13 solution "*"14 includedirs {15 "D:/Libraries/wxwidgets/include/msvc/",16 "D:/Libraries/wxwidgets/include/",17 }18 libdirs { "D:/Libraries/wxwidgets/lib/vc140_dll" }19 defines { "__WXMSW__", "_UNICODE", "WXUSINGDLL", "wxMSVC_VERSION_AUTO" } -
trunk/src/core/library.cc
r438 r520 11 11 # include <windows.h> 12 12 # define NV_LIB_EXT ".dll" 13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryEx ( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) )13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryExA( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ) 14 14 # define NV_LIB_GET( handle, name ) reinterpret_cast<void*>( GetProcAddress( static_cast<HMODULE>( handle ), name ) ) 15 15 # define NV_LIB_CLOSE( handle ) ( FreeLibrary( static_cast<HMODULE>( handle ) ) != 0 ) -
trunk/src/curses/curses_terminal.cc
r514 r520 131 131 } 132 132 133 // if result is a typable char from the 0..9 range 134 if ( result >= 0x108 && result <= 0x108 + 12 ) 135 { 136 kevent.key.code = static_cast<nv::key_code>( nv::KEY_F1 + result - 0x108 - 1 ); 137 } 138 133 139 // other recognized codes 134 140 switch ( result ) -
trunk/src/engine/default_resource_manager.cc
r519 r520 11 11 default_resource_manager::default_resource_manager( context* context, bool clear_material_paths ) 12 12 { 13 m_images 14 m_meshes 15 m_binds 16 m_animators 17 m_materials 18 m_programs 19 m_gpu_meshes 20 m_mesh_datas 13 m_images = register_resource_handler< image_data >( new image_manager ); 14 m_meshes = register_resource_handler< data_channel_set >( new mesh_manager ); 15 m_binds = register_resource_handler< animator_bind_data >( new animator_bind_manager ); 16 m_animators = register_resource_handler< animator_data >( new animator_manager ); 17 m_materials = register_resource_handler< material >( new material_manager( clear_material_paths ) ); 18 m_programs = register_resource_handler< program >( new program_manager( context ) ); 19 m_gpu_meshes = register_resource_handler< gpu_mesh >( new gpu_mesh_manager( context, m_meshes ) ); 20 m_mesh_datas = register_resource_handler< mesh_data >( new mesh_data_manager( m_meshes ) ); 21 21 m_gpu_materials = register_resource_handler< gpu_material >( new gpu_material_manager( context, m_materials, m_images ) ); 22 m_models = register_resource_handler< model >( new model_manager( this, m_binds, m_mesh_datas ) ); 23 m_particles = register_resource_handler< particle_system_data >( new particle_manager ); 22 m_models = register_resource_handler< model >( new model_manager( this, m_binds, m_mesh_datas ) ); 23 m_particles = register_resource_handler< particle_system_data >( new particle_manager ); 24 m_ragdolls = register_resource_handler< ragdoll_data >( new ragdoll_manager( m_models ) ); 24 25 } 25 26 26 void default_resource_manager::initialize( lua::state* lua )27 void default_resource_manager::initialize( lua::state* lua, physics_world* world ) 27 28 { 28 29 m_lua = lua; … … 72 73 m_models->initialize( lua ); 73 74 m_particles->initialize( lua ); 75 m_ragdolls->initialize( lua ); 76 m_ragdolls->initialize( world ); 74 77 } 75 78 -
trunk/src/engine/particle_engine.cc
r519 r520 1 // Copyright (C) 2014-201 5ChaosForge Ltd1 // Copyright (C) 2014-2016 ChaosForge Ltd 2 2 // http://chaosforge.org/ 3 3 // … … 26 26 using namespace nv; 27 27 28 static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count )28 static void nv_particle_emitter_point( random_base*, const particle_emitter_data*, particle* p, uint32 count ) 29 29 { 30 30 for ( uint32 i = 0; i < count; ++i ) … … 34 34 } 35 35 36 static void nv_particle_emitter_box( const particle_emitter_data* pe, particle* p, uint32 count ) 37 { 38 random& r = random::get(); 39 for ( uint32 i = 0; i < count; ++i ) 40 { 41 p[i].position = 42 r.frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir + 43 r.frange( 0.0f, pe->extents[1] ) * pe->dir + 44 r.frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir; 45 } 46 } 47 48 static void nv_particle_emitter_cylinder( const particle_emitter_data* pe, particle* p, uint32 count ) 49 { 50 random& r = random::get(); 51 for ( uint32 i = 0; i < count; ++i ) 52 { 53 vec2 rellipse( r.disk_point( pe->precise ) * pe->extents[0] ); 36 static void nv_particle_emitter_box( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 37 { 38 for ( uint32 i = 0; i < count; ++i ) 39 { 40 p[i].position = 41 r->frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir + 42 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 43 r->frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir; 44 } 45 } 46 47 static void nv_particle_emitter_cylinder( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 48 { 49 for ( uint32 i = 0; i < count; ++i ) 50 { 51 vec2 rellipse( r->disk_point( pe->precise ) * pe->extents[0] ); 54 52 p[i].position = 55 53 rellipse.x * pe->cdir + 56 r .frange( 0.0f, pe->extents[1] ) * pe->dir +54 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 57 55 rellipse.y * pe->odir; 58 56 } 59 57 } 60 58 61 static void nv_particle_emitter_sphere( const particle_emitter_data* pe, particle* p, uint32 count ) 62 { 63 random& r = random::get(); 64 for ( uint32 i = 0; i < count; ++i ) 65 { 66 vec3 rsphere = r.sphere_point( pe->precise ) * pe->extents[0]; 59 static void nv_particle_emitter_sphere( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 60 { 61 for ( uint32 i = 0; i < count; ++i ) 62 { 63 vec3 rsphere = r->sphere_point( pe->precise ) * pe->extents[0]; 67 64 p[i].position = 68 65 rsphere.x * pe->cdir + … … 72 69 } 73 70 74 static void nv_particle_emitter_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count ) 75 { 76 random& r = random::get(); 77 for ( uint32 i = 0; i < count; ++i ) 78 { 79 vec2 rellipse = r.ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise ); 71 static void nv_particle_emitter_cylindroid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 72 { 73 for ( uint32 i = 0; i < count; ++i ) 74 { 75 vec2 rellipse = r->ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise ); 80 76 p[i].position = 81 77 rellipse.x * pe->cdir + 82 r .frange( 0.0f, pe->extents[1] ) * pe->dir +78 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 83 79 rellipse.y * pe->odir; 84 80 } 85 81 } 86 82 87 static void nv_particle_emitter_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count ) 88 { 89 random& r = random::get(); 90 for ( uint32 i = 0; i < count; ++i ) 91 { 92 vec3 rsphere = r.ellipsoid_point( pe->hextents, pe->precise ); 83 static void nv_particle_emitter_ellipsoid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 84 { 85 for ( uint32 i = 0; i < count; ++i ) 86 { 87 vec3 rsphere = r->ellipsoid_point( pe->hextents, pe->precise ); 93 88 p[i].position = 94 89 rsphere.x * pe->cdir + … … 98 93 } 99 94 100 static void nv_particle_emitter_hollow_cylinder( const particle_emitter_data* pe, particle* p, uint32 count ) 101 { 102 random& r = random::get(); 103 for ( uint32 i = 0; i < count; ++i ) 104 { 105 vec2 rellipse = r.hollow_disk_point( 95 static void nv_particle_emitter_hollow_cylinder( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 96 { 97 for ( uint32 i = 0; i < count; ++i ) 98 { 99 vec2 rellipse = r->hollow_disk_point( 106 100 pe->ihextents[0], 107 101 pe->hextents[0], … … 109 103 p[i].position = 110 104 rellipse.x * pe->cdir + 111 r .frange( 0.0f, pe->extents[1] ) * pe->dir +105 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 112 106 rellipse.y * pe->odir; 113 107 } 114 108 } 115 109 116 static void nv_particle_emitter_hollow_sphere( const particle_emitter_data* pe, particle* p, uint32 count ) 117 { 118 random& r = random::get(); 119 for ( uint32 i = 0; i < count; ++i ) 120 { 121 vec3 rellipse = r.hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise ); 110 static void nv_particle_emitter_hollow_sphere( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 111 { 112 for ( uint32 i = 0; i < count; ++i ) 113 { 114 vec3 rellipse = r->hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise ); 122 115 p[i].position = 123 116 rellipse.x * pe->cdir + … … 127 120 } 128 121 129 static void nv_particle_emitter_hollow_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count ) 130 { 131 random& r = random::get(); 132 for ( uint32 i = 0; i < count; ++i ) 133 { 134 vec2 rellipse = r.hollow_ellipse_point( 122 static void nv_particle_emitter_hollow_cylindroid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 123 { 124 for ( uint32 i = 0; i < count; ++i ) 125 { 126 vec2 rellipse = r->hollow_ellipse_point( 135 127 vec2( pe->ihextents[0], pe->ihextents[2] ), 136 128 vec2( pe->hextents[0], pe->hextents[2] ), … … 138 130 p[i].position = 139 131 rellipse.x * pe->cdir + 140 r .frange( 0.0f, pe->extents[1] ) * pe->dir +132 r->frange( 0.0f, pe->extents[1] ) * pe->dir + 141 133 rellipse.y * pe->odir; 142 134 } 143 135 } 144 136 145 static void nv_particle_emitter_hollow_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count ) 146 { 147 random& r = random::get(); 148 for ( uint32 i = 0; i < count; ++i ) 149 { 150 vec3 rellipse = r.hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise ); 137 static void nv_particle_emitter_hollow_ellipsoid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count ) 138 { 139 for ( uint32 i = 0; i < count; ++i ) 140 { 141 vec3 rellipse = r->hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise ); 151 142 p[i].position = 152 143 rellipse.x * pe->cdir + … … 278 269 } 279 270 280 nv::particle_engine::particle_engine( context* a_context, bool debug_data ) 281 { 282 m_context = a_context; 271 nv::particle_engine::particle_engine( context* a_context, random_base* rng, particle_group_manager* groups, bool debug_data ) 272 { 273 m_context = a_context; 274 m_pgm = groups; 275 m_rng = rng; 276 if ( m_rng == nullptr ) 277 m_rng = &random::get(); 278 283 279 if ( debug_data ) 284 280 { 285 281 m_debug_emitter_names = new nv::hash_map< nv::particle_emitter_func, nv::const_string >; 286 282 m_debug_affector_names = new nv::hash_map< nv::particle_affector_func, nv::const_string >; 287 m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >;288 283 m_debug_emitter_list = new nv::vector< nv::particle_emitter_func >; 289 284 m_debug_affector_list = new nv::vector< nv::particle_affector_func >; … … 294 289 } 295 290 296 nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_ system_group group )297 { 298 particle_system_group_info* ginfo = m_groups.get( group );299 if ( !ginfo )return nv::particle_system();300 291 nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_group group ) 292 { 293 if ( !m_pgm->ref( group ) ) 294 return nv::particle_system(); 295 301 296 particle_system result = m_systems.create(); 302 297 particle_system_info* info = m_systems.get( result ); … … 310 305 info->emitters[i].pause = 0; 311 306 else 312 info->emitters[i].pause = random::get().frange( data->emitters[i].duration_min, data->emitters[i].duration_max );307 info->emitters[i].pause = m_rng->frange( data->emitters[i].duration_min, data->emitters[i].duration_max ); 313 308 314 309 } … … 316 311 info->count = 0; 317 312 info->particles = new particle[data->quota]; 318 ginfo->ref_counter++;319 313 320 314 return result; 321 315 } 322 316 323 nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_ system_group group )317 nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_group group ) 324 318 { 325 319 if ( auto data = rdata.lock() ) … … 328 322 } 329 323 330 void nv::particle_engine::prepare( particle_system_group group ) 331 { 332 particle_system_group_info* info = m_groups.get( group ); 333 if ( info ) 334 { 335 info->count = 0; 336 } 337 } 338 339 nv::particle_system_group nv::particle_engine::create_group( uint32 max_particles ) 340 { 341 particle_system_group result = m_groups.create(); 342 particle_system_group_info* info = m_groups.get( result ); 343 info->local = false; 344 info->count = 0; 345 info->quota = max_particles; 346 info->vtx_buffer = m_context->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ ); 347 vertex_array_desc desc; 348 desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true ); 349 info->vtx_array = m_context->create_vertex_array( desc ); 350 info->quads = new particle_quad[info->quota]; 351 info->ref_counter = 0; 352 return result; 324 void nv::particle_engine::prepare( particle_group group ) 325 { 326 m_pgm->prepare( group ); 327 } 328 329 nv::particle_group nv::particle_engine::create_group( uint32 max_particles ) 330 { 331 return m_pgm->create_group( max_particles ); 353 332 } 354 333 … … 369 348 while ( m_systems.size() > 0 ) 370 349 release( m_systems.get_handle( 0 ) ); 371 while ( m_groups.size() > 0)372 release( m_groups.get_handle( 0 ));350 if ( m_pgm ) 351 m_pgm->reset(); 373 352 m_emitters.clear(); 374 353 m_affectors.clear(); … … 381 360 if ( info ) 382 361 { 383 particle_system_group_info* ginfo = m_groups.get( info->group ); 384 if ( ginfo ) ginfo->ref_counter--; 385 delete[] info->particles; 362 m_pgm->unref( info->group ); 363 delete[] info->particles; 386 364 m_systems.destroy( system ); 387 365 } 388 366 } 389 367 390 void nv::particle_engine::release( particle_system_group group ) 391 { 392 particle_system_group_info* info = m_groups.get( group ); 393 if ( info ) 394 { 395 delete[] info->quads; 396 m_context->release( info->vtx_array ); 397 m_groups.destroy( group ); 398 } 368 void nv::particle_engine::release( particle_group group ) 369 { 370 m_pgm->release( group ); 399 371 } 400 372 … … 403 375 particle_system_info* info = m_systems.get( system ); 404 376 if ( info ) 405 { 406 generate_data( info, s ); 407 } 377 m_pgm->generate_data( array_view< particle >( info->particles, info->count ), info->data, info->group, s ); 408 378 } 409 379 … … 440 410 info->texcoords[1] = b; 441 411 } 442 }443 444 void nv::particle_engine::generate_data( particle_system_info* info, const scene_state& s )445 {446 // void* rawptr = m_context->map_buffer( info->vtx_buffer, nv::WRITE_UNSYNCHRONIZED, offset, info->count*sizeof( particle_quad ) );447 // particle_quad* quads = reinterpret_cast<particle_quad*>( rawptr );448 449 particle_system_group_info* group = m_groups.get( info->group );450 if ( !info )451 {452 return;453 }454 455 vec2 lb = vec2( -0.5f, -0.5f );456 vec2 rt = vec2( 0.5f, 0.5f );457 458 switch ( info->data->origin )459 {460 case particle_origin::CENTER : break;461 case particle_origin::TOP_LEFT : lb = vec2(0.f,-1.f); rt = vec2(1.f,0.f); break;462 case particle_origin::TOP_CENTER : lb.y = -1.f; rt.y = 0.f; break;463 case particle_origin::TOP_RIGHT : lb = vec2(-1.f,-1.f); rt = vec2(); break;464 case particle_origin::CENTER_LEFT : lb.x = 0.f; rt.x = 1.f; break;465 case particle_origin::CENTER_RIGHT : lb.x = -1.f; rt.x = 0.f; break;466 case particle_origin::BOTTOM_LEFT : lb = vec2(); rt = vec2(1.f,1.f); break;467 case particle_origin::BOTTOM_CENTER : lb.y = 0.f; rt.y = 1.f; break;468 case particle_origin::BOTTOM_RIGHT : lb = vec2(-1.f,0.f); rt = vec2(.0f,1.f); break;469 }470 471 const vec3 sm[4] =472 {473 vec3( lb.x, lb.y, 0.0f ),474 vec3( rt.x, lb.y, 0.0f ),475 vec3( lb.x, rt.y, 0.0f ),476 vec3( rt.x, rt.y, 0.0f ),477 };478 vec3 z( 0.0f, 0.0f ,1.0f );479 480 particle_orientation orientation = info->data->orientation;481 vec3 common_up ( info->data->common_up );482 vec3 common_dir( info->data->common_dir );483 bool accurate_facing = info->data->accurate_facing;484 mat3 rot_mat;485 vec3 right;486 vec3 pdir( 0.0f, 1.0f, 0.0f );487 488 vec3 camera_pos = s.get_camera().get_position();489 vec3 inv_view_dir = math::normalize( -s.get_camera().get_direction() );490 491 for ( uint32 i = 0; i < info->count; ++i )492 {493 const particle& pdata = info->particles[i];494 // particle_quad& rdata = quads[i];495 particle_quad& rdata = group->quads[i + group->count];496 497 vec3 view_dir( inv_view_dir );498 if ( accurate_facing ) view_dir = math::normalize( camera_pos - pdata.position );499 500 switch ( orientation )501 {502 case particle_orientation::POINT :503 right = math::normalize( math::cross( view_dir, vec3( 0, 1, 0 ) ) );504 right = math::rotate( right, pdata.rotation, view_dir );505 rot_mat = mat3( right, math::cross( right, -view_dir ), -view_dir );506 break;507 case particle_orientation::ORIENTED :508 pdir = normalize_safe( pdata.velocity, pdir );509 right = math::normalize( math::cross( pdir, view_dir ) );510 rot_mat = mat3( right, pdir, math::cross( pdir, right ) );511 break;512 case particle_orientation::ORIENTED_COMMON :513 right = math::normalize( math::cross( common_dir, view_dir ) );514 rot_mat = mat3( right, common_dir, math::cross( common_dir, right ) );515 break;516 case particle_orientation::PERPENDICULAR :517 pdir = normalize_safe( pdata.velocity, pdir );518 right = math::normalize( math::cross( common_up, pdir ) );519 rot_mat = mat3( right, common_up, math::cross( common_up, right ) );520 break;521 case particle_orientation::PERPENDICULAR_COMMON :522 right = math::normalize( math::cross( common_up, common_dir ) );523 rot_mat = mat3( right, common_up, math::cross( common_up, right ) );524 break;525 }526 527 vec2 texcoords[4] =528 {529 pdata.tcoord_a,530 vec2( pdata.tcoord_b.x, pdata.tcoord_a.y ),531 vec2( pdata.tcoord_a.x, pdata.tcoord_b.y ),532 pdata.tcoord_b533 };534 535 vec3 size( pdata.size.x, pdata.size.y, 0.0f );536 vec3 s0 = rot_mat * ( ( size * sm[0] ) );537 vec3 s1 = rot_mat * ( ( size * sm[1] ) );538 vec3 s2 = rot_mat * ( ( size * sm[2] ) );539 vec3 s3 = rot_mat * ( ( size * sm[3] ) );540 541 rdata.data[0].position = pdata.position + s0;542 rdata.data[0].color = pdata.color;543 rdata.data[0].texcoord = texcoords[0];544 545 rdata.data[1].position = pdata.position + s1;546 rdata.data[1].color = pdata.color;547 rdata.data[1].texcoord = texcoords[1];548 549 rdata.data[2].position = pdata.position + s2;550 rdata.data[2].color = pdata.color;551 rdata.data[2].texcoord = texcoords[2];552 553 rdata.data[3].position = pdata.position + s3;554 rdata.data[3].color = pdata.color;555 rdata.data[3].texcoord = texcoords[3];556 557 rdata.data[4] = rdata.data[2];558 rdata.data[5] = rdata.data[1];559 }560 // m_context->unmap_buffer( info->vtx_buffer );561 562 m_context->update( group->vtx_buffer, group->quads, group->count*sizeof(particle_quad), info->count*sizeof( particle_quad ) );563 group->count += info->count;564 412 } 565 413 … … 584 432 if ( ecount == 0 ) return; 585 433 586 random& r = random::get();587 434 bool local = model.is_identity(); 588 435 // if ( !local ) … … 605 452 { 606 453 particle& pinfo = info->particles[info->count]; 607 edata.emitter_func( &(info->data->emitters[i]), &pinfo, 1 );454 edata.emitter_func( m_rng, &(info->data->emitters[i]), &pinfo, 1 ); 608 455 pinfo.position = vec3(); 609 456 pinfo.position+= edata.position; … … 611 458 pinfo.position = pinfo.position * model; 612 459 pinfo.color = edata.color_min == edata.color_max ? 613 edata.color_min : r.range( edata.color_min, edata.color_max );460 edata.color_min : m_rng->range( edata.color_min, edata.color_max ); 614 461 pinfo.size = edata.size_min == edata.size_max ? 615 edata.size_min : r.range( edata.size_min, edata.size_max );462 edata.size_min : m_rng->range( edata.size_min, edata.size_max ); 616 463 if ( edata.square ) pinfo.size.y = pinfo.size.x; 617 464 float velocity = edata.velocity_min == edata.velocity_max ? 618 edata.velocity_min : r.frange( edata.velocity_min, edata.velocity_max );465 edata.velocity_min : m_rng->frange( edata.velocity_min, edata.velocity_max ); 619 466 pinfo.lifetime = dtime + einfo.next; 620 467 pinfo.death = ( edata.lifetime_min == edata.lifetime_max ? 621 edata.lifetime_min : r.frange( edata.lifetime_min, edata.lifetime_max ) );622 pinfo.rotation = r.frand( 2* math::pi<float>() );468 edata.lifetime_min : m_rng->frange( edata.lifetime_min, edata.lifetime_max ) ); 469 pinfo.rotation = m_rng->frand( 2* math::pi<float>() ); 623 470 pinfo.tcoord_a = info->texcoords[0]; 624 471 pinfo.tcoord_b = info->texcoords[1]; … … 628 475 { 629 476 float emission_angle = math::radians( edata.angle ); 630 float cos_theta = r.frange( cos( emission_angle ), 1.0f );477 float cos_theta = m_rng->frange( cos( emission_angle ), 1.0f ); 631 478 float sin_theta = sqrt(1.0f - cos_theta * cos_theta ); 632 float phi = r.frange( 0.0f, 2* math::pi<float>() );479 float phi = m_rng->frange( 0.0f, 2* math::pi<float>() ); 633 480 pinfo.velocity = model.get_orientation() * 634 481 ( edata.odir * ( cos(phi) * sin_theta ) + … … 672 519 uint32 ecount = info->data->emitter_count; 673 520 if ( ecount == 0 ) return; 674 random& r = random::get();675 521 676 522 for ( uint32 i = 0; i < ecount; ++i ) … … 691 537 einfo.active = false; 692 538 if ( edata.repeat_min > 0.0f ) 693 einfo.pause += r.frange( edata.repeat_min, edata.repeat_max );539 einfo.pause += m_rng->frange( edata.repeat_min, edata.repeat_max ); 694 540 else 695 541 einfo.pause = 0.0f; … … 698 544 { 699 545 einfo.active = true; 700 einfo.pause += r.frange( edata.duration_min, edata.duration_max );546 einfo.pause += m_rng->frange( edata.duration_min, edata.duration_max ); 701 547 } 702 548 } … … 776 622 } 777 623 778 nv::particle_render_data nv::particle_engine::get_render_data( particle_system_group group ) 779 { 780 const particle_system_group_info* info = m_groups.get( group ); 781 if ( info ) 782 { 783 return{ info->count, info->vtx_array }; 784 } 785 return { 0, nv::vertex_array() }; 624 nv::particle_render_data nv::particle_engine::get_render_data( particle_group group ) 625 { 626 return m_pgm->get_render_data( group ); 786 627 } 787 628 … … 794 635 } 795 636 796 void nv::particle_engine::register_types( type_database* db ) 637 const nv::type_entry* nv::particle_engine::get_debug_type( particle_affector_func f ) 638 { 639 if ( m_debug_affector_types ) 640 { 641 auto it = m_debug_affector_types->find( f ); 642 if ( it != m_debug_affector_types->end() ) 643 return it->second; 644 } 645 return nullptr; 646 } 647 648 void nv::particle_engine::register_types( type_database* db, bool debug_data ) 797 649 { 798 650 db->create_type<particle_orientation>() … … 816 668 ; 817 669 818 if ( m_debug_affector_types ) 819 { 670 if ( debug_data ) 671 { 672 if ( !m_debug_affector_types ) 673 m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >; 674 820 675 int you_could_get_rid_of_the_init_function_using_these; int error; 821 676 int universal_vm_based_affector; … … 849 704 } 850 705 } 706 -
trunk/src/engine/particle_manager.cc
r518 r520 61 61 data->emitter_count = 0; 62 62 data->affector_count = 0; 63 64 const_string orientation = table.get_string( "orientation", "point" ); 65 if ( orientation == "point" ) { data->orientation = particle_orientation::POINT; } 66 else if ( orientation == "oriented" ) { data->orientation = particle_orientation::ORIENTED; } 67 else if ( orientation == "oriented_common" ) { data->orientation = particle_orientation::ORIENTED_COMMON; } 68 else if ( orientation == "perpendicular" ) { data->orientation = particle_orientation::PERPENDICULAR; } 69 else if ( orientation == "perpendicular_common" ) { data->orientation = particle_orientation::PERPENDICULAR_COMMON; } 70 else 71 { 72 NV_LOG_ERROR( "Unknown orientation type! (", orientation, ")!" ); 73 data->orientation = particle_orientation::POINT; 74 } 75 76 const_string origin = table.get_string( "origin", "center" ); 77 if ( origin == "center" ) { data->origin = particle_origin::CENTER; } 78 else if ( origin == "top_left" ) { data->origin = particle_origin::TOP_LEFT; } 79 else if ( origin == "top_center" ) { data->origin = particle_origin::TOP_CENTER; } 80 else if ( origin == "top_right" ) { data->origin = particle_origin::TOP_RIGHT; } 81 else if ( origin == "center_left" ) { data->origin = particle_origin::CENTER_LEFT; } 82 else if ( origin == "center_right" ) { data->origin = particle_origin::CENTER_RIGHT; } 83 else if ( origin == "bottom_left" ) { data->origin = particle_origin::BOTTOM_LEFT; } 84 else if ( origin == "bottom_center" ) { data->origin = particle_origin::BOTTOM_CENTER; } 85 else if ( origin == "bottom_right" ) { data->origin = particle_origin::BOTTOM_RIGHT; } 86 else 87 { 88 NV_LOG_ERROR( "Unknown particle origin! (", origin, ")!" ); 89 data->origin = particle_origin::CENTER; 90 } 63 data->orientation = particle_orientation( table.get_unsigned("orientation", 0) ); 64 data->origin = particle_origin( table.get_unsigned( "origin",0 ) ); 91 65 92 66 data->common_up = math::normalize( table.get<vec3>("common_up", vec3(1,0,0) ) ); -
trunk/src/gfx/debug_draw.cc
r509 r520 101 101 } 102 102 103 void nv::debug_data::push_wire_capsule( const transform& tr, float radius, float height ) 104 { 105 vec3 p = tr.get_position(); 106 quat o = tr.get_orientation(); 107 vec3 dir = o * vec3( 0, 1, 0 ); 108 vec3 ldir = o * vec3( 1, 0, 0 ); 109 vec3 h1dir = o * normalize( vec3( 1, -1, 0 ) ); 110 vec3 h2dir = o * normalize( vec3( 1, 1, 0 ) ); 111 vec3 sp1[12]; 112 vec3 sp2[12]; 113 vec3 hsp1[12]; 114 vec3 hsp2[12]; 115 for ( uint32 i = 0; i < 12; ++i ) 116 { 117 sp1[i] = nv::math::rotate( ldir * radius, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 118 hsp1[i] = nv::math::rotate( h1dir * radius, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 119 } 120 for ( uint32 i = 0; i < 12; ++i ) 121 { 122 sp2[i] = nv::math::rotate( ldir * radius + height * dir, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 123 hsp2[i] = nv::math::rotate( h2dir * radius + height * dir, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir ); 124 } 125 126 for ( uint32 i = 0; i < 12; ++i ) 127 { 128 push_line( p + sp1[i], p + sp1[( i + 1 ) % 12], vec3( 1.0f, 0.0f, 0.0f ) ); 129 push_line( p + sp2[i], p + sp2[( i + 1 ) % 12], vec3( 0.0f, 1.0f, 0.0f ) ); 130 push_line( p + sp1[i], p + sp2[i], vec3( 0.0f, 0.0f, 1.0f ) ); 131 132 push_line( p + hsp1[i], p + sp1[i], vec3( 0.0f, 0.0f, 1.0f ) ); 133 push_line( p + hsp1[i], p + hsp1[( i + 1 ) % 12], vec3( 1.0f, 0.0f, 0.0f ) ); 134 push_line( p + hsp2[i], p + sp2[i], vec3( 0.0f, 0.0f, 1.0f ) ); 135 push_line( p + hsp2[i], p + hsp2[( i + 1 ) % 12], vec3( 0.0f, 1.0f, 0.0f ) ); 136 137 push_line( p + hsp1[i], p - radius * dir, vec3( 0.0f, 0.0f, 1.0f ) ); 138 push_line( p + hsp2[i], p + ( height + radius ) * dir, vec3( 0.0f, 0.0f, 1.0f ) ); 139 140 } 141 142 143 } 144 145 103 146 nv::debug_data::~debug_data() 104 147 { -
trunk/src/gfx/gfx_terminal.cc
r514 r520 84 84 fgcolor = fg.get_argb32(); 85 85 bgcolor = bg.get_argb32(); 86 gylph = uint32( ch ); 87 NV_LOG_INFO( uint32( 88 ( fgcolor & uint32( 0x00FF0000 ) ) >> 16 ), "-", uint32( ( fgcolor & uint32( 0x0000FF00 ) ) >> 8 ),"-" , uint32( fgcolor & uint32( 0x000000FF ) ) ); 86 gylph = uint32( uint8(ch) ); 89 87 } 90 88 }; … … 139 137 m_dc.p = m_context->create_program( nv_gfx_terminal_vs, nv_gfx_terminal_fs ); 140 138 141 m_data->buffer = m_context->create_buffer( nv::UNIFORM_BUFFER, nv:: DYNAMIC_DRAW, tsize.x * tsize.y * sizeof( gfx_terminal_uniform_block ), m_data->data );139 m_data->buffer = m_context->create_buffer( nv::UNIFORM_BUFFER, nv::STREAM_DRAW, tsize.x * tsize.y * sizeof( gfx_terminal_uniform_block ), m_data->data ); 142 140 m_context->bind( m_data->buffer, 7 ); 143 141 m_context->get_device()->set_opt_uniform( m_dc.p, "term_size", vec2( tsize ) ); … … 151 149 void gfx_terminal::update() 152 150 { 153 m_context->bind( m_data->buffer, 7 ); 154 m_context->update( m_data->buffer, m_data->data, 0, m_data->size.x * m_data->size.y * sizeof( gfx_terminal_uniform_block ) ); 155 m_update_needed = false; 151 if ( m_update_needed ) 152 { 153 m_context->bind( m_data->buffer, 7 ); 154 m_context->update( m_data->buffer, m_data->data, 0, m_data->size.x * m_data->size.y * sizeof( gfx_terminal_uniform_block ) ); 155 m_update_needed = false; 156 } 156 157 } 157 158 -
trunk/src/gfx/mesh_creator.cc
r503 r520 87 87 } 88 88 89 90 nv::aabb nv::mesh_data_creator::calculate_aabb() 91 { 92 NV_ASSERT_ALWAYS( m_pos_channel, "No position channel found!" ); 93 vec3 minv; 94 vec3 maxv; 95 96 if ( m_pos_channel->size() > 0 ) 97 { 98 minv = *reinterpret_cast<const vec3*>( m_pos_channel->raw_data() + m_pos_offset ); 99 maxv = minv; 100 } 101 102 for ( uint32 c = 0; c < m_pos_channel->size(); ++c ) 103 { 104 vec3 v = *reinterpret_cast<const vec3*>( m_pos_channel->raw_data() + c*m_pos_channel->element_size() + m_pos_offset ); 105 minv = nv::math::min( minv, v ); 106 maxv = nv::math::max( maxv, v ); 107 } 108 vec3 extents = maxv - minv; 109 vec3 hextents = extents * 0.5f; 110 vec3 halfv = minv + hextents; 111 return aabb( nv::transform( halfv ), hextents ); 112 } 89 113 90 114 void nv::mesh_data_creator::transform( const vec3& pos, const mat3& r33, float scale /*= 1.0f */ ) -
trunk/src/gfx/skeleton_instance.cc
r486 r520 182 182 } 183 183 184 void nv::skeleton_transforms::delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent, const array_view< bool >& mask ) 185 { 186 transform global_mat = parent; 187 bool b = mask[id]; 188 if ( !b ) 189 global_mat = m_transforms[id]; 190 else 191 { 192 global_mat *= m_transforms[id]; 193 m_transforms[id] = global_mat; 194 } 195 for ( auto child : node_data.children( id ) ) 196 { 197 delocalize_rec( node_data, child, global_mat, mask ); 198 } 199 } 200 -
trunk/src/gl/gl_context.cc
r515 r520 125 125 } 126 126 } 127 128 nv::image_data* nv::gl_context::dump_image( image_format f, image_data* reuse ) 129 { 130 NV_ASSERT_ALWAYS( f.type == nv::UBYTE, "Bad format passed to dump" ); 131 NV_ASSERT_ALWAYS( f.format == nv::RGB || f.format == nv::RGBA, "Bad format passed to dump" ); 132 glPixelStorei( GL_PACK_ALIGNMENT, 1 ); 133 image_data* result = reuse; 134 if ( !result ) result = new image_data( f, ivec2( m_viewport.z, m_viewport.w ) ); 135 glReadPixels( 0, 0, m_viewport.z, m_viewport.w, f.format == nv::RGB ? GL_RGB : GL_RGBA, datatype_to_gl_enum( f.type ), const_cast< uint8* >( result->get_data() ) ); 136 return result; 137 } 138 127 139 128 140 const framebuffer_info* nv::gl_context::get_framebuffer_info( framebuffer f ) const -
trunk/src/gui/gui_ascii_renderer.cc
r514 r520 98 98 m_terminal->print( abs.ll(), er->border_color, term_color(), er->border_chars[6] ); 99 99 m_terminal->print( abs.lr, er->border_color, term_color(), er->border_chars[7] ); 100 m_terminal->update();100 //m_terminal->update(); 101 101 } 102 102 if ( !e->m_text.empty() ) -
trunk/src/gui/gui_environment.cc
r492 r520 183 183 handle h = get_element( position( ev.mbutton.x, ev.mbutton.y ) ); 184 184 element* e = m_elements.get( h ); 185 if (e) 185 186 if ( e->m_on_click ) e->m_on_click(); 186 187 -
trunk/src/image/miniz.cc
r487 r520 2668 2668 return tinfl_decompress_mem_to_heap( source_buf, source_buf_len, out_len, parse_header ? TINFL_FLAG_PARSE_ZLIB_HEADER : 0 ); 2669 2669 } 2670 2671 int nv::miniz_compress( unsigned char *pDest, unsigned long *pDest_len, const unsigned char *pSource, unsigned long source_len, int level ) 2672 { 2673 NV_PROFILE( "compress" ); 2674 return mz_compress2( pDest, pDest_len, pSource, source_len, level ); 2675 } 2676 2677 unsigned long nv::miniz_bound( unsigned long source_len ) 2678 { 2679 return mz_compressBound( source_len ); 2680 } -
trunk/src/lib/gl.cc
r501 r520 189 189 190 190 191 HWND hWndFake = CreateWindow (TEXT("Dummy67789"), "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN,191 HWND hWndFake = CreateWindowA("Dummy67789", "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN, 192 192 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, 193 193 NULL, GetModuleHandle(nullptr), NULL); … … 213 213 wgl_makecurrent(hDC, hRCFake); 214 214 215 LoadLibrary ( "gdi32.dll" );215 LoadLibraryA( "gdi32.dll" ); 216 216 bool gl_loaded = nv::load_gl_library( path ); 217 217 bool wgl_loaded = nv::load_wgl_library( path ); -
trunk/src/lua/lua_area.cc
r503 r520 8 8 9 9 #include "nv/lua/lua_raw.hh" 10 #include "nv/ core/random.hh"10 #include "nv/lua/lua_aux.hh" 11 11 12 12 using nv::lua::detail::is_coord; … … 333 333 nv::sint32 xs = ( b.x - a.x ) + 1; 334 334 nv::sint32 ys = ( b.y - a.y ) - 1; 335 nv::sint32 roll = nv:: random::get().srand( 2 * xs + 2 * ys );335 nv::sint32 roll = nv::lua::rng().srand( 2 * xs + 2 * ys ); 336 336 nv::ivec2 result; 337 337 … … 356 356 nv::sint32 xs = ( b.x - a.x ) - 1; 357 357 nv::sint32 ys = ( b.y - a.y ) - 1; 358 nv::sint32 roll = nv:: random::get().srand( 2 * xs + 2 * ys );358 nv::sint32 roll = nv::lua::rng().srand( 2 * xs + 2 * ys ); 359 359 nv::ivec2 result; 360 360 … … 375 375 { 376 376 nv::rectangle area = to_area( L, 1 ); 377 push_coord( L, nv:: random::get().range( area.ul, area.lr ) );377 push_coord( L, nv::lua::rng().range( area.ul, area.lr ) ); 378 378 return 1; 379 379 } … … 383 383 nv::rectangle area = to_area( L, 1 ); 384 384 nv::ivec2 dim = to_coord( L, 2 ); 385 nv::ivec2 start = nv:: random::get().range( area.ul, area.lr - dim );385 nv::ivec2 start = nv::lua::rng().range( area.ul, area.lr - dim ); 386 386 push_area( L, nv::rectangle( start, start + dim ) ); 387 387 return 1; -
trunk/src/lua/lua_aux.cc
r503 r520 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/core/random.hh" 11 12 static nv::random lua_rng; 11 13 12 14 static int nluaaux_table_copy( lua_State* L ) … … 94 96 if ( dice < 1 ) luaL_argerror( L, 1, "die count lower than 1!" ); 95 97 if ( sides < 1 ) luaL_argerror( L, 2, "side count lower than 1!" ); 96 lua_pushnumber( L, nv::random::get().dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) );98 lua_pushnumber( L, lua_rng.dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) ); 97 99 return 1; 98 100 } … … 102 104 if ( lua_gettop( L ) == 0 ) 103 105 { 104 lua_pushnumber( L, nv::random::get().frand(1.0f) );106 lua_pushnumber( L, lua_rng.frand(1.0f) ); 105 107 } 106 108 else … … 110 112 lua_Integer arg1 = luaL_checkinteger( L, 1 ); 111 113 if ( arg1 < 1 ) arg1 = 1; 112 nlua_pushunsigned( L, nv::random::get().urange( 1, static_cast<nv::uint32>( arg1 ) ) );114 nlua_pushunsigned( L, lua_rng.urange( 1, static_cast<nv::uint32>( arg1 ) ) ); 113 115 } 114 116 else … … 116 118 int arg1 = static_cast< int >( luaL_checkinteger( L, 1 ) ); 117 119 int arg2 = static_cast< int >( luaL_checkinteger( L, 2 ) ); 118 int result = ( arg2 >= arg1 ? nv::random::get().srange( arg1, arg2 ) : nv::random::get().srange( arg2, arg1 ) );120 int result = ( arg2 >= arg1 ? lua_rng.srange( arg1, arg2 ) : lua_rng.srange( arg2, arg1 ) ); 119 121 lua_pushinteger( L, result ); 120 122 } … … 125 127 static int nluaaux_math_randomseed( lua_State* L ) 126 128 { 127 nv::random::get().set_seed( nlua_tounsigned( L, 1 ) );129 lua_rng.set_seed( nlua_tounsigned( L, 1 ) ); 128 130 return 0; 129 131 } … … 137 139 }; 138 140 141 nv::random & nv::lua::rng() 142 { 143 return lua_rng; 144 } 145 139 146 void nv::lua::register_aux( lua::state* state ) 140 147 { -
trunk/src/lua/lua_map_tile.cc
r503 r520 11 11 #include "nv/stl/numeric.hh" 12 12 #include "nv/stl/algorithm.hh" 13 #include "nv/ core/random.hh"13 #include "nv/lua/lua_aux.hh" 14 14 #include "nv/lua/lua_area.hh" 15 15 #include "nv/lua/lua_math.hh" … … 207 207 static int nlua_map_tile_flip_random( lua_State* L ) 208 208 { 209 switch ( nv:: random::get().urand( 4 ) )209 switch ( nv::lua::rng().urand( 4 ) ) 210 210 { 211 211 case 1 : nlua_map_tile_flip_x( L ); break; -
trunk/src/lua/lua_math.cc
r512 r520 8 8 9 9 #include "nv/lua/lua_raw.hh" 10 #include "nv/ core/random.hh"10 #include "nv/lua/lua_aux.hh" 11 11 #include "nv/stl/type_traits/common.hh" 12 12 … … 126 126 int nlua_vec_random( lua_State* L ) 127 127 { 128 push_vec<T>( L, nv:: random::get().range( to_vec<T>( L, 1 ), to_vec<T>( L, 2 ) ) );128 push_vec<T>( L, nv::lua::rng().range( to_vec<T>( L, 1 ), to_vec<T>( L, 2 ) ) ); 129 129 return 1; 130 130 }
Note: See TracChangeset
for help on using the changeset viewer.