]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
support pitch shifting in the tuba if the engine supports it for faster level loading
authorRudolf Polzer <divverent@xonotic.org>
Sat, 24 Sep 2011 15:32:16 +0000 (17:32 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Sat, 24 Sep 2011 15:32:16 +0000 (17:32 +0200)
(currently, we require only sounds for notes -18, -12, -6, 0, 6, 12, 18, 24)

balance25.cfg
balanceFruit.cfg
balanceLeeStricklin.cfg
balanceXonotic.cfg
balancetZork.cfg
qcsrc/client/autocvars.qh
qcsrc/client/tuba.qc

index 64ad2b9603d012a8c2dadf83bb7f11e3c3b57e80..81381f4638cbc21084ac14e196e476554331e121 100644 (file)
@@ -697,6 +697,7 @@ set g_balance_tuba_damage 5
 set g_balance_tuba_edgedamage 0
 set g_balance_tuba_radius 200
 set g_balance_tuba_force 40
+set g_balance_tuba_pitchstep 6
 // }}}
 // {{{ fireball
 set g_balance_fireball_primary_ammo 40
index 64935cf29a794334bc91ede9d6f302bf7994a7a5..9e73743e9d6bf5a695c860dad883467d0c4ad8f3 100644 (file)
@@ -697,6 +697,7 @@ set g_balance_tuba_damage 5
 set g_balance_tuba_edgedamage 0
 set g_balance_tuba_radius 200
 set g_balance_tuba_force 40
+set g_balance_tuba_pitchstep 6
 // }}}
 // {{{ fireball
 set g_balance_fireball_primary_ammo 40
index 3908f5c80b8943c95aa92d0af2597a640923a988..b73360f204f479af25598a4ecb83559a3abd4a94 100644 (file)
@@ -697,6 +697,7 @@ set g_balance_tuba_damage 5
 set g_balance_tuba_edgedamage 0
 set g_balance_tuba_radius 200
 set g_balance_tuba_force 40
+set g_balance_tuba_pitchstep 6
 // }}}
 // {{{ fireball
 set g_balance_fireball_primary_ammo 5
index 28be464598136b1e33ac5d511808b02c6893abdc..182e66cb1ccb486be92967163d2036a128321033 100644 (file)
@@ -697,6 +697,7 @@ set g_balance_tuba_damage 5
 set g_balance_tuba_edgedamage 0
 set g_balance_tuba_radius 200
 set g_balance_tuba_force 40
+set g_balance_tuba_pitchstep 6
 // }}}
 // {{{ fireball // this is a superweapon -- lets make it behave as one. 
 set g_balance_fireball_primary_ammo 20
index 00c33085a67dc8e71f9e3055f4a900c19e91a6cc..fd229feb9f394aa8157e749d210ab8cd0b751e57 100644 (file)
@@ -696,6 +696,7 @@ set g_balance_tuba_damage 5
 set g_balance_tuba_edgedamage 0
 set g_balance_tuba_radius 200
 set g_balance_tuba_force 40
+set g_balance_tuba_pitchstep 6
 // }}}
 // {{{ fireball
 set g_balance_fireball_primary_ammo 40
index 8f3372a6c821726040637f3abdc07d8e351a21f3..7451ee7c300a13b54d9f0bb56f1898798434d23e 100644 (file)
@@ -121,6 +121,7 @@ float autocvar_g_balance_damagepush_speedfactor;
 float autocvar_g_balance_tuba_attenuation;
 float autocvar_g_balance_tuba_fadetime;
 float autocvar_g_balance_tuba_volume;
+float autocvar_g_balance_tuba_pitchstep;
 float autocvar_g_warmup_limit;
 var float autocvar_g_waypointsprite_uppercase = 1;
 var float autocvar_g_waypointsprite_alpha = 1;
index 7f5896ff66c0b3f543e9c117ef42c2a64f2496b6..379f9c675057222e439e4d2077b1a67fb2a4216f 100644 (file)
@@ -1,9 +1,78 @@
+#define TUBA_MIN -18
+#define TUBA_MAX  27
+
 #define TUBA_STARTNOTE(n) strcat("weapons/tuba_loopnote", ftos(n), ".wav")
 .float note; // note
 .float attenuate; // if set, attenuate it
 .float cnt; // current volume
 .float count; // initial volume
 
+float Tuba_PitchStep;
+
+void tubasound(entity e, float restart)
+{
+       string snd1;
+
+       snd1 = string_null;
+
+       if(Tuba_PitchStep)
+       {
+               string snd2;
+               float f1, f2;
+               float p1, p2;
+               float m;
+
+               f1 = 1;
+               p1 = 1;
+               snd2 = string_null;
+               f2 = 0;
+               p2 = 1;
+
+               m = mod(e.note, Tuba_PitchStep);
+               if(m)
+               {
+                       if(e.note - m < TUBA_MIN)
+                       {
+                               if(restart)
+                                       snd1 = TUBA_STARTNOTE(e.note - m + Tuba_PitchStep);
+                               p1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
+                       }
+                       else if(e.note - m + Tuba_PitchStep > TUBA_MAX)
+                       {
+                               if(restart)
+                                       snd1 = TUBA_STARTNOTE(e.note - m);
+                               p1 = pow(2.0, m / 12.0);
+                       }
+                       else
+                       {
+                               if(restart)
+                                       snd1 = TUBA_STARTNOTE(e.note - m);
+                               f1 = 1 - m / Tuba_PitchStep;
+                               p1 = pow(2.0, m / 12.0);
+                               if(restart)
+                                       snd2 = TUBA_STARTNOTE(e.note - m + Tuba_PitchStep);
+                               f2 = m / Tuba_PitchStep;
+                               p2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
+                       }
+               }
+               else
+               {
+                       if(restart)
+                               snd1 = TUBA_STARTNOTE(e.note);
+               }
+
+               sound7(e, CH_TUBA, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0);
+               if(f2)
+                       sound7(e.enemy, CH_TUBA, snd2, e.cnt * f2, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p2, 0);
+       }
+       else
+       {
+               if(restart)
+                       snd1 = TUBA_STARTNOTE(e.note);
+               sound(e, CH_TUBA, snd1, e.cnt, e.attenuate * autocvar_g_balance_tuba_attenuation);
+       }
+}
+
 void Ent_TubaNote_Think()
 {
        float f;
@@ -16,15 +85,16 @@ void Ent_TubaNote_Think()
        if(self.cnt <= 0)
        {
                sound(self, CH_TUBA, "misc/null.wav", 0, 0);
+               if(self.enemy)
+               {
+                       sound(self.enemy, CH_TUBA, "misc/null.wav", 0, 0);
+                       remove(self.enemy);
+               }
                remove(self);
        }
        else
        {
-#ifdef PITCHSHIFT
-               sound7(self, CH_TUBA, "", self.cnt, self.attenuate * autocvar_g_balance_tuba_attenuation, 100 * pow(2.0, self.note / 12.0), 0);
-#else
-               sound(self, CH_TUBA, "", self.cnt, self.attenuate * autocvar_g_balance_tuba_attenuation);
-#endif
+               tubasound(self, 0);
        }
 }
 
@@ -33,11 +103,7 @@ void Ent_TubaNote_UpdateSound()
        self.enemy.cnt = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
        self.enemy.count = self.enemy.cnt;
        self.enemy.note = self.note;
-#ifdef PITCHSHIFT
-       sound7(self.enemy, CH_TUBA, TUBA_STARTNOTE(0), self.enemy.cnt, self.enemy.attenuate * autocvar_g_balance_tuba_attenuation, 100 * pow(2.0, self.note / 12.0), 0);
-#else
-       sound(self.enemy, CH_TUBA, TUBA_STARTNOTE(self.note), self.enemy.cnt, self.enemy.attenuate * autocvar_g_balance_tuba_attenuation);
-#endif
+       tubasound(self.enemy, 1);
 }
 
 void Ent_TubaNote_StopSound()
@@ -58,6 +124,11 @@ void Ent_TubaNote(float bIsNew)
        {
                self.enemy = spawn();
                self.enemy.classname = "tuba_note";
+               if(Tuba_PitchStep)
+               {
+                       self.enemy.enemy = spawn();
+                       self.enemy.enemy.classname = "tuba_note_2";
+               }
                bIsNew = TRUE;
        }
        if(f & 1)
@@ -67,6 +138,8 @@ void Ent_TubaNote(float bIsNew)
                self.enemy.origin_z = ReadCoord();
                setorigin(self.enemy, self.enemy.origin);
                self.enemy.attenuate = ReadByte();
+               if(self.enemy.enemy)
+                       setorigin(self.enemy.enemy, self.enemy.origin);
        }
        self.think = Ent_TubaNote_StopSound;
        self.entremove = Ent_TubaNote_StopSound;
@@ -82,13 +155,18 @@ void Ent_TubaNote(float bIsNew)
 void Tuba_Precache()
 {
        float i;
-#ifdef PITCHSHIFT
-       precache_sound(TUBA_STARTNOTE(0));
-#else
-       for(i = -18; i <= +27; ++i)
+       Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
+       if(Tuba_PitchStep)
+       {
+               if(!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7"))
+               {
+                       print("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
+                       Tuba_PitchStep = 0;
+               }
+       }
+       for(i = TUBA_MIN; i <= TUBA_MAX; ++i)
        {
-               precache_sound(TUBA_STARTNOTE(i));
+               if(!Tuba_PitchStep || (mod(i, Tuba_PitchStep) == 0))
+                       precache_sound(TUBA_STARTNOTE(i));
        }
-#endif
-       //precache_sound(""); // we want to change volume of existing sounds
 }