Skip to content

Commit

Permalink
refactor: simplify feature implementation (#326)
Browse files Browse the repository at this point in the history
* refactor: make feature->Draw optional

* refactor: make feature->Reset optional

* refactor: make feature->SetupResources optional

* refactor: remove unnecessary override

* refactor: simplify feature::Save/Load and made them optional

* refactor: add virtual and override keywords to features

* refactor: make feature->DrawSettings optional

* refactor: make feature->RestoreDefaultSettings optional

* refactor: remove feature-Draw and remove empty functions
  • Loading branch information
FlayaN authored Jul 23, 2024
1 parent 4d820b9 commit 0ffb136
Show file tree
Hide file tree
Showing 32 changed files with 143 additions and 377 deletions.
10 changes: 9 additions & 1 deletion src/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

#include "State.h"

void Feature::Load(json&)
void Feature::Load(json& o_json)
{
if (o_json[GetName()].is_object())
LoadSettings(o_json[GetName()]);

// Convert string to wstring
auto ini_filename = std::format("{}.ini", GetShortName());
std::wstring ini_filename_w;
Expand Down Expand Up @@ -63,6 +66,11 @@ void Feature::Load(json&)
}
}

void Feature::Save(json& o_json)
{
SaveSettings(o_json[GetName()]);
}

bool Feature::ValidateCache(CSimpleIniA& a_ini)
{
auto name = GetName();
Expand Down
16 changes: 9 additions & 7 deletions src/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ struct Feature
*/
virtual bool SupportsVR() { return false; }

virtual void SetupResources() = 0;
virtual void Reset() = 0;
virtual void SetupResources() {}
virtual void Reset() {}

virtual void DrawSettings() = 0;
virtual void Draw(const RE::BSShader* shader, const uint32_t descriptor) = 0;
virtual void DrawSettings() {}
virtual void DrawDeferred() {}
virtual void DrawPreProcess() {}
virtual void Prepass() {}

virtual void DataLoaded() {}
virtual void PostPostLoad() {}

virtual void Load(json& o_json);
virtual void Save(json& o_json) = 0;
void Load(json& o_json);
void Save(json& o_json);

virtual void RestoreDefaultSettings() = 0;
virtual void SaveSettings(json&) {}
virtual void LoadSettings(json&) {}

virtual void RestoreDefaultSettings() {}

virtual bool ValidateCache(CSimpleIniA& a_ini);
virtual void WriteDiskCacheInfo(CSimpleIniA& a_ini);
Expand Down
21 changes: 0 additions & 21 deletions src/Features/CloudShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include "Deferred.h"
#include "Util.h"

void CloudShadows::DrawSettings()
{
}

void CloudShadows::CheckResourcesSide(int side)
{
static Util::FrameChecker frame_checker[6];
Expand Down Expand Up @@ -96,19 +92,6 @@ void CloudShadows::Prepass()
context->PSSetShaderResources(27, 1, &srv);
}

void CloudShadows::Draw(const RE::BSShader*, const uint32_t)
{
}

void CloudShadows::Load(json& o_json)
{
Feature::Load(o_json);
}

void CloudShadows::Save(json&)
{
}

void CloudShadows::SetupResources()
{
auto renderer = RE::BSGraphics::Renderer::GetSingleton();
Expand Down Expand Up @@ -136,7 +119,3 @@ void CloudShadows::SetupResources()
}
}
}

void CloudShadows::RestoreDefaultSettings()
{
}
17 changes: 3 additions & 14 deletions src/Features/CloudShadows.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct CloudShadows : Feature
return &singleton;
}

virtual inline std::string GetName() override { return "Cloud Shadows"; }
virtual inline std::string GetShortName() override { return "CloudShadows"; }
virtual inline std::string GetName() { return "Cloud Shadows"; }
virtual inline std::string GetShortName() { return "CloudShadows"; }
virtual inline std::string_view GetShaderDefineName() override { return "CLOUD_SHADOWS"; }
virtual inline bool HasShaderDefine(RE::BSShader::Type) override { return true; }

Expand All @@ -26,22 +26,11 @@ struct CloudShadows : Feature

virtual void SetupResources() override;

virtual inline void Reset() override {}

virtual void DrawSettings() override;

void CheckResourcesSide(int side);
void ModifySky(RE::BSRenderPass* Pass);

virtual void Prepass() override;

virtual void Draw(const RE::BSShader* shader, const uint32_t descriptor) override;

virtual void Load(json& o_json) override;
virtual void Save(json& o_json) override;

virtual void RestoreDefaultSettings() override;

virtual inline void PostPostLoad() override { Hooks::Install(); }

struct Hooks
Expand All @@ -62,5 +51,5 @@ struct CloudShadows : Feature
logger::info("[Cloud Shadows] Installed hooks");
}
};
bool SupportsVR() override { return true; };
virtual bool SupportsVR() override { return true; };
};
21 changes: 0 additions & 21 deletions src/Features/DynamicCubemaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,6 @@ void DynamicCubemaps::PostDeferred()
context->PSSetShaderResources(64, 2, views);
}

void DynamicCubemaps::Prepass()
{
}

void DynamicCubemaps::Draw(const RE::BSShader*, const uint32_t)
{
}

void DynamicCubemaps::SetupResources()
{
GetComputeShaderUpdate();
Expand Down Expand Up @@ -530,16 +522,3 @@ void DynamicCubemaps::Reset()
else
activeReflections = false;
}

void DynamicCubemaps::Load(json& o_json)
{
Feature::Load(o_json);
}

void DynamicCubemaps::Save(json&)
{
}

void DynamicCubemaps::RestoreDefaultSettings()
{
}
19 changes: 5 additions & 14 deletions src/Features/DynamicCubemaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,15 @@ struct DynamicCubemaps : Feature

virtual inline std::string GetName() { return "Dynamic Cubemaps"; }
virtual inline std::string GetShortName() { return "DynamicCubemaps"; }
inline std::string_view GetShaderDefineName() override { return "DYNAMIC_CUBEMAPS"; }
virtual inline std::string_view GetShaderDefineName() override { return "DYNAMIC_CUBEMAPS"; }
bool HasShaderDefine(RE::BSShader::Type) override { return true; };

virtual void SetupResources();
virtual void Reset();
virtual void SetupResources() override;
virtual void Reset() override;

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

virtual void Draw(const RE::BSShader* shader, const uint32_t descriptor);

virtual void Load(json& o_json);
virtual void Save(json& o_json);

virtual void RestoreDefaultSettings();

std::vector<std::string> iniVRCubeMapSettings{
{ "bAutoWaterSilhouetteReflections:Water" }, //IniSettings 0x1eaa018
{ "bForceHighDetailReflections:Water" }, //IniSettings 0x1eaa030
Expand All @@ -129,11 +122,9 @@ struct DynamicCubemaps : Feature

void UpdateCubemapCapture();

virtual void Prepass() override;

void Inferrence(bool a_reflections);

void Irradiance(bool a_reflections);

bool SupportsVR() override { return true; };
virtual bool SupportsVR() override { return true; };
};
11 changes: 4 additions & 7 deletions src/Features/ExtendedMaterials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,14 @@ void ExtendedMaterials::DrawSettings()
}
}

void ExtendedMaterials::Load(json& o_json)
void ExtendedMaterials::LoadSettings(json& o_json)
{
if (o_json[GetName()].is_object())
settings = o_json[GetName()];

Feature::Load(o_json);
settings = o_json;
}

void ExtendedMaterials::Save(json& o_json)
void ExtendedMaterials::SaveSettings(json& o_json)
{
o_json[GetName()] = settings;
o_json = settings;
}

void ExtendedMaterials::RestoreDefaultSettings()
Expand Down
17 changes: 6 additions & 11 deletions src/Features/ExtendedMaterials.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ExtendedMaterials : Feature

virtual inline std::string GetName() { return "Extended Materials"; }
virtual inline std::string GetShortName() { return "ExtendedMaterials"; }
inline std::string_view GetShaderDefineName() override { return "EXTENDED_MATERIALS"; }
virtual inline std::string_view GetShaderDefineName() override { return "EXTENDED_MATERIALS"; }

bool HasShaderDefine(RE::BSShader::Type shaderType) override;

Expand All @@ -28,19 +28,14 @@ struct ExtendedMaterials : Feature

Settings settings;

virtual void SetupResources(){};
virtual inline void Reset() {}

virtual void DataLoaded() override;

virtual void DrawSettings();

virtual void Draw(const RE::BSShader*, const uint32_t){};
virtual void DrawSettings() override;

virtual void Load(json& o_json);
virtual void Save(json& o_json);
virtual void LoadSettings(json& o_json) override;
virtual void SaveSettings(json& o_json) override;

virtual void RestoreDefaultSettings();
virtual void RestoreDefaultSettings() override;

bool SupportsVR() override { return true; };
virtual bool SupportsVR() override { return true; };
};
11 changes: 4 additions & 7 deletions src/Features/GrassCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,14 @@ void GrassCollision::Update()
}
}

void GrassCollision::Load(json& o_json)
void GrassCollision::LoadSettings(json& o_json)
{
if (o_json[GetName()].is_object())
settings = o_json[GetName()];

Feature::Load(o_json);
settings = o_json;
}

void GrassCollision::Save(json& o_json)
void GrassCollision::SaveSettings(json& o_json)
{
o_json[GetName()] = settings;
o_json = settings;
}

void GrassCollision::RestoreDefaultSettings()
Expand Down
17 changes: 8 additions & 9 deletions src/Features/GrassCollision.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct GrassCollision : Feature

virtual inline std::string GetName() { return "Grass Collision"; }
virtual inline std::string GetShortName() { return "GrassCollision"; }
inline std::string_view GetShaderDefineName() override { return "GRASS_COLLISION"; }
virtual inline std::string_view GetShaderDefineName() override { return "GRASS_COLLISION"; }

bool HasShaderDefine(RE::BSShader::Type shaderType) override;

Expand Down Expand Up @@ -46,22 +46,21 @@ struct GrassCollision : Feature
ConstantBuffer* perFrame = nullptr;
int eyeCount = !REL::Module::IsVR() ? 1 : 2;

virtual void SetupResources();
virtual void Reset();
virtual void SetupResources() override;
virtual void Reset() override;

virtual void DrawSettings();
virtual void DrawSettings() override;
void UpdateCollisions(PerFrame& perFrame);
void Update();
virtual void Draw(const RE::BSShader*, const uint32_t){};

virtual void Load(json& o_json);
virtual void Save(json& o_json);
virtual void LoadSettings(json& o_json) override;
virtual void SaveSettings(json& o_json) override;

virtual void RestoreDefaultSettings();
virtual void RestoreDefaultSettings() override;

virtual void PostPostLoad() override;

bool SupportsVR() override { return true; };
virtual bool SupportsVR() override { return true; };

struct Hooks
{
Expand Down
11 changes: 4 additions & 7 deletions src/Features/GrassLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,14 @@ void GrassLighting::DrawSettings()
}
}

void GrassLighting::Load(json& o_json)
void GrassLighting::LoadSettings(json& o_json)
{
if (o_json[GetName()].is_object())
settings = o_json[GetName()];

Feature::Load(o_json);
settings = o_json;
}

void GrassLighting::Save(json& o_json)
void GrassLighting::SaveSettings(json& o_json)
{
o_json[GetName()] = settings;
o_json = settings;
}

void GrassLighting::RestoreDefaultSettings()
Expand Down
15 changes: 5 additions & 10 deletions src/Features/GrassLighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@ struct GrassLighting : Feature

Settings settings;

virtual void SetupResources(){};
virtual void DrawSettings() override;

virtual void DrawSettings();
virtual void Reset(){};
virtual void LoadSettings(json& o_json) override;
virtual void SaveSettings(json& o_json) override;

virtual void Draw(const RE::BSShader*, const uint32_t){};
virtual void RestoreDefaultSettings() override;

virtual void Load(json& o_json);
virtual void Save(json& o_json);

virtual void RestoreDefaultSettings();

bool SupportsVR() override { return true; };
virtual bool SupportsVR() override { return true; };
};
Loading

0 comments on commit 0ffb136

Please sign in to comment.