mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
qfbsp now mostly works. only known issue is multiple texture wads don't
load properly and possibly a "reached occupant" issue (dunno if it's the map or qfbsp)
This commit is contained in:
parent
54fa6ebae2
commit
0cd34d155f
9 changed files with 256 additions and 130 deletions
|
@ -71,7 +71,7 @@
|
|||
#define BSPVERSION 29
|
||||
#define TOOLVERSION 2
|
||||
|
||||
typedef struct {
|
||||
typedef struct lump_s {
|
||||
int fileofs;
|
||||
int filelen;
|
||||
} lump_t;
|
||||
|
@ -94,7 +94,7 @@ typedef struct {
|
|||
|
||||
#define HEADER_LUMPS 15
|
||||
|
||||
typedef struct {
|
||||
typedef struct dmodel_s {
|
||||
float mins[3], maxs[3];
|
||||
float origin[3];
|
||||
int headnode[MAX_MAP_HULLS];
|
||||
|
@ -102,12 +102,12 @@ typedef struct {
|
|||
int firstface, numfaces;
|
||||
} dmodel_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct dheader_s {
|
||||
int version;
|
||||
lump_t lumps[HEADER_LUMPS];
|
||||
} dheader_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct dmiptexlump_s {
|
||||
int nummiptex;
|
||||
int dataofs[4]; // [nummiptex]
|
||||
} dmiptexlump_t;
|
||||
|
@ -120,7 +120,7 @@ typedef struct miptex_s {
|
|||
} miptex_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
typedef struct dvertex_s {
|
||||
float point[3];
|
||||
} dvertex_t;
|
||||
|
||||
|
@ -135,7 +135,7 @@ typedef struct {
|
|||
#define PLANE_ANYY 4
|
||||
#define PLANE_ANYZ 5
|
||||
|
||||
typedef struct {
|
||||
typedef struct dplane_s {
|
||||
float normal[3];
|
||||
float dist;
|
||||
int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
|
||||
|
@ -159,7 +159,7 @@ typedef struct {
|
|||
|
||||
|
||||
// !!! if this is changed, it must be changed in asm_i386.h too !!!
|
||||
typedef struct {
|
||||
typedef struct dnode_s {
|
||||
int planenum;
|
||||
short children[2]; // negative numbers are -(leafs+1), not nodes
|
||||
short mins[3]; // for sphere culling
|
||||
|
@ -168,7 +168,7 @@ typedef struct {
|
|||
unsigned short numfaces; // counting both sides
|
||||
} dnode_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct dclipnode_s {
|
||||
int planenum;
|
||||
short children[2]; // negative numbers are contents
|
||||
} dclipnode_t;
|
||||
|
@ -183,12 +183,12 @@ typedef struct texinfo_s {
|
|||
|
||||
// note that edge 0 is never used, because negative edge nums are used for
|
||||
// counterclockwise use of the edge in a face
|
||||
typedef struct {
|
||||
typedef struct dedge_s {
|
||||
unsigned short v[2]; // vertex numbers
|
||||
} dedge_t;
|
||||
|
||||
#define MAXLIGHTMAPS 4
|
||||
typedef struct {
|
||||
typedef struct dface_s {
|
||||
short planenum;
|
||||
short side;
|
||||
|
||||
|
@ -212,7 +212,7 @@ typedef struct {
|
|||
|
||||
// leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
|
||||
// all other leafs need visibility info
|
||||
typedef struct {
|
||||
typedef struct dleaf_s {
|
||||
int contents;
|
||||
int visofs; // -1 = no visibility info
|
||||
|
||||
|
@ -281,6 +281,22 @@ typedef struct bsp_s {
|
|||
|
||||
bsp_t *LoadBSPFile (QFile *file, int size);
|
||||
void WriteBSPFile (bsp_t *bsp, QFile *file);
|
||||
bsp_t *BSP_New (void);
|
||||
void BSP_AddPlane (bsp_t *bsp, dplane_t *plane);
|
||||
void BSP_AddLeaf (bsp_t *bsp, dleaf_t *leaf);
|
||||
void BSP_AddVertex (bsp_t *bsp, dvertex_t *vertex);
|
||||
void BSP_AddNode (bsp_t *bsp, dnode_t *node);
|
||||
void BSP_AddTexinfo (bsp_t *bsp, texinfo_t *texinfo);
|
||||
void BSP_AddFace (bsp_t *bsp, dface_t *face);
|
||||
void BSP_AddClipnode (bsp_t *bsp, dclipnode_t *clipnode);
|
||||
void BSP_AddMarkSurface (bsp_t *bsp, unsigned short marksurface);
|
||||
void BSP_AddSurfEdge (bsp_t *bsp, int surfedge);
|
||||
void BSP_AddEdge (bsp_t *bsp, dedge_t *edge);
|
||||
void BSP_AddModel (bsp_t *bsp, dmodel_t *model);
|
||||
void BSP_AddLighting (bsp_t *bsp, byte *lightdata, int lightdatasize);
|
||||
void BSP_AddVisibility (bsp_t *bsp, byte *visdata, int visdatasize);
|
||||
void BSP_AddEntities (bsp_t *bsp, char *entdata, int entdatasize);
|
||||
void BSP_AddTextures (bsp_t *bsp, byte *texdata, int texdatasize);
|
||||
|
||||
#endif
|
||||
#endif // __bspfile_h_
|
||||
|
|
|
@ -302,3 +302,116 @@ do { \
|
|||
Qwrite (file, header, size);
|
||||
free (header);
|
||||
}
|
||||
|
||||
bsp_t *
|
||||
BSP_New (void)
|
||||
{
|
||||
return calloc (1, sizeof (bsp_t));
|
||||
}
|
||||
|
||||
void BSP_AddPlane (bsp_t *bsp, dplane_t *plane)
|
||||
{
|
||||
bsp->planes = realloc (bsp->planes,
|
||||
(bsp->numplanes + 1) * sizeof (dplane_t));
|
||||
bsp->planes[bsp->numplanes++] = *plane;
|
||||
}
|
||||
|
||||
void BSP_AddLeaf (bsp_t *bsp, dleaf_t *leaf)
|
||||
{
|
||||
bsp->leafs = realloc (bsp->leafs,
|
||||
(bsp->numleafs + 1) * sizeof (dleaf_t));
|
||||
bsp->leafs[bsp->numleafs++] = *leaf;
|
||||
}
|
||||
|
||||
void BSP_AddVertex (bsp_t *bsp, dvertex_t *vertex)
|
||||
{
|
||||
bsp->vertexes = realloc (bsp->vertexes,
|
||||
(bsp->numvertexes + 1) * sizeof (dvertex_t));
|
||||
bsp->vertexes[bsp->numvertexes++] = *vertex;
|
||||
}
|
||||
|
||||
void BSP_AddNode (bsp_t *bsp, dnode_t *node)
|
||||
{
|
||||
bsp->nodes = realloc (bsp->nodes,
|
||||
(bsp->numnodes + 1) * sizeof (dnode_t));
|
||||
bsp->nodes[bsp->numnodes++] = *node;
|
||||
}
|
||||
|
||||
void
|
||||
BSP_AddTexinfo (bsp_t *bsp, texinfo_t *texinfo)
|
||||
{
|
||||
bsp->texinfo = realloc (bsp->texinfo,
|
||||
(bsp->numtexinfo + 1) * sizeof (texinfo_t));
|
||||
bsp->texinfo[bsp->numtexinfo++] = *texinfo;
|
||||
}
|
||||
|
||||
void BSP_AddFace (bsp_t *bsp, dface_t *face)
|
||||
{
|
||||
bsp->faces = realloc (bsp->faces,
|
||||
(bsp->numfaces + 1) * sizeof (dface_t));
|
||||
bsp->faces[bsp->numfaces++] = *face;
|
||||
}
|
||||
|
||||
void BSP_AddClipnode (bsp_t *bsp, dclipnode_t *clipnode)
|
||||
{
|
||||
bsp->clipnodes = realloc (bsp->clipnodes,
|
||||
(bsp->numclipnodes + 1) * sizeof (dclipnode_t));
|
||||
bsp->clipnodes[bsp->numclipnodes++] = *clipnode;
|
||||
}
|
||||
|
||||
void BSP_AddMarkSurface (bsp_t *bsp, unsigned short marksurface)
|
||||
{
|
||||
bsp->marksurfaces = realloc (bsp->marksurfaces,
|
||||
(bsp->nummarksurfaces + 1)
|
||||
* sizeof (unsigned short));
|
||||
bsp->marksurfaces[bsp->nummarksurfaces++] = marksurface;
|
||||
}
|
||||
|
||||
void BSP_AddSurfEdge (bsp_t *bsp, int surfedge)
|
||||
{
|
||||
bsp->surfedges = realloc (bsp->surfedges,
|
||||
(bsp->numsurfedges + 1) * sizeof (int));
|
||||
bsp->surfedges[bsp->numsurfedges++] = surfedge;
|
||||
}
|
||||
|
||||
void BSP_AddEdge (bsp_t *bsp, dedge_t *edge)
|
||||
{
|
||||
bsp->edges = realloc (bsp->edges,
|
||||
(bsp->numedges + 1) * sizeof (dedge_t));
|
||||
bsp->edges[bsp->numedges++] = *edge;
|
||||
}
|
||||
|
||||
void BSP_AddModel (bsp_t *bsp, dmodel_t *model)
|
||||
{
|
||||
bsp->models = realloc (bsp->models,
|
||||
(bsp->nummodels + 1) * sizeof (dmodel_t));
|
||||
bsp->models[bsp->nummodels++] = *model;
|
||||
}
|
||||
|
||||
void BSP_AddLighting (bsp_t *bsp, byte *lightdata, int lightdatasize)
|
||||
{
|
||||
bsp->lightdatasize = lightdatasize;
|
||||
bsp->lightdata = malloc (lightdatasize);
|
||||
memcpy (bsp->lightdata, lightdata, lightdatasize);
|
||||
}
|
||||
|
||||
void BSP_AddVisibility (bsp_t *bsp, byte *visdata, int visdatasize)
|
||||
{
|
||||
bsp->visdatasize = visdatasize;
|
||||
bsp->visdata = malloc (visdatasize);
|
||||
memcpy (bsp->visdata, visdata, visdatasize);
|
||||
}
|
||||
|
||||
void BSP_AddEntities (bsp_t *bsp, char *entdata, int entdatasize)
|
||||
{
|
||||
bsp->entdatasize = entdatasize;
|
||||
bsp->entdata = malloc (entdatasize);
|
||||
memcpy (bsp->entdata, entdata, entdatasize);
|
||||
}
|
||||
|
||||
void BSP_AddTextures (bsp_t *bsp, byte *texdata, int texdatasize)
|
||||
{
|
||||
bsp->texdatasize = texdatasize;
|
||||
bsp->texdata = malloc (texdatasize);
|
||||
memcpy (bsp->texdata, texdata, texdatasize);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
See file, 'COPYING', for details.
|
||||
*/
|
||||
|
||||
#define MAX_FACES 16
|
||||
#define MAX_FACES 128
|
||||
typedef struct mface_s
|
||||
{
|
||||
struct mface_s *next;
|
||||
|
|
|
@ -429,8 +429,8 @@ vec3_t hull_size[3][2] = {
|
|||
|
||||
};
|
||||
|
||||
#define MAX_HULL_POINTS 32
|
||||
#define MAX_HULL_EDGES 64
|
||||
#define MAX_HULL_POINTS 64
|
||||
#define MAX_HULL_EDGES 128
|
||||
|
||||
int num_hull_points;
|
||||
vec3_t hull_points[MAX_HULL_POINTS];
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
|
@ -97,10 +98,7 @@ FindTexinfo (texinfo_t *t)
|
|||
}
|
||||
|
||||
// allocate a new texture
|
||||
if (bsp->numtexinfo == MAX_MAP_TEXINFO)
|
||||
Sys_Error ("numtexinfo == MAX_MAP_TEXINFO");
|
||||
bsp->texinfo[i] = *t;
|
||||
bsp->numtexinfo++;
|
||||
BSP_AddTexinfo (bsp, t);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -438,8 +436,13 @@ void
|
|||
LoadMapFile (char *filename)
|
||||
{
|
||||
char *buf;
|
||||
QFile *file;
|
||||
|
||||
buf = COM_LoadFile (filename, 0);
|
||||
file = Qopen (filename, "rt");
|
||||
buf = malloc (Qfilesize (file) + 1);
|
||||
buf[Qfilesize (file)] = 0;
|
||||
Qread (file, buf, Qfilesize (file));
|
||||
Qclose (file);
|
||||
|
||||
StartTokenParsing (buf);
|
||||
|
||||
|
@ -524,33 +527,25 @@ GetVectorForKey (entity_t *ent, char *key, vec3_t vec)
|
|||
void
|
||||
WriteEntitiesToString (void)
|
||||
{
|
||||
char *buf, *end;
|
||||
dstring_t *buf;
|
||||
char line[128];
|
||||
epair_t *ep;
|
||||
int i;
|
||||
|
||||
buf = bsp->entdata;
|
||||
end = buf;
|
||||
*end = 0;
|
||||
buf = dstring_newstr ();
|
||||
|
||||
for (i = 0; i < num_entities; i++) {
|
||||
ep = entities[i].epairs;
|
||||
if (!ep)
|
||||
continue; // ent got removed
|
||||
|
||||
strcat (end, "{\n");
|
||||
end += 2;
|
||||
dstring_appendstr (buf, "{\n");
|
||||
|
||||
for (ep = entities[i].epairs; ep; ep = ep->next) {
|
||||
sprintf (line, "\"%s\" \"%s\"\n", ep->key, ep->value);
|
||||
strcat (end, line);
|
||||
end += strlen (line);
|
||||
dstring_appendstr (buf, line);
|
||||
}
|
||||
strcat (end, "}\n");
|
||||
end += 2;
|
||||
|
||||
if (end > buf + MAX_MAP_ENTSTRING)
|
||||
Sys_Error ("Entity text too long");
|
||||
dstring_appendstr (buf, "}\n");
|
||||
}
|
||||
bsp->entdatasize = end - buf + 1;
|
||||
BSP_AddEntities (bsp, buf->str, buf->size);
|
||||
}
|
||||
|
|
|
@ -682,7 +682,7 @@ void
|
|||
ReadClipHull (int hullnum)
|
||||
{
|
||||
FILE *f;
|
||||
dclipnode_t *d;
|
||||
dclipnode_t d;
|
||||
dplane_t p;
|
||||
float f1, f2, f3, f4;
|
||||
int firstclipnode, junk, c1, c2, i, j, n;
|
||||
|
@ -713,8 +713,6 @@ ReadClipHull (int hullnum)
|
|||
for (i = 0; i < n; i++) {
|
||||
if (bsp->numclipnodes == MAX_MAP_CLIPNODES)
|
||||
Sys_Error ("ReadClipHull: MAX_MAP_CLIPNODES");
|
||||
d = &bsp->clipnodes[bsp->numclipnodes];
|
||||
bsp->numclipnodes++;
|
||||
if (fscanf (f, "%i : %f %f %f %f : %i %i\n", &junk, &f1, &f2, &f3, &f4,
|
||||
&c1, &c2) != 7)
|
||||
Sys_Error ("Error parsing %s", hullfilename);
|
||||
|
@ -729,9 +727,10 @@ ReadClipHull (int hullnum)
|
|||
norm[2] = f3; // vec_t precision
|
||||
p.type = PlaneTypeForNormal (norm);
|
||||
|
||||
d->children[0] = c1 >= 0 ? c1 + firstclipnode : c1;
|
||||
d->children[1] = c2 >= 0 ? c2 + firstclipnode : c2;
|
||||
d->planenum = FindFinalPlane (&p);
|
||||
d.children[0] = c1 >= 0 ? c1 + firstclipnode : c1;
|
||||
d.children[1] = c2 >= 0 ? c2 + firstclipnode : c2;
|
||||
d.planenum = FindFinalPlane (&p);
|
||||
BSP_AddClipnode (bsp, &d);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -849,6 +848,7 @@ ProcessFile (char *sourcebase, char *bspfilename1)
|
|||
remove (portfilename);
|
||||
remove (pointfilename);
|
||||
}
|
||||
bsp = BSP_New ();
|
||||
// load brushes and entities
|
||||
LoadMapFile (sourcebase);
|
||||
if (onlyents) {
|
||||
|
|
|
@ -157,8 +157,7 @@ RecursiveGrowRegion (dface_t *r, face_t *f)
|
|||
// emit a surfedge
|
||||
if (bsp->numsurfedges == MAX_MAP_SURFEDGES)
|
||||
Sys_Error ("numsurfedges == MAX_MAP_SURFEDGES");
|
||||
bsp->surfedges[bsp->numsurfedges] = e;
|
||||
bsp->numsurfedges++;
|
||||
BSP_AddSurfEdge (bsp, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,7 +389,7 @@ CountRealNumbers (void)
|
|||
void
|
||||
GrowNodeRegion_r (node_t * node)
|
||||
{
|
||||
dface_t *r;
|
||||
dface_t r;
|
||||
face_t *f;
|
||||
int i;
|
||||
|
||||
|
@ -407,14 +406,13 @@ GrowNodeRegion_r (node_t * node)
|
|||
if (bsp->numfaces == MAX_MAP_FACES)
|
||||
Sys_Error ("MAX_MAP_FACES");
|
||||
f->outputnumber = bsp->numfaces;
|
||||
r = &bsp->faces[bsp->numfaces];
|
||||
|
||||
r->planenum = node->outputplanenum;
|
||||
r->side = f->planeside;
|
||||
r->texinfo = f->texturenum;
|
||||
r.planenum = node->outputplanenum;
|
||||
r.side = f->planeside;
|
||||
r.texinfo = f->texturenum;
|
||||
for (i = 0; i < MAXLIGHTMAPS; i++)
|
||||
r->styles[i] = 255;
|
||||
r->lightofs = -1;
|
||||
r.styles[i] = 255;
|
||||
r.lightofs = -1;
|
||||
|
||||
// add the face and mergable neighbors to it
|
||||
#if 0
|
||||
|
@ -422,17 +420,16 @@ GrowNodeRegion_r (node_t * node)
|
|||
AddFaceToRegionSize (f);
|
||||
RecursiveGrowRegion (r, f);
|
||||
#endif
|
||||
r->firstedge = firstedge = bsp->numsurfedges;
|
||||
r.firstedge = firstedge = bsp->numsurfedges;
|
||||
for (i = 0; i < f->numpoints; i++) {
|
||||
if (bsp->numsurfedges == MAX_MAP_SURFEDGES)
|
||||
Sys_Error ("numsurfedges == MAX_MAP_SURFEDGES");
|
||||
bsp->surfedges[bsp->numsurfedges] = f->edges[i];
|
||||
bsp->numsurfedges++;
|
||||
BSP_AddSurfEdge (bsp, f->edges[i]);
|
||||
}
|
||||
|
||||
r->numedges = bsp->numsurfedges - r->firstedge;
|
||||
r.numedges = bsp->numsurfedges - r.firstedge;
|
||||
|
||||
bsp->numfaces++;
|
||||
BSP_AddFace (bsp, &r);
|
||||
}
|
||||
|
||||
node->numfaces = bsp->numfaces - node->firstface;
|
||||
|
|
|
@ -248,6 +248,7 @@ GetVertex (vec3_t in, int planenum)
|
|||
hashvert_t *hv;
|
||||
int h, i;
|
||||
vec3_t vert;
|
||||
dvertex_t v;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (fabs (in[i] - (int) (in[i] + 0.5)) < 0.001)
|
||||
|
@ -293,10 +294,11 @@ GetVertex (vec3_t in, int planenum)
|
|||
if (bsp->numvertexes == MAX_MAP_VERTS)
|
||||
Sys_Error ("numvertexes == MAX_MAP_VERTS");
|
||||
|
||||
bsp->vertexes[bsp->numvertexes].point[0] = vert[0];
|
||||
bsp->vertexes[bsp->numvertexes].point[1] = vert[1];
|
||||
bsp->vertexes[bsp->numvertexes].point[2] = vert[2];
|
||||
bsp->numvertexes++;
|
||||
v.point[0] = vert[0];
|
||||
v.point[1] = vert[1];
|
||||
v.point[2] = vert[2];
|
||||
|
||||
BSP_AddVertex (bsp, &v);
|
||||
|
||||
return hv->num;
|
||||
}
|
||||
|
@ -315,7 +317,7 @@ Don't allow four way edges
|
|||
int
|
||||
GetEdge (vec3_t p1, vec3_t p2, face_t *f)
|
||||
{
|
||||
dedge_t *edge;
|
||||
dedge_t edge;
|
||||
int v1, v2, i;
|
||||
|
||||
if (!f->contents[0])
|
||||
|
@ -325,8 +327,7 @@ GetEdge (vec3_t p1, vec3_t p2, face_t *f)
|
|||
v1 = GetVertex (p1, f->planenum);
|
||||
v2 = GetVertex (p2, f->planenum);
|
||||
for (i = firstmodeledge; i < bsp->numedges; i++) {
|
||||
edge = &bsp->edges[i];
|
||||
if (v1 == edge->v[1] && v2 == edge->v[0]
|
||||
if (v1 == bsp->edges[i].v[1] && v2 == bsp->edges[i].v[0]
|
||||
&& !edgefaces[i][1]
|
||||
&& edgefaces[i][0]->contents[0] == f->contents[0]) {
|
||||
edgefaces[i][1] = f;
|
||||
|
@ -337,10 +338,9 @@ GetEdge (vec3_t p1, vec3_t p2, face_t *f)
|
|||
// emit an edge
|
||||
if (bsp->numedges == MAX_MAP_EDGES)
|
||||
Sys_Error ("numedges == MAX_MAP_EDGES");
|
||||
edge = &bsp->edges[bsp->numedges];
|
||||
bsp->numedges++;
|
||||
edge->v[0] = v1;
|
||||
edge->v[1] = v2;
|
||||
edge.v[0] = v1;
|
||||
edge.v[1] = v2;
|
||||
BSP_AddEdge (bsp, &edge);
|
||||
edgefaces[i][0] = f;
|
||||
|
||||
return i;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/qendian.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
|
@ -69,9 +70,7 @@ FindFinalPlane (dplane_t *p)
|
|||
// new plane
|
||||
if (bsp->numplanes == MAX_MAP_PLANES)
|
||||
Sys_Error ("numplanes == MAX_MAP_PLANES");
|
||||
dplane = &bsp->planes[bsp->numplanes];
|
||||
*dplane = *p;
|
||||
bsp->numplanes++;
|
||||
BSP_AddPlane (bsp, p);
|
||||
|
||||
return bsp->numplanes - 1;
|
||||
}
|
||||
|
@ -81,7 +80,7 @@ int planemapping[MAX_MAP_PLANES];
|
|||
void
|
||||
WriteNodePlanes_r (node_t *node)
|
||||
{
|
||||
dplane_t *dplane;
|
||||
dplane_t dplane;
|
||||
plane_t *plane;
|
||||
|
||||
if (node->planenum == -1)
|
||||
|
@ -89,17 +88,14 @@ WriteNodePlanes_r (node_t *node)
|
|||
if (planemapping[node->planenum] == -1) { // a new plane
|
||||
planemapping[node->planenum] = bsp->numplanes;
|
||||
|
||||
if (bsp->numplanes == MAX_MAP_PLANES)
|
||||
Sys_Error ("numplanes == MAX_MAP_PLANES");
|
||||
plane = &planes[node->planenum];
|
||||
dplane = &bsp->planes[bsp->numplanes];
|
||||
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->numplanes++;
|
||||
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);
|
||||
}
|
||||
|
||||
node->outputplanenum = planemapping[node->planenum];
|
||||
|
@ -120,7 +116,7 @@ WriteNodePlanes (node_t *nodes)
|
|||
int
|
||||
WriteClipNodes_r (node_t *node)
|
||||
{
|
||||
dclipnode_t *cn;
|
||||
dclipnode_t cn;
|
||||
int num, c, i;
|
||||
|
||||
// FIXME: free more stuff?
|
||||
|
@ -131,11 +127,10 @@ WriteClipNodes_r (node_t *node)
|
|||
}
|
||||
// emit a clipnode
|
||||
c = bsp->numclipnodes;
|
||||
cn = &bsp->clipnodes[bsp->numclipnodes];
|
||||
bsp->numclipnodes++;
|
||||
cn->planenum = node->outputplanenum;
|
||||
cn.planenum = node->outputplanenum;
|
||||
for (i = 0; i < 2; i++)
|
||||
cn->children[i] = WriteClipNodes_r (node->children[i]);
|
||||
cn.children[i] = WriteClipNodes_r (node->children[i]);
|
||||
BSP_AddClipnode (bsp, &cn);
|
||||
|
||||
free (node);
|
||||
return c;
|
||||
|
@ -161,23 +156,20 @@ WriteClipNodes (node_t *nodes)
|
|||
void
|
||||
WriteLeaf (node_t *node)
|
||||
{
|
||||
dleaf_t *leaf_p;
|
||||
dleaf_t leaf_p;
|
||||
face_t **fp, *f;
|
||||
|
||||
// emit a leaf
|
||||
leaf_p = &bsp->leafs[bsp->numleafs];
|
||||
bsp->numleafs++;
|
||||
|
||||
leaf_p->contents = node->contents;
|
||||
leaf_p.contents = node->contents;
|
||||
|
||||
// write bounding box info
|
||||
VectorCopy (node->mins, leaf_p->mins);
|
||||
VectorCopy (node->maxs, leaf_p->maxs);
|
||||
VectorCopy (node->mins, leaf_p.mins);
|
||||
VectorCopy (node->maxs, leaf_p.maxs);
|
||||
|
||||
leaf_p->visofs = -1; // no vis info yet
|
||||
leaf_p.visofs = -1; // no vis info yet
|
||||
|
||||
// write the marksurfaces
|
||||
leaf_p->firstmarksurface = bsp->nummarksurfaces;
|
||||
leaf_p.firstmarksurface = bsp->nummarksurfaces;
|
||||
|
||||
for (fp = node->markfaces; *fp; fp++) {
|
||||
// emit a marksurface
|
||||
|
@ -185,26 +177,27 @@ WriteLeaf (node_t *node)
|
|||
Sys_Error ("nummarksurfaces == MAX_MAP_MARKSURFACES");
|
||||
f = *fp;
|
||||
do {
|
||||
bsp->marksurfaces[bsp->nummarksurfaces] = f->outputnumber;
|
||||
bsp->nummarksurfaces++;
|
||||
BSP_AddMarkSurface (bsp, f->outputnumber);
|
||||
f = f->original; // grab tjunction split faces
|
||||
} while (f);
|
||||
}
|
||||
|
||||
leaf_p->nummarksurfaces = bsp->nummarksurfaces - leaf_p->firstmarksurface;
|
||||
leaf_p.nummarksurfaces = bsp->nummarksurfaces - leaf_p.firstmarksurface;
|
||||
}
|
||||
|
||||
void
|
||||
WriteDrawNodes_r (node_t *node)
|
||||
{
|
||||
static dnode_t dummy;
|
||||
dnode_t *n;
|
||||
int i;
|
||||
int nodenum = bsp->numnodes;
|
||||
|
||||
// emit a node
|
||||
if (bsp->numnodes == MAX_MAP_NODES)
|
||||
Sys_Error ("numnodes == MAX_MAP_NODES");
|
||||
n = &bsp->nodes[bsp->numnodes];
|
||||
bsp->numnodes++;
|
||||
BSP_AddNode (bsp, &dummy);
|
||||
n = &bsp->nodes[nodenum];
|
||||
|
||||
VectorCopy (node->mins, n->mins);
|
||||
VectorCopy (node->maxs, n->maxs);
|
||||
|
@ -215,6 +208,7 @@ WriteDrawNodes_r (node_t *node)
|
|||
|
||||
// recursively output the other nodes
|
||||
for (i = 0; i < 2; i++) {
|
||||
n = &bsp->nodes[nodenum];
|
||||
if (node->children[i]->planenum == -1) {
|
||||
if (node->children[i]->contents == CONTENTS_SOLID)
|
||||
n->children[i] = -1;
|
||||
|
@ -232,7 +226,7 @@ WriteDrawNodes_r (node_t *node)
|
|||
void
|
||||
WriteDrawNodes (node_t *headnode)
|
||||
{
|
||||
dmodel_t *bm;
|
||||
dmodel_t bm;
|
||||
int start, i;
|
||||
|
||||
#if 0
|
||||
|
@ -243,12 +237,10 @@ WriteDrawNodes (node_t *headnode)
|
|||
// emit a model
|
||||
if (bsp->nummodels == MAX_MAP_MODELS)
|
||||
Sys_Error ("nummodels == MAX_MAP_MODELS");
|
||||
bm = &bsp->models[bsp->nummodels];
|
||||
bsp->nummodels++;
|
||||
|
||||
bm->headnode[0] = bsp->numnodes;
|
||||
bm->firstface = firstface;
|
||||
bm->numfaces = bsp->numfaces - firstface;
|
||||
bm.headnode[0] = bsp->numnodes;
|
||||
bm.firstface = firstface;
|
||||
bm.numfaces = bsp->numfaces - firstface;
|
||||
firstface = bsp->numfaces;
|
||||
|
||||
start = bsp->numleafs;
|
||||
|
@ -257,12 +249,13 @@ WriteDrawNodes (node_t *headnode)
|
|||
WriteLeaf (headnode);
|
||||
else
|
||||
WriteDrawNodes_r (headnode);
|
||||
bm->visleafs = bsp->numleafs - start;
|
||||
bm.visleafs = bsp->numleafs - start;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
bm->mins[i] = headnode->mins[i] + SIDESPACE + 1; // remove the padding
|
||||
bm->maxs[i] = headnode->maxs[i] - SIDESPACE - 1;
|
||||
bm.mins[i] = headnode->mins[i] + SIDESPACE + 1; // remove the padding
|
||||
bm.maxs[i] = headnode->maxs[i] - SIDESPACE - 1;
|
||||
}
|
||||
BSP_AddModel (bsp, &bm);
|
||||
// FIXME: are all the children decendant of padded nodes?
|
||||
}
|
||||
|
||||
|
@ -276,15 +269,11 @@ Used by the clipping hull processes that only need to store headclipnode
|
|||
void
|
||||
BumpModel (int hullnum)
|
||||
{
|
||||
dmodel_t *bm;
|
||||
static dmodel_t bm;
|
||||
|
||||
// emit a model
|
||||
if (bsp->nummodels == MAX_MAP_MODELS)
|
||||
Sys_Error ("nummodels == MAX_MAP_MODELS");
|
||||
bm = &bsp->models[bsp->nummodels];
|
||||
bsp->nummodels++;
|
||||
|
||||
bm->headnode[hullnum] = headclipnode;
|
||||
bm.headnode[hullnum] = headclipnode;
|
||||
BSP_AddModel (bsp, &bm);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
@ -332,6 +321,8 @@ TEX_InitFromWad (char *path)
|
|||
int i;
|
||||
|
||||
texfile = Qopen (path, "rb");
|
||||
if (!texfile)
|
||||
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);
|
||||
|
@ -349,17 +340,20 @@ TEX_InitFromWad (char *path)
|
|||
}
|
||||
|
||||
int
|
||||
LoadLump (char *name, byte *dest)
|
||||
LoadLump (char *name, dstring_t *dest)
|
||||
{
|
||||
char cname[16];
|
||||
int i;
|
||||
int ofs = dest->size;
|
||||
|
||||
CleanupName (name, cname);
|
||||
|
||||
for (i = 0; i < wadinfo.numlumps; i++) {
|
||||
if (!strcmp (cname, lumpinfo[i].name)) {
|
||||
dest->size += lumpinfo[i].disksize;
|
||||
dstring_adjust (dest);
|
||||
Qseek (texfile, lumpinfo[i].filepos, SEEK_SET);
|
||||
Qread (texfile, dest, lumpinfo[i].disksize);
|
||||
Qread (texfile, dest->str + ofs, lumpinfo[i].disksize);
|
||||
return lumpinfo[i].disksize;
|
||||
}
|
||||
}
|
||||
|
@ -402,8 +396,8 @@ AddAnimatingTextures (void)
|
|||
void
|
||||
WriteMiptex (void)
|
||||
{
|
||||
byte *data;
|
||||
char *path;
|
||||
dstring_t *data;
|
||||
char *path, *p;
|
||||
char fullpath[1024];
|
||||
dmiptexlump_t *l;
|
||||
int i, len;
|
||||
|
@ -417,27 +411,36 @@ WriteMiptex (void)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
path = strdup (path);
|
||||
p = strtok (path, ";"); // yeah yeah. but it works :)
|
||||
while (p) {
|
||||
sprintf (fullpath, "%s/%s", /* FIXME gamedir */ ".", path);
|
||||
|
||||
TEX_InitFromWad (fullpath);
|
||||
|
||||
AddAnimatingTextures ();
|
||||
|
||||
l = (dmiptexlump_t *) bsp->texdata;
|
||||
data = (byte *) & l->dataofs[nummiptex];
|
||||
p = strtok (0, ";");
|
||||
}
|
||||
free (path);
|
||||
|
||||
data = dstring_new ();
|
||||
data->size = sizeof (dmiptexlump_t);
|
||||
dstring_adjust (data);
|
||||
|
||||
l = (dmiptexlump_t *) data->str;
|
||||
l->nummiptex = nummiptex;
|
||||
data->size = (char *) &l->dataofs[nummiptex] - data->str;
|
||||
dstring_adjust (data);
|
||||
l = (dmiptexlump_t *) data->str;
|
||||
|
||||
for (i = 0; i < nummiptex; i++) {
|
||||
l->dataofs[i] = data - (byte *) l;
|
||||
l->dataofs[i] = data->size;
|
||||
len = LoadLump (miptex[i], data);
|
||||
if (data + len - bsp->texdata >= MAX_MAP_MIPTEX)
|
||||
Sys_Error ("Textures exceeded MAX_MAP_MIPTEX");
|
||||
if (!len)
|
||||
l->dataofs[i] = -1; // didn't find the texture
|
||||
data += len;
|
||||
}
|
||||
|
||||
bsp->texdatasize = data - bsp->texdata;
|
||||
BSP_AddTextures (bsp, data->str, data->size);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -445,12 +448,14 @@ WriteMiptex (void)
|
|||
void
|
||||
BeginBSPFile (void)
|
||||
{
|
||||
static dedge_t edge;
|
||||
static dleaf_t leaf;
|
||||
// edge 0 is not used, because 0 can't be negated
|
||||
bsp->numedges = 1;
|
||||
BSP_AddEdge (bsp, &edge);
|
||||
|
||||
// leaf 0 is common solid with no faces
|
||||
bsp->numleafs = 1;
|
||||
bsp->leafs[0].contents = CONTENTS_SOLID;
|
||||
leaf.contents = CONTENTS_SOLID;
|
||||
BSP_AddLeaf (bsp, &leaf);
|
||||
|
||||
firstface = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue