source: trunk/src/engine/resource_system.cc @ 541

Last change on this file since 541 was 539, checked in by epyon, 8 years ago
  • temporary_proxy implemented
  • table_guard now uses temporary_proxy as main read functionality
File size: 1.5 KB
Line 
1// Copyright (C) 2014-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
7#include "nv/engine/resource_system.hh"
8#include "nv/stl/range.hh"
9#include "nv/lua/lua_nova.hh"
10
11void nv::lua_resource_manager_base::initialize( lua::state* a_lua_state )
12{
13        m_lua = a_lua_state;
14        string128 storage_name = "register_" + get_resource_name();
15        lua::register_storage( m_lua, get_storage_name(), storage_name );
16}
17
18bool nv::lua_resource_manager_base::load_resource( const string_view& id )
19{
20        lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) );
21        load_resource( table, id );
22        return true;
23}
24
25void nv::lua_resource_manager_base::load_all( bool do_clear )
26{
27        if ( do_clear ) clear();
28        lua::table_guard table( m_lua, get_storage_name() );
29        uint32 count = table["__counter"].get_uint32();
30        for ( auto i : range( count ) )
31        {
32                lua::table_guard sub_table( table, i + 1 );
33                shash64 id = sub_table["id"].get_shash64();
34                load_resource( sub_table, id );
35        }
36}
37
38void nv::lua_resource_manager_base::preload_ids()
39{
40        m_id_hash.clear();
41        lua::table_guard table( m_lua, get_storage_name() );
42        uint32 count = table["__counter"].get_uint32();
43        for ( auto i : range( count ) )
44        {
45                lua::table_guard sub_table( table, i + 1 );
46                string64 id = sub_table["id"].get_string64();
47                NV_ASSERT( m_id_hash.find( id ) == m_id_hash.end(), "HASH COLLISION" );
48                m_id_hash[id] = id;
49        }
50}
Note: See TracBrowser for help on using the repository browser.