Changeset 438
- Timestamp:
- 07/23/15 17:29:49 (10 years ago)
- Location:
- trunk
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/random.hh
r397 r438 18 18 { 19 19 public: 20 typedef unsigned int result_type; // std::mt19937::result_type20 typedef unsigned int result_type; // mt19937::result_type 21 21 typedef unsigned int seed_type; 22 22 … … 174 174 } 175 175 private: 176 // temporary solution until we get rid of std::random176 // temporary solution until we get rid of ::random 177 177 char m_data[16 * 1024]; 178 178 }; -
trunk/nv/core/time.hh
r395 r438 34 34 35 35 /** 36 * Get millisecond count based on std::clock36 * Get millisecond count based on ::clock 37 37 */ 38 38 uint32 get_cpu_ms(); 39 39 40 40 /** 41 * Get microsecond count based on std::clock41 * Get microsecond count based on ::clock 42 42 */ 43 43 uint64 get_cpu_us(); -
trunk/nv/core/types.hh
r431 r438 33 33 }; 34 34 35 template<>36 struct is_container < std::string>37 {38 static const bool value = false;39 };35 // template<> 36 // struct is_container < string_view > 37 // { 38 // static const bool value = false; 39 // }; 40 40 41 41 struct type_entry; -
trunk/nv/engine/program_manager.hh
r399 r438 28 28 protected: 29 29 virtual resource_id load_resource( lua::table_guard& table ); 30 void load_source( lua::table_guard& table, std::string& out, const std::string& append );30 string_buffer load_source( lua::table_guard& table, const string_view& append ); 31 31 virtual void release( program p ); 32 32 private: 33 33 context* m_context; 34 std::string m_vertex_head; 35 std::string m_fragment_head; 34 const_string m_shader_head; 36 35 }; 37 36 -
trunk/nv/gfx/texture_font.hh
r399 r438 43 43 { 44 44 public: 45 texture_font( texture_atlas* atlas, const char *filename, float size );45 texture_font( texture_atlas* atlas, const string_view& filename, float size ); 46 46 const texture_glyph* get_glyph( uint16 charcode ) const; 47 47 bool load_glyphs( string_view codes ); … … 54 54 55 55 texture_atlas* m_atlas; //!< Atlas Image object for this font. 56 st d::string m_filename; //!< Name of the file.56 string128 m_filename;//!< Filename 57 57 float m_size; //!< Font size. 58 58 float m_height; //!< Height of the font. (x-height?) -
trunk/nv/gl/gl_device.hh
r406 r438 56 56 virtual int get_attribute_location( program p, const std::string& name, bool fatal = true ) const; 57 57 virtual void prepare_program( program p ); 58 virtual const std::string&get_shader_header() const { return m_shader_header; }58 virtual string_view get_shader_header() const { return m_shader_header; } 59 59 virtual ~gl_device(); 60 60 protected: 61 61 uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const; 62 62 63 64 63 private: 65 64 bool compile( gl_program_info* p, string_view vertex_program, string_view fragment_program ); … … 68 67 void load_attributes( gl_program_info* p ); 69 68 void load_uniforms( gl_program_info* p ); 70 st d::stringm_shader_header;69 string_buffer m_shader_header; 71 70 handle_store< gl_texture_info, texture > m_textures; 72 71 handle_store< gl_buffer_info, buffer > m_buffers; -
trunk/nv/gl/gl_enum.hh
r395 r438 45 45 unsigned int datatype_to_gl_enum( datatype type ); 46 46 datatype gl_enum_to_datatype( unsigned int gl_enum ); 47 st d::stringdatatype_to_glsl_type( datatype type );47 string_view datatype_to_glsl_type( datatype type ); 48 48 49 49 } // namespace nv -
trunk/nv/interface/device.hh
r412 r438 182 182 virtual const texture_info* get_texture_info( texture ) const = 0; 183 183 virtual const buffer_info* get_buffer_info( buffer ) const = 0; 184 virtual const std::string&get_shader_header() const = 0;184 virtual string_view get_shader_header() const = 0; 185 185 186 186 virtual texture create_texture( image_data* data, sampler asampler ) -
trunk/nv/io/c_file_system.hh
r422 r438 25 25 c_file_system(); 26 26 virtual ~c_file_system(); 27 virtual bool exists( const char* fpath ); 28 virtual stream* open( const char* fpath, const char* fmode = "rb" ); 27 virtual const_string slurp( const string_view& path ); 28 virtual bool exists( const string_view& ); 29 virtual stream* open( const string_view&, const string_view& = "rb" ); 29 30 }; 30 31 -
trunk/nv/io/c_stream.hh
r422 r438 26 26 protected: 27 27 c_stream(); 28 // TODO: const char* is prone to deletion - don't store it, or store differently! 28 29 c_stream( void* pfile, const char* filename ); 29 30 public: -
trunk/nv/lua/lua_values.hh
r406 r438 167 167 168 168 template <> 169 struct pass_traits < const_string > 170 { 171 static void push( lua_State *L, const const_string& s ) { detail::push_string_view( L, s ); } 172 static const_string to( lua_State *L, int index ) { return const_string( detail::to_string_view( L, index ) ); } 173 static const_string to( lua_State *L, int index, const_string def ) { return const_string( detail::to_string_view( L, index, def ) ); } 174 }; 175 176 template <> 169 177 struct pass_traits<ref> 170 178 { -
trunk/nv/stl/container/contiguous_storage.hh
r435 r438 83 83 reallocate( 0, false ); 84 84 m_data = other.m_data; 85 other.m_data = nullptr; 85 86 } 86 87 return *this; -
trunk/nv/stl/container/growing_storage.hh
r437 r438 112 112 inline growing_storage& operator=( growing_storage&& other ) 113 113 { 114 Storage::reallocate( 0, false ); 115 m_size = other.m_size; 116 Storage::operator=( nv::move( other ) ); 117 other.m_size = size_impl_type(); 114 if ( this != &other ) 115 { 116 m_size = other.m_size; 117 Storage::operator=( nv::move( other ) ); 118 other.m_size = size_impl_type(); 119 } 118 120 return *this; 119 121 } … … 179 181 void insert( iterator position, const value_type& value ) 180 182 { 181 iterator iend = Storage::data() + m_size;183 ptrdiff_t offset = position - Storage::data(); 182 184 if ( try_grow( 1 ) ) 183 185 { 184 raw_alias_copy( position, iend, position + 1 ); 185 copy_construct_object( position, value ); 186 iterator iposition = Storage::data() + offset; 187 iterator iend = Storage::data() + m_size - 1; 188 raw_alias_copy( iposition, iend, iposition + 1 ); 189 copy_construct_object( iposition, value ); 186 190 } 187 191 } … … 192 196 // TODO: distance can't be called on destructive iterators - check 193 197 // and use pushback if needed? 194 iterator iend = Storage::data() + m_size;198 ptrdiff_t offset = position - Storage::data(); 195 199 size_type d = distance( first, last ); 196 200 if ( try_grow( d ) ) 197 201 { 198 raw_alias_copy( position, iend, position + d ); 199 InitializePolicy::copy( first, last, position ); 202 iterator iposition = Storage::data() + offset; 203 iterator iend = Storage::data() + m_size - d; 204 raw_alias_copy( iposition, iend, iposition + d ); 205 InitializePolicy::copy( first, last, iposition ); 200 206 } 201 207 } -
trunk/nv/stl/file_system.hh
r422 r438 14 14 15 15 #include <nv/common.hh> 16 #include <nv/stl/string.hh> 16 17 #include <nv/stl/stream.hh> 17 18 … … 25 26 public: 26 27 virtual ~file_system() {} 27 virtual bool exists( const char* fpath ) = 0; 28 virtual stream* open( const char* fpath, const char* fmode = "rb" ) = 0; 28 virtual const_string slurp( const string_view& path ) = 0; 29 virtual bool exists( const string_view& path ) = 0; 30 virtual stream* open( const string_view& path, const string_view& mode = "rb" ) = 0; 31 29 32 }; 30 33 -
trunk/nv/stl/string.hh
r435 r438 29 29 #include <nv/stl/string/short_string.hh> 30 30 #include <string> 31 #include <sstream>32 31 #include <nv/stl/type_traits/primary.hh> 33 32 #include <nv/stl/memory.hh> … … 47 46 inline H operator()( const std::string& value ) const { return get( value ); } 48 47 }; 49 50 51 /**52 * Simple function for slurping a file into a string.53 */54 std::string slurp( const std::string& filename );55 48 56 49 namespace detail -
trunk/nv/stl/string/const_string.hh
r433 r438 41 41 initialize( s, N - 1 ); 42 42 } 43 // TODO : implement 44 // inline string_buffer_base( const string_twine& twine ); 45 43 46 ~const_string() 44 47 { … … 74 77 { 75 78 char* new_data = new char[s + 1]; 76 nvmemcpy( new_data, p, s );79 if (p) nvmemcpy( new_data, p, s ); 77 80 new_data[s] = 0; 78 81 assign( new_data, s ); -
trunk/nv/stl/string/short_string.hh
r435 r438 10 10 #include <nv/stl/string/common.hh> 11 11 #include <nv/stl/string/string_base.hh> 12 #include <nv/stl/string/string_twine.hh> 12 13 #include <nv/stl/container/random_access.hh> 13 14 #include <nv/stl/container/contiguous_storage.hh> … … 32 33 } 33 34 35 36 template < typename Base > 37 inline explicit string_buffer_base( const string_base< Base >& s ) : this_type( s.data(), s.size() ) {} 34 38 inline explicit string_buffer_base( const string_view& s ) : this_type( s.data(), s.size() ) {} 35 template < typename S > 36 inline string_buffer_base( const string_base<S>& rhs ) : this_type( rhs.data(), rhs.size() ) {} 39 40 inline string_buffer_base( const string_twine& twine ) 41 { 42 append( twine ); 43 } 37 44 inline string_buffer_base( string_buffer_base&& copy ) = default; 38 45 inline string_buffer_base& operator=( string_buffer_base&& other ) = default; 39 inline string_buffer_base& operator=( const string_view& other )40 {41 clear();42 append( other );43 }44 46 45 47 size_t append( const char* data, size_t sz ) … … 49 51 raw_copy_n( data, amount, this->begin() + pos ); 50 52 return amount; 53 } 54 55 size_t append( const string_twine& twine ) 56 { 57 size_t pos = size(); 58 size_t dump_size = twine.dump_size(); 59 expand_by( dump_size ); 60 twine.dump( array_ref< char >( data() + pos, size() - pos ) ); 61 return size() - pos; 51 62 } 52 63 … … 111 122 void reserve( size_type new_capacity ) 112 123 { 113 Storage::reserve( new_capacity + 1 , true);124 Storage::reserve( new_capacity + 1 ); 114 125 this->data()[this->size()] = 0; 115 126 } … … 117 128 void resize( size_type new_size ) 118 129 { 119 Storage::reserve( new_size + 1 , true);130 Storage::reserve( new_size + 1 ); 120 131 Storage::resize( min( new_size, capacity() - 1 ) ); 121 132 this->data()[this->size()] = 0; -
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.