resource manager hot reload (#864)
This commit is contained in:
@@ -1616,6 +1616,7 @@ Axis Aligned Bounding Box. Can be intersected with other primitives.
|
||||
- Intersects(AABB aabb) : bool result
|
||||
- Intersects(Sphere sphere) : bool result
|
||||
- Intersects(Ray ray) : bool result
|
||||
- Intersects(Vector point) : bool result
|
||||
- GetMin() : Vector result
|
||||
- GetMax() : Vector result
|
||||
- SetMin(Vector vector)
|
||||
@@ -1637,6 +1638,7 @@ Sphere defined by center Vector and radius. Can be intersected with other primit
|
||||
- Intersects(Sphere sphere) : bool result
|
||||
- Intersects(Capsule capsule) : bool result
|
||||
- Intersects(Ray ray) : bool result
|
||||
- Intersects(Vector point) : bool result
|
||||
- GetCenter() : Vector result
|
||||
- GetRadius() : float result
|
||||
- SetCenter(Vector value)
|
||||
|
||||
@@ -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:
|
||||
{
|
||||
|
||||
@@ -1064,6 +1064,8 @@ namespace wi::helper
|
||||
|
||||
uint64_t FileTimestamp(const std::string& fileName)
|
||||
{
|
||||
if (!FileExists(fileName))
|
||||
return 0;
|
||||
auto tim = std::filesystem::last_write_time(ToNativeString(fileName));
|
||||
return std::chrono::duration_cast<std::chrono::duration<uint64_t>>(tim.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
@@ -260,6 +260,13 @@ namespace wi::lua::primitive
|
||||
int argc = wi::lua::SGetArgCount(L);
|
||||
if (argc > 0)
|
||||
{
|
||||
Vector_BindLua* _vec = Luna<Vector_BindLua>::lightcheck(L, 1);
|
||||
if (_vec)
|
||||
{
|
||||
wi::lua::SSetBool(L, aabb.intersects(_vec->GetFloat3()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
AABB_BindLua* _aabb = Luna<AABB_BindLua>::lightcheck(L, 1);
|
||||
if (_aabb)
|
||||
{
|
||||
@@ -446,6 +453,14 @@ namespace wi::lua::primitive
|
||||
int argc = wi::lua::SGetArgCount(L);
|
||||
if (argc > 0)
|
||||
{
|
||||
Vector_BindLua* _vec = Luna<Vector_BindLua>::lightcheck(L, 1);
|
||||
if (_vec)
|
||||
{
|
||||
bool intersects = sphere.intersects(_vec->GetFloat3());
|
||||
wi::lua::SSetBool(L, intersects);
|
||||
return 1;
|
||||
}
|
||||
|
||||
AABB_BindLua* _aabb = Luna<AABB_BindLua>::lightcheck(L, 1);
|
||||
if (_aabb)
|
||||
{
|
||||
|
||||
+965
-872
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,7 @@ namespace wi
|
||||
const wi::graphics::Texture& GetTexture() const;
|
||||
const wi::audio::Sound& GetSound() const;
|
||||
const std::string& GetScript() const;
|
||||
size_t GetScriptHash() const;
|
||||
const wi::video::Video& GetVideo() const;
|
||||
int GetTextureSRGBSubresource() const;
|
||||
int GetFontStyle() const;
|
||||
@@ -38,7 +39,6 @@ namespace wi
|
||||
void SetVideo(const wi::video::Video& script);
|
||||
|
||||
// Resource marked for recreate on resourcemanager::Load()
|
||||
// It keeps embedded file data if exists
|
||||
void SetOutdated();
|
||||
|
||||
// Let the streaming system know the required resolution of this resource
|
||||
@@ -107,6 +107,12 @@ namespace wi
|
||||
// Launching or finalizing background streaming jobs is attempted here
|
||||
void UpdateStreamingResources(float dt);
|
||||
|
||||
// Returns true if any of the loaded resources are outdated compared to their files
|
||||
bool CheckResourcesOutdated();
|
||||
|
||||
// Reload all resources that are outdated
|
||||
void ReloadOutdatedResources();
|
||||
|
||||
struct ResourceSerializer
|
||||
{
|
||||
wi::vector<Resource> resources;
|
||||
|
||||
@@ -4966,8 +4966,10 @@ namespace wi::scene
|
||||
|
||||
if (script.IsPlaying())
|
||||
{
|
||||
if (script.script.empty() && script.resource.IsValid())
|
||||
if (script.resource.IsValid() && (script.script.empty() || script.script_hash != script.resource.GetScriptHash()))
|
||||
{
|
||||
script.script.clear();
|
||||
script.script_hash = script.resource.GetScriptHash();
|
||||
std::string str = script.resource.GetScript();
|
||||
wi::lua::AttachScriptParameters(str, script.filename, wi::lua::GeneratePID(), "local function GetEntity() return " + std::to_string(entity) + "; end;", "");
|
||||
wi::lua::CompileText(str, script.script);
|
||||
|
||||
@@ -1716,6 +1716,7 @@ namespace wi::scene
|
||||
// Non-serialized attributes:
|
||||
wi::vector<uint8_t> script; // compiled script binary data
|
||||
wi::Resource resource;
|
||||
size_t script_hash = 0;
|
||||
|
||||
inline void Play() { _flags |= PLAYING; }
|
||||
inline void SetPlayOnce(bool once = true) { if (once) { _flags |= PLAY_ONCE; } else { _flags &= ~PLAY_ONCE; } }
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wi::version
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 71;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 488;
|
||||
const int revision = 489;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
@@ -50,7 +50,7 @@ All contributors: https://github.com/turanszkij/WickedEngine/graphs/contributors
|
||||
|
||||
Patreon supporters
|
||||
---------------------------
|
||||
Nemerle, James Webb, Quifeng Jin, TheGameCreators, Joseph Goldin, Yuri, Sergey K, Yukawa Kanta, Dragon Josh, John, LurkingNinja, Bernardo Del Castillo, Invictus, Scott Hunt, Yazan Altaki, Tuan NV, Robert MacGregor, cybernescence, Alexander Dahlin, blueapples, Delhills, NI NI, Sherief, ktopoet, Justin Macklin, Cédric Fabre, TogetherTeam, Bartosz Boczula, Arne Koenig, Ivan Trajchev, nathants, Fahd Ahmed, Gabriel Jadderson, SAS_Controller, Dominik Madarász, Segfault, Mike amanfo, Dennis Brakhane, rookie, Peter Moore, therealjtgill, Nicolas Embleton, Desuuc, radino1977, Anthony Curtis, manni heck, Matthias Hölzl, Phyffer, Lucas Pinheiro, Tapkaara, gpman, Anthony Python, Gnowos, Klaus, slaughternaut, Paul Brain, Connor Greaves, Alexandr, Lee Bamber, MCAlarm MC2, Titoutan, Willow, Aldo, lokimx, K. Osterman, Nomad, ykl, Alex Krokos, Timmy, Avaflow, mat, Hexegonel Samael Michael, Joe Spataro, soru, GeniokV, Mammoth, Ignacio, datae
|
||||
Nemerle, James Webb, Quifeng Jin, TheGameCreators, Joseph Goldin, Yuri, Sergey K, Yukawa Kanta, Dragon Josh, John, LurkingNinja, Bernardo Del Castillo, Invictus, Scott Hunt, Yazan Altaki, Tuan NV, Robert MacGregor, cybernescence, Alexander Dahlin, blueapples, Delhills, NI NI, Sherief, ktopoet, Justin Macklin, Cédric Fabre, TogetherTeam, Bartosz Boczula, Arne Koenig, Ivan Trajchev, nathants, Fahd Ahmed, Gabriel Jadderson, SAS_Controller, Dominik Madarász, Segfault, Mike amanfo, Dennis Brakhane, rookie, Peter Moore, therealjtgill, Nicolas Embleton, Desuuc, radino1977, Anthony Curtis, manni heck, Matthias Hölzl, Phyffer, Lucas Pinheiro, Tapkaara, gpman, Anthony Python, Gnowos, Klaus, slaughternaut, Paul Brain, Connor Greaves, Alexandr, Lee Bamber, MCAlarm MC2, Titoutan, Willow, Aldo, lokimx, K. Osterman, Nomad, ykl, Alex Krokos, Timmy, Avaflow, mat, Hexegonel Samael Michael, Joe Spataro, soru, GeniokV, Mammoth, Ignacio, datae, Jason Rice
|
||||
)";
|
||||
|
||||
return credits;
|
||||
|
||||
Reference in New Issue
Block a user