X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fsounds%2Fsound.qh;h=49cfb4488c9e478f7bf90dddf95c7787a143d62e;hb=77ffd30cbf1e94a546f70026e69e56e8d777ba83;hp=90b2758aca3569e841d6cfa185ca2a556847bd2d;hpb=8ba1f6c672361186033b8bebc3be677ac94bd4da;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/sounds/sound.qh b/qcsrc/common/sounds/sound.qh index 90b2758ac..49cfb4488 100644 --- a/qcsrc/common/sounds/sound.qh +++ b/qcsrc/common/sounds/sound.qh @@ -1,5 +1,4 @@ -#ifndef SOUND_H -#define SOUND_H +#pragma once // negative = SVQC autochannels // positive = one per entity @@ -23,7 +22,7 @@ const int CH_PLAYER_SINGLE = 7; // const int CH_BGM_SINGLE = -8; const int CH_BGM_SINGLE = 8; const int CH_AMBIENT = -9; -// const int CH_AMBIENT_SINGLE = 9; +const int CH_AMBIENT_SINGLE = 9; const float ATTEN_NONE = 0; const float ATTEN_MIN = 0.015625; @@ -35,6 +34,7 @@ const float ATTEN_MAX = 3.984375; const float VOL_BASE = 0.7; const float VOL_BASEVOICE = 1.0; +const float VOL_MUFFLED = 0.35; // Play all sounds via sound7, for access to the extra channels. // Otherwise, channels 8 to 15 would be blocked for a weird QW feature. @@ -92,42 +92,55 @@ const float VOL_BASEVOICE = 1.0; } \ } MACRO_END +string _Sound_fixpath(string base) +{ + if (base == "") return string_null; +#ifdef SVQC + return strcat(base, ".wav"); // let the client engine decide +#else +#define extensions(x) \ + x(wav) \ + x(ogg) \ + x(flac) \ + /**/ +#define tryext(ext) { \ + string s = strcat(base, "." #ext); \ + if (fexists(strcat("sound/", s))) { \ + return s; \ + } \ + } + extensions(tryext); + LOG_WARNF("Missing sound: \"%s\"", strcat("sound/", base)); +#undef tryext +#undef extensions + return string_null; +#endif +} + CLASS(Sound, Object) - ATTRIB(Sound, m_id, int, 0) - ATTRIB(Sound, sound_str, string(), func_null) + ATTRIB(Sound, m_id, int, 0); + ATTRIB(Sound, sound_str, string()); + ATTRIB(Sound, sound_str_, string); CONSTRUCTOR(Sound, string() path) { CONSTRUCT(Sound); this.sound_str = path; } - #define Sound_fixpath(this) _Sound_fixpath((this).sound_str()) - string _Sound_fixpath(string base) - { - if (base == "") return string_null; -#ifdef SVQC - return strcat(base, ".wav"); // let the client engine decide -#else - #define extensions(x) \ - x(wav) \ - x(ogg) \ - x(flac) \ - /**/ - #define tryext(ext) { string s = strcat(base, "." #ext); if (fexists(strcat("sound/", s))) return s; } - extensions(tryext); - LOG_WARNINGF("Missing sound: \"%s\"\n", strcat("sound/", base)); - #undef tryext - #undef extensions - return string_null; -#endif - } METHOD(Sound, sound_precache, void(Sound this)) { - TC(Sound, this); - string s = Sound_fixpath(this); + TC(Sound, this); + string s = _Sound_fixpath(this.sound_str()); if (!s) return; - LOG_DEBUGF("precache_sound(\"%s\")\n", s); + profile(sprintf("precache_sound(\"%s\")", s)); precache_sound(s); + strcpy(this.sound_str_, s); } ENDCLASS(Sound) -#endif +entity _Sound_fixpath_this; +string _Sound_fixpath_cached; +#define Sound_fixpath(this) ( \ + _Sound_fixpath_this = (this), \ + _Sound_fixpath_cached = _Sound_fixpath_this.sound_str_, \ + _Sound_fixpath_cached ? _Sound_fixpath_cached : _Sound_fixpath(_Sound_fixpath_this.sound_str()) \ +)