[316] | 1 | // Copyright (C) 2014 ChaosForge Ltd
|
---|
| 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
| 4 | // This file is part of NV Libraries.
|
---|
| 5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
| 6 |
|
---|
| 7 | #include "nv/engine/resource_system.hh"
|
---|
| 8 | #include "nv/range.hh"
|
---|
| 9 | #include "nv/lua/lua_nova.hh"
|
---|
| 10 |
|
---|
| 11 | void nv::resource_manager_base::initialize( lua::state* a_lua_state )
|
---|
| 12 | {
|
---|
| 13 | m_lua = a_lua_state;
|
---|
| 14 | std::string constructor_name( get_resource_name() );
|
---|
| 15 | constructor_name = "register_"+constructor_name;
|
---|
| 16 | lua::register_storage( m_lua, get_storage_name(), constructor_name.c_str() );
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | nv::resource_id nv::resource_manager_base::load_resource( const std::string& id )
|
---|
| 20 | {
|
---|
| 21 | lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) );
|
---|
| 22 | resource_id rid = load_resource( table );
|
---|
| 23 | if ( rid != 0 ) m_names[ id ] = rid;
|
---|
| 24 | return rid;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | void nv::resource_manager_base::load_all()
|
---|
| 28 | {
|
---|
| 29 | clear();
|
---|
| 30 | lua::table_guard table( m_lua, get_storage_name() );
|
---|
| 31 | uint32 count = table.get_integer( "__counter" );
|
---|
| 32 | for ( auto i : range( count ) )
|
---|
| 33 | {
|
---|
| 34 | lua::table_guard sub_table( table, i+1 );
|
---|
| 35 | resource_id rid = load_resource( sub_table );
|
---|
| 36 | if ( rid != 0 ) m_names[ sub_table.get_string("id") ] = rid;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | nv::resource_type_id nv::resource_system::register_resource_type( const string& name, resource_manager_base* manager )
|
---|
| 41 | {
|
---|
| 42 | return 0;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | nv::resource_type_id nv::resource_system::get_resource_type_id( const string& name ) const
|
---|
| 46 | {
|
---|
| 47 | return 0;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void nv::resource_system::initialize( lua::state* a_lua_state )
|
---|
| 51 | {
|
---|
| 52 |
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | nv::resource_system::~resource_system()
|
---|
| 56 | {
|
---|
| 57 |
|
---|
| 58 | }
|
---|