Beispiel #1
0
ResourceHandle ResourceManager::loadResource(ResourceLoadOptions& options)
{
	if( !archive ) return ResourceHandle(HandleInvalid);

	Path fileExt = PathGetFileExtension(options.name);
	
	// If the file has no extension, search for one with the same
	// name but with known resource loadable file extensions.

	if(fileExt.empty() && !findResource(options))
	{
		LogError("Could not find matching file for '%s'", options.name.c_str());
		return ResourceHandle(HandleInvalid);
	}

	// Check if the resource is already loaded.
	ResourceHandle handle = getResource(options.name);
	if( handle ) return handle;

	if( !validateResource(options.name) )
		return ResourceHandle(HandleInvalid);

	Resource* resource = prepareResource(options);
	
	if( !resource )
		return ResourceHandle(HandleInvalid); 

	handle = ResourceHandleCreate(resource);
	
	if(handle == HandleInvalid)
		return ResourceHandle(HandleInvalid);

	// Register the decoded resource in the map.
	Path base = PathGetFile(options.name);
	auto key = MurmurHash64(base.c_str(), base.size(), 0);
	resources.set(key, handle);

	decodeResource(options);

	return handle;
}
Beispiel #2
0
void ResourceManager::registerLoader(ResourceLoader* loader)
{
	if( !loader ) return;

	Class* klass = loader->getType();
	LogInfo( "Registering resource loader '%s'", klass->name );
	
	for( auto ext : loader->getExtensions() )
	{
		auto key = MurmurHash64(ext.c_str(), ext.size(), 0);
		if(resourceLoaders.has(key))
		{
			LogDebug("Extension '%s' already has a resource loader", ext.c_str());
			continue;
		}

		resourceLoaders.set(key, loader);
	}

	onResourceLoaderRegistered( *loader );
}
void MyDirectSound::SaveSoundBlock( MyDirectSoundBuffer* o, const void* data, DWORD size )
{
	M_ASSERT(data != NULL);
	M_ASSERT(size > 0);

	const UINT64 hash = MurmurHash64( data, size );

	SoundChunksByHashT::iterator it = m_soundChunks.find( hash );

	if( it == m_soundChunks.end() )
	{

#ifdef OUTPUT_FOLDER

		// generate unique file name
		char buffer[32];
		sprintf(buffer, "%016llX", hash);

		char filepath[MAX_PATH];
		strcpy_s(filepath, OUTPUT_FOLDER);
		strcat_s(filepath, buffer);
		strcat_s(filepath, ".wav");

		SaveWavToFile( o, data, size, filepath );

#endif // if defined (OUTPUT_FOLDER)

		SoundChunk newChunk;

		//// redundant memory allocations and a copy, but who cares...
		//newChunk.data.resize(size);
		//memcpy(&newChunk.data[0], data, size);

		m_soundChunks.insert( std::make_pair( hash, newChunk ) );
	}
}
Beispiel #4
0
static inline uint64_t hash(const char* str) {
    return MurmurHash64(str, strlen(str), 0);
}
Beispiel #5
0
int creat_sign_murmurs64(const char *psrc,int slen,unsigned int *sign1,unsigned int *sign2,unsigned int seed){
    unsigned long long res=MurmurHash64(psrc,slen,seed);
    *sign1=(res>>32);
    *sign2=(res & 0x0ffffffff);
    return 1;
}