- Timestamp:
- 07/23/15 21:16:01 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/engine/resource_system.cc
r433 r440 12 12 { 13 13 m_lua = a_lua_state; 14 st d::string delete_me = "register_" + std::string( get_resource_name().data(), get_resource_name().size());15 lua::register_storage( m_lua, get_storage_name(), st ring_view( delete_me.c_str(), delete_me.size() ));14 string128 storage_name = "register_" + get_resource_name(); 15 lua::register_storage( m_lua, get_storage_name(), storage_name ); 16 16 } 17 17 -
trunk/src/formats/md5_loader.cc
r433 r440 14 14 #include <stdio.h> // sscanf 15 15 #include <stdlib.h> // atof 16 17 #include <string> // TODO: remove 16 18 17 19 using namespace nv; -
trunk/src/gui/gui_ascii_renderer.cc
r406 r440 49 49 er->clear = true; 50 50 int color = 0; 51 std::string path; 52 std::string text; 51 string128 path; 53 52 const char* stext[] = { nullptr, "selected", "hover" }; 54 53 const char* selector = stext[0]; -
trunk/src/gui/gui_environment.cc
r433 r440 9 9 #include "nv/gui/gui_renderer.hh" 10 10 11 #include <algorithm> // std::find on std::list12 13 11 /* 14 12 … … 27 25 : m_renderer( r ) 28 26 { 27 r->set_environment( this ); 29 28 m_screen = create_element( handle(), m_renderer->get_area() ); 30 29 } … … 161 160 while ( !parent->m_children.empty() ) 162 161 { 163 destroy_element( parent->m_children. front() );162 destroy_element( parent->m_children.back() ); 164 163 } 165 164 } … … 196 195 } 197 196 197 nv::string_view nv::gui::environment::get_string( shash64 h ) 198 { 199 return m_strings[h]; 200 } 201 198 202 bool nv::gui::environment::set_selected( handle e ) 199 203 { … … 235 239 236 240 handle result; 237 element::list::reverse_iteratorit = el->m_children.rbegin();241 auto it = el->m_children.rbegin(); 238 242 239 243 while ( it != el->m_children.rend() ) … … 254 258 if ( e && parent ) 255 259 { 256 auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );260 auto it = find( parent->m_children.begin(), parent->m_children.end(), child ); 257 261 if ( it != parent->m_children.end() ) 258 262 { … … 264 268 } 265 269 266 void nv::gui::environment::move_to_bottom( handle child )267 {268 element* e = m_elements.get( child );269 element* parent = m_elements.get( e->m_parent );270 if ( e && parent )271 {272 auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );273 if ( it != parent->m_children.end() )274 {275 parent->m_children.erase( it );276 parent->m_children.push_front( child );277 parent->m_flags[DIRTY] = true;278 }279 }280 }281 282 270 void nv::gui::environment::set_relative( handle e, const rectangle& r ) 283 271 { … … 312 300 } 313 301 314 void nv::gui::environment::set_class( handle e, const st d::string& text )302 void nv::gui::environment::set_class( handle e, const string_view& text ) 315 303 { 316 304 element* ep = m_elements.get(e); 317 305 if ( ep != nullptr ) 318 306 { 319 ep->m_class = text;307 ep->m_class = m_strings.insert( text ); 320 308 ep->m_flags[DIRTY] = true; 321 309 } 322 310 } 323 311 324 void nv::gui::environment::set_text( handle e, const st d::string& text )312 void nv::gui::environment::set_text( handle e, const string_twine& text ) 325 313 { 326 314 element* ep = m_elements.get(e); 327 315 if ( ep != nullptr ) 328 316 { 329 ep->m_text = text;317 ep->m_text.assign( text ); 330 318 ep->m_flags[DIRTY] = true; 331 319 } … … 337 325 if ( p ) 338 326 { 339 auto it = std::find( p->m_children.begin(), p->m_children.end(), child );327 auto it = find( p->m_children.begin(), p->m_children.end(), child ); 340 328 if ( it != p->m_children.end() ) 341 329 { 342 330 element* e = m_elements.get( *it ); 343 331 e->m_parent = handle(); 344 p->m_children.erase( it);345 } 346 } 347 } 348 332 p->m_children.erase( it ); 333 } 334 } 335 } 336 -
trunk/src/gui/gui_gfx_renderer.cc
r437 r440 243 243 int border = 0; 244 244 vec4 color; 245 std::string path; 246 std::string text; 247 const char* stext[] = { nullptr, "selected", "hover" }; 245 string128 path; 246 const char* stext[] = { "", "selected", "hover" }; 248 247 const char* selector = stext[border]; 249 248 if ( e->m_flags[HOVER] ) selector = stext[2]; … … 252 251 if ( m_style.get( e, "skin", selector, path ) ) 253 252 { 254 size_t image_id = load_image( string_view( path.c_str(), path.size() ));253 size_t image_id = load_image( path ); 255 254 const image_info* image = get_image( image_id ); 256 255 if ( image ) … … 312 311 } 313 312 314 text =e->m_text;315 if ( ! text.empty() )313 e->m_text; 314 if ( !e->m_text.empty() ) 316 315 { 317 316 if ( m_style.get( e, "text_color", selector, color ) && m_style.get( e, "text_font", selector, path ) && m_style.get( e, "text_size", selector, border ) ) 318 317 { 319 size_t font_id = load_font( string_view( path.c_str(), path.size() ), size_t( border ) );318 size_t font_id = load_font( path, size_t( border ) ); 320 319 texture_font* font = get_font( font_id ); 321 320 position p = abs.ul + position( 0, border ); 322 for ( char c : text )321 for ( char c : e->m_text ) 323 322 { 324 323 const texture_glyph* g = font->get_glyph( static_cast<uint16>( c ) ); -
trunk/src/gui/gui_style.cc
r433 r440 7 7 #include "nv/gui/gui_style.hh" 8 8 9 #include "nv/gui/gui_environment.hh" 9 10 #include <nv/lua/lua_raw.hh> 10 11 … … 12 13 using namespace nv::gui; 13 14 14 style::style()15 {16 }17 18 15 void style::load_style( const string_view& filename ) 19 16 { 17 NV_ASSERT_ALWAYS( m_env, "Environment not set in style!" ); 20 18 m_lua.do_file( filename ); 21 19 } 22 20 23 bool style::get( element* e, const char* centry, const char* cselector, std::string& s )21 bool style::get( element* e, const string_view& centry, const string_view& cselector, string128& s ) 24 22 { 25 23 lua::stack_guard guard( m_lua ); 26 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TSTRING ) ) return false; 27 s = lua_tostring( m_lua, -1 ); 24 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TSTRING ) ) return false; 25 // TODO: create lua_tostringbuffer< size > 26 s.assign( lua_tostring( m_lua, -1 ) ); 28 27 return true; 29 28 } 30 29 31 bool style::get( element* e, const char* centry, const char*cselector, vec4& vec )30 bool style::get( element* e, const string_view& centry, const string_view& cselector, vec4& vec ) 32 31 { 33 32 lua::stack_guard guard( m_lua ); 34 if ( !resolve( e->m_id .c_str(), e->m_class.c_str(), cselector, centry, LUA_TTABLE ) ) return false;33 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TTABLE ) ) return false; 35 34 vec = vec4(); 36 35 for ( int i = 0; i < 4; ++i ) … … 44 43 } 45 44 46 bool style::get( element* e, const char* centry, const char*cselector, int& i )45 bool style::get( element* e, const string_view& centry, const string_view& cselector, int& i ) 47 46 { 48 47 lua::stack_guard guard( m_lua ); 49 if ( !resolve( e->m_id .c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;48 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false; 50 49 i = static_cast< int >( lua_tointeger( m_lua, -1 ) ); 51 50 return true; 52 51 } 53 52 54 bool style::get( element* e, const char* centry, const char*cselector, double& d )53 bool style::get( element* e, const string_view& centry, const string_view& cselector, double& d ) 55 54 { 56 55 lua::stack_guard guard( m_lua ); 57 if ( !resolve( e->m_id .c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;56 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false; 58 57 d = lua_tonumber( m_lua, -1 ); 59 58 return true; … … 64 63 } 65 64 66 bool style::find_entry( const char* cselector, const char*centry, int type )65 bool style::find_entry( const string_view& cselector, const string_view& centry, int type ) 67 66 { 68 67 if ( lua_istable( m_lua, -1 ) ) 69 68 { 70 if ( cselector)69 if ( !cselector.empty() ) 71 70 { 72 lua_getfield( m_lua, -1, cselector );71 lua_getfield( m_lua, -1, cselector.data() ); 73 72 if ( lua_istable( m_lua, -1 ) ) 74 73 { 75 lua_getfield( m_lua, -1, centry );74 lua_getfield( m_lua, -1, centry.data() ); 76 75 if ( lua_type( m_lua, -1 ) == type ) 77 76 { … … 83 82 } 84 83 85 lua_getfield( m_lua, -1, centry );84 lua_getfield( m_lua, -1, centry.data() ); 86 85 if ( lua_type( m_lua, -1 ) == type ) return true; 87 86 } … … 89 88 } 90 89 91 bool style::resolve( const char* cid, const char* cclass, const char* cselector, const char*centry, int type )90 bool style::resolve( shash64 cid, shash64 cclass, const string_view& cselector, const string_view& centry, int type ) 92 91 { 93 92 lua_getglobal( m_lua, "default" ); … … 95 94 96 95 // check id 97 lua_getfield( m_lua, -1, cid ); 98 if ( find_entry( cselector, centry, type ) ) return true; 99 lua_settop( m_lua, global ); 100 96 string_view id( m_env->get_string( cid ) ); 97 if ( !id.empty() ) 98 { 99 lua_getfield( m_lua, -1, id.data() ); 100 if ( find_entry( cselector, centry, type ) ) return true; 101 lua_settop( m_lua, global ); 102 } 101 103 // check class 102 lua_getfield( m_lua, -1, cclass ); 103 if ( find_entry( cselector, centry, type ) ) return true; 104 lua_settop( m_lua, global ); 104 string_view klass( m_env->get_string( cclass ) ); 105 if ( !klass.empty() ) 106 { 107 lua_getfield( m_lua, -1, klass.data() ); 108 if ( find_entry( cselector, centry, type ) ) return true; 109 lua_settop( m_lua, global ); 110 } 105 111 106 112 // check entry -
trunk/src/lib/gl.cc
r406 r440 56 56 57 57 58 static void* load_gl_ext_symbol_impl( const char*name, nv::log_level fail_level = nv::LOG_DEBUG )59 { 60 void* result = gl_ext_loader( name );58 static void* load_gl_ext_symbol_impl( const nv::string_view& name, nv::log_level fail_level = nv::LOG_DEBUG ) 59 { 60 void* result = gl_ext_loader( name.data() ); 61 61 NV_LOG( ( result ? nv::LOG_DEBUG : fail_level ), "load_gl_ext_symbol : ", name, ( result ? " succeded." : "failed." ) ); 62 62 return result; 63 63 } 64 64 65 static void* load_gl_ext_symbol( const char* name, bool iterate, const char*ext )65 static void* load_gl_ext_symbol( const nv::string_view& name, bool iterate, const nv::string_view& ext ) 66 66 { 67 67 void * result = nullptr; 68 result = load_gl_ext_symbol_impl( ext ? ( std::string(name) + ext ).c_str() : name ); 68 nv::string128 test_name = name + ext; 69 result = load_gl_ext_symbol_impl( !ext.empty() ? test_name : name ); 69 70 if ( result ) return result; 70 71 if ( iterate ) 71 72 { 72 result = gl_ext_loader( (std::string(name) + "ARB").c_str() ); 73 test_name = name + "ARB"_ls; 74 result = gl_ext_loader( test_name.data() ); 73 75 if ( result ) return result; 74 result = gl_ext_loader( (std::string(name) + "EXT").c_str() ); 76 test_name = name + "EXT"_ls; 77 result = gl_ext_loader( test_name.data() ); 75 78 if ( result ) return result; 76 79 } … … 255 258 256 259 # define NV_GL_FUN_EXT( rtype, symbol, fparams ) \ 257 void_assign( symbol, load_gl_ext_symbol(#symbol, true, nullptr) ); \260 void_assign( symbol, load_gl_ext_symbol(#symbol, true, string_view()) ); \ 258 261 count++; if ( !symbol ) fail_count++; 259 262 -
trunk/src/lua/lua_function.cc
r433 r440 21 21 { 22 22 lua_pop( L, 1 ); 23 NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string() .c_str());23 NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string() ); 24 24 } 25 25 … … 27 27 { 28 28 lua_pop( L, 1 ); 29 NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string() .c_str());29 NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string() ); 30 30 } 31 31 m_ref = luaL_ref( L, LUA_REGISTRYINDEX ); … … 64 64 if ( status != 0 ) 65 65 { 66 st d::string error = lua_tostring( L, -1);66 string128 error( nlua_tostringview( L, -1 ) ); 67 67 lua_pop( L, 1 ); 68 NV_LUA_ABORT( "function_base::call", "call failed - ", error .c_str());68 NV_LUA_ABORT( "function_base::call", "call failed - ", error ); 69 69 } 70 70 } -
trunk/src/lua/lua_map_tile.cc
r433 r440 16 16 #include "nv/lua/lua_values.hh" 17 17 #include "nv/lua/lua_raw.hh" 18 19 // TODO: REMOVE 20 #include <string> 18 21 19 22 static const char* NLUA_MAP_TILE_METATABLE = "map_tile"; -
trunk/src/lua/lua_path.cc
r435 r440 74 74 } 75 75 76 st d::stringnv::lua::path::to_string() const76 string128 nv::lua::path::to_string() const 77 77 { 78 char buffer[64]; 79 char* start = buffer; 80 char* current = buffer; 78 string128 buffer; 81 79 bool dot = false; 82 bool oos = false;83 80 for ( const element& e : m_elements ) 84 81 { 85 if ( current - start > 48 ) { oos = true; break; } 86 if ( dot ) *current++ = '.'; 82 if ( dot ) buffer.append( "." ); 87 83 if ( e.length == 0 ) 88 84 { 89 *current++ = '['; 90 current += uint32_to_buffer( array_ref< char >( current, current - start ), e.value ); 91 *current++ = ']'; 85 buffer.append( "["_ls + e.value + "]"_ls ); 92 86 dot = false; 93 87 } 94 88 else 95 89 { 96 if ( size_t(current - start) + e.length > 60 ) { oos = true; break; } 97 nvmemcpy( current, e.str, e.length ); 98 current += e.length; 90 buffer.append( e.str, e.length ); 99 91 dot = true; 100 92 } 101 93 } 102 if (oos) 103 { 104 *current++ = '.'; 105 *current++ = '.'; 106 *current++ = '.'; 107 } 108 *current++ = '\0'; 109 return std::string( buffer, size_t(current - start - 1) ); 94 return buffer; 110 95 } -
trunk/src/lua/lua_state.cc
r437 r440 116 116 if ( !p.resolve( m_state, global ) ) 117 117 { 118 NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string() .c_str());118 NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string() ); 119 119 return false; 120 120 } … … 123 123 { 124 124 lua_pop( m_state, 1 ); 125 NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string() .c_str());125 NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string() ); 126 126 return false; 127 127 } … … 212 212 lua_pop( m_state, 1 ); 213 213 return shash64( result ); 214 }215 216 std::string lua::table_guard::get_std_string( string_view element, string_view defval /*= string_view() */ )217 {218 lua_getfield( m_state, -1, element.data() );219 size_t l = 0;220 const char* str = nullptr;221 if ( lua_type( m_state, -1 ) == LUA_TSTRING )222 {223 str = lua_tolstring( m_state, -1, &l );224 }225 else226 {227 l = defval.size();228 str = defval.data();229 }230 std::string result( str, l );231 lua_pop( m_state, 1 );232 return result;233 214 } 234 215 … … 250 231 lua_pop( m_state, 1 ); 251 232 return result; 233 } 234 235 string128 lua::table_guard::get_string128( string_view element, string_view defval ) 236 { 237 lua_getfield( m_state, -1, element.data() ); 238 size_t l = 0; 239 const char* str = nullptr; 240 if ( lua_type( m_state, -1 ) == LUA_TSTRING ) 241 { 242 str = lua_tolstring( m_state, -1, &l ); 243 } 244 else 245 { 246 l = defval.size(); 247 str = defval.data(); 248 } 249 string128 result( str, l ); 250 lua_pop( m_state, 1 ); 251 return result; 252 252 } 253 253 -
trunk/src/lua/lua_values.cc
r399 r440 65 65 } 66 66 67 void nv::lua::detail::push_string ( lua_State *L, const std::string& s )68 {69 lua_pushlstring( L, s.c_str(), s.size() );70 }71 72 67 void nv::lua::detail::push_cstring ( lua_State *L, const char* s ) 73 68 { … … 109 104 { 110 105 return lua_toboolean( L, index ) != 0; 111 }112 113 std::string nv::lua::detail::to_string ( lua_State *L, int index )114 {115 size_t length = 0;116 const char* result = lua_tolstring( L, index, &length );117 return std::string( result, length );118 106 } 119 107 … … 171 159 } 172 160 173 std::string nv::lua::detail::to_string ( lua_State *L, int index, const std::string&def )161 nv::string_view nv::lua::detail::to_string_view( lua_State *L, int index, string_view def ) 174 162 { 175 return ( lua_type( L, index ) == LUA_TSTRING ? lua_tostring( L, index ) : def );163 return ( lua_type( L, index ) == LUA_TSTRING ? nlua_tostringview( L, index ) : def ); 176 164 } 177 165 -
trunk/src/sdl/sdl_window.cc
r406 r440 36 36 uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; 37 37 if (fullscreen) flags |= SDL_WINDOW_FULLSCREEN; 38 m_title = "Nova Engine";39 m_handle = SDL_CreateWindow( m_title. c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,38 m_title.assign( "Nova Engine" ); 39 m_handle = SDL_CreateWindow( m_title.data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 40 40 width, height, flags ); 41 41 if ( m_handle == 0 ) … … 77 77 } 78 78 79 void sdl::window::set_title( const st d::string& title )79 void sdl::window::set_title( const string_view& title ) 80 80 { 81 SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title. c_str() );82 m_title = title;81 SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.data() ); 82 m_title.assign( title ); 83 83 } 84 84 -
trunk/src/stl/assert.cc
r410 r440 10 10 extern "C" { 11 11 #if NV_COMPILER == NV_MSVC 12 _ACRTIMP NV_NORETURN void __cdecl exit( _In_int _Code );12 NV_NORETURN void __cdecl exit( int _Code ); 13 13 #else 14 14 void exit( int status_code ) NV_NORETURN;
Note: See TracChangeset
for help on using the changeset viewer.