From 19e88bb92d048bff5257dda260b43d055dedd40a Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 7 Feb 2015 16:54:02 +1100 Subject: [PATCH] Cleanup --- qcsrc/client/tuba.qc | 202 ++++++++++++++++++++----------------------- qcsrc/client/tuba.qh | 25 +----- 2 files changed, 93 insertions(+), 134 deletions(-) diff --git a/qcsrc/client/tuba.qc b/qcsrc/client/tuba.qc index dec00043f..358fbd011 100644 --- a/qcsrc/client/tuba.qc +++ b/qcsrc/client/tuba.qc @@ -1,98 +1,94 @@ #include "tuba.qh" -void tubasound(entity e, float restart) +#define TUBA_STARTNOTE(i, n) strcat("weapons/tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n), ".wav") + +const int TUBA_MIN = -18; +const int TUBA_MAX = 27; +const int TUBA_INSTRUMENTS = 3; + +.int note; +.bool tuba_attenuate; +.float tuba_volume; +.float tuba_volume_initial; +.int tuba_instrument; + +int Tuba_PitchStep; + +void tubasound(entity e, bool 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 = e.note % Tuba_PitchStep; - if(m) - { - if(e.note - m < TUBA_MIN) - { - if(restart) + string snd1 = string_null; + if (Tuba_PitchStep) { + float vol1 = 1; + float speed1 = 1; + string snd2 = string_null; + float vol2 = 0; + float speed2 = 1; + + int m = e.note % Tuba_PitchStep; + if (m) { + if (e.note - m < TUBA_MIN) { + if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, 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) + } + speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0); + } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) { + if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m); - p1 = pow(2.0, m / 12.0); - } - else - { - if(restart) + } + speed1 = pow(2.0, m / 12.0); + } else { + if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m); - f1 = cos(M_PI_2 * m / Tuba_PitchStep); - p1 = pow(2.0, m / 12.0); - if(restart) + } + vol1 = cos(M_PI_2 * m / Tuba_PitchStep); + speed1 = pow(2.0, m / 12.0); + if (restart) { snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep); - f2 = sin(M_PI_2 * m / Tuba_PitchStep); - p2 = pow(2.0, (m - Tuba_PitchStep) / 12.0); + } + vol2 = sin(M_PI_2 * m / Tuba_PitchStep); + speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0); } - } - else - { - if(restart) - snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note); + } else if (restart) { + snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note); } - sound7(e, CH_TUBA_SINGLE, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0); - if(f2) - sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.cnt * f2, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p2, 0); - } - else - { - if(restart) + sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed1, 0); + if (vol2) { + sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed2, 0); + } + } else { + if (restart) { snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note); - sound(e, CH_TUBA_SINGLE, snd1, e.cnt, e.attenuate * autocvar_g_balance_tuba_attenuation); + } + sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation); } } void Ent_TubaNote_Think() { - float f; - f = autocvar_g_balance_tuba_fadetime; - if(f > 0) - self.cnt -= frametime * self.count / f; - else - self.cnt = 0; + float f = autocvar_g_balance_tuba_fadetime; + if (f > 0) { + self.tuba_volume -= frametime * self.tuba_volume_initial / f; + } else { + self.tuba_volume = 0; + } self.nextthink = time; - if(self.cnt <= 0) - { + if (self.tuba_volume <= 0) { sound(self, CH_TUBA_SINGLE, "misc/null.wav", 0, 0); - if(self.enemy) - { + if (self.enemy) { sound(self.enemy, CH_TUBA_SINGLE, "misc/null.wav", 0, 0); remove(self.enemy); } remove(self); - } - else - { + } else { tubasound(self, 0); } } 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.tuba_volume = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1); + self.enemy.tuba_volume_initial = self.enemy.tuba_volume; self.enemy.note = self.note; self.enemy.tuba_instrument = self.tuba_instrument; tubasound(self.enemy, 1); @@ -104,57 +100,47 @@ void Ent_TubaNote_StopSound() self.enemy = world; } -void Ent_TubaNote(float bIsNew) +void Ent_TubaNote(bool isNew) { - int f, n, i; - float att, upd; - f = ReadByte(); - - upd = 0; - - if(f & 1) - { - n = ReadChar(); - i = ReadByte(); - att = (i & 1); - i = floor(i / 2); - - if(n != self.note || i != self.tuba_instrument || bIsNew) - { - if(self.enemy) + bool upd = false; + int f = ReadByte(); + if (f & 1) { + int n = ReadChar(); + int i = ReadByte(); + bool att = (i & 1); + i >>= 1; + + if (self.enemy) { + if (n != self.note || i != self.tuba_instrument || isNew) { Ent_TubaNote_StopSound(); - } - - if(!self.enemy) - { + } + } else { self.enemy = spawn(); self.enemy.classname = "tuba_note"; - if(Tuba_PitchStep) - { + if (Tuba_PitchStep) { self.enemy.enemy = spawn(); self.enemy.enemy.classname = "tuba_note_2"; } - bIsNew = true; + isNew = true; } - self.enemy.attenuate = att; + self.enemy.tuba_attenuate = att; - if(bIsNew) - { + if (isNew) { self.note = n; self.tuba_instrument = i; - upd = 1; + upd = true; } } - if(f & 2) - { + if (f & 2) { self.enemy.origin_x = ReadCoord(); self.enemy.origin_y = ReadCoord(); self.enemy.origin_z = ReadCoord(); setorigin(self.enemy, self.enemy.origin); - if(self.enemy.enemy) + if (self.enemy.enemy) { setorigin(self.enemy.enemy, self.enemy.origin); + } } self.think = Ent_TubaNote_StopSound; @@ -162,29 +148,25 @@ void Ent_TubaNote(float bIsNew) self.enemy.think = Ent_TubaNote_Think; self.enemy.nextthink = time + 10; - if(upd) + if (upd) { Ent_TubaNote_UpdateSound(); + } } void Tuba_Precache() { - float i; - int n; Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep; - if(Tuba_PitchStep) - { - if(!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) - { + 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(n = TUBA_MIN; n <= TUBA_MAX; ++n) - { - if(!Tuba_PitchStep || ((n % Tuba_PitchStep) == 0)) - { - for(i = 0; i < TUBA_INSTRUMENTS; ++i) + for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) { + if (!Tuba_PitchStep || (n % Tuba_PitchStep) == 0) { + for (int i = 0; i < TUBA_INSTRUMENTS; ++i) { precache_sound(TUBA_STARTNOTE(i, n)); + } } } } diff --git a/qcsrc/client/tuba.qh b/qcsrc/client/tuba.qh index 81517b4e4..bdc1386ea 100644 --- a/qcsrc/client/tuba.qh +++ b/qcsrc/client/tuba.qh @@ -1,28 +1,5 @@ #ifndef TUBA_H #define TUBA_H - -const float TUBA_MIN = -18; -const float TUBA_MAX = 27; -const float TUBA_INSTRUMENTS = 3; - -#define TUBA_STARTNOTE(i,n) strcat("weapons/tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n), ".wav") -.int note; // note -.float attenuate; // if set, attenuate it -.float cnt; // current volume -.float count; // initial volume -.float tuba_instrument; - -int Tuba_PitchStep; - -void tubasound(entity e, float restart); - -void Ent_TubaNote_Think(); - -void Ent_TubaNote_UpdateSound(); - -void Ent_TubaNote_StopSound(); - -void Ent_TubaNote(float bIsNew); - +void Ent_TubaNote(bool isNew); void Tuba_Precache(); #endif -- 2.39.2