Changeset 498


Ignore:
Timestamp:
06/03/16 16:24:49 (9 years ago)
Author:
epyon
Message:
  • ecs implementation
  • mipmapping by default for material manager
  • minor fixes
Location:
trunk
Files:
5 edited

Legend:

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

    r497 r498  
    104104                };
    105105       
     106
     107
    106108                template < typename HANDLE = handle<> >
    107109                class ecs
     
    110112                        typedef HANDLE handle_type;
    111113
    112                         template < typename COMPONENT, typename MANAGER >
    113                         void register_component( string_view /*name*/, MANAGER* /*manager*/ )
    114                         {
    115 
    116                         }
    117 
    118                         handle_type create_handle()
     114                        typedef uint32 message_type;
     115
     116                        struct message
     117                        {
     118                                message_type type;
     119                                handle_type  entity;
     120                                uint8        payload[128 - sizeof( uint32 ) - sizeof( handle_type )];
     121                        };
     122
     123                        class component_interface
     124                        {
     125                        public:
     126                                virtual bool handle_message( const message& ) = 0;
     127                                virtual void clear() = 0;
     128                                virtual void remove( handle_type h ) = 0;
     129                        };
     130
     131                        template < typename Payload >
     132                        static const Payload& message_cast( const message& m )
     133                        {
     134                                static_assert( sizeof( Payload ) < sizeof( message::payload ), "Payload size over limit!" );
     135                                NV_ASSERT( Payload::message_id == m.type, "Payload cast fail!" );
     136                                return *reinterpret_cast<const Payload*>( &( m.payload ) );
     137                        }
     138
     139                        template < typename COMPONENT >
     140                        void register_component( string_view /*name*/, component_interface* c )
     141                        {
     142                                m_components.push_back( c );
     143                        }
     144
     145                        bool dispatch( const message& m )
     146                        {
     147                                for ( auto c : m_components )
     148                                        c->handle_message( m );
     149                                return true;
     150                        }
     151
     152                        template < typename Payload, typename ...Args >
     153                        bool dispatch( handle_type h, Args&&... args )
     154                        {
     155                                message m{ Payload::message_id, h };
     156                                new( &m.payload ) Payload{ nv::forward<Args>( args )... };
     157                                return dispatch( m );
     158                        }
     159
     160                        handle_type create()
    119161                        {
    120162                                return m_handles.create_handle();
    121163                        }
    122164
    123                         void free_handle( handle_type h )
    124                         {
     165                        void clear()
     166                        {
     167                                for ( auto c : m_components )
     168                                        c->clear();
     169                                m_handles.clear();
     170                        }
     171
     172                        void remove( handle_type h )
     173                        {
     174                                for ( auto c : m_components )
     175                                        c->remove( h );
    125176                                m_handles.free_handle( h );
    126177                        }
     
    133184                protected:
    134185                        handle_manager< handle_type > m_handles;
     186                        vector< component_interface* > m_components;
    135187                };
    136188
    137189                template < typename ECS, typename COMPONENT >
    138                 class component
     190                class component : public ECS::component_interface
    139191                {
    140192                public:
    141193                        typedef ECS                                    ecs_type;
     194                        typedef typename ecs_type::message             message_type;
    142195                        typedef typename ecs_type::handle_type         handle_type;
    143196                        typedef index_table< handle_type >             index_table_type;
     
    169222                        }
    170223
     224                        template < typename ...Args >
     225                        value_type& insert( handle_type h, Args&&... args )
     226                        {
     227                                /*index_type i = */m_index.insert( h );
     228                                //NV_ASSERT( i == m_data.size(), "Fail!" );
     229                                m_data.emplace_back( nv::forward<Args>( args )... );
     230                                return m_data.back();
     231                        }
     232
    171233                        bool exists( handle_type h )
    172234                        {
     
    174236                        }
    175237
    176                         void clear()
     238                        virtual void clear()
    177239                        {
    178240                                m_index.clear();
     
    192254                        }
    193255
    194                         void remove( handle_type h )
     256                        virtual void remove( handle_type h )
    195257                        {
    196258                                index_type dead_eindex = m_index.remove_swap( h );
     
    202264                                m_data.pop_back();
    203265                        }
     266
     267                        virtual bool handle_message( const message_type& )
     268                        {
     269                                return true;
     270                        }
     271
    204272
    205273                        handle_type get_handle( index_type i ) const { return m_index.get_handle( i ); }
  • trunk/nv/stl/handle.hh

    r497 r498  
    115115                        const index_entry& entry = m_entries[h.index()];
    116116                        return entry.next_free == USED && entry.counter == hop::get_counter( h );
     117                }
     118
     119                void clear()
     120                {
     121                        m_first_free = NONE;
     122                        m_last_free  = NONE;
     123                        m_entries.clear();
    117124                }
    118125
     
    385392                void resize_to( index_type i )
    386393                {
    387                         index_type size = index_type( m_indexes.size() );
     394                        index_type size = index_type( m_handles.size() );
    388395                        if ( i >= size )
    389396                        {
  • trunk/nv/stl/memory.hh

    r472 r498  
    191191        inline void construct_object( T* object, Args&&... params )
    192192        {
    193                 new ( object )T( ::nv::forward<Args>( params )... );
     193                new ( object )T{ ::nv::forward<Args>( params )... };
    194194        }
    195195
  • trunk/src/engine/material_manager.cc

    r491 r498  
    2828        {
    2929                gpu_material* result = new gpu_material;
    30                 sampler smp( sampler::LINEAR, sampler::REPEAT );
     30                sampler smp( sampler::LINEAR_MIPMAP_LINEAR, sampler::REPEAT );
    3131                for ( uint32 i = 0; i < size( mat->paths ); ++i )
    3232                        if ( !mat->paths[i].empty() )
  • trunk/src/gl/gl_device.cc

    r493 r498  
    109109
    110110        // Detect if mipmapping was requested
    111         if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
    112         {
    113                 // TODO: This should not be done if we use framebuffers!
    114                 glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE);
    115         }
     111//      if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     112//      {
     113//              // TODO: This should not be done if we use framebuffers!
     114//              glTexParameteri( gl_type, GL_GENERATE_MIPMAP, GL_TRUE);
     115//      }
    116116
    117117        if ( asampler.filter_max != sampler::NEAREST )
     
    154154        else
    155155                glTexImage2DMultisample( gl_type, 4, gl_internal, size.x, size.y, 1 );
     156
     157        if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     158        {
     159                // TODO: This should not be done if we use framebuffers!
     160                glGenerateMipmap( gl_type );
     161        }
     162
    156163
    157164        glBindTexture( gl_type, 0 );
Note: See TracChangeset for help on using the changeset viewer.