Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Nov 23, 2023
1 parent fa63a0b commit 06e1e0e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/framework/graphics/drawpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ class DrawPool

std::vector<Matrix3> m_transformMatrixStack;
std::vector<FrameBufferPtr> m_temporaryFramebuffers;

std::vector<DrawObject> m_objects[MAX_DRAW_DEPTH + 1][static_cast<uint8_t>(DrawOrder::LAST)];
std::vector<DrawObject> m_objectsDraw;

stdext::map<size_t, CoordsBuffer*> m_coords;

Expand Down
67 changes: 31 additions & 36 deletions src/framework/graphics/drawpoolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,37 @@ 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);
}

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)
Expand Down Expand Up @@ -201,28 +194,30 @@ void DrawPoolManager::preDraw(const DrawPoolType type, const std::function<void(
select(type);
const auto pool = getCurrentPool();

if (pool->isStatus(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<uint8_t>(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);
}
}

0 comments on commit 06e1e0e

Please sign in to comment.