bool SoundManager::addSoundBufferFromFile(const std::string& fileName, const std::string& soundBufferID)
{
    sf::SoundBuffer* soundBuffer = new sf::SoundBuffer();
    if(soundBuffer->loadFromFile(fileName))
    {
        if(!addSoundBuffer(soundBuffer, soundBufferID))
        {
            printf("Failed to add \"%s\" to manager\n", fileName);
            delete soundBuffer;
            return false;
        }
    }
    return true;
}
示例#2
0
sf::SoundBuffer * DataManager::getSoundBuffer( const std::string path )
{
    if(DataManager::singleton == NULL)
    {
        DataManager::singleton = new DataManager;
    }

    sf::SoundBuffer * s = NULL;
    std::map< std::string, sf::SoundBuffer * >::iterator i = DataManager::singleton->m_sounds.find( path );
    if( i == DataManager::singleton->m_sounds.end() )
    {
        s = addSoundBuffer( path );
    }
    else
    {
        s = (*i).second;
    }

    return s;
}