From 06e1e0ebe9b5c775ef0f174391ca23ceae9f8843 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 23 Nov 2023 19:28:35 -0300 Subject: [PATCH] improve --- src/framework/graphics/drawpool.h | 2 + src/framework/graphics/drawpoolmanager.cpp | 67 ++++++++++------------ 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/framework/graphics/drawpool.h b/src/framework/graphics/drawpool.h index bf0eca31e2..9781f0d3d3 100644 --- a/src/framework/graphics/drawpool.h +++ b/src/framework/graphics/drawpool.h @@ -259,7 +259,9 @@ class DrawPool std::vector m_transformMatrixStack; std::vector m_temporaryFramebuffers; + std::vector m_objects[MAX_DRAW_DEPTH + 1][static_cast(DrawOrder::LAST)]; + std::vector m_objectsDraw; stdext::map m_coords; diff --git a/src/framework/graphics/drawpoolmanager.cpp b/src/framework/graphics/drawpoolmanager.cpp index b6707abdb8..75aefa6b83 100644 --- a/src/framework/graphics/drawpoolmanager.cpp +++ b/src/framework/graphics/drawpoolmanager.cpp @@ -65,33 +65,27 @@ void DrawPoolManager::draw() void DrawPoolManager::drawPool(const DrawPoolType type) { const auto pool = get(type); + std::scoped_lock l(pool->m_mutex); + if (!pool->isEnabled()) return; bool canDraw = false; - { - std::scoped_lock l(pool->m_mutex); - if (!pool->hasFrameBuffer()) { - for (const auto& obj : pool->m_objects[0][DrawOrder::FIRST]) { - drawObject(obj); - } - return; + if (!pool->hasFrameBuffer()) { + for (const auto& obj : pool->m_objectsDraw) { + drawObject(obj); } - canDraw = pool->m_framebuffer->canDraw(); + return; } + canDraw = pool->m_framebuffer->canDraw(); if (!canDraw) return; if (pool->isStatus(DrawPool::DrawStatus::CAN_REPAINT)) { - std::scoped_lock l(pool->m_mutex); - pool->m_drawStatus.store(DrawPool::DrawStatus::DRAWING); pool->m_framebuffer->bind(); - for (int_fast8_t i = -1; ++i <= pool->m_depthLevel;) { - for (const auto& order : pool->m_objects[i]) - for (const auto& obj : order) - drawObject(obj); - } + for (const auto& obj : pool->m_objectsDraw) + drawObject(obj); pool->m_framebuffer->release(); pool->m_drawStatus.store(DrawPool::DrawStatus::DRAWING_DONE); @@ -99,10 +93,9 @@ void DrawPoolManager::drawPool(const DrawPoolType type) { g_painter->resetState(); - if (pool->m_beforeDraw) pool->m_beforeDraw(); { - std::scoped_lock l(pool->m_mutex); - pool->m_framebuffer->draw(); - }if (pool->m_afterDraw) pool->m_afterDraw(); + if (pool->m_beforeDraw) pool->m_beforeDraw(); + pool->m_framebuffer->draw(); + if (pool->m_afterDraw) pool->m_afterDraw(); } void DrawPoolManager::drawObject(const DrawPool::DrawObject& obj) @@ -201,28 +194,30 @@ void DrawPoolManager::preDraw(const DrawPoolType type, const std::functionisStatus(DrawPool::DrawStatus::DRAWING)) - return; + pool->resetState(); - std::scoped_lock l(pool->m_mutex); - pool->m_drawStatus.store(DrawPool::DrawStatus::PRE_DRAW); - { - pool->setEnable(true); - pool->resetState(); + // when the selected pool is MAP, reset the creature information state. + if (type == DrawPoolType::MAP) { + get(DrawPoolType::CREATURE_INFORMATION)->resetState(); + } - if (pool->hasFrameBuffer()) { - pool->m_framebuffer->prepare(dest, src, colorClear); + if (f) f(); - // when the selected pool is MAP, reset the creature information state. - if (type == DrawPoolType::MAP) { - get(DrawPoolType::CREATURE_INFORMATION)->resetState(); - } - } + std::scoped_lock l(pool->m_mutex); - if (f) - f(); + pool->setEnable(true); + if (pool->m_framebuffer) { + pool->m_framebuffer->prepare(dest, src, colorClear); } - if (pool->canRepaint(true)) + if (pool->canRepaint(true)) { + pool->m_objectsDraw.clear(); + for (int_fast8_t depth = 0; depth <= MAX_DRAW_DEPTH; ++depth) { + for (int_fast8_t order = 0; order < static_cast(DrawOrder::LAST); ++order) { + auto& objs = pool->m_objects[depth][order]; + pool->m_objectsDraw.insert(pool->m_objectsDraw.end(), make_move_iterator(objs.begin()), make_move_iterator(objs.end())); + } + } pool->m_drawStatus.store(DrawPool::DrawStatus::CAN_REPAINT); + } } \ No newline at end of file