added shadertime field in csqc
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 15 Feb 2009 21:45:55 +0000 (21:45 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 15 Feb 2009 21:45:55 +0000 (21:45 +0000)
added shadertime support in renderer
added shadertime support in client (defaults to last time model changed)
this means shader animMap commands are now time-synced to entity spawn

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

cl_main.c
cl_parse.c
csprogs.c
gl_rmain.c
progsvm.h
prvm_edict.c

index 48bcae8..33bd31d 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -598,7 +598,7 @@ void CL_ClearTempEntities (void)
        r_refdef.scene.numtempentities = 0;
 }
 
-entity_render_t *CL_NewTempEntity(void)
+entity_render_t *CL_NewTempEntity(double shadertime)
 {
        entity_render_t *render;
 
@@ -610,6 +610,7 @@ entity_render_t *CL_NewTempEntity(void)
        memset (render, 0, sizeof(*render));
        r_refdef.scene.entities[r_refdef.scene.numentities++] = render;
 
+       render->shadertime = shadertime;
        render->alpha = 1;
        VectorSet(render->colormod, 1, 1, 1);
        return render;
@@ -822,7 +823,7 @@ void CL_AddQWCTFFlagModel(entity_t *player, int skin)
        }
        // end of code taken from QuakeWorld
 
-       flagrender = CL_NewTempEntity();
+       flagrender = CL_NewTempEntity(player->render.shadertime);
        if (!flagrender)
                return;
 
@@ -1533,7 +1534,7 @@ static void CL_RelinkEffects(void)
 
                        // if we're drawing effects, get a new temp entity
                        // (NewTempEntity adds it to the render entities list for us)
-                       if (r_draweffects.integer && (entrender = CL_NewTempEntity()))
+                       if (r_draweffects.integer && (entrender = CL_NewTempEntity(e->starttime)))
                        {
                                // interpolation stuff
                                entrender->frame1 = intframe;
@@ -1658,7 +1659,7 @@ void CL_RelinkBeams(void)
                d = VectorNormalizeLength(dist);
                while (d > 0)
                {
-                       entrender = CL_NewTempEntity ();
+                       entrender = CL_NewTempEntity (0);
                        if (!entrender)
                                return;
                        //VectorCopy (org, ent->render.origin);
@@ -1690,7 +1691,7 @@ static void CL_RelinkQWNails(void)
 
                // if we're drawing effects, get a new temp entity
                // (NewTempEntity adds it to the render entities list for us)
-               if (!(entrender = CL_NewTempEntity()))
+               if (!(entrender = CL_NewTempEntity(0)))
                        continue;
 
                // normal stuff
index 0b8af8e..673a26f 100644 (file)
@@ -1734,6 +1734,7 @@ void CL_MoveLerpEntityStates(entity_t *ent)
                ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
                ent->render.frame1time = ent->render.frame2time = cl.time;
                ent->render.framelerp = 1;
+               ent->render.shadertime = cl.time;
                // reset various persistent stuff
                ent->persistent.muzzleflash = 0;
                ent->persistent.trail_allowed = false;
index 8539312..f9d5e7d 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -154,7 +154,7 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
        if (!model)
                return false;
 
-       entrender = CL_NewTempEntity();
+       entrender = CL_NewTempEntity(0);
        if (!entrender)
                return false;
 
@@ -209,6 +209,7 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
        if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame1time))) entrender->frame2time = val->_float;
        if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame2time))) entrender->frame1time = val->_float;
        if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.lerpfrac))) entrender->framelerp = val->_float;
+       if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.shadertime))) entrender->shadertime = val->_float;
 
        // concat the matrices to make the entity relative to its tag
        Matrix4x4_Concat(&entrender->matrix, &tagmatrix, &matrix2);
index 6b6bf85..31e1053 100644 (file)
@@ -4616,12 +4616,12 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                }
                t->currentskinframe = r_qwskincache_skinframe[i];
                if (t->currentskinframe == NULL)
-                       t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->frame2time)) % t->numskinframes];
+                       t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->shadertime)) % t->numskinframes];
        }
        else if (t->numskinframes >= 2)
-               t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->frame2time)) % t->numskinframes];
+               t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->shadertime)) % t->numskinframes];
        if (t->backgroundnumskinframes >= 2)
-               t->backgroundcurrentskinframe = t->backgroundskinframes[(int)(t->backgroundskinframerate * (cl.time - ent->frame2time)) % t->backgroundnumskinframes];
+               t->backgroundcurrentskinframe = t->backgroundskinframes[(int)(t->backgroundskinframerate * (cl.time - ent->shadertime)) % t->backgroundnumskinframes];
 
        t->currentmaterialflags = t->basematerialflags;
        t->currentalpha = ent->alpha;
index edad32a..c4ace92 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -179,6 +179,7 @@ typedef struct prvm_prog_fieldoffsets_s
        int frame1time; // csqc
        int frame2; // csqc
        int frame2time; // csqc
+       int shadertime; // csqc
        int frame; // common - used by OP_STATE
        int fullbright; // ssqc - Nehahra support
        int glow_color; // ssqc
index 82314f8..0199f24 100644 (file)
@@ -1457,6 +1457,7 @@ void PRVM_FindOffsets(void)
        prog->fieldoffsets.frame1time                     = PRVM_ED_FindFieldOffset("frame1time");
        prog->fieldoffsets.frame2                         = PRVM_ED_FindFieldOffset("frame2");
        prog->fieldoffsets.frame2time                     = PRVM_ED_FindFieldOffset("frame2time");
+       prog->fieldoffsets.shadertime                     = PRVM_ED_FindFieldOffset("shadertime");
        prog->fieldoffsets.fullbright                     = PRVM_ED_FindFieldOffset("fullbright");
        prog->fieldoffsets.glow_color                     = PRVM_ED_FindFieldOffset("glow_color");
        prog->fieldoffsets.glow_size                      = PRVM_ED_FindFieldOffset("glow_size");
@@ -1553,6 +1554,9 @@ void PRVM_FindOffsets(void)
        prog->globaloffsets.drawfont                      = PRVM_ED_FindGlobalOffset("drawfont");
        prog->globaloffsets.require_spawnfunc_prefix      = PRVM_ED_FindGlobalOffset("require_spawnfunc_prefix");
        prog->globaloffsets.worldstatus                   = PRVM_ED_FindGlobalOffset("worldstatus");
+       prog->globaloffsets.servertime                    = PRVM_ED_FindGlobalOffset("servertime");
+       prog->globaloffsets.serverprevtime                = PRVM_ED_FindGlobalOffset("serverprevtime");
+       prog->globaloffsets.serverdeltatime               = PRVM_ED_FindGlobalOffset("serverdeltatime");
 
        // menu qc only uses some functions, nothing else
        prog->funcoffsets.m_draw                          = PRVM_ED_FindFunctionOffset("m_draw");