当前位置: 首页>>代码示例>>C++>>正文


C++ BackgroundMusicsMap::insert方法代码示例

本文整理汇总了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));
		}
	}
开发者ID:01jeremylee,项目名称:cocos2dx_recipe,代码行数:43,代码来源:SimpleAudioEngine.cpp

示例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));
    }
}
开发者ID:skatpgusskat,项目名称:December,代码行数:39,代码来源:SimpleAudioEngineOpenAL.cpp


注:本文中的BackgroundMusicsMap::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。