]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
eliminated model->meshlist, replaced with an embedded model->surfmesh to cut down...
[xonotic/darkplaces.git] / clvm_cmds.c
index 7b3900a6c2b1023a3e653aa017e71f5fb4d70ebf..4b155e4d5fe9d92bd811db59ec7f741bb6364918 100644 (file)
@@ -441,11 +441,11 @@ void VM_CL_lightstyle (void)
 
        i = PRVM_G_FLOAT(OFS_PARM0);
        c = PRVM_G_STRING(OFS_PARM1);
-       if (i >= cl_max_lightstyle)
+       if (i >= cl.max_lightstyle)
                PF_WARNING("VM_CL_lightstyle >= MAX_LIGHTSTYLES\n");
-       strlcpy (cl_lightstyle[i].map,  MSG_ReadString(), sizeof (cl_lightstyle[i].map));
-       cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
-       cl_lightstyle[i].length = (int)strlen(cl_lightstyle[i].map);
+       strlcpy (cl.lightstyle[i].map,  MSG_ReadString(), sizeof (cl.lightstyle[i].map));
+       cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
+       cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
 }
 
 // #40 float(entity e) checkbottom
@@ -474,7 +474,7 @@ void VM_CL_checkbottom (void)
                {
                        start[0] = x ? maxs[0] : mins[0];
                        start[1] = y ? maxs[1] : mins[1];
-                       if (!(CL_PointSuperContents(start) & SUPERCONTENTS_SOLID))
+                       if (!(CL_PointSuperContents(start) & (SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY)))
                                goto realcheck;
                }
 
@@ -1110,13 +1110,13 @@ void CSQC_ParseBeam (int ent, vec3_t start, vec3_t end, model_t *m, int lightnin
        beam_t  *b;
 
        // override any beam with the same entity
-       for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
+       for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
        {
                if (b->entity == ent && ent)
                {
                        //b->entity = ent;
                        b->lightning = lightning;
-                       b->relativestartvalid = (ent && cl_csqcentities[ent].state_current.active) ? 2 : 0;
+                       b->relativestartvalid = (ent && cl.csqcentities[ent].state_current.active) ? 2 : 0;
                        b->model = m;
                        b->endtime = cl.time + 0.2;
                        VectorCopy (start, b->start);
@@ -1126,13 +1126,13 @@ void CSQC_ParseBeam (int ent, vec3_t start, vec3_t end, model_t *m, int lightnin
        }
 
        // find a free beam
-       for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
+       for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
        {
                if (!b->model || b->endtime < cl.time)
                {
                        b->entity = ent;
                        b->lightning = lightning;
-                       b->relativestartvalid = (ent && cl_csqcentities[ent].state_current.active) ? 2 : 0;
+                       b->relativestartvalid = (ent && cl.csqcentities[ent].state_current.active) ? 2 : 0;
                        b->model = m;
                        b->endtime = cl.time + 0.2;
                        VectorCopy (start, b->start);
@@ -1163,10 +1163,10 @@ void VM_CL_trailparticles (void)
                Con_Printf("CSQC_ParseBeam: invalid entity number %i\n", entnum);
                return;
        }
-       if (entnum >= cl_max_csqcentities)
+       if (entnum >= cl.max_csqcentities)
                CL_ExpandCSQCEntities(entnum);
 
-       ent = &cl_csqcentities[entnum];
+       ent = &cl.csqcentities[entnum];
 
        if(prog->argc > 4)
                col = PRVM_G_FLOAT(OFS_PARM4);
@@ -1327,13 +1327,13 @@ void VM_CL_getinputstate (void)
                        prog->globals.client->input_timelength = cl.movement_queue[i].frametime;
                        if(cl.movement_queue[i].crouch)
                        {
-                               VectorCopy(cl_playercrouchmins, prog->globals.client->pmove_mins);
-                               VectorCopy(cl_playercrouchmaxs, prog->globals.client->pmove_maxs);
+                               VectorCopy(cl.playercrouchmins, prog->globals.client->pmove_mins);
+                               VectorCopy(cl.playercrouchmaxs, prog->globals.client->pmove_maxs);
                        }
                        else
                        {
-                               VectorCopy(cl_playerstandmins, prog->globals.client->pmove_mins);
-                               VectorCopy(cl_playerstandmaxs, prog->globals.client->pmove_maxs);
+                               VectorCopy(cl.playerstandmins, prog->globals.client->pmove_mins);
+                               VectorCopy(cl.playerstandmaxs, prog->globals.client->pmove_maxs);
                        }
                }
 }
@@ -1890,20 +1890,18 @@ static void VM_CL_NewBeam (int ent, float *start, float *end, model_t *m, qboole
 {
        beam_t  *b;
        int             i;
-       extern entity_t *cl_csqcentities;
-       extern int cl_max_csqcentities;
 
-       if (ent >= cl_max_csqcentities)
+       if (ent >= cl.max_csqcentities)
                CL_ExpandCSQCEntities(ent);
 
        // override any beam with the same entity
-       for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
+       for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
        {
                if (b->entity == ent && ent)
                {
                        //b->entity = ent;
                        b->lightning = lightning;
-                       b->relativestartvalid = (ent && cl_csqcentities[ent].state_current.active) ? 2 : 0;
+                       b->relativestartvalid = (ent && cl.csqcentities[ent].state_current.active) ? 2 : 0;
                        b->model = m;
                        b->endtime = cl.time + 0.2;
                        VectorCopy (start, b->start);
@@ -1913,13 +1911,13 @@ static void VM_CL_NewBeam (int ent, float *start, float *end, model_t *m, qboole
        }
 
        // find a free beam
-       for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
+       for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
        {
                if (!b->model || b->endtime < cl.time)
                {
                        b->entity = ent;
                        b->lightning = lightning;
-                       b->relativestartvalid = (ent && cl_csqcentities[ent].state_current.active) ? 2 : 0;
+                       b->relativestartvalid = (ent && cl.csqcentities[ent].state_current.active) ? 2 : 0;
                        b->model = m;
                        b->endtime = cl.time + 0.2;
                        VectorCopy (start, b->start);
@@ -1978,7 +1976,7 @@ void VM_CL_te_plasmaburn (void)
 //DP_QC_GETSURFACE
 
 void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out);
-static msurface_t *cl_getsurface(prvm_edict_t *ed, int surfacenum)
+static model_t *cl_getmodel(prvm_edict_t *ed)
 {
        int modelindex;
        model_t *model = NULL;
@@ -1998,8 +1996,11 @@ static msurface_t *cl_getsurface(prvm_edict_t *ed, int surfacenum)
                if(modelindex < MAX_MODELS)
                        model = cl.model_precache[modelindex];
        }
-       if(!model)
-               return NULL;
+       return model;
+}
+
+static msurface_t *cl_getsurface(model_t *model, int surfacenum)
+{
        if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
                return NULL;
        return model->data_surfaces + surfacenum + model->firstmodelsurface;
@@ -2008,9 +2009,10 @@ static msurface_t *cl_getsurface(prvm_edict_t *ed, int surfacenum)
 // #434 float(entity e, float s) getsurfacenumpoints
 void VM_CL_getsurfacenumpoints(void)
 {
+       model_t *model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0));
        msurface_t *surface;
        // return 0 if no such surface
-       if (!(surface = cl_getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!model || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
        {
                PRVM_G_FLOAT(OFS_RETURN) = 0;
                return;
@@ -2024,35 +2026,35 @@ void VM_CL_getsurfacenumpoints(void)
 void VM_CL_getsurfacepoint(void)
 {
        prvm_edict_t *ed;
+       model_t *model;
        msurface_t *surface;
        int pointnum;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
        ed = PRVM_G_EDICT(OFS_PARM0);
-       if (!ed || ed->priv.server->free)
-               return;
-       if (!(surface = cl_getsurface(ed, PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(ed)) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // note: this (incorrectly) assumes it is a simple polygon
        pointnum = PRVM_G_FLOAT(OFS_PARM2);
        if (pointnum < 0 || pointnum >= surface->num_vertices)
                return;
        // FIXME: implement rotation/scaling
-       VectorAdd(&(surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
+       VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
 }
 
 // #436 vector(entity e, float s) getsurfacenormal
 void VM_CL_getsurfacenormal(void)
 {
+       model_t *model;
        msurface_t *surface;
        vec3_t normal;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
-       if (!(surface = cl_getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
        // note: this (incorrectly) assumes it is a simple polygon
        // note: this only returns the first triangle, so it doesn't work very
        // well for curved surfaces or arbitrary meshes
-       TriangleNormal((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 3, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
+       TriangleNormal((model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex), (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 3, (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
        VectorNormalize(normal);
        VectorCopy(normal, PRVM_G_VECTOR(OFS_RETURN));
 }
@@ -2060,9 +2062,10 @@ void VM_CL_getsurfacenormal(void)
 // #437 string(entity e, float s) getsurfacetexture
 void VM_CL_getsurfacetexture(void)
 {
+       model_t *model;
        msurface_t *surface;
        PRVM_G_INT(OFS_RETURN) = 0;
-       if (!(surface = cl_getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(surface->texture->name);
 }
@@ -2070,7 +2073,7 @@ void VM_CL_getsurfacetexture(void)
 // #438 float(entity e, vector p) getsurfacenearpoint
 void VM_CL_getsurfacenearpoint(void)
 {
-       int surfacenum, best, modelindex;
+       int surfacenum, best;
        vec3_t clipped, p;
        vec_t dist, bestdist;
        prvm_edict_t *ed;
@@ -2079,28 +2082,11 @@ void VM_CL_getsurfacenearpoint(void)
        vec_t *point;
        PRVM_G_FLOAT(OFS_RETURN) = -1;
        ed = PRVM_G_EDICT(OFS_PARM0);
-       point = PRVM_G_VECTOR(OFS_PARM1);
-
-       if (!ed || ed->priv.server->free)
-               return;
-       modelindex = ed->fields.client->modelindex;
-       if(!modelindex)
-               return;
-       if(modelindex<0)
-       {
-               modelindex = -(modelindex+1);
-               if(modelindex < MAX_MODELS)
-                       model = cl.csqc_model_precache[modelindex];
-       }
-       else
-               if(modelindex < MAX_MODELS)
-                       model = cl.model_precache[modelindex];
-       if(!model)
-               return;
-       if (!model->num_surfaces)
+       if(!(model = cl_getmodel(ed)) || !model->num_surfaces)
                return;
 
        // FIXME: implement rotation/scaling
+       point = PRVM_G_VECTOR(OFS_PARM1);
        VectorSubtract(point, ed->fields.client->origin, p);
        best = -1;
        bestdist = 1000000000;
@@ -2133,13 +2119,12 @@ void VM_CL_getsurfacenearpoint(void)
 void VM_CL_getsurfaceclippedpoint(void)
 {
        prvm_edict_t *ed;
+       model_t *model;
        msurface_t *surface;
        vec3_t p, out;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
        ed = PRVM_G_EDICT(OFS_PARM0);
-       if (!ed || ed->priv.server->free)
-               return;
-       if (!(surface = cl_getsurface(ed, PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(ed)) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
        VectorSubtract(PRVM_G_VECTOR(OFS_PARM2), ed->fields.client->origin, p);
@@ -2601,16 +2586,16 @@ void VM_CL_selecttraceline (void)
        csqcents = PRVM_G_FLOAT(OFS_PARM3);
        ent = 0;
 
-       if((csqcents && ignore > cl_num_csqcentities) || (!csqcents && ignore > cl_num_entities))
+       if((csqcents && ignore > cl.num_csqcentities) || (!csqcents && ignore > cl.num_entities))
        {
                Con_Printf("VM_CL_selecttraceline: out of entities\n");
                return;
        }
        else
                if(csqcents)
-                       prog->globals.client->trace_fraction = CL_SelectTraceLine(v1, v2, prog->globals.client->trace_endpos, prog->globals.client->trace_plane_normal, &prog->globals.client->trace_ent, &cl_csqcentities[ignore].render, csqcents);
+                       prog->globals.client->trace_fraction = CL_SelectTraceLine(v1, v2, prog->globals.client->trace_endpos, prog->globals.client->trace_plane_normal, &prog->globals.client->trace_ent, &cl.csqcentities[ignore].render, csqcents);
                else
-                       prog->globals.client->trace_fraction = CL_SelectTraceLine(v1, v2, prog->globals.client->trace_endpos, prog->globals.client->trace_plane_normal, &ent, &cl_entities[ignore].render, csqcents);
+                       prog->globals.client->trace_fraction = CL_SelectTraceLine(v1, v2, prog->globals.client->trace_endpos, prog->globals.client->trace_plane_normal, &ent, &cl.entities[ignore].render, csqcents);
        PRVM_G_FLOAT(OFS_RETURN) = ent;
 }