feat: start loading some stuff async
This commit is contained in:
+26
-3
@@ -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); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user