From e588b371bdfc77fd35352c18b4a197a2760d6d81 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 10 Sep 2014 14:09:42 +0800 Subject: [PATCH] Replace with 'struct' for AudioInfo/ProfileHelper. --- cocos/audio/AudioEngine.cpp | 49 ++++++++++++++++--------------- cocos/audio/include/AudioEngine.h | 42 +++++++++++++------------- cocos/audio/ios/AudioEngine-inl.h | 1 - 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/cocos/audio/AudioEngine.cpp b/cocos/audio/AudioEngine.cpp index d485bd6695..28a3a74114 100644 --- a/cocos/audio/AudioEngine.cpp +++ b/cocos/audio/AudioEngine.cpp @@ -42,10 +42,10 @@ const float AudioEngine::TIME_UNKNOWN = -1.0f; //audio file path,audio IDs std::unordered_map> AudioEngine::_audioPathIDMap; -//profileName,ProfileManage -std::unordered_map AudioEngine::_audioPathProfileManageMap; +//profileName,ProfileHelper +std::unordered_map AudioEngine::_audioPathProfileHelperMap; int AudioEngine::_maxInstances = kMaxSources; -AudioEngine::ProfileManage* AudioEngine::_defaultProfileManage; +AudioEngine::ProfileHelper* AudioEngine::_defaultProfileHelper; std::unordered_map AudioEngine::_audioIDInfoMap; AudioEngineImpl* AudioEngine::_audioEngineImpl = nullptr; @@ -54,8 +54,8 @@ void AudioEngine::end() delete _audioEngineImpl; _audioEngineImpl = nullptr; - delete _defaultProfileManage; - _defaultProfileManage = nullptr; + delete _defaultProfileHelper; + _defaultProfileHelper = nullptr; } bool AudioEngine::lazyInit() @@ -84,10 +84,10 @@ int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, co break; } - ProfileManage* manage = _defaultProfileManage; + ProfileHelper* manage = _defaultProfileHelper; if (profile && profile != &manage->profile){ CC_ASSERT(!profile->name.empty()); - manage = &_audioPathProfileManageMap[profile->name]; + manage = &_audioPathProfileHelperMap[profile->name]; manage->profile = *profile; } @@ -133,7 +133,7 @@ int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, co manage->lastPlayTime = utils::gettime(); manage->audioIDs.push_back(ret); } - audioRef.profileManage = manage; + audioRef.profileHelper = manage; } } while (0); @@ -152,15 +152,18 @@ void AudioEngine::setLoop(int audioID, bool loop) void AudioEngine::setVolume(int audioID, float volume) { auto it = _audioIDInfoMap.find(audioID); - if (it != _audioIDInfoMap.end() && it->second.volume != volume){ + if (it != _audioIDInfoMap.end()){ if (volume < 0.0f) { volume = 0.0f; } else if (volume > 1.0f){ volume = 1.0f; } - _audioEngineImpl->setVolume(audioID, volume); - it->second.volume = volume; + + if (it->second.volume != volume){ + _audioEngineImpl->setVolume(audioID, volume); + it->second.volume = volume; + } } } @@ -222,8 +225,8 @@ void AudioEngine::remove(int audioID) { auto it = _audioIDInfoMap.find(audioID); if (it != _audioIDInfoMap.end()){ - if (it->second.profileManage) { - it->second.profileManage->audioIDs.remove(audioID); + if (it->second.profileHelper) { + it->second.profileHelper->audioIDs.remove(audioID); } _audioPathIDMap[*it->second.filePath].remove(audioID); _audioIDInfoMap.erase(audioID); @@ -236,8 +239,8 @@ void AudioEngine::stopAll() auto itEnd = _audioIDInfoMap.end(); for (auto it = _audioIDInfoMap.begin(); it != itEnd; ++it) { - if (it->second.profileManage){ - it->second.profileManage->audioIDs.remove(it->first); + if (it->second.profileHelper){ + it->second.profileHelper->audioIDs.remove(it->first); } } _audioPathIDMap.clear(); @@ -254,8 +257,8 @@ void AudioEngine::uncache(const std::string &filePath) auto itInfo = _audioIDInfoMap.find(audioID); if (itInfo != _audioIDInfoMap.end()){ - if (itInfo->second.profileManage) { - itInfo->second.profileManage->audioIDs.remove(audioID); + if (itInfo->second.profileHelper) { + itInfo->second.profileHelper->audioIDs.remove(audioID); } _audioIDInfoMap.erase(audioID); } @@ -363,7 +366,7 @@ AudioProfile* AudioEngine::getProfile(int audioID) auto it = _audioIDInfoMap.find(audioID); if (it != _audioIDInfoMap.end()) { - return &it->second.profileManage->profile; + return &it->second.profileHelper->profile; } return nullptr; @@ -371,18 +374,18 @@ AudioProfile* AudioEngine::getProfile(int audioID) AudioProfile* AudioEngine::getDefaultProfile() { - if (_defaultProfileManage == nullptr) + if (_defaultProfileHelper == nullptr) { - _defaultProfileManage = new (std::nothrow) ProfileManage(); + _defaultProfileHelper = new (std::nothrow) ProfileHelper(); } - return &_defaultProfileManage->profile; + return &_defaultProfileHelper->profile; } AudioProfile* AudioEngine::getProfile(const std::string &name) { - auto it = _audioPathProfileManageMap.find(name); - if (it != _audioPathProfileManageMap.end()) { + auto it = _audioPathProfileHelperMap.find(name); + if (it != _audioPathProfileHelperMap.end()) { return &it->second.profile; } else { return nullptr; diff --git a/cocos/audio/include/AudioEngine.h b/cocos/audio/include/AudioEngine.h index d4442a562d..a3663b0868 100644 --- a/cocos/audio/include/AudioEngine.h +++ b/cocos/audio/include/AudioEngine.h @@ -211,35 +211,25 @@ protected: static void remove(int audioID); - class ProfileManage + struct ProfileHelper { - public: AudioProfile profile; - ProfileManage() - : lastPlayTime(0.0) - { - - } - std::list audioIDs; double lastPlayTime; - }; - class AudioInfo - { - public: - AudioInfo() - : profileManage(nullptr) - , duration(TIME_UNKNOWN) - , state(AudioState::INITIALZING) + ProfileHelper() + : lastPlayTime(0.0) { - + } - + }; + + struct AudioInfo + { const std::string* filePath; - ProfileManage* profileManage; + ProfileHelper* profileHelper; float volume; bool loop; @@ -247,6 +237,14 @@ protected: AudioState state; bool is3dAudio; + + AudioInfo() + : profileHelper(nullptr) + , duration(TIME_UNKNOWN) + , state(AudioState::INITIALZING) + { + + } }; //audioID,audioAttribute @@ -255,12 +253,12 @@ protected: //audio file path,audio IDs static std::unordered_map> _audioPathIDMap; - //profileName,ProfileManage - static std::unordered_map _audioPathProfileManageMap; + //profileName,ProfileHelper + static std::unordered_map _audioPathProfileHelperMap; static int _maxInstances; - static ProfileManage* _defaultProfileManage; + static ProfileHelper* _defaultProfileHelper; static AudioEngineImpl* _audioEngineImpl; diff --git a/cocos/audio/ios/AudioEngine-inl.h b/cocos/audio/ios/AudioEngine-inl.h index 835367a06f..5421389948 100644 --- a/cocos/audio/ios/AudioEngine-inl.h +++ b/cocos/audio/ios/AudioEngine-inl.h @@ -33,7 +33,6 @@ #include "AudioPlayer.h" NS_CC_BEGIN -class AudioProfile; #define kMaxSources 32