[395] | 1 | // Copyright (C) 2014-2015 ChaosForge Ltd
|
---|
[316] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[316] | 6 |
|
---|
| 7 | #include "nv/engine/resource_system.hh"
|
---|
[368] | 8 | #include "nv/stl/range.hh"
|
---|
[316] | 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;
|
---|
[399] | 14 | lua::register_storage( m_lua, get_storage_name(), string_view( "register_" + get_resource_name().to_string() ) );
|
---|
[316] | 15 | }
|
---|
| 16 |
|
---|
| 17 | nv::resource_id nv::resource_manager_base::load_resource( const std::string& id )
|
---|
| 18 | {
|
---|
| 19 | lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) );
|
---|
| 20 | resource_id rid = load_resource( table );
|
---|
| 21 | if ( rid != 0 ) m_names[ id ] = rid;
|
---|
| 22 | return rid;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | void nv::resource_manager_base::load_all()
|
---|
| 26 | {
|
---|
| 27 | clear();
|
---|
| 28 | lua::table_guard table( m_lua, get_storage_name() );
|
---|
[323] | 29 | uint32 count = table.get_unsigned( "__counter" );
|
---|
[316] | 30 | for ( auto i : range( count ) )
|
---|
| 31 | {
|
---|
| 32 | lua::table_guard sub_table( table, i+1 );
|
---|
| 33 | resource_id rid = load_resource( sub_table );
|
---|
[361] | 34 | if ( rid != 0 ) m_names[ sub_table.get_std_string("id") ] = rid;
|
---|
[316] | 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[380] | 38 | nv::resource_type_id nv::resource_system::register_resource_type( const std::string& /*name*/, resource_manager_base* /*manager*/ )
|
---|
[316] | 39 | {
|
---|
| 40 | return 0;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[380] | 43 | nv::resource_type_id nv::resource_system::get_resource_type_id( const std::string& /*name*/ ) const
|
---|
[316] | 44 | {
|
---|
| 45 | return 0;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[319] | 48 | void nv::resource_system::initialize( lua::state* /*a_lua_state*/ )
|
---|
[316] | 49 | {
|
---|
| 50 |
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | nv::resource_system::~resource_system()
|
---|
| 54 | {
|
---|
| 55 |
|
---|
| 56 | }
|
---|