From: TimePath Date: Thu, 24 Dec 2015 09:20:35 +0000 (+1100) Subject: tuba: move to common X-Git-Tag: xonotic-v0.8.2~1391 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2b2e1f680d36476da2f4cfebe9e534577c5efe48;p=xonotic%2Fxonotic-data.pk3dir.git tuba: move to common --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index e436052f9..fad35276c 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -8,7 +8,6 @@ #include "quickmenu.qh" #include "scoreboard.qh" #include "shownames.qh" -#include "tuba.qh" #include "../common/t_items.qh" #include "wall.qh" #include "weapons/projectile.qh" diff --git a/qcsrc/client/progs.inc b/qcsrc/client/progs.inc index fa6728d3b..0f95ad580 100644 --- a/qcsrc/client/progs.inc +++ b/qcsrc/client/progs.inc @@ -15,7 +15,6 @@ #include "scoreboard.qc" #include "shownames.qc" #include "teamradar.qc" -#include "tuba.qc" #include "view.qc" #include "wall.qc" diff --git a/qcsrc/client/tuba.qc b/qcsrc/client/tuba.qc deleted file mode 100644 index 8f8fc4db5..000000000 --- a/qcsrc/client/tuba.qc +++ /dev/null @@ -1,174 +0,0 @@ -#include "tuba.qh" - -#include "../common/constants.qh" - - -#define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n)))) - -const int TUBA_MIN = -18; -const int TUBA_MAX = 27; -const int TUBA_INSTRUMENTS = 3; - -class(Tuba) .int note; -class(Tuba) .bool tuba_attenuate; -class(Tuba) .float tuba_volume; -class(Tuba) .float tuba_volume_initial; -class(Tuba) .int tuba_instrument; - -int Tuba_PitchStep; - -void tubasound(entity e, bool 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 = pymod(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); - } - 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); - } - speed1 = pow(2.0, m / 12.0); - } else { - if (restart) { - snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m); - } - 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); - } - 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); - } - - 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.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation); - } -} - -void Ent_TubaNote_Think() -{SELFPARAM(); - 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.tuba_volume <= 0) { - sound(self, CH_TUBA_SINGLE, SND_Null, 0, 0); - if (self.enemy) { - sound(self.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0); - remove(self.enemy); - } - remove(self); - } else { - tubasound(self, 0); - } -} - -void Ent_TubaNote_UpdateSound() -{SELFPARAM(); - 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); -} - -void Ent_TubaNote_StopSound() -{SELFPARAM(); - self.enemy.nextthink = time; - self.enemy = world; -} - -NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew) -{ - 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(); - } - } else { - self.enemy = new(tuba_note); - if (Tuba_PitchStep) { - self.enemy.enemy = new(tuba_note_2); - } - isNew = true; - } - - self.enemy.tuba_attenuate = att; - - if (isNew) { - self.note = n; - self.tuba_instrument = i; - upd = true; - } - } - - 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) { - setorigin(self.enemy.enemy, self.enemy.origin); - } - } - - self.think = Ent_TubaNote_StopSound; - self.entremove = Ent_TubaNote_StopSound; - self.enemy.think = Ent_TubaNote_Think; - self.enemy.nextthink = time + 10; - - if (upd) { - Ent_TubaNote_UpdateSound(); - } - return true; -} - -PRECACHE(Tuba) -{ - Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep; - if (Tuba_PitchStep) { - if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) { - LOG_INFO("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n"); - Tuba_PitchStep = 0; - } - } - for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) { - 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/client/tuba.qh b/qcsrc/client/tuba.qh deleted file mode 100644 index 0a310c359..000000000 --- a/qcsrc/client/tuba.qh +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef CLIENT_TUBA_H -#define CLIENT_TUBA_H - -entityclass(Tuba); - -#endif diff --git a/qcsrc/common/weapons/weapon/tuba.qc b/qcsrc/common/weapons/weapon/tuba.qc index 084c5cff4..bb750d721 100644 --- a/qcsrc/common/weapons/weapon/tuba.qc +++ b/qcsrc/common/weapons/weapon/tuba.qc @@ -54,6 +54,7 @@ REGISTER_WEAPON(TUBA, tuba, NEW(Tuba)); .vector tuba_lastnotes[MAX_TUBANOTES]; #endif #endif + #ifdef IMPLEMENTATION #ifdef SVQC spawnfunc(weapon_tuba) { weapon_defaultspawnfunc(this, WEP_TUBA); } @@ -459,5 +460,180 @@ void W_Tuba_NoteOn(float hittype) return WEAPON_TUBA_MURDER; } +#endif + +#ifdef CSQC + +#define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n)))) + +const int TUBA_MIN = -18; +const int TUBA_MAX = 27; +const int TUBA_INSTRUMENTS = 3; + +entityclass(Tuba); +class(Tuba) .int note; +class(Tuba) .bool tuba_attenuate; +class(Tuba) .float tuba_volume; +class(Tuba) .float tuba_volume_initial; +class(Tuba) .int tuba_instrument; + +int Tuba_PitchStep; + +void tubasound(entity e, bool 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 = pymod(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); + } + 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); + } + speed1 = pow(2.0, m / 12.0); + } else { + if (restart) { + snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m); + } + 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); + } + 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); + } + + 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.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation); + } +} + +void Ent_TubaNote_Think() +{SELFPARAM(); + 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.tuba_volume <= 0) { + sound(self, CH_TUBA_SINGLE, SND_Null, 0, 0); + if (self.enemy) { + sound(self.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0); + remove(self.enemy); + } + remove(self); + } else { + tubasound(self, 0); + } +} + +void Ent_TubaNote_UpdateSound() +{SELFPARAM(); + 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); +} + +void Ent_TubaNote_StopSound() +{SELFPARAM(); + self.enemy.nextthink = time; + self.enemy = world; +} + +NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew) +{ + 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(); + } + } else { + self.enemy = new(tuba_note); + if (Tuba_PitchStep) { + self.enemy.enemy = new(tuba_note_2); + } + isNew = true; + } + + self.enemy.tuba_attenuate = att; + + if (isNew) { + self.note = n; + self.tuba_instrument = i; + upd = true; + } + } + + 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) { + setorigin(self.enemy.enemy, self.enemy.origin); + } + } + + self.think = Ent_TubaNote_StopSound; + self.entremove = Ent_TubaNote_StopSound; + self.enemy.think = Ent_TubaNote_Think; + self.enemy.nextthink = time + 10; + + if (upd) { + Ent_TubaNote_UpdateSound(); + } + return true; +} + +PRECACHE(Tuba) +{ + Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep; + if (Tuba_PitchStep) { + if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) { + LOG_INFO("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n"); + Tuba_PitchStep = 0; + } + } + for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) { + if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) { + for (int i = 0; i < TUBA_INSTRUMENTS; ++i) { + precache_sound(TUBA_STARTNOTE(i, n)); + } + } + } +} + #endif #endif