X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fsounds%2Fsound.qh;h=45cd41f15e1041e28acdfe95d0265749db116b7f;hp=1e02758580b7a7e2c982fd36dbd3019013809a61;hb=cab88c9722dd8c504eb5d797d80c3e524ebfa08b;hpb=a853ff36bca341c4a328f97485d3b502efccc73d diff --git a/qcsrc/common/sounds/sound.qh b/qcsrc/common/sounds/sound.qh index 1e02758580..45cd41f15e 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,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; @@ -35,18 +35,17 @@ 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. #ifdef SVQC #define _sound(e, c, s, v, a) \ - do \ - { \ + MACRO_BEGIN \ entity __e = e; \ - if (!sound_allowed(MSG_BROADCAST, __e)) break; \ - sound7(__e, c, s, v, a, 0, 0); \ - } \ - while (0) + if (sound_allowed(MSG_BROADCAST, __e)) \ + sound7(__e, c, s, v, a, 0, 0); \ + MACRO_END #else #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0) #endif @@ -65,8 +64,7 @@ const float VOL_BASEVOICE = 1.0; * @param sf */ #define sound8(e, o, chan, samp, vol, atten, speed, sf) \ - do \ - { \ + MACRO_BEGIN \ entity __e; \ int __chan = chan; \ string __samp = samp; \ @@ -77,8 +75,7 @@ const float VOL_BASEVOICE = 1.0; auto = true; \ __chan = fabs(__chan); \ entity tmp = __e = new(csqc_autochannel); \ - make_pure(tmp); \ - tmp.think = SUB_Remove_self; \ + setthink(tmp, SUB_Remove); \ tmp.nextthink = time + soundlength(__samp); \ } \ vector old_origin = __e.origin; \ @@ -87,55 +84,62 @@ const float VOL_BASEVOICE = 1.0; setorigin(__e, o); \ setsize(__e, '0 0 0', '0 0 0'); \ sound7(__e, __chan, __samp, vol, atten, speed, sf); \ - if (auto) break; \ - setorigin(__e, old_origin); \ - setsize(__e, old_mins, old_maxs); \ - } \ - while (0) + if (!auto) \ + { \ + setorigin(__e, old_origin); \ + setsize(__e, old_mins, old_maxs); \ + } \ + 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; - #define extensions(x) \ - x(wav) \ - x(ogg) \ - x(flac) \ - /**/ - string relative; - #define tryext(ext) { if (fexists(strcat("sound/", relative = strcat(base, "." #ext)))) break; } - do - { - extensions(tryext); -#undef tryext -#undef extensions - LOG_WARNINGF("Missing sound: \"%s\"\n", strcat("sound/", base)); -#ifdef CSQC - return string_null; -#endif - } - while (0); -#ifdef SVQC - return strcat(base, ".wav"); // let the client engine decide -#else - return relative; -#endif - } - METHOD(Sound, sound_precache, void(entity this)) + METHOD(Sound, sound_precache, void(Sound this)) { - string s = Sound_fixpath(this); + TC(Sound, this); + string s = _Sound_fixpath(this.sound_str()); if (!s) return; - LOG_TRACEF("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()) \ +)