mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 22:31:05 +00:00
first stab at getting bsp to portal working. produces a portal file that
looks ok at first glance but the numbers are a tad bogus. More loading errors, I guess.
This commit is contained in:
parent
4f66e8fc60
commit
440e03374e
6 changed files with 286 additions and 29 deletions
|
@ -25,8 +25,7 @@
|
||||||
#include "QF/mathlib.h"
|
#include "QF/mathlib.h"
|
||||||
#include "QF/bspfile.h"
|
#include "QF/bspfile.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
vec3_t normal;
|
vec3_t normal;
|
||||||
vec_t dist;
|
vec_t dist;
|
||||||
int type;
|
int type;
|
||||||
|
@ -48,8 +47,7 @@ typedef struct
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
int numpoints;
|
int numpoints;
|
||||||
vec3_t points[8]; // variable sized
|
vec3_t points[8]; // variable sized
|
||||||
} winding_t;
|
} winding_t;
|
||||||
|
@ -65,8 +63,7 @@ void DivideWinding (winding_t *in, plane_t *split, winding_t **front, winding_t
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
typedef struct visfacet_s
|
typedef struct visfacet_s {
|
||||||
{
|
|
||||||
struct visfacet_s *next;
|
struct visfacet_s *next;
|
||||||
|
|
||||||
int planenum;
|
int planenum;
|
||||||
|
@ -83,8 +80,7 @@ typedef struct visfacet_s
|
||||||
int *edges;
|
int *edges;
|
||||||
} face_t;
|
} face_t;
|
||||||
|
|
||||||
typedef struct surface_s
|
typedef struct surface_s {
|
||||||
{
|
|
||||||
struct surface_s *next;
|
struct surface_s *next;
|
||||||
struct surface_s *original; // before BSP cuts it up
|
struct surface_s *original; // before BSP cuts it up
|
||||||
int planenum;
|
int planenum;
|
||||||
|
@ -100,8 +96,7 @@ typedef struct surface_s
|
||||||
// there is a node_t structure for every node and leaf in the bsp tree
|
// there is a node_t structure for every node and leaf in the bsp tree
|
||||||
#define PLANENUM_LEAF -1
|
#define PLANENUM_LEAF -1
|
||||||
|
|
||||||
typedef struct node_s
|
typedef struct node_s {
|
||||||
{
|
|
||||||
vec3_t mins,maxs; // bounding volume, not just points inside
|
vec3_t mins,maxs; // bounding volume, not just points inside
|
||||||
|
|
||||||
// information for decision nodes
|
// information for decision nodes
|
||||||
|
@ -129,16 +124,14 @@ typedef struct node_s
|
||||||
|
|
||||||
#define NUM_CONTENTS 2 // solid and water
|
#define NUM_CONTENTS 2 // solid and water
|
||||||
|
|
||||||
typedef struct brush_s
|
typedef struct brush_s {
|
||||||
{
|
|
||||||
struct brush_s *next;
|
struct brush_s *next;
|
||||||
vec3_t mins, maxs;
|
vec3_t mins, maxs;
|
||||||
face_t *faces;
|
face_t *faces;
|
||||||
int contents;
|
int contents;
|
||||||
} brush_t;
|
} brush_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
vec3_t mins, maxs;
|
vec3_t mins, maxs;
|
||||||
brush_t *brushes; // NULL terminated list
|
brush_t *brushes; // NULL terminated list
|
||||||
} brushset_t;
|
} brushset_t;
|
||||||
|
@ -191,8 +184,7 @@ void MakeFaceEdges (node_t *headnode);
|
||||||
|
|
||||||
// portals.c ==================================================================
|
// portals.c ==================================================================
|
||||||
|
|
||||||
typedef struct portal_s
|
typedef struct portal_s {
|
||||||
{
|
|
||||||
int planenum;
|
int planenum;
|
||||||
node_t *nodes[2]; // [0] = front side of planenum
|
node_t *nodes[2]; // [0] = front side of planenum
|
||||||
struct portal_s *next[2];
|
struct portal_s *next[2];
|
||||||
|
@ -250,6 +242,10 @@ void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3);
|
||||||
|
|
||||||
qboolean FillOutside (node_t *node);
|
qboolean FillOutside (node_t *node);
|
||||||
|
|
||||||
|
// readbsp.c ==================================================================
|
||||||
|
|
||||||
|
void LoadBSP (void);
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
extern brushset_t *brushset;
|
extern brushset_t *brushset;
|
||||||
|
|
|
@ -38,6 +38,7 @@ typedef struct {
|
||||||
qboolean nofill;
|
qboolean nofill;
|
||||||
qboolean noclip;
|
qboolean noclip;
|
||||||
qboolean onlyents;
|
qboolean onlyents;
|
||||||
|
qboolean portal;
|
||||||
qboolean usehulls;
|
qboolean usehulls;
|
||||||
qboolean watervis;
|
qboolean watervis;
|
||||||
int hullnum;
|
int hullnum;
|
||||||
|
|
|
@ -17,7 +17,7 @@ EXTRA_PROGRAMS= qfbsp
|
||||||
|
|
||||||
qfbsp_SOURCES= \
|
qfbsp_SOURCES= \
|
||||||
brush.c csg4.c map.c merge.c nodraw.c options.c outside.c portals.c \
|
brush.c csg4.c map.c merge.c nodraw.c options.c outside.c portals.c \
|
||||||
qfbsp.c region.c solidbsp.c surfaces.c tjunc.c writebsp.c
|
qfbsp.c readbsp.c region.c solidbsp.c surfaces.c tjunc.c writebsp.c
|
||||||
|
|
||||||
qfbsp_LDADD= $(QFBSP_LIBS)
|
qfbsp_LDADD= $(QFBSP_LIBS)
|
||||||
qfbsp_DEPENDENCIES= $(QFBSP_DEPS)
|
qfbsp_DEPENDENCIES= $(QFBSP_DEPS)
|
||||||
|
|
|
@ -57,6 +57,7 @@ static struct option const long_options[] = {
|
||||||
{"nofill", no_argument, 0, 'f'},
|
{"nofill", no_argument, 0, 'f'},
|
||||||
{"noclip", no_argument, 0, 'c'},
|
{"noclip", no_argument, 0, 'c'},
|
||||||
{"onlyents", no_argument, 0, 'e'},
|
{"onlyents", no_argument, 0, 'e'},
|
||||||
|
{"portal", no_argument, 0, 'p'},
|
||||||
{"usehulls", no_argument, 0, 'u'},
|
{"usehulls", no_argument, 0, 'u'},
|
||||||
{"hullnum", required_argument, 0, 'H'},
|
{"hullnum", required_argument, 0, 'H'},
|
||||||
{"subdivide", required_argument, 0, 's'},
|
{"subdivide", required_argument, 0, 's'},
|
||||||
|
@ -75,6 +76,7 @@ static const char *short_options =
|
||||||
"f" // nofill
|
"f" // nofill
|
||||||
"c" // noclip
|
"c" // noclip
|
||||||
"e" // onlyents
|
"e" // onlyents
|
||||||
|
"p" // portal
|
||||||
"u" // usehulls
|
"u" // usehulls
|
||||||
"H:" // hullnum
|
"H:" // hullnum
|
||||||
"s:" // subdivide
|
"s:" // subdivide
|
||||||
|
@ -98,6 +100,7 @@ usage (int status)
|
||||||
" -t, --notjunc\n"
|
" -t, --notjunc\n"
|
||||||
" -c, --noclip\n"
|
" -c, --noclip\n"
|
||||||
" -e, --onlyents\n"
|
" -e, --onlyents\n"
|
||||||
|
" -p, --portal\n"
|
||||||
" -u, --usehulls Use the existing hull files\n"
|
" -u, --usehulls Use the existing hull files\n"
|
||||||
" -H, --hullnum [num]\n"
|
" -H, --hullnum [num]\n"
|
||||||
" -s, --subdivide [size]\n"
|
" -s, --subdivide [size]\n"
|
||||||
|
@ -148,6 +151,9 @@ DecodeArgs (int argc, char **argv)
|
||||||
case 'e': // onlyents
|
case 'e': // onlyents
|
||||||
options.onlyents = true;
|
options.onlyents = true;
|
||||||
break;
|
break;
|
||||||
|
case 'p': // portal
|
||||||
|
options.portal = true;
|
||||||
|
break;
|
||||||
case 'u': // usehulls
|
case 'u': // usehulls
|
||||||
options.usehulls = true;
|
options.usehulls = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -765,24 +765,29 @@ ProcessFile (void)
|
||||||
QFS_StripExtension (options.bspfile, options.pointfile);
|
QFS_StripExtension (options.bspfile, options.pointfile);
|
||||||
strcat (options.pointfile, ".pts");
|
strcat (options.pointfile, ".pts");
|
||||||
bsp = BSP_New ();
|
bsp = BSP_New ();
|
||||||
|
if (options.portal) {
|
||||||
|
LoadBSP ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// load brushes and entities
|
// load brushes and entities
|
||||||
LoadMapFile (options.mapfile);
|
LoadMapFile (options.mapfile);
|
||||||
|
|
||||||
if (!options.onlyents) {
|
|
||||||
remove (options.bspfile);
|
|
||||||
if (!options.usehulls) {
|
|
||||||
options.hullfile[strlen (options.hullfile) - 1] = '1';
|
|
||||||
remove (options.hullfile);
|
|
||||||
options.hullfile[strlen (options.hullfile) - 1] = '2';
|
|
||||||
remove (options.hullfile);
|
|
||||||
}
|
|
||||||
remove (options.portfile);
|
|
||||||
remove (options.pointfile);
|
|
||||||
}
|
|
||||||
if (options.onlyents) {
|
if (options.onlyents) {
|
||||||
UpdateEntLump ();
|
UpdateEntLump ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove (options.bspfile);
|
||||||
|
if (!options.usehulls) {
|
||||||
|
options.hullfile[strlen (options.hullfile) - 1] = '1';
|
||||||
|
remove (options.hullfile);
|
||||||
|
options.hullfile[strlen (options.hullfile) - 1] = '2';
|
||||||
|
remove (options.hullfile);
|
||||||
|
}
|
||||||
|
remove (options.portfile);
|
||||||
|
remove (options.pointfile);
|
||||||
|
|
||||||
// init the tables to be shared by all models
|
// init the tables to be shared by all models
|
||||||
BeginBSPFile ();
|
BeginBSPFile ();
|
||||||
|
|
||||||
|
@ -809,7 +814,6 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
// XXX SetQdirFromPath (argv[i]);
|
// XXX SetQdirFromPath (argv[i]);
|
||||||
|
|
||||||
|
|
||||||
// do it!
|
// do it!
|
||||||
start = Sys_DoubleTime ();
|
start = Sys_DoubleTime ();
|
||||||
ProcessFile ();
|
ProcessFile ();
|
||||||
|
|
250
tools/qfbsp/source/readbsp.c
Normal file
250
tools/qfbsp/source/readbsp.c
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
/*
|
||||||
|
#FILENAME#
|
||||||
|
|
||||||
|
#DESCRIPTION#
|
||||||
|
|
||||||
|
Copyright (C) 2003 #AUTHOR#
|
||||||
|
|
||||||
|
Author: #AUTHOR#
|
||||||
|
Date: #DATE#
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "QF/dstring.h"
|
||||||
|
#include "QF/qendian.h"
|
||||||
|
#include "QF/sys.h"
|
||||||
|
#include "QF/va.h"
|
||||||
|
#include "QF/wad.h"
|
||||||
|
|
||||||
|
#include "bsp5.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
face_t *mfaces;
|
||||||
|
node_t *nodes;
|
||||||
|
node_t *leafs;
|
||||||
|
texinfo_t *texinfo;
|
||||||
|
dvertex_t *vertices;
|
||||||
|
dedge_t *edges;
|
||||||
|
int *surfedges;
|
||||||
|
unsigned short *marksurfaces;
|
||||||
|
plane_t *mplanes;
|
||||||
|
static brushset_t bs;
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_texinfo (void)
|
||||||
|
{
|
||||||
|
texinfo = bsp->texinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_entities (void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_clipnodes (void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_surfedges (void)
|
||||||
|
{
|
||||||
|
surfedges = bsp->surfedges;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_edges (void)
|
||||||
|
{
|
||||||
|
edges = bsp->edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_planes (void)
|
||||||
|
{
|
||||||
|
dplane_t *p;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
mplanes = malloc (bsp->numplanes * sizeof (plane_t));
|
||||||
|
for (i = 0; i < bsp->numplanes; i++) {
|
||||||
|
p = bsp->planes + i;
|
||||||
|
VectorCopy (p->normal, mplanes[i].normal);
|
||||||
|
mplanes[i].dist = p->dist;
|
||||||
|
mplanes[i].type = p->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_marksurfaces (void)
|
||||||
|
{
|
||||||
|
marksurfaces = bsp->marksurfaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_faces (void)
|
||||||
|
{
|
||||||
|
dface_t *f;
|
||||||
|
int i, j;
|
||||||
|
winding_t *points;
|
||||||
|
|
||||||
|
mfaces = calloc (bsp->numfaces, sizeof (face_t));
|
||||||
|
for (i = 0; i < bsp->numfaces; i++) {
|
||||||
|
f = bsp->faces + i;
|
||||||
|
mfaces[i].planenum = f->planenum;
|
||||||
|
mfaces[i].planeside = f->side;
|
||||||
|
mfaces[i].texturenum = f->texinfo;
|
||||||
|
mfaces[i].points = NewWinding (f->numedges);
|
||||||
|
mfaces[i].edges = surfedges + f->firstedge;
|
||||||
|
|
||||||
|
points = mfaces[i].points;
|
||||||
|
points->numpoints = f->numedges;
|
||||||
|
for (j = 0; j < points->numpoints; j++) {
|
||||||
|
int e = mfaces[i].edges[j];
|
||||||
|
int v;
|
||||||
|
|
||||||
|
if (e < 0) {
|
||||||
|
v = edges[-e].v[1];
|
||||||
|
} else {
|
||||||
|
v = edges[e].v[0];
|
||||||
|
}
|
||||||
|
VectorCopy (vertices[v].point, points->points[j]);
|
||||||
|
printf ("%g %g %g\n", points->points[j][0], points->points[j][1], points->points[j][2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_vertices (void)
|
||||||
|
{
|
||||||
|
vertices = bsp->vertexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_leafs (void)
|
||||||
|
{
|
||||||
|
dleaf_t *l;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
leafs = calloc (bsp->numleafs, sizeof (node_t));
|
||||||
|
for (i = 0; i < bsp->numleafs; i++) {
|
||||||
|
l = bsp->leafs + i;
|
||||||
|
leafs[i].planenum = -1;
|
||||||
|
leafs[i].contents = l->contents;
|
||||||
|
VectorCopy (l->mins, leafs[i].mins);
|
||||||
|
VectorCopy (l->maxs, leafs[i].maxs);
|
||||||
|
leafs[i].markfaces = calloc (l->nummarksurfaces + 1,
|
||||||
|
sizeof (face_t *));
|
||||||
|
for (j = 0; j < l->nummarksurfaces; j++) {
|
||||||
|
unsigned short ms = l->firstmarksurface + j;
|
||||||
|
leafs[i].markfaces[j] = mfaces + marksurfaces[ms];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_nodes (void)
|
||||||
|
{
|
||||||
|
dnode_t *n;
|
||||||
|
face_t *f;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
nodes = calloc (bsp->numnodes, sizeof (node_t));
|
||||||
|
for (i = 0; i < bsp->numnodes; i++) {
|
||||||
|
n = bsp->nodes + i;
|
||||||
|
VectorCopy (n->mins, nodes[i].mins);
|
||||||
|
VectorCopy (n->maxs, nodes[i].maxs);
|
||||||
|
nodes[i].outputplanenum = n->planenum;
|
||||||
|
nodes[i].planenum = nodes[i].outputplanenum;
|
||||||
|
nodes[i].firstface = n->firstface;
|
||||||
|
nodes[i].numfaces = n->numfaces;
|
||||||
|
for (j = 0; j < 2; j++) {
|
||||||
|
if (n->children[j] < 0) {
|
||||||
|
nodes[i].children[j] = leafs - n->children[j] - 1;
|
||||||
|
} else {
|
||||||
|
nodes[i].children[j] = nodes + n->children[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nodes[i].numfaces) {
|
||||||
|
nodes[i].faces = mfaces + nodes[i].firstface;
|
||||||
|
for (j = 0, f = nodes[i].faces; j < n->numfaces - 1; j++, f++) {
|
||||||
|
f->next = f + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_models (void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_textures (void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LoadBSP (void)
|
||||||
|
{
|
||||||
|
QFile *f;
|
||||||
|
|
||||||
|
f = Qopen (options.bspfile, "rb");
|
||||||
|
if (!f)
|
||||||
|
Sys_Error ("couldn't open %s. %s", options.bspfile, strerror(errno));
|
||||||
|
bsp = LoadBSPFile (f, Qfilesize (f));
|
||||||
|
Qclose (f);
|
||||||
|
|
||||||
|
load_texinfo ();
|
||||||
|
load_entities ();
|
||||||
|
load_clipnodes ();
|
||||||
|
load_surfedges ();
|
||||||
|
load_edges ();
|
||||||
|
load_planes ();
|
||||||
|
load_marksurfaces ();
|
||||||
|
load_vertices ();
|
||||||
|
load_faces ();
|
||||||
|
load_leafs ();
|
||||||
|
load_nodes ();
|
||||||
|
load_models ();
|
||||||
|
load_textures ();
|
||||||
|
|
||||||
|
memcpy (planes, mplanes, bsp->numplanes * sizeof (plane_t));
|
||||||
|
VectorCopy (bsp->models[0].mins, bs.mins)
|
||||||
|
VectorCopy (bsp->models[0].maxs, bs.maxs)
|
||||||
|
brushset = &bs;
|
||||||
|
PortalizeWorldDetail (nodes);
|
||||||
|
WritePortalfile (nodes);
|
||||||
|
}
|
Loading…
Reference in a new issue