X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fslider_decibels.qc;h=c3eb4b0abd1cf2226480eeba3176c4a22a91f631;hb=692cb758fe8f25fa078bfd5885333ee031885600;hp=07632320ed29d89da88f90d7e914c00576833b35;hpb=15a18e8ca7c55ac8187b9ea266d15c2d6e0cb869;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/slider_decibels.qc b/qcsrc/menu/xonotic/slider_decibels.qc index 07632320e..c3eb4b0ab 100644 --- a/qcsrc/menu/xonotic/slider_decibels.qc +++ b/qcsrc/menu/xonotic/slider_decibels.qc @@ -1,11 +1,12 @@ -#include "../../warpzonelib/mathlib.qh" - -#ifdef INTERFACE -CLASS(XonoticDecibelsSlider) EXTENDS(XonoticSlider) - METHOD(XonoticDecibelsSlider, loadCvars, void(entity)) - METHOD(XonoticDecibelsSlider, saveCvars, void(entity)) - METHOD(XonoticDecibelsSlider, valueToText, string(entity, float)) +#ifndef SLIDER_DECIBELS_H +#define SLIDER_DECIBELS_H +#include "slider.qc" +CLASS(XonoticDecibelsSlider, XonoticSlider) + METHOD(XonoticDecibelsSlider, loadCvars, void(entity)); + METHOD(XonoticDecibelsSlider, saveCvars, void(entity)); + METHOD(XonoticDecibelsSlider, valueToText, string(entity, float)); ENDCLASS(XonoticDecibelsSlider) +entity makeXonoticDecibelsSlider_T(float, float, float, string, string); entity makeXonoticDecibelsSlider(float, float, float, string); #endif @@ -39,13 +40,17 @@ float fromDecibelOfSquare(float f, float mi) return exp(A * f); } -entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar) +entity makeXonoticDecibelsSlider_T(float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip) { entity me; - me = spawnXonoticDecibelsSlider(); - me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar); + me = NEW(XonoticDecibelsSlider); + me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar, theTooltip); return me; } +entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar) +{ + return makeXonoticDecibelsSlider_T(theValueMin, theValueMax, theValueStep, theCvar, string_null); +} void XonoticDecibelsSlider_loadCvars(entity me) { float v; @@ -57,9 +62,9 @@ void XonoticDecibelsSlider_loadCvars(entity me) // snapping if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin)) - Slider_setValue(me, me.valueMax); + Slider_setValue_noAnim(me, me.valueMax); else - Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep) ); + Slider_setValue_noAnim(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep)); } void XonoticDecibelsSlider_saveCvars(entity me) { @@ -89,19 +94,20 @@ string XonoticDecibelsSlider_valueToText(entity me, float v) return sprintf(_("%s dB"), ftos_decimals(toDecibelOfSquare(fromDecibelOfSquare(v, me.valueMin), 0), me.valueDigits)); } -void _TEST_XonoticDecibelsSlider() +bool autocvar_test_XonoticDecibelsSlider = false; +TEST(XonoticDecibelsSlider, SoundTest) { - float i; - for(i = -400; i < 0; ++i) + if (!autocvar_test_XonoticDecibelsSlider) { SUCCEED(); return; } + for (int i = -400; i < 0; ++i) { float db = i * 0.1; float v = fromDecibelOfSquare(db, -40); float dbv = toDecibelOfSquare(v, -40); float d = dbv - db; - printf("%f -> %f -> %f (diff: %f)\n", db, v, dbv, d); - TEST_Check(fabs(d) > 0.02); + LOG_INFOF("%f -> %f -> %f (diff: %f)\n", db, v, dbv, d); + EXPECT_GT(fabs(d), 0.02); } - TEST_OK(); + SUCCEED(); } #endif