Applying paxed's patch. "This diff makes the image size cache in mapc
[neverball] / share / mapc.c
index 005ae56..0d7749b 100644 (file)
@@ -33,7 +33,6 @@
 #include <math.h>
 
 #include "vec3.h"
-#include "glext.h"
 #include "solid.h"
 #include "base_config.h"
 
@@ -295,10 +294,31 @@ static void targets(struct s_file *fp)
  * regardless of the number of surfaces refering to it.
  */
 
-static char *image_s[MAXM];
-static int   image_w[MAXM];
-static int   image_h[MAXM];
-static int   image_n;
+struct _imagedata
+{
+    char *s;
+    int w, h;
+};
+
+static struct _imagedata *imagedata = NULL;
+static int image_n = 0;
+static int image_alloc = 0;
+
+#define IMAGE_REALLOC 32
+
+static void free_imagedata()
+{
+    int i;
+
+    if (imagedata)
+    {
+        for (i = 0; i < image_n; i++)
+            free(imagedata[i].s);
+        free(imagedata);
+    }
+
+    image_n = image_alloc = 0;
+}
 
 static int size_load(const char *file, int *w, int *h)
 {
@@ -323,14 +343,15 @@ static void size_image(const char *name, int *w, int *h)
     char png[MAXSTR];
     int i;
 
-    for (i = 0; i < image_n; i++)
-        if (strncmp(image_s[i], name, MAXSTR) == 0)
-        {
-            *w = image_w[i];
-            *h = image_h[i];
+    if (imagedata)
+        for (i = 0; i < image_n; i++)
+            if (strncmp(imagedata[i].s, name, MAXSTR) == 0)
+            {
+                *w = imagedata[i].w;
+                *h = imagedata[i].h;
 
-            return;
-        }
+                return;
+            }
 
     *w = 0;
     *h = 0;
@@ -343,11 +364,30 @@ static void size_image(const char *name, int *w, int *h)
         size_load(config_data(tga), w, h) ||
         size_load(config_data(jpg), w, h))
     {
-        image_s[image_n] = (char *) calloc(strlen(name) + 1, 1);
-        image_w[image_n] = *w;
-        image_h[image_n] = *h;
 
-        strcpy(image_s[image_n], name);
+        if (image_n + 1 >= image_alloc)
+        {
+            struct _imagedata *tmp =
+                (struct _imagedata *) malloc(sizeof(struct _imagedata) * (image_alloc + IMAGE_REALLOC));
+            if (!tmp)
+            {
+                printf("malloc error\n");
+                exit(1);
+            }
+            if (imagedata)
+            {
+                (void) memcpy(tmp, imagedata, sizeof(struct _imagedata) * image_alloc);
+                free(imagedata);
+            }
+            imagedata = tmp;
+            image_alloc += IMAGE_REALLOC;
+        }
+
+        imagedata[image_n].s = (char *) calloc(strlen(name) + 1, 1);
+        imagedata[image_n].w = *w;
+        imagedata[image_n].h = *h;
+        strcpy(imagedata[image_n].s, name);
+
         image_n++;
     }
 }
@@ -928,11 +968,17 @@ static void make_goal(struct s_file *fp,
     zp->p[1] = 0.f;
     zp->p[2] = 0.f;
     zp->r    = 0.75;
+    zp->s    = 0;
+    zp->c    = 0;
 
     for (i = 0; i < c; i++)
     {
         if (strcmp(k[i], "radius") == 0)
             sscanf(v[i], "%f", &zp->r);
+        if (strcmp(k[i], "skip") == 0)
+            sscanf(v[i], "%d", &zp->s);
+        if (strcmp(k[i], "special") == 0)
+            sscanf(v[i], "%d", &zp->c);
 
         if (strcmp(k[i], "origin") == 0)
         {
@@ -1126,11 +1172,16 @@ static void make_ball(struct s_file *fp,
     up->w[1] = 0.f;
     up->w[2] = 0.f;
 
+    up->a = 90.f;
+
     for (i = 0; i < c; i++)
     {
         if (strcmp(k[i], "radius") == 0)
             sscanf(v[i], "%f", &up->r);
 
+        if (strcmp(k[i], "angle") == 0)
+            sscanf(v[i], "%f", &up->a);
+
         if (strcmp(k[i], "origin") == 0)
         {
             int x = 0, y = 0, z = 0;
@@ -2043,6 +2094,12 @@ static void dump_file(struct s_file *p, const char *name)
            p->rc, p->uc, p->ac, p->ic);
 }
 
+/* Skip the ugly SDL main substitution */
+/* Since we only need sdl_image */
+#ifdef main
+#    undef main
+#endif
+
 int main(int argc, char *argv[])
 {
     char src[MAXSTR];
@@ -2080,6 +2137,8 @@ int main(int argc, char *argv[])
                 sol_stor(&f, dst);
 
                 fclose(fin);
+
+                free_imagedata();
             }
         }
         else fprintf(stderr, "Failure to establish data directory\n");