mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
Use QF's wadfile support.
Still fragile, but it can load wad files.
This commit is contained in:
parent
972e98ec09
commit
f6ebcd45ac
1 changed files with 26 additions and 49 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "QF/qendian.h"
|
#include "QF/qendian.h"
|
||||||
#include "QF/quakeio.h"
|
#include "QF/quakeio.h"
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
|
#include "QF/wadfile.h"
|
||||||
|
|
||||||
#include "TexturePalette.h"
|
#include "TexturePalette.h"
|
||||||
#include "Preferences.h"
|
#include "Preferences.h"
|
||||||
|
@ -16,8 +17,6 @@
|
||||||
id texturepalette_i;
|
id texturepalette_i;
|
||||||
|
|
||||||
|
|
||||||
#define TYP_MIPTEX 67
|
|
||||||
|
|
||||||
int tex_count;
|
int tex_count;
|
||||||
qtexture_t qtextures[MAX_TEXTURES];
|
qtexture_t qtextures[MAX_TEXTURES];
|
||||||
|
|
||||||
|
@ -74,11 +73,16 @@ TEX_InitPalette
|
||||||
==============
|
==============
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
TEX_InitPalette (byte * pal)
|
TEX_InitPalette (wad_t *wad, lumpinfo_t *pallump)
|
||||||
{
|
{
|
||||||
|
byte *pal, *opal;
|
||||||
int r, g, b, v;
|
int r, g, b, v;
|
||||||
int i;
|
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++) {
|
for (i = 0; i < 256; i++) {
|
||||||
r = pal[0];
|
r = pal[0];
|
||||||
g = pal[1];
|
g = pal[1];
|
||||||
|
@ -90,6 +94,7 @@ TEX_InitPalette (byte * pal)
|
||||||
|
|
||||||
tex_palette[i] = v;
|
tex_palette[i] = v;
|
||||||
}
|
}
|
||||||
|
free (opal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,8 +104,9 @@ TEX_ImageFromMiptex
|
||||||
=================
|
=================
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
TEX_ImageFromMiptex (miptex_t *qtex)
|
TEX_ImageFromMiptex (wad_t *wad, lumpinfo_t *qtexlump)
|
||||||
{
|
{
|
||||||
|
miptex_t *qtex;
|
||||||
NSBitmapImageRep *bm;
|
NSBitmapImageRep *bm;
|
||||||
byte *source;
|
byte *source;
|
||||||
unsigned *dest;
|
unsigned *dest;
|
||||||
|
@ -108,6 +114,10 @@ TEX_ImageFromMiptex (miptex_t *qtex)
|
||||||
qtexture_t *q;
|
qtexture_t *q;
|
||||||
int tr, tg, tb;
|
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);
|
width = LittleLong (qtex->width);
|
||||||
height = LittleLong (qtex->height);
|
height = LittleLong (qtex->height);
|
||||||
|
|
||||||
|
@ -139,27 +149,11 @@ TEX_ImageFromMiptex (miptex_t *qtex)
|
||||||
q->flatcolor.chan[1] = tg / count;
|
q->flatcolor.chan[1] = tg / count;
|
||||||
q->flatcolor.chan[2] = tb / count;
|
q->flatcolor.chan[2] = tb / count;
|
||||||
q->flatcolor.chan[3] = 0xff;
|
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
|
TEX_InitFromWad
|
||||||
|
@ -171,17 +165,14 @@ TEX_InitFromWad (char *path)
|
||||||
int i;
|
int i;
|
||||||
char local[1024];
|
char local[1024];
|
||||||
char newpath[1024];
|
char newpath[1024];
|
||||||
byte *wadfile;
|
|
||||||
wadinfo_t *wadinfo;
|
|
||||||
lumpinfo_t *lumpinfo;
|
|
||||||
int numlumps;
|
|
||||||
float start, stop;
|
float start, stop;
|
||||||
QFile *file;
|
wad_t *wad;
|
||||||
size_t size;
|
lumpinfo_t *lumpinfo;
|
||||||
|
|
||||||
start = Sys_DoubleTime ();
|
start = Sys_DoubleTime ();
|
||||||
|
|
||||||
strcpy (newpath,[preferences_i getProjectPath]);
|
strcpy (newpath,[preferences_i getProjectPath]);
|
||||||
|
if (newpath[0])
|
||||||
strcat (newpath, "/");
|
strcat (newpath, "/");
|
||||||
strcat (newpath, path);
|
strcat (newpath, path);
|
||||||
|
|
||||||
|
@ -191,42 +182,28 @@ TEX_InitFromWad (char *path)
|
||||||
tex_count = 0;
|
tex_count = 0;
|
||||||
|
|
||||||
// try and use the cached wadfile
|
// try and use the cached wadfile
|
||||||
sprintf (local, "/qcache%s", newpath);
|
|
||||||
|
|
||||||
// Sys_UpdateFile (local, newpath);
|
Sys_Printf ("TEX_InitFromWad %s\n", newpath);
|
||||||
// FIXME use wad functions
|
wad = wad_open (newpath);
|
||||||
file = Qopen (local, "rb");
|
|
||||||
size = Qfilesize (file);
|
|
||||||
wadfile = malloc (size);
|
|
||||||
Qread (file, wadfile, size);
|
|
||||||
Qclose (file);
|
|
||||||
wadinfo = (wadinfo_t *) wadfile;
|
|
||||||
|
|
||||||
if (strncmp ((char *) wadfile, "WAD2", 4)) {
|
lumpinfo = wad->lumps;
|
||||||
unlink (local);
|
|
||||||
Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", newpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
numlumps = LittleLong (wadinfo->numlumps);
|
|
||||||
lumpinfo = (lumpinfo_t *) (wadfile + LittleLong (wadinfo->infotableofs));
|
|
||||||
|
|
||||||
if (strcmp (lumpinfo->name, "PALETTE")) {
|
if (strcmp (lumpinfo->name, "PALETTE")) {
|
||||||
unlink (local);
|
unlink (local);
|
||||||
Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0", path);
|
Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEX_InitPalette (wadfile + LittleLong (lumpinfo->filepos));
|
TEX_InitPalette (wad, lumpinfo);
|
||||||
|
|
||||||
lumpinfo++;
|
lumpinfo++;
|
||||||
for (i = 1; i < numlumps; i++, lumpinfo++) {
|
for (i = 1; i < wad->numlumps; i++, lumpinfo++) {
|
||||||
if (lumpinfo->type != TYP_MIPTEX)
|
if (lumpinfo->type != TYP_MIPTEX)
|
||||||
Sys_Error ("TEX_InitFromWad: %s is not a miptex!", lumpinfo->name);
|
Sys_Error ("TEX_InitFromWad: %s is not a miptex!", lumpinfo->name);
|
||||||
// XXX CleanupName (lumpinfo->name,qtextures[tex_count].name);
|
// XXX CleanupName (lumpinfo->name,qtextures[tex_count].name);
|
||||||
TEX_ImageFromMiptex ((miptex_t *) (wadfile +
|
TEX_ImageFromMiptex (wad, lumpinfo);
|
||||||
LittleLong (lumpinfo->filepos)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free (wadfile);
|
wad_close (wad);
|
||||||
|
|
||||||
stop = Sys_DoubleTime ();
|
stop = Sys_DoubleTime ();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue