From f6ebcd45ac4eb246e64699fa33be8875095d0995 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 12 Sep 2010 19:47:44 +0900 Subject: [PATCH] Use QF's wadfile support. Still fragile, but it can load wad files. --- tools/Forge/Bundles/MapEdit/TexturePalette.m | 75 +++++++------------- 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/tools/Forge/Bundles/MapEdit/TexturePalette.m b/tools/Forge/Bundles/MapEdit/TexturePalette.m index d167c4608..bffea9565 100644 --- a/tools/Forge/Bundles/MapEdit/TexturePalette.m +++ b/tools/Forge/Bundles/MapEdit/TexturePalette.m @@ -3,6 +3,7 @@ #include "QF/qendian.h" #include "QF/quakeio.h" #include "QF/sys.h" +#include "QF/wadfile.h" #include "TexturePalette.h" #include "Preferences.h" @@ -16,8 +17,6 @@ id texturepalette_i; -#define TYP_MIPTEX 67 - int tex_count; qtexture_t qtextures[MAX_TEXTURES]; @@ -74,11 +73,16 @@ TEX_InitPalette ============== */ void -TEX_InitPalette (byte * pal) +TEX_InitPalette (wad_t *wad, lumpinfo_t *pallump) { + byte *pal, *opal; int r, g, b, v; int i; + opal = pal = malloc (pallump->size); + Qseek (wad->handle, pallump->filepos, SEEK_SET); + Qread (wad->handle, pal, pallump->size); + for (i = 0; i < 256; i++) { r = pal[0]; g = pal[1]; @@ -90,6 +94,7 @@ TEX_InitPalette (byte * pal) tex_palette[i] = v; } + free (opal); } @@ -99,8 +104,9 @@ TEX_ImageFromMiptex ================= */ void -TEX_ImageFromMiptex (miptex_t *qtex) +TEX_ImageFromMiptex (wad_t *wad, lumpinfo_t *qtexlump) { + miptex_t *qtex; NSBitmapImageRep *bm; byte *source; unsigned *dest; @@ -108,6 +114,10 @@ TEX_ImageFromMiptex (miptex_t *qtex) qtexture_t *q; int tr, tg, tb; + qtex = malloc (qtexlump->size); + Qseek (wad->handle, qtexlump->filepos, SEEK_SET); + Qread (wad->handle, qtex, qtexlump->size); + width = LittleLong (qtex->width); height = LittleLong (qtex->height); @@ -139,27 +149,11 @@ TEX_ImageFromMiptex (miptex_t *qtex) q->flatcolor.chan[1] = tg / count; q->flatcolor.chan[2] = tb / count; q->flatcolor.chan[3] = 0xff; + free (qtex); } //============================================================================= -typedef struct { - char identification[4]; // should be WAD2 or 2DAW - int numlumps; - int infotableofs; -} wadinfo_t; - - -typedef struct { - int filepos; - int disksize; - int size; // uncompressed - char type; - char compression; - char pad1, pad2; - char name[16]; // must be null terminated -} lumpinfo_t; - /* ================= TEX_InitFromWad @@ -171,18 +165,15 @@ TEX_InitFromWad (char *path) int i; char local[1024]; char newpath[1024]; - byte *wadfile; - wadinfo_t *wadinfo; - lumpinfo_t *lumpinfo; - int numlumps; float start, stop; - QFile *file; - size_t size; + wad_t *wad; + lumpinfo_t *lumpinfo; start = Sys_DoubleTime (); strcpy (newpath,[preferences_i getProjectPath]); - strcat (newpath, "/"); + if (newpath[0]) + strcat (newpath, "/"); strcat (newpath, path); // free any textures @@ -191,42 +182,28 @@ TEX_InitFromWad (char *path) tex_count = 0; // try and use the cached wadfile - sprintf (local, "/qcache%s", newpath); - // Sys_UpdateFile (local, newpath); - // FIXME use wad functions - file = Qopen (local, "rb"); - size = Qfilesize (file); - wadfile = malloc (size); - Qread (file, wadfile, size); - Qclose (file); - wadinfo = (wadinfo_t *) wadfile; + Sys_Printf ("TEX_InitFromWad %s\n", newpath); + wad = wad_open (newpath); - if (strncmp ((char *) wadfile, "WAD2", 4)) { - unlink (local); - Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", newpath); - } - - numlumps = LittleLong (wadinfo->numlumps); - lumpinfo = (lumpinfo_t *) (wadfile + LittleLong (wadinfo->infotableofs)); + lumpinfo = wad->lumps; if (strcmp (lumpinfo->name, "PALETTE")) { unlink (local); Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0", path); } - TEX_InitPalette (wadfile + LittleLong (lumpinfo->filepos)); + TEX_InitPalette (wad, lumpinfo); lumpinfo++; - for (i = 1; i < numlumps; i++, lumpinfo++) { + for (i = 1; i < wad->numlumps; i++, lumpinfo++) { if (lumpinfo->type != TYP_MIPTEX) Sys_Error ("TEX_InitFromWad: %s is not a miptex!", lumpinfo->name); // XXX CleanupName (lumpinfo->name,qtextures[tex_count].name); - TEX_ImageFromMiptex ((miptex_t *) (wadfile + - LittleLong (lumpinfo->filepos))); + TEX_ImageFromMiptex (wad, lumpinfo); } - free (wadfile); + wad_close (wad); stop = Sys_DoubleTime ();