- Timestamp:
- 02/11/17 01:25:20 (8 years ago)
- Location:
- trunk/nv/ecs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/ecs/ecs.hh
r548 r549 234 234 } 235 235 236 template< typename Component > 237 bool runc( Component& c ) 238 { 239 return run( *reinterpret_cast<const handle_type*>( &c ) ); 240 } 241 236 242 template < typename SC > 237 243 SC& get() … … 272 278 }; 273 279 280 template <> 281 struct gather_components<> 282 { 283 gather_components( this_type& ) {}; 284 bool run( handle_type ) { return true; } 285 template < typename Component > 286 bool runc( Component& ) { return true; } 287 }; 274 288 275 289 template< typename System > … … 280 294 has_ecs_update< this_type, System, time_type >::type{} ); 281 295 } 282 283 296 284 297 template < typename Component, typename Handler > … … 290 303 register_handler< Handler >( name, (Handler*)c ); 291 304 register_component_messages< Handler, mpl::list< Component > >( (Handler*)( c ), message_list{} ); 292 register_ecs_component_update< Handler >( (Handler*)( c ), mpl::list< Component >{} ); 293 register_component_update< Handler >( (Handler*)( c ), mpl::list< Component >{} ); 305 register_ecs_component_update< Handler >( (Handler*)( c ), mpl::list< Component >{}, 306 has_ecs_component_update< this_type, Handler, mpl::list< Component >, time_type >::type{} ); 307 register_component_update< Handler >( (Handler*)( c ), mpl::list< Component >{}, 308 has_component_update< Handler, mpl::list< Component >, time_type >::type{} ); 294 309 register_ecs_update< Handler >( (Handler*)( c ), 295 310 has_ecs_update< this_type, Handler, time_type >::type{} ); … … 447 462 void register_component_messages( System* h, List<Messages...>&& ) 448 463 { 449 int unused_0[] = { ( register_ecs_component_message<System,Messages>( h, Components{} ), 0 )... }; 450 int unused_1[] = { ( register_component_message<System,Messages>( h, Components{} ), 0 )... }; 451 int unused_2[] = { ( register_ecs_message<System,Messages>( h ), 0 )... }; 452 } 453 454 template < typename System, typename Message, typename C > 455 typename enable_if< has_component_message< System, mpl::list< C >, Message >::value, void >::type 456 register_component_message( System* s, mpl::list< C >&& ) 457 { 458 component_interface* ci = get_interface<C>(); 459 register_callback( Message::message_id, [=] ( const message& msg ) 460 { 461 const Message& m = message_cast<Message>( msg ); 462 auto callback = [=] ( handle_type h ) 463 { 464 if ( void* c = ci->get_raw( h ) ) 465 s->on( m, *( (C*)( c ) ) ); 466 }; 467 if ( msg.recursive ) 468 this->recursive_call( m.entity, nv::move( callback ) ); 469 else 470 callback( m.entity ); 471 } ); 464 int unused_0[] = { ( register_ecs_component_message<System,Messages>( h, Components{} , has_ecs_component_message< this_type, System, Components, Messages >::type{} ), 0 )... }; 465 int unused_1[] = { ( register_component_message<System,Messages>( h, Components{}, has_component_message< System, Components, Messages >::type{} ), 0 )... }; 466 int unused_2[] = { ( register_ecs_message<System,Messages>( h, has_ecs_message< this_type, System, Messages >::type{} ), 0 )... }; 472 467 } 473 468 474 469 template < typename System, typename Message, typename C, typename... Cs > 475 typename enable_if< has_component_message< System, mpl::list< C, Cs...>, Message >::value, void >::type 476 register_component_message( System* s, mpl::list< C, Cs...>&& ) 470 void register_component_message( System* s, mpl::list< C, Cs...>&&, true_type&& ) 477 471 { 478 472 component_interface* ci = get_interface<C>(); … … 497 491 } 498 492 499 template < typename System, typename Message, typename C >500 typename enable_if< has_ecs_component_message< this_type, System, mpl::list< C >, Message >::value, void >::type501 register_ecs_component_message( System* s, mpl::list< C >&& )502 {503 component_interface* ci = get_interface<C>();504 register_callback( Message::message_id, [=] ( const message& msg )505 {506 const Message& m = message_cast<Message>( msg );507 auto callback = [=] ( handle_type h )508 {509 if ( void* c = ci->get_raw( h ) )510 s->on( m, *this, *( (C*)( c ) ) );511 };512 if ( msg.recursive )513 this->recursive_call( m.entity, nv::move( callback ) );514 else515 callback( m.entity );516 } );517 518 }519 520 493 template < typename System, typename Message, typename C, typename... Cs > 521 typename enable_if< has_ecs_component_message< this_type, System, mpl::list< C, Cs...>, Message >::value, void >::type 522 register_ecs_component_message( System* s, mpl::list< C, Cs...>&& ) 494 void register_ecs_component_message( System* s, mpl::list< C, Cs...>&&, true_type&& ) 523 495 { 524 496 component_interface* ci = get_interface<C>(); … … 543 515 } 544 516 template < typename System, typename Message > 545 typename enable_if< has_ecs_message< this_type, System, Message >::value, void >::type 546 register_ecs_message( System* s ) 517 void register_ecs_message( System* s, true_type&& ) 547 518 { 548 519 register_callback( Message::message_id, [=] ( const message& msg ) … … 554 525 555 526 template < typename System, typename Message, typename... Cs > 556 typename enable_if< !has_component_message< System, mpl::list< Cs...>, Message >::value, void >::type 557 register_component_message( System*, mpl::list< Cs...>&& ) {} 527 void register_component_message( System*, mpl::list< Cs...>&&, false_type&& ) {} 558 528 559 529 template < typename System, typename Message, typename... Cs > 560 typename enable_if< !has_ecs_component_message< this_type, System, mpl::list< Cs...>, Message >::value, void >::type 561 register_ecs_component_message( System*, mpl::list< Cs...>&& ) {} 530 void register_ecs_component_message( System*, mpl::list< Cs...>&&, false_type&& ) {} 562 531 563 532 template < typename System, typename Message > 564 typename enable_if< !has_ecs_message< this_type, System, Message >::value, void >::type 565 register_ecs_message( System* ) {} 533 void register_ecs_message( System*, false_type&& ) {} 566 534 567 535 template < typename System > … … 574 542 } 575 543 576 template < typename System, typename C > 577 typename enable_if< has_component_update< System, mpl::list< C >, time_type >::value, void >::type 578 register_component_update( System* s, mpl::list< C >&& ) 544 template < typename System, typename C, typename... Cs > 545 void register_component_update( System* s, mpl::list< C, Cs...>&&, true_type&& ) 579 546 { 580 547 component_interface* ci = get_interface<C>(); … … 582 549 register_update( [=] ( time_type dtime ) 583 550 { 551 gather_components< Cs... > gather( *this ); 584 552 for ( auto& c : *storage ) 585 s->update( c, dtime ); 553 { 554 if ( gather.runc( c ) ) 555 s->update( c, gather.get<Cs>()..., dtime ); 556 } 586 557 } ); 587 558 } 588 559 589 560 template < typename System, typename C, typename... Cs > 590 typename enable_if< has_component_update< System, mpl::list< C, Cs...>, time_type >::value, void >::type 591 register_component_update( System* s, mpl::list< C, Cs...>&& ) 561 void register_ecs_component_update( System* s, mpl::list< C, Cs...>&&, true_type&& ) 592 562 { 593 563 component_interface* ci = get_interface<C>(); … … 595 565 register_update( [=] ( time_type dtime ) 596 566 { 597 gather_components< Cs... > gather( *this );598 for ( auto& c : *storage )599 {600 handle_type h = handle_cast( c );601 if ( gather.run( h ) )602 s->update( c, gather.get<Cs>()..., dtime );603 }604 } );605 }606 607 template < typename System, typename C >608 typename enable_if< has_ecs_component_update< this_type, System, mpl::list< C >, time_type >::value, void >::type609 register_ecs_component_update( System* s, mpl::list< C >&& )610 {611 component_interface* ci = get_interface<C>();612 component_storage_handler<C>* storage = storage_cast<C>( ci->storage() );613 register_update( [=] ( time_type dtime )614 {615 for ( auto& c : *storage )616 s->update( *this, c, dtime );617 } );618 }619 620 621 622 template < typename System, typename C, typename... Cs >623 typename enable_if< has_ecs_component_update< this_type, System, mpl::list< C, Cs...>, time_type >::value, void >::type624 register_ecs_component_update( System* s, mpl::list< C, Cs...>&& )625 {626 component_interface* ci = get_interface<C>();627 component_storage_handler<C>* storage = storage_cast<C>( ci->storage() );628 register_update( [=] ( time_type dtime )629 {630 567 gather_components< Cs... > gather(*this); 631 568 for ( auto& c : *storage ) 632 569 { 633 handle_type h = handle_cast( c ); 634 if ( gather.run( h ) ) 570 if ( gather.runc( c ) ) 635 571 s->update( *this, c, gather.get<Cs>()..., dtime ); 636 572 } … … 643 579 644 580 template < typename System, typename... Cs > 645 typename enable_if< !has_component_update< System, mpl::list< Cs...>, time_type >::value, void >::type 646 register_component_update( System*, mpl::list< Cs...>&& ) {} 581 void register_component_update( System*, mpl::list< Cs...>&&, false_type&& ) {} 647 582 648 583 template < typename System, typename... Cs > 649 typename enable_if< !has_ecs_component_update< this_type, System, mpl::list< Cs...>, time_type >::value, void >::type 650 register_ecs_component_update( System*, mpl::list< Cs...>&& ) {} 584 void register_ecs_component_update( System*, mpl::list< Cs...>&&, false_type&& ) {} 651 585 652 586 void register_update( update_handler&& handler ) -
trunk/nv/ecs/message_queue.hh
r547 r549 47 47 static constexpr nv::false_type check( ... ); 48 48 49 public: 49 50 typedef decltype( check<C>( 0 ) ) type; 50 51 51 public:52 52 static constexpr bool value = type::value; 53 53 };
Note: See TracChangeset
for help on using the changeset viewer.