X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fsounds%2Fsound.qh;h=af85fa1a332082b48d3d2d5c33345141ee274588;hp=8c4aecbda029829c753e9b1641ceeb490cc04259;hb=772fb683d951a622cc8520827096ec34fdea4763;hpb=34e7f534e2015466228eb3a78c9857741b736dca diff --git a/qcsrc/common/sounds/sound.qh b/qcsrc/common/sounds/sound.qh index 8c4aecbda..af85fa1a3 100644 --- a/qcsrc/common/sounds/sound.qh +++ b/qcsrc/common/sounds/sound.qh @@ -22,10 +22,11 @@ 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; +const float ATTEN_LOW = 0.2; const float ATTEN_NORM = 0.5; const float ATTEN_LARGE = 1; const float ATTEN_IDLE = 2; @@ -41,11 +42,10 @@ const float VOL_MUFFLED = 0.35; #ifdef SVQC #define _sound(e, c, s, v, a) \ MACRO_BEGIN \ - { \ entity __e = e; \ if (sound_allowed(MSG_BROADCAST, __e)) \ sound7(__e, c, s, v, a, 0, 0); \ - } MACRO_END + MACRO_END #else #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0) #endif @@ -65,7 +65,6 @@ const float VOL_MUFFLED = 0.35; */ #define sound8(e, o, chan, samp, vol, atten, speed, sf) \ MACRO_BEGIN \ - { \ entity __e; \ int __chan = chan; \ string __samp = samp; \ @@ -90,42 +89,57 @@ const float VOL_MUFFLED = 0.35; setorigin(__e, old_origin); \ setsize(__e, old_mins, old_maxs); \ } \ - } MACRO_END + 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()); + 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_WARNF("Missing sound: \"%s\"", 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; profile(sprintf("precache_sound(\"%s\")", s)); precache_sound(s); + strcpy(this.sound_str_, s); } ENDCLASS(Sound) + +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()) \ +)