Changeset 474 for trunk


Ignore:
Timestamp:
10/09/15 14:07:43 (10 years ago)
Author:
epyon
Message:
  • resource manager updates
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/engine/program_manager.hh

    r438 r474  
    2727                virtual string_view get_resource_name() const { return "program"; }
    2828        protected:
    29                 virtual resource_id load_resource( lua::table_guard& table );
     29                virtual res_id load_resource( lua::table_guard& table );
    3030                string_buffer load_source( lua::table_guard& table, const string_view& append );
    31                 virtual void release( program p );
     31                virtual void release( program* p );
    3232        private:
    3333                context* m_context;
  • trunk/nv/engine/resource_system.hh

    r432 r474  
    1616#include <nv/common.hh>
    1717#include <nv/interface/context.hh>
     18#include <nv/core/resource.hh>
    1819#include <nv/lua/lua_state.hh>
    1920#include <nv/stl/hash_store.hh>
     
    2324{
    2425
    25         typedef uint32 resource_id;
    26         typedef uint32 resource_type_id;
     26        typedef uint32 res_id;
     27        typedef uint32 res_type_id;
    2728
    2829        class resource_system;
    2930
    30         class resource_manager_base
     31        class resource_manager_base : public resource_handler
    3132        {
    3233        public:
     
    3738                virtual void clear() { m_names.clear(); }
    3839                void load_all();
    39                 resource_id load_resource( const string_view& id );
     40                res_id load_resource( const string_view& id );
    4041                virtual ~resource_manager_base() {}
    4142        protected:
    42                 virtual resource_id load_resource( lua::table_guard& table ) = 0;
     43                virtual res_id load_resource( lua::table_guard& table ) = 0;
     44
     45//              virtual const void* lock( resource_id id, resource_type_id );
     46                virtual void unlock( resource_id, resource_type_id ) {};
     47                virtual void release( resource_id, resource_type_id ) {};
    4348
    4449                lua::state* m_lua;
    45                 hash_store< shash64, resource_id > m_names;
     50                hash_store< shash64, res_id > m_names;
    4651        };
    4752
     
    5055        {
    5156        public:
    52                 resource_manager() { m_data.push_back(T()); }
    53                 T get_resource( resource_id id )
     57                resource_manager() { m_data.push_back(nullptr); }
     58                T* get_resource( res_id id )
    5459                {
    55                         return ( id < m_data.size() ? m_data[ id ] : T() );
     60                        return ( id < m_data.size() ? m_data[ id ] : nullptr );
    5661                }
    57                 T get_resource( const string_view& id )
     62                T* get_resource( const string_view& id )
    5863                {
    5964                        auto m = m_names.find( id );
     
    6469                        return get_resource( load_resource( id ) );
    6570                }
     71                resource< T > get( const string_view& id )
     72                {
     73                        auto m = m_names.find( id );
     74                        if ( m != m_names.end() )
     75                        {
     76                                return create< T >( id );
     77                        }
     78                        else
     79                        {
     80                                if ( get_resource( id ) != nullptr )
     81                                {
     82                                        return create< T >( id );
     83                                }
     84                        }
     85//                      NV_ASSERT( false, "resource_manager.get failed!" );
     86                        return resource<T>();
     87                }
    6688                virtual void clear()
    6789                {
     
    7092                                release( m_data[i] );
    7193                        m_data.clear();
    72                         m_data.push_back( T() );
     94                        m_data.push_back( nullptr );
    7395                }
     96
    7497                virtual ~resource_manager()
    7598                {
     
    77100                }
    78101        protected:
    79                 virtual void release( T ) {}
     102                virtual const void* lock( resource_id id, resource_type_id )
     103                {
     104                        auto m = m_names.find( id );
     105                        if ( m != m_names.end() )
     106                        {
     107                                return m_data[m->second];
     108                        }
     109                        return nullptr;
     110                }
    80111
    81                 resource_id add( T resource )
     112                virtual void release( T* ) {}
     113
     114                res_id add( T* resource )
    82115                {
    83116                        m_data.push_back( resource );
     
    85118                }
    86119
    87                 vector< T > m_data;
     120                vector< T* > m_data;
    88121        };
    89 
    90 
    91         class resource_system
    92         {
    93         public:
    94                 explicit resource_system() : m_lua_state( nullptr ) { m_managers.push_back(nullptr); }
    95                 resource_type_id register_resource_type( const string_view& name, resource_manager_base* manager );
    96                 resource_type_id get_resource_type_id( const string_view& name ) const;
    97                 void initialize( lua::state* a_lua_state );
    98                 virtual ~resource_system();
    99         protected:
    100                 vector< resource_manager_base* >     m_managers;
    101                 hash_store< shash64, resource_id > m_manager_names;
    102                 lua::state* m_lua_state;
    103         };
    104 
     122       
    105123}
    106124
  • trunk/src/engine/program_manager.cc

    r438 r474  
    1616}
    1717
    18 nv::resource_id nv::program_manager::load_resource( lua::table_guard& table )
     18nv::res_id nv::program_manager::load_resource( lua::table_guard& table )
    1919{
    2020        NV_LOG_DEBUG( table.get_string("id") );
     
    3636        }
    3737
    38         nv::program program = m_context->get_device()->create_program( vsource, fsource );
     38        nv::program* program = new nv::program( m_context->get_device()->create_program( vsource, fsource ) );
    3939        return add( program );
    4040}
    4141
    42 void nv::program_manager::release( program p )
     42void nv::program_manager::release( program* p )
    4343{
    44         m_context->get_device()->release( p );
     44        m_context->get_device()->release( *p );
     45        delete p;
    4546}
    4647
  • trunk/src/engine/resource_system.cc

    r440 r474  
    1616}
    1717
    18 nv::resource_id nv::resource_manager_base::load_resource( const string_view& id )
     18nv::res_id nv::resource_manager_base::load_resource( const string_view& id )
    1919{
    2020        lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) );
    21         resource_id rid = load_resource( table );
     21        res_id rid = load_resource( table );
    2222        if ( rid != 0 ) m_names[ id ] = rid;
    2323        return rid;
     
    3232        {
    3333                lua::table_guard sub_table( table, i+1 );
    34                 resource_id rid = load_resource( sub_table );
     34                res_id rid = load_resource( sub_table );
    3535                if ( rid != 0 ) m_names[ sub_table.get_string_hash_64("id") ] = rid;
    3636        }
    3737}
    38 
    39 nv::resource_type_id nv::resource_system::register_resource_type( const string_view& /*name*/, resource_manager_base* /*manager*/ )
    40 {
    41         return 0;
    42 }
    43 
    44 nv::resource_type_id nv::resource_system::get_resource_type_id( const string_view& /*name*/ ) const
    45 {
    46         return 0;
    47 }
    48 
    49 void nv::resource_system::initialize( lua::state* /*a_lua_state*/ )
    50 {
    51 
    52 }
    53 
    54 nv::resource_system::~resource_system()
    55 {
    56 
    57 }
Note: See TracChangeset for help on using the changeset viewer.