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

Last change on this file since 524 was 524, checked in by epyon, 9 years ago
  • god I really suck with proper commits -_-
File size: 1.5 KB
RevLine 
[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
[477]11void nv::lua_resource_manager_base::initialize( lua::state* a_lua_state )
[316]12{
13        m_lua = a_lua_state;
[440]14        string128 storage_name = "register_" + get_resource_name();
15        lua::register_storage( m_lua, get_storage_name(), storage_name );
[316]16}
17
[477]18bool nv::lua_resource_manager_base::load_resource( const string_view& id )
[316]19{
20        lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) );
[477]21        load_resource( table, id );
22        return true;
[316]23}
24
[486]25void nv::lua_resource_manager_base::load_all( bool do_clear )
[316]26{
[486]27        if ( do_clear ) clear();
[316]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        {
[477]32                lua::table_guard sub_table( table, i + 1 );
33                load_resource( sub_table, sub_table.get_string_hash_64( "id" ) );
[316]34        }
35}
[524]36
37void nv::lua_resource_manager_base::preload_ids()
38{
39        m_id_hash.clear();
40        lua::table_guard table( m_lua, get_storage_name() );
41        uint32 count = table.get_unsigned( "__counter" );
42        for ( auto i : range( count ) )
43        {
44                lua::table_guard sub_table( table, i + 1 );
45                string64 id = sub_table.get_string64( "id" );
46                NV_ASSERT( m_id_hash.find( id ) == m_id_hash.end(), "HASH COLLISION - ", id, " - ", m_id_hash[id] );
47                m_id_hash[id] = id;
48        }
49}
Note: See TracBrowser for help on using the repository browser.