Esempio n. 1
0
	uint32_t RenderMaterialManager::makeMaterialHash( const ConstString & _materialName, uint32_t _textureCount, const RenderTextureInterfacePtr * _textures ) const
	{
		uint32_t material_hash = (uint32_t)_materialName.hash();

		for( uint32_t i = 0; i != _textureCount; ++i )
		{
			uint32_t texture_id = _textures[i]->getId();

			material_hash += texture_id + i * 3571;
		}

		return material_hash;
	}
Esempio n. 2
0
	ResourceReferencePtr ResourceManager::createResource( const ConstString & _locale, const ConstString& _category, const ConstString& _group, const ConstString& _name, const ConstString& _type )
	{
		ResourceReferencePtr resource = this->generateResource( _type );

		if( resource == nullptr )
		{
			LOGGER_ERROR( m_serviceProvider )("ResourceManager createResource: invalid generate resource locale '%s' category '%s' group '%s' name '%s' type '%s'"
				, _locale.c_str()
				, _category.c_str()
				, _group.c_str()
				, _name.c_str()
				, _type.c_str()
				);

			return nullptr;
		}

		resource->setLocale( _locale );
		resource->setCategory( _category );
		resource->setGroup( _group );
		resource->setName( _name );

		ResourceEntry entry;
				
		entry.resource = resource;
		entry.isLocked = false;

		ConstString::hash_type hash = _name.hash();
		uint32_t table = (uint32_t)hash % MENGINE_RESOURCE_MANAGER_HASH_SIZE;
		TMapResource & resources = m_resources[table];

		std::pair<TMapResource::iterator, bool> insert_result = resources.insert( std::make_pair( _name, entry ) );

		TResourceCacheKey cache_key = std::make_pair( _category, _group );

		TMapResourceCache::iterator it_cache_found = m_resourcesCache.find( cache_key );

		if( it_cache_found == m_resourcesCache.end() )
		{
			TVectorResources new_resources;
			
			it_cache_found = m_resourcesCache.insert( it_cache_found, std::make_pair( cache_key, new_resources ) );
		}
		
		TVectorResources & cahce_resources = it_cache_found->second;

		cahce_resources.push_back( resource );

		if( insert_result.second == false )
		{
			ResourceEntry & insert_entry = insert_result.first->second;

			const ConstString & insert_category = insert_entry.resource->getCategory();
			const ConstString & insert_group = insert_entry.resource->getGroup();

			TResourceCacheKey remove_cache_key = std::make_pair( insert_category, insert_group );

			TMapResourceCache::iterator it_remove_cache_found = m_resourcesCache.find( remove_cache_key );

			TVectorResources::iterator it_remove_found = std::remove(
				it_remove_cache_found->second.begin(),
				it_remove_cache_found->second.end(),
				insert_entry.resource );

			it_remove_cache_found->second.erase( it_remove_found );

			resources[_name] = entry;
		}
        
		return resource;
	}