]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added network protocol for sound speed
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Sep 2011 08:56:11 +0000 (08:56 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 16 Sep 2011 08:56:11 +0000 (08:56 +0000)
(ushort speed*4000, not compatible with FTEQW, different flag)
added optional pitchchange parameter to pointsound

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11355 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
protocol.h
server.h
sv_main.c
sv_phys.c
svvm_cmds.c

index 3d56d11199524f718b880249a9707b05a3952524..18f00dcfe48f8b3285ea5420ecfa97ae53dbf04f 100644 (file)
@@ -210,6 +210,7 @@ void CL_ParseStartSoundPacket(int largesoundindex)
        int     volume;
        int     field_mask;
        float   attenuation;
+       float   speed;
 
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
        {
@@ -224,6 +225,8 @@ void CL_ParseStartSoundPacket(int largesoundindex)
                        attenuation = MSG_ReadByte () / 64.0;
                else
                        attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
+       
+               speed = 1.0f;
 
                ent = (channel>>3)&1023;
                channel &= 7;
@@ -244,6 +247,11 @@ void CL_ParseStartSoundPacket(int largesoundindex)
                else
                        attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
 
+               if (field_mask & SND_SPEEDUSHORT4000)
+                       speed = ((unsigned short)MSG_ReadShort ()) / 4000.0f;
+               else
+                       speed = 1.0f;
+
                if (field_mask & SND_LARGEENTITY)
                {
                        ent = (unsigned short) MSG_ReadShort ();
index 50a5215b826b7e4db30b9709becccf230b28099a..9d694f0f10eb397eb9c2e503a237e9c82ed8018f 100644 (file)
@@ -165,6 +165,7 @@ void Protocol_Names(char *buffer, size_t buffersize);
 #define        SND_LOOPING             (1<<2)          // a long
 #define        SND_LARGEENTITY (1<<3)          // a short and a byte (instead of a short)
 #define        SND_LARGESOUND  (1<<4)          // a short (instead of a byte)
+#define        SND_SPEEDUSHORT4000     (1<<5)          // ushort speed*4000 (speed is usually 1.0, a value of 0.0 is the same as 1.0)
 
 
 // defaults for clientinfo messages
index 538a6220666b17d8623da3c502024b823fc73bcb..a83e6f30618d5780300495bafba532d4e403cfac 100644 (file)
--- a/server.h
+++ b/server.h
@@ -494,8 +494,8 @@ void SV_Init (void);
 
 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
-void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qboolean reliable);
-void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float attenuation);
+void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qboolean reliable, float speed);
+void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float attenuation, float speed);
 
 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
 void SV_DropClient (qboolean crash);
index aa7ce3208078a5ec59257f9ac7fe8ccf33114d0b..c60e15b08e97ef7298ee16cc5c879a9f0158b574 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -699,10 +699,10 @@ Larger attenuations will drop off.  (max 4 attenuation)
 
 ==================
 */
-void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qboolean reliable)
+void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qboolean reliable, float speed)
 {
        sizebuf_t *dest;
-       int sound_num, field_mask, i, ent;
+       int sound_num, field_mask, i, ent, speed4000;
 
        dest = (reliable ? &sv.reliable_datagram : &sv.datagram);
 
@@ -736,6 +736,7 @@ void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int v
 
        ent = PRVM_NUM_FOR_EDICT(entity);
 
+       speed4000 = (int)(speed * 40.0f);
        field_mask = 0;
        if (volume != DEFAULT_SOUND_PACKET_VOLUME)
                field_mask |= SND_VOLUME;
@@ -745,6 +746,8 @@ void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int v
                field_mask |= SND_LARGEENTITY;
        if (sound_num >= 256)
                field_mask |= SND_LARGESOUND;
+       if (speed4000 && speed4000 != 4000)
+               field_mask |= SND_SPEEDUSHORT4000;
 
 // directed messages go only to the entity they are targeted on
        MSG_WriteByte (dest, svc_sound);
@@ -753,6 +756,8 @@ void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int v
                MSG_WriteByte (dest, volume);
        if (field_mask & SND_ATTENUATION)
                MSG_WriteByte (dest, (int)(attenuation*64));
+       if (field_mask & SND_SPEEDUSHORT4000)
+               MSG_WriteShort (dest, speed4000);
        if (field_mask & SND_LARGEENTITY)
        {
                MSG_WriteShort (dest, ent);
@@ -785,9 +790,9 @@ function, therefore the check for it is omitted.
 
 ==================
 */
-void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float attenuation)
+void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float attenuation, float speed)
 {
-       int sound_num, field_mask, i;
+       int sound_num, field_mask, i, speed4000;
 
        if (volume < 0 || volume > 255)
        {
@@ -809,6 +814,7 @@ void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float at
        if (!sound_num)
                return;
 
+       speed4000 = (int)(speed * 40.0f);
        field_mask = 0;
        if (volume != DEFAULT_SOUND_PACKET_VOLUME)
                field_mask |= SND_VOLUME;
@@ -816,6 +822,8 @@ void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float at
                field_mask |= SND_ATTENUATION;
        if (sound_num >= 256)
                field_mask |= SND_LARGESOUND;
+       if (speed4000 && speed4000 != 4000)
+               field_mask |= SND_SPEEDUSHORT4000;
 
 // directed messages go only to the entity they are targeted on
        MSG_WriteByte (&sv.datagram, svc_sound);
@@ -824,6 +832,8 @@ void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float at
                MSG_WriteByte (&sv.datagram, volume);
        if (field_mask & SND_ATTENUATION)
                MSG_WriteByte (&sv.datagram, (int)(attenuation*64));
+       if (field_mask & SND_SPEEDUSHORT4000)
+               MSG_WriteShort (&sv.datagram, speed4000);
        // Always write entnum 0 for the world entity
        MSG_WriteShort (&sv.datagram, (0<<3) | 0);
        if (field_mask & SND_LARGESOUND)
index 629727c698946c9ebe21d75087351e2a15fd29ff..a3f84f4b0230910cec2b0ca1799c0a675f8e6e16 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -2523,7 +2523,7 @@ void SV_CheckWaterTransition (prvm_edict_t *ent)
        { // Contents Transition Function Invalid; Potentially Play Water Sound
                // check if the entity crossed into or out of water
                if (sv_sound_watersplash.string && ((PRVM_serveredictfloat(ent, watertype) == CONTENTS_WATER || PRVM_serveredictfloat(ent, watertype) == CONTENTS_SLIME) != (cont == CONTENTS_WATER || cont == CONTENTS_SLIME)))
-                       SV_StartSound (ent, 0, sv_sound_watersplash.string, 255, 1, false);
+                       SV_StartSound (ent, 0, sv_sound_watersplash.string, 255, 1, false, 1.0f);
        }
 
        if (cont <= CONTENTS_WATER)
@@ -2768,7 +2768,7 @@ void SV_Physics_Step (prvm_edict_t *ent)
                                else
                                // Check for Engine Landing Sound
                                if(sv_sound_land.string)
-                                       SV_StartSound(ent, 0, sv_sound_land.string, 255, 1, false);
+                                       SV_StartSound(ent, 0, sv_sound_land.string, 255, 1, false, 1.0f);
                        }
                        ent->priv.server->waterposition_forceupdate = true;
                }
index 30d17453fafedb0577399490d02c604dbc630e7c..310af6d8b21cf05d3b7b5b691bcc7d79764b7c5f 100644 (file)
@@ -533,7 +533,7 @@ static void VM_SV_sound (void)
        if (prog->argc < 6)
                pitchchange = 0;
        else
-               pitchchange = PRVM_G_FLOAT(OFS_PARM5);
+               pitchchange = PRVM_G_FLOAT(OFS_PARM5) * 0.01f;
 
        if (prog->argc < 7)
        {
@@ -567,7 +567,7 @@ static void VM_SV_sound (void)
                return;
        }
 
-       SV_StartSound (entity, channel, sample, volume, attenuation, flags & CHANFLAG_RELIABLE);
+       SV_StartSound (entity, channel, sample, volume, attenuation, flags & CHANFLAG_RELIABLE, pitchchange);
 }
 
 /*
@@ -585,14 +585,16 @@ static void VM_SV_pointsound(void)
        const char      *sample;
        int             volume;
        float           attenuation;
+       float           pitchchange;
        vec3_t          org;
 
-       VM_SAFEPARMCOUNT(4, VM_SV_pointsound);
+       VM_SAFEPARMCOUNTRANGE(4, 5, VM_SV_pointsound);
 
        VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org);
        sample = PRVM_G_STRING(OFS_PARM1);
        volume = (int)(PRVM_G_FLOAT(OFS_PARM2) * 255);
        attenuation = PRVM_G_FLOAT(OFS_PARM3);
+       pitchchange = prog->argc < 5 ? 0 : PRVM_G_FLOAT(OFS_PARM4) * 0.01f;
 
        if (volume < 0 || volume > 255)
        {
@@ -606,7 +608,7 @@ static void VM_SV_pointsound(void)
                return;
        }
 
-       SV_StartPointSound (org, sample, volume, attenuation);
+       SV_StartPointSound (org, sample, volume, attenuation, pitchchange);
 }
 
 /*