本文整理汇总了C++中BackgroundMusicsMap::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ BackgroundMusicsMap::insert方法的具体用法?C++ BackgroundMusicsMap::insert怎么用?C++ BackgroundMusicsMap::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackgroundMusicsMap
的用法示例。
在下文中一共展示了BackgroundMusicsMap::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
}
示例2: 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));
}
}