From 6626655308df16b551a01e8c6d20079220402a56 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Fri, 26 Sep 2014 09:36:43 +0800 Subject: [PATCH 1/3] move render logic from Director to scene --- cocos/2d/CCScene.cpp | 39 +++++++++++++++++++++++++++++++++++++++ cocos/2d/CCScene.h | 5 ++++- cocos/base/CCDirector.cpp | 37 ++----------------------------------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index 1d1688c4d6..8672741d00 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -30,6 +30,7 @@ THE SOFTWARE. #include "base/CCCamera.h" #include "base/CCEventDispatcher.h" #include "base/CCEventListenerCustom.h" +#include "renderer/CCRenderer.h" #include "deprecated/CCString.h" #if CC_USE_PHYSICS @@ -124,6 +125,44 @@ void Scene::onProjectionChanged(EventCustom* event) } } +void Scene::render(Renderer* renderer) +{ + auto director = Director::getInstance(); + Camera* defaultCamera = nullptr; + for (const auto& camera : _cameras) + { + Camera::_visitingCamera = camera; + if (Camera::_visitingCamera->getCameraFlag() == CameraFlag::DEFAULT) + { + defaultCamera = Camera::_visitingCamera; + continue; + } + + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix()); + + //visit the scene + visit(renderer, Mat4::IDENTITY, 0); + renderer->render(); + + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + } + //draw with default camera + if (defaultCamera) + { + Camera::_visitingCamera = defaultCamera; + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix()); + + //visit the scene + visit(renderer, Mat4::IDENTITY, 0); + renderer->render(); + + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + } + Camera::_visitingCamera = nullptr; +} + #if CC_USE_PHYSICS void Scene::addChild(Node* child, int zOrder, int tag) { diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index 64b9287c2d..0533389af8 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -34,6 +34,7 @@ THE SOFTWARE. NS_CC_BEGIN class Camera; +class Renderer; class EventListenerCustom; class EventCustom; #if CC_USE_PHYSICS @@ -72,6 +73,9 @@ public: /** get all cameras */ const std::vector& getCameras() const { return _cameras; } + /** render the scene */ + void render(Renderer* renderer); + CC_CONSTRUCTOR_ACCESS: Scene(); virtual ~Scene(); @@ -86,7 +90,6 @@ protected: friend class ProtectedNode; friend class SpriteBatchNode; friend class Camera; - friend class Director; friend class Renderer; std::vector _cameras; //weak ref to Camera diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 90ec7ed85d..d4a90c6080 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -287,41 +287,8 @@ void Director::drawScene() //clear draw stats _renderer->clearDrawStats(); - Camera* defaultCamera = nullptr; - const auto& cameras = _runningScene->_cameras; - //draw with camera - for (size_t i = 0; i < cameras.size(); i++) - { - Camera::_visitingCamera = cameras[i]; - if (Camera::_visitingCamera->getCameraFlag() == CameraFlag::DEFAULT) - { - defaultCamera = Camera::_visitingCamera; - continue; - } - - pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); - loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix()); - - //visit the scene - _runningScene->visit(_renderer, Mat4::IDENTITY, 0); - _renderer->render(); - - popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); - } - //draw with default camera - if (defaultCamera) - { - Camera::_visitingCamera = defaultCamera; - pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); - loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix()); - - //visit the scene - _runningScene->visit(_renderer, Mat4::IDENTITY, 0); - _renderer->render(); - - popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); - } - Camera::_visitingCamera = nullptr; + //render the scene + _runningScene->render(_renderer); _eventDispatcher->dispatchEvent(_eventAfterVisit); } From 87c04a3e5d7b8d6d760b20154c370b210f8359ea Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Fri, 26 Sep 2014 07:00:12 +0000 Subject: [PATCH 2/3] [AUTO][ci skip]: updating cocos2dx_files.json --- templates/cocos2dx_files.json | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index eef8e80084..fc7d272e38 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -3634,6 +3634,7 @@ "cocos/scripting/lua-bindings/auto/api/ControlSwitch.lua", "cocos/scripting/lua-bindings/auto/api/Controller.lua", "cocos/scripting/lua-bindings/auto/api/DelayTime.lua", + "cocos/scripting/lua-bindings/auto/api/Device.lua", "cocos/scripting/lua-bindings/auto/api/Director.lua", "cocos/scripting/lua-bindings/auto/api/DisplayData.lua", "cocos/scripting/lua-bindings/auto/api/DisplayManager.lua", From 2ac96ed06e7b67b072da6650e514a66f3facbce2 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Fri, 26 Sep 2014 16:39:54 +0800 Subject: [PATCH 3/3] Fix the lua-tests compile error and some bugs in the NewAudioEngineTest and update cocos2dx_audioengine.ini to support macro_judgement --- .../cocos2d_lua_bindings.xcodeproj/project.pbxproj | 8 ++++++++ .../src/NewAudioEngineTest/NewAudioEngineTest.lua | 6 +++--- tools/tolua/cocos2dx_audioengine.ini | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj index 0bf19a511a..85095f3068 100644 --- a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 150906F019D556C5002C4D97 /* lua_cocos2dx_audioengine_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDB0319C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.cpp */; }; + 150906F119D556C8002C4D97 /* lua_cocos2dx_audioengine_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3E2BDB0419C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.hpp */; }; + 150906F219D556CE002C4D97 /* lua_cocos2dx_audioengine_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDB0819C5E6100055CDCD /* lua_cocos2dx_audioengine_manual.cpp */; }; + 150906F319D556D1002C4D97 /* lua_cocos2dx_audioengine_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E2BDB0919C5E6100055CDCD /* lua_cocos2dx_audioengine_manual.h */; }; 15415A7019A71768004F1E71 /* lua_cocos2dx_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */; }; 15415A7119A71782004F1E71 /* lua_cocos2dx_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */; }; 15415A7219A718FB004F1E71 /* lua_cocos2dx_3d_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1516227F19A0F3E3006099B8 /* lua_cocos2dx_3d_auto.cpp */; }; @@ -749,6 +753,7 @@ 15AC69E01987711400D17520 /* luaconf.h in Headers */, 155C7DF819A71C4400F08B25 /* lua_cocos2dx_cocosdenshion_manual.h in Headers */, 15415AAF19A71A53004F1E71 /* except.h in Headers */, + 150906F319D556D1002C4D97 /* lua_cocos2dx_audioengine_manual.h in Headers */, 155C7E0419A71C6D00F08B25 /* lua_cocos2dx_cocosbuilder_manual.h in Headers */, 15415ACB19A71A53004F1E71 /* socket.h in Headers */, 15415ADF19A71A53004F1E71 /* usocket.h in Headers */, @@ -784,6 +789,7 @@ 15415AC719A71A53004F1E71 /* select.h in Headers */, 155C7E1C19A71CC200F08B25 /* lua_cocos2dx_spine_manual.hpp in Headers */, 15C1C2D41987499F00A46ACC /* lua_cocos2dx_auto.hpp in Headers */, + 150906F119D556C8002C4D97 /* lua_cocos2dx_audioengine_auto.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -921,6 +927,7 @@ files = ( 15415A7219A718FB004F1E71 /* lua_cocos2dx_3d_auto.cpp in Sources */, 15415A7319A718FB004F1E71 /* lua_cocos2dx_cocosbuilder_auto.cpp in Sources */, + 150906F219D556CE002C4D97 /* lua_cocos2dx_audioengine_manual.cpp in Sources */, 15415A7519A718FB004F1E71 /* lua_cocos2dx_experimental_video_auto.cpp in Sources */, 15415A7619A718FB004F1E71 /* lua_cocos2dx_ui_auto.cpp in Sources */, 15415A7719A718FB004F1E71 /* lua_cocos2dx_spine_auto.cpp in Sources */, @@ -962,6 +969,7 @@ 15C1C2CE1987498B00A46ACC /* LuaOpengl.cpp in Sources */, 566F015F19B5EB0F00FCA620 /* CustomGUIReader.cpp in Sources */, 15415AC119A71A53004F1E71 /* options.c in Sources */, + 150906F019D556C5002C4D97 /* lua_cocos2dx_audioengine_auto.cpp in Sources */, 155C7E0A19A71C8B00F08B25 /* lua_cocos2dx_network_manual.cpp in Sources */, 15415AD119A71A53004F1E71 /* timeout.c in Sources */, 15C1C2CF1987498B00A46ACC /* lua_cocos2dx_deprecated.cpp in Sources */, diff --git a/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua b/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua index c587e8a85e..d737b8a29c 100644 --- a/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua +++ b/tests/lua-tests/src/NewAudioEngineTest/NewAudioEngineTest.lua @@ -350,7 +350,7 @@ function AudioProfileTest.create() AudioProfileTest._files = {} AudioProfileTest._files[1] = "background.mp3" local targetPlatform = cc.Application:getInstance():getTargetPlatform() - if (cc.PLATFORM_OS_MAC == currPlatform or cc.PLATFORM_OS_IPHONE == targetPlatform or cc.PLATFORM_OS_IPAD == targetPlatform) then + if (cc.PLATFORM_OS_MAC == targetPlatform or cc.PLATFORM_OS_IPHONE == targetPlatform or cc.PLATFORM_OS_IPAD == targetPlatform) then AudioProfileTest._files[2] = "background.caf" elseif (cc.PLATFORM_OS_ANDROID == targetPlatform) then AudioProfileTest._files[2] = "background.ogg" @@ -388,7 +388,7 @@ function AudioProfileTest.create() ccexp.AudioEngine:setFinishCallback(audioID,finishCallback) end end - + local item = cc.MenuItemFont:create("play "..AudioProfileTest._files[index]) item:setFontSizeObj(20) item:setPosition(cc.p(layerSize.width * 0.5,layerSize.height * heightRatio)) @@ -490,7 +490,7 @@ function LargeAudioFileTest.create() local layerSize = layer:getContentSize() local function playAudio(tag, sender) - ccexp.AudioEngine:play2d("audio/Chee Lai(Arise).mp3") + ccexp.AudioEngine:play2d("audio/LuckyDay.mp3") end local playItem = cc.MenuItemFont:create("play large audio file") diff --git a/tools/tolua/cocos2dx_audioengine.ini b/tools/tolua/cocos2dx_audioengine.ini index 0bacd53a73..2f608e0d8f 100644 --- a/tools/tolua/cocos2dx_audioengine.ini +++ b/tools/tolua/cocos2dx_audioengine.ini @@ -7,6 +7,8 @@ prefix = cocos2dx_audioengine # all classes will be embedded in that namespace target_namespace = ccexp +macro_judgement = #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC + 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_