Changeset 551
- Timestamp:
- 03/14/17 16:44:18 (8 years ago)
- Location:
- trunk
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv.lua
r537 r551 112 112 links { "nv-core", "nv-lib", "nv-io", "nv-gfx", "nv-lua" } 113 113 114 --[[ 114 115 -- injection! 115 116 solution( solution().name ) 116 117 configuration "gmake" 117 if _ACTION == "gmake-clang"then118 if CLANG then 118 119 buildoptions { 119 "-std=c++1 z",120 "-std=c++14", 120 121 -- -- on Mac OS X don't try to use old stdc++ 121 122 -- "-stdlib=libc++", 122 "-Weverything",123 -- "-Weverything", 123 124 -- math is so much easier with these 125 "-w", 124 126 "-Wno-gnu-anonymous-struct", 125 127 "-Wno-nested-anon-types", … … 163 165 164 166 if _ACTION == "gmake-clang" then 165 premake.gcc.cc = "clang" 166 premake.gcc.cxx = "clang++" 167 toolset "clang" 167 168 _ACTION = "gmake" 168 169 end … … 178 179 end 179 180 end 181 182 --]] -
trunk/nv/base/common.hh
r533 r551 184 184 #endif 185 185 186 #if NV_COMPILER != NV_MSVC 187 #define NULL 0 188 #endif 189 186 190 namespace nv 187 191 { -
trunk/nv/core/resource.hh
r513 r551 221 221 shash64 hid( id ); 222 222 if ( m->second->exists( hid ) || m->second->load_resource( id ) ) 223 return m->second-> create< T >( hid );223 return m->second->template create< T >( hid ); 224 224 NV_ASSERT( false, "resource_manager.get failed!" ); 225 225 return resource< T >(); … … 234 234 if ( m->second->exists( hid ) ) 235 235 { 236 return m->second-> create< T >( hid );236 return m->second->template create< T >( hid ); 237 237 } 238 238 NV_ASSERT( false, "resource_manager.get failed!" ); … … 246 246 NV_ASSERT( m != m_handlers.end(), "Resource type unrecognized!" ); 247 247 m->second->raw_add( id, value ); 248 return m->second-> create< T >( id );248 return m->second->template create< T >( id ); 249 249 } 250 250 -
trunk/nv/ecs/component.hh
r550 r551 37 37 typename Component, 38 38 typename Handler, 39 template < typename, typename > class IndexTable = index_table39 template < typename, typename > class IndexTable = flat_index_table 40 40 > 41 41 class component : public Ecs::component_interface … … 47 47 typedef typename ecs_type::time_type time_type; 48 48 typedef IndexTable< handle_type, sint32 > index_table_type; 49 typedef index_table< handle_type, sint32 > idx_table; 49 50 typedef Component value_type; 50 51 typedef Component component_type; … … 58 59 typedef typename storage_type::const_reference const_reference; 59 60 60 component( ecs_type& a_ecs, string_view a_name, bool relational = false , uint32 reserve = 0)61 component( ecs_type& a_ecs, string_view a_name, bool relational = false ) 61 62 : m_ecs( a_ecs ), m_relational( relational ), m_storage( nullptr ) 62 63 { 63 m_storage = new storage_type; 64 m_ecs.register_component<component_type, Handler>( a_name, this ); 65 if ( reserve != 0 ) 66 { 67 m_storage->reserve( reserve ); 68 } 64 m_index = new index_table_type; 65 m_storage = (storage_type*)m_ecs.template register_component<component_type, Handler>( a_name, this ); 66 // if ( reserve != 0 ) 67 // { 68 // m_storage->reserve( reserve ); 69 // } 70 } 71 72 void temp_storage( storage_type* storage ) 73 { 74 69 75 } 70 76 71 77 virtual uint32 temp_index( handle_type h ) const final 72 78 { 73 return m_index .get( h );79 return m_index->get( h ); 74 80 } 75 81 … … 77 83 inline value_type& insert( handle_type h ) 78 84 { 79 index_type i = m_index .insert( h );85 index_type i = m_index->insert( h ); 80 86 NV_ASSERT( i == index_type( m_storage->size() ), "Fail!" ); 81 87 NV_UNUSED( i ); … … 87 93 value_type& insert( handle_type h, Args&&... args ) 88 94 { 89 index_type i = m_index .insert( h );95 index_type i = m_index->insert( h ); 90 96 NV_ASSERT( i == index_type( m_storage->size() ), "Fail!" ); 91 97 NV_UNUSED( i ); … … 102 108 bool exists( handle_type h ) 103 109 { 104 return m_index .exists( h );110 return m_index->exists( h ); 105 111 } 106 112 107 113 void call_destroy( value_type* data ) 108 114 { 109 for ( auto dh : m_destroy )115 for ( auto dh : this->m_destroy ) 110 116 dh( data ); 111 117 } … … 113 119 virtual void clear_() final 114 120 { 115 for ( uint32 i = 0; i < m_storage->size(); ++i ) 116 call_destroy( &(*m_storage)[i] ); 117 m_index.clear();121 m_index->clear(); 122 for ( uint32 i = 0; i < m_storage->size(); ++i ) 123 call_destroy( &( *m_storage )[i] ); 118 124 m_storage->clear(); 119 125 } … … 121 127 value_type* get( handle_type h ) 122 128 { 123 index_type i = m_index .get( h );129 index_type i = m_index->get( h ); 124 130 return i >= 0 ? &( ( *m_storage )[unsigned( i )] ) : nullptr; 125 131 } 126 132 const value_type* get( handle_type h ) const 127 133 { 128 index_type i = m_index .get( h );134 index_type i = m_index->get( h ); 129 135 return i >= 0 ? &( ( *m_storage )[unsigned( i )] ) : nullptr; 130 136 } … … 133 139 const void* get_raw( handle_type h ) const { return get( h ); } 134 140 135 virtual void remove ( handle_type h ) final141 virtual void remove_( handle_type h ) final 136 142 { 137 143 value_type* v = get( h ); 138 144 if ( v == nullptr ) return; 139 145 call_destroy( v ); 140 index_type dead_eindex = m_index .remove_swap( h );146 index_type dead_eindex = m_index->remove_swap( h ); 141 147 if ( dead_eindex == -1 ) return; 142 148 if ( dead_eindex != static_cast<index_type>( m_storage->size() - 1 ) ) … … 149 155 } 150 156 151 void remove_by_index ( index_typei )152 { 153 if ( i > size() ) return;157 void remove_by_index_( uint32 i ) 158 { 159 if ( i > m_storage->size() ) return; 154 160 call_destroy( &(*m_storage)[i] ); 155 index_type dead_eindex = m_index .remove_swap_by_index( i );161 index_type dead_eindex = m_index->remove_swap_by_index( i ); 156 162 if ( dead_eindex == -1 ) return; 157 163 if ( dead_eindex != static_cast<index_type>( m_storage->size() - 1 ) ) … … 164 170 } 165 171 166 template < typename F >167 void remove_if( F f )168 {169 uint32 i = 0;170 while ( i < size() )171 {172 auto& md = ( *m_storage )[i];173 if ( f( md ) )174 remove_by_index( i );175 else176 ++i;177 }178 }179 180 172 virtual void on_attach( handle_type, handle_type child ) final 181 173 { … … 186 178 } 187 179 188 ~component() 189 { 190 clear_(); 191 delete m_storage; 192 m_storage = nullptr; 180 virtual ~component() 181 { 182 //clear_(); 183 delete m_index; 193 184 } 194 185 195 inline const value_type& operator[] ( index_type i ) const { return ( *m_storage )[i]; }196 inline value_type& operator[] ( index_type i ) { return ( *m_storage )[i]; }197 198 186 inline size_t size() const { return m_storage->size(); } 199 200 inline iterator begin() { return m_storage->begin(); } 201 inline const_iterator begin() const { return m_storage->begin(); } 202 203 inline iterator end() { return m_storage->end(); } 204 inline const_iterator end() const { return m_storage->end(); } 205 206 inline virtual component_storage* storage() { return m_storage; } 187 inline virtual component_storage* storage() { return m_storage; } 207 188 protected: 208 189 ecs_type& m_ecs; … … 211 192 void swap( handle_type a, handle_type b ) 212 193 { 213 index_type ai = m_index .get( a );214 index_type bi = m_index .get( b );194 index_type ai = m_index->get( a ); 195 index_type bi = m_index->get( b ); 215 196 if ( ai < 0 || bi < 0 ) return; 216 m_index .swap( a, b );197 m_index->swap( a, b ); 217 198 value_type t = nv::move( ( *m_storage )[ai] ); 218 199 ( *m_storage )[ai] = nv::move( ( *m_storage )[bi] ); … … 225 206 } 226 207 227 void relational_remove( handle_type a )228 {229 index_type i = m_index.get( a );230 remove( a );231 relational_rebuild( i );232 }233 234 208 void relational_rebuild( index_type i ) 235 209 { … … 237 211 handle_type p = m_ecs.get_parent( h ); 238 212 if ( !p ) return; 239 if ( i < m_index .get( p ) )213 if ( i < m_index->get( p ) ) 240 214 { 241 215 swap( h, p ); … … 248 222 handle_type p = m_ecs.get_parent( h ); 249 223 if ( !p ) return; 250 if ( m_index .get( h ) < m_index.get( p ) )224 if ( m_index->get( h ) < m_index->get( p ) ) 251 225 { 252 226 swap( h, p ); … … 256 230 } 257 231 258 bool 259 i ndex_table_typem_index;232 bool m_relational; 233 idx_table* m_index; 260 234 }; 261 235 -
trunk/nv/ecs/ecs.hh
r550 r551 39 39 typedef ecs< Handle, MessageList, Time > this_type; 40 40 typedef Handle handle_type; 41 using base_type::time_type; 42 using base_type::message_type; 43 using base_type::message; 44 45 using update_handler = function< void( time_type ) >; 46 using destroy_handler = function< void( void* ) >; 47 using create_handler = function< void( handle_type, void*, const lua::stack_proxy& ) >; 41 typedef typename base_type::time_type time_type; 42 using typename base_type::message_list; 43 using typename base_type::message_type; 44 using typename base_type::message; 45 46 using destructor_handler = function< void() >; 47 using update_handler = function< void( time_type ) >; 48 using destroy_handler = function< void( void* ) >; 49 using create_handler = function< void( handle_type, void*, const lua::stack_proxy& ) >; 48 50 49 51 class component_interface … … 51 53 public: 52 54 virtual void clear_() = 0; 53 virtual void remove ( handle_type h ) = 0;55 virtual void remove_( handle_type h ) = 0; 54 56 virtual void on_attach( handle_type parent, handle_type child ) = 0; 55 57 virtual void* get_raw( handle_type h ) = 0; 56 58 virtual void* insert_raw( handle_type h ) = 0; 57 59 virtual const void* get_raw( handle_type h ) const = 0; 58 virtual component_storage* storage() = 0;59 60 virtual uint32 temp_index( handle_type h ) const = 0; 61 virtual void remove_by_index_( uint32 i ) = 0; 62 60 63 61 64 void run_create( handle_type h, const lua::stack_proxy& p ) … … 140 143 } 141 144 142 template < typename... Components >145 template < int, typename... Components > 143 146 struct gather_components 144 147 { … … 175 178 176 179 private: 177 template < int Index, typename C, typename... C omponents >180 template < int Index, typename C, typename... Cs > 178 181 void fill( this_type& ecs ) 179 182 { 180 183 cis[Index] = ecs.get_interface< C >(); 181 184 NV_ASSERT( cis[Index], "What the fuck is this?" ); 182 fill< Index + 1, C omponents... >( ecs );185 fill< Index + 1, Cs... >( ecs ); 183 186 } 184 187 … … 186 189 void fill( this_type& ) {} 187 190 188 template < int Index, typename SC, typename C, typename... C omponents >191 template < int Index, typename SC, typename C, typename... Cs > 189 192 C& run_get() 190 193 { 191 return get_impl< Index, SC, C, C omponents... >( nv::is_same< SC, C >{} );192 } 193 194 template < int Index, typename SC, typename C, typename C2, typename... C omponents >194 return get_impl< Index, SC, C, Cs... >( nv::is_same< SC, C >{} ); 195 } 196 197 template < int Index, typename SC, typename C, typename C2, typename... Cs > 195 198 C& get_impl( false_type&& ) 196 199 { 197 return get_impl< Index + 1, SC, C2, C omponents...>( nv::is_same< SC, C >() );198 } 199 200 template < int Index, typename SC, typename C, typename... C omponents >200 return get_impl< Index + 1, SC, C2, Cs...>( nv::is_same< SC, C >() ); 201 } 202 203 template < int Index, typename SC, typename C, typename... Cs > 201 204 C& get_impl( true_type&& ) 202 205 { … … 206 209 }; 207 210 208 template < >209 struct gather_components< >210 { 211 gather_components( this_type& ) {} ;211 template <int I> 212 struct gather_components<I> 213 { 214 gather_components( this_type& ) {} 212 215 bool run( handle_type ) { return true; } 213 216 template < typename Component > … … 215 218 }; 216 219 217 template< typename System > 218 void register_system( string_view name, System* c ) 219 { 220 register_handler< System >( name, (System*)( c ) ); 221 register_component_helper< System >( c, has_components< System >::type{} ); 222 register_ecs_update< System >( (System*)( c ), 223 has_ecs_update< this_type, System, time_type >::type{} ); 220 template< typename System, typename... Args > 221 System* register_system( string_view name, Args&&... args ) 222 { 223 System* result = new System( nv::forward< Args >( args )... ); 224 225 this->template register_handler< System >( name, (System*)( result ) ); 226 register_component_helper< System >( result, typename has_components< System >::type() ); 227 register_ecs_update< System >( (System*)( result ), 228 typename has_ecs_update< this_type, System, time_type >::type() ); 229 m_cleanup.emplace_back( [=] () { delete result; } ); 230 return result; 224 231 } 225 232 … … 227 234 void register_component_helper( System* c, true_type&& ) 228 235 { 229 using component_list = System::components; 230 register_component_messages< System, component_list >( c, message_list{} ); 231 register_ecs_component_update< System >( c, component_list{}, 232 has_ecs_component_update< this_type, System, component_list, time_type >::type{} ); 233 register_component_update< System >( c, component_list{}, 234 has_component_update< System, component_list, time_type >::type{} ); 236 using component_list = typename System::components; 237 register_component_messages< System, component_list >( c, message_list() ); 238 register_ecs_component_update< System >( c, component_list(), 239 typename has_ecs_component_update< this_type, System, component_list, time_type >::type() ); 240 register_component_update< System >( c, component_list(), 241 typename has_component_update< System, component_list, time_type >::type() ); 242 register_destroy< System, mpl::head<component_list> >( (System*)( c ), 243 typename has_destroy< System, mpl::head<component_list> >::type() ); 235 244 } 236 245 … … 241 250 242 251 template < typename Component, typename Handler > 243 void register_component( string_view name, component_interface* c ) 244 { 252 component_storage* register_component( string_view name, component_interface* c ) 253 { 254 auto s = new component_storage_handler< Component >; 255 m_cstorage.push_back( s ); 256 m_cmap[thash64::create<Component>()] = s; 257 m_cmap_by_name[name] = s; 258 245 259 m_components.push_back( c ); 246 260 m_component_map[thash64::create<Component>()] = c; 247 261 m_component_map_by_name[name] = c; 248 register_handler< Handler >( name, (Handler*)c );249 register_component_messages< Handler, mpl::list< Component > >( (Handler*)( c ), message_list {});250 register_ecs_component_update< Handler >( (Handler*)( c ), mpl::list< Component > {},251 has_ecs_component_update< this_type, Handler, mpl::list< Component >, time_type >::type{});252 register_component_update< Handler >( (Handler*)( c ), mpl::list< Component > {},253 has_component_update< Handler, mpl::list< Component >, time_type >::type{});262 this->template register_handler< Handler >( name, (Handler*)c ); 263 register_component_messages< Handler, mpl::list< Component > >( (Handler*)( c ), message_list() ); 264 register_ecs_component_update< Handler >( (Handler*)( c ), mpl::list< Component >(), 265 typename has_ecs_component_update< this_type, Handler, mpl::list< Component >, time_type >::type() ); 266 register_component_update< Handler >( (Handler*)( c ), mpl::list< Component >(), 267 typename has_component_update< Handler, mpl::list< Component >, time_type >::type() ); 254 268 register_ecs_update< Handler >( (Handler*)( c ), 255 has_ecs_update< this_type, Handler, time_type >::type{});269 typename has_ecs_update< this_type, Handler, time_type >::type() ); 256 270 register_destroy< Handler, Component >( (Handler*)( c ), 257 has_destroy< Handler, Component >::type{});271 typename has_destroy< Handler, Component >::type() ); 258 272 register_create< Handler, Component, handle_type >( (Handler*)( c ), 259 has_create< Handler, Component, handle_type >::type{} ); 260 // auto s = c->storage(); 261 // m_cstorage.push_back( s ); 262 // m_cmap[thash64::create<Component>()] = s; 263 // m_cmap_by_name[name] = s; 273 typename has_create< Handler, Component, handle_type >::type() ); 274 275 return s; 276 } 277 278 template < typename ComponentManager, typename ...Args > 279 ComponentManager* register_component_manager( Args&&... args ) 280 { 281 ComponentManager* result = new ComponentManager( *this, nv::forward< Args >( args )... ); 282 m_cleanup.emplace_back( [=] () { delete result; } ); 283 return result; 264 284 } 265 285 … … 271 291 void update( time_type dtime ) 272 292 { 273 update_time( dtime );293 this->update_time( dtime ); 274 294 for ( auto u : m_update_handlers ) 275 295 u( dtime ); 296 for ( auto h : m_dead_handles ) 297 remove( h ); 298 m_dead_handles.clear(); 276 299 } 277 300 278 301 void clear() 279 302 { 280 reset_events();303 this->reset_events(); 281 304 for ( auto c : m_components ) 282 305 c->clear_(); … … 286 309 ~ecs() 287 310 { 311 for ( auto s : m_cstorage ) 312 delete s; 313 m_cstorage.clear(); 288 314 // for ( auto cs : m_component_storage ) 289 315 // delete cs; 290 316 // m_cstorage.clear(); 291 317 // reverse order delete; 318 if ( !m_cleanup.empty() ) 319 for ( int i = (int)m_cleanup.size() - 1; i >= 0; --i ) 320 m_cleanup[i](); 321 m_cleanup.clear(); 292 322 } 293 323 … … 343 373 } 344 374 375 template < typename C, typename F > 376 void remove_component_if( F&& f ) 377 { 378 auto storage = get_storage<C>(); 379 auto temp_component = get_interface<C>(); 380 uint32 i = 0; 381 while ( i < storage->size() ) 382 if ( f( ( *storage )[i] ) ) 383 temp_component->remove_by_index_( i ); 384 else 385 ++i; 386 } 387 388 template < typename C> 389 void remove_component( handle_type h ) 390 { 391 auto temp_component = get_interface<C>(); 392 temp_component->remove_( h ); 393 } 394 395 template < typename C, typename F > 396 void for_each( F&& f ) 397 { 398 auto storage = get_storage<C>(); 399 NV_ASSERT( storage, "Invalid component" ); 400 for ( auto& c : *storage ) 401 { 402 f( c ); 403 } 404 } 405 406 345 407 template < typename F > 346 408 void recursive_call( handle_type h, F&& f ) … … 351 413 } 352 414 415 void mark_remove( handle_type h ) 416 { 417 m_dead_handles.push_back( h ); 418 } 419 353 420 void remove( handle_type h ) 354 421 { … … 360 427 } 361 428 for ( auto c : m_components ) 362 c->remove ( h );429 c->remove_( h ); 363 430 m_handles.free_handle( h ); 364 431 } … … 396 463 Component* get( handle_type h ) 397 464 { 398 return static_cast<Component*>( m_component_map[thash64::create< Component >()]->get_raw( h ) ); 465 auto it = m_component_map.find( thash64::create< Component >() ); 466 NV_ASSERT( it != m_component_map.end(), "Get fail!" ); 467 return static_cast<Component*>( it->second->get_raw( h ) ); 399 468 } 400 469 … … 402 471 const Component* get( handle_type h ) const 403 472 { 404 return static_cast<const Component*>( m_component_map[thash64::create< Component >()]->get_raw( h ) ); 405 } 406 407 template < typename Component > 408 typename component_storage_handler< Component >* 473 auto it = m_component_map.find( thash64::create< Component >() ); 474 NV_ASSERT( it != m_component_map.end(), "Get fail!" ); 475 return static_cast<const Component*>( it->second->get_raw( h ) ); 476 } 477 478 template < typename Component > 479 component_storage_handler< Component >* 409 480 get_storage() 410 481 { … … 413 484 414 485 template < typename Component > 415 const typenamecomponent_storage_handler< Component >*486 const component_storage_handler< Component >* 416 487 get_storage() const 417 488 { 418 489 return storage_cast<Component>( m_cmap[thash64::create< Component >()] ); 490 } 491 492 template < typename Component > 493 Component& add_component( handle_type h ) 494 { 495 component_interface* ci = get_interface<Component>(); 496 return *((Component*)ci->insert_raw( h )); 497 } 498 499 template < typename Component, typename ...Args > 500 Component& add_component( handle_type h, Args&&... args ) 501 { 502 component_interface* ci = get_interface<Component>(); 503 Component& result = *( (Component*)ci->insert_raw( h ) ); 504 result = Component{ nv::forward<Args>( args )... }; 505 return result; 419 506 } 420 507 … … 422 509 void register_component_messages( System* h, List<Messages...>&& ) 423 510 { 424 int unused_0[] = { ( register_ecs_component_message<System,Messages>( h, Components {} , has_ecs_component_message< this_type, System, Components, Messages >::type{}), 0 )... };425 int unused_1[] = { ( register_component_message<System,Messages>( h, Components {}, has_component_message< System, Components, Messages >::type{}), 0 )... };426 int unused_2[] = { ( register_ecs_message<System,Messages>( h, has_ecs_message< this_type, System, Messages >::type{}), 0 )... };427 } 428 511 int unused_0[] = { ( register_ecs_component_message<System,Messages>( h, Components() , typename has_ecs_component_message< this_type, System, Components, Messages >::type() ), 0 )... }; 512 int unused_1[] = { ( register_component_message<System,Messages>( h, Components(), typename has_component_message< System, Components, Messages >::type() ), 0 )... }; 513 int unused_2[] = { ( register_ecs_message<System,Messages>( h, typename has_ecs_message< this_type, System, Messages >::type() ), 0 )... }; 514 } 515 429 516 template < typename System, typename Message, typename C, typename... Cs > 430 517 void register_component_message( System* s, mpl::list< C, Cs...>&&, true_type&& ) … … 438 525 if ( void* c = ci->get_raw( h ) ) 439 526 { 440 gather_components< Cs... > gather( *this );527 gather_components<0, Cs... > gather( *this ); 441 528 if ( gather.run( h ) ) 442 s->on( m, *( (C*)( c ) ), gather. get<Cs>()... );529 s->on( m, *( (C*)( c ) ), gather.template get<Cs>()... ); 443 530 } 444 531 }; … … 462 549 if ( void* c = ci->get_raw( h ) ) 463 550 { 464 gather_components< Cs... > gather( *this );551 gather_components<0, Cs... > gather( *this ); 465 552 if ( gather.run( h ) ) 466 s->on( m, *this, *( (C*)( c ) ), gather. get<Cs>()... );553 s->on( m, *this, *( (C*)( c ) ), gather.template get<Cs>()... ); 467 554 } 468 555 }; … … 514 601 } 515 602 516 template < typename System, typename Component, typename H andle>603 template < typename System, typename Component, typename H > 517 604 void register_create( System* s, true_type&& ) 518 605 { 519 606 component_interface* ci = get_interface<Component>(); 520 607 NV_ASSERT( ci, "Unregistered component!" ); 521 ci->m_create.push_back( [=] ( H andleh, void* data, const lua::stack_proxy& p )608 ci->m_create.push_back( [=] ( H h, void* data, const lua::stack_proxy& p ) 522 609 { 523 610 s->create( h, *( (Component*)data ), p ); … … 529 616 void register_component_update( System* s, mpl::list< C, Cs...>&&, true_type&& ) 530 617 { 531 component_interface* ci = get_interface<C>(); 532 component_storage_handler<C>* storage = storage_cast<C>( ci->storage() ); 618 component_storage_handler<C>* storage = get_storage<C>(); 533 619 register_update( [=] ( time_type dtime ) 534 620 { 535 gather_components< Cs... > gather( *this );621 gather_components<0, Cs... > gather( *this ); 536 622 for ( auto& c : *storage ) 537 623 { 538 624 if ( gather.runc( c ) ) 539 s->update( c, gather. get<Cs>()..., dtime );625 s->update( c, gather.template get<Cs>()..., dtime ); 540 626 } 541 627 } ); … … 545 631 void register_ecs_component_update( System* s, mpl::list< C, Cs...>&&, true_type&& ) 546 632 { 547 component_interface* ci = get_interface<C>(); 548 component_storage_handler<C>* storage = storage_cast<C>( ci->storage() ); 633 component_storage_handler<C>* storage = get_storage<C>(); 549 634 register_update( [=] ( time_type dtime ) 550 635 { 551 gather_components< Cs... > gather(*this);636 gather_components<0, Cs... > gather(*this); 552 637 for ( auto& c : *storage ) 553 638 { 554 639 if ( gather.runc( c ) ) 555 s->update( *this, c, gather. get<Cs>()..., dtime );640 s->update( *this, c, gather.template get<Cs>()..., dtime ); 556 641 } 557 642 } ); … … 565 650 void register_destroy( System*, false_type&& ) {} 566 651 567 template < typename System, typename Component, typename H andle>652 template < typename System, typename Component, typename H > 568 653 void register_create( System*, false_type&& ) {} 569 654 … … 582 667 583 668 handle_tree_manager< handle_type > m_handles; 669 vector< handle_type > m_dead_handles; 584 670 vector< component_interface* > m_components; 585 671 hash_store< thash64, component_interface* > m_component_map; … … 587 673 vector< update_handler > m_update_handlers; 588 674 589 // vector< component_storage* > m_cstorage; 590 // hash_store< thash64, component_storage* > m_cmap; 591 // hash_store< shash64, component_storage* > m_cmap_by_name; 675 vector< component_storage* > m_cstorage; 676 hash_store< thash64, component_storage* > m_cmap; 677 hash_store< shash64, component_storage* > m_cmap_by_name; 678 679 vector< component_interface* > m_temp_components; 680 vector< destructor_handler > m_cleanup; 592 681 }; 593 682 -
trunk/nv/ecs/message_queue.hh
r550 r551 84 84 } 85 85 86 template<> 87 void register_handler<void>( string_view /*name*/, void* ) 86 void register_handler( string_view /*name*/, void* ) 88 87 { 89 88 } … … 123 122 message m{ Payload::message_id, 0, m_time + delay }; 124 123 new( &m.payload ) Payload{ nv::forward<Args>( args )... }; 124 return queue( m ); 125 } 126 127 // FIXME: Clang hack 128 template < typename Payload > 129 bool queue( time_type delay, Payload&& arg ) 130 { 131 message m{ Payload::message_id, 0, m_time + delay }; 132 new( &m.payload ) Payload( arg ); 125 133 return queue( m ); 126 134 } -
trunk/nv/engine/mesh_manager.hh
r509 r551 79 79 string_view resolve( shash64 h ) { return ( *m_strings )[h]; } 80 80 resource< data_channel_set > get_path( const string_view& path, 81 resource< mesh_data > def ault= resource< mesh_data >(),81 resource< mesh_data > def = resource< mesh_data >(), 82 82 data_node_info* info = nullptr ); 83 83 -
trunk/nv/engine/resource_system.hh
r524 r551 194 194 virtual resource< T > load_resource( source_type u ) 195 195 { 196 if ( exists( u.id() ) ) return this->template create< T >( u.id() );196 if ( this->exists( u.id() ) ) return this->template create< T >( u.id() ); 197 197 return create_resource( u ); 198 198 } -
trunk/nv/interface/context.hh
r550 r551 272 272 vertex_array create_vertex_array( const VTX* v, uint32 vcount, const IDX* i, uint32 icount, buffer_hint hint ) 273 273 { 274 buffer vb = this->create_buffer( VERTEX_BUFFER, hint, count * sizeof( VTX ), v );274 buffer vb = this->create_buffer( VERTEX_BUFFER, hint, vcount * sizeof( VTX ), v ); 275 275 buffer ib = this->create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i ); 276 276 vertex_array_desc desc; -
trunk/nv/interface/physics_world.hh
r528 r551 24 24 { 25 25 public: 26 explicitcollision_shape( void* p = nullptr, void* m = nullptr ) : internal( p ), mesh( m ) {}26 collision_shape( void* p = nullptr, void* m = nullptr ) : internal( p ), mesh( m ) {} 27 27 void* internal = nullptr; 28 28 void* mesh = nullptr; … … 33 33 { 34 34 public: 35 explicitrigid_body( void* p = nullptr ) : internal( p ) {}35 rigid_body( void* p = nullptr ) : internal( p ) {} 36 36 void* internal = nullptr; 37 37 }; … … 40 40 { 41 41 public: 42 explicitconstraint( void* p = nullptr ) : internal( p ) {}42 constraint( void* p = nullptr ) : internal( p ) {} 43 43 void* internal = nullptr; 44 44 }; -
trunk/nv/lua/lua_handle.hh
r395 r551 10 10 #include <nv/common.hh> 11 11 #include <nv/stl/handle.hh> 12 #include <nv/stl/handle_manager.hh> 12 13 #include <nv/lua/lua_values.hh> 13 14 -
trunk/nv/lua/lua_proxy.hh
r540 r551 12 12 #include <nv/stl/string.hh> 13 13 #include <nv/stl/string_table.hh> 14 #include <nv/lua/lua_values.hh> 14 15 15 16 namespace nv … … 87 88 bool read( T& t ) const 88 89 { 89 NV_ASSERT( m_state->get_type_data(), "stack_proxy::read - type database not created!" ); 90 const type_database* tdb = m_state->get_type_data()->get_type_database(); 90 const type_database* tdb = get_type_db(); 91 91 NV_ASSERT( tdb, "stack_proxy::read - type database not set!" ); 92 92 const type_entry* entry = tdb->get_type<T>(); … … 100 100 // string_view to_string_view(); 101 101 protected: 102 const type_database* get_type_db() const; 103 102 104 // Not public because not permanent 103 105 string_view get_string_view() const; -
trunk/nv/lua/lua_state.hh
r540 r551 57 57 } 58 58 const type_database* get_type_database() const { return m_type_database; } 59 type_database* get_type_database() { return m_type_database; } 59 60 60 61 template < typename T > … … 204 205 205 206 const type_data* get_type_data() const { return m_lua_types; } 206 207 208 207 type_data* get_type_data() { return m_lua_types; } 209 208 210 209 protected: -
trunk/nv/stl/flags.hh
r508 r551 227 227 } 228 228 229 template < uint32 S IZE, typename T>230 inline friend flags< S IZE, T > operator &( const flags< SIZE, T >& lhs, const flags< SIZE, T>& rhs );231 232 template < uint32 S IZE, typename T>233 inline friend flags< S IZE, T > operator |( const flags< SIZE, T >& lhs, const flags< SIZE, T>& rhs );229 template < uint32 S, typename T2 > 230 inline friend flags< S, T2 > operator &( const flags< S, T2 >& lhs, const flags< S, T2 >& rhs ); 231 232 template < uint32 S, typename T2 > 233 inline friend flags< S, T2 > operator |( const flags< S, T2 >& lhs, const flags< S, T2 >& rhs ); 234 234 235 235 private: -
trunk/nv/stl/functional/hash.hh
r533 r551 86 86 }; 87 87 88 // template < typename T > 89 // struct hash< T*, uintptr_t > : detail::hash_base< T, uintptr_t > 90 // { 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 ); } 93 // }; 94 88 95 template < typename T > 89 struct hash< T*, uintptr_t > : detail::hash_base< T, uintptr_t > 90 { 91 inline uintptr_t operator()( T* value ) const { return reinterpret_cast<uintptr_t>( value ); } 96 struct hash< T, uintptr_t, 97 typename enable_if< is_function_pointer< T >::value, 98 void 99 >::type > : detail::hash_base< T, uintptr_t > 100 { 101 inline uintptr_t operator()( T value ) const { return reinterpret_cast<uintptr_t>( value ); } 92 102 static constexpr uintptr_t get( T value ) { return reinterpret_cast<uintptr_t>( value ); } 93 103 }; -
trunk/nv/stl/handle_manager.hh
r536 r551 25 25 { 26 26 public: 27 typedef typename Handlehandle_type;27 typedef Handle handle_type; 28 28 typedef typename handle_type::value_type value_type; 29 29 -
trunk/nv/stl/handle_store.hh
r543 r551 39 39 { 40 40 m_data.reserve( reserve ); 41 m_index es.reserve( reserve );41 m_index.reserve( reserve ); 42 42 } 43 43 … … 98 98 private: 99 99 storage_type m_data; 100 index_table< handle_type, index_type > m_index;100 flat_index_table< handle_type, index_type > m_index; 101 101 }; 102 102 -
trunk/nv/stl/index_table.hh
r545 r551 31 31 typedef Index index_type; 32 32 33 index_table() {} 34 index_table( uint32 reserve ) 33 virtual index_type insert( handle_type h ) = 0; 34 virtual bool exists( handle_type h ) const = 0; 35 virtual index_type get( handle_type h ) const = 0; 36 virtual void swap( handle_type a, handle_type b ) = 0; 37 virtual index_type remove_swap( handle_type h ) = 0; 38 virtual index_type remove_swap_by_index( index_type dead_eindex ) = 0; 39 virtual void clear() = 0; 40 virtual uint32 size() const = 0; 41 }; 42 43 44 template < 45 typename Handle, 46 typename Index = sint32 47 > 48 class flat_index_table : public index_table< Handle, Index > 49 { 50 public: 51 typedef Handle handle_type; 52 typedef Index index_type; 53 54 flat_index_table() {} 55 flat_index_table( uint32 reserve ) 35 56 { 36 57 m_indexes.reserve( reserve ); … … 129 150 typename Index = sint32 130 151 > 131 class hashed_index_table 152 class hashed_index_table : public index_table< Handle, Index > 132 153 { 133 154 public: -
trunk/nv/stl/math/geometric.hh
r550 r551 69 69 inline T inv_length( T v ) 70 70 { 71 return T( 1 ) / abs( x);71 return T( 1 ) / abs( v ); 72 72 } 73 73 -
trunk/nv/stl/range.hh
r537 r551 85 85 static const T invalid = T( 0 ); 86 86 87 bits_iterator_base( T value, T current ) : forward_iterator_base<T>( current ), m_full( value )87 bits_iterator_base( T value, T current ) : value_enumerator_base<T>( current ), m_full( value ) 88 88 { 89 89 if( !( static_cast<base_type>( value ) & static_cast<base_type>( current ) ) ) -
trunk/nv/stl/type_traits/common.hh
r550 r551 29 29 }; 30 30 31 template < typename T >32 constexpr T integral_constant_v = integral_constant<T>::value;33 34 31 // TODO: Propagate 35 32 template< bool B > … … 38 35 typedef bool_constant<true> true_type; 39 36 typedef bool_constant<false> false_type; 40 41 template < typename T >42 constexpr T bool_constant_v = bool_constant<T>::value;43 37 44 38 template< bool Test, typename T = void> -
trunk/nv_bullet.lua
r533 r551 28 28 29 29 includedirs { "D:/Libraries/bullet2/src/" } 30 31 configuration "debug"30 31 filter { "configurations:debug", "platforms:*32" } 32 32 nv_bullet_configure( "D:/Libraries/bullet2/x86/", "RelWithDebInfo", "_rdbg" ) 33 33 -- nv_bullet_configure( "D:/Libraries/bullet2/x86/", "Debug", "_debug" ) 34 34 35 configuration "profiler"35 filter { "configurations:profiler", "platforms:*32" } 36 36 nv_bullet_configure( "D:/Libraries/bullet2/x86/", "Release" ) 37 37 38 configuration "release"38 filter { "configurations:release", "platforms:*32" } 39 39 nv_bullet_configure( "D:/Libraries/bullet2/x86/", "Release" ) 40 40 41 configuration "debug_64"41 filter { "configurations:debug", "platforms:*64" } 42 42 nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "RelWithDebInfo", "_rdbg" ) 43 43 -- nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "Debug", "_debug" ) 44 44 45 configuration "profiler_64"45 filter { "configurations:profiler", "platforms:*64" } 46 46 nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "Release" ) 47 47 48 configuration "release_64"48 filter { "configurations:release", "platforms:*64" } 49 49 nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "Release" ) 50 50 51 filter {} 51 52 52 -
trunk/premake5.lua
r362 r551 1 solution"nv"1 workspace "nv" 2 2 configurations { "debug", "release" } 3 3 targetdir "bin" -
trunk/src/engine/mesh_manager.cc
r534 r551 29 29 } 30 30 31 nv::resource< nv::data_channel_set > nv::mesh_data_manager::get_path( const string_view& path, resource< mesh_data > def ault/*= resource< mesh_data >()*/, data_node_info* info /*= nullptr */ )31 nv::resource< nv::data_channel_set > nv::mesh_data_manager::get_path( const string_view& path, resource< mesh_data > def /*= resource< mesh_data >()*/, data_node_info* info /*= nullptr */ ) 32 32 { 33 nv::resource< nv::mesh_data > mr = def ault;33 nv::resource< nv::mesh_data > mr = def; 34 34 35 35 nv::string_view sub_mesh_name; -
trunk/src/image/png_writer.cc
r534 r551 12 12 #include <stdarg.h> 13 13 14 using namespace nv;14 //using namespace nv; 15 15 16 16 #if NV_COMPILER == NV_CLANG … … 33 33 }; 34 34 35 #define STBI_MALLOC(sz) nv malloc(sz)36 #define STBI_REALLOC(p,sz) nv realloc(p,sz)37 #define STBI_FREE(p) nv free(p)38 #define STBI_MEMMOVE(d,s,c) nv memmove(d,s,c)35 #define STBI_MALLOC(sz) nv::nvmalloc(sz) 36 #define STBI_REALLOC(p,sz) nv::nvrealloc(p,sz) 37 #define STBI_FREE(p) nv::nvfree(p) 38 #define STBI_MEMMOVE(d,s,c) nv::nvmemmove(d,s,c) 39 39 40 40 typedef void stbi_write_func( void *context, void *data, int size ); … … 57 57 58 58 template < typename T > 59 inline uchar8 byte_cast( T x )60 { 61 return uchar8( ( x ) & 255 );59 inline nv::uchar8 byte_cast( T x ) 60 { 61 return nv::uchar8( ( x ) & 255 ); 62 62 } 63 63 … … 246 246 } 247 247 248 static int iabs( int i ) 249 { 250 return i >= 0 ? i : -i; 251 } 252 248 253 static unsigned char stbiw__paeth( int a, int b, int c ) 249 254 { 250 int p = a + b - c, pa = abs( p - a ), pb = abs( p - b ), pc =abs( p - c );255 int p = a + b - c, pa = iabs( p - a ), pb = iabs( p - b ), pc = iabs( p - c ); 251 256 if ( pa <= pb && pa <= pc ) return byte_cast( a ); 252 257 if ( pb <= pc ) return byte_cast( b ); … … 320 325 if ( p ) break; 321 326 for ( i = 0; i < x*n; ++i ) 322 est += abs( (signed char)line_buffer[i] );327 est += iabs( (signed char)line_buffer[i] ); 323 328 if ( est < bestval ) { bestval = est; best = k; } 324 329 } -
trunk/src/lua/lua_proxy.cc
r541 r551 76 76 } 77 77 78 const nv::type_database* nv::lua::stack_proxy::get_type_db() const 79 { 80 NV_ASSERT( m_state->get_type_data(), "type database not created!" ); 81 return m_state->get_type_data()->get_type_database(); 82 } 83 78 84 nv::string_view nv::lua::stack_proxy::get_string_view() const 79 85 {
Note: See TracChangeset
for help on using the changeset viewer.