]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/sounds/sound.qh
Greatly reduce amount of hidden spam when changing maps, also fix uses of self in...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / sounds / sound.qh
index 36bdaa833085db167c5190b946d7a701e5592faa..7225cef825ccb4ef2df20c0f4911542a88f37f2e 100644 (file)
@@ -1,22 +1,29 @@
 #ifndef SOUND_H
 #define SOUND_H
 
+// negative = SVQC autochannels
+// positive = one per entity
+
 const int CH_INFO = 0;
-const int CH_TRIGGER = -3;
 const int CH_WEAPON_A = -1;
+const int CH_WEAPON_B = -1;
 const int CH_WEAPON_SINGLE = 1;
 const int CH_VOICE = -2;
-const int CH_BGM_SINGLE = 8;
-const int CH_AMBIENT = -9;
+// const int CH_VOICE_SINGLE = 2;
+const int CH_TRIGGER = -3;
 const int CH_TRIGGER_SINGLE = 3;
 const int CH_SHOTS = -4;
 const int CH_SHOTS_SINGLE = 4;
-const int CH_WEAPON_B = -1;
+// const int CH_TUBA = -5;
+const int CH_TUBA_SINGLE = 5;
 const int CH_PAIN = -6;
 const int CH_PAIN_SINGLE = 6;
 const int CH_PLAYER = -7;
 const int CH_PLAYER_SINGLE = 7;
-const int CH_TUBA_SINGLE = 5;
+// const int CH_BGM_SINGLE = -8;
+const int CH_BGM_SINGLE = 8;
+const int CH_AMBIENT = -9;
+// const int CH_AMBIENT_SINGLE = 9;
 
 const float ATTEN_NONE = 0;
 const float ATTEN_MIN = 0.015625;
@@ -33,13 +40,12 @@ const float VOL_BASEVOICE = 1.0;
 // 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
@@ -58,19 +64,33 @@ const float VOL_BASEVOICE = 1.0;
  * @param sf
  */
 #define sound8(e, o, chan, samp, vol, atten, speed, sf) \
-       do \
+       MACRO_BEGIN \
        { \
-               entity __e = e; \
+               entity __e; \
+               int __chan = chan; \
+               string __samp = samp; \
+               bool auto = false; \
+               if (__chan > 0) __e = e; \
+               else \
+               { \
+                       auto = true; \
+                       __chan = fabs(__chan); \
+                       entity tmp = __e = new(csqc_autochannel); \
+                       tmp.think = SUB_Remove_self; \
+                       tmp.nextthink = time + soundlength(__samp); \
+               } \
                vector old_origin = __e.origin; \
                vector old_mins = __e.mins; \
                vector old_maxs = __e.maxs; \
                setorigin(__e, o); \
                setsize(__e, '0 0 0', '0 0 0'); \
-               sound7(__e, chan, samp, vol, atten, speed, sf); \
-               setorigin(__e, old_origin); \
-               setsize(__e, old_mins, old_maxs); \
-       } \
-       while (0)
+               sound7(__e, __chan, __samp, vol, atten, speed, sf); \
+               if (!auto) \
+               { \
+                       setorigin(__e, old_origin); \
+                       setsize(__e, old_mins, old_maxs); \
+               } \
+       } MACRO_END
 
 CLASS(Sound, Object)
        ATTRIB(Sound, m_id, int, 0)
@@ -84,29 +104,27 @@ CLASS(Sound, Object)
        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) \
                        /**/
-               string full, relative;
-               #define tryext(ext) { if (fexists(full = strcat("sound/", relative = strcat(base, "." #ext)))) break; }
-               do
-               {
-                       extensions(tryext);
-#undef tryext
-#undef extensions
-                       LOG_WARNINGF("Missing sound: \"%s\"\n", full);
-                       return string_null;
-               }
-               while (0);
-               return relative;
+               #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(entity this))
        {
                string s = Sound_fixpath(this);
                if (!s) return;
-               LOG_TRACEF("precache_sound(\"%s\")\n", s);
+               LOG_DEBUGF("precache_sound(\"%s\")\n", s);
                precache_sound(s);
        }
 ENDCLASS(Sound)