2002-08-25 23:06:23 +00:00
|
|
|
/*
|
|
|
|
vis.h
|
|
|
|
|
|
|
|
PVS/PHS generation tool
|
|
|
|
|
2002-09-25 01:51:58 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-08-25 23:06:23 +00:00
|
|
|
Copyright (C) 2002 Colin Thompson
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __vis_h
|
|
|
|
#define __vis_h
|
|
|
|
|
2002-09-20 19:03:06 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-19 04:40:42 +00:00
|
|
|
#if defined (HAVE_PTHREAD_H) && defined (HAVE_PTHREAD)
|
2013-03-18 04:31:35 +00:00
|
|
|
#define USE_PTHREADS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_PTHREADS
|
2002-08-25 23:06:23 +00:00
|
|
|
#include <pthread.h>
|
2013-03-18 05:26:52 +00:00
|
|
|
extern pthread_rwlock_t *global_lock;
|
2013-03-18 06:03:11 +00:00
|
|
|
extern pthread_rwlock_t *portal_locks;
|
2021-07-27 11:04:19 +00:00
|
|
|
extern pthread_rwlock_t *stats_lock;
|
2013-03-18 05:26:52 +00:00
|
|
|
|
|
|
|
#define WRLOCK(l) \
|
|
|
|
do { \
|
|
|
|
if (options.threads > 1) \
|
|
|
|
pthread_rwlock_wrlock (l); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RDLOCK(l) \
|
2013-03-18 04:31:35 +00:00
|
|
|
do { \
|
|
|
|
if (options.threads > 1) \
|
2013-03-18 05:26:52 +00:00
|
|
|
pthread_rwlock_rdlock (l); \
|
2013-03-18 04:31:35 +00:00
|
|
|
} while (0)
|
2013-03-18 05:26:52 +00:00
|
|
|
|
|
|
|
#define UNLOCK(l) \
|
2013-03-18 04:31:35 +00:00
|
|
|
do { \
|
|
|
|
if (options.threads > 1) \
|
2013-03-18 05:26:52 +00:00
|
|
|
pthread_rwlock_unlock (l); \
|
2013-03-18 04:31:35 +00:00
|
|
|
} while (0)
|
2013-03-18 06:03:11 +00:00
|
|
|
|
|
|
|
#define WRLOCK_PORTAL(p) WRLOCK (&portal_locks[p - portals])
|
|
|
|
#define RDLOCK_PORTAL(p) RDLOCK (&portal_locks[p - portals])
|
|
|
|
#define UNLOCK_PORTAL(p) UNLOCK (&portal_locks[p - portals])
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
#else
|
2021-03-26 06:27:48 +00:00
|
|
|
#define LOCK(l)
|
|
|
|
#define UNLOCK(l)
|
|
|
|
#define WRLOCK_PORTAL(p)
|
|
|
|
#define RDLOCK_PORTAL(p)
|
|
|
|
#define UNLOCK_PORTAL(p)
|
2002-08-25 23:06:23 +00:00
|
|
|
#endif
|
|
|
|
|
2021-03-27 14:04:13 +00:00
|
|
|
#include "QF/cmem.h"
|
2021-03-28 12:11:13 +00:00
|
|
|
#include "QF/dstring.h"
|
2013-03-07 02:06:55 +00:00
|
|
|
#include "QF/set.h"
|
2021-07-29 02:49:18 +00:00
|
|
|
#include "QF/zone.h"
|
2021-03-28 10:55:47 +00:00
|
|
|
#include "QF/simd/vec4f.h"
|
2013-03-07 02:06:55 +00:00
|
|
|
|
2004-02-02 05:44:46 +00:00
|
|
|
#define PORTALFILE "PRT1"
|
|
|
|
#define PORTALFILE_AM "PRT1-AM"
|
2013-03-07 09:51:32 +00:00
|
|
|
#define PORTALFILE2 "PRT2"
|
2002-08-25 23:06:23 +00:00
|
|
|
#define ON_EPSILON 0.1
|
|
|
|
|
2021-01-01 09:58:26 +00:00
|
|
|
typedef struct winding_s {
|
|
|
|
struct winding_s *next;
|
2023-06-13 09:06:11 +00:00
|
|
|
bool original; // don't free, it's part of the portal
|
2021-01-01 07:32:36 +00:00
|
|
|
unsigned numpoints;
|
2021-03-28 10:55:47 +00:00
|
|
|
int id;
|
|
|
|
int thread;
|
2021-07-29 02:49:18 +00:00
|
|
|
vec4f_t points[1]; // variable sized
|
2002-08-25 23:06:23 +00:00
|
|
|
} winding_t;
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
typedef enum {
|
|
|
|
stat_none,
|
2002-09-22 21:54:41 +00:00
|
|
|
stat_selected,
|
2012-05-21 23:23:22 +00:00
|
|
|
stat_working,
|
|
|
|
stat_done
|
2002-08-25 23:06:23 +00:00
|
|
|
} vstatus_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2021-03-28 10:55:47 +00:00
|
|
|
vec4f_t plane; // normal pointing into neighbor
|
|
|
|
vspheref_t sphere; // bounding sphere
|
2003-02-04 23:26:26 +00:00
|
|
|
int cluster; // neighbor
|
2002-09-21 21:27:38 +00:00
|
|
|
winding_t *winding;
|
|
|
|
vstatus_t status;
|
2013-03-07 02:06:55 +00:00
|
|
|
set_t *visbits;
|
|
|
|
set_t *mightsee;
|
2002-09-21 21:27:38 +00:00
|
|
|
int nummightsee;
|
|
|
|
int numcansee;
|
2002-08-25 23:06:23 +00:00
|
|
|
} portal_t;
|
|
|
|
|
|
|
|
typedef struct seperating_plane_s {
|
2021-03-28 10:55:47 +00:00
|
|
|
vec4f_t plane; // from portal is on positive side
|
2002-09-19 02:37:52 +00:00
|
|
|
struct seperating_plane_s *next;
|
2002-08-25 23:06:23 +00:00
|
|
|
} sep_t;
|
|
|
|
|
|
|
|
typedef struct passage_s {
|
2002-09-19 02:37:52 +00:00
|
|
|
struct passage_s *next;
|
2003-02-04 23:26:26 +00:00
|
|
|
int from, to; // cluster numbers
|
2002-09-21 21:27:38 +00:00
|
|
|
sep_t *planes;
|
2002-08-25 23:06:23 +00:00
|
|
|
} passage_t;
|
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
typedef struct cluster_s {
|
2002-09-21 21:27:38 +00:00
|
|
|
int numportals;
|
2021-03-28 10:55:47 +00:00
|
|
|
int visofs;
|
2021-07-30 09:52:47 +00:00
|
|
|
vspheref_t sphere;
|
2002-09-21 21:27:38 +00:00
|
|
|
passage_t *passages;
|
2021-07-29 12:03:07 +00:00
|
|
|
portal_t *portals;
|
2003-02-04 23:26:26 +00:00
|
|
|
} cluster_t;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
typedef struct pstack_s {
|
2013-03-14 10:40:19 +00:00
|
|
|
struct pstack_s *next; ///< linked list of active stack objects
|
2013-03-17 10:18:38 +00:00
|
|
|
cluster_t *cluster; ///< the cluster being sub-vised
|
|
|
|
winding_t *source_winding; ///< clipped source portal winding
|
|
|
|
portal_t *pass_portal; ///< the portal exiting from the cluster
|
2021-03-28 10:55:47 +00:00
|
|
|
vec4f_t pass_plane; ///< plane of the pass portal
|
2013-03-17 10:18:38 +00:00
|
|
|
winding_t *pass_winding; ///< clipped pass portal winding
|
2013-03-18 03:47:59 +00:00
|
|
|
set_t *mightsee;
|
2013-03-08 13:20:29 +00:00
|
|
|
sep_t *separators[2];
|
2002-08-25 23:06:23 +00:00
|
|
|
} pstack_t;
|
|
|
|
|
2013-03-14 02:33:47 +00:00
|
|
|
typedef struct {
|
2021-07-30 14:07:12 +00:00
|
|
|
unsigned long portaltest; ///< number of portals tested via separators
|
|
|
|
unsigned long portalpass; ///< number of portals through which vis passes
|
|
|
|
unsigned long portalcheck; ///< number of portal checks
|
|
|
|
unsigned long targettested; ///< number of times target portal tested
|
|
|
|
unsigned long targettrimmed;///< number of times target portal trimmed
|
|
|
|
unsigned long targetclipped;///< number of times target portal clipped away
|
|
|
|
unsigned long sourcetested; ///< number of times source portal tested
|
|
|
|
unsigned long sourcetrimmed;///< number of times source portal trimmed
|
|
|
|
unsigned long sourceclipped;///< number of times source portal clipped away
|
|
|
|
unsigned long chains; ///< number of visits to clusters
|
|
|
|
unsigned long mighttest; ///< amount mightsee is used for masked tests
|
|
|
|
unsigned long vistest; ///< amount visbits is used for masked tests
|
|
|
|
unsigned long mightseeupdate;///< amount of updates to waiting portals
|
2021-03-27 14:04:13 +00:00
|
|
|
unsigned sep_alloc; ///< how many separators were allocated
|
|
|
|
unsigned sep_free; ///< how many separators were freed
|
|
|
|
unsigned sep_highwater; ///< most separators in flight
|
|
|
|
unsigned sep_maxbulk; ///< most separators freed at once
|
2021-07-29 02:49:18 +00:00
|
|
|
size_t winding_mark; ///< most memory allocated to windings
|
2021-03-27 14:04:13 +00:00
|
|
|
unsigned stack_alloc; ///< how many stack blocks were allocated
|
|
|
|
unsigned stack_free; ///< how many stack blocks were freed
|
2013-03-14 02:33:47 +00:00
|
|
|
} visstat_t;
|
|
|
|
|
2013-03-08 13:20:29 +00:00
|
|
|
typedef struct threaddata_s {
|
2013-03-14 10:40:19 +00:00
|
|
|
visstat_t stats; ///< per-thread statistics merged on completion
|
|
|
|
set_t *clustervis; ///< clusters base portal can see
|
|
|
|
portal_t *base; ///< portal for which this thread is being run
|
2013-03-18 03:47:59 +00:00
|
|
|
pstack_t pstack_head;
|
2013-03-14 10:40:19 +00:00
|
|
|
sep_t *sep_freelist; ///< per-thread list of free separators
|
2021-03-27 14:04:13 +00:00
|
|
|
memsuper_t *memsuper; ///< per-thread memory pool
|
2021-07-29 02:49:18 +00:00
|
|
|
memhunk_t *hunk;
|
2021-03-28 12:11:13 +00:00
|
|
|
dstring_t *str;
|
2013-03-18 04:30:50 +00:00
|
|
|
set_pool_t set_pool;
|
2021-03-27 14:04:13 +00:00
|
|
|
int id;
|
2021-03-28 10:55:47 +00:00
|
|
|
int winding_id;
|
2002-08-25 23:06:23 +00:00
|
|
|
} threaddata_t;
|
|
|
|
|
2013-03-19 02:42:09 +00:00
|
|
|
typedef struct {
|
|
|
|
set_t *portalsee;
|
2021-07-30 14:07:12 +00:00
|
|
|
unsigned long selfcull; ///< number of protals culled by self
|
|
|
|
unsigned long clustercull; ///< number of portals culled by cluster sphere
|
|
|
|
unsigned long clustertest; ///< number of portals tested by cluster
|
|
|
|
unsigned long spheretest; ///< number of portal sphere tests done
|
|
|
|
unsigned long spherecull; ///< number of portals culled by sphere tests
|
|
|
|
unsigned long spherepass; ///< number of portals passed by sphere tests
|
|
|
|
unsigned long windingtest; ///< number of portal pairs tested by winding
|
|
|
|
unsigned long windingcull; ///< number of portals culled by winding tests
|
|
|
|
unsigned long windingpass; ///< number of portals passed by winding tests
|
|
|
|
unsigned long clustersee;
|
2021-03-27 14:04:13 +00:00
|
|
|
int id;
|
2013-03-19 02:42:09 +00:00
|
|
|
} basethread_t;
|
|
|
|
|
2021-01-01 07:32:36 +00:00
|
|
|
extern unsigned numportals;
|
|
|
|
extern unsigned portalclusters;
|
|
|
|
extern unsigned numrealleafs;
|
2002-08-25 23:06:23 +00:00
|
|
|
extern int bitbytes;
|
2003-02-04 23:26:26 +00:00
|
|
|
extern int bitbytes_l;
|
2002-08-25 23:06:23 +00:00
|
|
|
extern int bitlongs;
|
2002-09-23 22:54:28 +00:00
|
|
|
extern struct bsp_s *bsp;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
extern portal_t *portals;
|
2003-02-04 23:26:26 +00:00
|
|
|
extern cluster_t *clusters;
|
2021-08-03 02:37:24 +00:00
|
|
|
extern uint32_t *leafcluster;
|
2002-08-25 23:06:23 +00:00
|
|
|
extern byte *uncompressed;
|
|
|
|
|
2021-01-01 09:58:26 +00:00
|
|
|
winding_t *NewWinding (threaddata_t *thread, int points);
|
2021-03-28 10:55:47 +00:00
|
|
|
winding_t *ClipWinding (threaddata_t *thread, winding_t *in, vec4f_t split,
|
2023-06-13 09:06:11 +00:00
|
|
|
bool keepon);
|
2021-01-01 09:58:26 +00:00
|
|
|
winding_t *CopyWinding (threaddata_t *thread, const winding_t *w);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
void ClusterFlow (int clusternum);
|
2013-03-19 02:42:09 +00:00
|
|
|
void PortalBase (basethread_t *thread, portal_t *portal);
|
2013-03-14 02:33:47 +00:00
|
|
|
void PortalFlow (threaddata_t *data, portal_t *portal);
|
2002-08-25 23:06:23 +00:00
|
|
|
void CalcAmbientSounds (void);
|
|
|
|
|
2021-07-27 12:47:19 +00:00
|
|
|
struct sizebuf_s;
|
|
|
|
int CompressRow (struct sizebuf_s *dest, const byte *vis, unsigned num_leafs,
|
|
|
|
int utf8);
|
2021-07-27 11:04:19 +00:00
|
|
|
|
2021-07-26 13:42:03 +00:00
|
|
|
void CalcFatPVS (void);
|
|
|
|
|
2021-08-03 12:52:24 +00:00
|
|
|
void RunThreads (const char *heading, void *(*thread_func) (void *),
|
|
|
|
int (*calc_progress)(void));
|
2021-07-26 13:42:03 +00:00
|
|
|
|
|
|
|
extern const char spinner[];
|
|
|
|
extern const char progress[];
|
|
|
|
extern int *working;
|
2021-08-03 12:52:24 +00:00
|
|
|
extern int progress_tick;
|
2021-07-26 13:42:03 +00:00
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
#endif// __vis_h
|