diff --git a/src/util/quicktune.cpp b/src/util/quicktune.cpp index a1a3e4465..343301f1b 100644 --- a/src/util/quicktune.cpp +++ b/src/util/quicktune.cpp @@ -13,6 +13,8 @@ std::string QuicktuneValue::getString() return "(none)"; case QVT_FLOAT: return ftos(value_QVT_FLOAT.current); + case QVT_INT: + return itos(value_QVT_INT.current); } return ""; } @@ -22,14 +24,21 @@ void QuicktuneValue::relativeAdd(float amount) switch(type){ case QVT_NONE: break; - case QVT_FLOAT: - value_QVT_FLOAT.current += amount * (value_QVT_FLOAT.max - value_QVT_FLOAT.min); - if(value_QVT_FLOAT.current > value_QVT_FLOAT.max) - value_QVT_FLOAT.current = value_QVT_FLOAT.max; - if(value_QVT_FLOAT.current < value_QVT_FLOAT.min) - value_QVT_FLOAT.current = value_QVT_FLOAT.min; + case QVT_FLOAT: { + float &v = value_QVT_FLOAT.current; + v += amount * (value_QVT_FLOAT.max - value_QVT_FLOAT.min); + v = core::clamp(v, value_QVT_FLOAT.min, value_QVT_FLOAT.max); break; } + case QVT_INT: { + int &v = value_QVT_INT.current; + int diff = std::floor(amount * (value_QVT_INT.max - value_QVT_INT.min)); + if (!diff) + diff = amount < 0 ? -1 : 1; + v = core::clamp(v + diff, value_QVT_INT.min, value_QVT_INT.max); + break; + } + } } static std::map g_values; @@ -44,12 +53,9 @@ const std::vector &getQuicktuneNames() QuicktuneValue getQuicktuneValue(const std::string &name) { MutexAutoLock lock(g_mutex); - std::map::iterator i = g_values.find(name); - if(i == g_values.end()){ - QuicktuneValue val; - val.type = QVT_NONE; - return val; - } + auto i = g_values.find(name); + if (i == g_values.end()) + return QuicktuneValue(); return i->second; } @@ -64,15 +70,15 @@ void updateQuicktuneValue(const std::string &name, QuicktuneValue &val) { MutexAutoLock lock(g_mutex); auto i = g_values.find(name); - if(i == g_values.end()){ + if (i == g_values.end()) { g_values[name] = val; g_names.push_back(name); return; } QuicktuneValue &ref = i->second; - if(ref.modified) + if (ref.modified) { val = ref; - else{ + } else { ref = val; ref.modified = false; } diff --git a/src/util/quicktune.h b/src/util/quicktune.h index caed0f6a2..263fdcee6 100644 --- a/src/util/quicktune.h +++ b/src/util/quicktune.h @@ -37,19 +37,21 @@ #include #include -enum QuicktuneValueType{ +enum QuicktuneValueType { QVT_NONE, - QVT_FLOAT + QVT_FLOAT, + QVT_INT }; struct QuicktuneValue { QuicktuneValueType type = QVT_NONE; - union{ - struct{ - float current; - float min; - float max; + union { + struct { + float current, min, max; } value_QVT_FLOAT; + struct { + int current, min, max; + } value_QVT_INT; }; bool modified = false; @@ -65,19 +67,15 @@ void setQuicktuneValue(const std::string &name, const QuicktuneValue &val); void updateQuicktuneValue(const std::string &name, QuicktuneValue &val); -#ifndef NDEBUG - #define QUICKTUNE(type_, var, min_, max_, name){\ - QuicktuneValue qv;\ - qv.type = type_;\ - qv.value_##type_.current = var;\ - qv.value_##type_.min = min_;\ - qv.value_##type_.max = max_;\ - updateQuicktuneValue(name, qv);\ - var = qv.value_##type_.current;\ - } -#else // NDEBUG - #define QUICKTUNE(type, var, min_, max_, name){} -#endif +#define QUICKTUNE(type_, var, min_, max_, name) do { \ + QuicktuneValue qv; \ + qv.type = type_; \ + qv.value_##type_.current = var; \ + qv.value_##type_.min = min_; \ + qv.value_##type_.max = max_; \ + updateQuicktuneValue(name, qv); \ + var = qv.value_##type_.current; \ + } while (0) #define QUICKTUNE_AUTONAME(type_, var, min_, max_)\ QUICKTUNE(type_, var, min_, max_, #var)