diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index 8aee034..8407242 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -1,5 +1,6 @@ target_sources(SeeleEngine PRIVATE + EngineTypes.h MinimalEngine.h MinimalEngine.cpp main.cpp) diff --git a/src/Engine/ThreadPool.cpp b/src/Engine/ThreadPool.cpp new file mode 100644 index 0000000..c43b38f --- /dev/null +++ b/src/Engine/ThreadPool.cpp @@ -0,0 +1,20 @@ +#include "ThreadPool.h" + +using namespace Seele; + +static ThreadPool gThreadPool; + +Job JobPromise::get_return_object() noexcept { + return Job { std::coroutine_handle::from_promise(*this) }; +} + +ThreadPool::ThreadPool(uint32 threadCount) + : workers(threadCount) +{ + +} + +static ThreadPool& getGlobalThreadPool() +{ + return gThreadPool; +} \ No newline at end of file diff --git a/src/Engine/ThreadPool.h b/src/Engine/ThreadPool.h new file mode 100644 index 0000000..b245610 --- /dev/null +++ b/src/Engine/ThreadPool.h @@ -0,0 +1,64 @@ +#pragma once +#include +#include +#include "MinimalEngine.h" + +namespace Seele +{ +enum class JobStage +{ + INPUT, + GAMELOGIC, + RENDER, + DONT_CARE +}; +struct [[nodiscard]] Job; +struct JobPromise +{ + Job get_return_object() noexcept; + + std::suspend_never initial_suspend() const noexcept { return {}; } + std::suspend_never final_suspend() const noexcept { return {}; } + + void return_void() noexcept {} + void unhandled_exception() noexcept { + std::cerr << "Unhandled exception caught" << std::endl; + exit(1); + }; +}; +struct [[nodiscard]] Job +{ +public: + using promise_type = JobPromise; + + explicit Job(std::coroutine_handle handle, JobStage stage = JobStage::DONT_CARE) + : handle(handle) + , stage(stage) + {} + ~Job() + { + if(handle) + { + handle.destroy(); + } + } +private: + std::coroutine_handle handle; + JobStage stage; +}; + +class ThreadPool +{ +public: + ThreadPool(uint32 threadCount = std::thread::hardware_concurrency); + virtual ~ThreadPool(); + void schedule(std::function function) + { + + } +private: + Array workers; + void threadLoop(); +}; +static ThreadPool& getGlobalThreadPool(); +} // namespace Seele diff --git a/src/Engine/UI/RenderHierarchy.cpp b/src/Engine/UI/RenderHierarchy.cpp index 05b53fa..4c7cb06 100644 --- a/src/Engine/UI/RenderHierarchy.cpp +++ b/src/Engine/UI/RenderHierarchy.cpp @@ -35,7 +35,7 @@ void RenderHierarchy::addElement(PElement addedElement) updates.add(new AddElementRenderHierarchyUpdate{ addedElement.getHandle(), addedElement->getParent().getHandle() - })); + }); } void RenderHierarchy::removeElement(PElement elementToRemove) @@ -68,6 +68,6 @@ void RenderHierarchy::updateHierarchy() } for(auto update : localUpdates) { - + update->apply(drawElements); } } diff --git a/src/Engine/Window/View.h b/src/Engine/Window/View.h index 6a027cb..a5d1150 100644 --- a/src/Engine/Window/View.h +++ b/src/Engine/Window/View.h @@ -4,7 +4,6 @@ namespace Seele { DECLARE_REF(Window) - // A view is a part of the window, which can be anything from a scene viewport to an inspector class View { diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index f519b55..3acdc17 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -54,7 +54,7 @@ void Window::setFocused(PView view) } -void Window::viewWorker(WindowView* windowView) +void Window::viewWorker(WindowView* windowView) { while(true) {