Changeset 431
- Timestamp:
- 07/21/15 13:31:23 (10 years ago)
- Location:
- trunk
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/types.hh
r429 r431 56 56 struct type_field 57 57 { 58 uint64name; //!< name of the field58 shash64 name; //!< name of the field 59 59 type_hash hash; //!< typeinfo for later retrieval of type 60 60 type_entry* type; //!< pointer to field type … … 65 65 struct type_enum 66 66 { 67 uint64 name;68 sint32 value;67 shash64 name; 68 sint32 value; 69 69 }; 70 70 … … 146 146 } 147 147 148 string_view resolve_name( uint64 name_hash )148 string_view resolve_name( shash64 name_hash ) 149 149 { 150 150 return m_names[name_hash]; -
trunk/nv/engine/resource_system.hh
r399 r431 37 37 virtual void clear() { m_names.clear(); } 38 38 void load_all(); 39 resource_id load_resource( const st d::string& id );39 resource_id load_resource( const string_view& id ); 40 40 virtual ~resource_manager_base() {} 41 41 protected: … … 43 43 44 44 lua::state* m_lua; 45 unordered_map< std::string, resource_id > m_names;45 hashed_table< shash64, resource_id > m_names; 46 46 }; 47 47 … … 55 55 return ( id < m_data.size() ? m_data[ id ] : T() ); 56 56 } 57 T get_resource( const st d::string& id )57 T get_resource( const string_view& id ) 58 58 { 59 59 auto m = m_names.find( id ); … … 93 93 public: 94 94 explicit resource_system() : m_lua_state( nullptr ) { m_managers.push_back(nullptr); } 95 resource_type_id register_resource_type( const st d::string& name, resource_manager_base* manager );96 resource_type_id get_resource_type_id( const st d::string& name ) const;95 resource_type_id register_resource_type( const string_view& name, resource_manager_base* manager ); 96 resource_type_id get_resource_type_id( const string_view& name ) const; 97 97 void initialize( lua::state* a_lua_state ); 98 98 virtual ~resource_system(); 99 99 protected: 100 100 vector< resource_manager_base* > m_managers; 101 unordered_map< std::string, resource_id > m_manager_names;101 unordered_map< uint64, resource_id > m_manager_names; 102 102 lua::state* m_lua_state; 103 103 }; -
trunk/nv/formats/nmd_loader.hh
r428 r431 56 56 uint16 children; 57 57 uint32 size; 58 uint64name;58 shash64 name; 59 59 mat4 transform; 60 60 sint16 parent_id; -
trunk/nv/gfx/skeletal_mesh.hh
r430 r431 38 38 { 39 39 public: 40 skeletal_animation_entry_cpu( uint64 name, const mesh_nodes_data* a_animation, bool a_looping )40 skeletal_animation_entry_cpu( shash64 name, const mesh_nodes_data* a_animation, bool a_looping ) 41 41 : animation_entry( name, a_looping, a_animation->get_frame_rate(), 0.0f, a_animation->get_duration() ), m_node_data( a_animation ) 42 42 { 43 43 initialize(); 44 44 } 45 skeletal_animation_entry_cpu( uint64 name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping )45 skeletal_animation_entry_cpu( shash64 name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping ) 46 46 : animation_entry( name, a_looping, a_animation->get_frame_rate(), time_start, time_end ), m_node_data( a_animation ) 47 47 { … … 75 75 { 76 76 public: 77 skeletal_animation_entry_gpu( uint64 name, const mesh_nodes_data* anim, bool a_looping )77 skeletal_animation_entry_gpu( shash64 name, const mesh_nodes_data* anim, bool a_looping ) 78 78 : animation_entry( name, a_looping, anim->get_frame_rate(), 0.0f, anim->get_duration() ) 79 79 , m_node_data( anim ) … … 82 82 } 83 83 84 skeletal_animation_entry_gpu( uint64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping )84 skeletal_animation_entry_gpu( shash64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping ) 85 85 : animation_entry( name, a_looping, anim->get_frame_rate(), time_start, time_end ) 86 86 , m_node_data( anim ) -
trunk/nv/interface/animated_mesh.hh
r423 r431 25 25 { 26 26 public: 27 animation_entry( uint64 name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ),27 animation_entry( shash64 name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ), 28 28 m_start( a_start ), m_end( a_end ), m_duration( m_end - m_start ), m_material_idx(0) {} 29 uint64 get_name() const { return m_name; }29 shash64 get_name() const { return m_name; } 30 30 uint32 get_frame_rate() const { return m_frame_rate; } 31 31 float get_duration() const { return m_duration; } … … 47 47 virtual ~animation_entry() {} 48 48 protected: 49 uint64 m_name;50 bool m_looping;51 uint32 m_frame_rate;52 float m_start;53 float m_end;54 float m_duration;55 uint32 m_material_idx;49 shash64 m_name; 50 bool m_looping; 51 uint32 m_frame_rate; 52 float m_start; 53 float m_end; 54 float m_duration; 55 uint32 m_material_idx; 56 56 }; 57 57 -
trunk/nv/interface/data_channel.hh
r424 r431 91 91 for ( uint32 c = 0; c < other.m_size; ++c ) 92 92 m_channels[c] = move( other.m_channels[c] ); 93 m_size = other.m_size;94 m_parent_id = other.m_parent_id;95 m_transform = other.m_transform;96 m_name = other.m_name;93 m_size = other.m_size; 94 m_parent_id = other.m_parent_id; 95 m_transform = other.m_transform; 96 m_name = other.m_name; 97 97 other.m_size = 0; 98 98 } … … 209 209 const_iterator end() const { return &m_channels[ m_size ]; } 210 210 211 uint64 get_name() const { return m_name; }211 shash64 get_name() const { return m_name; } 212 212 sint16 get_parent_id() const { return m_parent_id; } 213 213 const mat4& get_transform() const { return m_transform; } … … 218 218 { 219 219 m_size = 0; 220 m_name = 0;221 220 m_parent_id = -1; 222 221 } … … 224 223 raw_data_channel m_channels[4]; 225 224 226 uint32 m_size;227 uint64 m_name;228 sint16 m_parent_id;229 mat4 m_transform;225 uint32 m_size; 226 shash64 m_name; 227 sint16 m_parent_id; 228 mat4 m_transform; 230 229 }; 231 230 -
trunk/nv/interface/data_channel_access.hh
r427 r431 144 144 const mat4& get_transform() const { return m_set->m_transform; } 145 145 146 void set_name( uint64 name ) { m_set->m_name = name; }147 uint64 get_name() const { return m_set->m_name; }146 void set_name( shash64 name ) { m_set->m_name = name; } 147 shash64 get_name() const { return m_set->m_name; } 148 148 149 149 void set_parent_id( sint16 name ) { m_set->m_parent_id = name; } -
trunk/nv/interface/map_area.hh
r406 r431 16 16 #include <nv/core/position.hh> 17 17 #include <nv/stl/string.hh> 18 #include <string>19 18 20 19 namespace nv … … 27 26 virtual uint32 get_cell( const position& p ) const = 0; 28 27 virtual void set_cell( const position& p, uint32 value ) = 0; 29 virtual uint32 string_to_id( const st d::string& ) const { return 0; }30 virtual st d::string id_to_string( uint32 ) const { return std::string(); }28 virtual uint32 string_to_id( const string_view& ) const { return 0; } 29 virtual string_view id_to_string( uint32 ) const { return string_view(); } 31 30 virtual dimension get_size() const = 0; 32 31 virtual position get_shift() const { return position(); } … … 48 47 virtual dimension get_size() const { return m_area.get_size(); } 49 48 virtual position get_shift() const { return m_area.ul + m_map_area->get_shift(); } 50 virtual uint32 string_to_id( const st d::string& s ) const { return m_map_area->string_to_id( s ); }51 virtual st d::stringid_to_string( uint32 id ) const { return m_map_area->id_to_string( id ); }49 virtual uint32 string_to_id( const string_view& s ) const { return m_map_area->string_to_id( s ); } 50 virtual string_view id_to_string( uint32 id ) const { return m_map_area->id_to_string( id ); } 52 51 private: 53 52 map_area* m_map_area; -
trunk/nv/interface/mesh_data.hh
r430 r431 32 32 typedef storage::const_iterator const_iterator; 33 33 34 explicit mesh_nodes_data( uint64 name )34 explicit mesh_nodes_data( shash64 name ) 35 35 : m_name( name ), m_frame_rate(0), m_duration(0.0f), m_flat( false ) 36 36 { 37 37 } 38 38 39 explicit mesh_nodes_data( uint64 name, uint16 a_fps, float a_frames, bool a_flat )39 explicit mesh_nodes_data( shash64 name, uint16 a_fps, float a_frames, bool a_flat ) 40 40 : m_name( name ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat ) 41 41 { … … 56 56 } 57 57 58 const data_channel_set* get_by_hash( uint64 h ) const58 const data_channel_set* get_by_hash( shash64 h ) const 59 59 { 60 60 for ( auto data : m_data ) … … 65 65 } 66 66 67 int get_index_by_hash( uint64 h ) const67 int get_index_by_hash( shash64 h ) const 68 68 { 69 69 for ( uint32 i = 0; i < m_data.size(); ++i ) … … 86 86 uint16 get_frame_rate() const { return m_frame_rate; } 87 87 float get_duration() const { return m_duration; } 88 void set_name( uint64 name ) { m_name = name; } 89 uint64 get_name() const { return m_name; } 88 shash64 get_name() const { return m_name; } 90 89 91 90 ~mesh_nodes_data() … … 96 95 private: 97 96 vector< data_channel_set* > m_data; 98 uint64 m_name;97 shash64 m_name; 99 98 uint16 m_frame_rate; 100 99 float m_duration; -
trunk/nv/interface/mesh_loader.hh
r428 r431 37 37 virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 ) { return nullptr; } 38 38 protected: 39 inline uint64 make_name( const string_view& name )39 inline shash64 make_name( const string_view& name ) 40 40 { 41 return m_strings ? m_strings->insert( name ) : name.get_hash< uint64 >();41 return m_strings ? m_strings->insert( name ) : shash64( name.get_hash< uint64 >() ); 42 42 } 43 43 string_table* m_strings; -
trunk/nv/lua/lua_state.hh
r426 r431 15 15 #include <nv/stl/flags.hh> 16 16 #include <nv/stl/handle.hh> 17 #include <nv/stl/string_table.hh> 17 18 #include <nv/stl/type_traits/function.hh> 18 19 … … 294 295 size_t get_size(); 295 296 bool has_field( string_view element ); 296 uint64 get_string_hash_64( string_view element, uint64 defval = 0 ); 297 shash64 get_string_hash_64( string_view element, uint64 defval = 0 ); 298 shash64 get_string( string_view element, string_table& table, uint64 defval = 0 ); 297 299 std::string get_std_string( string_view element, string_view defval = string_view() ); 298 300 const_string get_string( string_view element, string_view defval = string_view() ); -
trunk/nv/stl/functional/hash.hh
r428 r431 135 135 136 136 template < typename H, typename T > 137 constexpr H hash_value( const T& value )138 {139 return hash<T, H>::get( value );140 }141 142 template < typename H, typename T >143 137 constexpr H hash_combine( H seed, const T& h ) 144 138 { … … 168 162 } 169 163 164 template < typename H, typename Tag = void > 165 class hash_value 166 { 167 public: 168 typedef H hash_type; 169 typedef H value_type; 170 typedef hash_value< H, Tag > this_type; 171 172 173 // TODO: enforce exact type? 174 constexpr hash_value() : m_value( 0 ) {} 175 constexpr explicit hash_value( hash_type value ) : m_value( value ) {} 176 constexpr hash_value( const hash_value& ) = default; 177 178 constexpr bool valid() const { return m_value != 0; } 179 180 template < typename H, typename Tag > 181 friend constexpr bool operator==( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs ); 182 template < typename H, typename Tag > 183 friend constexpr bool operator!=( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs ); 184 185 constexpr H value() const { return m_value; } 186 protected: 187 hash_type m_value; 188 }; 189 190 template < typename T > 191 struct is_hash_value : is_template_base_of< T, hash_value > {}; 192 193 template< typename T, typename H > 194 struct hash< T, H, 195 typename enable_if< 196 is_hash_value<T>::value && 197 is_same< H, typename T::hash_type >::value, 198 void 199 >::type > : detail::hash_base< T, H > 200 { 201 typedef H hash_type; 202 static H get( const T& value ) 203 { 204 return value.value(); 205 } 206 inline H operator()( const T& value ) const { return get( value ); } 207 }; 208 209 template < typename H, typename Tag > 210 constexpr bool operator==( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs ) 211 { 212 return lhs.m_value == rhs.m_value; 213 } 214 215 template < typename H, typename Tag > 216 constexpr bool operator!=( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs ) 217 { 218 return lhs.m_value != rhs.m_value; 219 } 220 221 typedef hash_value< uint32 > hash32; 222 typedef hash_value< uint64 > hash64; 170 223 171 224 template < typename T, typename H, bool StoreElement = true > -
trunk/nv/stl/string.hh
r410 r431 42 42 // string 43 43 44 template< >45 struct hash< std::string, size_t>46 { 47 static size_tget( const std::string& value )48 { 49 return hash_string< size_t>( value.c_str(), value.length() );50 } 51 inline size_toperator()( const std::string& value ) const { return get( value ); }44 template< typename H > 45 struct hash< std::string, H > : detail::hash_base< std::string, H > 46 { 47 static H get( const std::string& value ) 48 { 49 return hash_string< H >( value.c_str(), value.length() ); 50 } 51 inline H operator()( const std::string& value ) const { return get( value ); } 52 52 }; 53 53 … … 164 164 template< typename T, typename H > 165 165 struct hash< T, H, typename enable_if< is_string_base<T>::value, void >::type > 166 : detail::hash_base< T, H > 166 167 { 167 168 static H get( const T& value ) … … 615 616 } 616 617 618 struct string_hash_tag {}; 619 620 template < typename H > 621 class string_hash : public hash_value< H, string_hash_tag > 622 { 623 public: 624 typedef H hash_type; 625 typedef H value_type; 626 typedef string_hash< H > this_type; 627 typedef hash_value< H, string_hash_tag > inherited_type; 628 629 // TODO: enforce exact type? 630 constexpr string_hash() : inherited_type() {} 631 inline string_hash( const string_view& rhs ) : inherited_type( hash_string< H >( rhs.data(), rhs.size() ) ) {} 632 template < typename S > 633 inline string_hash( const string_base<S>& rhs ) : inherited_type( hash_string< H >( rhs.data(), rhs.size() ) ) {} 634 constexpr string_hash( const char* str, size_t len ) : inherited_type( hash_string< H >( str, len ) ) {} 635 636 // Literal constructors 637 template< size_t N > 638 constexpr string_hash( char( &s )[N] ) : inherited_type( hash_string< H >( s, N - 1 ) ) {} 639 template< size_t N > 640 constexpr string_hash( const char( &s )[N] ) : inherited_type( hash_string< H >( s, N - 1 ) ) {} 641 642 constexpr explicit string_hash( hash_type value ) : inherited_type( value ) {} 643 constexpr string_hash( const string_hash& value ) = default; 644 }; 645 646 typedef string_hash< uint32 > shash32; 647 typedef string_hash< uint64 > shash64; 617 648 } 618 649 -
trunk/nv/stl/string_table.hh
r428 r431 26 26 public: 27 27 typedef string_view value_type; 28 typedef uint64 key_type;28 typedef shash64 key_type; 29 29 typedef uint64 hash_type; 30 30 typedef uint32 size_type; 31 31 typedef uint16 length_type; 32 typedef unordered_map< key_type, size_type > indexer_type;32 typedef unordered_map< hash_type, size_type > indexer_type; 33 33 typedef vector< char > storage_type; 34 34 typedef indexer_type::const_iterator const_iterator; … … 39 39 key_type insert( const value_type& str ) 40 40 { 41 key_type hash_value = str.get_hash< uint64 >();41 hash_type hash_value = str.get_hash< uint64 >(); 42 42 insert( hash_value, str ); 43 return hash_value;43 return key_type( hash_value ); 44 44 } 45 45 46 46 bool exists( key_type i ) const 47 47 { 48 return m_map.find( i ) != m_map.end();48 return m_map.find( i.value() ) != m_map.end(); 49 49 } 50 50 51 51 value_type at( key_type i ) const 52 52 { 53 const auto& it = m_map.find( i );53 const auto& it = m_map.find( i.value() ); 54 54 NV_ASSERT_ALWAYS( it != m_map.end(), "Key not found in string_table!" ); 55 55 return extract_raw( it->second ); … … 58 58 value_type operator[]( key_type i ) const 59 59 { 60 const auto& it = m_map.find( i );60 const auto& it = m_map.find( i.value() ); 61 61 return it != m_map.end() ? extract_raw( it->second ) : value_type(); 62 62 } -
trunk/nv/stl/unordered_map.hh
r408 r431 227 227 typename Hash = hash< Key >, 228 228 typename KeyEqual = equal_to< Key >, 229 typename HashEntryPolicy = hash_table_stl_map_policy< Key, T, size_t, KeyEqual, Hash >229 typename HashEntryPolicy = hash_table_stl_map_policy< Key, T, typename Hash::result_type, KeyEqual, Hash > 230 230 > 231 231 class unordered_map … … 324 324 }; 325 325 326 // TODO: remove and make a proper hashed map 327 template < 328 typename Key, 329 typename T, 330 typename Hasher = hash< Key, typename Key::value_type >, 331 typename KeyEqual = equal_to< Key >, 332 typename HashEntryPolicy = hash_table_stl_map_policy< Key, T, typename Key::value_type, KeyEqual, Hasher > 333 > 334 class hashed_table 335 : public hash_table< 336 HashEntryPolicy, 337 hash_table_no_extra_types_policy, 338 hash_table_prime_rehash_policy, 339 HashEntryPolicy 340 > 341 { 342 public: 343 typedef hash_table< 344 HashEntryPolicy, 345 hash_table_no_extra_types_policy, 346 hash_table_prime_rehash_policy, 347 HashEntryPolicy 348 > base_type; 349 typedef typename base_type::value_type value_type; 350 typedef typename base_type::pointer pointer; 351 typedef typename base_type::const_pointer const_pointer; 352 typedef typename base_type::reference reference; 353 typedef typename base_type::const_reference const_reference; 354 typedef typename base_type::iterator iterator; 355 typedef typename base_type::const_iterator const_iterator; 356 typedef typename base_type::size_type size_type; 357 typedef typename base_type::difference_type difference_type; 358 typedef typename base_type::key_type key_type; 359 typedef typename base_type::mapped_type mapped_type; 360 typedef typename base_type::node_type node_type; 361 typedef typename base_type::insert_return_type insert_return_type; 362 typedef Hasher hasher; 363 typedef KeyEqual key_equal; 364 365 using base_type::base_type; 366 367 mapped_type& operator[]( const key_type& key ) 368 { 369 return ( *base_type::insert_key( key ).first ).second; 370 } 371 }; 372 373 326 374 } 327 375 -
trunk/src/engine/resource_system.cc
r399 r431 15 15 } 16 16 17 nv::resource_id nv::resource_manager_base::load_resource( const st d::string& id )17 nv::resource_id nv::resource_manager_base::load_resource( const string_view& id ) 18 18 { 19 19 lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) ); … … 32 32 lua::table_guard sub_table( table, i+1 ); 33 33 resource_id rid = load_resource( sub_table ); 34 if ( rid != 0 ) m_names[ sub_table.get_st d_string("id") ] = rid;34 if ( rid != 0 ) m_names[ sub_table.get_string_hash_64("id") ] = rid; 35 35 } 36 36 } 37 37 38 nv::resource_type_id nv::resource_system::register_resource_type( const st d::string& /*name*/, resource_manager_base* /*manager*/ )38 nv::resource_type_id nv::resource_system::register_resource_type( const string_view& /*name*/, resource_manager_base* /*manager*/ ) 39 39 { 40 40 return 0; 41 41 } 42 42 43 nv::resource_type_id nv::resource_system::get_resource_type_id( const st d::string& /*name*/ ) const43 nv::resource_type_id nv::resource_system::get_resource_type_id( const string_view& /*name*/ ) const 44 44 { 45 45 return 0; -
trunk/src/formats/assimp_loader.cc
r428 r431 288 288 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); 289 289 mesh_nodes_data* result = new mesh_nodes_data( make_name( "bones" ) ); 290 unordered_map< uint64, uint16 > names;290 hashed_table< shash64, uint16 > names; 291 291 for ( unsigned int m = 0; m < m_mesh_count; ++m ) 292 292 { -
trunk/src/formats/md3_loader.cc
r427 r431 420 420 uint32 node_count = uint32( md3->header.num_tags ); 421 421 if ( node_count == 0 ) return nullptr; 422 mesh_nodes_data* result = new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0);422 mesh_nodes_data* result = new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : shash64() ); 423 423 for ( uint32 i = 0; i < node_count; ++i ) 424 424 { -
trunk/src/formats/nmd_loader.cc
r428 r431 233 233 sheader.children = 0; 234 234 sheader.size = strings.dump_size(); 235 sheader.name = 0;235 sheader.name = shash64(); 236 236 sheader.parent_id = -1; 237 237 sheader.attributes = 0; -
trunk/src/gfx/skeletal_mesh.cc
r430 r431 177 177 { 178 178 const data_channel_set* bone = (*bones)[ bi ]; 179 bone_names[ bone->get_name() ] = bi;179 bone_names[ bone->get_name().value() ] = bi; 180 180 m_offsets[bi] = bone->get_transform(); 181 181 } … … 186 186 sint16 bone_id = -1; 187 187 188 auto bi = bone_names.find( node->get_name() );188 auto bi = bone_names.find( node->get_name().value() ); 189 189 if ( bi != bone_names.end() ) 190 190 { -
trunk/src/lua/lua_map_area.cc
r406 r431 137 137 { 138 138 nv::map_area* ma = to_map_area( L, 1 ); 139 lua_pushstring( L, ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ).c_str() ); 139 nv::string_view result( ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ) ); 140 lua_pushlstring( L, result.data(), result.size() ); 140 141 return 1; 141 142 } -
trunk/src/lua/lua_state.cc
r426 r431 184 184 } 185 185 186 uint64 nv::lua::table_guard::get_string_hash_64( string_view element, uint64 defval /*= 0 */ )186 shash64 nv::lua::table_guard::get_string_hash_64( string_view element, uint64 defval /*= 0 */ ) 187 187 { 188 188 lua_getfield( m_state, -1, element.data() ); … … 196 196 } 197 197 lua_pop( m_state, 1 ); 198 return result; 198 return shash64( result ); 199 } 200 201 shash64 nv::lua::table_guard::get_string( string_view element, string_table& table, uint64 defval /*= 0 */ ) 202 { 203 lua_getfield( m_state, -1, element.data() ); 204 size_t l = 0; 205 const char* str = nullptr; 206 uint64 result = defval; 207 if ( lua_type( m_state, -1 ) == LUA_TSTRING ) 208 { 209 str = lua_tolstring( m_state, -1, &l ); 210 result = table.insert( string_view( str, l ) ).value(); 211 } 212 lua_pop( m_state, 1 ); 213 return shash64( result ); 199 214 } 200 215
Note: See TracChangeset
for help on using the changeset viewer.