]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
audited R_Mesh_Matrix calls and RSurf_ActiveEntity calls and moved them to more appro...
[xonotic/darkplaces.git] / model_shared.c
index 920d85e571a5c44c54d4922b580ea0df698b51f6..1edb3fb44504470b95c0e976a8eb59beebb65d3b 100644 (file)
@@ -154,8 +154,16 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea
 
        crc = 0;
        buf = NULL;
+
+       // even if the model is loaded it still may need reloading...
+
+       // if the model is a worldmodel and is being referred to as a
+       // non-worldmodel here, then it needs reloading to get rid of the
+       // submodels
        if (mod->isworldmodel != isworldmodel)
                mod->loaded = false;
+
+       // if it is not loaded or checkdisk is true we need to calculate the crc
        if (!mod->loaded || checkdisk)
        {
                if (checkdisk && mod->loaded)
@@ -164,13 +172,15 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea
                if (buf)
                {
                        crc = CRC_Block((unsigned char *)buf, filesize);
+                       // we need to reload the model if the crc does not match
                        if (mod->crc != crc)
                                mod->loaded = false;
                }
        }
+
+       // if the model is already loaded and checks passed, just return
        if (mod->loaded)
        {
-               // already loaded
                if (buf)
                        Mem_Free(buf);
                return mod;
@@ -381,7 +391,7 @@ static void Mod_Print(void)
        Con_Print("Loaded models:\n");
        for (i = 0, mod = mod_known;i < mod_numknown;i++, mod++)
                if (mod->name[0])
-                       Con_Printf("%4iK %s\n", mod->mempool ? (mod->mempool->totalsize + 1023) / 1024 : 0, mod->name);
+                       Con_Printf("%4iK %s\n", mod->mempool ? (int)((mod->mempool->totalsize + 1023) / 1024) : 0, mod->name);
 }
 
 /*
@@ -972,19 +982,25 @@ void Mod_ShadowMesh_Free(shadowmesh_t *mesh)
        }
 }
 
-static rtexture_t *GL_TextureForSkinLayer(const unsigned char *in, int width, int height, const char *name, const unsigned int *palette, int textureflags)
+static rtexture_t *GL_TextureForSkinLayer(const unsigned char *in, int width, int height, const char *name, const unsigned int *palette, int textureflags, qboolean force)
 {
        int i;
-       for (i = 0;i < width*height;i++)
-               if (((unsigned char *)&palette[in[i]])[3] > 0)
-                       return R_LoadTexture2D (loadmodel->texturepool, name, width, height, in, TEXTYPE_PALETTE, textureflags, palette);
-       return NULL;
+       if (!force)
+       {
+               for (i = 0;i < width*height;i++)
+                       if (((unsigned char *)&palette[in[i]])[3] > 0)
+                               break;
+               if (i == width*height)
+                       return NULL;
+       }
+       return R_LoadTexture2D (loadmodel->texturepool, name, width, height, in, TEXTYPE_PALETTE, textureflags, palette);
 }
 
 int Mod_LoadSkinFrame(skinframe_t *skinframe, const char *basename, int textureflags, int loadpantsandshirt, int loadglowtexture)
 {
        imageskin_t s;
        memset(skinframe, 0, sizeof(*skinframe));
+       skinframe->base = r_texture_notexture;
        if (cls.state == ca_dedicated)
                return false;
        if (!image_loadskin(&s, basename))
@@ -1067,16 +1083,16 @@ int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, const char *basename, int
                        Mem_Free(temp1);
                }
                // use either a custom palette, or the quake palette
-               skinframe->base = skinframe->merged = GL_TextureForSkinLayer(skindata, width, height, va("%s_merged", basename), palette ? palette : (loadglowtexture ? palette_nofullbrights : ((textureflags & TEXF_ALPHA) ? palette_transparent : palette_complete)), textureflags); // all
+               skinframe->base = skinframe->merged = GL_TextureForSkinLayer(skindata, width, height, va("%s_merged", basename), palette ? palette : (loadglowtexture ? palette_nofullbrights : ((textureflags & TEXF_ALPHA) ? palette_transparent : palette_complete)), textureflags, true); // all
                if (!palette && loadglowtexture)
-                       skinframe->glow = GL_TextureForSkinLayer(skindata, width, height, va("%s_glow", basename), palette_onlyfullbrights, textureflags); // glow
+                       skinframe->glow = GL_TextureForSkinLayer(skindata, width, height, va("%s_glow", basename), palette_onlyfullbrights, textureflags, false); // glow
                if (!palette && loadpantsandshirt)
                {
-                       skinframe->pants = GL_TextureForSkinLayer(skindata, width, height, va("%s_pants", basename), palette_pantsaswhite, textureflags); // pants
-                       skinframe->shirt = GL_TextureForSkinLayer(skindata, width, height, va("%s_shirt", basename), palette_shirtaswhite, textureflags); // shirt
+                       skinframe->pants = GL_TextureForSkinLayer(skindata, width, height, va("%s_pants", basename), palette_pantsaswhite, textureflags, false); // pants
+                       skinframe->shirt = GL_TextureForSkinLayer(skindata, width, height, va("%s_shirt", basename), palette_shirtaswhite, textureflags, false); // shirt
                }
                if (skinframe->pants || skinframe->shirt)
-                       skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename),loadglowtexture ? palette_nocolormapnofullbrights : palette_nocolormap, textureflags); // no special colors
+                       skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename),loadglowtexture ? palette_nocolormapnofullbrights : palette_nocolormap, textureflags, false); // no special colors
                if (textureflags & TEXF_ALPHA)
                {
                        // if not using a custom alphapalette, use the quake one
@@ -1086,7 +1102,7 @@ int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, const char *basename, int
                                if (((unsigned char *)alphapalette)[skindata[i]*4+3] < 255)
                                        break;
                        if (i < width * height)
-                               skinframe->fog = GL_TextureForSkinLayer(skindata, width, height, va("%s_fog", basename), alphapalette, textureflags); // fog mask
+                               skinframe->fog = GL_TextureForSkinLayer(skindata, width, height, va("%s_fog", basename), alphapalette, textureflags, true); // fog mask
                }
        }
        else