Changeset 439
- Timestamp:
- 07/23/15 18:14:48 (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/engine/particle_engine.hh
r395 r439 165 165 void load( lua::table_guard& table ); 166 166 void draw( particle_system system, const render_state& rs, const scene_state& ss ); 167 particle_system create_system( const st d::string& id );167 particle_system create_system( const string_view& id ); 168 168 void release( particle_system system ); 169 169 void update( particle_system system, const scene_state& s, uint32 ms ); 170 170 void set_texcoords( particle_system system, vec2 a, vec2 b ); 171 void register_emmiter_type( const st d::string& name, particle_emmiter_func func );172 void register_affector_type( const st d::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 ); 173 173 ~particle_engine(); 174 174 private: … … 194 194 uint32 m_last_update; 195 195 196 handle_store< particle_system_info, particle_system > 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; 198 198 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; 201 201 }; 202 202 -
trunk/nv/gl/gl_device.hh
r438 r439 54 54 virtual const buffer_info* get_buffer_info( buffer t ) const; 55 55 56 virtual int get_attribute_location( program p, const st d::string& name, bool fatal = true ) const;56 virtual int get_attribute_location( program p, const string_view& name, bool fatal = true ) const; 57 57 virtual void prepare_program( program p ); 58 58 virtual string_view get_shader_header() const { return m_shader_header; } 59 59 virtual ~gl_device(); 60 60 protected: 61 uniform_base* get_uniform( program p, const st d::string& name, bool fatal = true ) const;61 uniform_base* get_uniform( program p, const string_view& name, bool fatal = true ) const; 62 62 63 63 private: -
trunk/nv/interface/device.hh
r438 r439 17 17 #include <nv/stl/string.hh> 18 18 #include <nv/stl/handle.hh> 19 #include <nv/stl/hash_store.hh> 19 20 #include <nv/interface/uniform.hh> 20 21 #include <nv/interface/mesh_data.hh> … … 68 69 struct attribute 69 70 { 70 std::string name;71 71 int location; 72 72 datatype type; … … 74 74 }; 75 75 76 typedef unordered_map< std::string, attribute > attribute_map;76 typedef hash_store< shash64, attribute > attribute_map; 77 77 78 78 struct texture_tag {}; … … 189 189 } 190 190 191 int try_get_attribute_location( program p, const st d::string& name ) const191 int try_get_attribute_location( program p, const string_view& name ) const 192 192 { 193 193 return get_attribute_location( p, name, false ); 194 194 } 195 195 196 virtual int get_attribute_location( program p, const st d::string& name, bool fatal = true ) const = 0;197 198 template < typename T > 199 void set_uniform_array( program p, const st d::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 ) 200 200 { 201 201 uniform_base* base = get_uniform( p, name, fatal ); … … 212 212 213 213 template < typename T > 214 void set_opt_uniform_array( program p, const st d::string& name, const T* value, uint32 count )214 void set_opt_uniform_array( program p, const string_view& name, const T* value, uint32 count ) 215 215 { 216 216 set_uniform_array( p, name, value, count, false ); … … 218 218 219 219 template < typename T > 220 void set_opt_uniform_array( program p, const st d::string& name, const array_view<T>& value )220 void set_opt_uniform_array( program p, const string_view& name, const array_view<T>& value ) 221 221 { 222 222 set_uniform_array( p, name, value.data(), value.size(), false ); … … 225 225 226 226 template < typename T > 227 void set_uniform( program p, const st d::string& name, const T& value, bool fatal = true )227 void set_uniform( program p, const string_view& name, const T& value, bool fatal = true ) 228 228 { 229 229 uniform_base* base = get_uniform( p, name, fatal ); … … 238 238 239 239 template < typename T > 240 void set_opt_uniform( program p, const st d::string& name, const T& value )240 void set_opt_uniform( program p, const string_view& name, const T& value ) 241 241 { 242 242 set_uniform( p, name, value, false ); … … 265 265 266 266 protected: 267 virtual uniform_base* get_uniform( program p, const st d::string& name, bool fatal = true ) const = 0;267 virtual uniform_base* get_uniform( program p, const string_view& name, bool fatal = true ) const = 0; 268 268 269 269 void initialize_engine_uniforms() -
trunk/nv/interface/uniform.hh
r406 r439 17 17 #include <nv/interface/camera.hh> 18 18 #include <nv/stl/string.hh> 19 #include <nv/stl/string_map.hh> 19 20 #include <nv/stl/unordered_map.hh> 20 21 … … 26 27 { 27 28 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 ) {} 30 31 bool try_type_check( datatype ) 31 32 { … … 44 45 bool is_dirty() const { return m_dirty; } 45 46 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 ); 47 48 virtual ~uniform_base() {} 48 49 protected: 49 std::string m_name;50 50 datatype m_type; 51 51 int m_location; … … 60 60 typedef T value_type; 61 61 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 ) 64 64 { 65 65 m_value = new T[ m_length ]; … … 149 149 }; 150 150 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 153 155 // TODO - change to literal type map 154 156 typedef nv::unordered_map< string_view, engine_uniform_factory_base* > engine_uniform_factory_map; … … 248 250 }; 249 251 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 ) 251 253 { 252 254 switch( utype ) 253 255 { 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 ); 265 267 default : return nullptr; 266 268 } -
trunk/src/engine/particle_engine.cc
r433 r439 302 302 void nv::particle_engine::load( lua::table_guard& table ) 303 303 { 304 s td::string id = table.get_std_string( "id" );305 if ( id == "")304 shash64 id = table.get_string_hash_64( "id" ); 305 if ( !id.valid() ) 306 306 { 307 307 NV_LOG_ERROR( "Bad table passed to particle_engine!" ) … … 355 355 { 356 356 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" ); 359 359 if ( type == "emmiter" ) 360 360 { … … 370 370 { 371 371 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, ")" ); 373 373 } 374 374 … … 435 435 { 436 436 data.affector_count--; 437 NV_LOG_WARNING( "Bad data passed to ", s tring_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!" ); 438 438 } 439 439 } … … 441 441 { 442 442 data.affector_count--; 443 NV_LOG_WARNING( "Unknown affector type in particle system! (", s tring_view( sub_type.c_str(), sub_type.size() ), ")" );443 NV_LOG_WARNING( "Unknown affector type in particle system! (", sub_type, ")" ); 444 444 } 445 445 } … … 469 469 } 470 470 471 nv::particle_system nv::particle_engine::create_system( const st d::string& id )471 nv::particle_system nv::particle_engine::create_system( const string_view& id ) 472 472 { 473 473 auto it = m_names.find( id ); … … 823 823 } 824 824 825 void nv::particle_engine::register_emmiter_type( const st d::string& name, particle_emmiter_func func )825 void nv::particle_engine::register_emmiter_type( const string_view& name, particle_emmiter_func func ) 826 826 { 827 827 m_emmiters[ name ] = func; … … 842 842 } 843 843 844 void nv::particle_engine::register_affector_type( const st d::string& name, particle_affector_init_func init, particle_affector_func process )844 void nv::particle_engine::register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process ) 845 845 { 846 846 m_affectors[ name ].init = init; -
trunk/src/gl/gl_device.cc
r438 r439 212 212 for ( auto& i : *info->m_uniform_map ) 213 213 { 214 auto j = lmap.find( i.first .c_str());214 auto j = lmap.find( i.first ); 215 215 if ( j != lmap.end() ) 216 216 { … … 218 218 } 219 219 220 auto k = map.find( i.first .c_str());220 auto k = map.find( i.first ); 221 221 if ( k != map.end() ) 222 222 { … … 227 227 } 228 228 229 uniform_base* nv::gl_device::get_uniform( program p, const st d::string& name, bool fatal /*= true */ ) const229 uniform_base* nv::gl_device::get_uniform( program p, const string_view& name, bool fatal /*= true */ ) const 230 230 { 231 231 const gl_program_info* info = m_programs.get( p ); … … 238 238 if ( fatal ) 239 239 { 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!" ); 241 241 NV_ABORT( "gl_device : uniform not found!" ); 242 242 } … … 245 245 } 246 246 247 int nv::gl_device::get_attribute_location( program p, const st d::string& name, bool fatal /*= true */ ) const247 int nv::gl_device::get_attribute_location( program p, const string_view& name, bool fatal /*= true */ ) const 248 248 { 249 249 const gl_program_info* info = m_programs.get( p ); … … 257 257 if ( fatal ) 258 258 { 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!" ); 260 260 NV_ABORT( "gl_device : attribute not found!" ); 261 261 } … … 357 357 glGetActiveAttrib( p->glid, i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer ); 358 358 359 st d::stringname( name_buffer, size_t( attr_nlen ) );359 string_view name( name_buffer, size_t( attr_nlen ) ); 360 360 361 361 // skip built-ins 362 362 if ( name.substr(0,3) == "gl_" ) continue; 363 363 364 int attr_loc = glGetAttribLocation( p->glid, name. c_str() );364 int attr_loc = glGetAttribLocation( p->glid, name.data() ); 365 365 366 366 attribute& attr = (*p->m_attribute_map)[ name ]; 367 attr.name = name;368 367 attr.location = attr_loc; 369 368 attr.type = gl_enum_to_datatype( attr_type ); … … 386 385 glGetActiveUniform( p->glid, i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer ); 387 386 388 st d::stringname( name_buffer, size_t( uni_nlen ) );387 string_view name( name_buffer, size_t( uni_nlen ) ); 389 388 390 389 // skip built-ins 391 390 if ( name.substr(0,3) == "gl_" ) continue; 392 391 393 int uni_loc = glGetUniformLocation( p->glid, name. c_str() );392 int uni_loc = glGetUniformLocation( p->glid, name.data() ); 394 393 datatype utype = gl_enum_to_datatype( uni_type ); 395 394 396 395 // check for array 397 s td::string::size_typearrchar = name.find( '[' );398 if ( arrchar != st d::string::npos )396 size_t arrchar = name.find( '[' ); 397 if ( arrchar != string_view::npos ) 399 398 { 400 399 name = name.substr( 0, arrchar ); 401 400 } 402 401 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 ); 404 403 NV_ASSERT( u, "Unknown uniform type!" ); 405 404 (*p->m_uniform_map)[ name ] = u;
Note: See TracChangeset
for help on using the changeset viewer.