feat: start loading some stuff async

This commit is contained in:
2026-10-24 01:29:00 +02:00
parent 9c5a97cfbd
commit aa3eef259c
6 changed files with 53 additions and 8 deletions
+26 -3
View File
@@ -70,13 +70,11 @@ void App::init(const AppParams& params)
.maximized = params.startMaximized,
});
gfxDevice.init(window.GetHandle(), params.appName, false);
initDevices();
imguiPass.init(window.GetHandle(), gfxDevice);
resources.init(gfxDevice);
renderer.init(gfxDevice, resources, params.renderSize);
InputManager::GetInstance().Init();
AudioSystem::GetInstance().Init();
Time::GetInstance().Update();
customInitStarted = true;
@@ -90,6 +88,31 @@ void App::init(const AppParams& params)
}
}
void App::initDevices()
{
ZoneScopedN("App::initDevices");
auto& jobs = JobSystem::GetInstance();
auto gfxInit = jobs.Async([this] { gfxDevice.init(window.GetHandle(), m_params.appName, false); });
auto audioInit = jobs.Async([] { AudioSystem::GetInstance().Init(); });
// SDL wants its subsystems initialised on the main thread
std::exception_ptr inputError;
try {
InputManager::GetInstance().Init();
} catch (...) {
inputError = std::current_exception();
}
// Wait for both before rethrowing anything, cleanup must not race a running init
gfxInit.wait();
audioInit.wait();
if (inputError) {
std::rethrow_exception(inputError);
}
gfxInit.get();
audioInit.get();
}
void App::attachLayer(std::unique_ptr<AppLayer> newLayer)
{
if (layer) {
@@ -15,6 +15,7 @@
#include <destrum/Serialization/GlmJson.h>
#include <destrum/Serialization/MaterialSerialization.h>
#include <destrum/Serialization/ObjectSerialization.h>
#include <destrum/Threading/JobSystem.h>
using json = nlohmann::json;
@@ -349,7 +350,5 @@ bool SceneSerializer::LoadFromJson(Scene& scene, const json& root) {
std::future<SceneSerializer::LoadResult> SceneSerializer::LoadSceneFileAsync(
const std::filesystem::path& path) {
return std::async(std::launch::async, [path]() {
return LoadSceneFile(path);
});
return JobSystem::GetInstance().Async([path] { return LoadSceneFile(path); });
}