Merge branch 'TimePath/soundregistry' into 'master'
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 26 Sep 2015 11:12:45 +0000 (11:12 +0000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 26 Sep 2015 11:12:45 +0000 (11:12 +0000)
Sound registry

Destringified sounds in favor of constants

Automated precaching

Closes #1303

See merge request !226

1  2 
qcsrc/Makefile
qcsrc/lib/_all.inc
qcsrc/server/cl_player.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/t_items.qc

diff --combined qcsrc/Makefile
@@@ -2,39 -2,41 +2,41 @@@ SCM := $(shell if [ -d .svn ]; then ech
  PERL ?= perl
  QCCFLAGS_WATERMARK ?= -DWATERMARK='"$(shell git describe)"'
  QCC ?= gmqcc
 -
 + 
  QCCVERSIONFILE := qccversion.$(shell (cd server && $(QCC) --version) > qccversion.txt && git hash-object qccversion.txt)
  
  # We eventually need to get rid of these.
  QCCFLAGS_WTFS ?= \
        -Wno-field-redeclared
  
- QCCFLAGS ?= \
-       -std=gmqcc \
-       -O3 -flno \
-       -Werror -fno-bail-on-werror -Wall \
-       -fftepp -fftepp-predefs -Wcpp -futf8 -frelaxed-switch -freturn-assignments \
-       $(QCCFLAGS_WTFS) \
-       $(QCCFLAGS_FEATURES) \
-       $(QCCFLAGS_EXTRA) $(QCCFLAGS_WATERMARK)
  QCCFLAGS_FEATURES ?= \
        -DVEHICLES_ENABLED=1 \
        -DVEHICLES_USE_ODE=0 \
        -DBUILD_MOD=$(BUILD_MOD)
  
+ QCCFLAGS ?= \
+       -std=gmqcc \
+       -O3 \
+       -Werror -Wall -Wcpp \
+       $(QCCFLAGS_WTFS) \
+       -fftepp -flno -futf8 -fno-bail-on-werror -fftepp-predefs \
+       -frelaxed-switch -freturn-assignments \
+       $(QCCFLAGS_WATERMARK) \
+       $(QCCFLAGS_FEATURES) \
+       $(QCCFLAGS_EXTRA)
  # xonotic build system overrides this by command line argument to turn off the update-cvarcount step
  XON_BUILDSYSTEM =
  
- all: qc
  .PHONY: all
+ all: qc
  
  .PHONY: qc
  qc: ../menu.dat ../progs.dat ../csprogs.dat
  
  .PHONY: clean
  clean:
-       rm -f ../progs.dat ../menu.dat ../csprogs.dat server/precache-for-csqc.inc
+       rm -f ../progs.dat ../menu.dat ../csprogs.dat
  
  $(QCCVERSIONFILE):
        $(RM) qccversion.*
@@@ -45,11 -47,8 +47,8 @@@ FILES_CSPROGS = $(shell find client li
        @echo make[1]: Entering directory \`$(PWD)/client\'
        cd client && $(QCC) $(QCCFLAGS) -DCSQC
  
- server/precache-for-csqc.inc: $(FILES_CSPROGS)
-       sh collect-precache.sh
  FILES_PROGS = $(shell find server lib common warpzonelib csqcmodellib -type f -not -name fteqcc.log -not -name qc.asm)
- ../progs.dat: $(FILES_PROGS) $(QCCVERSIONFILE) server/precache-for-csqc.inc
+ ../progs.dat: $(FILES_PROGS) $(QCCVERSIONFILE)
        @echo make[1]: Entering directory \`$(PWD)/server\'
        cd server && $(QCC) $(QCCFLAGS) -DSVQC
  
diff --combined qcsrc/lib/_all.inc
@@@ -7,6 -7,7 +7,7 @@@
  #include "cvar.qh"
  #include "defer.qh"
  #include "draw.qh"
+ #include "file.qh"
  #include "i18n.qh"
  #include "lazy.qh"
  #include "log.qh"
@@@ -19,7 -20,6 +20,7 @@@
  #include "prandom.qc"
  #include "progname.qh"
  #include "registry.qh"
 +#include "replicate.qh"
  #include "sortlist.qc"
  #include "static.qh"
  #include "string.qh"
@@@ -182,11 -182,11 +182,11 @@@ void PlayerCorpseDamage (entity inflict
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
-                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
+                       sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
                else if (take > 30)
-                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
+                       sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
                else if (take > 10)
-                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
+                       sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
        }
  
        if (take > 50)
@@@ -395,11 -395,11 +395,11 @@@ void PlayerDamage (entity inflictor, en
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
-                       sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
+                       sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
                else if (take > 30)
-                       sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
+                       sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
                else if (take > 10)
-                       sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
+                       sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
        }
  
        if (take > 50)
@@@ -986,15 -986,16 +986,15 @@@ void PrecacheGlobalSound(string samples
  
  void PrecachePlayerSounds(string f)
  {
 -      float fh;
 -      string s;
 -      fh = fopen(f, FILE_READ);
 -      if(fh < 0)
 +      int fh = fopen(f, FILE_READ);
 +      if (fh < 0)
                return;
 -      while((s = fgets(fh)))
 +      for (string s; (s = fgets(fh)); )
        {
 -              if(tokenize_console(s) != 3)
 +              int n = tokenize_console(s);
 +              if (n != 3)
                {
 -                      LOG_TRACE("Invalid sound info line: ", s, "\n");
 +                      if (n != 0) LOG_TRACEF("Invalid sound info line: %s\n", s);
                        continue;
                }
                PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
@@@ -1225,7 -1226,7 +1225,7 @@@ void GlobalSound(string sample, float c
                        }
                        break;
                case VOICETYPE_PLAYERSOUND:
-                       sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
+                       _sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
                        break;
                default:
                        backtrace("Invalid voice type!");
@@@ -417,8 -417,6 +417,8 @@@ void GetCvars(float f
  
        Notification_GetCvars();
  
 +      ReplicateVars(this, s, f);
 +
        GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
        GetCvars_handleFloat(s, f, cvar_cl_autoscreenshot, "cl_autoscreenshot");
        GetCvars_handleFloat(s, f, cvar_cl_jetpack_jump, "cl_jetpack_jump");
@@@ -764,14 -762,6 +764,6 @@@ float sound_allowed(float destin, entit
      return true;
  }
  
- #undef sound
- void sound(entity e, float chan, string samp, float vol, float attenu)
- {
-     if (!sound_allowed(MSG_BROADCAST, e))
-         return;
-     sound7(e, chan, samp, vol, attenu, 0, 0);
- }
  void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float attenu)
  {
      float entno, idx;
@@@ -847,7 -837,7 +839,7 @@@ void stopsoundto(float _dest, entity e
      if (entno >= 8192 || chan < 0 || chan > 7)
      {
          float idx, sflags;
-         idx = precache_sound_index("misc/null.wav");
+         idx = precache_sound_index(SND(Null));
          sflags = SND_LARGEENTITY;
          if (idx >= 256)
              sflags |= SND_LARGESOUND;
@@@ -895,7 -885,7 +887,7 @@@ float spamsound(entity e, float chan, s
      if (time > e.spamtime)
      {
          e.spamtime = time;
-         sound(e, chan, samp, vol, _atten);
+         _sound(e, chan, samp, vol, _atten);
          return true;
      }
      return false;
@@@ -920,7 -910,7 +912,7 @@@ void play2all(string samp
      if (autocvar_bot_sound_monopoly)
          return;
  
-     sound(world, CH_INFO, samp, VOL_BASE, ATTEN_NONE);
+     _sound(world, CH_INFO, samp, VOL_BASE, ATTEN_NONE);
  }
  
  void PrecachePlayerSounds(string f);
@@@ -1013,36 -1003,8 +1005,8 @@@ void precache(
      }
  
      // gore and miscellaneous sounds
-     //precache_sound ("misc/h2ohit.wav");
-     precache_sound ("misc/armorimpact.wav");
-     precache_sound ("misc/bodyimpact1.wav");
-     precache_sound ("misc/bodyimpact2.wav");
-     precache_sound ("misc/gib.wav");
-     precache_sound ("misc/gib_splat01.wav");
-     precache_sound ("misc/gib_splat02.wav");
-     precache_sound ("misc/gib_splat03.wav");
-     precache_sound ("misc/gib_splat04.wav");
      PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
      PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
-     precache_sound ("misc/null.wav");
-     precache_sound ("misc/spawn.wav");
-     precache_sound ("misc/talk.wav");
-     precache_sound ("misc/teleport.wav");
-     precache_sound ("misc/poweroff.wav");
-     precache_sound ("player/lava.wav");
-     precache_sound ("player/slime.wav");
-     // common weapon precaches
-       precache_sound (W_Sound("reload")); // until weapons have individual reload sounds, precache the reload sound here
-     precache_sound (W_Sound("weapon_switch"));
-     precache_sound (W_Sound("weaponpickup"));
-     precache_sound (W_Sound("unavailable"));
-     precache_sound (W_Sound("dryfire"));
-     if (g_grappling_hook)
-     {
-         precache_sound (W_Sound("hook_fire")); // hook
-         precache_sound (W_Sound("hook_impact")); // hook
-     }
  
  #if 0
      // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
          ambientsound ('0 0 0', self.noise, VOL_BASE, ATTEN_NONE);
      }
  #endif
- #include "precache-for-csqc.inc"
  }
  
  
diff --combined qcsrc/server/t_items.qc
@@@ -436,11 -436,11 +436,11 @@@ void Item_Respawn (void
        Item_Show(self, 1);
        // this is ugly...
        if(self.items == ITEM_Strength.m_itemid)
-               sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTEN_NORM);    // play respawn sound
+               sound (self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTEN_NORM);   // play respawn sound
        else if(self.items == ITEM_Shield.m_itemid)
-               sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTEN_NORM);      // play respawn sound
+               sound (self, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTEN_NORM);     // play respawn sound
        else
-               sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
+               sound (self, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM);        // play respawn sound
        setorigin (self, self.origin);
  
      if (Item_ItemsTime_Allow(self.itemdef, self.weapons))
@@@ -472,24 -472,15 +472,24 @@@ void Item_RespawnCountdown (void
                if(self.count == 1)
                {
                        MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
 -                      int wpextra = 0;
 -            entity e = self.itemdef;
 -            if (e) wpextra = e.m_id;
 -                      if (self.flags & FL_WEAPON) {
 -                              entity wi = get_weaponinfo(self.weapon);
 -                              if (wi) wpextra = wi.m_id;
 -                      }
 -            entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP);
 -            wp.wp_extra = wpextra;
 +                      do {
 +                              {
 +                                      entity wi = get_weaponinfo(self.weapon);
 +                                      if (wi.m_id) {
 +                                              entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP);
 +                                              wp.wp_extra = wi.m_id;
 +                                              break;
 +                                      }
 +                              }
 +                              {
 +                                      entity ii = self.itemdef;
 +                                      if (ii.m_id) {
 +                                              entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP);
 +                                              wp.wp_extra = ii.m_id;
 +                                              break;
 +                                      }
 +                              }
 +                      } while (0);
              if(self.waypointsprite_attached)
              {
                  GameItem def = self.itemdef;
                                if(self.waypointsprite_visible_for_player(e))
                                {
                                        msg_entity = e;
-                                       soundto(MSG_ONE, this, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM);      // play respawn sound
+                                       soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM);    // play respawn sound
                                }
                        setself(this);
  
                        //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
                }
                else
-                       sound(self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
+                       sound(self, CH_TRIGGER, SND_ITEMRESPAWNCOUNTDOWN, VOL_BASE, ATTEN_NORM);        // play respawn sound
        }
  }
  
@@@ -759,7 -750,7 +759,7 @@@ void Item_Touch (void
        other.last_pickup = time;
  
        Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
-       sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTEN_NORM);
+       _sound (other, CH_TRIGGER, (self.item_pickupsound ? self.item_pickupsound : self.item_pickupsound_ent.sound_str()), VOL_BASE, ATTEN_NORM);
  
        if (self.classname == "droppedweapon")
                remove (self);
@@@ -1128,14 -1119,6 +1128,6 @@@ void StartItem (string itemmodel, strin
                precache_model (self.model);
                precache_sound (self.item_pickupsound);
  
-               precache_sound ("misc/itemrespawncountdown.wav");
-               if(itemid == ITEM_Strength.m_itemid)
-                       precache_sound ("misc/strength_respawn.wav");
-               else if(itemid == ITEM_Shield.m_itemid)
-                       precache_sound ("misc/shield_respawn.wav");
-               else
-                       precache_sound ("misc/itemrespawn.wav");
                if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
                        self.target = "###item###"; // for finding the nearest item using find()
  
@@@ -1380,7 -1363,6 +1372,6 @@@ void spawnfunc_item_health100() { spawn
  
  void spawnfunc_item_strength()
  {SELFPARAM();
-               precache_sound("weapons/strength_fire.wav");
                if(!self.strength_finished)
                        self.strength_finished = autocvar_g_balance_powerup_strength_time;
                StartItemA (ITEM_Strength);
@@@ -1434,13 -1416,6 +1425,6 @@@ void spawnfunc_target_items (void
        if(!self.superweapons_finished)
                self.superweapons_finished = autocvar_g_balance_superweapons_time;
  
-       precache_sound("misc/itempickup.wav");
-       precache_sound("misc/megahealth.wav");
-       precache_sound("misc/armor25.wav");
-       precache_sound("misc/powerup.wav");
-       precache_sound("misc/poweroff.wav");
-       precache_sound(W_Sound("weaponpickup"));
        n = tokenize_console(self.netname);
        if(argv(0) == "give")
        {
@@@ -1669,12 -1644,12 +1653,12 @@@ void GiveSound(entity e, float v0, floa
        if(v1 <= v0 - t)
        {
                if(snd_decr != "")
-                       sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
+                       _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);
+                       _sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
        }
  }
  
@@@ -1840,31 -1815,31 +1824,31 @@@ float GiveItems(entity e, float beginar
                op = OP_SET;
        }
  
-       POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, "misc/itempickup.wav", string_null);
-       POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
-       POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
-       POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, "misc/itempickup.wav", string_null);
+       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);
        for(j = WEP_FIRST; j <= WEP_LAST; ++j)
        {
                wi = get_weaponinfo(j);
                if(wi.weapon)
                {
-                       POSTGIVE_WEAPON(e, j, W_Sound("weaponpickup"), string_null);
+                       POSTGIVE_WEAPON(e, j, SND(WEAPONPICKUP), string_null);
                        if (!(save_weapons & WepSet_FromWeapon(j)))
                                if(e.weapons & WepSet_FromWeapon(j))
                                        WEP_ACTION(wi.weapon, WR_INIT);
                }
        }
-       POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
-       POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
-       POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
-       POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
-       POSTGIVE_VALUE(e, ammo_plasma, 0, "misc/itempickup.wav", string_null);
-       POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
-       POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", 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, "misc/itempickup.wav", string_null);
-       POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/armor25.wav", string_null);
-       POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/megahealth.wav", string_null);
+       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);
  
        if(e.superweapons_finished <= 0)
                if(self.weapons & WEPSET_SUPERWEAPONS)