From 3282366ea7442435efe8db9a54d67f16f6b30049 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 26 Jul 2024 15:29:49 +1000 Subject: [PATCH] PostProcessing/FX: Preserve option declaration order --- src/util/postprocessing_shader.h | 4 +++- src/util/postprocessing_shader_fx.cpp | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/util/postprocessing_shader.h b/src/util/postprocessing_shader.h index 5be75e6a0..3c8e30f8b 100644 --- a/src/util/postprocessing_shader.h +++ b/src/util/postprocessing_shader.h @@ -54,12 +54,14 @@ public: u32 target_height) = 0; protected: + using OptionList = std::vector; + static void ParseKeyValue(std::string_view line, std::string_view* key, std::string_view* value); virtual void OnOptionChanged(const ShaderOption& option); std::string m_name; - std::vector m_options; + OptionList m_options; }; } // namespace PostProcessing \ No newline at end of file diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index 122135d39..7b2bbd3a2 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -746,13 +746,17 @@ bool PostProcessing::ReShadeFXShader::CreateOptions(const reshadefx::module& mod } } - m_options.push_back(std::move(opt)); + OptionList::iterator iter = std::find_if(m_options.begin(), m_options.end(), + [&opt](const ShaderOption& it) { return it.category == opt.category; }); + if (iter != m_options.end()) + { + // insert at the end of this category + while (iter != m_options.end() && iter->category == opt.category) + ++iter; + } + m_options.insert(iter, std::move(opt)); } - // sort based on category - std::sort(m_options.begin(), m_options.end(), - [](const ShaderOption& lhs, const ShaderOption& rhs) { return lhs.category < rhs.category; }); - m_uniforms_size = mod.total_uniform_size; DEV_LOG("{}: {} options", m_filename, m_options.size()); return true;