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
|
|
|
|
2002-11-08 17:36:47 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
# include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-09-19 16:58:48 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2011-08-25 13:35:20 +00:00
|
|
|
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
|
2007-03-22 23:20:57 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2002-09-19 16:58:48 +00:00
|
|
|
#include <stdlib.h>
|
2003-08-11 17:11:44 +00:00
|
|
|
#include <errno.h>
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2010-08-18 08:52:13 +00:00
|
|
|
#include "csg4.h"
|
|
|
|
#include "brush.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
#include "bsp5.h"
|
2010-08-18 08:52:13 +00:00
|
|
|
#include "merge.h"
|
2002-09-20 21:48:34 +00:00
|
|
|
#include "options.h"
|
2010-08-18 08:52:13 +00:00
|
|
|
#include "outside.h"
|
|
|
|
#include "portals.h"
|
|
|
|
#include "readbsp.h"
|
|
|
|
#include "solidbsp.h"
|
|
|
|
#include "surfaces.h"
|
|
|
|
#include "writebsp.h"
|
|
|
|
#include "tjunc.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-09-01 01:06:54 +00:00
|
|
|
/** \addtogroup qfbsp
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
options_t options;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
bsp_t *bsp;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
brushset_t *brushset;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int valid;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
char *argv0; // changed after fork();
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
qboolean worldmodel;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int hullnum;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
node_t *
|
2002-09-19 17:14:23 +00:00
|
|
|
AllocNode (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
node_t *n;
|
|
|
|
|
|
|
|
n = malloc (sizeof (node_t));
|
|
|
|
memset (n, 0, sizeof (node_t));
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
ProcessEntity (int entnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
brushset_t *bs;
|
2002-09-19 17:14:23 +00:00
|
|
|
char mod[80];
|
2002-09-19 18:51:19 +00:00
|
|
|
entity_t *ent;
|
2002-09-19 17:14:23 +00:00
|
|
|
surface_t *surfs;
|
|
|
|
node_t *nodes;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
ent = &entities[entnum];
|
|
|
|
if (!ent->brushes)
|
2002-09-19 17:14:23 +00:00
|
|
|
return; // non-bmodel entity
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (entnum > 0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
worldmodel = false;
|
|
|
|
if (entnum == 1)
|
|
|
|
qprintf ("--- Internal Entities ---\n");
|
|
|
|
sprintf (mod, "*%i", bsp->nummodels);
|
2002-09-20 21:48:34 +00:00
|
|
|
if (options.verbosity)
|
2002-09-19 16:58:48 +00:00
|
|
|
PrintEntity (ent);
|
|
|
|
|
|
|
|
if (hullnum == 0)
|
|
|
|
printf ("MODEL: %s\n", mod);
|
|
|
|
SetKeyValue (ent, "model", mod);
|
2002-09-19 17:14:23 +00:00
|
|
|
} else
|
2002-09-19 16:58:48 +00:00
|
|
|
worldmodel = true;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// take the brush_ts and clip off all overlapping and contained faces,
|
|
|
|
// leaving a perfect skin of the model with no hidden faces
|
2002-09-19 16:58:48 +00:00
|
|
|
bs = Brush_LoadEntity (ent, hullnum);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
if (!bs->brushes) {
|
2002-09-19 16:58:48 +00:00
|
|
|
PrintEntity (ent);
|
|
|
|
Sys_Error ("Entity with no valid brushes");
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
brushset = bs;
|
|
|
|
surfs = CSGFaces (bs);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (hullnum != 0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
nodes = SolidBSP (surfs, true);
|
2002-09-20 21:48:34 +00:00
|
|
|
if (entnum == 0 && !options.nofill) {
|
|
|
|
// assume non-world bmodels are simple
|
2002-09-19 16:58:48 +00:00
|
|
|
PortalizeWorld (nodes);
|
2002-09-19 17:14:23 +00:00
|
|
|
if (FillOutside (nodes)) {
|
2002-09-19 16:58:48 +00:00
|
|
|
surfs = GatherNodeFaces (nodes);
|
2002-09-19 18:51:19 +00:00
|
|
|
nodes = SolidBSP (surfs, false); // make a really good tree
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
FreeAllPortals (nodes);
|
|
|
|
}
|
|
|
|
WriteNodePlanes (nodes);
|
|
|
|
WriteClipNodes (nodes);
|
|
|
|
BumpModel (hullnum);
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
|
|
|
// SolidBSP generates a node tree
|
2010-08-27 13:12:13 +00:00
|
|
|
//
|
2002-09-19 17:14:23 +00:00
|
|
|
// if not the world, make a good tree first
|
|
|
|
// the world is just going to make a bad tree
|
|
|
|
// because the outside filling will force a regeneration later
|
|
|
|
nodes = SolidBSP (surfs, entnum == 0);
|
|
|
|
|
|
|
|
// build all the portals in the bsp tree
|
|
|
|
// some portals are solid polygons, and some are paths to other leafs
|
2002-09-20 21:48:34 +00:00
|
|
|
if (entnum == 0 && !options.nofill) {
|
|
|
|
// assume non-world bmodels are simple
|
2002-09-19 16:58:48 +00:00
|
|
|
PortalizeWorld (nodes);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
if (FillOutside (nodes)) {
|
2002-09-19 16:58:48 +00:00
|
|
|
FreeAllPortals (nodes);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
// get the remaining faces together into surfaces again
|
2002-09-19 16:58:48 +00:00
|
|
|
surfs = GatherNodeFaces (nodes);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// merge polygons
|
2002-09-19 16:58:48 +00:00
|
|
|
MergeAll (surfs);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// make a really good tree
|
2002-09-19 16:58:48 +00:00
|
|
|
nodes = SolidBSP (surfs, false);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// make the real portals for vis tracing
|
2003-09-17 22:46:37 +00:00
|
|
|
PortalizeWorldDetail (nodes);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// save portal file for vis tracing
|
2002-09-19 16:58:48 +00:00
|
|
|
WritePortalfile (nodes);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// fix tjunctions
|
2002-09-19 16:58:48 +00:00
|
|
|
tjunc (nodes);
|
|
|
|
}
|
|
|
|
FreeAllPortals (nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteNodePlanes (nodes);
|
|
|
|
MakeFaceEdges (nodes);
|
|
|
|
WriteDrawNodes (nodes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
UpdateEntLump (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int m, entnum;
|
|
|
|
char mod[80];
|
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
|
|
|
m = 1;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (entnum = 1; entnum < num_entities; entnum++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!entities[entnum].brushes)
|
|
|
|
continue;
|
|
|
|
sprintf (mod, "*%i", m);
|
|
|
|
SetKeyValue (&entities[entnum], "model", mod);
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("Updating entities lump...\n");
|
2002-09-20 21:48:34 +00:00
|
|
|
f = Qopen (options.bspfile, "rb");
|
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
|
|
|
bsp = LoadBSPFile (f, Qfilesize (f));
|
|
|
|
Qclose (f);
|
2002-09-19 17:14:23 +00:00
|
|
|
WriteEntitiesToString ();
|
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 17:14:23 +00:00
|
|
|
WriteBSPFile (bsp, f);
|
2010-08-23 00:04:21 +00:00
|
|
|
BSP_Free (bsp);
|
2002-09-19 16:58:48 +00:00
|
|
|
Qclose (f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
WriteClipHull
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Write the clipping hull out to a text file so the parent process can get it
|
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
|
|
|
WriteClipHull (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
FILE *f;
|
2002-09-19 17:14:23 +00:00
|
|
|
dclipnode_t *d;
|
2002-09-19 18:51:19 +00:00
|
|
|
dplane_t *p;
|
|
|
|
int i;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
options.hullfile[strlen (options.hullfile) - 1] = '0' + hullnum;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
qprintf ("---- WriteClipHull ----\n");
|
2002-09-20 21:48:34 +00:00
|
|
|
qprintf ("Writing %s\n", options.hullfile);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
f = fopen (options.hullfile, "w");
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!f)
|
2002-09-20 21:48:34 +00:00
|
|
|
Sys_Error ("Couldn't open %s", options.hullfile);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
fprintf (f, "%i\n", bsp->nummodels);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < bsp->nummodels; i++)
|
2002-09-19 16:58:48 +00:00
|
|
|
fprintf (f, "%i\n", bsp->models[i].headnode[hullnum]);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
fprintf (f, "\n%i\n", bsp->numclipnodes);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < bsp->numclipnodes; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
d = &bsp->clipnodes[i];
|
|
|
|
p = &bsp->planes[d->planenum];
|
2010-01-13 06:42:26 +00:00
|
|
|
// the node number is written out only for human readability
|
2002-09-19 17:14:23 +00:00
|
|
|
fprintf (f, "%5i : %f %f %f %f : %5i %5i\n", i, p->normal[0],
|
|
|
|
p->normal[1], p->normal[2], p->dist, d->children[0],
|
|
|
|
d->children[1]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
fclose (f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
ReadClipHull
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Read the files written out by the child processes
|
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
|
|
|
ReadClipHull (int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
FILE *f;
|
2002-09-19 20:39:33 +00:00
|
|
|
dclipnode_t d;
|
2010-12-10 03:42:37 +00:00
|
|
|
plane_t p;
|
|
|
|
dplane_t dp;
|
2002-09-19 18:51:19 +00:00
|
|
|
float f1, f2, f3, f4;
|
|
|
|
int firstclipnode, junk, c1, c2, i, j, n;
|
2010-12-10 09:13:48 +00:00
|
|
|
int flip;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
options.hullfile[strlen (options.hullfile) - 1] = '0' + hullnum;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-20 21:48:34 +00:00
|
|
|
f = fopen (options.hullfile, "r");
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!f)
|
2002-09-20 21:48:34 +00:00
|
|
|
Sys_Error ("Couldn't open %s", options.hullfile);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-09-08 21:57:34 +00:00
|
|
|
if (fscanf (f, "%d\n", &n) != 1)
|
2002-09-20 21:48:34 +00:00
|
|
|
Sys_Error ("Error parsing %s", options.hullfile);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
if (n != bsp->nummodels)
|
2002-09-19 17:14:23 +00:00
|
|
|
Sys_Error ("ReadClipHull: hull had %i models, base had %i", n,
|
|
|
|
bsp->nummodels);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2007-01-06 21:31:03 +00:00
|
|
|
if (fscanf (f, "%d\n", &j) != 1)
|
|
|
|
Sys_Error ("Error parsing %s", options.hullfile);
|
2002-09-19 16:58:48 +00:00
|
|
|
bsp->models[i].headnode[hullnum] = bsp->numclipnodes + j;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
|
2007-01-06 21:31:03 +00:00
|
|
|
if (fscanf (f, "\n%d\n", &n) != 1)
|
|
|
|
Sys_Error ("Error parsing %s", options.hullfile);
|
2002-09-19 16:58:48 +00:00
|
|
|
firstclipnode = bsp->numclipnodes;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (bsp->numclipnodes == MAX_MAP_CLIPNODES)
|
|
|
|
Sys_Error ("ReadClipHull: MAX_MAP_CLIPNODES");
|
2003-09-08 21:57:34 +00:00
|
|
|
if (fscanf (f, "%d : %f %f %f %f : %d %d\n", &junk, &f1, &f2, &f3, &f4,
|
2002-09-19 18:51:19 +00:00
|
|
|
&c1, &c2) != 7)
|
2002-09-20 21:48:34 +00:00
|
|
|
Sys_Error ("Error parsing %s", options.hullfile);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-09-02 04:01:17 +00:00
|
|
|
VectorSet (f1, f2, f3, p.normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
p.dist = f4;
|
2010-12-10 09:13:48 +00:00
|
|
|
flip = NormalizePlane (&p);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-12-10 03:42:37 +00:00
|
|
|
VectorCopy (p.normal, dp.normal);
|
|
|
|
dp.dist = p.dist;
|
|
|
|
dp.type = p.type;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-12-10 09:13:48 +00:00
|
|
|
d.children[flip] = c1 >= 0 ? c1 + firstclipnode : c1;
|
|
|
|
d.children[!flip] = c2 >= 0 ? c2 + firstclipnode : c2;
|
2010-12-10 03:42:37 +00:00
|
|
|
|
|
|
|
d.planenum = FindFinalPlane (&dp);
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddClipnode (bsp, &d);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
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
|
|
|
CreateSingleHull (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int entnum;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// for each entity in the map file that has geometry
|
2002-09-19 17:14:23 +00:00
|
|
|
for (entnum = 0; entnum < num_entities; entnum++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
ProcessEntity (entnum);
|
2002-09-20 21:48:34 +00:00
|
|
|
if (options.verbosity < 2)
|
|
|
|
options.verbosity = 0; // don't print rest of entities
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hullnum)
|
|
|
|
WriteClipHull ();
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
CreateHulls (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2010-01-13 06:42:26 +00:00
|
|
|
// commanded to create only a single hull
|
2002-09-19 17:14:23 +00:00
|
|
|
if (hullnum) {
|
2002-09-19 16:58:48 +00:00
|
|
|
CreateSingleHull ();
|
|
|
|
exit (0);
|
|
|
|
}
|
2002-09-23 16:27:17 +00:00
|
|
|
// commanded to use the allready existing hulls 1 and 2
|
2002-09-20 21:48:34 +00:00
|
|
|
if (options.usehulls) {
|
2002-09-19 16:58:48 +00:00
|
|
|
CreateSingleHull ();
|
|
|
|
return;
|
|
|
|
}
|
2002-09-23 16:27:17 +00:00
|
|
|
// commanded to ignore the hulls altogether
|
2002-09-20 21:48:34 +00:00
|
|
|
if (options.noclip) {
|
2002-09-19 16:58:48 +00:00
|
|
|
CreateSingleHull ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// create all the hulls
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#ifdef __alpha
|
|
|
|
printf ("forking hull processes...\n");
|
2002-09-23 16:27:17 +00:00
|
|
|
// fork a process for each clipping hull
|
2002-09-19 16:58:48 +00:00
|
|
|
fflush (stdout);
|
2002-09-19 17:14:23 +00:00
|
|
|
if (!fork ()) {
|
2002-09-19 16:58:48 +00:00
|
|
|
hullnum = 1;
|
2002-09-20 21:48:34 +00:00
|
|
|
options.verbosity = 0;
|
2002-11-10 02:50:42 +00:00
|
|
|
options.drawflag = false;
|
2002-09-19 16:58:48 +00:00
|
|
|
sprintf (argv0, "HUL%i", hullnum);
|
2002-09-19 17:14:23 +00:00
|
|
|
} else if (!fork ()) {
|
2002-09-19 16:58:48 +00:00
|
|
|
hullnum = 2;
|
2002-09-20 21:48:34 +00:00
|
|
|
options.verbosity = 0;
|
2002-11-10 02:50:42 +00:00
|
|
|
options.drawflag = false;
|
2002-09-19 16:58:48 +00:00
|
|
|
sprintf (argv0, "HUL%i", hullnum);
|
|
|
|
}
|
|
|
|
CreateSingleHull ();
|
|
|
|
|
|
|
|
if (hullnum)
|
|
|
|
exit (0);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
wait (NULL); // wait for clip hull process to finish
|
|
|
|
wait (NULL); // wait for clip hull process to finish
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#else
|
2002-09-23 16:27:17 +00:00
|
|
|
// create the hulls sequentially
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("building hulls sequentially...\n");
|
|
|
|
|
|
|
|
hullnum = 1;
|
|
|
|
CreateSingleHull ();
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
bsp->nummodels = 0;
|
|
|
|
bsp->numplanes = 0;
|
|
|
|
bsp->numclipnodes = 0;
|
|
|
|
hullnum = 2;
|
|
|
|
CreateSingleHull ();
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
bsp->nummodels = 0;
|
|
|
|
bsp->numplanes = 0;
|
|
|
|
bsp->numclipnodes = 0;
|
|
|
|
hullnum = 0;
|
|
|
|
CreateSingleHull ();
|
2002-09-19 17:14:23 +00:00
|
|
|
#endif
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
|
|
|
ProcessFile (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2003-08-11 20:43:26 +00:00
|
|
|
bsp = BSP_New ();
|
2004-01-11 08:48:58 +00:00
|
|
|
|
2004-04-30 21:51:00 +00:00
|
|
|
if (options.extract) {
|
2004-01-15 07:16:44 +00:00
|
|
|
LoadBSP ();
|
2004-04-30 21:51:00 +00:00
|
|
|
if (options.portal)
|
|
|
|
bsp2prt ();
|
|
|
|
if (options.extract_textures)
|
|
|
|
extract_textures ();
|
|
|
|
if (options.extract_entities)
|
|
|
|
extract_entities ();
|
2009-03-18 03:28:34 +00:00
|
|
|
if (options.extract_hull)
|
|
|
|
extract_hull ();
|
2010-08-23 00:04:21 +00:00
|
|
|
BSP_Free (bsp);
|
2004-01-15 07:16:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-11 20:43:26 +00:00
|
|
|
// load brushes and entities
|
|
|
|
LoadMapFile (options.mapfile);
|
2002-09-20 21:48:34 +00:00
|
|
|
|
|
|
|
if (options.onlyents) {
|
2002-09-19 16:58:48 +00:00
|
|
|
UpdateEntLump ();
|
2010-08-23 00:04:21 +00:00
|
|
|
BSP_Free (bsp);
|
2002-09-19 16:58:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-01-11 08:48:58 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// init the tables to be shared by all models
|
2002-09-19 16:58:48 +00:00
|
|
|
BeginBSPFile ();
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// the clipping hulls will be written out to text files by forked processes
|
2002-09-19 16:58:48 +00:00
|
|
|
CreateHulls ();
|
|
|
|
|
|
|
|
ReadClipHull (1);
|
|
|
|
ReadClipHull (2);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
WriteEntitiesToString ();
|
2002-09-19 16:58:48 +00:00
|
|
|
FinishBSPFile ();
|
2010-08-23 00:04:21 +00:00
|
|
|
BSP_Free (bsp);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
double start, end;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-25 17:48:43 +00:00
|
|
|
// let forked processes change name for ps status
|
|
|
|
this_program = argv0 = argv[0];
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// check command line flags
|
2002-09-20 21:48:34 +00:00
|
|
|
DecodeArgs (argc, argv);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// XXX SetQdirFromPath (argv[i]);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// do it!
|
2002-09-19 16:58:48 +00:00
|
|
|
start = Sys_DoubleTime ();
|
2003-01-06 18:28:13 +00:00
|
|
|
ProcessFile ();
|
2002-09-19 16:58:48 +00:00
|
|
|
end = Sys_DoubleTime ();
|
2002-09-19 17:14:23 +00:00
|
|
|
printf ("%5.1f seconds elapsed\n", end - start);
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-05-07 07:18:36 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
qprintf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
if (!options.verbosity)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
vprintf (fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
}
|
2010-09-01 01:06:54 +00:00
|
|
|
|
|
|
|
//@}
|