- Timestamp:
- 07/23/15 17:29:49 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/library.cc
r437 r438 6 6 7 7 #include "nv/core/library.hh" 8 #include <string>9 8 10 9 #if NV_PLATFORM == NV_WINDOWS … … 74 73 NV_LOG_NOTICE( "library \"", m_name, "\" : loading..." ); 75 74 76 st d::string name( m_name.data(), m_name.length());77 st d::stringext( NV_LIB_EXT );75 string128 name( m_name ); 76 string_view ext( NV_LIB_EXT ); 78 77 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 ) ) 80 79 { 81 name.append( ext .data(), ext.length());80 name.append( ext ); 82 81 } 83 82 84 m_handle = NV_LIB_OPEN( name. c_str() );83 m_handle = NV_LIB_OPEN( name.data() ); 85 84 86 85 if ( m_handle == NULL ) 87 86 { 88 NV_LOG_NOTICE( "library \"", m_name, "\" : failed to open!" );87 NV_LOG_NOTICE( "library \"", name, "\" : failed to open!" ); 89 88 return false; 90 89 } -
trunk/src/engine/program_manager.cc
r433 r438 9 9 #include "nv/core/logging.hh" 10 10 #include "nv/lua/lua_nova.hh" 11 11 #include "nv/io/c_file_system.hh" 12 12 13 13 nv::program_manager::program_manager( context* a_context ) : m_context( a_context ) 14 14 { 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(); 17 16 } 18 17 … … 20 19 { 21 20 NV_LOG_DEBUG( table.get_string("id") ); 22 st d::stringvsource;23 st d::stringfsource;24 st d::string csource;21 string_buffer vsource; 22 string_buffer fsource; 23 string_buffer header( m_shader_head ); 25 24 if ( table.is_table("common") ) 26 25 { 27 26 lua::table_guard common( table, "common" ); 28 load_source( common, csource, "" );27 header.append( "\n" + load_source( common, "" ) + "\n" ); 29 28 } 30 29 { 31 30 lua::table_guard vtable( table, "vertex" ); 32 load_source( vtable, vsource, m_vertex_head+"\n"+csource+"\n");31 vsource = load_source( vtable, header ); 33 32 } 34 33 { 35 34 lua::table_guard ftable( table, "fragment" ); 36 load_source( ftable, fsource, m_fragment_head+"\n"+csource+"\n");35 fsource = load_source( ftable, header ); 37 36 } 38 37 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 ); 40 39 return add( program ); 41 40 } … … 46 45 } 47 46 48 void nv::program_manager::load_source( lua::table_guard& table, std::string& out, const std::string& append )47 nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append ) 49 48 { 50 out = append; 49 c_file_system fs; 50 string_buffer out( append ); 51 51 if ( table.is_string( "files" ) ) 52 52 { 53 out += nv::slurp( table.get_std_string( "files") );53 out.append( fs.slurp( table.get_string( "files" ) ) ); 54 54 } 55 55 else if ( table.is_table( "files" ) ) … … 59 59 for ( uint32 i = 1; i <= count; ++i ) 60 60 { 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 ) ); 64 64 } 65 65 } … … 67 67 if ( table.is_string( "file" ) ) 68 68 { 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 ); 70 71 } 71 72 72 73 if ( table.is_string( "source" ) ) 73 74 { 74 out += table.get_std_string( "source");75 out.append( table.get_string( "source" ) ); 75 76 } 77 return out; 76 78 } -
trunk/src/gfx/texture_font.cc
r405 r438 29 29 } 30 30 31 texture_font::texture_font( texture_atlas* atlas, const char *filename, float size )32 : m_atlas( atlas ), m_filename( filename), m_size( size ),31 texture_font::texture_font( texture_atlas* atlas, const string_view& filename, float size ) 32 : m_atlas( atlas ), m_filename( filename ), m_size( size ), 33 33 m_height(0), m_linegap(0), m_ascender(0), m_descender(0), 34 34 m_hinting( true ), m_filtering( true ), m_rlibrary( nullptr ), m_rface( nullptr ) … … 53 53 NV_CHECK_FREETYPE_ERROR( error, "error on FT_Init_FreeType, code - ", error ); 54 54 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) ); 56 56 NV_CHECK_FREETYPE_ERROR( error, "error on FT_New_Face, code - ", error ); 57 57 -
trunk/src/gl/gl_device.cc
r433 r438 17 17 gl_device::gl_device() 18 18 { 19 m_shader_header = "#version 120\n";19 m_shader_header.append( "#version 120\n" ); 20 20 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" ); 22 22 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" ); 24 24 } 25 25 -
trunk/src/gl/gl_enum.cc
r395 r438 354 354 } 355 355 356 st d::stringnv::datatype_to_glsl_type( datatype type )356 string_view nv::datatype_to_glsl_type( datatype type ) 357 357 { 358 358 switch( type ) -
trunk/src/io/c_file_system.cc
r395 r438 11 11 using namespace nv; 12 12 13 13 14 c_file_system::c_file_system() 14 15 { … … 21 22 } 22 23 23 bool c_file_system::exists( const char*fpath )24 bool c_file_system::exists( const string_view& fpath ) 24 25 { 25 FILE* file = ::fopen( fpath , "rb" );26 FILE* file = ::fopen( fpath.data(), "rb" ); 26 27 if ( !file ) 27 28 { … … 32 33 } 33 34 34 stream* c_file_system::open( const char* fpath, const char*fmode /*= "rb" */ )35 stream* c_file_system::open( const string_view& fpath, const string_view& fmode /*= "rb" */ ) 35 36 { 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() ); 38 39 if ( !file ) 39 40 { 40 41 return nullptr; 41 42 } 42 return new c_stream( file, fpath );43 return new c_stream( file, fpath.data() ); 43 44 } 45 46 nv::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 30 30 { 31 31 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 ); 33 33 } 34 34 else if ( type == LUA_TNUMBER ) 35 35 { 36 36 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 ); 38 38 } 39 39 return "UNKNOWN!"; -
trunk/src/stl/string.cc
r435 r438 12 12 #include <cstdlib> 13 13 #include <fstream> // for slurp only 14 #include <sstream> // for slurp only 14 15 15 16 using namespace nv; 16 17 17 18 //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 }27 19 28 20 static inline void string_reverse( char* begin, char* end )
Note: See TracChangeset
for help on using the changeset viewer.