Changeset 505 for trunk/src/engine


Ignore:
Timestamp:
07/12/16 20:22:23 (9 years ago)
Author:
epyon
Message:
  • several STL updates
  • several minor fixes
Location:
trunk/src/engine
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/engine/image_manager.cc

    r504 r505  
    1212using namespace nv;
    1313
    14 void nv::image_manager::add_base_path( const string_view& path )
     14bool image_manager::load_resource( const string_view& filename )
    1515{
    16         m_paths.emplace_back( path );
     16        c_file_system fs;
     17        if ( stream* file = open_stream( fs, filename ) )
     18        {
     19                png_loader loader;
     20                image_data* result = loader.load( *file );
     21                delete file;
     22                if ( result )
     23                {
     24                        add( filename, result );
     25                        return true;
     26                }
     27        }
     28        return false;
    1729}
    1830
    19 bool image_manager::load_resource( const string_view& filename )
    20 {
    21         png_loader loader;
    22         c_file_system fs;
    23         image_data* result = nullptr;
    24         if ( fs.exists( filename ) )
    25         {
    26                 stream* file = fs.open( filename );
    27                 result = loader.load( *file );
    28                 delete file;
    29         }
    30         else if ( m_paths.size() > 0 )
    31         {
    32                 for ( const auto& path : m_paths )
    33                 {
    34                         string128 fpath = path;
    35                         fpath.append( filename );
    36                         if ( fs.exists( fpath ) )
    37                         {
    38                                 stream* file = fs.open( fpath );
    39                                 result = loader.load( *file );
    40                                 delete file;
    41                                 break;
    42                         }
    43                 }
    44         }
    45         if ( result )
    46                 add( filename, result );
    47         return result != nullptr;
    48 }
    49 
  • trunk/src/engine/material_manager.cc

    r501 r505  
    1414
    1515nv::gpu_material_manager::gpu_material_manager( context* context, material_manager* matmgr, image_manager* imgmgr )
    16         : m_context( context )
    17         , m_material_manager( matmgr )
     16        : dependant_resource_manager( matmgr ), m_context( context )
    1817        , m_image_manager( imgmgr )
    1918{
     
    2322}
    2423
    25 bool gpu_material_manager::load_resource( const string_view& id )
     24nv::resource< nv::gpu_material > nv::gpu_material_manager::create_resource( resource< material > m )
    2625{
    27         if ( auto mat = m_material_manager->get( id ).lock() )
     26        resource_id id = m.id();
     27        if ( auto mat = m.lock() )
    2828        {
    2929                gpu_material* result = new gpu_material;
     
    3939
    4040                // HACK
    41                 for ( uint32 i = 0; i < 8; ++i )
    42                         if ( result->textures[i].is_nil() )
    43                                 result->textures[i] = m_default;
    44                        
    45                 add( id, result );
    46                 return true;
     41                for ( uint32 i = 0; i < 8; ++i )
     42                        if ( result->textures[i].is_nil() )
     43                                result->textures[i] = m_default;
     44
     45                return add( id, result );
    4746        }
    48         return false;
     47        return resource< nv::gpu_material >();
    4948}
    5049
  • trunk/src/engine/mesh_manager.cc

    r484 r505  
    66
    77#include "nv/engine/mesh_manager.hh"
     8#include "nv/formats/nmd_loader.hh"
     9#include "nv/io/c_file_system.hh"
    810
    911using namespace nv;
    1012
    11 resource< gpu_mesh > gpu_mesh_manager::load_resource( resource< data_channel_set > mesh )
     13resource< gpu_mesh > gpu_mesh_manager::create_resource( resource< data_channel_set > mesh )
    1214{
    13         resource< gpu_mesh > result = get( mesh.id().value() );
    14         if ( result ) return result;
    1515        if ( auto lmesh = mesh.lock() )
    1616        {
     
    2424}
    2525
    26 bool nv::gpu_mesh_manager::load_resource( const string_view& id )
    27 {
    28         if ( auto lmesh = m_mesh_manager->get( id ).lock() )
    29         {
    30                 gpu_mesh* gm = new gpu_mesh;
    31                 gm->va = m_context->create_vertex_array( &*lmesh, STATIC_DRAW );
    32                 gm->count = lmesh->get_channel_size( slot::INDEX );
    33                 gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : NORMAL;
    34                 add( id, gm );
    35                 return true;
    36         }
    37         return false;
    38 }
    39 
    4026void gpu_mesh_manager::release( gpu_mesh* m )
    4127{
    4228        m_context->release( m->va );
    4329}
     30
     31nv::resource< nv::data_channel_set > nv::mesh_data_manager::get_path( const string_view& path, resource< mesh_data > default /*= resource< mesh_data >()*/, data_node_info* info /*= nullptr */ )
     32{
     33        nv::resource< nv::mesh_data > mr = default;
     34
     35        nv::string_view sub_mesh_name;
     36        nv::string128 base_mesh_name( path );
     37        nv::size_t sub_mesh_pos = path.find( ":" );
     38        nv::size_t dot_pos = path.find( "." );
     39        if ( sub_mesh_pos != nv::string_view::npos )
     40        {
     41                sub_mesh_name = path.substr( sub_mesh_pos + 1 );
     42                base_mesh_name.assign( path.substr( 0, sub_mesh_pos ) );
     43                NV_LOG_INFO( "Requested submesh - [", sub_mesh_name, "] in [", base_mesh_name, "]" );
     44        }
     45
     46        if ( dot_pos != nv::string_view::npos )
     47        {
     48                mr = get( base_mesh_name );
     49        }
     50        else
     51        {
     52                sub_mesh_name = base_mesh_name;
     53        }
     54
     55        if ( !mr )
     56        {
     57                NV_LOG_ERROR( "MESH FILE NOT FOUND - ", path );
     58                NV_ASSERT( false, "MESH FILE NOT FOUND!" );
     59                return nv::resource< nv::data_channel_set >();
     60        }
     61
     62        if ( auto mdata = mr.lock() )
     63        {
     64                sint32 index = -1;
     65                if ( sub_mesh_name.empty() )
     66                {
     67                        index = 0;
     68                }
     69                else if ( sub_mesh_name[0] >= '0' && sub_mesh_name[0] <= '9' )
     70                {
     71                        index = nv::buffer_to_uint32( sub_mesh_name.data(), nullptr );
     72                }
     73                else
     74                {
     75                        auto itr = mdata->names.find( sub_mesh_name );
     76                        if ( itr != mdata->names.end() )
     77                                index = itr->second;
     78                }
     79                if ( index >= 0 )
     80                {
     81                        if ( info )
     82                                *info = mdata->infos[index];
     83                        return mdata->meshes[index];
     84                }
     85
     86                NV_LOG_ERROR( "Resource path fail! - ", path );
     87                NV_ASSERT( false, "Resource path fail!" );
     88        }
     89        else
     90        {
     91                NV_LOG_ERROR( "Resource lock fail! - ", path );
     92                NV_ASSERT( false, "Resource lock fail!" );
     93        }
     94        return nv::resource< nv::data_channel_set >();
     95}
     96
     97bool nv::mesh_data_manager::load_resource( const string_view& id )
     98{
     99        nmd_loader* loader = nullptr;
     100        c_file_system fs;
     101        stream* mesh_file = open_stream( fs, id );
     102        if ( !mesh_file ) return false;
     103
     104        loader = new nmd_loader( m_strings );
     105        loader->load( *mesh_file );
     106        delete mesh_file;
     107
     108        mesh_data* result = new mesh_data;
     109        result->node_data = loader->release_data_node_list();
     110        if ( result->node_data )
     111        {
     112                data_node_list* nd = result->node_data;
     113                for ( uint32 i = 0; i < nd->size(); ++i )
     114                        result->node_names[(*nd)[i].name] = i;
     115        }
     116        for ( uint32 i = 0; i < loader->get_mesh_count(); ++i )
     117        {
     118                data_node_info info;
     119                data_channel_set* data = loader->release_mesh_data( i, info );
     120                result->infos.push_back( info );
     121                result->names[ info.name ] = i;
     122                auto mesh = m_mesh_manager->add( shash64( id.get_hash() + i ), data );
     123                result->meshes.push_back( mesh );
     124        }
     125        delete loader;
     126        if ( result )
     127                add( id, result );
     128        return result != nullptr;
     129}
  • trunk/src/engine/program_manager.cc

    r501 r505  
    4545}
    4646
     47nv::const_string nv::program_manager::file_to_string( const string_view& path )
     48{
     49        c_file_system fs;
     50        stream* fstream = open_stream( fs, path );
     51        if ( !fstream ) return const_string();
     52        uint32 size = fstream->size();
     53        const_string result( nullptr, size );
     54        fstream->read( const_cast<char*>( result.data() ), size, 1 );
     55        delete fstream;
     56        return result;
     57}
     58
    4759nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append )
    4860{
     
    5163        if ( table.is_string( "files" ) )
    5264        {
    53                 out.append( fs.slurp( table.get_string( "files" ) ) );
     65                out.append( file_to_string( table.get_string( "files" ) ) );
    5466        }
    5567        else if ( table.is_table( "files" ) )
     
    6173                        const_string include( inctable.get<const_string,uint32>(i) );
    6274                        if ( i == count ) out.append( "#line 1\n" );
    63                         out.append( fs.slurp( include ) );
     75                        out.append( file_to_string( include ) );
    6476                }
    6577        }
     
    6779        if ( table.is_string( "file" ) )
    6880        {
    69                 const_string data = fs.slurp( table.get_string( "file" ) );
     81                const_string data = file_to_string( table.get_string( "file" ) );
    7082                out.append( "#line 1\n" + data );
    7183        }
Note: See TracChangeset for help on using the changeset viewer.