Skip to content

Commit

Permalink
feat: simplify feature loading
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN committed Oct 1, 2023
1 parent a1fb0f7 commit b11a87d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Feature*>& GetFeatureList();
Expand Down
2 changes: 1 addition & 1 deletion src/Features/ExtendedMaterials.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ExtendedMaterials : Feature
virtual void SetupResources();
virtual inline void Reset() {}

void DataLoaded();
virtual void DataLoaded() override;

virtual void DrawSettings();

Expand Down
6 changes: 6 additions & 0 deletions src/Features/LightLimitFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/Features/LightLimitFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LightData>& lightsData, LightLimitFix::LightData& light, ParticleLights::Config* a_config = nullptr, RE::BSGeometry* a_geometry = nullptr, double timer = 0.0f);
Expand Down
2 changes: 1 addition & 1 deletion src/Features/ScreenSpaceShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ uint32_t GetTechnique(uint32_t descriptor)
return 0x3F & (descriptor >> 24);
}

void ScreenSpaceShadows::ClearComputeShader()
void ScreenSpaceShadows::ClearShaderCache()
{
if (raymarchProgram) {
raymarchProgram->Release();
Expand Down
2 changes: 1 addition & 1 deletion src/Features/ScreenSpaceShadows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class State
bool upscalerLoaded = false;

void Draw();
void DrawDeferred();
void Reset();
void Setup();

Expand Down
16 changes: 9 additions & 7 deletions src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand All @@ -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;
Expand Down

0 comments on commit b11a87d

Please sign in to comment.