From cf4c335dc6cf5ba79ba44083390e6a2d431eb9ba Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 7 Nov 2015 21:02:40 +1100 Subject: [PATCH] Global sounds: register --- qcsrc/common/monsters/sv_monsters.qc | 2 +- qcsrc/common/physics.qc | 4 ++-- qcsrc/server/cl_player.qc | 10 +++++----- qcsrc/server/cl_player.qh | 25 ++++++++++++++++++++++++- qcsrc/server/defs.qh | 5 ----- qcsrc/server/miscfunctions.qc | 10 ---------- qcsrc/server/sv_main.qc | 4 ++-- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 2b55d423e..31e5d2784 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -346,7 +346,7 @@ void Monster_Sound(.string samplefield, float sound_delay, float delaytoo, float if(delaytoo) if(time < self.msound_delay) return; // too early - GlobalSound(self.(samplefield), chan, VOICETYPE_PLAYERSOUND); + _GlobalSound(self.(samplefield), chan, VOICETYPE_PLAYERSOUND); self.msound_delay = time + sound_delay; } diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 755fc0aca..b01efd32b 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -1115,9 +1115,9 @@ void PM_check_hitground() if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) { if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) - GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND); + GlobalSound(GS_FALL_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND); else - GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND); + GlobalSound(GS_FALL, CH_PLAYER, VOICETYPE_PLAYERSOUND); } } } diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index bf808d8e3..cd1ce6901 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -960,7 +960,7 @@ int Say(entity source, float teamsay, entity privatesay, string msgin, bool floo return ret; } -float GetVoiceMessageVoiceType(string type) +int GetVoiceMessageVoiceType(string type) { if (type == "taunt") return VOICETYPE_TAUNT; if (type == "teamshoot") return VOICETYPE_LASTATTACKER; @@ -1166,7 +1166,7 @@ void FakeGlobalSound(string sample, int chan, int voicetype) } } -void GlobalSound(string sample, int chan, int voicetype) +void _GlobalSound(string sample, int chan, int voicetype) { SELFPARAM(); if (sample == "") return; @@ -1238,10 +1238,10 @@ void GlobalSound(string sample, int chan, int voicetype) } } -void PlayerSound(.string samplefield, float chan, float voicetype) +void PlayerSound(.string samplefield, int chan, float voicetype) { SELFPARAM(); - GlobalSound(this.(samplefield), chan, voicetype); + _GlobalSound(this.(samplefield), chan, voicetype); } void VoiceMessage(string type, string msg) @@ -1258,7 +1258,7 @@ void VoiceMessage(string type, string msg) int flood = Say(this, ownteam, world, msg, true); void(string sample, int chan, int voicetype) f; f = (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) ? FakeGlobalSound - : (flood > 0) ? GlobalSound + : (flood > 0) ? _GlobalSound : func_null; if (f) f(this.(sample), CH_VOICE, voicetype); } diff --git a/qcsrc/server/cl_player.qh b/qcsrc/server/cl_player.qh index 83ca3282f..ef27f6a63 100644 --- a/qcsrc/server/cl_player.qh +++ b/qcsrc/server/cl_player.qh @@ -94,8 +94,31 @@ void ClearPlayerSounds(entity this); float LoadPlayerSounds(string f, bool strict); void UpdatePlayerSounds(entity this); void FakeGlobalSound(string sample, float chan, float voicetype); -void GlobalSound(string sample, float chan, float voicetype); +void _GlobalSound(string sample, float chan, float voicetype); +#define GlobalSound(def, chan, voicetype) _GlobalSound((def).m_globalsoundstr, chan, voicetype) void PlayerSound(.string samplefield, float chan, float voicetype); void VoiceMessage(string type, string msg); +.string m_globalsoundstr; +REGISTRY(GlobalSounds, BITS(8) - 1) +#define GlobalSounds_from(i) _GlobalSounds_from(i, NULL) +#define REGISTER_GLOBALSOUND(id, str) \ + REGISTER(RegisterGlobalSounds, GS, GlobalSounds, id, m_id, new(GlobalSound)) \ + { \ + make_pure(this); \ + this.m_globalsoundstr = str; \ + } +REGISTER_REGISTRY(RegisterGlobalSounds) +REGISTRY_SORT(GlobalSounds, 0) +REGISTRY_CHECK(GlobalSounds) +PRECACHE(GlobalSounds) +{ + FOREACH(GlobalSounds, true, LAMBDA(PrecacheGlobalSound(it.m_globalsoundstr))); +} + +REGISTER_GLOBALSOUND(STEP, "misc/footstep0 6") +REGISTER_GLOBALSOUND(STEP_METAL, "misc/metalfootstep0 6") +REGISTER_GLOBALSOUND(FALL, "misc/hitground 4") +REGISTER_GLOBALSOUND(FALL_METAL, "misc/metalhitground 4") + #endif diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 2a4c93966..64157162c 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -303,11 +303,6 @@ float tracebox_hits_trigger_hurt(vector start, vector mi, vector ma, vector end) float next_pingtime; -string globalsound_fall; -string globalsound_metalfall; -string globalsound_step; -string globalsound_metalstep; - const float VOICETYPE_PLAYERSOUND = 10; const float VOICETYPE_TEAMRADIO = 11; const float VOICETYPE_LASTATTACKER = 12; diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 2f459c35f..2b00fbffa 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -964,16 +964,6 @@ void precache() precache_playermodels(autocvar_sv_defaultplayermodel); } - if (g_footsteps) - { - PrecacheGlobalSound((globalsound_step = "misc/footstep0 6")); - PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6")); - } - - // gore and miscellaneous sounds - PrecacheGlobalSound((globalsound_fall = "misc/hitground 4")); - PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4")); - #if 0 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks). diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index 09c9263d7..0d5fa234f 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -159,9 +159,9 @@ void CreatureFrame () if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) { if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) - GlobalSound(globalsound_metalstep, CH_PLAYER, VOICETYPE_PLAYERSOUND); + GlobalSound(GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND); else - GlobalSound(globalsound_step, CH_PLAYER, VOICETYPE_PLAYERSOUND); + GlobalSound(GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND); } } } -- 2.39.2