]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Sound_fixpath: reduce server load
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 6 Jan 2016 21:53:51 +0000 (08:53 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 6 Jan 2016 22:06:40 +0000 (09:06 +1100)
qcsrc/common/sounds/all.qh
qcsrc/common/sounds/sound.qh
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh

index 8225db7368c30f5593c2c1e435897b0123cbb8d5..02098e8755dc805eec8e8a4605544ca5df34b719 100644 (file)
@@ -11,7 +11,7 @@ REGISTER_REGISTRY(Sounds)
     string SND_##name##_get() { return path; } \
     REGISTER(Sounds, SND, name, m_id, NEW(Sound, SND_##name##_get))
 
-// Used in places where a string is required
+/** @deprecated Used in places where a string is required for legacy reasons, prefer using SND_id constants instead */
 #define SND(id) Sound_fixpath(SND_##id)
 
 PRECACHE(Sounds) {
index 7e9ba263240f759de67320a778bbc9137612edea..53185b0fb5f168a6953706e96baadafa67592f0a 100644 (file)
@@ -105,28 +105,20 @@ 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 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;
+               #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))
index 72bfafd125460dd040405514e5cf1b3f8cdeca56..33ce76c02f859573b5a9c9a4de66d847f71cfd7e 100644 (file)
@@ -1610,19 +1610,19 @@ float GiveWeapon(entity e, float wpn, float op, float val)
        return (v0 != v1);
 }
 
-void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
+void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
 {
        if(v1 == v0)
                return;
        if(v1 <= v0 - t)
        {
-               if(snd_decr != "")
-                       _sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
+               if(snd_decr != NULL)
+                       sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
        }
        else if(v0 >= v0 + t)
        {
-               if(snd_incr != "")
-                       _sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
+               if(snd_incr != NULL)
+                       sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
        }
 }
 
@@ -1780,26 +1780,26 @@ float GiveItems(entity e, float beginarg, float endarg)
                op = OP_SET;
        }
 
-       POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND(ITEMPICKUP), string_null);
-       POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND(POWERUP), SND(POWEROFF));
-       POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND(POWERUP), SND(POWEROFF));
-       POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null);
+       POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
+       POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND_POWERUP, SND_POWEROFF);
+       POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
        FOREACH(Weapons, it != WEP_Null, LAMBDA(
-               POSTGIVE_WEAPON(e, it, SND(WEAPONPICKUP), string_null);
+               POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
                if(!(save_weapons & (it.m_wepset)))
                        if(e.weapons & (it.m_wepset))
                                it.wr_init(it);
        ));
-       POSTGIVE_VALUE(e, strength_finished, 1, SND(POWERUP), SND(POWEROFF));
-       POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", SND(POWEROFF));
-       POSTGIVE_VALUE(e, ammo_nails, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_cells, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_plasma, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_shells, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_rockets, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(ARMOR25), string_null);
-       POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(MEGAHEALTH), string_null);
+       POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
+       POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
+       POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null);
+       POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null);
 
        if(e.superweapons_finished <= 0)
                if(self.weapons & WEPSET_SUPERWEAPONS)
index 1dc79f8cc24266cf9250bf46f9cf81a89d7cb4a0..86e5c7c8ea1084239c5080344d2370d6ceb9bb33 100644 (file)
@@ -123,7 +123,7 @@ float GiveBit(entity e, .float fld, float bit, float op, float val);
 
 float GiveValue(entity e, .float fld, float op, float val);
 
-void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr);
+void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr);
 
 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime);