]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
patch from div0 that enables printf format warnings in gcc
[xonotic/darkplaces.git] / model_shared.c
index 8b2333f48e01d19c3153cb4e765cbbd719e8b80c..a613449eb92d80caf06203a777c32b61a91c0e5a 100644 (file)
@@ -49,7 +49,7 @@ static void mod_start(void)
        model_t *mod;
 
        for (i = 0, mod = mod_known;i < mod_numknown;i++, mod++)
-               if (mod->name[0])
+               if (mod->name[0] && mod->name[0] != '*')
                        if (mod->used)
                                Mod_LoadModel(mod, true, false, mod->isworldmodel);
 }
@@ -60,7 +60,7 @@ static void mod_shutdown(void)
        model_t *mod;
 
        for (i = 0, mod = mod_known;i < mod_numknown;i++, mod++)
-               if (mod->loaded)
+               if (mod->loaded || mod->mempool)
                        Mod_UnloadModel(mod);
 }
 
@@ -118,7 +118,7 @@ void Mod_UnloadModel (model_t *mod)
        char name[MAX_QPATH];
        qboolean isworldmodel;
        qboolean used;
-       strcpy(name, mod->name);
+       strlcpy(name, mod->name, sizeof(name));
        isworldmodel = mod->isworldmodel;
        used = mod->used;
        // free textures/memory attached to the model
@@ -127,7 +127,7 @@ void Mod_UnloadModel (model_t *mod)
        // clear the struct to make it available
        memset(mod, 0, sizeof(model_t));
        // restore the fields we want to preserve
-       strcpy(mod->name, name);
+       strlcpy(mod->name, name, sizeof(mod->name));
        mod->isworldmodel = isworldmodel;
        mod->used = used;
        mod->loaded = false;
@@ -178,7 +178,7 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea
 
        Con_DPrintf("loading model %s\n", mod->name);
        // LordHavoc: unload the existing model in this slot (if there is one)
-       if (mod->loaded)
+       if (mod->loaded || mod->mempool)
                Mod_UnloadModel(mod);
 
        // load the model
@@ -197,15 +197,16 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea
        VectorSet(mod->rotatedmins, -mod->radius, -mod->radius, -mod->radius);
        VectorSet(mod->rotatedmaxs, mod->radius, mod->radius, mod->radius);
 
-       // all models use memory, so allocate a memory pool
-       mod->mempool = Mem_AllocPool(mod->name, 0, NULL);
-       // all models load textures, so allocate a texture pool
-       if (cls.state != ca_dedicated)
-               mod->texturepool = R_AllocTexturePool();
-
        if (buf)
        {
                char *bufend = (char *)buf + filesize;
+
+               // all models use memory, so allocate a memory pool
+               mod->mempool = Mem_AllocPool(mod->name, 0, NULL);
+               // all models load textures, so allocate a texture pool
+               if (cls.state != ca_dedicated)
+                       mod->texturepool = R_AllocTexturePool();
+
                num = LittleLong(*((int *)buf));
                // call the apropriate loader
                loadmodel = mod;
@@ -322,7 +323,7 @@ model_t *Mod_FindName(const char *name)
        if (mod_numknown == i)
                mod_numknown++;
        mod = mod_known + i;
-       strcpy (mod->name, name);
+       strlcpy (mod->name, name, sizeof(mod->name));
        mod->loaded = false;
        mod->used = true;
        return mod;
@@ -344,6 +345,24 @@ model_t *Mod_ForName(const char *name, qboolean crash, qboolean checkdisk, qbool
        return model;
 }
 
+/*
+==================
+Mod_Reload
+
+Reloads all models if they have changed
+==================
+*/
+void Mod_Reload()
+{
+       int i;
+       model_t *mod;
+
+       for (i = 0, mod = mod_known;i < mod_numknown;i++, mod++)
+               if (mod->name[0] && mod->name[0] != '*')
+                       if (mod->used)
+                               Mod_LoadModel(mod, true, true, mod->isworldmodel);
+}
+
 unsigned char *mod_base;
 
 
@@ -362,7 +381,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);
 }
 
 /*
@@ -953,13 +972,18 @@ 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)
@@ -1048,16 +1072,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
@@ -1067,7 +1091,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