]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Dynamically allocate Q3 shader texture frames.
authorres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 17 Dec 2007 03:04:48 +0000 (03:04 +0000)
committerres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 17 Dec 2007 03:04:48 +0000 (03:04 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7807 d7cf8633-e32d-0410-b094-e92efae38249

model_shared.c
model_shared.h

index 5dcafffac758bb78f64a55885db82d1ba43e4ed6..005dd3282da75b24a8db5d9f82302d6e9618738c 100644 (file)
@@ -44,6 +44,7 @@ typedef struct q3shader_data_s
 {
   memexpandablearray_t hash_entries;
   q3shader_hash_entry_t hash[Q3SHADER_HASH_SIZE];
+  memexpandablearray_t char_ptrs;
 } q3shader_data_t;
 static q3shader_data_t* q3shader_data;
 
@@ -1126,6 +1127,8 @@ static void Q3Shaders_Clear()
                sizeof (q3shader_data_t));
        Mem_ExpandableArray_NewArray (&q3shader_data->hash_entries, 
                q3shaders_mem, sizeof (q3shader_hash_entry_t), 256);
+       Mem_ExpandableArray_NewArray (&q3shader_data->char_ptrs,
+               q3shaders_mem, sizeof (char**), 256);
 }
 
 static void Q3Shader_AddToHash (q3shaderinfo_t* shader)
@@ -1306,7 +1309,9 @@ void Mod_LoadQ3Shaders(void)
                                                                layer->clampmap = true;
                                                        layer->numframes = 1;
                                                        layer->framerate = 1;
-                                                       strlcpy(layer->texturename[0], parameter[1], sizeof(layer->texturename));
+                                                       layer->texturename = (char**)Mem_ExpandableArray_AllocRecord (
+                                                               &q3shader_data->char_ptrs);
+                                                       layer->texturename[0] = Mem_strdup (q3shaders_mem, parameter[1]);
                                                        if (!strcasecmp(parameter[1], "$lightmap"))
                                                                shader.lighting = true;
                                                }
@@ -1315,8 +1320,9 @@ void Mod_LoadQ3Shaders(void)
                                                        int i;
                                                        layer->numframes = min(numparameters - 2, TEXTURE_MAXFRAMES);
                                                        layer->framerate = atof(parameter[1]);
+                                                       layer->texturename = Mem_Alloc (q3shaders_mem, sizeof (char*) * layer->numframes);
                                                        for (i = 0;i < layer->numframes;i++)
-                                                               strlcpy(layer->texturename[i], parameter[i + 2], sizeof(layer->texturename));
+                                                               layer->texturename[i] = Mem_strdup (q3shaders_mem, parameter[i + 2]);
                                                }
                                                else if (numparameters >= 2 && !strcasecmp(parameter[0], "rgbgen"))
                                                {
@@ -1629,7 +1635,8 @@ void Mod_LoadQ3Shaders(void)
                                        shader.primarylayer = 1;
                                }
                                // now see if the lightmap came first, and if so choose the second texture instead
-                               if (!strcasecmp(shader.layers[shader.primarylayer].texturename[0], "$lightmap"))
+                               if ((shader.layers[shader.primarylayer].texturename != NULL)
+                                 && !strcasecmp(shader.layers[shader.primarylayer].texturename[0], "$lightmap"))
                                {
                                        shader.backgroundlayer = -1;
                                        shader.primarylayer = 1;
index f27a242a6594f22e4f5c1529a2316c031c4310c3..4020b2b716a096a6c844819a8368d1fb38e733f5 100644 (file)
@@ -341,7 +341,7 @@ typedef struct q3shaderinfo_layer_s
        int clampmap;
        float framerate;
        int numframes;
-       char texturename[TEXTURE_MAXFRAMES][Q3PATHLENGTH];
+       char** texturename;
        int blendfunc[2];
        q3shaderinfo_layer_rgbgen_t rgbgen;
        q3shaderinfo_layer_alphagen_t alphagen;