From a7f5d9c150a00019278a4b126f13402b8fc8ee9e Mon Sep 17 00:00:00 2001 From: owen <1053210246@qq.com> Date: Mon, 24 Jun 2019 16:44:44 +0800 Subject: [PATCH] Native optimize --- native/cocos/renderer/scene/MemPool.cpp | 4 +- native/cocos/renderer/scene/NodeProxy.cpp | 3 +- native/cocos/renderer/scene/RenderFlow.cpp | 89 +++++++++++----------- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/native/cocos/renderer/scene/MemPool.cpp b/native/cocos/renderer/scene/MemPool.cpp index a07417da43..c191039717 100644 --- a/native/cocos/renderer/scene/MemPool.cpp +++ b/native/cocos/renderer/scene/MemPool.cpp @@ -116,8 +116,6 @@ void MemPool::removeCommonData(std::size_t unitID) auto unit = _commonPool[unitID]; if (unit) { - delete unit; - _commonPool[unitID] = nullptr; for (auto it = _commonList.begin(); it != _commonList.end(); it++) { if ((*it)->unitID == unitID) @@ -126,6 +124,8 @@ void MemPool::removeCommonData(std::size_t unitID) break; } } + delete unit; + _commonPool[unitID] = nullptr; } } diff --git a/native/cocos/renderer/scene/NodeProxy.cpp b/native/cocos/renderer/scene/NodeProxy.cpp index fab560ce83..c4885772b8 100644 --- a/native/cocos/renderer/scene/NodeProxy.cpp +++ b/native/cocos/renderer/scene/NodeProxy.cpp @@ -448,8 +448,7 @@ void NodeProxy::visitAsRoot(ModelBatcher* batcher, Scene* scene) { _worldMatDirty = 0; _parentOpacityDirty = 0; - // visitWithoutTransform(batcher, scene); - visit(batcher, scene); + visitWithoutTransform(batcher, scene); } void NodeProxy::visitWithoutTransform(ModelBatcher* batcher, Scene* scene) diff --git a/native/cocos/renderer/scene/RenderFlow.cpp b/native/cocos/renderer/scene/RenderFlow.cpp index 014f9f848f..0cc6da3b9d 100644 --- a/native/cocos/renderer/scene/RenderFlow.cpp +++ b/native/cocos/renderer/scene/RenderFlow.cpp @@ -243,51 +243,50 @@ void RenderFlow::render(NodeProxy* scene) { if (scene != nullptr) { - -//#if SUB_RENDER_THREAD_COUNT > 0 -// -// int mainThreadTid = RENDER_THREAD_COUNT - 1; -// bool threadBegan = false; -// -// NodeMemPool* instance = NodeMemPool::getInstance(); -// auto& commonList = instance->getCommonList(); -// if (commonList.size() < LocalMat_Use_Thread_Unit_Count) -// { -// calculateLocalMatrix(); -// } -// else -// { -// _parallelStage = ParallelStage::LOCAL_MAT; -// _paralleTask->begin(); -// threadBegan = true; -// -// calculateLocalMatrix(mainThreadTid); -// while(*_runFlag != ParallelTask::RunFlag::ProcessFinished) std::this_thread::yield(); -// } -// -// _parallelStage = ParallelStage::WORLD_MAT; -// _curLevel = 0; -// for(auto count = _levelInfoArr.size(); _curLevel < count; _curLevel++) -// { -// auto& levelInfos = _levelInfoArr[_curLevel]; -// if (levelInfos.size() < WorldMat_Use_Thread_Node_count) -// { -// calculateLevelWorldMatrix(); -// } -// else -// { -// if (!threadBegan) _paralleTask->begin(); -// *_runFlag = ParallelTask::RunFlag::ToProcess; -// calculateLevelWorldMatrix(mainThreadTid); -// while(*_runFlag != ParallelTask::RunFlag::ProcessFinished) std::this_thread::yield(); -// } -// } -// -// if (threadBegan) _paralleTask->stop(); -//#else -// calculateLocalMatrix(); -// calculateWorldMatrix(); -//#endif +#if SUB_RENDER_THREAD_COUNT > 0 + + int mainThreadTid = RENDER_THREAD_COUNT - 1; + bool threadBegan = false; + + NodeMemPool* instance = NodeMemPool::getInstance(); + auto& commonList = instance->getCommonList(); + if (commonList.size() < LocalMat_Use_Thread_Unit_Count) + { + calculateLocalMatrix(); + } + else + { + _parallelStage = ParallelStage::LOCAL_MAT; + _paralleTask->begin(); + threadBegan = true; + + calculateLocalMatrix(mainThreadTid); + while(*_runFlag != ParallelTask::RunFlag::ProcessFinished) std::this_thread::yield(); + } + + _parallelStage = ParallelStage::WORLD_MAT; + _curLevel = 0; + for(auto count = _levelInfoArr.size(); _curLevel < count; _curLevel++) + { + auto& levelInfos = _levelInfoArr[_curLevel]; + if (levelInfos.size() < WorldMat_Use_Thread_Node_count) + { + calculateLevelWorldMatrix(); + } + else + { + if (!threadBegan) _paralleTask->begin(); + *_runFlag = ParallelTask::RunFlag::ToProcess; + calculateLevelWorldMatrix(mainThreadTid); + while(*_runFlag != ParallelTask::RunFlag::ProcessFinished) std::this_thread::yield(); + } + } + + if (threadBegan) _paralleTask->stop(); +#else + calculateLocalMatrix(); + calculateWorldMatrix(); +#endif _batcher->startBatch(); scene->visitAsRoot(_batcher, _scene);