Changeset 439


Ignore:
Timestamp:
07/23/15 18:14:48 (10 years ago)
Author:
epyon
Message:
  • more std::string removal
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/engine/particle_engine.hh

    r395 r439  
    165165                void load( lua::table_guard& table );
    166166                void draw( particle_system system, const render_state& rs, const scene_state& ss );
    167                 particle_system create_system( const std::string& id );
     167                particle_system create_system( const string_view& id );
    168168                void release( particle_system system );
    169169                void update( particle_system system, const scene_state& s, uint32 ms );
    170170                void set_texcoords( particle_system system, vec2 a, vec2 b );
    171                 void register_emmiter_type( const std::string& name, particle_emmiter_func func );
    172                 void register_affector_type( const std::string& name, particle_affector_init_func init, particle_affector_func process );
     171                void register_emmiter_type( const string_view& name, particle_emmiter_func func );
     172                void register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process );
    173173                ~particle_engine();
    174174        private:
     
    194194                uint32   m_last_update;
    195195
    196                 handle_store< particle_system_info, particle_system >      m_systems;
    197                 unordered_map< std::string, uint32 >                  m_names;
     196                handle_store< particle_system_info, particle_system > m_systems;
     197                hash_store< shash64, uint32 >                         m_names;
    198198                vector< particle_system_data >                        m_data;
    199                 unordered_map< std::string, particle_emmiter_func >   m_emmiters;
    200                 unordered_map< std::string, particle_affector_funcs > m_affectors;
     199                hash_store< shash64, particle_emmiter_func >          m_emmiters;
     200                hash_store< shash64, particle_affector_funcs >        m_affectors;
    201201        };
    202202
  • trunk/nv/gl/gl_device.hh

    r438 r439  
    5454                virtual const buffer_info* get_buffer_info( buffer t ) const;
    5555
    56                 virtual int get_attribute_location( program p, const std::string& name, bool fatal = true ) const;
     56                virtual int get_attribute_location( program p, const string_view& name, bool fatal = true ) const;
    5757                virtual void prepare_program( program p );
    5858                virtual string_view get_shader_header() const { return m_shader_header; }
    5959                virtual ~gl_device();
    6060        protected:
    61                 uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const;
     61                uniform_base* get_uniform( program p, const string_view& name, bool fatal = true ) const;
    6262
    6363        private:
  • trunk/nv/interface/device.hh

    r438 r439  
    1717#include <nv/stl/string.hh>
    1818#include <nv/stl/handle.hh>
     19#include <nv/stl/hash_store.hh>
    1920#include <nv/interface/uniform.hh>
    2021#include <nv/interface/mesh_data.hh>
     
    6869        struct attribute
    6970        {
    70                 std::string   name;
    7171                int      location;
    7272                datatype type;
     
    7474        };
    7575
    76         typedef unordered_map< std::string, attribute >    attribute_map;
     76        typedef hash_store< shash64, attribute >    attribute_map;
    7777
    7878        struct texture_tag {};
     
    189189                }
    190190
    191                 int try_get_attribute_location( program p, const std::string& name ) const
     191                int try_get_attribute_location( program p, const string_view& name ) const
    192192                {
    193193                        return get_attribute_location( p, name, false );
    194194                }
    195195
    196                 virtual int get_attribute_location( program p, const std::string& name, bool fatal = true ) const = 0;
    197 
    198                 template < typename T >
    199                 void set_uniform_array( program p, const std::string& name, const T* value, uint32 count, bool fatal = true )
     196                virtual int get_attribute_location( program p, const string_view& name, bool fatal = true ) const = 0;
     197
     198                template < typename T >
     199                void set_uniform_array( program p, const string_view& name, const T* value, uint32 count, bool fatal = true )
    200200                {
    201201                        uniform_base* base = get_uniform( p, name, fatal );
     
    212212
    213213                template < typename T >
    214                 void set_opt_uniform_array( program p, const std::string& name, const T* value, uint32 count )
     214                void set_opt_uniform_array( program p, const string_view& name, const T* value, uint32 count )
    215215                {
    216216                        set_uniform_array( p, name, value, count, false );
     
    218218
    219219                template < typename T >
    220                 void set_opt_uniform_array( program p, const std::string& name, const array_view<T>& value )
     220                void set_opt_uniform_array( program p, const string_view& name, const array_view<T>& value )
    221221                {
    222222                        set_uniform_array( p, name, value.data(), value.size(), false );
     
    225225
    226226                template < typename T >
    227                 void set_uniform( program p, const std::string& name, const T& value, bool fatal = true )
     227                void set_uniform( program p, const string_view& name, const T& value, bool fatal = true )
    228228                {
    229229                        uniform_base* base = get_uniform( p, name, fatal );
     
    238238
    239239                template < typename T >
    240                 void set_opt_uniform( program p, const std::string& name, const T& value )
     240                void set_opt_uniform( program p, const string_view& name, const T& value )
    241241                {
    242242                        set_uniform( p, name, value, false );
     
    265265
    266266        protected:
    267                 virtual uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const = 0;
     267                virtual uniform_base* get_uniform( program p, const string_view& name, bool fatal = true ) const = 0;
    268268
    269269                void initialize_engine_uniforms()
  • trunk/nv/interface/uniform.hh

    r406 r439  
    1717#include <nv/interface/camera.hh>
    1818#include <nv/stl/string.hh>
     19#include <nv/stl/string_map.hh>
    1920#include <nv/stl/unordered_map.hh>
    2021
     
    2627        {
    2728        public:
    28                 uniform_base( const std::string& name, datatype type, int location, int length )
    29                         : m_name( name ), m_type( type ), m_location(location), m_length( length ), m_dirty( true ) {}
     29                uniform_base( datatype type, int location, int length )
     30                        : m_type( type ), m_location(location), m_length( length ), m_dirty( true ) {}
    3031                bool try_type_check( datatype )
    3132                {
     
    4445                bool is_dirty() const { return m_dirty; }
    4546                void clean() { m_dirty = false; }
    46                 static uniform_base* create( datatype utype, const std::string& name, int location, int length );
     47                static uniform_base* create( datatype utype, int location, int length );
    4748                virtual ~uniform_base() {}
    4849        protected:
    49                 std::string   m_name;
    5050                datatype m_type;
    5151                int      m_location;
     
    6060                typedef T value_type;
    6161
    62                 uniform( const std::string& name, int location, int length )
    63                         : uniform_base( name, type_to_enum< T >::type, location, length ), m_value( nullptr )
     62                uniform( int location, int length )
     63                        : uniform_base( type_to_enum< T >::type, location, length ), m_value( nullptr )
    6464                {
    6565                        m_value = new T[ m_length ];
     
    149149        };
    150150
    151         typedef nv::unordered_map< std::string, uniform_base* >                uniform_map;
    152         typedef nv::vector< engine_uniform_base* >                        engine_uniform_list;
     151        // TODO - nv::hash_store< shash64, uniform_base* >
     152        typedef nv::string_map< uniform_base* >                uniform_map;
     153        typedef nv::vector< engine_uniform_base* >             engine_uniform_list;
     154
    153155        // TODO - change to literal type map
    154156        typedef nv::unordered_map< string_view, engine_uniform_factory_base* > engine_uniform_factory_map;
     
    248250        };
    249251
    250         inline uniform_base* uniform_base::create( datatype utype, const std::string& name, int location, int length )
     252        inline uniform_base* uniform_base::create( datatype utype, int location, int length )
    251253        {
    252254                switch( utype )
    253255                {
    254                 case FLOAT          : return new uniform< enum_to_type< FLOAT          >::type >( name, location, length );
    255                 case INT            : return new uniform< enum_to_type< INT            >::type >( name, location, length );
    256                 case FLOAT_VECTOR_2 : return new uniform< enum_to_type< FLOAT_VECTOR_2 >::type >( name, location, length );
    257                 case FLOAT_VECTOR_3 : return new uniform< enum_to_type< FLOAT_VECTOR_3 >::type >( name, location, length );
    258                 case FLOAT_VECTOR_4 : return new uniform< enum_to_type< FLOAT_VECTOR_4 >::type >( name, location, length );
    259                 case INT_VECTOR_2   : return new uniform< enum_to_type< INT_VECTOR_2   >::type >( name, location, length );
    260                 case INT_VECTOR_3   : return new uniform< enum_to_type< INT_VECTOR_3   >::type >( name, location, length );
    261                 case INT_VECTOR_4   : return new uniform< enum_to_type< INT_VECTOR_4   >::type >( name, location, length );
    262                 case FLOAT_MATRIX_2 : return new uniform< enum_to_type< FLOAT_MATRIX_2 >::type >( name, location, length );
    263                 case FLOAT_MATRIX_3 : return new uniform< enum_to_type< FLOAT_MATRIX_3 >::type >( name, location, length );
    264                 case FLOAT_MATRIX_4 : return new uniform< enum_to_type< FLOAT_MATRIX_4 >::type >( name, location, length );
     256                case FLOAT          : return new uniform< enum_to_type< FLOAT          >::type >( location, length );
     257                case INT            : return new uniform< enum_to_type< INT            >::type >( location, length );
     258                case FLOAT_VECTOR_2 : return new uniform< enum_to_type< FLOAT_VECTOR_2 >::type >( location, length );
     259                case FLOAT_VECTOR_3 : return new uniform< enum_to_type< FLOAT_VECTOR_3 >::type >( location, length );
     260                case FLOAT_VECTOR_4 : return new uniform< enum_to_type< FLOAT_VECTOR_4 >::type >( location, length );
     261                case INT_VECTOR_2   : return new uniform< enum_to_type< INT_VECTOR_2   >::type >( location, length );
     262                case INT_VECTOR_3   : return new uniform< enum_to_type< INT_VECTOR_3   >::type >( location, length );
     263                case INT_VECTOR_4   : return new uniform< enum_to_type< INT_VECTOR_4   >::type >( location, length );
     264                case FLOAT_MATRIX_2 : return new uniform< enum_to_type< FLOAT_MATRIX_2 >::type >( location, length );
     265                case FLOAT_MATRIX_3 : return new uniform< enum_to_type< FLOAT_MATRIX_3 >::type >( location, length );
     266                case FLOAT_MATRIX_4 : return new uniform< enum_to_type< FLOAT_MATRIX_4 >::type >( location, length );
    265267                default     : return nullptr;
    266268                }
  • trunk/src/engine/particle_engine.cc

    r433 r439  
    302302void nv::particle_engine::load( lua::table_guard& table )
    303303{
    304         std::string id = table.get_std_string( "id" );
    305         if ( id == "" )
     304        shash64 id = table.get_string_hash_64( "id" );
     305        if ( !id.valid() )
    306306        {
    307307                NV_LOG_ERROR( "Bad table passed to particle_engine!" )
     
    355355        {
    356356                lua::table_guard element( table, i+1 );
    357                 const_string type     = element.get_string("type");
    358                 std::string sub_type = element.get_std_string("sub_type");
     357                const_string type     = element.get_string( "type" );
     358                const_string sub_type = element.get_string( "sub_type" );
    359359                if ( type == "emmiter" )
    360360                {
     
    370370                                {
    371371                                        edata.emmiter_func = nv_particle_emmiter_point;
    372                                         NV_LOG_WARNING( "Unknown emmiter type in particle system! (", sub_type.c_str(), ")" );
     372                                        NV_LOG_WARNING( "Unknown emmiter type in particle system! (", sub_type, ")" );
    373373                                }
    374374
     
    435435                                        {
    436436                                                data.affector_count--;
    437                                                 NV_LOG_WARNING( "Bad data passed to ", string_view( sub_type.c_str(), sub_type.size() ), " affector in particle system!" );
     437                                                NV_LOG_WARNING( "Bad data passed to ", sub_type, " affector in particle system!" );
    438438                                        }
    439439                                }
     
    441441                                {
    442442                                        data.affector_count--;
    443                                         NV_LOG_WARNING( "Unknown affector type in particle system! (", string_view( sub_type.c_str(), sub_type.size() ), ")" );
     443                                        NV_LOG_WARNING( "Unknown affector type in particle system! (", sub_type, ")" );
    444444                                }
    445445                        }
     
    469469}
    470470
    471 nv::particle_system nv::particle_engine::create_system( const std::string& id )
     471nv::particle_system nv::particle_engine::create_system( const string_view& id )
    472472{
    473473        auto it = m_names.find( id );
     
    823823}
    824824
    825 void nv::particle_engine::register_emmiter_type( const std::string& name, particle_emmiter_func func )
     825void nv::particle_engine::register_emmiter_type( const string_view& name, particle_emmiter_func func )
    826826{
    827827        m_emmiters[ name ] = func;
     
    842842}
    843843
    844 void nv::particle_engine::register_affector_type( const std::string& name, particle_affector_init_func init, particle_affector_func process )
     844void nv::particle_engine::register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process )
    845845{
    846846        m_affectors[ name ].init    = init;
  • trunk/src/gl/gl_device.cc

    r438 r439  
    212212                for ( auto& i : *info->m_uniform_map )
    213213                {
    214                         auto j = lmap.find( i.first.c_str() );
     214                        auto j = lmap.find( i.first );
    215215                        if ( j != lmap.end() )
    216216                        {
     
    218218                        }                       
    219219
    220                         auto k = map.find( i.first.c_str() );
     220                        auto k = map.find( i.first );
    221221                        if ( k != map.end() )
    222222                        {
     
    227227}
    228228
    229 uniform_base* nv::gl_device::get_uniform( program p, const std::string& name, bool fatal /*= true */ ) const
     229uniform_base* nv::gl_device::get_uniform( program p, const string_view& name, bool fatal /*= true */ ) const
    230230{
    231231        const gl_program_info* info = m_programs.get( p );
     
    238238                if ( fatal )
    239239                {
    240                         NV_LOG_CRITICAL( "gl_device : uniform '", string_view( name.c_str(), name.size() ), "' not found in program!" );
     240                        NV_LOG_CRITICAL( "gl_device : uniform '", name, "' not found in program!" );
    241241                        NV_ABORT( "gl_device : uniform not found!" );
    242242                }
     
    245245}
    246246
    247 int nv::gl_device::get_attribute_location( program p, const std::string& name, bool fatal /*= true */ ) const
     247int nv::gl_device::get_attribute_location( program p, const string_view& name, bool fatal /*= true */ ) const
    248248{
    249249        const gl_program_info* info = m_programs.get( p );
     
    257257                if ( fatal )
    258258                {
    259                         NV_LOG_CRITICAL( "gl_device : attribute '", string_view( name.c_str(), name.size() ), "' not found in program!" );
     259                        NV_LOG_CRITICAL( "gl_device : attribute '", name, "' not found in program!" );
    260260                        NV_ABORT( "gl_device : attribute not found!" );
    261261                }
     
    357357                glGetActiveAttrib( p->glid, i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer );
    358358
    359                 std::string name( name_buffer, size_t( attr_nlen ) );
     359                string_view name( name_buffer, size_t( attr_nlen ) );
    360360
    361361                // skip built-ins
    362362                if ( name.substr(0,3) == "gl_" ) continue;
    363363
    364                 int attr_loc = glGetAttribLocation( p->glid, name.c_str() );
     364                int attr_loc = glGetAttribLocation( p->glid, name.data() );
    365365
    366366                attribute& attr = (*p->m_attribute_map)[ name ];
    367                 attr.name     = name;
    368367                attr.location = attr_loc;
    369368                attr.type     = gl_enum_to_datatype( attr_type );
     
    386385                glGetActiveUniform( p->glid, i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer );
    387386
    388                 std::string name( name_buffer, size_t( uni_nlen ) );
     387                string_view name( name_buffer, size_t( uni_nlen ) );
    389388
    390389                // skip built-ins
    391390                if ( name.substr(0,3) == "gl_" ) continue;
    392391
    393                 int uni_loc = glGetUniformLocation( p->glid, name.c_str() );
     392                int uni_loc = glGetUniformLocation( p->glid, name.data() );
    394393                datatype utype = gl_enum_to_datatype( uni_type );
    395394
    396395                // check for array
    397                 std::string::size_type arrchar = name.find( '[' );
    398                 if ( arrchar != std::string::npos )
     396                size_t arrchar = name.find( '[' );
     397                if ( arrchar != string_view::npos )
    399398                {
    400399                        name = name.substr( 0, arrchar );
    401400                }
    402401
    403                 uniform_base* u = uniform_base::create( utype, name, uni_loc, uni_len );
     402                uniform_base* u = uniform_base::create( utype, uni_loc, uni_len );
    404403                NV_ASSERT( u, "Unknown uniform type!" );
    405404                (*p->m_uniform_map)[ name ] = u;
Note: See TracChangeset for help on using the changeset viewer.