resource manager hot reload (#864)
This commit is contained in:
@@ -97,6 +97,50 @@ void Editor::Initialize()
|
||||
renderComponent.Load();
|
||||
ActivatePath(&renderComponent, 0.2f);
|
||||
}
|
||||
void Editor::HotReload()
|
||||
{
|
||||
if (!wi::initializer::IsInitializeFinished())
|
||||
return;
|
||||
|
||||
static wi::jobsystem::context hotreload_ctx;
|
||||
wi::jobsystem::Wait(hotreload_ctx);
|
||||
hotreload_ctx.priority = wi::jobsystem::Priority::Low;
|
||||
|
||||
if (wi::shadercompiler::GetRegisteredShaderCount() > 0)
|
||||
{
|
||||
wi::jobsystem::Execute(hotreload_ctx, [](wi::jobsystem::JobArgs args) {
|
||||
wi::backlog::post("[Shader check] Started checking " + std::to_string(wi::shadercompiler::GetRegisteredShaderCount()) + " registered shaders for changes...");
|
||||
if (wi::shadercompiler::CheckRegisteredShadersOutdated())
|
||||
{
|
||||
wi::backlog::post("[Shader check] Changes detected, initiating reload...");
|
||||
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [](uint64_t userdata) {
|
||||
wi::renderer::ReloadShaders();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
wi::backlog::post("[Shader check] All up to date");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
wi::jobsystem::Execute(hotreload_ctx, [](wi::jobsystem::JobArgs args) {
|
||||
wi::backlog::post("[Resource check] Started checking resource manager for changes...");
|
||||
if (wi::resourcemanager::CheckResourcesOutdated())
|
||||
{
|
||||
wi::backlog::post("[Resource check] Changes detected, initiating reload...");
|
||||
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [](uint64_t userdata) {
|
||||
wi::resourcemanager::ReloadOutdatedResources();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
wi::backlog::post("[Resource check] All up to date");
|
||||
}
|
||||
});
|
||||
|
||||
renderComponent.ReloadLanguage();
|
||||
}
|
||||
|
||||
void EditorComponent::ResizeBuffers()
|
||||
{
|
||||
|
||||
@@ -229,6 +229,8 @@ public:
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void HotReload();
|
||||
|
||||
~Editor() override
|
||||
{
|
||||
config.Commit();
|
||||
|
||||
+1
-18
@@ -35,24 +35,7 @@ int sdl_loop(Editor &editor)
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
editor.is_window_active = true;
|
||||
if (wi::shadercompiler::GetRegisteredShaderCount() > 0)
|
||||
{
|
||||
std::thread([] {
|
||||
wi::backlog::post("[Shader check] Started checking " + std::to_string(wi::shadercompiler::GetRegisteredShaderCount()) + " registered shaders for changes...");
|
||||
if (wi::shadercompiler::CheckRegisteredShadersOutdated())
|
||||
{
|
||||
wi::backlog::post("[Shader check] Changes detected, initiating reload...");
|
||||
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [](uint64_t userdata) {
|
||||
wi::renderer::ReloadShaders();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
wi::backlog::post("[Shader check] All up to date");
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
editor.renderComponent.ReloadLanguage();
|
||||
editor.HotReload();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
+1
-23
@@ -276,29 +276,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
editor.is_window_active = true;
|
||||
if (wi::shadercompiler::GetRegisteredShaderCount() > 0)
|
||||
{
|
||||
static wi::jobsystem::context shader_check_ctx;
|
||||
if (!wi::jobsystem::IsBusy(shader_check_ctx))
|
||||
{
|
||||
shader_check_ctx.priority = wi::jobsystem::Priority::Low;
|
||||
wi::jobsystem::Execute(shader_check_ctx, [](wi::jobsystem::JobArgs args) {
|
||||
wi::backlog::post("[Shader check] Started checking " + std::to_string(wi::shadercompiler::GetRegisteredShaderCount()) + " registered shaders for changes...");
|
||||
if (wi::shadercompiler::CheckRegisteredShadersOutdated())
|
||||
{
|
||||
wi::backlog::post("[Shader check] Changes detected, initiating reload...");
|
||||
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [](uint64_t userdata) {
|
||||
wi::renderer::ReloadShaders();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
wi::backlog::post("[Shader check] All up to date");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
editor.renderComponent.ReloadLanguage();
|
||||
editor.HotReload();
|
||||
break;
|
||||
case WM_PAINT:
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user