]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
prevent creation of a cvar named "", as that breaks cvar()
[xonotic/darkplaces.git] / model_shared.c
index ac16b9acf0bc8600a6381dd09b550d85c8924932..6ea5a859889fd9dd68b48a6686907b446259baee 100644 (file)
@@ -91,21 +91,23 @@ static void mod_newmap(void)
        int nummodels = Mem_ExpandableArray_IndexRange(&models);
        dp_model_t *mod;
 
-       R_SkinFrame_PrepareForPurge();
        for (i = 0;i < nummodels;i++)
        {
-               if ((mod = (dp_model_t*) Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->mempool && mod->data_textures)
+               if ((mod = (dp_model_t*) Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->mempool)
                {
-                       for (j = 0;j < mod->num_textures;j++)
+                       for (j = 0;j < mod->num_textures && mod->data_textures;j++)
                        {
                                for (k = 0;k < mod->data_textures[j].numskinframes;k++)
                                        R_SkinFrame_MarkUsed(mod->data_textures[j].skinframes[k]);
                                for (k = 0;k < mod->data_textures[j].backgroundnumskinframes;k++)
                                        R_SkinFrame_MarkUsed(mod->data_textures[j].backgroundskinframes[k]);
                        }
+                       if (mod->brush.solidskyskinframe)
+                               R_SkinFrame_MarkUsed(mod->brush.solidskyskinframe);
+                       if (mod->brush.alphaskyskinframe)
+                               R_SkinFrame_MarkUsed(mod->brush.alphaskyskinframe);
                }
        }
-       R_SkinFrame_Purge();
 
        if (!cl_stainmaps_clearonload.integer)
                return;
@@ -1263,6 +1265,7 @@ void Mod_CreateCollisionMesh(dp_model_t *mod)
        if (!mempool && mod->brush.parentmodel)
                mempool = mod->brush.parentmodel->mempool;
        // make a single combined collision mesh for physics engine use
+       // TODO rewrite this to use the collision brushes as source, to fix issues with e.g. common/caulk which creates no drawsurface
        numcollisionmeshtriangles = 0;
        for (k = 0;k < mod->nummodelsurfaces;k++)
        {
@@ -1360,9 +1363,9 @@ void Mod_Terrain_SurfaceRecurseChunk(dp_model_t *model, int stepsize, int x, int
                return;
        VectorSet(mins, model->terrain.mins[0] +  x    * stepsize * model->terrain.scale[0], model->terrain.mins[1] +  y    * stepsize * model->terrain.scale[1], model->terrain.mins[2]);
        VectorSet(maxs, model->terrain.mins[0] + (x+1) * stepsize * model->terrain.scale[0], model->terrain.mins[1] + (y+1) * stepsize * model->terrain.scale[1], model->terrain.maxs[2]);
-       viewvector[0] = bound(mins[0], modelorg, maxs[0]) - model->terrain.vieworigin[0];
-       viewvector[1] = bound(mins[1], modelorg, maxs[1]) - model->terrain.vieworigin[1];
-       viewvector[2] = bound(mins[2], modelorg, maxs[2]) - model->terrain.vieworigin[2];
+       viewvector[0] = bound(mins[0], localvieworigin, maxs[0]) - model->terrain.vieworigin[0];
+       viewvector[1] = bound(mins[1], localvieworigin, maxs[1]) - model->terrain.vieworigin[1];
+       viewvector[2] = bound(mins[2], localvieworigin, maxs[2]) - model->terrain.vieworigin[2];
        if (stepsize > 1 && VectorLength(viewvector) < stepsize*model->terrain.scale[0]*r_terrain_lodscale.value)
        {
                // too close for this stepsize, emit as 4 chunks instead
@@ -2534,13 +2537,14 @@ static void Mod_Decompile_OBJ(dp_model_t *model, const char *filename, const cha
                countvertices += surface->num_vertices;
                countfaces += surface->num_triangles;
                texname = (surface->texture && surface->texture->name[0]) ? surface->texture->name : "default";
-               for (textureindex = 0;textureindex < maxtextures && texturenames[textureindex*MAX_QPATH];textureindex++)
+               for (textureindex = 0;textureindex < counttextures;textureindex++)
                        if (!strcmp(texturenames + textureindex * MAX_QPATH, texname))
                                break;
+               if (textureindex < counttextures)
+                       continue; // already wrote this material entry
                if (textureindex >= maxtextures)
                        continue; // just a precaution
-               if (counttextures < textureindex + 1)
-                       counttextures = textureindex + 1;
+               textureindex = counttextures++;
                strlcpy(texturenames + textureindex * MAX_QPATH, texname, MAX_QPATH);
                if (outbufferpos >= outbuffermax >> 1)
                {