Пример #1
0
void ResourceManager::addResource(Resource &resource, uint64 hash, ChangeID &change) {
	normalizeType(resource);

	ResourceMap::iterator resList = _resources.find(hash);
	if (resList == _resources.end()) {
		// We don't have a resource with this name yet, create a new resource list for it

		std::pair<ResourceMap::iterator, bool> result;

		result = _resources.insert(std::make_pair(hash, ResourceList()));

		resList = result.first;
	}

#ifdef CHECK_HASH_COLLISION
	checkHashCollision(resource, resList);
#endif

	// Add the resource to the list and sort by priority
	resList->second.push_back(resource);
	resList->second.sort();

	// Remember the resource in the change set
	change._change->resources.push_back(ResourceChange());
	change._change->resources.back().hashIt = resList;
	change._change->resources.back().resIt  = --resList->second.end();
}
Пример #2
0
void ResourceManager::addResource(Resource &resource, Common::UString name, ChangeID &change) {
	name.tolower();
	if (name.empty())
		return;

	// Normalize resource type *sigh*
	if      (resource.type == kFileTypeQST2)
		resource.type = kFileTypeQST;
	else if (resource.type == kFileTypeMDX2)
		resource.type = kFileTypeMDX;
	else if (resource.type == kFileTypeTXB2)
		resource.type = kFileTypeTXB;
	else if (resource.type == kFileTypeCRE)
		resource.type = kFileTypeBTC;

	// Resolve the type aliases
	std::map<FileType, FileType>::const_iterator alias = _typeAliases.find(resource.type);
	if (alias != _typeAliases.end())
		resource.type = alias->second;

	ResourceMap::iterator resTypeMap = _resources.find(name);
	if (resTypeMap == _resources.end()) {
		// We don't yet have a resource with this name, create a new type map for it

		std::pair<ResourceMap::iterator, bool> result;

		result = _resources.insert(std::make_pair(name, ResourceTypeMap()));

		resTypeMap = result.first;
	}

	ResourceTypeMap::iterator resList = resTypeMap->second.find(resource.type);
	if (resList == resTypeMap->second.end()) {
		// We don't yet have a resource with that name and type, create a new resource list for it

		std::pair<ResourceTypeMap::iterator, bool> result;

		result = resTypeMap->second.insert(std::make_pair(resource.type, ResourceList()));

		resList = result.first;
	}

	// Add the resource to the list
	resList->second.push_back(resource);

	// And sort the list by priority
	resList->second.sort();

	// Remember the resource in the change set
	change._change->resources.push_back(ResourceChange());
	change._change->resources.back().nameIt = resTypeMap;
	change._change->resources.back().typeIt = resList;
	change._change->resources.back().resIt  = --resList->second.end();
}