Applying code standard new window, job, jobsystem and imui

This commit is contained in:
Antoine Pilote
2024-09-04 00:51:43 -04:00
parent dc3c993962
commit 10b8c862e7
8 changed files with 585 additions and 587 deletions

View File

@@ -1,27 +1,24 @@
#include "Job.h"
#include <Tracy.hpp>
namespace Nuake {
using namespace Nuake;
Job::Job(std::function<void()> job, std::function<void()> end)
: m_Job(job)
, m_End(end)
Job::Job(std::function<void()> logic, std::function<void()> endLogic) :
job(logic),
end(endLogic)
{
this->thread = std::thread([this, logic]()
{
m_End = end;
ZoneScoped;
job();
isDone = true;
});
}
m_Thread = std::thread([this, job]()
{
ZoneScoped;
job();
m_IsDone = true;
});
}
void Job::End()
void Job::End()
{
if (end)
{
if (m_End)
{
m_End();
}
end();
}
}

View File

@@ -9,17 +9,20 @@ namespace Nuake {
class Job
{
public:
Job(std::function<void()> job, std::function<void()> end);
Job(std::function<void()> logic, std::function<void()> endLogic);
Job(const Job&) = delete;
Job& operator=(const Job&) = delete;
~Job() { m_Thread.join(); }
bool IsDone() { return m_IsDone; }
~Job() { thread.join(); }
public:
bool IsDone() { return isDone; }
void End();
private:
std::thread m_Thread;
std::atomic<bool> m_IsDone;
std::function<void()> m_Job;
std::function<void()> m_End;
std::thread thread;
std::atomic<bool> isDone;
std::function<void()> job;
std::function<void()> end;
};
}

View File

@@ -2,23 +2,22 @@
#include <Tracy.hpp>
namespace Nuake {
using namespace Nuake;
void JobSystem::Update()
void JobSystem::Update()
{
ZoneScoped;
for(auto it = jobs.begin(); it != jobs.end();)
{
ZoneScoped;
for(auto it = m_Jobs.begin(); it != m_Jobs.end();)
if(it->get()->IsDone())
{
if(it->get()->IsDone())
{
it->get()->End();
it = m_Jobs.erase(it);
}
else
{
++it;
}
it->get()->End();
it = jobs.erase(it);
}
else
{
++it;
}
}
}

View File

@@ -5,11 +5,7 @@ namespace Nuake {
class JobSystem
{
private:
std::vector<std::unique_ptr<Job>> m_Jobs;
public:
JobSystem() = default;
~JobSystem() = default;
@@ -19,11 +15,15 @@ namespace Nuake {
return instance;
}
public:
void Dispatch(std::function<void()> job, std::function<void()> end)
{
m_Jobs.push_back(std::make_unique<Job>(job, end));
jobs.push_back(std::make_unique<Job>(job, end));
}
void Update();
private:
std::vector<std::unique_ptr<Job>> jobs;
};
}