]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
Fix some warnings found by cppcheck
[xonotic/darkplaces.git] / model_shared.c
index 73d87d2d22c6beb81cd7eca91c2362ad2b1d635e..077197aa23b0ab09091e4957add9d7db5c072425 100644 (file)
@@ -65,7 +65,7 @@ static void mod_start(void)
        int nummodels = (int)Mem_ExpandableArray_IndexRange(&models);
        dp_model_t *mod;
 
-       SCR_PushLoadingScreen(false, "Loading models", 1.0);
+       SCR_PushLoadingScreen("Loading models", 1.0);
        count = 0;
        for (i = 0;i < nummodels;i++)
                if ((mod = (dp_model_t*) Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0] && mod->name[0] != '*')
@@ -75,7 +75,7 @@ static void mod_start(void)
                if ((mod = (dp_model_t*) Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0] && mod->name[0] != '*')
                        if (mod->used)
                        {
-                               SCR_PushLoadingScreen(true, mod->name, 1.0 / count);
+                               SCR_PushLoadingScreen(mod->name, 1.0 / count);
                                Mod_LoadModel(mod, true, false);
                                SCR_PopLoadingScreen(false);
                        }
@@ -174,10 +174,10 @@ void Mod_Init (void)
        Cvar_RegisterVariable(&mod_generatelightmaps_vertexradius);
        Cvar_RegisterVariable(&mod_generatelightmaps_gridradius);
 
-       Cmd_AddCommand(&cmd_client, "modellist", Mod_Print_f, "prints a list of loaded models");
-       Cmd_AddCommand(&cmd_client, "modelprecache", Mod_Precache_f, "load a model");
-       Cmd_AddCommand(&cmd_client, "modeldecompile", Mod_Decompile_f, "exports a model in several formats for editing purposes");
-       Cmd_AddCommand(&cmd_client, "mod_generatelightmaps", Mod_GenerateLightmaps_f, "rebuilds lighting on current worldmodel");
+       Cmd_AddCommand(CMD_CLIENT, "modellist", Mod_Print_f, "prints a list of loaded models");
+       Cmd_AddCommand(CMD_CLIENT, "modelprecache", Mod_Precache_f, "load a model");
+       Cmd_AddCommand(CMD_CLIENT, "modeldecompile", Mod_Decompile_f, "exports a model in several formats for editing purposes");
+       Cmd_AddCommand(CMD_CLIENT, "mod_generatelightmaps", Mod_GenerateLightmaps_f, "rebuilds lighting on current worldmodel");
 }
 
 void Mod_RenderInit(void)
@@ -458,7 +458,7 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk)
        if (developer_loading.integer)
                Con_Printf("loading model %s\n", mod->name);
        
-       SCR_PushLoadingScreen(true, mod->name, 1);
+       SCR_PushLoadingScreen(mod->name, 1);
 
        // LadyHavoc: unload the existing model in this slot (if there is one)
        if (mod->loaded || mod->mempool)
@@ -579,9 +579,6 @@ dp_model_t *Mod_FindName(const char *name, const char *parentname)
        if (!parentname)
                parentname = "";
 
-       // if we're not dedicatd, the renderer calls will crash without video
-       Host_StartVideo();
-
        nummodels = (int)Mem_ExpandableArray_IndexRange(&models);
 
        if (!name[0])
@@ -638,7 +635,7 @@ void Mod_Reload(void)
        int nummodels = (int)Mem_ExpandableArray_IndexRange(&models);
        dp_model_t *mod;
 
-       SCR_PushLoadingScreen(false, "Reloading models", 1.0);
+       SCR_PushLoadingScreen("Reloading models", 1.0);
        count = 0;
        for (i = 0;i < nummodels;i++)
                if ((mod = (dp_model_t *) Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0] && mod->name[0] != '*' && mod->used)
@@ -646,7 +643,7 @@ void Mod_Reload(void)
        for (i = 0;i < nummodels;i++)
                if ((mod = (dp_model_t *) Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0] && mod->name[0] != '*' && mod->used)
                {
-                       SCR_PushLoadingScreen(true, mod->name, 1.0 / count);
+                       SCR_PushLoadingScreen(mod->name, 1.0 / count);
                        Mod_LoadModel(mod, true, true);
                        SCR_PopLoadingScreen(false);
                }
@@ -2555,6 +2552,7 @@ nothing                GL_ZERO GL_ONE
        {
                if (developer_extra.integer)
                        Con_DPrintf("^1%s:^7 using fallback noshader material for ^3\"%s\"\n", modelname, name);
+               texture->basematerialflags = defaultmaterialflags;
                texture->supercontents = SUPERCONTENTS_SOLID | SUPERCONTENTS_OPAQUE;
        }
        else if (!strcmp(texture->name, "common/nodraw") || !strcmp(texture->name, "textures/common/nodraw"))
@@ -2651,7 +2649,7 @@ void Mod_LoadCustomMaterial(mempool_t *mempool, texture_t *texture, const char *
 
 void Mod_UnloadCustomMaterial(texture_t *texture, qboolean purgeskins)
 {
-       int i, j;
+       long unsigned int i, j;
        for (i = 0; i < sizeof(texture->shaderpasses) / sizeof(texture->shaderpasses[0]); i++)
        {
                if (texture->shaderpasses[i])
@@ -2865,6 +2863,8 @@ void Mod_MakeSortedSurfaces(dp_model_t *mod)
        for (j = 0;j < mod->nummodelsurfaces;j++)
        {
                const msurface_t *surface = mod->data_surfaces + j + mod->firstmodelsurface;
+               if(!surface->texture)
+                       continue;
                t = (int)(surface->texture - mod->data_textures);
                numsurfacesfortexture[t]++;
        }
@@ -2877,6 +2877,8 @@ void Mod_MakeSortedSurfaces(dp_model_t *mod)
        for (j = 0;j < mod->nummodelsurfaces;j++)
        {
                const msurface_t *surface = mod->data_surfaces + j + mod->firstmodelsurface;
+               if (!surface->texture)
+                       continue;
                t = (int)(surface->texture - mod->data_textures);
                mod->sortedmodelsurfaces[firstsurfacefortexture[t]++] = j + mod->firstmodelsurface;
        }
@@ -4398,9 +4400,10 @@ texture_t *Mod_Mesh_GetTexture(dp_model_t *mod, const char *name, int defaultdra
 {
        int i;
        texture_t *t;
-       for (i = 0; i < mod->num_textures; i++)
-               if (!strcmp(mod->data_textures[i].name, name))
-                       return mod->data_textures + i;
+       int drawflag = defaultdrawflags & DRAWFLAG_MASK;
+       for (i = 0, t = mod->data_textures; i < mod->num_textures; i++, t++)
+               if (!strcmp(t->name, name) && t->mesh_drawflag == drawflag && t->mesh_defaulttexflags == defaulttexflags && t->mesh_defaultmaterialflags == defaultmaterialflags)
+                       return t;
        if (mod->max_textures <= mod->num_textures)
        {
                texture_t *oldtextures = mod->data_textures;
@@ -4411,7 +4414,10 @@ texture_t *Mod_Mesh_GetTexture(dp_model_t *mod, const char *name, int defaultdra
                        mod->data_surfaces[i].texture = mod->data_textures + (mod->data_surfaces[i].texture - oldtextures);
        }
        t = &mod->data_textures[mod->num_textures++];
-       Mod_LoadTextureFromQ3Shader(mod->mempool, mod->name, t, name, false, true, defaulttexflags, defaultmaterialflags);
+       Mod_LoadTextureFromQ3Shader(mod->mempool, mod->name, t, name, true, true, defaulttexflags, defaultmaterialflags);
+       t->mesh_drawflag = drawflag;
+       t->mesh_defaulttexflags = defaulttexflags;
+       t->mesh_defaultmaterialflags = defaultmaterialflags;
        switch (defaultdrawflags & DRAWFLAG_MASK)
        {
        case DRAWFLAG_ADDITIVE:
@@ -4598,7 +4604,7 @@ static void Mod_Mesh_MakeSortedSurfaces(dp_model_t *mod)
        }
 }
 
-void Mod_Mesh_ComputeBounds(dp_model_t *mod)
+static void Mod_Mesh_ComputeBounds(dp_model_t *mod)
 {
        int i;
        vec_t x2a, x2b, y2a, y2b, z2a, z2b, x2, y2, z2, yawradius, rotatedradius;
@@ -4678,7 +4684,7 @@ void Mod_Mesh_Validate(dp_model_t *mod)
        }
 }
 
-void Mod_Mesh_UploadDynamicBuffers(dp_model_t *mod)
+static void Mod_Mesh_UploadDynamicBuffers(dp_model_t *mod)
 {
        mod->surfmesh.data_element3s_indexbuffer = mod->surfmesh.data_element3s ? R_BufferData_Store(mod->surfmesh.num_triangles * sizeof(short[3]), mod->surfmesh.data_element3s, R_BUFFERDATA_INDEX16, &mod->surfmesh.data_element3s_bufferoffset) : NULL;
        mod->surfmesh.data_element3i_indexbuffer = mod->surfmesh.data_element3i ? R_BufferData_Store(mod->surfmesh.num_triangles * sizeof(int[3]), mod->surfmesh.data_element3i, R_BUFFERDATA_INDEX32, &mod->surfmesh.data_element3i_bufferoffset) : NULL;