From: TimePath Date: Sat, 7 Feb 2015 07:03:54 +0000 (+1100) Subject: Fix the tuba with pythonic modulo X-Git-Tag: xonotic-v0.8.1~123^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=089db410e5e72d677d93703d390871bc31125701;p=xonotic%2Fxonotic-data.pk3dir.git Fix the tuba with pythonic modulo Closes #1455 --- diff --git a/qcsrc/client/tuba.qc b/qcsrc/client/tuba.qc index 358fbd011..cd518e091 100644 --- a/qcsrc/client/tuba.qc +++ b/qcsrc/client/tuba.qc @@ -24,7 +24,7 @@ void tubasound(entity e, bool restart) float vol2 = 0; float speed2 = 1; - int m = e.note % Tuba_PitchStep; + int m = pymod(e.note, Tuba_PitchStep); if (m) { if (e.note - m < TUBA_MIN) { if (restart) { @@ -163,7 +163,7 @@ void Tuba_Precache() } } for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) { - if (!Tuba_PitchStep || (n % Tuba_PitchStep) == 0) { + if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) { for (int i = 0; i < TUBA_INSTRUMENTS; ++i) { precache_sound(TUBA_STARTNOTE(i, n)); } diff --git a/qcsrc/warpzonelib/mathlib.qc b/qcsrc/warpzonelib/mathlib.qc index b948b203e..d86af8a00 100644 --- a/qcsrc/warpzonelib/mathlib.qc +++ b/qcsrc/warpzonelib/mathlib.qc @@ -175,6 +175,20 @@ float tgamma(float x) return exp(v.x) * v.y; } +/** + * Pythonic mod: + * TODO: %% operator? + * + * 1 % 2 == 1 + * -1 % 2 == 1 + * 1 % -2 == -1 + * -1 % -2 == -1 + */ +float pymod(float x, float y) +{ + return x - y * floor(x / y); +} + float nearbyint(float x) { return rint(x); diff --git a/qcsrc/warpzonelib/mathlib.qh b/qcsrc/warpzonelib/mathlib.qh index 7eebd032c..a37ba63de 100644 --- a/qcsrc/warpzonelib/mathlib.qh +++ b/qcsrc/warpzonelib/mathlib.qh @@ -60,6 +60,17 @@ float erfc(float x); vector lgamma(float x); // value in _x, sign in _y float tgamma(float x); +/** + * Pythonic mod: + * TODO: %% operator? + * + * 1 % 2 == 1 + * -1 % 2 == 1 + * 1 % -2 == -1 + * -1 % -2 == -1 + */ +float pymod(float x, float y); + //float ceil(float x); //float floor(float x); float nearbyint(float x);