multiple wad files seem to work now

This commit is contained in:
Bill Currie 2002-09-19 20:58:29 +00:00
parent 0cd34d155f
commit 8aa08dec28

View file

@ -284,7 +284,6 @@ typedef struct {
int infotableofs; int infotableofs;
} wadinfo_t; } wadinfo_t;
typedef struct { typedef struct {
int filepos; int filepos;
int disksize; int disksize;
@ -295,9 +294,14 @@ typedef struct {
char name[16]; // must be null terminated char name[16]; // must be null terminated
} lumpinfo_t; } lumpinfo_t;
typedef struct wadlist_s {
struct wadlist_s *next;
wadinfo_t wadinfo;
lumpinfo_t *lumpinfo;
} wadlist_t;
QFile *texfile; QFile *texfile;
wadinfo_t wadinfo; wadlist_t *wadlist;
lumpinfo_t *lumpinfo;
void void
CleanupName (char *in, char *out) CleanupName (char *in, char *out)
@ -319,24 +323,30 @@ void
TEX_InitFromWad (char *path) TEX_InitFromWad (char *path)
{ {
int i; int i;
wadlist_t *wl;
texfile = Qopen (path, "rb"); texfile = Qopen (path, "rb");
if (!texfile) if (!texfile)
Sys_Error ("couldn't open %s", path); Sys_Error ("couldn't open %s", path);
Qread (texfile, &wadinfo, sizeof (wadinfo));
if (strncmp (wadinfo.identification, "WAD2", 4))
Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", path);
wadinfo.numlumps = LittleLong (wadinfo.numlumps);
wadinfo.infotableofs = LittleLong (wadinfo.infotableofs);
Qseek (texfile, wadinfo.infotableofs, SEEK_SET);
lumpinfo = malloc (wadinfo.numlumps * sizeof (lumpinfo_t));
Qread (texfile, lumpinfo, wadinfo.numlumps * sizeof (lumpinfo_t));
for (i = 0; i < wadinfo.numlumps; i++) { wl = calloc (1, sizeof (wadlist_t));
CleanupName (lumpinfo[i].name, lumpinfo[i].name);
lumpinfo[i].filepos = LittleLong (lumpinfo[i].filepos); Qread (texfile, &wl->wadinfo, sizeof (wadinfo_t));
lumpinfo[i].disksize = LittleLong (lumpinfo[i].disksize); if (strncmp (wl->wadinfo.identification, "WAD2", 4))
Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", path);
wl->wadinfo.numlumps = LittleLong (wl->wadinfo.numlumps);
wl->wadinfo.infotableofs = LittleLong (wl->wadinfo.infotableofs);
Qseek (texfile, wl->wadinfo.infotableofs, SEEK_SET);
wl->lumpinfo = malloc (wl->wadinfo.numlumps * sizeof (lumpinfo_t));
Qread (texfile, wl->lumpinfo, wl->wadinfo.numlumps * sizeof (lumpinfo_t));
for (i = 0; i < wl->wadinfo.numlumps; i++) {
CleanupName (wl->lumpinfo[i].name, wl->lumpinfo[i].name);
wl->lumpinfo[i].filepos = LittleLong (wl->lumpinfo[i].filepos);
wl->lumpinfo[i].disksize = LittleLong (wl->lumpinfo[i].disksize);
} }
wl->next = wadlist;
wadlist = wl;
} }
int int
@ -345,16 +355,19 @@ LoadLump (char *name, dstring_t *dest)
char cname[16]; char cname[16];
int i; int i;
int ofs = dest->size; int ofs = dest->size;
wadlist_t *wl;
CleanupName (name, cname); CleanupName (name, cname);
for (i = 0; i < wadinfo.numlumps; i++) { for (wl = wadlist; wl; wl = wl->next) {
if (!strcmp (cname, lumpinfo[i].name)) { for (i = 0; i < wl->wadinfo.numlumps; i++) {
dest->size += lumpinfo[i].disksize; if (!strcmp (cname, wl->lumpinfo[i].name)) {
dest->size += wl->lumpinfo[i].disksize;
dstring_adjust (dest); dstring_adjust (dest);
Qseek (texfile, lumpinfo[i].filepos, SEEK_SET); Qseek (texfile, wl->lumpinfo[i].filepos, SEEK_SET);
Qread (texfile, dest->str + ofs, lumpinfo[i].disksize); Qread (texfile, dest->str + ofs, wl->lumpinfo[i].disksize);
return lumpinfo[i].disksize; return wl->lumpinfo[i].disksize;
}
} }
} }
@ -367,6 +380,7 @@ AddAnimatingTextures (void)
{ {
int base, i, j, k; int base, i, j, k;
char name[32]; char name[32];
wadlist_t *wl;
base = nummiptex; base = nummiptex;
@ -382,13 +396,16 @@ AddAnimatingTextures (void)
name[1] = 'A' + j - 10; // alternate animation name[1] = 'A' + j - 10; // alternate animation
// see if this name exists in the wadfile // see if this name exists in the wadfile
for (k = 0; k < wadinfo.numlumps; k++) for (wl = wadlist; wl; wl = wl->next) {
if (!strcmp (name, lumpinfo[k].name)) { for (k = 0; k < wl->wadinfo.numlumps; k++) {
if (!strcmp (name, wl->lumpinfo[k].name)) {
FindMiptex (name); // add to the miptex list FindMiptex (name); // add to the miptex list
break; break;
} }
} }
} }
}
}
printf ("added %i texture frames\n", nummiptex - base); printf ("added %i texture frames\n", nummiptex - base);
} }
@ -414,7 +431,7 @@ WriteMiptex (void)
path = strdup (path); path = strdup (path);
p = strtok (path, ";"); // yeah yeah. but it works :) p = strtok (path, ";"); // yeah yeah. but it works :)
while (p) { while (p) {
sprintf (fullpath, "%s/%s", /* FIXME gamedir */ ".", path); sprintf (fullpath, "%s/%s", /* FIXME gamedir */ ".", p);
TEX_InitFromWad (fullpath); TEX_InitFromWad (fullpath);