-/*
+/*
* Copyright (C) 2003 Robert Kooima
*
* NEVERBALL is free software; you can redistribute it and/or modify
#include <math.h>
#include "vec3.h"
-#include "glext.h"
#include "solid.h"
#include "base_config.h"
/* Ohhhh... arbitrary! */
-#define MAXM 256
+#define MAXM 256
#define MAXV 32767
-#define MAXE 32767
-#define MAXS 32767
-#define MAXT 32767
-#define MAXG 32767
-#define MAXL 1024
-#define MAXN 1024
-#define MAXP 512
-#define MAXB 512
-#define MAXC 1024
+#define MAXE 32767
+#define MAXS 32767
+#define MAXT 32767
+#define MAXG 32767
+#define MAXL 1024
+#define MAXN 1024
+#define MAXP 512
+#define MAXB 512
+#define MAXC 1024
#define MAXZ 16
-#define MAXJ 32
-#define MAXX 16
-#define MAXR 1024
-#define MAXU 16
+#define MAXJ 32
+#define MAXX 16
+#define MAXR 1024
+#define MAXU 16
#define MAXW 32
#define MAXD 128
-#define MAXA 512
-#define MAXI 32767
+#define MAXA 8192
+#define MAXI 32767
static int overflow(const char *s)
{
* 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)
{
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;
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++;
}
}
gp->si += (s0 - 1);
gp->sj += (s0 - 1);
gp->sk += (s0 - 1);
-
+
gp->mi = mi;
}
v_crs(plane_n[pi], u, v);
v_nrm(plane_n[pi], plane_n[pi]);
-
+
plane_d[pi] = v_dot(plane_n[pi], p1);
for (i = 0; i < 6; i++)
if (strcmp(k[i], "targetname") == 0)
make_sym(v[i], bi);
- if (strcmp(k[i], "target") == 0)
+ else if (strcmp(k[i], "target") == 0)
make_ref(v[i], &bp->pi);
- if (strcmp(k[i], "model") == 0)
+ else if (strcmp(k[i], "model") == 0)
read_obj(fp, v[i]);
- if (strcmp(k[i], "origin") == 0)
+ else if (strcmp(k[i], "origin") == 0)
sscanf(v[i], "%d %d %d", &x, &y, &z);
- if (strcmp(k[i], "message") == 0)
+ else if (strcmp(k[i], "classname") != 0)
{
- strcpy(fp->av, v[i]);
- fp->ac = (int) (strlen(v[i]) + 1);
+ /* Considers other strings as metadata */
+ strcat(fp->av, k[i]);
+ strcat(fp->av, "=");
+ strcat(fp->av, v[i]);
+ strcat(fp->av, "\n");
+ fp->ac += (int) (strlen(v[i]) + (strlen(k[i])) + 2);
}
}
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)
{
xp->t = 0;
xp->f0 = 0;
xp->f = 0;
+ xp->i = 0;
for (i = 0; i < c; i++)
{
if (strcmp(k[i], "state") == 0)
xp->f = atoi(v[i]);
+ if (strcmp(k[i], "invisible") == 0)
+ xp->i = atoi(v[i]);
+
if (strcmp(k[i], "origin") == 0)
{
int x = 0, y = 0, z = 0;
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;
m_basis(M, fp->sv[si].n, fp->sv[sj].n, fp->sv[sk].n);
m_xps(X, M);
-
+
if (m_inv(I, X))
{
m_vxfm(p, I, d);
}
/* Sort all lumps in the range by their flag values. */
-
+
for (li = 1; li < lc; li++)
for (lj = 0; lj < li; lj++)
if (fp->lv[l0 + li].fl < fp->lv[l0 + lj].fl)
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];
sol_stor(&f, dst);
fclose(fin);
+
+ free_imagedata();
}
}
else fprintf(stderr, "Failure to establish data directory\n");