make csqc entity sounds follow their entity
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 15 Jan 2009 13:19:07 +0000 (13:19 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 15 Jan 2009 13:19:07 +0000 (13:19 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8653 d7cf8633-e32d-0410-b094-e92efae38249

csprogs.c
csprogs.h
snd_main.c

index 2bf1941..3961e6b 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -13,6 +13,7 @@
 #define CSQC_RETURNVAL prog->globals.generic[OFS_RETURN]
 #define CSQC_BEGIN             csqc_tmpprog=prog;prog=0;PRVM_SetProg(PRVM_CLIENTPROG);
 #define CSQC_END               prog=csqc_tmpprog;
+
 static prvm_prog_t *csqc_tmpprog;
 
 //[515]: these are required funcs
@@ -926,3 +927,27 @@ void CL_VM_ShutDown (void)
        Con_Print("CSQC ^1unloaded\n");
        cl.csqc_loaded = false;
 }
+
+qboolean CL_VM_GetEntitySoundOrigin(int entnum, vec3_t out)
+{
+       prvm_edict_t *ed;
+       dp_model_t *mod;
+       qboolean r = 0;
+
+       CSQC_BEGIN;
+
+       ed = PRVM_EDICT_NUM(entnum - 32768);
+
+       if(!ed->priv.required->free)
+       {
+               mod = CL_GetModelFromEdict(ed);
+               VectorCopy(ed->fields.client->origin, out);
+               if (mod && mod->soundfromcenter)
+                       VectorMAMAM(1.0f, out, 0.5f, mod->normalmins, 0.5f, mod->normalmaxs, out);
+               r = 1;
+       }
+
+       CSQC_END;
+
+       return r;
+}
index 24856dd..7a4394c 100644 (file)
--- a/csprogs.h
+++ b/csprogs.h
@@ -55,4 +55,6 @@ extern cvar_t csqc_progsize;
 
 qboolean MakeDownloadPacket(const char *filename, unsigned char *data, unsigned long len, int crc, int cnt, sizebuf_t *buf, int protocol);
 
+qboolean CL_VM_GetEntitySoundOrigin(int entnum, vec3_t out);
+
 #endif
index 001af19..cd30df0 100644 (file)
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "snd_main.h"
 #include "snd_ogg.h"
 #include "snd_modplug.h"
+#include "csprogs.h"
 
 
 #define SND_MIN_SPEED 8000
@@ -1246,7 +1247,9 @@ void SND_Spatialize(channel_t *ch, qboolean isstatic)
        {
                if (ch->entnum >= 32768)
                {
-                       // TODO: sounds that follow CSQC entities?
+                       //Con_Printf("-- entnum %i origin %f %f %f neworigin %f %f %f\n", ch->entnum, ch->origin[0], ch->origin[1], ch->origin[2], cl.entities[ch->entnum].state_current.origin[0], cl.entities[ch->entnum].state_current.origin[1], cl.entities[ch->entnum].state_current.origin[2]);
+
+                       CL_VM_GetEntitySoundOrigin(ch->entnum, ch->origin);
                }
                else if (cl.entities[ch->entnum].state_current.active)
                {