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/bspfile.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
vec3_t normal;
|
||||
vec_t dist;
|
||||
int type;
|
||||
|
@ -48,8 +47,7 @@ typedef struct
|
|||
|
||||
//============================================================================
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
int numpoints;
|
||||
vec3_t points[8]; // variable sized
|
||||
} 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;
|
||||
|
||||
int planenum;
|
||||
|
@ -83,8 +80,7 @@ typedef struct visfacet_s
|
|||
int *edges;
|
||||
} face_t;
|
||||
|
||||
typedef struct surface_s
|
||||
{
|
||||
typedef struct surface_s {
|
||||
struct surface_s *next;
|
||||
struct surface_s *original; // before BSP cuts it up
|
||||
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
|
||||
#define PLANENUM_LEAF -1
|
||||
|
||||
typedef struct node_s
|
||||
{
|
||||
typedef struct node_s {
|
||||
vec3_t mins,maxs; // bounding volume, not just points inside
|
||||
|
||||
// information for decision nodes
|
||||
|
@ -129,16 +124,14 @@ typedef struct node_s
|
|||
|
||||
#define NUM_CONTENTS 2 // solid and water
|
||||
|
||||
typedef struct brush_s
|
||||
{
|
||||
typedef struct brush_s {
|
||||
struct brush_s *next;
|
||||
vec3_t mins, maxs;
|
||||
face_t *faces;
|
||||
int contents;
|
||||
} brush_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
vec3_t mins, maxs;
|
||||
brush_t *brushes; // NULL terminated list
|
||||
} brushset_t;
|
||||
|
@ -191,8 +184,7 @@ void MakeFaceEdges (node_t *headnode);
|
|||
|
||||
// portals.c ==================================================================
|
||||
|
||||
typedef struct portal_s
|
||||
{
|
||||
typedef struct portal_s {
|
||||
int planenum;
|
||||
node_t *nodes[2]; // [0] = front side of planenum
|
||||
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);
|
||||
|
||||
// readbsp.c ==================================================================
|
||||
|
||||
void LoadBSP (void);
|
||||
|
||||
//=============================================================================
|
||||
|
||||
extern brushset_t *brushset;
|
||||
|
|
|
@ -38,6 +38,7 @@ typedef struct {
|
|||
qboolean nofill;
|
||||
qboolean noclip;
|
||||
qboolean onlyents;
|
||||
qboolean portal;
|
||||
qboolean usehulls;
|
||||
qboolean watervis;
|
||||
int hullnum;
|
||||
|
|
|
@ -17,7 +17,7 @@ EXTRA_PROGRAMS= qfbsp
|
|||
|
||||
qfbsp_SOURCES= \
|
||||
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_DEPENDENCIES= $(QFBSP_DEPS)
|
||||
|
|
|
@ -57,6 +57,7 @@ static struct option const long_options[] = {
|
|||
{"nofill", no_argument, 0, 'f'},
|
||||
{"noclip", no_argument, 0, 'c'},
|
||||
{"onlyents", no_argument, 0, 'e'},
|
||||
{"portal", no_argument, 0, 'p'},
|
||||
{"usehulls", no_argument, 0, 'u'},
|
||||
{"hullnum", required_argument, 0, 'H'},
|
||||
{"subdivide", required_argument, 0, 's'},
|
||||
|
@ -75,6 +76,7 @@ static const char *short_options =
|
|||
"f" // nofill
|
||||
"c" // noclip
|
||||
"e" // onlyents
|
||||
"p" // portal
|
||||
"u" // usehulls
|
||||
"H:" // hullnum
|
||||
"s:" // subdivide
|
||||
|
@ -98,6 +100,7 @@ usage (int status)
|
|||
" -t, --notjunc\n"
|
||||
" -c, --noclip\n"
|
||||
" -e, --onlyents\n"
|
||||
" -p, --portal\n"
|
||||
" -u, --usehulls Use the existing hull files\n"
|
||||
" -H, --hullnum [num]\n"
|
||||
" -s, --subdivide [size]\n"
|
||||
|
@ -148,6 +151,9 @@ DecodeArgs (int argc, char **argv)
|
|||
case 'e': // onlyents
|
||||
options.onlyents = true;
|
||||
break;
|
||||
case 'p': // portal
|
||||
options.portal = true;
|
||||
break;
|
||||
case 'u': // usehulls
|
||||
options.usehulls = true;
|
||||
break;
|
||||
|
|
|
@ -765,10 +765,19 @@ ProcessFile (void)
|
|||
QFS_StripExtension (options.bspfile, options.pointfile);
|
||||
strcat (options.pointfile, ".pts");
|
||||
bsp = BSP_New ();
|
||||
if (options.portal) {
|
||||
LoadBSP ();
|
||||
return;
|
||||
}
|
||||
|
||||
// load brushes and entities
|
||||
LoadMapFile (options.mapfile);
|
||||
|
||||
if (!options.onlyents) {
|
||||
if (options.onlyents) {
|
||||
UpdateEntLump ();
|
||||
return;
|
||||
}
|
||||
|
||||
remove (options.bspfile);
|
||||
if (!options.usehulls) {
|
||||
options.hullfile[strlen (options.hullfile) - 1] = '1';
|
||||
|
@ -778,11 +787,7 @@ ProcessFile (void)
|
|||
}
|
||||
remove (options.portfile);
|
||||
remove (options.pointfile);
|
||||
}
|
||||
if (options.onlyents) {
|
||||
UpdateEntLump ();
|
||||
return;
|
||||
}
|
||||
|
||||
// init the tables to be shared by all models
|
||||
BeginBSPFile ();
|
||||
|
||||
|
@ -809,7 +814,6 @@ main (int argc, char **argv)
|
|||
|
||||
// XXX SetQdirFromPath (argv[i]);
|
||||
|
||||
|
||||
// do it!
|
||||
start = Sys_DoubleTime ();
|
||||
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