00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "cmdlib.h"
00025 #include "mathlib.h"
00026 #include "bspfile.h"
00027
00028 #define MAX_PORTALS 32768
00029
00030 #define PORTALFILE "PRT1"
00031
00032 #define ON_EPSILON 0.1
00033
00034
00035
00036
00037 #define SEPERATORCACHE
00038
00039
00040 #define MAX_SEPERATORS 64
00041
00042 typedef struct
00043 {
00044 vec3_t normal;
00045 float dist;
00046 } plane_t;
00047
00048 #define MAX_POINTS_ON_WINDING 64
00049 #define MAX_POINTS_ON_FIXED_WINDING 12
00050
00051 typedef struct
00052 {
00053 int numpoints;
00054 vec3_t points[MAX_POINTS_ON_FIXED_WINDING];
00055 } winding_t;
00056
00057 winding_t *NewWinding (int points);
00058 void FreeWinding (winding_t *w);
00059 winding_t *CopyWinding (winding_t *w);
00060
00061
00062 typedef struct passage_s
00063 {
00064 struct passage_s *next;
00065 byte cansee[1];
00066 } passage_t;
00067
00068 typedef enum {stat_none, stat_working, stat_done} vstatus_t;
00069 typedef struct
00070 {
00071 int num;
00072 qboolean hint;
00073 qboolean removed;
00074 plane_t plane;
00075 int leaf;
00076
00077 vec3_t origin;
00078 float radius;
00079
00080 winding_t *winding;
00081 vstatus_t status;
00082 byte *portalfront;
00083 byte *portalflood;
00084 byte *portalvis;
00085
00086 int nummightsee;
00087 passage_t *passages;
00088
00089 } vportal_t;
00090
00091 #define MAX_PORTALS_ON_LEAF 128
00092 typedef struct leaf_s
00093 {
00094 int numportals;
00095 int merged;
00096 vportal_t *portals[MAX_PORTALS_ON_LEAF];
00097 } leaf_t;
00098
00099
00100 typedef struct pstack_s
00101 {
00102 byte mightsee[MAX_PORTALS/8];
00103 struct pstack_s *next;
00104 leaf_t *leaf;
00105 vportal_t *portal;
00106 winding_t *source;
00107 winding_t *pass;
00108
00109 winding_t windings[3];
00110 int freewindings[3];
00111
00112 plane_t portalplane;
00113 int depth;
00114 #ifdef SEPERATORCACHE
00115 plane_t seperators[2][MAX_SEPERATORS];
00116 int numseperators[2];
00117 #endif
00118 } pstack_t;
00119
00120 typedef struct
00121 {
00122 vportal_t *base;
00123 int c_chains;
00124 pstack_t pstack_head;
00125 } threaddata_t;
00126
00127
00128
00129 extern int numportals;
00130 extern int portalclusters;
00131
00132 extern vportal_t *portals;
00133 extern leaf_t *leafs;
00134
00135 extern int c_portaltest, c_portalpass, c_portalcheck;
00136 extern int c_portalskip, c_leafskip;
00137 extern int c_vistest, c_mighttest;
00138 extern int c_chains;
00139
00140 extern byte *vismap, *vismap_p, *vismap_end;
00141
00142 extern int testlevel;
00143
00144 extern byte *uncompressed;
00145
00146 extern int leafbytes, leaflongs;
00147 extern int portalbytes, portallongs;
00148
00149
00150 void LeafFlow (int leafnum);
00151
00152
00153 void BasePortalVis(int portalnum);
00154 void BetterPortalVis(int portalnum);
00155 void PortalFlow(int portalnum);
00156 void PassagePortalFlow(int portalnum);
00157 void CreatePassages(int portalnum);
00158 void PassageFlow(int portalnum);
00159
00160 extern vportal_t *sorted_portals[MAX_MAP_PORTALS*2];
00161
00162 int CountBits (byte *bits, int numbits);