Changeset 361


Ignore:
Timestamp:
05/15/15 12:01:41 (10 years ago)
Author:
epyon
Message:
  • more string_ref changes
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gl/gl_device.hh

    r350 r361  
    4040
    4141                gl_device();
    42                 virtual image_data* create_image_data( const std::string& filename ); // temporary
     42                virtual image_data* create_image_data( string_ref filename ); // temporary
    4343                virtual image_data* create_image_data( const uint8* data, uint32 size ); // temporary
    4444
    45                 virtual program create_program( const string& vs_source, const string& fs_source );
     45                virtual program create_program( string_ref vs_source, string_ref fs_source );
    4646                virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr );
    4747                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, void* data = nullptr );
     
    6262       
    6363        private:
    64                 bool compile( gl_program_info* p, const string& vertex_program, const string& fragment_program );
     64                bool compile( gl_program_info* p, string_ref vertex_program, string_ref fragment_program );
     65                bool compile( uint32 sh_type, string_ref shader_code, unsigned& glid );
    6566                void update_uniforms( gl_program_info* p );
    6667                void load_attributes( gl_program_info* p );
    6768                void load_uniforms( gl_program_info* p );
    68                 bool compile( uint32 sh_type, const std::string& shader_code, unsigned& glid );
    6969                std::string m_shader_header;
    7070                handle_store< gl_texture_info, texture >         m_textures;
  • trunk/nv/interface/device.hh

    r350 r361  
    156156                        initialize_engine_uniforms();
    157157                }
    158                 virtual program create_program( const string& vs_source, const string& fs_source ) = 0;
     158                virtual program create_program( string_ref vs_source, string_ref fs_source ) = 0;
    159159                virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr ) = 0;
    160160                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0;
    161161                // TODO: remove?
    162162                virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) { return create_texture( TEXTURE_2D, size, aformat, asampler, data ); }
    163                 virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary
     163                virtual image_data* create_image_data( string_ref filename ) = 0; // temporary
    164164                virtual image_data* create_image_data( const uint8* data, uint32 size ) = 0; // temporary
    165165                virtual void release( texture ) = 0;
  • trunk/nv/lua/lua_state.hh

    r360 r361  
    296296                        size_t get_size();
    297297                        bool has_field( string_ref element );
    298                         std::string get_string( string_ref element, string_ref defval = string_ref() );
     298                        std::string get_std_string( string_ref element, string_ref defval = string_ref() );
     299                        const_string get_string( string_ref element, string_ref defval = string_ref() );
    299300                        char get_char( string_ref element, char defval = ' ' );
    300301                        int get_integer( string_ref element, int defval = 0 );
  • trunk/src/engine/particle_engine.cc

    r353 r361  
    300300void nv::particle_engine::load( lua::table_guard& table )
    301301{
    302         std::string id = table.get_string( "id" );
     302        std::string id = table.get_std_string( "id" );
    303303        if ( id == "" )
    304304        {
     
    317317        data.affector_count  = 0;
    318318
    319         std::string orientation = table.get_string( "orientation", "point" );
     319        const_string orientation = table.get_string( "orientation", "point" );
    320320        if ( orientation == "point" )                     { data.orientation = particle_orientation::POINT; }
    321321        else if ( orientation == "oriented" )             { data.orientation = particle_orientation::ORIENTED; }
     
    329329        }
    330330
    331         std::string origin = table.get_string( "origin", "center" );
     331        const_string origin = table.get_string( "origin", "center" );
    332332        if      ( origin == "center" )        { data.origin = particle_origin::CENTER; }
    333333        else if ( origin == "top_left" )      { data.origin = particle_origin::TOP_LEFT; }
     
    353353        {
    354354                lua::table_guard element( table, i+1 );
    355                 std::string type     = element.get_string("type");
    356                 std::string sub_type = element.get_string("sub_type");
     355                const_string type     = element.get_string("type");
     356                std::string sub_type = element.get_std_string("sub_type");
    357357                if ( type == "emmiter" )
    358358                {
  • trunk/src/engine/program_manager.cc

    r323 r361  
    4949        if ( table.is_string( "files" ) )
    5050        {
    51                 out += nv::slurp( table.get_string( "files" ) );
     51                out += nv::slurp( table.get_std_string( "files" ) );
    5252        }
    5353        else if ( table.is_table( "files" ) )
     
    6565        if ( table.is_string( "file" ) )
    6666        {
    67                 out += "#line 1\n"+nv::slurp( table.get_string( "file" ) );
     67                out += "#line 1\n" + nv::slurp( table.get_std_string( "file" ) );
    6868        }
    6969
    7070        if ( table.is_string( "source" ) )
    7171        {
    72                 out += table.get_string( "source" );
     72                out += table.get_std_string( "source" );
    7373        }
    7474}
  • trunk/src/engine/resource_system.cc

    r358 r361  
    3535                lua::table_guard sub_table( table, i+1 );
    3636                resource_id rid = load_resource( sub_table );
    37                 if ( rid != 0 ) m_names[ sub_table.get_string("id") ] = rid;
     37                if ( rid != 0 ) m_names[ sub_table.get_std_string("id") ] = rid;
    3838        }
    3939}
  • trunk/src/gl/gl_device.cc

    r350 r361  
    2222}
    2323
    24 program gl_device::create_program( const string& vs_source, const string& fs_source )
     24program gl_device::create_program( string_ref vs_source, string_ref fs_source )
    2525{
    2626        program result = m_programs.create();
     
    3535// this is a temporary function that will be removed once we find a way to
    3636// pass binary file data around
    37 image_data* gl_device::create_image_data( const std::string& filename )
     37image_data* gl_device::create_image_data( string_ref filename )
    3838{
    3939        load_sdl_image_library();
    40         SDL_Surface* image = IMG_Load( filename.c_str() );
     40        SDL_Surface* image = IMG_Load( filename.data() );
    4141        if (!image)
    4242        {
    43                 NV_LOG( LOG_ERROR, "Image file " << filename.c_str() << " not found!" );
     43                NV_LOG( LOG_ERROR, "Image file " << filename << " not found!" );
    4444                return nullptr;
    4545        }
     
    254254}
    255255
    256 bool nv::gl_device::compile( gl_program_info* p, const string& vertex_program, const string& fragment_program )
     256bool nv::gl_device::compile( gl_program_info* p, string_ref vertex_program, string_ref fragment_program )
    257257{
    258258        if (!compile( GL_VERTEX_SHADER,   vertex_program, p->glidv ))   { return false; }
     
    397397}
    398398
    399 bool nv::gl_device::compile( uint32 sh_type, const std::string& shader_code, unsigned& glid )
     399bool nv::gl_device::compile( uint32 sh_type, string_ref shader_code, unsigned& glid )
    400400{
    401401        glid = glCreateShader( sh_type );
    402402
    403         const char* pc = shader_code.c_str();
    404 
    405         glShaderSource( glid,   1, &pc, 0 );
     403        const char* pc = shader_code.data();
     404        int l = shader_code.length();
     405
     406        glShaderSource( glid, 1, &pc, &l );
    406407        glCompileShader( glid );
    407408
  • trunk/src/lua/lua_state.cc

    r360 r361  
    179179}
    180180
    181 string lua::table_guard::get_string( string_ref element, string_ref defval /*= string_ref() */ )
    182 {
    183         lua_getfield( m_state, -1, element.data() );
    184         string result( ( lua_type( m_state, -1 ) == LUA_TSTRING ) ? lua_tostring( m_state, -1 ) : defval.to_string() );
    185         lua_pop( m_state, 1 );
    186         return result;
     181string lua::table_guard::get_std_string( string_ref element, string_ref defval /*= string_ref() */ )
     182{
     183        lua_getfield( m_state, -1, element.data() );
     184        size_t l = 0;
     185        const char* str = nullptr;
     186        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     187        {
     188                str = lua_tolstring( m_state, -1, &l );
     189        }
     190        else
     191        {
     192                l = defval.size();
     193                str = defval.data();
     194        }
     195        std::string result( str, l );
     196        lua_pop( m_state, 1 );
     197        return result;
     198}
     199
     200const_string lua::table_guard::get_string( string_ref element, string_ref defval /*= string_ref() */ )
     201{
     202        lua_getfield( m_state, -1, element.data() );
     203        size_t l = 0;
     204        const char* str = nullptr;
     205        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     206        {
     207                str = lua_tolstring( m_state, -1, &l );
     208        }
     209        else
     210        {
     211                l = defval.size();
     212                str = defval.data();
     213        }
     214        const_string result( str, l );
     215        lua_pop( m_state, 1 );
     216        return result;
    187217}
    188218
Note: See TracChangeset for help on using the changeset viewer.