]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix the tuba with pythonic modulo
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Feb 2015 07:03:54 +0000 (18:03 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Feb 2015 07:06:21 +0000 (18:06 +1100)
Closes #1455

qcsrc/client/tuba.qc
qcsrc/warpzonelib/mathlib.qc
qcsrc/warpzonelib/mathlib.qh

index 358fbd011d2a5759b7c44a6fe3bc382890ac6857..cd518e091d3c2ecdd3677aaf7c2ca50a5f6217aa 100644 (file)
@@ -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));
                        }
index b948b203eeb36ac4a06d00b6a91ab038b6dc1be3..d86af8a00ec786760c15a9440b525a7160d4a0ab 100644 (file)
@@ -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);
index 7eebd032c43d75c4d85f736518265115c34ef276..a37ba63de6c63b87ed3dad63d12ea1ad4637fe52 100644 (file)
@@ -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);