From b11a87d21d497a787d45320678e495baa01689e2 Mon Sep 17 00:00:00 2001 From: FlayaN Date: Sun, 1 Oct 2023 20:23:55 +0200 Subject: [PATCH] feat: simplify feature loading --- src/Feature.h | 5 +++++ src/Features/ExtendedMaterials.h | 2 +- src/Features/LightLimitFix.cpp | 6 ++++++ src/Features/LightLimitFix.h | 3 ++- src/Features/ScreenSpaceShadows.cpp | 2 +- src/Features/ScreenSpaceShadows.h | 2 +- src/Menu.cpp | 6 +++++- src/State.cpp | 9 +++++++++ src/State.h | 1 + src/XSEPlugin.cpp | 16 +++++++++------- 10 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/Feature.h b/src/Feature.h index 1b56bb21c..183e52052 100644 --- a/src/Feature.h +++ b/src/Feature.h @@ -13,12 +13,17 @@ struct Feature virtual void DrawSettings() = 0; virtual void Draw(const RE::BSShader* shader, const uint32_t descriptor) = 0; + virtual void DrawDeferred() {} + + virtual void DataLoaded() {} + virtual void PostPostLoad() {} virtual void Load(json& o_json); virtual void Save(json& o_json) = 0; virtual bool ValidateCache(CSimpleIniA& a_ini); virtual void WriteDiskCacheInfo(CSimpleIniA& a_ini); + virtual void ClearShaderCache() {} // Cat: add all the features in here static const std::vector& GetFeatureList(); diff --git a/src/Features/ExtendedMaterials.h b/src/Features/ExtendedMaterials.h index 0fb448d8c..6ac3bf3f2 100644 --- a/src/Features/ExtendedMaterials.h +++ b/src/Features/ExtendedMaterials.h @@ -47,7 +47,7 @@ struct ExtendedMaterials : Feature virtual void SetupResources(); virtual inline void Reset() {} - void DataLoaded(); + virtual void DataLoaded() override; virtual void DrawSettings(); diff --git a/src/Features/LightLimitFix.cpp b/src/Features/LightLimitFix.cpp index bf272e725..e7a27c765 100644 --- a/src/Features/LightLimitFix.cpp +++ b/src/Features/LightLimitFix.cpp @@ -570,6 +570,12 @@ void LightLimitFix::Draw(const RE::BSShader* shader, const uint32_t descriptor) } } +void LightLimitFix::PostPostLoad() +{ + ParticleLights::GetSingleton()->GetConfigs(); + LightLimitFix::InstallHooks(); +} + void LightLimitFix::DataLoaded() { auto iMagicLightMaxCount = RE::GameSettingCollection::GetSingleton()->GetSetting("iMagicLightMaxCount"); diff --git a/src/Features/LightLimitFix.h b/src/Features/LightLimitFix.h index c0ced98ab..5ca5cb6d3 100644 --- a/src/Features/LightLimitFix.h +++ b/src/Features/LightLimitFix.h @@ -115,7 +115,8 @@ struct LightLimitFix : Feature virtual void DrawSettings(); virtual void Draw(const RE::BSShader* shader, const uint32_t descriptor); - void DataLoaded(); + virtual void PostPostLoad() override; + virtual void DataLoaded() override; float CalculateLightDistance(float3 a_lightPosition, float a_radius); bool AddCachedParticleLights(eastl::vector& lightsData, LightLimitFix::LightData& light, ParticleLights::Config* a_config = nullptr, RE::BSGeometry* a_geometry = nullptr, double timer = 0.0f); diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index c95b8989f..f9731d21f 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -187,7 +187,7 @@ uint32_t GetTechnique(uint32_t descriptor) return 0x3F & (descriptor >> 24); } -void ScreenSpaceShadows::ClearComputeShader() +void ScreenSpaceShadows::ClearShaderCache() { if (raymarchProgram) { raymarchProgram->Release(); diff --git a/src/Features/ScreenSpaceShadows.h b/src/Features/ScreenSpaceShadows.h index a633abe21..d060eccb0 100644 --- a/src/Features/ScreenSpaceShadows.h +++ b/src/Features/ScreenSpaceShadows.h @@ -71,7 +71,7 @@ struct ScreenSpaceShadows : Feature void ModifyGrass(const RE::BSShader* shader, const uint32_t descriptor); void ModifyDistantTree(const RE::BSShader*, const uint32_t descriptor); - void ClearComputeShader(); + virtual void ClearShaderCache() override; ID3D11ComputeShader* GetComputeShader(); ID3D11ComputeShader* GetComputeShaderHorizontalBlur(); ID3D11ComputeShader* GetComputeShaderVerticalBlur(); diff --git a/src/Menu.cpp b/src/Menu.cpp index e8f2ce62f..6f9eaf62d 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -318,7 +318,11 @@ void Menu::DrawSettings() ImGui::TableNextColumn(); if (ImGui::Button("Clear Shader Cache", { -1, 0 })) { shaderCache.Clear(); - ScreenSpaceShadows::GetSingleton()->ClearComputeShader(); + for (auto* feature : Feature::GetFeatureList()) { + if (feature->loaded) { + feature->ClearShaderCache(); + } + } } if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); diff --git a/src/State.cpp b/src/State.cpp index 0499c3984..072dcb645 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -39,6 +39,15 @@ void State::Draw() currentShader = nullptr; } +void State::DrawDeferred() +{ + for (auto* feature : Feature::GetFeatureList()) { + if (feature->loaded) { + feature->DrawDeferred(); + } + } +} + void State::Reset() { for (auto* feature : Feature::GetFeatureList()) diff --git a/src/State.h b/src/State.h index bc3b43a61..e0fc776fd 100644 --- a/src/State.h +++ b/src/State.h @@ -27,6 +27,7 @@ class State bool upscalerLoaded = false; void Draw(); + void DrawDeferred(); void Reset(); void Setup(); diff --git a/src/XSEPlugin.cpp b/src/XSEPlugin.cpp index 53e5fe3dd..fcdc42cd8 100644 --- a/src/XSEPlugin.cpp +++ b/src/XSEPlugin.cpp @@ -96,9 +96,10 @@ void MessageHandler(SKSE::MessagingInterface::Message* message) shaderCache.ValidateDiskCache(); - if (LightLimitFix::GetSingleton()->loaded) { - ParticleLights::GetSingleton()->GetConfigs(); - LightLimitFix::InstallHooks(); + for (auto* feature : Feature::GetFeatureList()) { + if (feature->loaded) { + feature->PostPostLoad(); + } } } @@ -124,10 +125,11 @@ void MessageHandler(SKSE::MessagingInterface::Message* message) shaderCache.WriteDiskCacheInfo(); } - if (LightLimitFix::GetSingleton()->loaded) - LightLimitFix::GetSingleton()->DataLoaded(); - if (ExtendedMaterials::GetSingleton()->loaded) - ExtendedMaterials::GetSingleton()->DataLoaded(); + for (auto* feature : Feature::GetFeatureList()) { + if (feature->loaded) { + feature->DataLoaded(); + } + } } break;