]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - csprogs.c
changed Cmd_StuffCmds_f to combine the entire set of commandline arguments into one...
[xonotic/darkplaces.git] / csprogs.c
index 8aa55b240f674f6387a22e31216caf3dab61adec..7f3f4281d3b98c48bcf1155273b1e5563f168102 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -96,6 +96,7 @@ static void CL_VM_FindEdictFieldOffsets (void)
        }
 }
 
+void CL_VM_Error (const char *format, ...) DP_FUNC_PRINTF(1);
 void CL_VM_Error (const char *format, ...)     //[515]: hope it will be never executed =)
 {
        char errorstring[4096];
@@ -111,11 +112,37 @@ void CL_VM_Error (const char *format, ...)        //[515]: hope it will be never execut
        Mem_FreePool(&csqc_mempool);
 
        Cvar_SetValueQuick(&csqc_progcrc, -1);
+       Cvar_SetValueQuick(&csqc_progsize, -1);
 
 //     Host_AbortCurrentFrame();       //[515]: hmmm... if server says it needs csqc then client MUST disconnect
        Host_Error(va("CL_VM_Error: %s", errorstring));
 }
 
+model_t *CSQC_GetModelByIndex(int modelindex)
+{
+       if(!modelindex)
+               return NULL;
+       if (modelindex < 0)
+       {
+               modelindex = -(modelindex+1);
+               if (modelindex < MAX_MODELS)
+                       return cl.csqc_model_precache[modelindex];
+       }
+       else
+       {
+               if(modelindex < MAX_MODELS)
+                       return cl.model_precache[modelindex];
+       }
+       return NULL;
+}
+
+model_t *CSQC_GetModelFromEntity(prvm_edict_t *ed)
+{
+       if (!ed || ed->priv.server->free)
+               return NULL;
+       return CSQC_GetModelByIndex((int)ed->fields.client->modelindex);
+}
+
 //[515]: set globals before calling R_UpdateView, WEIRD CRAP
 static void CSQC_SetGlobals (void)
 {
@@ -169,43 +196,35 @@ extern cvar_t cl_noplayershadow;
 qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
 {
        int i;
+       float scale;
        prvm_eval_t *val;
        entity_t *e;
+       model_t *model;
        matrix4x4_t tagmatrix, matrix2;
 
-       e = CL_NewTempEntity();
-       if (!e)
+       model = CSQC_GetModelFromEntity(ed);
+       if (!model)
                return false;
 
-       i = (int)ed->fields.client->modelindex;
-       if(i >= MAX_MODELS || i <= -MAX_MODELS) //[515]: make work as error ?
-       {
-               Con_Print("CSQC_AddRenderEdict: modelindex >= MAX_MODELS\n");
-               ed->fields.client->modelindex = i = 0;
-       }
-
-       // model setup and some modelflags
-       if (i < MAX_MODELS)
-               e->render.model = cl.model_precache[e->state_current.modelindex];
-       else
-               e->render.model = cl.csqc_model_precache[65536-e->state_current.modelindex];
-
-       if (!e->render.model)
+       e = CL_NewTempEntity();
+       if (!e)
                return false;
 
+       e->render.model = model;
        e->render.colormap = (int)ed->fields.client->colormap;
        e->render.frame = (int)ed->fields.client->frame;
        e->render.skinnum = (int)ed->fields.client->skin;
        e->render.effects |= e->render.model->flags2 & (EF_FULLBRIGHT | EF_ADDITIVE);
+       scale = 1;
 
        if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_alpha)) && val->_float)             e->render.alpha = val->_float;
-       if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_scale)) && val->_float)             e->render.scale = val->_float;
+       if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_scale)) && val->_float)             e->render.scale = scale = val->_float;
        if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_colormod)) && VectorLength2(val->vector))   VectorCopy(val->vector, e->render.colormod);
        if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_effects)) && val->_float)   e->render.effects = (int)val->_float;
        if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_tag_entity)) && val->edict)
        {
                int tagentity;
-               int tagindex;
+               int tagindex = 0;
                tagentity = val->edict;
                if((val = PRVM_GETEDICTFIELDVALUE(ed, csqc_fieldoff_tag_index)) && val->_float)
                        tagindex = (int)val->_float;
@@ -230,8 +249,7 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
                        angles[0] = -angles[0];
 
                // set up the render matrix
-               // FIXME: e->render.scale should go away
-               Matrix4x4_CreateFromQuakeEntity(&matrix2, ed->fields.client->origin[0], ed->fields.client->origin[1], ed->fields.client->origin[2], angles[0], angles[1], angles[2], e->render.scale);
+               Matrix4x4_CreateFromQuakeEntity(&matrix2, ed->fields.client->origin[0], ed->fields.client->origin[1], ed->fields.client->origin[2], angles[0], angles[1], angles[2], scale);
        }
 
        // FIXME: csqc has frame1/frame2/frame1time/frame2time/lerpfrac but this implementation's cl_entvars_t lacks those fields
@@ -273,14 +291,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
        return true;
 }
 
-void CSQC_ClearCSQCEntities (void)
-{
-       memset(cl.csqcentities_active, 0, sizeof(cl.csqcentities_active));
-       cl.num_csqcentities = 0;
-}
-
-void CL_ExpandCSQCEntities (int num);
-
 qboolean CL_VM_InputEvent (qboolean pressed, int key)
 {
        qboolean r;
@@ -305,11 +315,10 @@ qboolean CL_VM_UpdateView (void)
                //VectorCopy(cl.viewangles, oldangles);
                *prog->time = cl.time;
                CSQC_SetGlobals();
-               cl.num_csqcentities = 0;
+               r_refdef.numentities = 0;
                PRVM_ExecuteProgram (prog->globals.client->CSQC_UpdateView, CL_F_UPDATEVIEW);
                //VectorCopy(oldangles, cl.viewangles);
        CSQC_END
-       csqc_frame = false;
        return true;
 }
 
@@ -357,10 +366,13 @@ void CL_VM_Parse_StuffCmd (const char *msg)
                // if this is setting a csqc variable, deprotect csqc_progcrc
                // temporarily so that it can be set by the cvar command,
                // and then reprotect it afterwards
-               int flags = csqc_progcrc.flags;
+               int crcflags = csqc_progcrc.flags;
+               int sizeflags = csqc_progcrc.flags;
                csqc_progcrc.flags &= ~CVAR_READONLY;
+               csqc_progsize.flags &= ~CVAR_READONLY;
                Cmd_ExecuteString (msg, src_command);
-               csqc_progcrc.flags = flags;
+               csqc_progcrc.flags = crcflags;
+               csqc_progsize.flags = sizeflags;
                return;
        }
        if(!csqc_loaded || !CSQC_Parse_StuffCmd)
@@ -487,12 +499,14 @@ void CL_VM_Init (void)
        unsigned char *csprogsdata;
        fs_offset_t csprogsdatasize;
        int csprogsdatacrc, requiredcrc;
-       entity_t *ent;
+       int requiredsize;
 
        // reset csqc_progcrc after reading it, so that changing servers doesn't
        // expect csqc on the next server
        requiredcrc = csqc_progcrc.integer;
+       requiredsize = csqc_progsize.integer;
        Cvar_SetValueQuick(&csqc_progcrc, -1);
+       Cvar_SetValueQuick(&csqc_progsize, -1);
 
        csqc_loaded = false;
        memset(cl.csqc_model_precache, 0, sizeof(cl.csqc_model_precache));
@@ -504,19 +518,26 @@ void CL_VM_Init (void)
 
        // see if the requested csprogs.dat file matches the requested crc
        csprogsdatacrc = -1;
-       csprogsdata = FS_LoadFile(csqc_progname.string, tempmempool, true, &csprogsdatasize);
+       csprogsdata = FS_LoadFile(va("dlcache/%s.%i.%i", csqc_progname.string, requiredsize, requiredcrc), tempmempool, true, &csprogsdatasize);
+       if (!csprogsdata)
+               csprogsdata = FS_LoadFile(csqc_progname.string, tempmempool, true, &csprogsdatasize);
        if (csprogsdata)
        {
                csprogsdatacrc = CRC_Block(csprogsdata, csprogsdatasize);
                Mem_Free(csprogsdata);
-               if (csprogsdatacrc != requiredcrc)
+               if (csprogsdatacrc != requiredcrc || csprogsdatasize != requiredsize)
                {
                        if (cls.demoplayback)
-                               Con_Printf("^1Your %s is not the same version as the demo was recorded with (CRC is %i but should be %i)\n", csqc_progname.string, csprogsdatacrc, requiredcrc);
+                       {
+                               Con_Printf("^1Warning: Your %s is not the same version as the demo was recorded with (CRC/size are %i/%i but should be %i/%i)\n", csqc_progname.string, csprogsdatacrc, (int)csprogsdatasize, requiredcrc, requiredsize);
+                               return;
+                       }
                        else
-                               Con_Printf("^1Your %s is not the same version as the server (CRC is %i but should be %i)\n", csqc_progname.string, csprogsdatacrc, requiredcrc);
-                       CL_Disconnect();
-                       return;
+                       {
+                               Con_Printf("^1Your %s is not the same version as the server (CRC is %i/%i but should be %i/%i)\n", csqc_progname.string, csprogsdatacrc, (int)csprogsdatasize, requiredcrc, requiredsize);
+                               CL_Disconnect();
+                               return;
+                       }
                }
        }
        else
@@ -554,7 +575,7 @@ void CL_VM_Init (void)
        PRVM_LoadProgs(csqc_progname.string, cl_numrequiredfunc, cl_required_func, 0, NULL);
 
        if(prog->loaded)
-               Con_Printf("CSQC ^5loaded (crc=%i)\n", csprogsdatacrc);
+               Con_Printf("CSQC ^5loaded (crc=%i, size=%i)\n", csprogsdatacrc, (int)csprogsdatasize);
        else
        {
                CL_VM_Error("CSQC ^2failed to load\n");
@@ -584,22 +605,13 @@ void CL_VM_Init (void)
 
        cl.csqc_vidvars.drawcrosshair = false;
        cl.csqc_vidvars.drawenginesbar = false;
-
-       // local state
-       ent = &cl.csqcentities[0];
-       // entire entity array was cleared, so just fill in a few fields
-       ent->state_current.active = true;
-       ent->render.model = cl.worldmodel = cl.model_precache[1];
-       ent->render.alpha = 1;
-       ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
-       Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
-       CL_UpdateRenderEntity(&ent->render);
 }
 
 void CL_VM_ShutDown (void)
 {
        Cmd_ClearCsqcFuncs();
        Cvar_SetValueQuick(&csqc_progcrc, -1);
+       Cvar_SetValueQuick(&csqc_progsize, -1);
        if(!csqc_loaded)
                return;
        CSQC_BEGIN