本文整理汇总了C++中BackgroundMusicsMap::end方法的典型用法代码示例。如果您正苦于以下问题:C++ BackgroundMusicsMap::end方法的具体用法?C++ BackgroundMusicsMap::end怎么用?C++ BackgroundMusicsMap::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackgroundMusicsMap
的用法示例。
在下文中一共展示了BackgroundMusicsMap::end方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: playBackgroundMusic
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
// If there is already a background music source we stop it first
if (s_backgroundSource != AL_NONE)
stopBackgroundMusic(false);
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
preloadBackgroundMusic(fullPath.c_str());
it = s_backgroundMusics.find(fullPath);
}
if (it != s_backgroundMusics.end())
{
s_backgroundSource = it->second->source;
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
setBackgroundVolume(s_volume);
alSourcePlay(s_backgroundSource);
checkALError("playBackgroundMusic:alSourcePlay");
}
}
示例2: stopBackground
static void stopBackground(bool bReleaseData)
{
// The background music might have been already stopped
// Stop request can come from
// - stopBackgroundMusic(..)
// - end(..)
if (s_backgroundSource != AL_NONE)
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
for (auto it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
if (it->second->source == s_backgroundSource)
{
alDeleteSources(1, &it->second->source);
checkALError("stopBackground:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("stopBackground:alDeleteBuffers");
delete it->second;
s_backgroundMusics.erase(it);
break;
}
}
}
s_backgroundSource = AL_NONE;
}
示例3: end
void SimpleAudioEngine::end()
{
checkALError("end");
// clear all the sounds
EffectsMap::const_iterator end = s_effects.end();
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
{
alSourceStop(it->second->source);
checkALError("end");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end");
alDeleteSources(1, &it->second->source);
checkALError("end");
delete it->second;
}
s_effects.clear();
// and the background too
stopBackground(true);
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
alSourceStop(it->second->source);
checkALError("end");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end");
alDeleteSources(1, &it->second->source);
checkALError("end");
delete it->second;
}
s_backgroundMusics.clear();
}
示例4: playBackgroundMusic
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
if (s_backgroundSource != AL_NONE)
stopBackgroundMusic(false);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
preloadBackgroundMusic(fullPath.c_str());
it = s_backgroundMusics.find(fullPath);
}
if (it != s_backgroundMusics.end())
{
s_backgroundSource = it->second->source;
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
alSourcePlay(s_backgroundSource);
checkALError("playBackgroundMusic");
}
}
示例5: end
void SimpleAudioEngine::end()
{
checkALError("end:init");
// clear all the sound effects
EffectsMap::const_iterator end = s_effects.end();
for (auto it = s_effects.begin(); it != end; ++it)
{
alSourceStop(it->second->source);
checkALError("end:alSourceStop");
alDeleteSources(1, &it->second->source);
checkALError("end:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end:alDeleteBuffers");
delete it->second;
}
s_effects.clear();
// and the background music too
stopBackground(true);
for (auto it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
alSourceStop(it->second->source);
checkALError("end:alSourceStop");
alDeleteSources(1, &it->second->source);
checkALError("end:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end:alDeleteBuffers");
delete it->second;
}
s_backgroundMusics.clear();
CC_SAFE_DELETE(s_engine);
}
示例6: end
void SimpleAudioEngine::end()
{
// clear all the sounds
EffectsMap::const_iterator end = s_effects.end();
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
{
Mix_FreeChunk(it->second->chunk);
delete it->second;
}
s_effects.clear();
// and the background too
stopBackground(true);
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
Mix_FreeMusic(it->second->music);
delete it->second;
}
s_backgroundMusics.clear();
}
示例7: preloadBackgroundMusic
//
// background audio
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
ALuint buffer = AL_NONE;
if (isOGGFile(fullPath.data()))
{
buffer = createBufferFromOGG(fullPath.data());
}
else
{
buffer = alutCreateBufferFromFile(fullPath.data());
}
checkALError("preloadBackgroundMusic");
if (buffer == AL_NONE)
{
fprintf(stderr, "Error loading file: '%s'\n", fullPath.data());
alDeleteBuffers(1, &buffer);
return;
}
ALuint source = AL_NONE;
alGenSources(1, &source);
checkALError("preloadBackgroundMusic");
alSourcei(source, AL_BUFFER, buffer);
checkALError("preloadBackgroundMusic");
backgroundMusicData* data = new backgroundMusicData();
data->buffer = buffer;
data->source = source;
s_backgroundMusics.insert(BackgroundMusicsMap::value_type(fullPath, data));
}
}
示例8: stopBackground
static void stopBackground(bool bReleaseData)
{
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
if (it->second->source == s_backgroundSource)
{
alDeleteBuffers(1, &it->second->buffer);
checkALError("stopBackground");
alDeleteSources(1, &it->second->source);
checkALError("stopBackground");
delete it->second;
s_backgroundMusics.erase(it);
break;
}
}
}
s_backgroundSource = AL_NONE;
}
示例9: preloadBackgroundMusic
//
// background audio
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
ALuint buffer = AL_NONE;
bool success = false;
OpenALFile file;
file.debugName = pszFilePath;
file.file = fopen(fullPath.c_str(), "rb");
if (!file.file) {
fprintf(stderr, "Cannot read file: '%s'\n", fullPath.data());
return;
}
const std::vector<OpenALDecoder *> &decoders = OpenALDecoder::getDecoders();
for (size_t i = 0, n = decoders.size(); !success && i < n; ++i)
success = decoders[i]->decode(file, buffer);
file.clear();
ALuint source = AL_NONE;
alGenSources(1, &source);
checkALError("preloadBackgroundMusic:alGenSources");
alSourcei(source, AL_BUFFER, buffer);
checkALError("preloadBackgroundMusic:alSourcei");
backgroundMusicData* data = new backgroundMusicData();
data->buffer = buffer;
data->source = source;
s_backgroundMusics.insert(BackgroundMusicsMap::value_type(fullPath, data));
}
}