From 73ae603d4f23aa25d1b0ff7b2a7c633f809efb9c Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 28 Feb 2013 09:44:12 +0000 Subject: [PATCH] csqc sound7 call now looks at the global variable sound_starttime to 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 ::stable-branch::merge=19b055e622e004a9429321df9f056001c4bd6fa6 --- clvm_cmds.c | 14 ++++++++++++-- prvm_offsets.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index ce8c42e7..67a496b9 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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 diff --git a/prvm_offsets.h b/prvm_offsets.h index f6c118a0..440b3e45 100644 --- a/prvm_offsets.h +++ b/prvm_offsets.h @@ -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) -- 2.39.2