2002-09-19 18:51:19 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
See file, 'COPYING', for details.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2003-08-11 17:11:44 +00:00
|
|
|
#include <errno.h>
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
#include "QF/dstring.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
2002-09-20 21:48:34 +00:00
|
|
|
#include "QF/va.h"
|
2004-01-09 23:34:32 +00:00
|
|
|
#include "QF/wad.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#include "bsp5.h"
|
2002-09-20 21:48:34 +00:00
|
|
|
#include "options.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int headclipnode;
|
|
|
|
int firstface;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
FindFinalPlane
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Used to find plane index numbers for clip nodes read from child processes
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2002-09-19 17:14:23 +00:00
|
|
|
int
|
|
|
|
FindFinalPlane (dplane_t *p)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
dplane_t *dplane;
|
2002-09-19 18:51:19 +00:00
|
|
|
int i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0, dplane = bsp->planes; i < bsp->numplanes; i++, dplane++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p->type != dplane->type)
|
|
|
|
continue;
|
|
|
|
if (p->dist != dplane->dist)
|
|
|
|
continue;
|
|
|
|
if (p->normal[0] != dplane->normal[0])
|
|
|
|
continue;
|
|
|
|
if (p->normal[1] != dplane->normal[1])
|
|
|
|
continue;
|
|
|
|
if (p->normal[2] != dplane->normal[2])
|
|
|
|
continue;
|
|
|
|
return i;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// new plane
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->numplanes == MAX_MAP_PLANES)
|
|
|
|
Sys_Error ("numplanes == MAX_MAP_PLANES");
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddPlane (bsp, p);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
return bsp->numplanes - 1;
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int planemapping[MAX_MAP_PLANES];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteNodePlanes_r (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dplane_t dplane;
|
2002-09-19 18:51:19 +00:00
|
|
|
plane_t *plane;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
if (node->planenum == -1)
|
|
|
|
return;
|
2002-09-19 17:14:23 +00:00
|
|
|
if (planemapping[node->planenum] == -1) { // a new plane
|
2002-09-19 16:58:48 +00:00
|
|
|
planemapping[node->planenum] = bsp->numplanes;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
plane = &planes[node->planenum];
|
2002-09-19 20:39:33 +00:00
|
|
|
|
|
|
|
dplane.normal[0] = plane->normal[0];
|
|
|
|
dplane.normal[1] = plane->normal[1];
|
|
|
|
dplane.normal[2] = plane->normal[2];
|
|
|
|
dplane.dist = plane->dist;
|
|
|
|
dplane.type = plane->type;
|
|
|
|
BSP_AddPlane (bsp, &dplane);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node->outputplanenum = planemapping[node->planenum];
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
WriteNodePlanes_r (node->children[0]);
|
|
|
|
WriteNodePlanes_r (node->children[1]);
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteNodePlanes (node_t *nodes)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
memset (planemapping, -1, sizeof (planemapping));
|
2002-09-19 16:58:48 +00:00
|
|
|
WriteNodePlanes_r (nodes);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteClipNodes_r (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dclipnode_t cn;
|
2002-09-19 18:51:19 +00:00
|
|
|
int num, c, i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// FIXME: free more stuff?
|
2002-09-19 17:14:23 +00:00
|
|
|
if (node->planenum == -1) {
|
2002-09-19 16:58:48 +00:00
|
|
|
num = node->contents;
|
|
|
|
free (node);
|
|
|
|
return num;
|
|
|
|
}
|
2002-09-23 16:27:17 +00:00
|
|
|
// emit a clipnode
|
2002-09-19 16:58:48 +00:00
|
|
|
c = bsp->numclipnodes;
|
2003-02-05 05:06:14 +00:00
|
|
|
BSP_AddClipnode (bsp, &cn);
|
2002-09-19 20:39:33 +00:00
|
|
|
cn.planenum = node->outputplanenum;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
2002-09-19 20:39:33 +00:00
|
|
|
cn.children[i] = WriteClipNodes_r (node->children[i]);
|
2003-02-05 05:06:14 +00:00
|
|
|
bsp->clipnodes[c] = cn;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
free (node);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
WriteClipNodes
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Called after the clipping hull is completed. Generates a disk format
|
|
|
|
representation and frees the original memory.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteClipNodes (node_t *nodes)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
|
|
|
headclipnode = bsp->numclipnodes;
|
|
|
|
WriteClipNodes_r (nodes);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteLeaf (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dleaf_t leaf_p;
|
2002-09-19 18:51:19 +00:00
|
|
|
face_t **fp, *f;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// emit a leaf
|
2002-09-19 20:39:33 +00:00
|
|
|
leaf_p.contents = node->contents;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// write bounding box info
|
2002-09-19 20:39:33 +00:00
|
|
|
VectorCopy (node->mins, leaf_p.mins);
|
|
|
|
VectorCopy (node->maxs, leaf_p.maxs);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
leaf_p.visofs = -1; // no vis info yet
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// write the marksurfaces
|
2002-09-19 20:39:33 +00:00
|
|
|
leaf_p.firstmarksurface = bsp->nummarksurfaces;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (fp = node->markfaces; *fp; fp++) {
|
|
|
|
// emit a marksurface
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->nummarksurfaces == MAX_MAP_MARKSURFACES)
|
|
|
|
Sys_Error ("nummarksurfaces == MAX_MAP_MARKSURFACES");
|
|
|
|
f = *fp;
|
2003-02-04 23:26:26 +00:00
|
|
|
if (f->texturenum < 0)
|
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
do {
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddMarkSurface (bsp, f->outputnumber);
|
2002-09-19 17:14:23 +00:00
|
|
|
f = f->original; // grab tjunction split faces
|
2002-09-19 16:58:48 +00:00
|
|
|
} while (f);
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
leaf_p.nummarksurfaces = bsp->nummarksurfaces - leaf_p.firstmarksurface;
|
2002-09-20 18:17:36 +00:00
|
|
|
BSP_AddLeaf (bsp, &leaf_p);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteDrawNodes_r (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
static dnode_t dummy;
|
2002-09-19 17:14:23 +00:00
|
|
|
dnode_t *n;
|
|
|
|
int i;
|
2002-09-19 20:39:33 +00:00
|
|
|
int nodenum = bsp->numnodes;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// emit a node
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->numnodes == MAX_MAP_NODES)
|
|
|
|
Sys_Error ("numnodes == MAX_MAP_NODES");
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddNode (bsp, &dummy);
|
|
|
|
n = &bsp->nodes[nodenum];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
VectorCopy (node->mins, n->mins);
|
|
|
|
VectorCopy (node->maxs, n->maxs);
|
|
|
|
|
|
|
|
n->planenum = node->outputplanenum;
|
|
|
|
n->firstface = node->firstface;
|
|
|
|
n->numfaces = node->numfaces;
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// recursively output the other nodes
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2002-09-19 20:39:33 +00:00
|
|
|
n = &bsp->nodes[nodenum];
|
2002-09-19 17:14:23 +00:00
|
|
|
if (node->children[i]->planenum == -1) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (node->children[i]->contents == CONTENTS_SOLID)
|
|
|
|
n->children[i] = -1;
|
2002-09-19 17:14:23 +00:00
|
|
|
else {
|
2002-09-19 16:58:48 +00:00
|
|
|
n->children[i] = -(bsp->numleafs + 1);
|
|
|
|
WriteLeaf (node->children[i]);
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
|
|
|
n->children[i] = bsp->numnodes;
|
2002-09-19 16:58:48 +00:00
|
|
|
WriteDrawNodes_r (node->children[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
WriteDrawNodes (node_t *headnode)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dmodel_t bm;
|
2002-09-19 18:51:19 +00:00
|
|
|
int start, i;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (headnode->contents < 0)
|
|
|
|
Sys_Error ("FinishBSPModel: empty model");
|
|
|
|
#endif
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// emit a model
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->nummodels == MAX_MAP_MODELS)
|
|
|
|
Sys_Error ("nummodels == MAX_MAP_MODELS");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
bm.headnode[0] = bsp->numnodes;
|
|
|
|
bm.firstface = firstface;
|
|
|
|
bm.numfaces = bsp->numfaces - firstface;
|
2002-09-19 16:58:48 +00:00
|
|
|
firstface = bsp->numfaces;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
start = bsp->numleafs;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (headnode->contents < 0)
|
2002-09-19 16:58:48 +00:00
|
|
|
WriteLeaf (headnode);
|
|
|
|
else
|
|
|
|
WriteDrawNodes_r (headnode);
|
2002-09-19 20:39:33 +00:00
|
|
|
bm.visleafs = bsp->numleafs - start;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2002-09-19 20:39:33 +00:00
|
|
|
bm.mins[i] = headnode->mins[i] + SIDESPACE + 1; // remove the padding
|
|
|
|
bm.maxs[i] = headnode->maxs[i] - SIDESPACE - 1;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddModel (bsp, &bm);
|
2002-09-23 16:27:17 +00:00
|
|
|
// FIXME: are all the children decendant of padded nodes?
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
BumpModel
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Used by the clipping hull processes that only need to store headclipnode
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
|
|
|
BumpModel (int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
static dmodel_t bm;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// emit a model
|
2002-09-19 20:39:33 +00:00
|
|
|
bm.headnode[hullnum] = headclipnode;
|
|
|
|
BSP_AddModel (bsp, &bm);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 20:58:29 +00:00
|
|
|
typedef struct wadlist_s {
|
|
|
|
struct wadlist_s *next;
|
2003-09-05 03:47:19 +00:00
|
|
|
const char *path;
|
2002-09-19 20:58:29 +00:00
|
|
|
wadinfo_t wadinfo;
|
|
|
|
lumpinfo_t *lumpinfo;
|
|
|
|
} wadlist_t;
|
|
|
|
|
|
|
|
wadlist_t *wadlist;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
CleanupName (char *in, char *out)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!in[i])
|
|
|
|
break;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
out[i] = toupper (in[i]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (; i < 16; i++)
|
2002-09-19 16:58:48 +00:00
|
|
|
out[i] = 0;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2002-09-19 17:14:23 +00:00
|
|
|
TEX_InitFromWad (char *path)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
2002-09-19 20:58:29 +00:00
|
|
|
wadlist_t *wl;
|
2003-09-05 03:47:19 +00:00
|
|
|
QFile *texfile;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
texfile = Qopen (path, "rbz");
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
if (!texfile)
|
2003-09-05 03:47:19 +00:00
|
|
|
texfile = Qopen (path = va ("%s.gz", path), "rbz");
|
2002-09-20 21:48:34 +00:00
|
|
|
#endif
|
2002-09-19 20:39:33 +00:00
|
|
|
if (!texfile)
|
2002-09-20 21:48:34 +00:00
|
|
|
return -1;
|
|
|
|
printf ("wadfile: %s\n", path);
|
2002-09-19 20:58:29 +00:00
|
|
|
|
|
|
|
wl = calloc (1, sizeof (wadlist_t));
|
2003-09-05 03:47:19 +00:00
|
|
|
wl->path = strdup (path);
|
2002-09-19 20:58:29 +00:00
|
|
|
|
|
|
|
Qread (texfile, &wl->wadinfo, sizeof (wadinfo_t));
|
2004-01-09 23:34:32 +00:00
|
|
|
if (strncmp (wl->wadinfo.id, "WAD2", 4))
|
2002-09-19 17:14:23 +00:00
|
|
|
Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", path);
|
2002-09-19 20:58:29 +00:00
|
|
|
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));
|
2003-09-05 03:47:19 +00:00
|
|
|
Qclose (texfile);
|
2002-09-19 20:58:29 +00:00
|
|
|
|
|
|
|
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);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 20:58:29 +00:00
|
|
|
wl->next = wadlist;
|
|
|
|
wadlist = wl;
|
2002-09-20 21:48:34 +00:00
|
|
|
return 0;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2002-09-19 20:39:33 +00:00
|
|
|
LoadLump (char *name, dstring_t *dest)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2003-07-08 20:11:10 +00:00
|
|
|
char cname[16]; //FIXME: overflow
|
2003-09-05 03:47:19 +00:00
|
|
|
int i, r;
|
2002-09-19 20:39:33 +00:00
|
|
|
int ofs = dest->size;
|
2002-09-19 20:58:29 +00:00
|
|
|
wadlist_t *wl;
|
2003-09-05 03:47:19 +00:00
|
|
|
QFile *texfile;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
CleanupName (name, cname);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:58:29 +00:00
|
|
|
for (wl = wadlist; wl; wl = wl->next) {
|
|
|
|
for (i = 0; i < wl->wadinfo.numlumps; i++) {
|
|
|
|
if (!strcmp (cname, wl->lumpinfo[i].name)) {
|
|
|
|
dest->size += wl->lumpinfo[i].disksize;
|
|
|
|
dstring_adjust (dest);
|
2003-09-05 03:47:19 +00:00
|
|
|
texfile = Qopen (wl->path, "rbz");
|
|
|
|
if (!texfile) {
|
|
|
|
printf ("couldn't open %s\n", wl->path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r = Qseek (texfile, wl->lumpinfo[i].filepos, SEEK_SET);
|
|
|
|
if (r == -1) {
|
|
|
|
printf ("seek error: %s:%s %d\n", wl->path,
|
|
|
|
wl->lumpinfo[i].name, wl->lumpinfo[i].filepos);
|
|
|
|
Qclose (texfile);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r = Qread (texfile, dest->str + ofs, wl->lumpinfo[i].disksize);
|
|
|
|
Qclose (texfile);
|
|
|
|
if (r != wl->lumpinfo[i].disksize) {
|
|
|
|
printf ("seek error: %s:%s %d\n", wl->path,
|
|
|
|
wl->lumpinfo[i].name, wl->lumpinfo[i].disksize);
|
|
|
|
continue;
|
|
|
|
}
|
2002-09-19 20:58:29 +00:00
|
|
|
return wl->lumpinfo[i].disksize;
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("WARNING: texture %s not found\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
AddAnimatingTextures (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int base, i, j, k;
|
2003-07-08 20:11:10 +00:00
|
|
|
char name[32]; //FIXME: overflow
|
2002-09-19 20:58:29 +00:00
|
|
|
wadlist_t *wl;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
base = nummiptex;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < base; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (miptex[i][0] != '+')
|
|
|
|
continue;
|
|
|
|
strcpy (name, miptex[i]);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (j = 0; j < 20; j++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (j < 10)
|
2002-09-19 17:14:23 +00:00
|
|
|
name[1] = '0' + j;
|
2002-09-19 16:58:48 +00:00
|
|
|
else
|
2002-09-19 17:14:23 +00:00
|
|
|
name[1] = 'A' + j - 10; // alternate animation
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
// see if this name exists in the wadfile
|
2002-09-19 20:58:29 +00:00
|
|
|
for (wl = wadlist; wl; wl = wl->next) {
|
|
|
|
for (k = 0; k < wl->wadinfo.numlumps; k++) {
|
|
|
|
if (!strcmp (name, wl->lumpinfo[k].name)) {
|
|
|
|
FindMiptex (name); // add to the miptex list
|
|
|
|
break;
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 20:58:29 +00:00
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:32:40 +00:00
|
|
|
if (nummiptex - base)
|
|
|
|
printf ("added %i texture frames\n", nummiptex - base);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
WriteMiptex (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dstring_t *data;
|
2002-09-20 21:48:34 +00:00
|
|
|
char *wad_list, *wad, *w;
|
|
|
|
char *path_list, *path, *p;
|
|
|
|
dstring_t *fullpath;
|
2002-09-19 18:51:19 +00:00
|
|
|
dmiptexlump_t *l;
|
2002-09-20 21:48:34 +00:00
|
|
|
int i, len, res = -1;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
(const char *)wad_list = ValueForKey (&entities[0], "_wad");
|
2002-09-20 21:48:34 +00:00
|
|
|
if (!wad_list || !wad_list[0]) {
|
2003-01-06 18:28:13 +00:00
|
|
|
(const char *)wad_list = ValueForKey (&entities[0], "wad");
|
2002-09-20 21:48:34 +00:00
|
|
|
if (!wad_list || !wad_list[0]) {
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("WARNING: no wadfile specified\n");
|
|
|
|
bsp->texdatasize = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-09-20 21:48:34 +00:00
|
|
|
fullpath = dstring_new ();
|
|
|
|
wad = wad_list = strdup (wad_list);
|
|
|
|
w = strchr (wad, ';');
|
|
|
|
if (w)
|
|
|
|
*w++ = 0;
|
|
|
|
while (1) {
|
|
|
|
path = path_list = strdup (options.wadpath);
|
|
|
|
p = strchr (path, ';');
|
|
|
|
if (p)
|
|
|
|
*p++ = 0;
|
|
|
|
while (1) {
|
|
|
|
dsprintf (fullpath, "%s%s%s", path, path[0] ? "/" : "", wad);
|
|
|
|
res = TEX_InitFromWad (fullpath->str);
|
|
|
|
if (!res)
|
|
|
|
break;
|
|
|
|
path = p;
|
|
|
|
if (!path || !*path)
|
|
|
|
break;
|
|
|
|
p = strchr (path, ';');
|
|
|
|
if (p)
|
|
|
|
*p++ = 0;
|
|
|
|
}
|
|
|
|
free (path_list);
|
|
|
|
if (res == -1)
|
|
|
|
Sys_Error ("couldn't open %s[.gz]", wad);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
AddAnimatingTextures ();
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
wad = w;
|
|
|
|
if (!wad || !*wad)
|
|
|
|
break;
|
|
|
|
w = strchr (wad, ';');
|
|
|
|
if (w)
|
|
|
|
*w++ = 0;
|
2002-09-19 20:39:33 +00:00
|
|
|
}
|
2002-09-20 21:48:34 +00:00
|
|
|
free (wad_list);
|
|
|
|
dstring_delete (fullpath);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
data = dstring_new ();
|
|
|
|
data->size = sizeof (dmiptexlump_t);
|
|
|
|
dstring_adjust (data);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
l = (dmiptexlump_t *) data->str;
|
2002-09-19 16:58:48 +00:00
|
|
|
l->nummiptex = nummiptex;
|
2002-09-19 20:39:33 +00:00
|
|
|
data->size = (char *) &l->dataofs[nummiptex] - data->str;
|
|
|
|
dstring_adjust (data);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < nummiptex; i++) {
|
2002-09-20 18:17:36 +00:00
|
|
|
l = (dmiptexlump_t *) data->str;
|
2002-09-19 20:39:33 +00:00
|
|
|
l->dataofs[i] = data->size;
|
2002-09-19 16:58:48 +00:00
|
|
|
len = LoadLump (miptex[i], data);
|
2002-09-20 18:17:36 +00:00
|
|
|
l = (dmiptexlump_t *) data->str;
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!len)
|
2002-09-19 17:14:23 +00:00
|
|
|
l->dataofs[i] = -1; // didn't find the texture
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddTextures (bsp, data->str, data->size);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
|
|
|
BeginBSPFile (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
static dedge_t edge;
|
|
|
|
static dleaf_t leaf;
|
2002-09-23 16:27:17 +00:00
|
|
|
// edge 0 is not used, because 0 can't be negated
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddEdge (bsp, &edge);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// leaf 0 is common solid with no faces
|
2002-09-19 20:39:33 +00:00
|
|
|
leaf.contents = CONTENTS_SOLID;
|
|
|
|
BSP_AddLeaf (bsp, &leaf);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
firstface = 0;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
|
|
|
FinishBSPFile (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
|
|
|
QFile *f;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("--- FinishBSPFile ---\n");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
WriteMiptex ();
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// XXX PrintBSPFileSizes ();
|
2003-09-03 22:00:08 +00:00
|
|
|
printf ("WriteBSPFile: %s\n", options.bspfile);
|
2002-09-20 21:48:34 +00:00
|
|
|
f = Qopen (options.bspfile, "wb");
|
2003-08-11 17:11:44 +00:00
|
|
|
if (!f)
|
|
|
|
Sys_Error ("couldn't open %s. %s", options.bspfile, strerror(errno));
|
2002-09-19 16:58:48 +00:00
|
|
|
WriteBSPFile (bsp, f);
|
|
|
|
Qclose (f);
|
|
|
|
}
|