- Timestamp:
- 10/09/15 14:07:43 (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/engine/program_manager.hh
r438 r474 27 27 virtual string_view get_resource_name() const { return "program"; } 28 28 protected: 29 virtual res ource_id load_resource( lua::table_guard& table );29 virtual res_id load_resource( lua::table_guard& table ); 30 30 string_buffer load_source( lua::table_guard& table, const string_view& append ); 31 virtual void release( program p );31 virtual void release( program* p ); 32 32 private: 33 33 context* m_context; -
trunk/nv/engine/resource_system.hh
r432 r474 16 16 #include <nv/common.hh> 17 17 #include <nv/interface/context.hh> 18 #include <nv/core/resource.hh> 18 19 #include <nv/lua/lua_state.hh> 19 20 #include <nv/stl/hash_store.hh> … … 23 24 { 24 25 25 typedef uint32 res ource_id;26 typedef uint32 res ource_type_id;26 typedef uint32 res_id; 27 typedef uint32 res_type_id; 27 28 28 29 class resource_system; 29 30 30 class resource_manager_base 31 class resource_manager_base : public resource_handler 31 32 { 32 33 public: … … 37 38 virtual void clear() { m_names.clear(); } 38 39 void load_all(); 39 res ource_id load_resource( const string_view& id );40 res_id load_resource( const string_view& id ); 40 41 virtual ~resource_manager_base() {} 41 42 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 ) {}; 43 48 44 49 lua::state* m_lua; 45 hash_store< shash64, res ource_id > m_names;50 hash_store< shash64, res_id > m_names; 46 51 }; 47 52 … … 50 55 { 51 56 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 ) 54 59 { 55 return ( id < m_data.size() ? m_data[ id ] : T());60 return ( id < m_data.size() ? m_data[ id ] : nullptr ); 56 61 } 57 T get_resource( const string_view& id )62 T* get_resource( const string_view& id ) 58 63 { 59 64 auto m = m_names.find( id ); … … 64 69 return get_resource( load_resource( id ) ); 65 70 } 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 } 66 88 virtual void clear() 67 89 { … … 70 92 release( m_data[i] ); 71 93 m_data.clear(); 72 m_data.push_back( T());94 m_data.push_back( nullptr ); 73 95 } 96 74 97 virtual ~resource_manager() 75 98 { … … 77 100 } 78 101 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 } 80 111 81 resource_id add( T resource ) 112 virtual void release( T* ) {} 113 114 res_id add( T* resource ) 82 115 { 83 116 m_data.push_back( resource ); … … 85 118 } 86 119 87 vector< T > m_data;120 vector< T* > m_data; 88 121 }; 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 105 123 } 106 124 -
trunk/src/engine/program_manager.cc
r438 r474 16 16 } 17 17 18 nv::res ource_id nv::program_manager::load_resource( lua::table_guard& table )18 nv::res_id nv::program_manager::load_resource( lua::table_guard& table ) 19 19 { 20 20 NV_LOG_DEBUG( table.get_string("id") ); … … 36 36 } 37 37 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 ) ); 39 39 return add( program ); 40 40 } 41 41 42 void nv::program_manager::release( program p )42 void nv::program_manager::release( program* p ) 43 43 { 44 m_context->get_device()->release( p ); 44 m_context->get_device()->release( *p ); 45 delete p; 45 46 } 46 47 -
trunk/src/engine/resource_system.cc
r440 r474 16 16 } 17 17 18 nv::res ource_id nv::resource_manager_base::load_resource( const string_view& id )18 nv::res_id nv::resource_manager_base::load_resource( const string_view& id ) 19 19 { 20 20 lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) ); 21 res ource_id rid = load_resource( table );21 res_id rid = load_resource( table ); 22 22 if ( rid != 0 ) m_names[ id ] = rid; 23 23 return rid; … … 32 32 { 33 33 lua::table_guard sub_table( table, i+1 ); 34 res ource_id rid = load_resource( sub_table );34 res_id rid = load_resource( sub_table ); 35 35 if ( rid != 0 ) m_names[ sub_table.get_string_hash_64("id") ] = rid; 36 36 } 37 37 } 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*/ ) const45 {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.