X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Feffects%2Fqc%2Fglobalsound.qc;h=8e671b17d755c574d72c8eac4c0b997567154cca;hb=d9d13627b0c82a96dab08c2f3cd2d966d5425ea8;hp=c3aaf62d46d7e91d5c78679585c82d471374665f;hpb=926ed1b0236982412cf330acad1298e0581e4e6e;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index c3aaf62d4..8e671b17d 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -2,25 +2,25 @@ #include -#ifdef IMPLEMENTATION #include #ifdef SVQC #include #endif + #ifdef CSQC + #include + #endif REGISTER_NET_TEMP(globalsound) REGISTER_NET_TEMP(playersound) - string GlobalSound_sample(string pair, float r); - #ifdef SVQC /** * @param from the source entity, its position is sent * @param gs the global sound def * @param r a random number in 0..1 */ - void globalsound(int channel, entity from, entity gs, float r, int chan, float _vol, float _atten) + void globalsound(int channel, entity from, entity gs, float r, int chan, float _vol, float _atten, float _pitch) { //assert(IS_PLAYER(from), eprint(from)); if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return; @@ -28,14 +28,16 @@ string sample = GlobalSound_sample(gs.m_globalsoundstr, r); switch (channel) { case MSG_ONE: - soundto(channel, from, chan, sample, _vol, _atten); + soundto(channel, from, chan, sample, _vol, _atten, _pitch); break; case MSG_ALL: - _sound(from, chan, sample, _vol, _atten); + if(sound_allowed(MSG_BROADCAST, from)) + sound7(from, chan, sample, _vol, _atten, _pitch, 0); break; } return; } + // FIXME: pitch not implemented WriteHeader(channel, globalsound); WriteByte(channel, gs.m_id); WriteByte(channel, r * 255); @@ -45,9 +47,7 @@ WriteByte(channel, floor(_atten * 64)); entcs_force_origin(from); vector o = from.origin + 0.5 * (from.mins + from.maxs); - WriteCoord(channel, o.x); - WriteCoord(channel, o.y); - WriteCoord(channel, o.z); + WriteVector(channel, o); } /** @@ -55,7 +55,7 @@ * @param ps the player sound def * @param r a random number in 0..1 */ - void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten) + void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten, float _pitch) { //assert(IS_PLAYER(from), eprint(from)); if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return; @@ -65,14 +65,16 @@ string sample = GlobalSound_sample(s, r); switch (channel) { case MSG_ONE: - soundto(channel, from, chan, sample, _vol, _atten); + soundto(channel, from, chan, sample, _vol, _atten, _pitch); break; case MSG_ALL: - _sound(from, chan, sample, _vol, _atten); + if(sound_allowed(MSG_BROADCAST, from)) + sound7(from, chan, sample, _vol, _atten, _pitch, 0); break; } return; } + // FIXME: pitch not implemented WriteHeader(channel, playersound); WriteByte(channel, ps.m_id); WriteByte(channel, r * 255); @@ -82,9 +84,7 @@ WriteByte(channel, floor(_atten * 64)); entcs_force_origin(from); vector o = from.origin + 0.5 * (from.mins + from.maxs); - WriteCoord(channel, o.x); - WriteCoord(channel, o.y); - WriteCoord(channel, o.z); + WriteVector(channel, o); } #endif @@ -92,7 +92,7 @@ NET_HANDLE(globalsound, bool isnew) { - entity gs = GlobalSounds_from(ReadByte()); + entity gs = REGISTRY_GET(GlobalSounds, ReadByte()); float r = ReadByte() / 255; string sample = GlobalSound_sample(gs.m_globalsoundstr, r); int who = ReadByte(); @@ -100,10 +100,7 @@ int chan = ReadSByte(); float vol = ReadByte() / 255; float atten = ReadByte() / 64; - vector o; - o.x = ReadCoord(); - o.y = ReadCoord(); - o.z = ReadCoord(); + vector o = ReadVector(); // TODO: is this really what we want to be doing? Footsteps that follow the player at head height? if (who == player_currententnum) e = findfloat(NULL, entnum, who); // play at camera position for full volume else if (e) e.origin = o; @@ -122,7 +119,7 @@ NET_HANDLE(playersound, bool isnew) { - entity ps = PlayerSounds_from(ReadByte()); + entity ps = REGISTRY_GET(PlayerSounds, ReadByte()); float r = ReadByte() / 255; int who = ReadByte(); entity e = entcs_receiver(who - 1); @@ -132,10 +129,7 @@ int chan = ReadSByte(); float vol = ReadByte() / 255; float atten = ReadByte() / 64; - vector o; - o.x = ReadCoord(); - o.y = ReadCoord(); - o.z = ReadCoord(); + vector o = ReadVector(); if (who == player_currententnum) e = findfloat(NULL, entnum, who); // play at camera position for full volume else if (e) e.origin = o; if (e) @@ -168,6 +162,18 @@ return sample; } + float GlobalSound_pitch(float _pitch) + { + // customizable gradient function that crosses (0,a), (c,1) and asymptotically approaches b + float a = 1.5; // max pitch + float b = 0.75; // min pitch + float c = 100; // standard pitch (scale * 100) + float d = _pitch; + float pitch_shift = (b*d*(a-1) + a*c*(1-b)) / (d*(a-1) + c*(1-b)); + + return pitch_shift * 100; + } + void PrecacheGlobalSound(string sample) { int n; @@ -250,8 +256,7 @@ .string fld = it.m_playersoundfld; if (this.(fld)) { - strunzone(this.(fld)); - this.(fld) = string_null; + strfree(this.(fld)); } }); } @@ -277,13 +282,12 @@ if (GetPlayerSoundSampleField_notFound) field = GetVoiceMessageSampleField(key); if (GetPlayerSoundSampleField_notFound) { - LOG_TRACEF("Invalid sound info field: %s", key); + LOG_TRACEF("Invalid sound info field in player sound file '%s': %s", f, key); continue; } string file = argv(1); string variants = argv(2); - if (this.(field)) strunzone(this.(field)); - this.(field) = strzone(strcat(file, " ", variants)); + strcpy(this.(field), strcat(file, " ", variants)); } fclose(fh); return true; @@ -297,16 +301,15 @@ void UpdatePlayerSounds(entity this) { if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) return; - if (this.model_for_playersound) strunzone(this.model_for_playersound); - this.model_for_playersound = strzone(this.model); + strcpy(this.model_for_playersound, this.model); this.skin_for_playersound = this.skin; ClearPlayerSounds(this); LoadPlayerSounds(this, "sound/player/default.sounds", true); if (this.model == "null" #ifdef SVQC - && autocvar_g_debug_globalsounds + && autocvar_g_debug_globalsounds #endif - ) return; + ) return; if (autocvar_g_debug_defaultsounds) return; if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) return; LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true); @@ -321,6 +324,8 @@ if (gs == NULL && ps == NULL && sample == "") return; if(this.classname == "body") return; float r = random(); + float myscale = ((this.scale) ? this.scale : 1); // safety net + float thepitch = ((myscale == 1) ? 0 : GlobalSound_pitch(myscale * 100)); if (sample != "") sample = GlobalSound_sample(sample, r); switch (voicetype) { @@ -334,18 +339,18 @@ if (IS_REAL_CLIENT(msg_entity)) { float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); - else soundto(MSG_ONE, this, chan, sample, vol, atten); + if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten, thepitch); + else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten, thepitch); + else soundto(MSG_ONE, this, chan, sample, vol, atten, thepitch); } } if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break; msg_entity = this; if (IS_REAL_CLIENT(msg_entity)) { - if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASE, ATTEN_NONE); - else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASE, ATTEN_NONE); - else soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE); + if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASE, ATTEN_NONE, thepitch); + else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASE, ATTEN_NONE, thepitch); + else soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE, thepitch); } break; } @@ -353,12 +358,11 @@ { #define X() \ MACRO_BEGIN \ - { \ float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \ - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); \ - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); \ - else soundto(MSG_ONE, this, chan, sample, vol, atten); \ - } MACRO_END + if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten, thepitch); \ + else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten, thepitch); \ + else soundto(MSG_ONE, this, chan, sample, vol, atten, thepitch); \ + MACRO_END if (fake) { msg_entity = this; X(); } else @@ -368,33 +372,37 @@ X(); }); } - #undef X + #undef X break; } case VOICETYPE_AUTOTAUNT: case VOICETYPE_TAUNT: { - if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) { break; }else {} - else if (IS_PLAYER(this) && !IS_DEAD(this)) animdecide_setaction(this, ANIMACTION_TAUNT, - true); - if (!sv_taunt) break; + if (voicetype == VOICETYPE_AUTOTAUNT) + { + if (!autocvar_sv_autotaunt) break; + } + else if (IS_PLAYER(this) && !IS_DEAD(this)) + animdecide_setaction(this, ANIMACTION_TAUNT, true); + + if (!autocvar_sv_taunt) break; if (autocvar_sv_gentle) break; float tauntrand = 0; if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random(); + #define X() \ MACRO_BEGIN \ - { \ if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < CS(msg_entity).cvar_cl_autotaunt) \ { \ float atten = (CS(msg_entity).cvar_cl_voice_directional >= 1) \ - ? bound(ATTEN_MIN, CS(msg_entity).cvar_cl_voice_directional_taunt_attenuation, \ + ? bound(ATTEN_MIN, CS(msg_entity).cvar_cl_voice_directional_taunt_attenuation, \ ATTEN_MAX) \ : ATTEN_NONE; \ - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); \ - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); \ - else soundto(MSG_ONE, this, chan, sample, vol, atten); \ + if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten, thepitch); \ + else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten, thepitch); \ + else soundto(MSG_ONE, this, chan, sample, vol, atten, thepitch); \ } \ - } MACRO_END + MACRO_END if (fake) { msg_entity = this; @@ -407,7 +415,7 @@ X(); }); } - #undef X + #undef X break; } case VOICETYPE_PLAYERSOUND: @@ -415,15 +423,15 @@ msg_entity = this; if (fake) { - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, ATTEN_NORM); - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, ATTEN_NORM); - else soundto(MSG_ONE, this, chan, sample, vol, ATTEN_NORM); + if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, ATTEN_NORM, thepitch); + else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, ATTEN_NORM, thepitch); + else soundto(MSG_ONE, this, chan, sample, vol, ATTEN_NORM, thepitch); } else { - if (gs) globalsound(MSG_ALL, this, gs, r, chan, vol, ATTEN_NORM); - else if (ps) playersound(MSG_ALL, this, ps, r, chan, vol, ATTEN_NORM); - else _sound(this, chan, sample, vol, ATTEN_NORM); + if (gs) globalsound(MSG_ALL, this, gs, r, chan, vol, ATTEN_NORM, thepitch); + else if (ps) playersound(MSG_ALL, this, ps, r, chan, vol, ATTEN_NORM, thepitch); + else if (sound_allowed(MSG_BROADCAST, this)) sound7(this, chan, sample, vol, ATTEN_NORM, thepitch, 0); } break; } @@ -436,4 +444,3 @@ } #endif -#endif