Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/libraries/tools/bsp/Q3Map.h @ 12138

Last change on this file since 12138 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 22.2 KB
Line 
1/*
2===========================================================================
3Copyright (C) 2008 Daniel Örstadius
4Copyright (C) 2009 Jared Prince
5
6This file is part of bsp-renderer source code.
7
8bsp-renderer is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
12
13bsp-renderer is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with bsp-renderer.  If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23// Q3Map.h -- handles the map data
24
25#ifndef _Q3MAP_H
26#define _Q3MAP_H
27
28#define WIN32_LEAN_AND_MEAN
29#include "windows.h"
30
31#include "Q3Map_Bezier.h"
32
33#include <string>
34#include <vector>
35
36#include "Q3Map_misc.h"
37
38//#include "JarDebug.h" //!! just for debugging, remove from final build
39
40#define MEMADD  65536 // memory is grown in 66k blocks
41#define MAX_TOKENSIZE 1024 // make sure tokens in texts aren't ridiculously large
42
43
44
45#define MINMAXLIMIT 10000000.0
46
47#define BRIGHTNESSTWEAK 0.5f //1.25f                            // tweak for spotlight brightness
48
49#define ADDTEXTUREUNIQUE_FAIL           -1
50#define ADDTEXLAMP_FAIL                                 -2
51
52#define ADDSPOTLIGHTTEXTURE_FAIL        -1
53
54////////////////////////////////////////////////////
55
56#define AXIS_X  0
57#define AXIS_Y  1
58#define AXIS_Z  2
59
60////////////////////////////////////////////////////
61/*
62#define FACESORT_FACE_LIMIT                     16777216
63#define FACESORT_FACE_SHIFT                     0
64#define FACESORT_FACE_MASK                      0x0000000000FFFFFF
65#define FACESORT_TEXTURE_LIMIT  4096
66#define FACESORT_TEXTURE_SHIFT  24
67#define FACESORT_TEXTURE_MASK           0x0000000FFF000000
68#define FACESORT_SUBZONE_LIMIT                  4096 // also see MAX_ZONE
69#define FACESORT_SUBZONE_SHIFT                  36
70#define FACESORT_SUBZONE_MASK                   0x0000FFF000000000
71*/
72
73#define FACESORT_FACE_LIMIT                     16777216
74#define FACESORT_FACE_SHIFT                     0
75#define FACESORT_FACE_MASK                      0x0000000000FFFFFF
76#define FACESORT_GROUP_LIMIT            65536   // also see MAX_TRANS
77#define FACESORT_GROUP_SHIFT            24
78#define FACESORT_GROUP_MASK                     0x000000FFFF000000
79#define FACESORT_TEXTURE_LIMIT  4096
80#define FACESORT_TEXTURE_SHIFT  40
81#define FACESORT_TEXTURE_MASK           0x000FFF0000000000
82#define FACESORT_SUBZONE_LIMIT  4096 // also see MAX_ZONE
83#define FACESORT_SUBZONE_SHIFT  52
84#define FACESORT_SUBZONE_MASK           0xFFF0000000000000
85
86#define GROUPSORT_FACE_LIMIT            16777216
87#define GROUPSORT_FACE_SHIFT            0
88#define GROUPSORT_FACE_MASK                     0x0000000000FFFFFF
89#define GROUPSORT_GROUP_LIMIT           16777216
90#define GROUPSORT_GROUP_SHIFT           24
91#define GROUPSORT_GROUP_MASK            0x0000FFFFFF000000
92#define GROUPSORT_SUBZONE_LIMIT 4096 // also see MAX_ZONE
93#define GROUPSORT_SUBZONE_SHIFT 52
94#define GROUPSORT_SUBZONE_MASK  0xFFF0000000000000
95
96
97
98////////////////////////////////////////////////////
99
100#define MAX_ZONE        4096                                                    // max subzones and max zones. Also see FACESORT_SUBZONE_LIMIT
101#define MAX_SUBZONEPERZONE      16                      // the most subzones that can make up a zone, further subzones ignored. INDEX_SUBZONECOUNT must be same as this
102#define INDEX_SUBZONECOUNT      16                      // helps subzone counting in m_nZone.  See MAX_SUBZONEPERZONE
103
104#define MAX_PORTAL      32768                                           // max subzoneportals in a map.
105#define MAX_PORTALPERZONE 64                            // the most portals that a zone can have, further portals ignored.  INDEX_PORTALCOUNT must be same as this
106#define MAX_ZONEPERPORTAL       8                                       // the most zones a portal can connect, further zones ignored.  INDEX_PORTALZONECOUNT must be the same as this
107#define MAX_LIGHTPERPORTAL 16                           // the most lights that can touch a portal, further lights ignored. INDEX_PORTALLIGHTCOUNT must be the same as this
108#define INDEX_PORTALCOUNT       64                              // helps portal counting in m_nZoneTouchesPortal. See MAX_PORTALSPERZONE
109#define INDEX_PORTALZONECOUNT 8                 // helps portalconnect counting in m_nPortalTouchesZone. See MAX_ZONEPERPORTAL
110#define INDEX_PORTALLIGHTCOUNT 16               // helps portallight counting in m_PortalConnectsLight. See MAX_LIGHTPERPORTAL
111
112#define MAX_ZONEPERZONE         64                              // the most zones that a zone can connect to.
113#define INDEX_ZONEPERZONECOUNT  64  // helps zone per zone counting.
114
115#define MAX_LIGHT               32768                                           // max lights in a map, both from the map and other things (flashlight, missiles, etc)
116#define MAX_LIGHTPERZONE 64                                     // the most lights that a zone can have, further lights ignored.  INDEX_LIGHTCOUNT must be same as this
117#define MAX_ZONEPERLIGHT        8                                       // the most zones a light can touch, further zones ignored.  INDEX_LIGHTZONECOUNT must be the same as this
118#define INDEX_LIGHTCOUNT        64                              // helps light counting in m_nZoneContainsLight.  see MAX_LIGHTPERZONE
119#define INDEX_LIGHTZONECOUNT    8                       // helps light counting in m_nLightContainedByZone. See MAX_ZONEPERLIGHT
120
121#define MAX_SUBLIGHT    262144                          // must be MAX_LIGHT * MAX_ZONEPERLIGHT
122#define MAX_TRANS                       65536                                   // most transparent objects per zone (objects may be defined in various ways).  see FACESORT_TRANS_LIMIT
123
124
125
126////////////////////////////////////////////////////
127
128#define SUBZONE_EPSILON 0.01f   // small buffer of extra size around subzones so that we don't accidentally exclude a point due to float accuracy errors.
129#define FRUSTUM_EPSILON 0.0001f // once frustum is this tiny consider it dead
130#define VERYSMALL 0.00001                       // small number
131
132#define PORTAL_UNCHECKED                0
133#define PORTAL_VISCHECK                 1
134#define PORTAL_VISIBLE                  2
135
136#define PORTALSTATE_OPENCHECK   0
137#define PORTALSTATE_CLOSED                      1
138#define PORTALSTATE_OPEN                                2
139
140#define ZONE_UNCHECKED                  0
141#define ZONE_VISIBLE                            1
142
143#define LIGHT_UNCHECKED                         0
144#define LIGHT_OUTOFFRUSTUM              1
145#define LIGHT_INSIDEFRUSTUM             2
146#define LIGHT_NOTVISIBLE                        4
147#define LIGHT_VISIBLE                                   8
148#define LIGHT_CHECKED                                   16
149
150///////////////////////////////////////////////////
151
152#define MAX_PROJECTORTEX        16              // most types of projector textures we can have per map.
153
154
155///////////////////////////////////////////////////
156
157// NOERROR is already defined in a windows file, it is 0
158#define ERROR_ParseMap                                          1
159#define ERROR_ParseEntities                             2
160#define ERROR_AllocateVertex                    3
161#define ERROR_AllocateTriangle          4
162#define ERROR_InitializeFaces                   5
163#define ERROR_ConvertFaces                              6
164#define ERROR_ConvertPatches                    7
165#define ERROR_ConvertLamps                              8
166#define ERROR_ConvertLampGlow                   9
167#define ERROR_ConvertLightGlow          10
168#define ERROR_AssignTriangles                   11
169#define ERROR_SortTriangles                             12
170#define ERROR_ConvertTexLamp                    13
171#define ERROR_SetupTransTextures        14
172#define ERROR_SortGroups                                        15
173
174
175///////////////////////////////////////////////////
176// error values for parsing key/values
177#define KEY_OK                                                                          0
178#define KEY_NONE                                                                        1
179#define KEY_ERROR                                                                       2
180
181//////////////////////////////////////////////////
182// entity types
183#define ENTITY_ERROR                                                    0
184#define ENTITY_UNKNOWN                                          1
185#define ENTITY_WORLDSPAWN                                       2
186#define ENTITY_LIGHT                                                    3
187
188///////////////////////////////////////////////////
189
190
191
192// The lump idexes that make up a bsp file.
193// Bzn bsp lump data is almost identical to q3a bsp lump data,  except that the
194// Effects, Lightmaps and VisData lumps are removed and there are two new lumps, one
195// describing the subzones and one describing the portals. The other difference is the lighting
196// entities (which are stored as normal entities in lump 0) since q3a bsps don't usually
197// store the light entities at all, and BZN has it's own unique set of lighting keys.
198
199const int Textures = 1;
200const int Planes = 2;
201const int Nodes = 3;
202const int Leafs = 4;
203const int LeafFaces = 5;
204const int LeafBrushes = 6;
205const int Brushes = 8;
206const int BrushSides = 9;
207const int Vertices = 10;
208const int MeshVerts = 11;
209const int Effects = 12;                         // removed from bzn
210const int Faces = 13;
211const int LightMaps = 14;                       // removed from bzn
212const int VisData = 16;                         // removed from bzn
213const int SubZoneData = 17 ;    // added to bzn: overlapping subzones form zones. Zones are like groups of axial boxes.
214const int PortalData = 18 ;             // added to bzn: portals overlapping different zones allow them to see each other.
215const int MAX_LUMP = 19 ;
216
217const int MAX_LUMP_SIZE = 100000000 ; // this value is very large and arbitrary, 100 megabytes.  Just make sure MAX_LUMP_SIZE * MAX_LUMP is less than the max size for a size_t or parseMap error checking won't work.
218
219enum {POLYGON = 1, PATCH, MESH, BILLBOARD};
220
221typedef struct{
222  int iOffset;
223  int iLength;
224} direntry_t;
225
226#define Q3NAMESIZE      64
227typedef struct {
228  char name[Q3NAMESIZE];
229  int flags;
230  int contents;
231} Q3BspTexture;
232
233typedef struct{
234  unsigned char magic[4];
235  int version;
236  direntry_t Lumps[MAX_LUMP];
237} Q3BspHeader_t;
238
239typedef struct{
240  int texture;
241  int effect;
242  int type;
243  int vertex;
244  int n_vertexes;
245  int meshvert;
246  int n_meshverts;
247  int lm_index;
248  int lm_start[2];
249  int lm_size[2];
250  float lm_origin[3];
251  float lm_vecs[2][3];
252  float normal[3];
253  int size[2];
254} Q3BspFace_t;
255
256typedef struct{
257  float position[3];
258  float texcoord[2][2];
259  float normal[3];
260  unsigned char color[4];
261} Q3BspVertex;
262
263typedef struct {
264  int cluster;
265  int area;
266  int mins[3];
267  int maxs[3];
268  int leafface;
269  int n_leaffaces;
270  int leafbrush;
271  int n_leafbrushes;
272} Q3BspLeaf;
273
274typedef struct {
275  float normal[3];
276  float dist;
277} Q3BspPlane;
278
279typedef struct {
280  int plane;
281  int children[2];
282  int mins[3];
283  int maxs[3];
284} Q3BspNode;
285
286typedef struct {
287  int brushside;
288  int n_brushsides;
289  int texture;
290} Q3BspBrush;
291
292typedef struct {
293  int plane;
294  int texture;
295} Q3BspBrushSide;
296
297typedef struct {
298  unsigned char lightmap[128][128][3];
299} Q3BspLightMap;
300
301typedef struct {
302  int n_vecs;
303  int sz_vecs;
304  unsigned char *vecs;
305} Q3BspVisData;
306
307typedef struct {
308  int size;
309  Bezier *bezier;
310} Q3BspPatch;
311
312
313// this struct must be the same as in BZNq3map2
314typedef struct
315{
316        int Zone ;
317        float Min[3] ;
318        float Max[3] ;
319}
320BZN_SubZone_t;
321
322// this struct must be the same as in BZNq3map2
323typedef struct
324{
325        float Min[3] ;
326        float Max[3] ;
327}
328BZN_Portal_t;
329
330
331typedef struct{
332        int texture;   
333        int type;
334        int vertex;
335        int n_vertexes;
336        int meshvert;
337        int n_meshverts;
338        int n_triangles;
339        int lm_index;   
340        float normal[3]; 
341        int zone ; // added by Jared
342        Q3BspPatch *patch;
343} Q3BspFaceRenderer;
344
345//////////////////////////////////////
346typedef struct {
347        int Zone ; // this gets set to -1 for triangles in no zone, and they don't get added to the manualobjects
348        int Texture ;
349        //int Lightmap ; // bzn doesn't use lightmaps
350        int VIndex[3] ;
351        int Lamp ; // which lamp this triangle came from, -1 for most triangles.
352
353        int Group ; // triangles from the same face are the same group, triangles from the same patch are the same group.  Most stuff is group 0 unless it needs special attention, such as transparent stuff
354} triangle_t;
355
356typedef struct {
357        unsigned int Flags ;
358        float   Position[3] ;
359        float Direction[3] ;
360        float Colour[3] ;
361        float Min[3] ;
362        float Max[3] ;
363        float   Cutoff ;
364        float   Angle ;
365        float Brightness ;
366        int Texture ; // texture index of light
367        unsigned int ZoneCount ; // how many zones this light touches
368        unsigned int CentreZone ; // which zone contains the centre of this light.  even if on a boundary, the light will only choose one zone as its centre.
369        short SubLightStart ; // where this light's sublights start in the sublight list.
370} light_t ;
371
372typedef struct {
373        unsigned int Flags ;
374        float   Position[3] ;
375        float Colour[3] ;
376        float Min[3] ;
377        float Max[3] ;
378        float Brightness ;
379        int Texture ; // texture index of light
380        int LightNode ; // -1 if not a node, 0 - 3 if a node.  LightNodes are used as the data for TexLamps, freeform geometry that gets converted to deferred shading lamp triangles.
381        unsigned short Zone[MAX_ZONEPERLIGHT+1] ; // the zones this lamp touches
382} lamp_t ;
383
384typedef struct
385{
386        float Min[3] ;
387        float Max[3] ;
388}
389minmax_t;
390
391// this used for the light culling algo, where each cutup light is treated as a subzone.
392typedef struct
393{
394        unsigned short Light ;
395        unsigned short Zone ;
396        float Min[3] ;
397        float Max[3] ;
398}
399sublight_t;
400
401
402class Q3Map
403{
404public:
405  Q3Map();
406  ~Q3Map();
407
408        int m_nNewCount ;
409
410        int m_nDebugA ;
411
412//      CJarDebug Q3Bug ; //!! just for debugging, remove from final build
413        char m_chBug[10240] ;
414
415        int ParseAndTriangulateMap(const char* pData, size_t Size) ;
416        void FreeParseMem(void) ;
417
418        int parseMap(const char* pMem, size_t Size);
419
420  int findVisibleFaces(const QVECTOR *camPos, int *facesToRender);
421  Q3BspFace_t *getFaces(void);
422  Q3BspPatch *handlePatch(int faceIndex);
423
424        char m_chSpotlightTexture[MAX_PROJECTORTEX][Q3NAMESIZE] ;
425        int m_nMaxSpotlightTexture ;
426        int AddSpolightTexture(char TEXNAME[]) ;
427
428private:
429
430 
431 
432 
433
434       
435
436  int findLeaf(const QVECTOR *camPos) const;
437  bool isClusterVisible(int visCluster, int testCluster) const; 
438
439  int *mVisibleFaces;
440
441  std::vector<Q3BspVisData> *patches;
442
443public:
444  // map data
445
446  Q3BspHeader_t m_BspHeader;
447
448  char *m_pEntities;
449
450  int m_iNumTexs;
451  Q3BspTexture *m_pTexturesOrig;
452
453  int m_iNumFaces;
454  Q3BspFace_t *m_pFaces; 
455
456  int m_iNumVertices;
457  Q3BspVertex *m_pVertices;
458
459  int m_iNumMeshVerts; 
460  int *m_pMeshVerts;
461
462  int m_iNumLeafs;
463  Q3BspLeaf *m_pLeafs;
464
465  int m_iNumLeafFaces;
466  int *m_pLeafFaces;
467
468  int m_iNumPlanes;
469  Q3BspPlane *m_pPlanes;
470
471  int m_iNumNodes;
472  Q3BspNode *m_pNodes;
473
474  int m_iNumLeafBrushes;
475  int *m_pLeafBrushes;
476
477  int m_iNumBrushes;
478  Q3BspBrush *m_pBrushes;
479
480  int m_iNumBrushSides;
481  Q3BspBrushSide *m_pBrushSides;
482
483  int m_iNumLightMaps;
484  Q3BspLightMap *m_pLightMaps;
485
486  Q3BspVisData *m_VisData;
487
488        int m_iNumSubZones ;
489  BZN_SubZone_t *m_pSubZones;
490
491        int m_iNumPortals ;
492  BZN_Portal_t *m_pPortals;
493
494
495
496
497  int m_ClusterCount ;
498
499        void swizzleCoords(void);
500  void swizzleFloat3(float t[3]);
501  void swizzleInt3(int t[3]);
502
503        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
504
505        // memory management for the triangles
506        int AllocateTriangleMemory(void) ;
507        void FreeTriangleMemory(void) ;
508        int ExpandTriangleMemory(void) ;
509        int AddTriangle(triangle_t Triangle) ;
510        int m_nTriangleSize ; // starting memory size
511        void* m_pTriangleMem ; // allocate starting memory space
512        triangle_t* m_pTriangle ; // a pointer to the memory cast as a triangle_t
513        int m_nTriangleMax ;
514        int m_nTriangleLimit ;
515
516        // memory management for the vertices
517        int AllocateVertexMemory(int nVertNum) ;
518        void FreeVertexMemory(void) ;
519        int ExpandVertexMemory(void) ;
520        int AddVertex(Q3BspVertex Vertex) ;
521        int m_nVertexSize ; // starting memory size
522        void* m_pVertexMem ; // allocate starting memory space
523        Q3BspVertex* m_pVertex ; // a pointer to the memory cast as a Q3BspVertex
524        int m_nVertexMax ;
525        int m_nVertexLimit ;
526
527        // memory management for the lights
528        int AllocateLightMemory(void) ;
529        void FreeLightMemory(void) ;
530        int ExpandLightMemory(void) ;
531        int AddLight(light_t Light) ;
532        int m_nLightSize ; // starting memory size
533        void* m_pLightMem ; // allocate starting memory space
534        light_t* m_pLight ; // a pointer to the memory cast as a light_t
535        int m_nLightMax ;
536        int m_nLightLimit ;
537
538        // memory management for the lamps (a lamp is a deferred shading non-shadowing point light)
539        int AllocateLampMemory(void) ;
540        void FreeLampMemory(void) ;
541        int ExpandLampMemory(void) ;
542        int AddLamp(lamp_t Lamp) ;
543        int m_nLampSize ; // starting memory size
544        void* m_pLampMem ; // allocate starting memory space
545        lamp_t* m_pLamp ; // a pointer to the memory cast as a lamp_t
546        int m_nLampMax ;
547        int m_nLampLimit ;
548
549        // memory management for the textures
550        int AllocateTextureMemory(void) ;
551        void FreeTextureMemory(void) ;
552        int ExpandTextureMemory(void) ;
553        int AddTexture(Q3BspTexture Texture) ;
554        int AddTextureUnique(Q3BspTexture Texture) ; // special version of the Add function, will not add if the texture name already exist.  returns texture index, or -1 on fail
555        int m_nTextureSize ; // starting memory size
556        void* m_pTextureMem ; // allocate starting memory space
557        Q3BspTexture* m_pTexture ; // a pointer to the memory cast as a Texture_t
558        int m_nTextureMax ;
559        int m_nTextureLimit ;
560
561        // memory management for the TexLamp Triangles
562        int AllocateTexLampMemory(void) ;
563        void FreeTexLampMemory(void) ;
564        int ExpandTexLampMemory(void) ;
565        int AddTexLamp(int TexLamp) ;
566        int m_nTexLampSize ; // starting memory size
567        void* m_pTexLampMem ; // allocate starting memory space
568        int* m_pTexLamp ; // a pointer to the memory cast as an int
569        int m_nTexLampMax ;
570        int m_nTexLampLimit ;
571
572        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
573
574
575        int ParseEntities(void) ;
576        int NextEntity(int* pPos, int nMaxPos) ;
577        int GetEntityType(int nPos, int nMaxPos) ;
578        int GetEntityKeyAndValue(int* pPos, int nMaxPos, char* pKey, char* pValue) ;
579        int GetNumbersFromValue(char* pValue, float *pNumber, int nNumberSize) ;
580        int GetNumbersFromValue(char* pValue, int *pNumber, int nNumberSize) ;
581        int ParseAndAddLight(int* pPos, int nMaxPos) ;
582
583        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
584
585        Q3BspFaceRenderer *m_BspFaces; 
586        int m_NumBspFaces;
587        void DestroyBspFacesMemory(void) ;
588        int initFaces(void) ;
589
590        // we keep track of common texture indexes to avoid slow calls to AddTextureUnique when we add default light texture indexes
591        int m_nDefaultTextureIndexLamp ;
592        int m_nDefaultTextureIndexLamp2Pass ;
593        int m_nDefaultTextureIndexGlowLamp ;
594        int m_nDefaultTextureIndexGlowLight ;
595        int m_nDefaultTextureIndexSpotlight ;
596
597        void GetTexLampTextureNumbers() ;
598        int m_nBZN_LightNode0 ;
599        int m_nBZN_LightNode1 ;
600        int m_nBZN_LightNode2 ;
601        int m_nBZN_LightNode3 ;
602
603        int m_nGroup ;
604
605        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
606        //
607        // Much easier to keep track of how zones/subzones/portals/lights connect to each other using hardwired arrays
608        // than dynamically allocated memory, even if it does waste a little space and impose some design limits.
609        // It's fast, easy to manage, and the total memory used is reasonably small. 
610        // The design limits are generous enough that it's unlikely maps will get anywhere near hitting them.
611        //
612        // Memory Footprints:
613        //
614        // m_nZone:                                                                                      4096 * (16+1) * sizeof(unsigned short) =         139,264
615        // m_ZoneBoundary                                                                4096 *                                  sizeof(minmax_t)24                     =          98,304
616        // m_nZoneTouchesPortal                                  4096 * (64+1) * sizeof(unsigned short) =         532,480
617        // m_nPortalTouchesZone                                 32768 * ( 8+1) * sizeof(unsigned short) =         589,824
618        //
619        // m_nZoneContainsLightCentre            4096 * (64+1) * sizeof(unsigned short) =         532,480
620        // m_nLightTouchesZone                                  32768 * ( 8+1) * sizeof(unsigned short) =         589,824
621        // m_nZoneTouchesSubLight                                4096 * (64+1) * sizeof(unsigned short) =         532,480
622        //
623        // m_nMultiZoneLight                                            32768 *                                  sizeof(unsigned short) =                65,536
624        // m_SubLight                                                                           32768 * 8                        * sizeof(sublight_t)28         =       6,815,744
625        // m_nZoneTouchesZone                                            4096 * (64+1) * sizeof(unsigned short) =         532,480
626        //
627        //                                                                                                                                                                                                                                                              TOTAL = 10,428,416 (9.9 meg)
628
629        unsigned short m_nZone[MAX_ZONE][MAX_SUBZONEPERZONE+1] ;                                                                        // last index is used as a counter, INDEX_SUBZONECOUNT
630        minmax_t m_ZoneBoundary[MAX_ZONE] ; // min and max of a zone.  Since zones might not be square, NEVER use this as the real zone boundary, work it out using the subzones instead.  This is just for cutting up lights.
631       
632        unsigned short m_nZoneTouchesPortal[MAX_ZONE][MAX_PORTALPERZONE+1] ;                    // last index is used as a counter, INDEX_PORTALCOUNT
633        unsigned short m_nPortalTouchesZone[MAX_PORTAL][MAX_ZONEPERPORTAL+1] ;          // last index is used as a counter, INDEX_PORTALZONECOUNT
634       
635        // PortalTouchesLight is true if the light AABB touches the portal.
636        unsigned short m_nPortalTouchesLight[MAX_PORTAL][MAX_LIGHTPERPORTAL+1] ;        // last index is used as a counter, INDEX_PORTALLIGHTCOUNT
637
638        unsigned short m_nZoneContainsLightCentre[MAX_ZONE][MAX_LIGHTPERZONE+1] ;                               // last index is used as a counter, INDEX_LIGHTCOUNT
639        unsigned short m_nLightTouchesZone[MAX_LIGHT][MAX_ZONEPERLIGHT+1] ;                             // last index is used as a counter, INDEX_LIGHTZONECOUNT
640        unsigned short m_nZoneTouchesSubLight[MAX_ZONE][MAX_LIGHTPERZONE+1] ;                           // last index is used as a counter, INDEX_LIGHTCOUNT
641
642        unsigned short m_nZoneTouchesZone[MAX_ZONE][MAX_ZONEPERZONE+1] ;                                // last index is used as a counter, INDEX_ZONEPERZONECOUNT
643
644        // list of lights that touche more than one zone.  These require more complex visibility checks
645        unsigned short m_nMultiZoneLight[MAX_LIGHT] ; 
646        int m_nMaxMultiZoneLight ;
647       
648        sublight_t m_SubLight[MAX_SUBLIGHT] ;
649        int m_nSubLightMax ;
650         
651
652        //
653        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
654
655
656        int m_nMaxZone ;
657
658        int ConvertFacesToTriangles(void) ;
659        int ConvertPatchesToTriangles(void) ;
660        int ConvertTexLampsToLampTriangles(void) ;
661        int ConvertLampsToTriangles(void) ;
662        int ConvertLampsToGlowTriangles(void) ;
663        int ConvertLightsToGlowTriangles(void) ;
664
665
666        void SetVertex(Q3BspVertex *pVert, float flXPos, float flYPos, float flZPos) ;
667        bool VectorsAreEqual(Q3BspVertex* pVecA, Q3BspVertex* pVecB) ;
668        Q3BspVertex NormalizedCrossProduct(Q3BspVertex VertA, Q3BspVertex VertB, Q3BspVertex VertC) ;
669        float VertexDistance(Q3BspVertex* VertA, Q3BspVertex* VertB) ;
670        void VertexScale(Q3BspVertex* pVert, float flScale) ;
671        Q3BspVertex GetNormalised(Q3BspVertex* pVector) ;
672        Q3BspVertex VectorAdd(Q3BspVertex* pVecA, Q3BspVertex* pVecB) ;
673        Q3BspVertex VectorSubtract(Q3BspVertex* pVecA, Q3BspVertex* pVecB) ;
674        Q3BspVertex VectorMultiply(Q3BspVertex* pVecA, Q3BspVertex* pVecB) ;
675
676        void SetupZones(void) ;
677        int GetNextSubZone(float *flPoint, int nStart, int nMax) ;
678
679        bool PointInSubZone(float *flPoint, int nSubZone) ;
680        bool PointInZone(float *flPos, int nZone) ;
681
682        bool AABBTouchesSubZone(float *flPointMin, float *flPointMax, int nSubZone) ;
683        bool AABBTouchesZone(float *flPosMin, float *flPosMax, int nZone) ;
684
685        int AssignTrianglesToZones(void) ;
686        int FindTriangleZone(int nTriangle) ;
687        int SetupTriangleZone(int nTriangle) ;
688        int SplitTriangle(int nTriangle, int nAxis, float flCutPos) ; // only does axial cuts.  returns false on failure, probably due to lack of memory.
689        void CreateTweenVert(Q3BspVertex* pVertA, Q3BspVertex* pVertB, float flPercent0, Q3BspVertex* pVertAB) ;
690       
691
692        int SortTrianglesIntoGroups(void) ;
693        static int compareGroups( const void *arg1, const void *arg2 ) ;
694
695        int SortTrianglesIntoBatches(void) ;
696        static int compareTriangles( const void *arg1, const void *arg2 ) ;
697
698        int SetupTransTextures(void) ;
699        int* m_pTransTexture ;
700
701
702        int AssignPortalsToZones(void) ;
703        int AssignLightsToPortals(void) ;
704        int AssignLightsToZones(void) ;
705        int AssignZonesToZones(void) ;
706
707};
708
709#endif /* _Q3MAP_H */
Note: See TracBrowser for help on using the repository browser.