Changeset 551 for trunk


Ignore:
Timestamp:
03/14/17 16:44:18 (8 years ago)
Author:
epyon
Message:
  • clang compatibility
  • ecs upgrades
Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv.lua

    r537 r551  
    112112        links { "nv-core", "nv-lib", "nv-io", "nv-gfx", "nv-lua" }
    113113
     114--[[
    114115-- injection!
    115116solution( solution().name )
    116117        configuration "gmake"
    117                 if _ACTION == "gmake-clang" then
     118                if CLANG then
    118119                        buildoptions {
    119                                 "-std=c++1z",
     120                                "-std=c++14",
    120121--                                -- on Mac OS X don't try to use old stdc++
    121122--                                "-stdlib=libc++",
    122                                 "-Weverything",
     123--                              "-Weverything",
    123124                                -- math is so much easier with these
     125                                "-w",
    124126                                "-Wno-gnu-anonymous-struct",
    125127                                "-Wno-nested-anon-types",
     
    163165
    164166if _ACTION == "gmake-clang" then
    165         premake.gcc.cc  = "clang"
    166         premake.gcc.cxx = "clang++"
     167        toolset "clang"
    167168        _ACTION = "gmake"
    168169end
     
    178179        end
    179180end
     181
     182--]]
  • trunk/nv/base/common.hh

    r533 r551  
    184184#endif
    185185
     186#if NV_COMPILER != NV_MSVC
     187#define NULL 0
     188#endif
     189
    186190namespace nv
    187191{
  • trunk/nv/core/resource.hh

    r513 r551  
    221221                        shash64 hid( id );
    222222                        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 );
    224224                        NV_ASSERT( false, "resource_manager.get failed!" );
    225225                        return resource< T >();
     
    234234                        if ( m->second->exists( hid ) )
    235235                        {
    236                                 return m->second->create< T >( hid );
     236                                return m->second->template create< T >( hid );
    237237                        }
    238238                        NV_ASSERT( false, "resource_manager.get failed!" );
     
    246246                        NV_ASSERT( m != m_handlers.end(), "Resource type unrecognized!" );
    247247                        m->second->raw_add( id, value );
    248                         return m->second->create< T >( id );
     248                        return m->second->template create< T >( id );
    249249                }
    250250
  • trunk/nv/ecs/component.hh

    r550 r551  
    3737                        typename Component,
    3838                        typename Handler,
    39                         template < typename, typename > class IndexTable = index_table
     39                        template < typename, typename > class IndexTable = flat_index_table
    4040                >
    4141                class component : public Ecs::component_interface
     
    4747                        typedef typename ecs_type::time_type            time_type;
    4848                        typedef IndexTable< handle_type, sint32 >       index_table_type;
     49                        typedef index_table< handle_type, sint32 >      idx_table;
    4950                        typedef Component                               value_type;
    5051                        typedef Component                               component_type;
     
    5859                        typedef typename storage_type::const_reference  const_reference;
    5960
    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 )
    6162                                : m_ecs( a_ecs ), m_relational( relational ), m_storage( nullptr )
    6263                        {
    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
    6975                        }
    7076
    7177                        virtual uint32 temp_index( handle_type h ) const  final
    7278                        {
    73                                 return m_index.get( h );
     79                                return m_index->get( h );
    7480                        }
    7581
     
    7783                        inline value_type& insert( handle_type h )
    7884                        {
    79                                 index_type i = m_index.insert( h );
     85                                index_type i = m_index->insert( h );
    8086                                NV_ASSERT( i == index_type( m_storage->size() ), "Fail!" );
    8187                                NV_UNUSED( i );
     
    8793                        value_type& insert( handle_type h, Args&&... args )
    8894                        {
    89                                 index_type i = m_index.insert( h );
     95                                index_type i = m_index->insert( h );
    9096                                NV_ASSERT( i == index_type( m_storage->size() ), "Fail!" );
    9197                                NV_UNUSED( i );
     
    102108                        bool exists( handle_type h )
    103109                        {
    104                                 return m_index.exists( h );
     110                                return m_index->exists( h );
    105111                        }
    106112
    107113                        void call_destroy( value_type* data )
    108114                        {
    109                                 for ( auto dh : m_destroy )
     115                                for ( auto dh : this->m_destroy )
    110116                                        dh( data );
    111117                        }
     
    113119                        virtual void clear_() final
    114120                        {
    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] );
    118124                                m_storage->clear();
    119125                        }
     
    121127                        value_type* get( handle_type h )
    122128                        {
    123                                 index_type i = m_index.get( h );
     129                                index_type i = m_index->get( h );
    124130                                return i >= 0 ? &( ( *m_storage )[unsigned( i )] ) : nullptr;
    125131                        }
    126132                        const value_type* get( handle_type h ) const
    127133                        {
    128                                 index_type i = m_index.get( h );
     134                                index_type i = m_index->get( h );
    129135                                return i >= 0 ? &( ( *m_storage )[unsigned( i )] ) : nullptr;
    130136                        }
     
    133139                        const void* get_raw( handle_type h ) const { return get( h ); }
    134140
    135                         virtual void remove( handle_type h ) final
     141                        virtual void remove_( handle_type h ) final
    136142                        {
    137143                                value_type* v = get( h );
    138144                                if ( v == nullptr ) return;
    139145                                call_destroy( v );
    140                                 index_type dead_eindex = m_index.remove_swap( h );
     146                                index_type dead_eindex = m_index->remove_swap( h );
    141147                                if ( dead_eindex == -1 ) return;
    142148                                if ( dead_eindex != static_cast<index_type>( m_storage->size() - 1 ) )
     
    149155                        }
    150156
    151                         void remove_by_index( index_type i )
    152                         {
    153                                 if ( i > size() ) return;
     157                        void remove_by_index_( uint32 i )
     158                        {
     159                                if ( i > m_storage->size() ) return;
    154160                                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 );
    156162                                if ( dead_eindex == -1 ) return;
    157163                                if ( dead_eindex != static_cast<index_type>( m_storage->size() - 1 ) )
     
    164170                        }
    165171
    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                                         else
    176                                                 ++i;
    177                                 }
    178                         }
    179 
    180172                        virtual void on_attach( handle_type, handle_type child ) final
    181173                        {
     
    186178                        }
    187179
    188                         ~component()
    189                         {
    190                                 clear_();
    191                                 delete m_storage;
    192                                 m_storage = nullptr;
     180                        virtual ~component()
     181                        {
     182                                //clear_();
     183                                delete m_index;
    193184                        }
    194185                       
    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 
    198186                        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; }
    207188                protected:
    208189                        ecs_type&        m_ecs;
     
    211192                        void swap( handle_type a, handle_type b )
    212193                        {
    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 );
    215196                                if ( ai < 0 || bi < 0 ) return;
    216                                 m_index.swap( a, b );
     197                                m_index->swap( a, b );
    217198                                value_type t = nv::move( ( *m_storage )[ai] );
    218199                                ( *m_storage )[ai] = nv::move( ( *m_storage )[bi] );
     
    225206                        }
    226207
    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 
    234208                        void relational_rebuild( index_type i )
    235209                        {
     
    237211                                handle_type p = m_ecs.get_parent( h );
    238212                                if ( !p ) return;
    239                                 if ( i < m_index.get( p ) )
     213                                if ( i < m_index->get( p ) )
    240214                                {
    241215                                        swap( h, p );
     
    248222                                handle_type p = m_ecs.get_parent( h );
    249223                                if ( !p ) return;
    250                                 if ( m_index.get( h ) < m_index.get( p ) )
     224                                if ( m_index->get( h ) < m_index->get( p ) )
    251225                                {
    252226                                        swap( h, p );
     
    256230                        }
    257231
    258                         bool             m_relational;
    259                         index_table_type m_index;
     232                        bool       m_relational;
     233                        idx_table* m_index;
    260234                };
    261235
  • trunk/nv/ecs/ecs.hh

    r550 r551  
    3939                        typedef ecs< Handle, MessageList, Time >   this_type;
    4040                        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& ) >;
    4850
    4951                        class component_interface
     
    5153                        public:
    5254                                virtual void clear_() = 0;
    53                                 virtual void remove( handle_type h ) = 0;
     55                                virtual void remove_( handle_type h ) = 0;
    5456                                virtual void on_attach( handle_type parent, handle_type child ) = 0;
    5557                                virtual void* get_raw( handle_type h ) = 0;
    5658                                virtual void* insert_raw( handle_type h ) = 0;
    5759                                virtual const void* get_raw( handle_type h ) const = 0;
    58                                 virtual component_storage* storage() = 0;
    5960                                virtual uint32 temp_index( handle_type h ) const = 0;
     61                                virtual void remove_by_index_( uint32 i ) = 0;
     62
    6063
    6164                                void run_create( handle_type h, const lua::stack_proxy& p )
     
    140143                        }
    141144
    142                         template < typename... Components >
     145                        template < int, typename... Components >
    143146                        struct gather_components
    144147                        {
     
    175178
    176179                        private:
    177                                 template < int Index, typename C, typename... Components >
     180                                template < int Index, typename C, typename... Cs >
    178181                                void fill( this_type& ecs )
    179182                                {
    180183                                        cis[Index] = ecs.get_interface< C >();
    181184                                        NV_ASSERT( cis[Index], "What the fuck is this?" );
    182                                         fill< Index + 1, Components... >( ecs );
     185                                        fill< Index + 1, Cs... >( ecs );
    183186                                }
    184187
     
    186189                                void fill( this_type& ) {}
    187190
    188                                 template < int Index, typename SC, typename C, typename... Components >
     191                                template < int Index, typename SC, typename C, typename... Cs >
    189192                                C& run_get()
    190193                                {
    191                                         return get_impl< Index, SC, C, Components... >( nv::is_same< SC, C >{} );
    192                                 }
    193 
    194                                 template < int Index, typename SC, typename C, typename C2, typename... Components >
     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 >
    195198                                C& get_impl( false_type&& )
    196199                                {
    197                                         return get_impl< Index + 1, SC, C2, Components...>( nv::is_same< SC, C >() );
    198                                 }
    199 
    200                                 template < int Index, typename SC, typename C, typename... Components >
     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 >
    201204                                C& get_impl( true_type&& )
    202205                                {
     
    206209                        };
    207210
    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& ) {}
    212215                                bool run( handle_type ) { return true;  }
    213216                                template < typename Component >
     
    215218                        };
    216219
    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;
    224231                        }
    225232
     
    227234                        void register_component_helper( System* c, true_type&& )
    228235                        {
    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() );
    235244                        }
    236245
     
    241250
    242251                        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
    245259                                m_components.push_back( c );
    246260                                m_component_map[thash64::create<Component>()] = c;
    247261                                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() );
    254268                                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() );
    256270                                register_destroy< Handler, Component >( (Handler*)( c ),
    257                                         has_destroy< Handler, Component >::type{} );
     271                                        typename has_destroy< Handler, Component >::type() );
    258272                                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;
    264284                        }
    265285
     
    271291                        void update( time_type dtime )
    272292                        {
    273                                 update_time( dtime );
     293                                this->update_time( dtime );
    274294                                for ( auto u : m_update_handlers )
    275295                                        u( dtime );
     296                                for ( auto h : m_dead_handles )
     297                                        remove( h );
     298                                m_dead_handles.clear();
    276299                        }
    277300
    278301                        void clear()
    279302                        {
    280                                 reset_events();
     303                                this->reset_events();
    281304                                for ( auto c : m_components )
    282305                                        c->clear_();
     
    286309                        ~ecs()
    287310                        {
     311                                for ( auto s : m_cstorage )
     312                                        delete s;
     313                                m_cstorage.clear();
    288314                                //                              for ( auto cs : m_component_storage )
    289315                                //                                      delete cs;
    290316                                //                              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();
    292322                        }
    293323
     
    343373                        }
    344374
     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
    345407                        template < typename F >
    346408                        void recursive_call( handle_type h, F&& f )
     
    351413                        }
    352414
     415                        void mark_remove( handle_type h )
     416                        {
     417                                m_dead_handles.push_back( h );
     418                        }
     419
    353420                        void remove( handle_type h )
    354421                        {
     
    360427                                }
    361428                                for ( auto c : m_components )
    362                                         c->remove( h );
     429                                        c->remove_( h );
    363430                                m_handles.free_handle( h );
    364431                        }
     
    396463                        Component* get( handle_type h )
    397464                        {
    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 ) );
    399468                        }
    400469
     
    402471                        const Component* get( handle_type h ) const
    403472                        {
    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 >*
    409480                                get_storage()
    410481                        {
     
    413484
    414485                        template < typename Component >
    415                         const typename component_storage_handler< Component >*
     486                        const component_storage_handler< Component >*
    416487                                get_storage() const
    417488                        {
    418489                                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;
    419506                        }
    420507
     
    422509                        void register_component_messages( System* h, List<Messages...>&& )
    423510                        {
    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                       
    429516                        template < typename System, typename Message, typename C, typename... Cs >
    430517                        void register_component_message( System* s, mpl::list< C, Cs...>&&, true_type&& )
     
    438525                                                if ( void* c = ci->get_raw( h ) )
    439526                                                {
    440                                                         gather_components< Cs... > gather( *this );
     527                                                        gather_components<0, Cs... > gather( *this );
    441528                                                        if ( gather.run( h ) )
    442                                                                 s->on( m, *( (C*)( c ) ), gather.get<Cs>()... );
     529                                                                s->on( m, *( (C*)( c ) ), gather.template get<Cs>()... );
    443530                                                }
    444531                                        };
     
    462549                                                if ( void* c = ci->get_raw( h ) )
    463550                                                {
    464                                                         gather_components< Cs... > gather( *this );
     551                                                        gather_components<0, Cs... > gather( *this );
    465552                                                        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>()... );
    467554                                                }
    468555                                        };
     
    514601                        }
    515602
    516                         template < typename System, typename Component, typename Handle >
     603                        template < typename System, typename Component, typename H >
    517604                        void register_create( System* s, true_type&& )
    518605                        {
    519606                                component_interface* ci = get_interface<Component>();
    520607                                NV_ASSERT( ci, "Unregistered component!" );
    521                                 ci->m_create.push_back( [=] ( Handle h, void* data, const lua::stack_proxy& p )
     608                                ci->m_create.push_back( [=] ( H h, void* data, const lua::stack_proxy& p )
    522609                                {
    523610                                        s->create( h, *( (Component*)data ), p );
     
    529616                        void register_component_update( System* s, mpl::list< C, Cs...>&&, true_type&& )
    530617                        {
    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>();
    533619                                register_update( [=] ( time_type dtime )
    534620                                {
    535                                         gather_components< Cs... > gather( *this );
     621                                        gather_components<0, Cs... > gather( *this );
    536622                                        for ( auto& c : *storage )
    537623                                        {
    538624                                                if ( gather.runc( c ) )
    539                                                         s->update( c, gather.get<Cs>()..., dtime );
     625                                                        s->update( c, gather.template get<Cs>()..., dtime );
    540626                                        }
    541627                                } );
     
    545631                        void register_ecs_component_update( System* s, mpl::list< C, Cs...>&&, true_type&& )
    546632                        {
    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>();
    549634                                register_update( [=] ( time_type dtime )
    550635                                {
    551                                         gather_components< Cs... > gather(*this);
     636                                        gather_components<0, Cs... > gather(*this);
    552637                                        for ( auto& c : *storage )
    553638                                        {
    554639                                                if ( gather.runc( c ) )
    555                                                         s->update( *this, c, gather.get<Cs>()..., dtime );
     640                                                        s->update( *this, c, gather.template get<Cs>()..., dtime );
    556641                                        }
    557642                                } );
     
    565650                        void register_destroy( System*, false_type&& ) {}
    566651
    567                         template < typename System, typename Component, typename Handle >
     652                        template < typename System, typename Component, typename H >
    568653                        void register_create( System*, false_type&& ) {}
    569654
     
    582667
    583668                        handle_tree_manager< handle_type >          m_handles;
     669                        vector< handle_type >                       m_dead_handles;
    584670                        vector< component_interface* >              m_components;
    585671                        hash_store< thash64, component_interface* > m_component_map;
     
    587673                        vector< update_handler >                    m_update_handlers;
    588674
    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;
    592681                };
    593682
  • trunk/nv/ecs/message_queue.hh

    r550 r551  
    8484                        }
    8585
    86                         template<>
    87                         void register_handler<void>( string_view /*name*/, void* )
     86                        void register_handler( string_view /*name*/, void* )
    8887                        {
    8988                        }
     
    123122                                message m{ Payload::message_id, 0, m_time + delay };
    124123                                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 );
    125133                                return queue( m );
    126134                        }
  • trunk/nv/engine/mesh_manager.hh

    r509 r551  
    7979                string_view resolve( shash64 h ) { return ( *m_strings )[h]; }
    8080                resource< data_channel_set > get_path( const string_view& path,
    81                         resource< mesh_data > default = resource< mesh_data >(),
     81                        resource< mesh_data > def = resource< mesh_data >(),
    8282                        data_node_info* info = nullptr );
    8383
  • trunk/nv/engine/resource_system.hh

    r524 r551  
    194194                virtual resource< T > load_resource( source_type u )
    195195                {
    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() );
    197197                        return create_resource( u );
    198198                }
  • trunk/nv/interface/context.hh

    r550 r551  
    272272                vertex_array create_vertex_array( const VTX* v, uint32 vcount, const IDX* i, uint32 icount, buffer_hint hint )
    273273                {
    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 );
    275275                        buffer       ib = this->create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i );
    276276                        vertex_array_desc desc;
  • trunk/nv/interface/physics_world.hh

    r528 r551  
    2424        {
    2525        public:
    26                 explicit collision_shape( void* p = nullptr, void* m = nullptr ) : internal( p ), mesh( m ) {}
     26                collision_shape( void* p = nullptr, void* m = nullptr ) : internal( p ), mesh( m ) {}
    2727                void* internal = nullptr;
    2828                void* mesh     = nullptr;
     
    3333        {
    3434        public:
    35                 explicit rigid_body( void* p = nullptr ) : internal( p ) {}
     35                rigid_body( void* p = nullptr ) : internal( p ) {}
    3636                void* internal = nullptr;
    3737        };
     
    4040        {
    4141        public:
    42                 explicit constraint( void* p = nullptr ) : internal( p ) {}
     42                constraint( void* p = nullptr ) : internal( p ) {}
    4343                void* internal = nullptr;
    4444        };
  • trunk/nv/lua/lua_handle.hh

    r395 r551  
    1010#include <nv/common.hh>
    1111#include <nv/stl/handle.hh>
     12#include <nv/stl/handle_manager.hh>
    1213#include <nv/lua/lua_values.hh>
    1314
  • trunk/nv/lua/lua_proxy.hh

    r540 r551  
    1212#include <nv/stl/string.hh>
    1313#include <nv/stl/string_table.hh>
     14#include <nv/lua/lua_values.hh>
    1415
    1516namespace nv
     
    8788                        bool read( T& t ) const
    8889                        {
    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();
    9191                                NV_ASSERT( tdb, "stack_proxy::read - type database not set!" );
    9292                                const type_entry* entry = tdb->get_type<T>();
     
    100100//                      string_view to_string_view();
    101101                protected:
     102                        const type_database* get_type_db() const;
     103
    102104                        // Not public because not permanent
    103105                        string_view get_string_view() const;
  • trunk/nv/lua/lua_state.hh

    r540 r551  
    5757                        }
    5858                        const type_database* get_type_database() const { return m_type_database; }
     59                        type_database* get_type_database() { return m_type_database; }
    5960
    6061                        template < typename T >
     
    204205
    205206                        const type_data* get_type_data() const { return m_lua_types; }
    206 
    207 
    208 
     207                        type_data* get_type_data() { return m_lua_types; }
    209208
    210209                protected:
  • trunk/nv/stl/flags.hh

    r508 r551  
    227227                }
    228228
    229                 template < uint32 SIZE, typename T >
    230                 inline friend flags< SIZE, T > operator &( const flags< SIZE, T >& lhs, const flags< SIZE, T >& rhs );
    231 
    232                 template < uint32 SIZE, typename T >
    233                 inline friend flags< SIZE, 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 );
    234234
    235235        private:
  • trunk/nv/stl/functional/hash.hh

    r533 r551  
    8686        };
    8787
     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
    8895        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 ); }
    92102                static constexpr uintptr_t get( T value ) { return reinterpret_cast<uintptr_t>( value ); }
    93103        };
  • trunk/nv/stl/handle_manager.hh

    r536 r551  
    2525        {
    2626        public:
    27                 typedef typename Handle                  handle_type;
     27                typedef Handle                           handle_type;
    2828                typedef typename handle_type::value_type value_type;
    2929
  • trunk/nv/stl/handle_store.hh

    r543 r551  
    3939                {
    4040                        m_data.reserve( reserve );
    41                         m_indexes.reserve( reserve );
     41                        m_index.reserve( reserve );
    4242                }
    4343
     
    9898        private:
    9999                storage_type                  m_data;
    100                 index_table< handle_type, index_type > m_index;
     100                flat_index_table< handle_type, index_type > m_index;
    101101        };
    102102
  • trunk/nv/stl/index_table.hh

    r545 r551  
    3131                typedef Index               index_type;
    3232
    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 )
    3556                {
    3657                        m_indexes.reserve( reserve );
     
    129150                typename Index = sint32
    130151        >
    131                 class hashed_index_table
     152                class hashed_index_table : public index_table< Handle, Index >
    132153        {
    133154        public:
  • trunk/nv/stl/math/geometric.hh

    r550 r551  
    6969                inline T inv_length( T v )
    7070                {
    71                         return T( 1 ) / abs( x );
     71                        return T( 1 ) / abs( v );
    7272                }
    7373
  • trunk/nv/stl/range.hh

    r537 r551  
    8585                        static const T invalid = T( 0 );
    8686
    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 )
    8888                        {
    8989                                if( !( static_cast<base_type>( value ) & static_cast<base_type>( current ) ) )
  • trunk/nv/stl/type_traits/common.hh

    r550 r551  
    2929        };
    3030
    31         template < typename T >
    32         constexpr T integral_constant_v = integral_constant<T>::value;
    33 
    3431        // TODO: Propagate
    3532        template< bool B >
     
    3835        typedef bool_constant<true> true_type;
    3936        typedef bool_constant<false> false_type;
    40 
    41         template < typename T >
    42         constexpr T bool_constant_v = bool_constant<T>::value;
    4337
    4438        template< bool Test, typename T = void>
  • trunk/nv_bullet.lua

    r533 r551  
    2828
    2929        includedirs { "D:/Libraries/bullet2/src/" }
    30 
    31         configuration "debug"
     30       
     31        filter { "configurations:debug", "platforms:*32" }
    3232                nv_bullet_configure( "D:/Libraries/bullet2/x86/", "RelWithDebInfo", "_rdbg" )
    3333--              nv_bullet_configure( "D:/Libraries/bullet2/x86/", "Debug", "_debug" )
    3434
    35         configuration "profiler"
     35        filter { "configurations:profiler", "platforms:*32" }
    3636                nv_bullet_configure( "D:/Libraries/bullet2/x86/", "Release" )
    3737
    38         configuration "release"
     38        filter { "configurations:release", "platforms:*32" }
    3939                nv_bullet_configure( "D:/Libraries/bullet2/x86/", "Release" )
    4040
    41         configuration "debug_64"
     41        filter { "configurations:debug", "platforms:*64" }
    4242                nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "RelWithDebInfo", "_rdbg" )
    4343--              nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "Debug", "_debug" )
    4444
    45         configuration "profiler_64"
     45        filter { "configurations:profiler", "platforms:*64" }
    4646                nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "Release" )
    4747
    48         configuration "release_64"
     48        filter { "configurations:release", "platforms:*64" }
    4949                nv_bullet_configure( "D:/Libraries/bullet2/x86_64/", "Release" )
    5050
     51        filter {}
    5152
    52 
  • trunk/premake5.lua

    r362 r551  
    1 solution "nv"
     1workspace "nv"
    22        configurations { "debug", "release" }
    33        targetdir "bin"
  • trunk/src/engine/mesh_manager.cc

    r534 r551  
    2929}
    3030
    31 nv::resource< nv::data_channel_set > nv::mesh_data_manager::get_path( const string_view& path, resource< mesh_data > default /*= resource< mesh_data >()*/, data_node_info* info /*= nullptr */ )
     31nv::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 */ )
    3232{
    33         nv::resource< nv::mesh_data > mr = default;
     33        nv::resource< nv::mesh_data > mr = def;
    3434
    3535        nv::string_view sub_mesh_name;
  • trunk/src/image/png_writer.cc

    r534 r551  
    1212#include <stdarg.h> 
    1313
    14 using namespace nv;
     14//using namespace nv;
    1515
    1616#if NV_COMPILER == NV_CLANG
     
    3333};
    3434
    35 #define STBI_MALLOC(sz)     nvmalloc(sz)
    36 #define STBI_REALLOC(p,sz)  nvrealloc(p,sz)
    37 #define STBI_FREE(p)        nvfree(p)
    38 #define STBI_MEMMOVE(d,s,c) nvmemmove(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)
    3939
    4040typedef void stbi_write_func( void *context, void *data, int size );
     
    5757
    5858template < typename T >
    59 inline uchar8 byte_cast( T x )
    60 {
    61         return uchar8( ( x ) & 255 );
     59inline nv::uchar8 byte_cast( T x )
     60{
     61        return nv::uchar8( ( x ) & 255 );
    6262}
    6363
     
    246246}
    247247
     248static int iabs( int i )
     249{
     250        return i >= 0 ? i : -i;
     251}
     252
    248253static unsigned char stbiw__paeth( int a, int b, int c )
    249254{
    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 );
    251256        if ( pa <= pb && pa <= pc ) return byte_cast( a );
    252257        if ( pb <= pc ) return byte_cast( b );
     
    320325                                if ( p ) break;
    321326                                for ( i = 0; i < x*n; ++i )
    322                                         est += abs( (signed char)line_buffer[i] );
     327                                        est += iabs( (signed char)line_buffer[i] );
    323328                                if ( est < bestval ) { bestval = est; best = k; }
    324329                        }
  • trunk/src/lua/lua_proxy.cc

    r541 r551  
    7676}
    7777
     78const 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
    7884nv::string_view nv::lua::stack_proxy::get_string_view() const
    7985{
Note: See TracChangeset for help on using the changeset viewer.