Skip to content

Commit f4bf38e

Browse files
committed
reshade: processAttributes: inlined & condensed
* processAttributes: local and parameter variable scoping + variable's domain coupling (by using closures) reduced. * reshade: inlined type_ternary parameter into IIFE
1 parent 4c46657 commit f4bf38e

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/reshade_effect_manager.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,13 @@ TimerUniform::~TimerUniform()
305305
template<typename T>
306306
using AnnotationArrayType = std::pair<const char*, const std::array<const std::optional<const std::reference_wrapper<T>>, 16>>; // reshadefx::constant::as_* index size = 16;
307307

308-
template <typename T, typename Callable>
309-
static void processAttributes(const decltype(reshadefx::uniform_info::annotations)& annotationInfo, const Callable getTypeAttribute, const std::initializer_list<AnnotationArrayType<T>>& listOfAnnotationAttributes){
308+
template <typename T>
309+
static void processAttributes(const decltype(reshadefx::uniform_info::annotations)& annotationInfo, const std::initializer_list<AnnotationArrayType<T>>& listOfAnnotationAttributes){
310+
const auto [is_type_x, true_type_t, false_type_t] = [](){
311+
if constexpr (std::is_same_v<T, float>) { return std::tuple{&reshadefx::type::is_floating_point, &reshadefx::constant::as_float, &reshadefx::constant::as_int};}
312+
if constexpr (std::is_same_v<T, int>) { return std::tuple{&reshadefx::type::is_integral, &reshadefx::constant::as_int, &reshadefx::constant::as_float};}
313+
}();
314+
const auto getTypeAttribute = [&](const auto a, const auto i){ return (a->type.*is_type_x)() ? (a->value.*true_type_t)[i] : static_cast<T>((a->value.*false_type_t)[i]);};
310315
const auto matchesAnnotationName = [&](const auto& name){ return std::ranges::find_if(annotationInfo, std::bind_front(std::equal_to{}, name), &reshadefx::annotation::name);};
311316
for(const auto &[attributeName, attributeVariableRefs] : listOfAnnotationAttributes) {
312317
if (const auto iter_ = matchesAnnotationName(attributeName); iter_ != std::end(annotationInfo))
@@ -323,10 +328,7 @@ static void processAttributes(const decltype(reshadefx::uniform_info::annotation
323328
PingPongUniform::PingPongUniform(reshadefx::uniform_info uniformInfo)
324329
: ReshadeUniform(uniformInfo)
325330
{
326-
const auto getFloatAttribute = [](const auto& annotationAttribute, auto idx){ return annotationAttribute->type.is_floating_point()
327-
? annotationAttribute->value.as_float[idx]
328-
: static_cast<float>(annotationAttribute->value.as_int[idx]);};
329-
processAttributes<float>(uniformInfo.annotations, getFloatAttribute, {{"min", {min}}, {"max", {max}}, {"smoothing", {smoothing}}, {"step", {stepMin, stepMax}}});
331+
processAttributes<float>(uniformInfo.annotations, {{"min", {min}}, {"max", {max}}, {"smoothing", {smoothing}}, {"step", {stepMin, stepMax}}});
330332
lastFrame = std::chrono::high_resolution_clock::now();
331333
}
332334
void PingPongUniform::update(void* mappedBuffer)
@@ -366,10 +368,7 @@ PingPongUniform::~PingPongUniform()
366368
RandomUniform::RandomUniform(reshadefx::uniform_info uniformInfo)
367369
: ReshadeUniform(uniformInfo)
368370
{
369-
const auto getIntAttribute = [](const auto& annotationAttribute, auto idx){ return annotationAttribute->type.is_integral()
370-
? annotationAttribute->value.as_int[idx]
371-
: static_cast<int>(annotationAttribute->value.as_float[idx]);};
372-
processAttributes<int>(uniformInfo.annotations, getIntAttribute, {{"min", {min}}, {"max", {max}}});
371+
processAttributes<int>(uniformInfo.annotations, {{"min", {min}}, {"max", {max}}});
373372
}
374373
void RandomUniform::update(void* mappedBuffer)
375374
{

0 commit comments

Comments
 (0)