Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
bofeng-song committed Dec 12, 2024
1 parent 00a8c6d commit 6caf091
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions native/cocos/editor-support/MiddlewareManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions native/cocos/editor-support/MiddlewareManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -112,7 +112,7 @@ class MiddlewareManager {
void updateCache();

ccstd::vector<IMiddleware *> _updateList;
ccstd::unordered_map<IMiddleware *, bool> _updateMap;
ccstd::unordered_map<IMiddleware *, bool> _operateCacheMap;
ccstd::unordered_map<int, MeshBuffer *> _mbMap;

SharedBufferManager _renderInfo;
Expand Down

0 comments on commit 6caf091

Please sign in to comment.