#include "solid.h"
#include "base_image.h"
#include "base_config.h"
+#include "fs.h"
+#include "common.h"
#define MAXSTR 256
#define MAXKEY 16
/*---------------------------------------------------------------------------*/
-static int debug_output = 0;
+static const char *input_file;
+static int debug_output = 0;
/*---------------------------------------------------------------------------*/
strcpy(jpg, name); strcat(jpg, ".jpg");
strcpy(png, name); strcat(png, ".png");
- if (size_load(config_data(png), w, h) ||
- size_load(config_data(jpg), w, h))
+ if (size_load(png, w, h) ||
+ size_load(jpg, w, h))
{
if (image_n + 1 >= image_alloc)
/* Read the given material file, adding a new material to the solid. */
+#define scan_vec4(f, s, v) \
+ if (fs_gets((s), sizeof (s), (f))) \
+ sscanf((s), "%f %f %f %f", (v), (v) + 1, (v) + 2, (v) + 3)
+
static int read_mtrl(struct s_file *fp, const char *name)
{
+ static char line[MAXSTR];
struct s_mtrl *mp;
- FILE *fin;
+ fs_file fin;
int mi;
for (mi = 0; mi < fp->mc; mi++)
mp->fl = 0;
mp->angle = 45.0f;
- if ((fin = fopen(config_data(name), "r")))
+ if ((fin = fs_open(name, "r")))
{
- fscanf(fin,
- "%f %f %f %f "
- "%f %f %f %f "
- "%f %f %f %f "
- "%f %f %f %f "
- "%f %d %f",
- mp->d, mp->d + 1, mp->d + 2, mp->d + 3,
- mp->a, mp->a + 1, mp->a + 2, mp->a + 3,
- mp->s, mp->s + 1, mp->s + 2, mp->s + 3,
- mp->e, mp->e + 1, mp->e + 2, mp->e + 3,
- mp->h, &mp->fl, &mp->angle);
- fclose(fin);
+ scan_vec4(fin, line, mp->d);
+ scan_vec4(fin, line, mp->a);
+ scan_vec4(fin, line, mp->s);
+ scan_vec4(fin, line, mp->e);
+
+ if (fs_gets(line, sizeof (line), fin))
+ mp->h[0] = strtod(line, NULL);
+
+ if (fs_gets(line, sizeof (line), fin))
+ mp->fl = strtol(line, NULL, 10);
+
+ if (fs_gets(line, sizeof (line), fin))
+ mp->angle = strtod(line, NULL);
+
+ fs_close(fin);
}
+ else
+ fprintf(stderr, "%s: unknown material \"%s\"\n", input_file, name);
return mi;
}
+#undef scan_vec4
+
/*---------------------------------------------------------------------------*/
/*
{
char line[MAXSTR];
char mtrl[MAXSTR];
- FILE *fin;
+ fs_file fin;
int v0 = fp->vc;
int t0 = fp->tc;
int s0 = fp->sc;
- if ((fin = fopen(config_data(name), "r")))
+ if ((fin = fs_open(name, "r")))
{
- while (fgets(line, MAXSTR, fin))
+ while (fs_gets(line, MAXSTR, fin))
{
if (strncmp(line, "usemtl", 6) == 0)
{
else if (strncmp(line, "vn", 2) == 0) read_vn(fp, line + 2);
else if (strncmp(line, "v", 1) == 0) read_v (fp, line + 1);
}
- fclose(fin);
+ fs_close(fin);
}
}
#define T_END 4
#define T_NOP 5
-static int map_token(FILE *fin, int pi, char key[MAXSTR], char val[MAXSTR])
+static int map_token(fs_file fin, int pi, char key[MAXSTR], char val[MAXSTR])
{
char buf[MAXSTR];
- if (fgets(buf, MAXSTR, fin))
+ if (fs_gets(buf, MAXSTR, fin))
{
char c;
float x0, y0, z0;
/* Parse a lump from the given file and add it to the solid. */
-static void read_lump(struct s_file *fp, FILE *fin)
+static void read_lump(struct s_file *fp, fs_file fin)
{
char k[MAXSTR];
char v[MAXSTR];
make_ref(v[i], &xp->pi);
if (strcmp(k[i], "timer") == 0)
+ {
sscanf(v[i], "%f", &xp->t0);
+ xp->t = xp->t0;
+ }
if (strcmp(k[i], "state") == 0)
{
/*---------------------------------------------------------------------------*/
-static void read_ent(struct s_file *fp, FILE *fin)
+static void read_ent(struct s_file *fp, fs_file fin)
{
char k[MAXKEY][MAXSTR];
char v[MAXKEY][MAXSTR];
if (!strcmp(v[i], "misc_model")) make_body(fp, k, v, c, l0);
}
-static void read_map(struct s_file *fp, FILE *fin)
+static void read_map(struct s_file *fp, fs_file fin)
{
char k[MAXSTR];
char v[MAXSTR];
int main(int argc, char *argv[])
{
- char src[MAXSTR];
- char dst[MAXSTR];
+ char src[MAXSTR] = "";
+ char dst[MAXSTR] = "";
struct s_file f;
- FILE *fin;
+ fs_file fin;
+
+ if (!fs_init(argv[0]))
+ {
+ fprintf(stderr, "Failure to initialize virtual file system\n");
+ return 1;
+ }
if (argc > 2)
{
+ input_file = argv[1];
+
if (argc > 3 && strcmp(argv[3], "--debug") == 0)
debug_output = 1;
- if (config_data_path(argv[2], NULL))
- {
- strncpy(src, argv[1], MAXSTR);
- strncpy(dst, argv[1], MAXSTR);
+ strncpy(src, argv[1], MAXSTR - 1);
+ strncpy(dst, argv[1], MAXSTR - 1);
- if (strcmp(dst + strlen(dst) - 4, ".map") == 0)
- strcpy(dst + strlen(dst) - 4, ".sol");
- else
- strcat(dst, ".sol");
+ if (strcmp(dst + strlen(dst) - 4, ".map") == 0)
+ strcpy(dst + strlen(dst) - 4, ".sol");
+ else
+ strcat(dst, ".sol");
- if ((fin = fopen(src, "r")))
+ fs_add_path (dir_name(src));
+ fs_set_write_dir(dir_name(dst));
+
+ if ((fin = fs_open(base_name(src, NULL), "r")))
+ {
+ if (!fs_add_path_with_archives(argv[2]))
{
- init_file(&f);
- read_map(&f, fin);
+ fprintf(stderr, "Failure to establish data directory\n");
+ fs_close(fin);
+ fs_quit();
+ return 1;
+ }
- resolve();
- targets(&f);
+ init_file(&f);
+ read_map(&f, fin);
- clip_file(&f);
- move_file(&f);
- uniq_file(&f);
- smth_file(&f);
- sort_file(&f);
- node_file(&f);
- dump_file(&f, dst);
+ resolve();
+ targets(&f);
- sol_stor(&f, dst);
+ clip_file(&f);
+ move_file(&f);
+ uniq_file(&f);
+ smth_file(&f);
+ sort_file(&f);
+ node_file(&f);
+ dump_file(&f, dst);
- fclose(fin);
+ sol_stor(&f, base_name(dst, NULL));
- free_imagedata();
- }
+ fs_close(fin);
+
+ free_imagedata();
}
- else fprintf(stderr, "Failure to establish data directory\n");
}
else fprintf(stderr, "Usage: %s <map> <data> [--debug]\n", argv[0]);