From 9942206c53d89b8112b9b8ce4394d031bf2b93f2 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Tue, 16 Sep 2014 10:22:25 +0800 Subject: [PATCH 1/2] move AudioEngine in cocos2d:experimental namespace --- cocos/audio/AudioEngine.cpp | 1 + cocos/audio/android/AudioEngine-inl.cpp | 1 + cocos/audio/android/AudioEngine-inl.h | 4 +- cocos/audio/include/AudioEngine.h | 2 + cocos/audio/ios/AudioEngine-inl.h | 3 +- cocos/audio/ios/AudioEngine-inl.mm | 1 + .../lua_cocos2dx_audioengine_manual.cpp | 48 +++++++++---------- .../NewAudioEngineTest/NewAudioEngineTest.cpp | 4 +- .../NewAudioEngineTest/NewAudioEngineTest.h | 2 +- .../NewAudioEngineTest/NewAudioEngineTest.lua | 48 +++++++++---------- tools/tolua/cocos2dx_audioengine.ini | 2 +- 11 files changed, 62 insertions(+), 54 deletions(-) diff --git a/cocos/audio/AudioEngine.cpp b/cocos/audio/AudioEngine.cpp index 0250e7d3cb..11c1556744 100644 --- a/cocos/audio/AudioEngine.cpp +++ b/cocos/audio/AudioEngine.cpp @@ -36,6 +36,7 @@ #define TIME_DELAY_PRECISION 0.0001 using namespace cocos2d; +using namespace cocos2d::experimental; const int AudioEngine::INVAILD_AUDIO_ID = -1; const float AudioEngine::TIME_UNKNOWN = -1.0f; diff --git a/cocos/audio/android/AudioEngine-inl.cpp b/cocos/audio/android/AudioEngine-inl.cpp index 267bdcdfdb..7783cd3f5c 100644 --- a/cocos/audio/android/AudioEngine-inl.cpp +++ b/cocos/audio/android/AudioEngine-inl.cpp @@ -39,6 +39,7 @@ #include using namespace cocos2d; +using namespace cocos2d::experimental; void PlayOverEvent(SLPlayItf caller, void* context, SLuint32 playEvent) { diff --git a/cocos/audio/android/AudioEngine-inl.h b/cocos/audio/android/AudioEngine-inl.h index bf9f7a7773..ee23f955e4 100644 --- a/cocos/audio/android/AudioEngine-inl.h +++ b/cocos/audio/android/AudioEngine-inl.h @@ -37,7 +37,7 @@ #define ERRORLOG(msg) log("fun:%s,line:%d,msg:%s",__func__,__LINE__,#msg) NS_CC_BEGIN - + namespace experimental{ class AudioEngineImpl; class AudioPlayer @@ -102,7 +102,7 @@ private: }; #endif // __AUDIO_ENGINE_INL_H_ - + } NS_CC_END #endif diff --git a/cocos/audio/include/AudioEngine.h b/cocos/audio/include/AudioEngine.h index a3663b0868..8501000b02 100644 --- a/cocos/audio/include/AudioEngine.h +++ b/cocos/audio/include/AudioEngine.h @@ -36,6 +36,7 @@ #endif // ERROR NS_CC_BEGIN + namespace experimental{ class EXPORT_DLL AudioProfile { @@ -265,6 +266,7 @@ protected: friend class AudioEngineImpl; }; +} NS_CC_END #endif // __AUDIO_ENGINE_H_ diff --git a/cocos/audio/ios/AudioEngine-inl.h b/cocos/audio/ios/AudioEngine-inl.h index 1f67978435..78f7dd161e 100644 --- a/cocos/audio/ios/AudioEngine-inl.h +++ b/cocos/audio/ios/AudioEngine-inl.h @@ -33,7 +33,7 @@ #include "AudioPlayer.h" NS_CC_BEGIN - + namespace experimental{ #define MAX_AUDIOINSTANCES 32 class AudioEngineThreadPool; @@ -88,6 +88,7 @@ private: int _currentAudioID; }; +} NS_CC_END #endif // __AUDIO_ENGINE_INL_H_ #endif diff --git a/cocos/audio/ios/AudioEngine-inl.mm b/cocos/audio/ios/AudioEngine-inl.mm index e81ade8588..f293cba0f5 100644 --- a/cocos/audio/ios/AudioEngine-inl.mm +++ b/cocos/audio/ios/AudioEngine-inl.mm @@ -31,6 +31,7 @@ #include "base/ccUtils.h" using namespace cocos2d; +using namespace cocos2d::experimental; static ALCdevice *s_ALDevice = nullptr; static ALCcontext *s_ALContext = nullptr; diff --git a/cocos/scripting/lua-bindings/manual/audioengine/lua_cocos2dx_audioengine_manual.cpp b/cocos/scripting/lua-bindings/manual/audioengine/lua_cocos2dx_audioengine_manual.cpp index b2771dda7a..0a1c9df9e2 100644 --- a/cocos/scripting/lua-bindings/manual/audioengine/lua_cocos2dx_audioengine_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/audioengine/lua_cocos2dx_audioengine_manual.cpp @@ -31,14 +31,14 @@ static int lua_get_AudioProfile_name(lua_State* L) { - cocos2d::AudioProfile* self = nullptr; + cocos2d::experimental::AudioProfile* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror; #endif - self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0); + self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { @@ -60,14 +60,14 @@ tolua_lerror: static int lua_set_AudioProfile_name(lua_State* L) { int argc = 0; - cocos2d::AudioProfile* self = nullptr; + cocos2d::experimental::AudioProfile* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror; #endif - self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0); + self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { @@ -99,14 +99,14 @@ tolua_lerror: static int lua_get_AudioProfile_maxInstances(lua_State* L) { - cocos2d::AudioProfile* self = nullptr; + cocos2d::experimental::AudioProfile* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror; #endif - self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0); + self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { @@ -128,14 +128,14 @@ tolua_lerror: static int lua_set_AudioProfile_maxInstances(lua_State* L) { int argc = 0; - cocos2d::AudioProfile* self = nullptr; + cocos2d::experimental::AudioProfile* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror; #endif - self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0); + self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { @@ -167,14 +167,14 @@ tolua_lerror: static int lua_get_AudioProfile_minDelay(lua_State* L) { - cocos2d::AudioProfile* self = nullptr; + cocos2d::experimental::AudioProfile* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror; #endif - self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0); + self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { @@ -196,14 +196,14 @@ tolua_lerror: static int lua_set_AudioProfile_minDelay(lua_State* L) { int argc = 0; - cocos2d::AudioProfile* self = nullptr; + cocos2d::experimental::AudioProfile* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror; #endif - self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0); + self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { @@ -243,7 +243,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"cc.AudioEngine",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"ccexp.AudioEngine",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -251,7 +251,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S) if (argc == 2) { int arg0; - ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.AudioEngine:setFinishCallback"); + ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccexp.AudioEngine:setFinishCallback"); #if COCOS2D_DEBUG >= 1 if (!toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err)) @@ -262,7 +262,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S) LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0)); - cocos2d::AudioEngine::setFinishCallback(arg0, [handler](int audioID, std::string filePath){ + cocos2d::experimental::AudioEngine::setFinishCallback(arg0, [handler](int audioID, std::string filePath){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushInt(audioID); @@ -275,7 +275,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S) return 0; } - CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "cc.AudioEngine:setFinishCallback",argc, 2); + CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.AudioEngine:setFinishCallback",argc, 2); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: @@ -292,7 +292,7 @@ int register_audioengine_module(lua_State* L) register_all_cocos2dx_audioengine(L); if (L) { - lua_pushstring(L, "cc.AudioProfile"); + lua_pushstring(L, "ccexp.AudioProfile"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -302,7 +302,7 @@ int register_audioengine_module(lua_State* L) } lua_pop(L, 1); - lua_pushstring(L, "cc.AudioEngine"); + lua_pushstring(L, "ccexp.AudioEngine"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { diff --git a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp index dcdd6d065e..d7163a2974 100644 --- a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp +++ b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp @@ -25,7 +25,9 @@ #include "NewAudioEngineTest.h" #include "ui/CocosGUI.h" +using namespace cocos2d; using namespace cocos2d::ui; +using namespace cocos2d::experimental; namespace { @@ -166,7 +168,7 @@ Layer* restartAction() bool _enabled; }; - class SliderEx : public ui::Slider + class SliderEx : public Slider { public: enum class TouchEvent diff --git a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h index 71cf0bafa4..9137c207c0 100644 --- a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h +++ b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.h @@ -111,7 +111,7 @@ public: private: static const int FILE_COUNT = 4; std::string _files[FILE_COUNT]; - AudioProfile _audioProfile; + cocos2d::experimental::AudioProfile _audioProfile; int _audioCount; Label* _showLabel; diff --git a/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua b/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua index ff13e13201..e8a54bff3b 100644 --- a/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua +++ b/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua @@ -123,7 +123,7 @@ function AudioControlTest.create() ------playItem local function playAudio(tag, sender) if AudioControlTest._audioID == cc.AUDIO_INVAILD_ID then - AudioControlTest._audioID = cc.AudioEngine:play2d("background.mp3", AudioControlTest._loopEnabled, AudioControlTest._volume) + AudioControlTest._audioID = ccexp.AudioEngine:play2d("background.mp3", AudioControlTest._loopEnabled, AudioControlTest._volume) if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then AudioControlTest._playItem:setEnabled(false) @@ -133,7 +133,7 @@ function AudioControlTest.create() AudioControlTest._playItem:setEnabled(true) end - cc.AudioEngine:setFinishCallback(AudioControlTest._audioID,finishCallback) + ccexp.AudioEngine:setFinishCallback(AudioControlTest._audioID,finishCallback) end end end @@ -145,7 +145,7 @@ function AudioControlTest.create() ------stopItem local function stopAudio(tag, sender) if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then - cc.AudioEngine:stop(AudioControlTest._audioID) + ccexp.AudioEngine:stop(AudioControlTest._audioID) AudioControlTest._audioID = cc.AUDIO_INVAILD_ID AudioControlTest._playItem:setEnabled(true) end @@ -158,7 +158,7 @@ function AudioControlTest.create() ------pauseItem local function pauseAudio(tag, sender) if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then - cc.AudioEngine:pause(AudioControlTest._audioID) + ccexp.AudioEngine:pause(AudioControlTest._audioID) end end @@ -169,7 +169,7 @@ function AudioControlTest.create() ------resumeItem local function resumeAudio(tag, sender) if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then - cc.AudioEngine:resume(AudioControlTest._audioID) + ccexp.AudioEngine:resume(AudioControlTest._audioID) end end @@ -181,7 +181,7 @@ function AudioControlTest.create() local function switchLoop(tag, sender) AudioControlTest._loopEnabled = not AudioControlTest._loopEnabled if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then - cc.AudioEngine:setLoop(AudioControlTest._audioID, AudioControlTest._loopEnabled) + ccexp.AudioEngine:setLoop(AudioControlTest._audioID, AudioControlTest._loopEnabled) end if AudioControlTest._loopEnabled then AudioControlTest.loopItem:setString("disable-loop") @@ -196,7 +196,7 @@ function AudioControlTest.create() ------uncacheItem local function uncache(tag, sender) - cc.AudioEngine:uncache("background.mp3") + ccexp.AudioEngine:uncache("background.mp3") AudioControlTest._audioID = cc.AUDIO_INVAILD_ID AudioControlTest._playItem:setEnabled(true) end @@ -218,7 +218,7 @@ function AudioControlTest.create() local function volumeSliderChangedEvent(sender,eventType) AudioControlTest._volume = sender:getPercent() / 100.0 if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then - cc.AudioEngine:setVolume(AudioControlTest._audioID, AudioControlTest._volume) + ccexp.AudioEngine:setVolume(AudioControlTest._audioID, AudioControlTest._volume) end end local volumeSlider = ccui.Slider:create() @@ -247,7 +247,7 @@ function AudioControlTest.create() AudioControlTest._updateTimeSlider = false else if (AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID and AudioControlTest._duration ~= cc.AUDIO_TIME_UNKNOWN) then - cc.AudioEngine:setCurrentTime(AudioControlTest._audioID,AudioControlTest._duration * ratio) + ccexp.AudioEngine:setCurrentTime(AudioControlTest._audioID,AudioControlTest._duration * ratio) end AudioControlTest._updateTimeSlider = true end @@ -261,10 +261,10 @@ function AudioControlTest.create() local function step(dt) if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then if AudioControlTest._duration == cc.AUDIO_TIME_UNKNOWN then - AudioControlTest._duration = cc.AudioEngine:getDuration(AudioControlTest._audioID) + AudioControlTest._duration = ccexp.AudioEngine:getDuration(AudioControlTest._audioID) end if AudioControlTest._duration ~= cc.AUDIO_TIME_UNKNOWN then - local time = cc.AudioEngine:getCurrentTime(AudioControlTest._audioID) + local time = ccexp.AudioEngine:getCurrentTime(AudioControlTest._audioID) AudioControlTest._timeRatio = time / AudioControlTest._duration if AudioControlTest._updateTimeSlider then AudioControlTest._timeSlider:setRatio(AudioControlTest._timeRatio) @@ -277,7 +277,7 @@ function AudioControlTest.create() function onNodeEvent(tag) if tag == "exit" then - cc.AudioEngine:stopAll() + ccexp.AudioEngine:stopAll() end end layer:registerScriptHandler(onNodeEvent) @@ -302,7 +302,7 @@ function PlaySimultaneouslyTest.create() local audioID = cc.AUDIO_INVAILD_ID --for k, v in pairs(PlaySimultaneouslyTest.files) do for index=1,10 do - audioID = cc.AudioEngine:play2d(PlaySimultaneouslyTest.files[index]) + audioID = ccexp.AudioEngine:play2d(PlaySimultaneouslyTest.files[index]) if audioID ~= cc.AUDIO_INVAILD_ID then PlaySimultaneouslyTest._playItem:setEnabled(false) @@ -315,7 +315,7 @@ function PlaySimultaneouslyTest.create() end end - cc.AudioEngine:setFinishCallback(audioID,finishCallback) + ccexp.AudioEngine:setFinishCallback(audioID,finishCallback) end end end @@ -330,7 +330,7 @@ function PlaySimultaneouslyTest.create() function onNodeEvent(tag) if tag == "exit" then - cc.AudioEngine:stopAll() + ccexp.AudioEngine:stopAll() end end layer:registerScriptHandler(onNodeEvent) @@ -358,7 +358,7 @@ function AudioProfileTest.create() AudioProfileTest._files[3] = "background.wav" AudioProfileTest._files[4] = "pew-pew-lei.wav" - AudioProfileTest._profile = cc.AudioProfile:new() + AudioProfileTest._profile = ccexp.AudioProfile:new() AudioProfileTest._profile.name = "AudioProfileTest" AudioProfileTest._profile.maxInstances = 3 AudioProfileTest._profile.minDelay = 1.0 @@ -374,7 +374,7 @@ function AudioProfileTest.create() local heightRatio = 0.7 for index=1,4 do local function itemClickCallback(tag, sender) - local audioID = cc.AudioEngine:play2d(AudioProfileTest._files[tag],false,1.0,AudioProfileTest._profile) + local audioID = ccexp.AudioEngine:play2d(AudioProfileTest._files[tag],false,1.0,AudioProfileTest._profile) if audioID ~= cc.AUDIO_INVAILD_ID then AudioProfileTest._time = AudioProfileTest._minDelay AudioProfileTest._audioCount = AudioProfileTest._audioCount + 1 @@ -385,7 +385,7 @@ function AudioProfileTest.create() AudioProfileTest._showLabel:setString(string.format("audio count:%d",AudioProfileTest._audioCount)) end - cc.AudioEngine:setFinishCallback(audioID,finishCallback) + ccexp.AudioEngine:setFinishCallback(audioID,finishCallback) end end @@ -431,7 +431,7 @@ function AudioProfileTest.create() function onNodeEvent(tag) if tag == "exit" then - cc.AudioEngine:stopAll() + ccexp.AudioEngine:stopAll() end end layer:registerScriptHandler(onNodeEvent) @@ -452,10 +452,10 @@ function InvalidAudioFileTest.create() local function playUnsupportedAudio(tag, sender) local targetPlatform = cc.Application:getInstance():getTargetPlatform() if (cc.PLATFORM_OS_IPHONE == targetPlatform or cc.PLATFORM_OS_IPAD == targetPlatform) then - cc.AudioEngine:play2d("background.ogg") + ccexp.AudioEngine:play2d("background.ogg") end if (cc.PLATFORM_OS_ANDROID == targetPlatform) then - cc.AudioEngine:play2d("background.caf") + ccexp.AudioEngine:play2d("background.caf") end end @@ -465,7 +465,7 @@ function InvalidAudioFileTest.create() -- not-existent audio local function playNotExistentAudio(tag, sender) - cc.AudioEngine:play2d("not-existent file.mp3") + ccexp.AudioEngine:play2d("not-existent file.mp3") end local playItem2 = cc.MenuItemFont:create("play not-existent file") @@ -490,7 +490,7 @@ function LargeAudioFileTest.create() local layerSize = layer:getContentSize() local function playAudio(tag, sender) - cc.AudioEngine:play2d("audio/Chee Lai(Arise).mp3") + ccexp.AudioEngine:play2d("audio/Chee Lai(Arise).mp3") end local playItem = cc.MenuItemFont:create("play large audio file") @@ -503,7 +503,7 @@ function LargeAudioFileTest.create() function onNodeEvent(tag) if tag == "exit" then - cc.AudioEngine:stopAll() + ccexp.AudioEngine:stopAll() end end layer:registerScriptHandler(onNodeEvent) diff --git a/tools/tolua/cocos2dx_audioengine.ini b/tools/tolua/cocos2dx_audioengine.ini index 345a5bd3a3..0bacd53a73 100644 --- a/tools/tolua/cocos2dx_audioengine.ini +++ b/tools/tolua/cocos2dx_audioengine.ini @@ -5,7 +5,7 @@ prefix = cocos2dx_audioengine # create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) # all classes will be embedded in that namespace -target_namespace = cc +target_namespace = ccexp android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include android_flags = -D_SIZE_T_DEFINED_ From 369c14ed498bca4f07989406982f2e250714eeb4 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Tue, 16 Sep 2014 14:57:58 +0800 Subject: [PATCH 2/2] fix compile error --- cocos/audio/ios/AudioCache.h | 2 + cocos/audio/ios/AudioCache.mm | 1 + cocos/audio/ios/AudioEngine-inl.mm | 150 +++++++++++++++-------------- cocos/audio/ios/AudioPlayer.h | 4 + cocos/audio/ios/AudioPlayer.mm | 1 + 5 files changed, 84 insertions(+), 74 deletions(-) diff --git a/cocos/audio/ios/AudioCache.h b/cocos/audio/ios/AudioCache.h index 603350e507..ca4e81b64f 100644 --- a/cocos/audio/ios/AudioCache.h +++ b/cocos/audio/ios/AudioCache.h @@ -39,6 +39,7 @@ #define QUEUEBUFFER_TIME_STEP 0.1 NS_CC_BEGIN +namespace experimental{ class AudioEngineImpl; class AudioPlayer; @@ -91,6 +92,7 @@ private: friend class AudioPlayer; } ; +} NS_CC_END #endif // __AUDIO_CACHE_H_ diff --git a/cocos/audio/ios/AudioCache.mm b/cocos/audio/ios/AudioCache.mm index 72dd5ac794..bb8fae552f 100644 --- a/cocos/audio/ios/AudioCache.mm +++ b/cocos/audio/ios/AudioCache.mm @@ -44,6 +44,7 @@ static ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* da return; } using namespace cocos2d; +using namespace cocos2d::experimental; AudioCache::AudioCache() : _pcmData(nullptr) diff --git a/cocos/audio/ios/AudioEngine-inl.mm b/cocos/audio/ios/AudioEngine-inl.mm index f293cba0f5..98868ff1dd 100644 --- a/cocos/audio/ios/AudioEngine-inl.mm +++ b/cocos/audio/ios/AudioEngine-inl.mm @@ -48,88 +48,90 @@ static void AudioInterrupionListenerCallback(void* user_data, UInt32 interruptio } namespace cocos2d { - class AudioEngineThreadPool - { - public: - AudioEngineThreadPool() - : _running(true) - , _numThread(6) + namespace experimental { + class AudioEngineThreadPool { - _threads.reserve(_numThread); - _tasks.reserve(_numThread); - - for (int index = 0; index < _numThread; ++index) { - _tasks.push_back(nullptr); - _threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,index) ) ); - } - } - - void addTask(const std::function &task){ - _taskMutex.lock(); - int targetIndex = -1; - for (int index = 0; index < _numThread; ++index) { - if (_tasks[index] == nullptr) { - targetIndex = index; - _tasks[index] = task; - break; + public: + AudioEngineThreadPool() + : _running(true) + , _numThread(6) + { + _threads.reserve(_numThread); + _tasks.reserve(_numThread); + + for (int index = 0; index < _numThread; ++index) { + _tasks.push_back(nullptr); + _threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,index) ) ); } } - if (targetIndex == -1) { - _tasks.push_back(task); - _threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,_numThread) ) ); - - _numThread++; - } - _taskMutex.unlock(); - _sleepCondition.notify_all(); - } - - void destroy() - { - _running = false; - _sleepCondition.notify_all(); - - for (int index = 0; index < _numThread; ++index) { - _threads[index].join(); - } - } - - private: - bool _running; - std::vector _threads; - std::vector< std::function > _tasks; - - void threadFunc(int index) - { - while (_running) { - std::function task = nullptr; + void addTask(const std::function &task){ _taskMutex.lock(); - task = _tasks[index]; - _taskMutex.unlock(); - - if (nullptr == task) - { - std::unique_lock lk(_sleepMutex); - _sleepCondition.wait(lk); - continue; + int targetIndex = -1; + for (int index = 0; index < _numThread; ++index) { + if (_tasks[index] == nullptr) { + targetIndex = index; + _tasks[index] = task; + break; + } + } + if (targetIndex == -1) { + _tasks.push_back(task); + _threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,_numThread) ) ); + + _numThread++; } - - task(); - - _taskMutex.lock(); - _tasks[index] = nullptr; _taskMutex.unlock(); + + _sleepCondition.notify_all(); } - } - - int _numThread; - - std::mutex _taskMutex; - std::mutex _sleepMutex; - std::condition_variable _sleepCondition; - - }; + + void destroy() + { + _running = false; + _sleepCondition.notify_all(); + + for (int index = 0; index < _numThread; ++index) { + _threads[index].join(); + } + } + + private: + bool _running; + std::vector _threads; + std::vector< std::function > _tasks; + + void threadFunc(int index) + { + while (_running) { + std::function task = nullptr; + _taskMutex.lock(); + task = _tasks[index]; + _taskMutex.unlock(); + + if (nullptr == task) + { + std::unique_lock lk(_sleepMutex); + _sleepCondition.wait(lk); + continue; + } + + task(); + + _taskMutex.lock(); + _tasks[index] = nullptr; + _taskMutex.unlock(); + } + } + + int _numThread; + + std::mutex _taskMutex; + std::mutex _sleepMutex; + std::condition_variable _sleepCondition; + + }; + } } AudioEngineImpl::AudioEngineImpl() diff --git a/cocos/audio/ios/AudioPlayer.h b/cocos/audio/ios/AudioPlayer.h index 76d9e3ad31..08e83d13be 100644 --- a/cocos/audio/ios/AudioPlayer.h +++ b/cocos/audio/ios/AudioPlayer.h @@ -32,6 +32,8 @@ #include "CCPlatformMacros.h" NS_CC_BEGIN +namespace experimental{ + class AudioCache; class AudioEngineImpl; @@ -70,6 +72,8 @@ private: friend class AudioEngineImpl; }; + +} NS_CC_END #endif // __AUDIO_PLAYER_H_ #endif diff --git a/cocos/audio/ios/AudioPlayer.mm b/cocos/audio/ios/AudioPlayer.mm index 8053900bc2..36633f676d 100644 --- a/cocos/audio/ios/AudioPlayer.mm +++ b/cocos/audio/ios/AudioPlayer.mm @@ -27,6 +27,7 @@ #import using namespace cocos2d; +using namespace cocos2d::experimental; AudioPlayer::AudioPlayer() : _exitThread(false)