diff --git a/native/cocos/editor-support/MiddlewareManager.cpp b/native/cocos/editor-support/MiddlewareManager.cpp index fd52ba19df3..d3ba2e42022 100644 --- a/native/cocos/editor-support/MiddlewareManager.cpp +++ b/native/cocos/editor-support/MiddlewareManager.cpp @@ -55,15 +55,17 @@ MeshBuffer *MiddlewareManager::getMeshBuffer(int format) { } void MiddlewareManager::updateCache() { - for (auto &iter: _updateMap) { + for (auto &iter: _operateCacheMap) { auto it = std::find(_updateList.begin(), _updateList.end(), iter.first); - if (iter.second && it == _updateList.end()) { - _updateList.push_back(iter.first); - } else if (!iter.second && it != _updateList.end()) { + if (iter.second) { + if (it == _updateList.end()) { + _updateList.push_back(iter.first); + } + } else if (it != _updateList.end()) { _updateList.erase(it); } } - _updateMap.clear(); + _operateCacheMap.clear(); } void MiddlewareManager::update(float dt) { @@ -116,11 +118,11 @@ void MiddlewareManager::render(float dt) { } void MiddlewareManager::addTimer(IMiddleware *editor) { - _updateMap[editor] = true; + _operateCacheMap[editor] = true; } void MiddlewareManager::removeTimer(IMiddleware *editor) { - _updateMap[editor] = false; + _operateCacheMap[editor] = false; } se_object_ptr MiddlewareManager::getVBTypedArray(int format, int bufferPos) { diff --git a/native/cocos/editor-support/MiddlewareManager.h b/native/cocos/editor-support/MiddlewareManager.h index 8f19f63f888..1ddcfab6426 100644 --- a/native/cocos/editor-support/MiddlewareManager.h +++ b/native/cocos/editor-support/MiddlewareManager.h @@ -83,13 +83,13 @@ class MiddlewareManager { void render(float dt); /** - * @brief Third party module add in _updateMap,it will update perframe. + * @brief Mark the add flag to _operateCacheMap, and perform the update in the next frame * @param[in] editor Module must implement IMiddleware interface. */ void addTimer(IMiddleware *editor); /** - * @brief Third party module remove from _updateMap,it will stop update. + * @brief Mark the remove flag to _operateCacheMap, and perform the update in the next frame * @param[in] editor Module must implement IMiddleware interface. */ void removeTimer(IMiddleware *editor); @@ -112,7 +112,7 @@ class MiddlewareManager { void updateCache(); ccstd::vector _updateList; - ccstd::unordered_map _updateMap; + ccstd::unordered_map _operateCacheMap; ccstd::unordered_map _mbMap; SharedBufferManager _renderInfo;