From 089db410e5e72d677d93703d390871bc31125701 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 7 Feb 2015 18:03:54 +1100 Subject: [PATCH] Fix the tuba with pythonic modulo Closes #1455 --- qcsrc/client/tuba.qc | 4 ++-- qcsrc/warpzonelib/mathlib.qc | 14 ++++++++++++++ qcsrc/warpzonelib/mathlib.qh | 11 +++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) 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); -- 2.39.2