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;
float volume;
float attenuation;
float pitchchange;
+ float startposition;
int flags;
vec3_t org;
pitchchange = 0;
else
pitchchange = PRVM_G_FLOAT(OFS_PARM5);
- // ignoring prog->argc < 7 for now (no flags supported yet)
if (prog->argc < 7)
flags = 0;
else
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))
return;
}
+ // TODO currently the only flag defined in the interface is
+ // SOUNDFLAG_RELIABLE. This one makes no sense at all from CSQC.
+ // 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, flags, 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, flags, pitchchange > 0.0f ? pitchchange * 0.01f : 1.0f);
}
// #483 void(vector origin, string sample, float volume, float attenuation) pointsound
int firstbone = PRVM_G_FLOAT(OFS_PARM4) - 1;
int lastbone = PRVM_G_FLOAT(OFS_PARM5) - 1;
dp_model_t *model = CL_GetModelByIndex(modelindex);
- float blendfrac;
int numblends;
int bonenum;
int blendindex;
lastbone = min(lastbone, skeleton->model->num_bones - 1);
VM_GenerateFrameGroupBlend(prog, framegroupblend, ed);
VM_FrameBlendFromFrameGroupBlend(frameblend, framegroupblend, model, cl.time);
- blendfrac = 1.0f - retainfrac;
for (numblends = 0;numblends < MAX_FRAMEBLENDS && frameblend[numblends].lerp;numblends++)
;
for (bonenum = firstbone;bonenum <= lastbone;bonenum++)
Matrix4x4_Accumulate(&bonematrix, &matrix, frameblend[blendindex].lerp);
}
Matrix4x4_Normalize3(&bonematrix, &bonematrix);
- Matrix4x4_Scale(&skeleton->relativetransforms[bonenum], retainfrac, retainfrac);
- Matrix4x4_Accumulate(&skeleton->relativetransforms[bonenum], &bonematrix, blendfrac);
+ Matrix4x4_Interpolate(&skeleton->relativetransforms[bonenum], &bonematrix, &skeleton->relativetransforms[bonenum], retainfrac);
}
PRVM_G_FLOAT(OFS_RETURN) = skeletonindex + 1;
}