]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
forgot to commit this
[xonotic/darkplaces.git] / model_shared.c
index f9fc38aec318cdc025f9d3f2d493c809edc0ceb1..a2ac48e6afda20853e9bb1e81e51b97da5784726 100644 (file)
@@ -30,12 +30,55 @@ model_t *loadmodel;
 #define        MAX_MOD_KNOWN   2048
 static model_t mod_known[MAX_MOD_KNOWN];
 
+rtexture_t *r_notexture;
+rtexturepool_t *r_notexturepool;
+
+texture_t r_surf_notexture;
+
+void Mod_SetupNoTexture(void)
+{
+       int x, y;
+       qbyte pix[16][16][4];
+
+       // this makes a light grey/dark grey checkerboard texture
+       for (y = 0;y < 16;y++)
+       {
+               for (x = 0;x < 16;x++)
+               {
+                       if ((y < 8) ^ (x < 8))
+                       {
+                               pix[y][x][0] = 128;
+                               pix[y][x][1] = 128;
+                               pix[y][x][2] = 128;
+                               pix[y][x][3] = 255;
+                       }
+                       else
+                       {
+                               pix[y][x][0] = 64;
+                               pix[y][x][1] = 64;
+                               pix[y][x][2] = 64;
+                               pix[y][x][3] = 255;
+                       }
+               }
+       }
+
+       r_notexturepool = R_AllocTexturePool();
+       r_notexture = R_LoadTexture(r_notexturepool, "notexture", 16, 16, &pix[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP);
+}
+
+extern void Mod_BrushStartup (void);
+extern void Mod_BrushShutdown (void);
+
 static void mod_start(void)
 {
        int i;
        for (i = 0;i < MAX_MOD_KNOWN;i++)
                if (mod_known[i].name[0])
                        Mod_UnloadModel(&mod_known[i]);
+       Mod_LoadModels();
+
+       Mod_SetupNoTexture();
+       Mod_BrushStartup();
 }
 
 static void mod_shutdown(void)
@@ -44,6 +87,9 @@ static void mod_shutdown(void)
        for (i = 0;i < MAX_MOD_KNOWN;i++)
                if (mod_known[i].name[0])
                        Mod_UnloadModel(&mod_known[i]);
+
+       R_FreeTexturePool(&r_notexturepool);
+       Mod_BrushShutdown();
 }
 
 static void mod_newmap(void)
@@ -151,9 +197,6 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
                crc = CRC_Block(buf, com_filesize);
        }
 
-       // make sure nothing got trashed
-       //Mem_CheckSentinelsGlobal();
-
        // allocate a new model
        loadmodel = mod;
 
@@ -179,9 +222,6 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
 
        Mem_Free(buf);
 
-       // make sure nothing got trashed
-       //Mem_CheckSentinelsGlobal();
-
        return mod;
 }
 
@@ -208,21 +248,12 @@ Mod_ClearAll
 */
 void Mod_ClearAll (void)
 {
-       /*
-       int             i;
-       model_t *mod;
-
-       for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++)
-               if (mod->name[0])
-                       if (mod->usesheap)
-                               Mod_FreeModel(mod);
-       */
 }
 
 void Mod_ClearUsed(void)
 {
-       int             i;
-       model_t *mod;
+       int i;
+       model_t *mod;
 
        for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++)
                if (mod->name[0])
@@ -231,8 +262,8 @@ void Mod_ClearUsed(void)
 
 void Mod_PurgeUnused(void)
 {
-       int             i;
-       model_t *mod;
+       int i;
+       model_t *mod;
 
        for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++)
                if (mod->name[0])
@@ -240,16 +271,27 @@ void Mod_PurgeUnused(void)
                                Mod_FreeModel(mod);
 }
 
+void Mod_LoadModels(void)
+{
+       int i;
+       model_t *mod;
+
+       for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++)
+               if (mod->name[0])
+                       if (mod->used)
+                               Mod_CheckLoaded(mod);
+}
+
 /*
 ==================
 Mod_FindName
 
 ==================
 */
-model_t *Mod_FindName (char *name)
+model_t *Mod_FindName (const char *name)
 {
-       int             i;
-       model_t *mod, *freemod;
+       int i;
+       model_t *mod, *freemod;
 
        if (!name[0])
                Host_Error ("Mod_ForName: NULL name");
@@ -289,7 +331,7 @@ Mod_TouchModel
 
 ==================
 */
-void Mod_TouchModel (char *name)
+void Mod_TouchModel (const char *name)
 {
        model_t *mod;
 
@@ -304,30 +346,13 @@ Mod_ForName
 Loads in a model for the given name
 ==================
 */
-model_t *Mod_ForName (char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel)
+model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel)
 {
        return Mod_LoadModel (Mod_FindName (name), crash, checkdisk, isworldmodel);
 }
 
 qbyte *mod_base;
 
-/*
-=================
-RadiusFromBounds
-=================
-*/
-/*
-float RadiusFromBounds (vec3_t mins, vec3_t maxs)
-{
-       int             i;
-       vec3_t  corner;
-
-       for (i=0 ; i<3 ; i++)
-               corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
-
-       return Length (corner);
-}
-*/
 
 //=============================================================================
 
@@ -355,5 +380,31 @@ static void Mod_Flush (void)
        for (i = 0;i < MAX_MOD_KNOWN;i++)
                if (mod_known[i].name[0])
                        Mod_UnloadModel(&mod_known[i]);
+       Mod_LoadModels();
 }
 
+int Mod_FindTriangleWithEdge(int *elements, int numtriangles, int start, int end)
+{
+       int i;
+       for (i = 0;i < numtriangles;i++, elements += 3)
+       {
+               if (elements[0] == start && elements[1] == end)
+                       return i;
+               if (elements[1] == start && elements[2] == end)
+                       return i;
+               if (elements[2] == start && elements[0] == end)
+                       return i;
+       }
+       return -1;
+}
+
+void Mod_BuildTriangleNeighbors(int *neighbors, int *elements, int numtriangles)
+{
+       int i, *e, *n;
+       for (i = 0, e = elements, n = neighbors;i < numtriangles;i++, e += 3, n += 3)
+       {
+               n[0] = Mod_FindTriangleWithEdge(elements, numtriangles, e[1], e[0]);
+               n[1] = Mod_FindTriangleWithEdge(elements, numtriangles, e[2], e[1]);
+               n[2] = Mod_FindTriangleWithEdge(elements, numtriangles, e[0], e[2]);
+       }
+}