Changeset 438 for trunk/src


Ignore:
Timestamp:
07/23/15 17:29:49 (10 years ago)
Author:
epyon
Message:
  • massive amount of std::string removal
  • removed slurp, use filesystem::slurp instead
  • lua_values const_string support
  • several bugfixes
  • program_manager and shader loading without std::string/std::stream
Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/library.cc

    r437 r438  
    66
    77#include "nv/core/library.hh"
    8 #include <string>
    98
    109#if NV_PLATFORM == NV_WINDOWS
     
    7473    NV_LOG_NOTICE( "library \"", m_name, "\" : loading..." );
    7574
    76         std::string name( m_name.data(), m_name.length() );
    77         std::string ext( NV_LIB_EXT );
     75        string128 name( m_name );
     76        string_view ext( NV_LIB_EXT );
    7877
    79         if ( name.length() < ext.length() || name.substr( name.length() - ext.length(), ext.length() ) != ext )
     78        if ( name.length() < ext.length() || !name.ends_with( ext ) )
    8079    {
    81         name.append( ext.data(), ext.length() );
     80        name.append( ext );
    8281    }
    8382
    84     m_handle = NV_LIB_OPEN( name.c_str() );
     83    m_handle = NV_LIB_OPEN( name.data() );
    8584
    8685    if ( m_handle == NULL )
    8786    {
    88                 NV_LOG_NOTICE( "library \"", m_name, "\" : failed to open!" );
     87                NV_LOG_NOTICE( "library \"", name, "\" : failed to open!" );
    8988                return false;
    9089    }
  • trunk/src/engine/program_manager.cc

    r433 r438  
    99#include "nv/core/logging.hh"
    1010#include "nv/lua/lua_nova.hh"
    11 
     11#include "nv/io/c_file_system.hh"
    1212
    1313nv::program_manager::program_manager( context* a_context ) : m_context( a_context )
    1414{
    15         m_vertex_head   = a_context->get_device()->get_shader_header();
    16         m_fragment_head = a_context->get_device()->get_shader_header();
     15        m_shader_head = a_context->get_device()->get_shader_header();
    1716}
    1817
     
    2019{
    2120        NV_LOG_DEBUG( table.get_string("id") );
    22         std::string vsource;
    23         std::string fsource;
    24         std::string csource;
     21        string_buffer vsource;
     22        string_buffer fsource;
     23        string_buffer header( m_shader_head );
    2524        if ( table.is_table("common") )
    2625        {
    2726                lua::table_guard common( table, "common" );
    28                 load_source( common, csource, "" );
     27                header.append( "\n" + load_source( common, "" ) + "\n" );
    2928        }
    3029        {
    3130                lua::table_guard vtable( table, "vertex" );
    32                 load_source( vtable, vsource, m_vertex_head+"\n"+csource+"\n");
     31                vsource = load_source( vtable, header );
    3332        }
    3433        {
    3534                lua::table_guard ftable( table, "fragment" );
    36                 load_source( ftable, fsource, m_fragment_head+"\n"+csource+"\n" );
     35                fsource = load_source( ftable, header );
    3736        }
    3837
    39         nv::program program = m_context->get_device()->create_program( string_view( vsource.c_str(), vsource.size() ), string_view( fsource.c_str(), fsource.size() ) );
     38        nv::program program = m_context->get_device()->create_program( vsource, fsource );
    4039        return add( program );
    4140}
     
    4645}
    4746
    48 void nv::program_manager::load_source( lua::table_guard& table, std::string& out, const std::string& append )
     47nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append )
    4948{
    50         out = append;
     49        c_file_system fs;
     50        string_buffer out( append );
    5151        if ( table.is_string( "files" ) )
    5252        {
    53                 out += nv::slurp( table.get_std_string( "files" ) );
     53                out.append( fs.slurp( table.get_string( "files" ) ) );
    5454        }
    5555        else if ( table.is_table( "files" ) )
     
    5959                for ( uint32 i = 1; i <= count; ++i )
    6060                {
    61                         std::string include( inctable.get<std::string,uint32>(i) );
    62                         if ( i == count ) out += "#line 1\n";
    63                         out += nv::slurp( include );
     61                        const_string include( inctable.get<const_string,uint32>(i) );
     62                        if ( i == count ) out.append( "#line 1\n" );
     63                        out.append( fs.slurp( include ) );
    6464                }
    6565        }
     
    6767        if ( table.is_string( "file" ) )
    6868        {
    69                 out += "#line 1\n" + nv::slurp( table.get_std_string( "file" ) );
     69                const_string data = fs.slurp( table.get_string( "file" ) );
     70                out.append( "#line 1\n" + data );
    7071        }
    7172
    7273        if ( table.is_string( "source" ) )
    7374        {
    74                 out += table.get_std_string( "source" );
     75                out.append( table.get_string( "source" ) );
    7576        }
     77        return out;
    7678}
  • trunk/src/gfx/texture_font.cc

    r405 r438  
    2929}
    3030
    31 texture_font::texture_font( texture_atlas* atlas, const char * filename, float size )
    32         : m_atlas( atlas ), m_filename(filename), m_size( size ),
     31texture_font::texture_font( texture_atlas* atlas, const string_view& filename, float size )
     32        : m_atlas( atlas ), m_filename( filename ), m_size( size ),
    3333        m_height(0), m_linegap(0), m_ascender(0), m_descender(0),
    3434        m_hinting( true ), m_filtering( true ), m_rlibrary( nullptr ), m_rface( nullptr )
     
    5353        NV_CHECK_FREETYPE_ERROR( error, "error on FT_Init_FreeType, code - ", error );
    5454
    55         error = FT_New_Face( reinterpret_cast<FT_Library>(m_rlibrary), filename, 0, reinterpret_cast<FT_Face*>(&m_rface) );
     55        error = FT_New_Face( reinterpret_cast<FT_Library>(m_rlibrary), filename.data(), 0, reinterpret_cast<FT_Face*>(&m_rface) );
    5656        NV_CHECK_FREETYPE_ERROR( error, "error on FT_New_Face, code - ", error );
    5757
  • trunk/src/gl/gl_device.cc

    r433 r438  
    1717gl_device::gl_device()
    1818{
    19         m_shader_header  = "#version 120\n";
     19        m_shader_header.append( "#version 120\n" );
    2020        for ( auto& i : get_uniform_factory() )
    21                 m_shader_header += "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ std::string( i.first.data(), i.first.size() ) +";\n";
     21                m_shader_header.append( "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ i.first +";\n" );
    2222        for ( auto& i : get_link_uniform_factory() )
    23                 m_shader_header += "uniform sampler2D "+std::string( i.first.data(), i.first.size() ) +";\n";
     23                m_shader_header.append( "uniform sampler2D "+i.first +";\n" );
    2424}
    2525
  • trunk/src/gl/gl_enum.cc

    r395 r438  
    354354}
    355355
    356 std::string nv::datatype_to_glsl_type( datatype type )
     356string_view nv::datatype_to_glsl_type( datatype type )
    357357{
    358358        switch( type )
  • trunk/src/io/c_file_system.cc

    r395 r438  
    1111using namespace nv;
    1212
     13
    1314c_file_system::c_file_system()
    1415{
     
    2122}
    2223
    23 bool c_file_system::exists( const char* fpath )
     24bool c_file_system::exists( const string_view& fpath )
    2425{
    25         FILE* file = ::fopen( fpath, "rb" );
     26        FILE* file = ::fopen( fpath.data(), "rb" );
    2627        if ( !file )
    2728        {
     
    3233}
    3334
    34 stream* c_file_system::open( const char* fpath, const char* fmode /*= "rb" */ )
     35stream* c_file_system::open( const string_view& fpath, const string_view& fmode /*= "rb" */ )
    3536{
    36         NV_ASSERT( fpath != nullptr && fmode != nullptr, "Bad parameters passed to open" );
    37         FILE* file = ::fopen( fpath, fmode );
     37        NV_ASSERT( !fpath.empty() && !fmode.empty(), "Bad parameters passed to open" );
     38        FILE* file = ::fopen( fpath.data(), fmode.data() );
    3839        if ( !file )
    3940        {
    4041                return nullptr;
    4142        }
    42         return new c_stream( file, fpath );
     43        return new c_stream( file, fpath.data() );
    4344}
     45
     46nv::const_string c_file_system::slurp( const string_view& path )
     47{
     48        stream* fstream = open( path, "rb" );
     49        if ( !fstream ) return const_string();
     50        uint32 size = fstream->size();
     51        const_string result( nullptr, size );
     52        fstream->read( const_cast<char*>( result.data() ), size, 1 );
     53        delete fstream;
     54        return result;
     55}
  • trunk/src/lua/lua_raw.cc

    r437 r438  
    3030        {
    3131                size_t l = nv::uint64_to_buffer( buffer, nv::uint64( lua_touserdata( L, idx ) ) );
    32                 return nv::string_view( buffer.data(), buffer.size() );
     32                return nv::string_view( buffer.data(), l );
    3333        }
    3434        else if ( type == LUA_TNUMBER )
    3535        {
    3636                size_t l = nv::f64_to_buffer( buffer, lua_tonumber( L, idx ) );
    37                 return nv::string_view( buffer.data(), buffer.size() );
     37                return nv::string_view( buffer.data(), l );
    3838        }
    3939        return "UNKNOWN!";
  • trunk/src/stl/string.cc

    r435 r438  
    1212#include <cstdlib>
    1313#include <fstream> // for slurp only
     14#include <sstream> // for slurp only
    1415
    1516using namespace nv;
    1617
    1718//static const double s_power_10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
    18 
    19 std::string nv::slurp( const std::string& filename )
    20 {
    21         std::ifstream input( filename );
    22         //              if ( !input.is_open() ) NV_THROW( std::runtime_error, "File "+filename+" not found!");
    23         std::stringstream sstr;
    24         while ( input >> sstr.rdbuf() );
    25         return sstr.str();
    26 }
    2719
    2820static inline void string_reverse( char* begin, char* end )
Note: See TracChangeset for help on using the changeset viewer.