2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
/* Files:
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
flow.c
|
|
|
|
qvis3.c
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "mathlib.h"
|
|
|
|
#include "bspfile.h"
|
|
|
|
#include "inout.h"
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
#ifdef WIN32
|
2012-03-17 20:01:54 +00:00
|
|
|
#ifdef NDEBUG // Don't show in a Release build
|
2007-11-04 03:34:51 +00:00
|
|
|
#pragma warning(disable : 4305) // truncate from double to float
|
|
|
|
#pragma warning(disable : 4244) // conversion from double to float
|
|
|
|
#pragma warning(disable : 4018) // signed/unsigned mismatch
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_PORTALS 32768
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define PORTALFILE "PRT1"
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define ON_EPSILON 0.1
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t normal;
|
|
|
|
float dist;
|
2007-11-04 03:34:51 +00:00
|
|
|
} plane_t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_POINTS_ON_WINDING 64
|
|
|
|
#define MAX_POINTS_ON_FIXED_WINDING 12
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean original; // don't free, it's part of the portal
|
|
|
|
int numpoints;
|
|
|
|
vec3_t points[MAX_POINTS_ON_FIXED_WINDING]; // variable sized
|
2007-11-04 03:34:51 +00:00
|
|
|
} winding_t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
winding_t *NewWinding( int points );
|
|
|
|
void FreeWinding( winding_t *w );
|
|
|
|
winding_t *CopyWinding( winding_t *w );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef enum {stat_none, stat_working, stat_done} vstatus_t;
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
plane_t plane; // normal pointing into neighbor
|
|
|
|
int leaf; // neighbor
|
|
|
|
|
|
|
|
vec3_t origin; // for fast clip testing
|
|
|
|
float radius;
|
|
|
|
|
|
|
|
winding_t *winding;
|
|
|
|
vstatus_t status;
|
|
|
|
byte *portalfront; // [portals], preliminary
|
|
|
|
byte *portalflood; // [portals], intermediate
|
|
|
|
byte *portalvis; // [portals], final
|
|
|
|
|
|
|
|
int nummightsee; // bit count on portalflood for sort
|
2007-11-04 03:34:51 +00:00
|
|
|
} portal_t;
|
|
|
|
|
|
|
|
typedef struct seperating_plane_s
|
|
|
|
{
|
|
|
|
struct seperating_plane_s *next;
|
2012-03-17 20:01:54 +00:00
|
|
|
plane_t plane; // from portal is on positive side
|
2007-11-04 03:34:51 +00:00
|
|
|
} sep_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct passage_s
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
struct passage_s *next;
|
|
|
|
int from, to; // leaf numbers
|
|
|
|
sep_t *planes;
|
2007-11-04 03:34:51 +00:00
|
|
|
} passage_t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_PORTALS_ON_LEAF 128
|
2007-11-04 03:34:51 +00:00
|
|
|
typedef struct leaf_s
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int numportals;
|
|
|
|
passage_t *passages;
|
|
|
|
portal_t *portals[MAX_PORTALS_ON_LEAF];
|
2007-11-04 03:34:51 +00:00
|
|
|
} leaf_t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
typedef struct pstack_s
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
byte mightsee[MAX_PORTALS / 8]; // bit string
|
|
|
|
struct pstack_s *next;
|
|
|
|
leaf_t *leaf;
|
|
|
|
portal_t *portal; // portal exiting
|
|
|
|
winding_t *source;
|
|
|
|
winding_t *pass;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
winding_t windings[3]; // source, pass, temp in any order
|
|
|
|
int freewindings[3];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
plane_t portalplane;
|
2007-11-04 03:34:51 +00:00
|
|
|
} pstack_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
portal_t *base;
|
|
|
|
int c_chains;
|
|
|
|
pstack_t pstack_head;
|
2007-11-04 03:34:51 +00:00
|
|
|
} threaddata_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern int numportals;
|
|
|
|
extern int portalclusters;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern portal_t *portals;
|
|
|
|
extern leaf_t *leafs;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern int c_portaltest, c_portalpass, c_portalcheck;
|
|
|
|
extern int c_portalskip, c_leafskip;
|
|
|
|
extern int c_vistest, c_mighttest;
|
|
|
|
extern int c_chains;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern byte *vismap, *vismap_p, *vismap_end; // past visfile
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern int testlevel;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern byte *uncompressed;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern int leafbytes, leaflongs;
|
|
|
|
extern int portalbytes, portallongs;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LeafFlow( int leafnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void BasePortalVis( int portalnum );
|
|
|
|
void BetterPortalVis( int portalnum );
|
|
|
|
void PortalFlow( int portalnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern portal_t *sorted_portals[MAX_MAP_PORTALS * 2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int CountBits( byte *bits, int numbits );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
// externs
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern char *mapname;
|