]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
csqc sound7 call now looks at the global variable sound_starttime to
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 Feb 2013 09:44:12 +0000 (09:44 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 Feb 2013 09:44:12 +0000 (09:44 +0000)
calculate a startposition from, this allows a sound to be played at a
later time (delayed) or an earlier time (for instance restoring a
dialogue sound in-progress when loading a savegame)

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

clvm_cmds.c
prvm_offsets.h

index ce8c42e74468eb17be296c9562d718ed219ac7d0..67a496b9e5a4c9c87852ea47f7312fb6b8827717 100644 (file)
@@ -165,7 +165,7 @@ static void VM_CL_setsize (prvm_prog_t *prog)
        CL_LinkEdict(e);
 }
 
-// #8 void(entity e, float chan, string samp, float volume, float atten) sound
+// #8 void(entity e, float chan, string samp, float volume, float atten[, float pitchchange[, float flags]]) sound
 static void VM_CL_sound (prvm_prog_t *prog)
 {
        const char                      *sample;
@@ -174,6 +174,7 @@ static void VM_CL_sound (prvm_prog_t *prog)
        float                           volume;
        float                           attenuation;
        float pitchchange;
+       float                           startposition;
        /*
        int flags;
        */
@@ -212,6 +213,15 @@ static void VM_CL_sound (prvm_prog_t *prog)
                flags = PRVM_G_FLOAT(OFS_PARM6);
        */
 
+       // sound_starttime exists instead of sound_startposition because in a
+       // networking sense you might not know when something is being received,
+       // so making sounds match up in sync would be impossible if relative
+       // position was sent
+       if (PRVM_clientglobalfloat(sound_starttime))
+               startposition = cl.time - PRVM_clientglobalfloat(sound_starttime);
+       else
+               startposition = 0;
+
        channel = CHAN_USER2ENGINE(channel);
 
        if (!IS_CHAN(channel))
@@ -225,7 +235,7 @@ static void VM_CL_sound (prvm_prog_t *prog)
        // We want to, in a later extension, expose more flags.
 
        CL_VM_GetEntitySoundOrigin(MAX_EDICTS + PRVM_NUM_FOR_EDICT(entity), org);
-       S_StartSound_StartPosition_Flags(MAX_EDICTS + PRVM_NUM_FOR_EDICT(entity), channel, S_FindName(sample), org, volume, attenuation, 0, 0, pitchchange > 0.0f ? pitchchange * 0.01f : 1.0f);
+       S_StartSound_StartPosition_Flags(MAX_EDICTS + PRVM_NUM_FOR_EDICT(entity), channel, S_FindName(sample), org, volume, attenuation, startposition, 0, pitchchange > 0.0f ? pitchchange * 0.01f : 1.0f);
 }
 
 // #483 void(vector origin, string sample, float volume, float attenuation) pointsound
index f6c118a0166fd03af75ba942a9f8e0c844cb2af2..440b3e455cb611789b5aefa76eb2d53ba4b833bf 100644 (file)
@@ -203,6 +203,7 @@ PRVM_DECLARE_clientglobalvector(v_up)
 PRVM_DECLARE_clientglobalvector(view_angles)
 PRVM_DECLARE_clientglobalvector(view_punchangle)
 PRVM_DECLARE_clientglobalvector(view_punchvector)
+PRVM_DECLARE_clientglobalfloat(sound_starttime)
 PRVM_DECLARE_field(SendEntity)
 PRVM_DECLARE_field(SendFlags)
 PRVM_DECLARE_field(Version)
@@ -573,6 +574,7 @@ PRVM_DECLARE_global(view_punchangle)
 PRVM_DECLARE_global(view_punchvector)
 PRVM_DECLARE_global(world)
 PRVM_DECLARE_global(worldstatus)
+PRVM_DECLARE_global(sound_starttime)
 PRVM_DECLARE_menufieldstring(classname)
 PRVM_DECLARE_menufunction(GameCommand)
 PRVM_DECLARE_menufunction(URI_Get_Callback)