]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
restore flags feature in csqc sound7 builtin, so that mods can use
[xonotic/darkplaces.git] / clvm_cmds.c
index 92db59dc9cd4ce997712b76e530f462e47104686..e1c6ff0d2a104bea4abea5e3b87bc29883c507d1 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;
        vec3_t                          org;
 
@@ -201,13 +202,21 @@ static void VM_CL_sound (prvm_prog_t *prog)
                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))
@@ -216,8 +225,12 @@ static void VM_CL_sound (prvm_prog_t *prog)
                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
@@ -3429,7 +3442,7 @@ void VM_CL_AddPolygonsToMeshQueue (prvm_prog_t *prog)
        for (i = 0;i < polys->num_triangles;i++)
        {
                VectorMAMAM(1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[0], 1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[1], 1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[2], center);
-               R_MeshQueue_AddTransparent(MESHQUEUE_SORT_DISTANCE, center, VM_DrawPolygonCallback, (entity_render_t *)polys, i, NULL);
+               R_MeshQueue_AddTransparent(TRANSPARENTSORT_DISTANCE, center, VM_DrawPolygonCallback, (entity_render_t *)polys, i, NULL);
        }
 
        /*polys->num_triangles = 0; // now done after rendering the scene,
@@ -3964,13 +3977,12 @@ static void VM_CL_skel_build(prvm_prog_t *prog)
        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;
        framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
        frameblend_t frameblend[MAX_FRAMEBLENDS];
-       matrix4x4_t blendedmatrix;
+       matrix4x4_t bonematrix;
        matrix4x4_t matrix;
        PRVM_G_FLOAT(OFS_RETURN) = 0;
        if (skeletonindex < 0 || skeletonindex >= MAX_EDICTS || !(skeleton = prog->skeletons[skeletonindex]))
@@ -3980,19 +3992,18 @@ static void VM_CL_skel_build(prvm_prog_t *prog)
        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++)
-               frameblend[numblends].lerp *= blendfrac;
+               ;
        for (bonenum = firstbone;bonenum <= lastbone;bonenum++)
        {
-               memset(&blendedmatrix, 0, sizeof(blendedmatrix));
-               Matrix4x4_Accumulate(&blendedmatrix, &skeleton->relativetransforms[bonenum], retainfrac);
+               memset(&bonematrix, 0, sizeof(bonematrix));
                for (blendindex = 0;blendindex < numblends;blendindex++)
                {
                        Matrix4x4_FromBonePose7s(&matrix, model->num_posescale, model->data_poses7s + 7 * (frameblend[blendindex].subframe * model->num_bones + bonenum));
-                       Matrix4x4_Accumulate(&blendedmatrix, &matrix, frameblend[blendindex].lerp);
+                       Matrix4x4_Accumulate(&bonematrix, &matrix, frameblend[blendindex].lerp);
                }
-               skeleton->relativetransforms[bonenum] = blendedmatrix;
+               Matrix4x4_Normalize3(&bonematrix, &bonematrix);
+               Matrix4x4_Interpolate(&skeleton->relativetransforms[bonenum], &bonematrix, &skeleton->relativetransforms[bonenum], retainfrac);
        }
        PRVM_G_FLOAT(OFS_RETURN) = skeletonindex + 1;
 }