- Timestamp:
- 05/29/15 17:28:16 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/library.cc
r365 r380 39 39 } 40 40 41 void library::open( const string&name )41 void library::open( string_ref name ) 42 42 { 43 m_name = name;43 m_name.assign( name.data(), name.size() ); 44 44 if ( !open() ) 45 45 { 46 46 m_handle = nullptr; 47 NV_THROW( library_error, "Can't load library!", name );47 NV_THROW( library_error, "Can't load library!", name.data() ); 48 48 } 49 49 } 50 50 51 bool nv::library::try_open( const string&name )51 bool nv::library::try_open( string_ref name ) 52 52 { 53 m_name = name;53 m_name.assign( name.data(), name.size() ); 54 54 if ( !open() ) 55 55 { … … 60 60 } 61 61 62 const string&library::get_name() const62 string_ref library::get_name() const 63 63 { 64 return m_name;64 return string_ref( m_name ); 65 65 } 66 66 … … 73 73 NV_LOG_NOTICE( "library : loading '", m_name, "'..." ); 74 74 75 string name = m_name; 76 string ext = NV_LIB_EXT; 77 size_t ext_len = ext.length(); 75 std::string name = m_name; 76 string_ref ext( NV_LIB_EXT ); 78 77 79 if ( name.length() < ext_len || name.substr( name.length() - ext_len, ext_len ) != ext ) 78 if ( name.length() < ext.length() || name.substr( name.length() - ext.length(), ext.length() ) != ext ) 80 79 { 81 name += ext;80 name.append( ext.data(), ext.length() ); 82 81 } 83 82 … … 93 92 } 94 93 95 void* library::get( const string&symbol )94 void* library::get( string_ref symbol ) 96 95 { 97 void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol. c_str() );96 void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.data() ); 98 97 if ( !result ) 99 98 { 100 NV_THROW( library_error, "Can't find symbol " + s ymbol+ "!", m_name );99 NV_THROW( library_error, "Can't find symbol " + std::string(symbol.data(),symbol.size()) + "!", m_name ); 101 100 } 102 101 return result; 103 102 } 104 103 105 void* nv::library::try_get( const string&symbol )104 void* nv::library::try_get( string_ref symbol ) 106 105 { 107 return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol. c_str() );106 return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.data() ); 108 107 } 109 108 … … 130 129 } 131 130 132 st ring library::get_error()131 std::string library::get_error() 133 132 { 134 133 #if NV_PLATFORM == NV_WINDOWS … … 137 136 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 138 137 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL ); 139 st ring msg( (char*)buffer );138 std::string msg( (char*)buffer ); 140 139 LocalFree( buffer ); 141 140 return msg; -
trunk/src/core/logger.cc
r376 r380 163 163 { 164 164 const char* lcolor = log_color[( level ) / 10]; 165 fwrite( lcolor, strlen(lcolor), 1, stdout );165 fwrite( lcolor, nvstrlen(lcolor), 1, stdout ); 166 166 } 167 167 fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, stdout ); -
trunk/src/core/profiler.cc
r376 r380 108 108 char buffer[128]; 109 109 snprintf( buffer, 128, "%-23s %6s %6s %9s %6s", "TAG", "%PARNT", "CALLS", "TOTAL(ms)", "AVG(ms)" ); 110 NV_LOG_INFO( string_ref( buffer, strlen(buffer) ) );110 NV_LOG_INFO( string_ref( buffer, nvstrlen( buffer ) ) ); 111 111 log_node_children( 0, m_root ); 112 112 NV_LOG_INFO( "-- PROFILER REPORT END ---------------------------------" ); … … 122 122 if ( c->m_calls > 0 ) 123 123 { 124 double pparent = ( (double)c->m_total_time_us / (double)c->m_parent->m_total_time_us ) * 100.f;125 intcalls = c->m_calls;126 doubletotal_ms = c->m_total_time_us / 1000.f;127 double avg_ms = ( (double)c->m_total_time_us / (double)c->m_calls ) / 1000.f;128 if ( indent > 0 ) memset( buffer, '-', indent );124 f64 pparent = ( (f64)c->m_total_time_us / (f64)c->m_parent->m_total_time_us ) * 100.f; 125 uint32 calls = c->m_calls; 126 f64 total_ms = c->m_total_time_us / 1000.f; 127 f64 avg_ms = ( (f64)c->m_total_time_us / (f64)c->m_calls ) / 1000.f; 128 if ( indent > 0 ) nvmemset( buffer, '-', indent ); 129 129 snprintf( buffer + indent, 128 - indent, "%*.*s %6.2f %6d %9.2f %6.2f", indent - 23, 23 - indent, 130 130 c->m_tag.c_str(), pparent, calls, total_ms, avg_ms ); 131 NV_LOG_INFO( string_ref( buffer, strlen( buffer ) ) );131 NV_LOG_INFO( string_ref( buffer, nvstrlen( buffer ) ) ); 132 132 if ( c->m_children.size() > 0 ) 133 133 { -
trunk/src/core/time.cc
r376 r380 74 74 struct timespec ts; 75 75 ts.tv_sec = 0; 76 ts.tv_nsec = ms * 1000000;76 ts.tv_nsec = (long)ms * 1000000; 77 77 nanosleep(&ts, NULL); 78 78 // usleep( ms * 1000 ); -
trunk/src/engine/program_manager.cc
r368 r380 46 46 } 47 47 48 void nv::program_manager::load_source( lua::table_guard& table, st ring& out, conststring& append )48 void nv::program_manager::load_source( lua::table_guard& table, std::string& out, const std::string& append ) 49 49 { 50 50 out = append; -
trunk/src/engine/resource_system.cc
r368 r380 36 36 } 37 37 38 nv::resource_type_id nv::resource_system::register_resource_type( const st ring& /*name*/, resource_manager_base* /*manager*/ )38 nv::resource_type_id nv::resource_system::register_resource_type( const std::string& /*name*/, resource_manager_base* /*manager*/ ) 39 39 { 40 40 return 0; 41 41 } 42 42 43 nv::resource_type_id nv::resource_system::get_resource_type_id( const st ring& /*name*/ ) const43 nv::resource_type_id nv::resource_system::get_resource_type_id( const std::string& /*name*/ ) const 44 44 { 45 45 return 0; -
trunk/src/formats/assimp_loader.cc
r376 r380 57 57 58 58 59 nv::assimp_loader::assimp_loader( const st ring& a_ext, uint32 a_assimp_flags /*= 0 */ )59 nv::assimp_loader::assimp_loader( const std::string& a_ext, uint32 a_assimp_flags /*= 0 */ ) 60 60 : m_scene( nullptr ), m_mesh_count(0) 61 61 { … … 374 374 const aiScene* scene = (const aiScene*)m_scene; 375 375 const aiNode* node = (const aiNode*)vnode; 376 st ring name( node->mName.data );376 std::string name( node->mName.data ); 377 377 const aiAnimation* anim = scene->mAnimations[anim_id]; 378 378 const aiNodeAnim* anode = nullptr; -
trunk/src/gfx/texture_font.cc
r367 r380 91 91 } 92 92 93 bool texture_font::load_glyphs( const string&codes )93 bool texture_font::load_glyphs( string_ref codes ) 94 94 { 95 95 FT_Face face = (FT_Face)(m_rface); -
trunk/src/gl/gl_device.cc
r365 r380 217 217 } 218 218 219 uniform_base* nv::gl_device::get_uniform( program p, const st ring& name, bool fatal /*= true */ ) const219 uniform_base* nv::gl_device::get_uniform( program p, const std::string& name, bool fatal /*= true */ ) const 220 220 { 221 221 const gl_program_info* info = m_programs.get( p ); … … 235 235 } 236 236 237 int nv::gl_device::get_attribute_location( program p, const st ring& name, bool fatal /*= true */ ) const237 int nv::gl_device::get_attribute_location( program p, const std::string& name, bool fatal /*= true */ ) const 238 238 { 239 239 const gl_program_info* info = m_programs.get( p ); … … 347 347 glGetActiveAttrib( p->glid, i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer ); 348 348 349 st ring name( name_buffer, size_t(attr_nlen) );349 std::string name( name_buffer, size_t( attr_nlen ) ); 350 350 351 351 // skip built-ins … … 376 376 glGetActiveUniform( p->glid, i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer ); 377 377 378 st ring name( name_buffer, size_t(uni_nlen) );378 std::string name( name_buffer, size_t( uni_nlen ) ); 379 379 380 380 // skip built-ins … … 385 385 386 386 // check for array 387 st ring::size_type arrchar = name.find('[');388 if ( arrchar != st ring::npos )387 std::string::size_type arrchar = name.find( '[' ); 388 if ( arrchar != std::string::npos ) 389 389 { 390 390 name = name.substr( 0, arrchar ); -
trunk/src/gui/gui_environment.cc
r356 r380 311 311 } 312 312 313 void nv::gui::environment::set_class( handle e, const st ring& text )313 void nv::gui::environment::set_class( handle e, const std::string& text ) 314 314 { 315 315 element* ep = m_elements.get(e); … … 321 321 } 322 322 323 void nv::gui::environment::set_text( handle e, const st ring& text )323 void nv::gui::environment::set_text( handle e, const std::string& text ) 324 324 { 325 325 element* ep = m_elements.get(e); -
trunk/src/gui/gui_gfx_renderer.cc
r378 r380 190 190 { 191 191 std::string id_name( filename ); 192 id_name.append( std::to_string( size ) ); 192 char buffer[8]; size_t len = nv::sint32_to_buffer( (sint32)size, buffer ); 193 id_name.append( std::string( buffer, len ) ); 193 194 auto i = m_font_names.find( id_name ); 194 195 if ( i != m_font_names.end() ) -
trunk/src/lua/lua_glm.cc
r378 r380 295 295 switch ( v.length() ) 296 296 { 297 case 1: lua_pushfstring( L, ( fl ? "(%f)" : "(%d)" ), v[0] ); 298 case 2: lua_pushfstring( L, ( fl ? "(%f,%f)" : "(%d,%d)" ), v[0], v[1] ); 299 case 3: lua_pushfstring( L, ( fl ? "(%f,%f,%f)" : "(%d,%d,%d)" ), v[0], v[1], v[2] ); 300 case 4: lua_pushfstring( L, ( fl ? "(%f,%f,%f,%f)" : "(%d,%d,%d,%d)" ), v[0], v[1], v[2], v[3] ); 297 case 1: lua_pushfstring( L, ( fl ? "(%f)" : "(%d)" ), v[0] ); break; 298 case 2: lua_pushfstring( L, ( fl ? "(%f,%f)" : "(%d,%d)" ), v[0], v[1] ); break; 299 case 3: lua_pushfstring( L, ( fl ? "(%f,%f,%f)" : "(%d,%d,%d)" ), v[0], v[1], v[2] ); break; 300 case 4: lua_pushfstring( L, ( fl ? "(%f,%f,%f,%f)" : "(%d,%d,%d,%d)" ), v[0], v[1], v[2], v[3] ); break; 301 301 default: 302 302 lua_pushliteral( L, "(vector?)" ); break; -
trunk/src/lua/lua_path.cc
r376 r380 32 32 } 33 33 34 void lua::path::push( nv:: size_tvalue )34 void lua::path::push( nv::uint32 value ) 35 35 { 36 36 m_elements[ m_count ].value = value; … … 50 50 if (m_count == 0) return false; 51 51 if (global) lua_pushglobaltable( L ); 52 for ( inti = 0; i < m_count; ++i )52 for ( uint32 i = 0; i < m_count; ++i ) 53 53 { 54 54 if ( lua_istable( L, -1 ) ) … … 76 76 std::string nv::lua::path::to_string() const 77 77 { 78 std::string result; 79 result.reserve( 64 ); 78 char buffer[64]; 79 char* start = buffer; 80 char* current = buffer; 80 81 bool dot = false; 82 bool oos = false; 81 83 for ( const element& e : m_elements ) 82 84 { 83 if ( dot ) result.append("."); 85 if ( current - start > 48 ) { oos = true; break; } 86 if ( dot ) *current++ = '.'; 84 87 if ( e.length == 0 ) 85 88 { 86 result.append("[" + nv::to_string( e.value ) + "]" ); 89 *current++ = '['; 90 current += uint32_to_buffer( e.value, current ); 91 *current++ = ']'; 87 92 dot = false; 88 93 } 89 94 else 90 95 { 91 result.append( e.str, e.length ); 96 if ( size_t(current - start) + e.length > 60 ) { oos = true; break; } 97 nvmemcpy( current, e.str, e.length ); 98 current += e.length; 92 99 dot = true; 93 100 } 94 101 } 95 return result; 102 if (oos) 103 { 104 *current++ = '.'; 105 *current++ = '.'; 106 *current++ = '.'; 107 } 108 *current++ = '\0'; 109 return std::string( buffer, size_t(current - start - 1) ); 96 110 } -
trunk/src/lua/lua_raw.cc
r368 r380 11 11 std::string nlua_typecontent( lua_State* L, int idx ) 12 12 { 13 switch ( lua_type( L, idx ) ) 13 int type = lua_type( L, idx ); 14 switch ( type ) 14 15 { 15 16 case LUA_TNONE : return "NONE"; 16 17 case LUA_TNIL : return "NIL"; 17 18 case LUA_TBOOLEAN : return lua_toboolean( L, idx ) == 0 ? "false" : "true"; 18 case LUA_TLIGHTUSERDATA : return nv::to_string( nv::uint64( lua_touserdata( L, idx ) ) );19 case LUA_TNUMBER : return nv::to_string( lua_tonumber( L, idx ) );19 //case LUA_TLIGHTUSERDATA : return std::to_string( nv::uint64( lua_touserdata( L, idx ) ) ); 20 //case LUA_TNUMBER : return std::to_string( lua_tonumber( L, idx ) ); 20 21 case LUA_TSTRING : return lua_tostring( L, idx ); 21 22 case LUA_TTABLE : return "TABLE"; 22 23 case LUA_TFUNCTION : return "FUNCTION"; 23 case LUA_TUSERDATA : return nv::to_string( nv::uint64( lua_touserdata( L, idx ) ) );24 // case LUA_TUSERDATA : return std::to_string( nv::uint64( lua_touserdata( L, idx ) ) ); 24 25 case LUA_TTHREAD : return "THREAD"; 25 default : return "UNKNOWN!"; 26 } 26 default : break; 27 } 28 char buffer[64]; 29 if ( type == LUA_TLIGHTUSERDATA || type == LUA_TUSERDATA ) 30 { 31 size_t l = nv::uint64_to_buffer( nv::uint64( lua_touserdata( L, idx ) ), buffer ); 32 return std::string( buffer, l ); 33 } 34 else if ( type == LUA_TNUMBER ) 35 { 36 size_t l = nv::f64_to_buffer( lua_tonumber( L, idx ), buffer ); 37 return std::string( buffer, l ); 38 } 39 return "UNKNOWN!"; 27 40 } 28 41 -
trunk/src/lua/lua_state.cc
r376 r380 179 179 } 180 180 181 st ring lua::table_guard::get_std_string( string_ref element, string_ref defval /*= string_ref() */ )181 std::string lua::table_guard::get_std_string( string_ref element, string_ref defval /*= string_ref() */ ) 182 182 { 183 183 lua_getfield( m_state, -1, element.data() ); -
trunk/src/sdl/sdl_window.cc
r367 r380 75 75 } 76 76 77 void sdl::window::set_title( const st ring& title )77 void sdl::window::set_title( const std::string& title ) 78 78 { 79 79 SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() ); -
trunk/src/stl/string.cc
r378 r380 97 97 { 98 98 #if NV_COMPILER == NV_MSVC 99 sprintf_s( str, 64, "%.*g", 6, n );99 int result = sprintf_s( str, 64, "%.*g", 6, n ); 100 100 #else 101 snprintf( str, 64, "%.*g", 6, n );101 int result = snprintf( str, 64, "%.*g", 6, n ); 102 102 #endif 103 sprintf( str, "%g", n ); 104 return strlen( str ); 103 return result > 0 ? ( nv::size_t )result : 0; 105 104 } 106 105 … … 108 107 { 109 108 #if NV_COMPILER == NV_MSVC 110 sprintf_s( str, 64, "%.*g", 6, n );109 int result = sprintf_s( str, 64, "%.*g", 6, n ); 111 110 #else 112 snprintf( str, 64, "%.*g", 6, n );111 int result = snprintf( str, 64, "%.*g", 6, n ); 113 112 #endif 114 return strlen( str );113 return result > 0 ? ( nv::size_t )result : 0; 115 114 } 116 115 … … 162 161 while ( *s >= '0' && *s <= '9' ) 163 162 { 164 result = ( result * 10 ) + ( *s - '0' );163 result = ( result * 10 ) + (uint32)( *s - '0' ); 165 164 ++s; 166 165 } … … 175 174 while ( *s >= '0' && *s <= '9' ) 176 175 { 177 result = ( result * 10 ) + ( *s - '0' );176 result = ( result * 10 ) + (uint32)( *s - '0' ); 178 177 ++s; 179 178 }
Note: See TracChangeset
for help on using the changeset viewer.