Changeset 549


Ignore:
Timestamp:
02/11/17 01:25:20 (8 years ago)
Author:
epyon
Message:
  • cleanup of ecs.hh
Location:
trunk/nv/ecs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/ecs/ecs.hh

    r548 r549  
    234234                                }
    235235
     236                                template< typename Component >
     237                                bool runc( Component& c )
     238                                {
     239                                        return run( *reinterpret_cast<const handle_type*>( &c ) );
     240                                }
     241
    236242                                template < typename SC >
    237243                                SC& get()
     
    272278                        };
    273279
     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                        };
    274288
    275289                        template< typename System >
     
    280294                                        has_ecs_update< this_type, System, time_type >::type{} );
    281295                        }
    282 
    283296
    284297                        template < typename Component, typename Handler >
     
    290303                                register_handler< Handler >( name, (Handler*)c );
    291304                                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{} );
    294309                                register_ecs_update< Handler >( (Handler*)( c ),
    295310                                        has_ecs_update< this_type, Handler, time_type >::type{} );
     
    447462                        void register_component_messages( System* h, List<Messages...>&& )
    448463                        {
    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 )... };
    472467                        }
    473468
    474469                        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&& )
    477471                        {
    478472                                component_interface* ci = get_interface<C>();
     
    497491                        }
    498492
    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 >::type
    501                                 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                                         else
    515                                                 callback( m.entity );
    516                                 } );
    517 
    518                         }
    519 
    520493                        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&& )
    523495                        {
    524496                                component_interface* ci = get_interface<C>();
     
    543515                        }
    544516                        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&& )
    547518                        {
    548519                                register_callback( Message::message_id, [=] ( const message& msg )
     
    554525
    555526                        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&& ) {}
    558528
    559529                        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&& ) {}
    562531
    563532                        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&& ) {}
    566534
    567535                        template < typename System >
     
    574542                        }
    575543
    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&& )
    579546                        {
    580547                                component_interface* ci = get_interface<C>();
     
    582549                                register_update( [=] ( time_type dtime )
    583550                                {
     551                                        gather_components< Cs... > gather( *this );
    584552                                        for ( auto& c : *storage )
    585                                                 s->update( c, dtime );
     553                                        {
     554                                                if ( gather.runc( c ) )
     555                                                        s->update( c, gather.get<Cs>()..., dtime );
     556                                        }
    586557                                } );
    587558                        }
    588559
    589560                        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&& )
    592562                        {
    593563                                component_interface* ci = get_interface<C>();
     
    595565                                register_update( [=] ( time_type dtime )
    596566                                {
    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 >::type
    609                         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 >::type
    624                                 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                                 {
    630567                                        gather_components< Cs... > gather(*this);
    631568                                        for ( auto& c : *storage )
    632569                                        {
    633                                                 handle_type h = handle_cast( c );
    634                                                 if ( gather.run( h ) )
     570                                                if ( gather.runc( c ) )
    635571                                                        s->update( *this, c, gather.get<Cs>()..., dtime );
    636572                                        }
     
    643579
    644580                        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&& ) {}
    647582
    648583                        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&& ) {}
    651585
    652586                        void register_update( update_handler&& handler )
  • trunk/nv/ecs/message_queue.hh

    r547 r549  
    4747                                static constexpr nv::false_type check( ... );
    4848
     49                        public:
    4950                                typedef decltype( check<C>( 0 ) ) type;
    5051
    51                         public:
    5252                                static constexpr bool value = type::value;
    5353                        };
Note: See TracChangeset for help on using the changeset viewer.