Changeset 474 for trunk/nv/engine/resource_system.hh
- Timestamp:
- 10/09/15 14:07:43 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.