Ejemplo n.º 1
0
AudioAsset* AssetManager::RequestAudio(const std::string &filename, bool loop) {
    assert(filename.c_str());
    AudioAsset* asset = static_cast<AudioAsset*>(GetAssetByFilename(filename));

    if (!asset) {
        asset = new AudioAsset();
        bool result = false;
        switch (mMethod) {
        case AssetLoadingMethod::LoadFromFile:
            result = asset->Load(filename, loop);
            break;
        case AssetLoadingMethod::LoadFromBinary:
            result = asset->Load(filename, loop);
            break;
        }

        if (result) {
            StoreAsset(asset);
        }
        else {
            printIn("%s: Failed to load\n", asset->mName.c_str());
            SAFE_DELETE(asset);
        }
    }

    if (asset) {
        asset->AddReference();
        printIn("%s: RefCount (%d)\n", asset->mName.c_str(), asset->mRefCount);
    }

    return asset;
}
Ejemplo n.º 2
0
    AudioAsset *Assets::RequestAudio(const std::string &filename, bool streamFromDisk, std::string decodeString)
	{
		AudioAsset *asset = NULL;
		std::string fullFilename = instance->contentPath + filename;
        
		//Debug::Log("instance->contentPath + filename: " + fullFilename);
        
		// check to see if we have one stored already
		asset = (AudioAsset*)instance->GetAssetByFilename(fullFilename);
        
		// if not, load it and store it
		if (!asset)
		{
			asset = new AudioAsset();
            asset->SetDecodeString(decodeString);
			asset->Load(fullFilename, streamFromDisk);
            
            // Return NULL if there was no asset...
            if (!asset->GetDataSize()){
                delete asset;
                return NULL;
            }
            
			instance->StoreAsset((Asset*)asset);
		}
        
		if (asset)
		{
			asset->AddReference();
		}
        
		// return what we found
		return asset;
	}