]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/compilers/aas/AASFile.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / tools / compilers / aas / AASFile.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #ifndef __AASFILE_H__
30 #define __AASFILE_H__
31
32 /*
33 ===============================================================================
34
35         AAS File
36
37 ===============================================================================
38 */
39
40 #define AAS_FILEID                                      "DewmAAS"
41 #define AAS_FILEVERSION                         "1.07"
42
43 // travel flags
44 #define TFL_INVALID                                     BIT(0)          // not valid
45 #define TFL_WALK                                        BIT(1)          // walking
46 #define TFL_CROUCH                                      BIT(2)          // crouching
47 #define TFL_WALKOFFLEDGE                        BIT(3)          // walking of a ledge
48 #define TFL_BARRIERJUMP                         BIT(4)          // jumping onto a barrier
49 #define TFL_JUMP                                        BIT(5)          // jumping
50 #define TFL_LADDER                                      BIT(6)          // climbing a ladder
51 #define TFL_SWIM                                        BIT(7)          // swimming
52 #define TFL_WATERJUMP                           BIT(8)          // jump out of the water
53 #define TFL_TELEPORT                            BIT(9)          // teleportation
54 #define TFL_ELEVATOR                            BIT(10)         // travel by elevator
55 #define TFL_FLY                                         BIT(11)         // fly
56 #define TFL_SPECIAL                                     BIT(12)         // special
57 #define TFL_WATER                                       BIT(21)         // travel through water
58 #define TFL_AIR                                         BIT(22)         // travel through air
59
60 // face flags
61 #define FACE_SOLID                                      BIT(0)          // solid at the other side
62 #define FACE_LADDER                                     BIT(1)          // ladder surface
63 #define FACE_FLOOR                                      BIT(2)          // standing on floor when on this face
64 #define FACE_LIQUID                                     BIT(3)          // face seperating two areas with liquid
65 #define FACE_LIQUIDSURFACE                      BIT(4)          // face seperating liquid and air
66
67 // area flags
68 #define AREA_FLOOR                                      BIT(0)          // AI can stand on the floor in this area
69 #define AREA_GAP                                        BIT(1)          // area has a gap
70 #define AREA_LEDGE                                      BIT(2)          // if entered the AI bbox partly floats above a ledge
71 #define AREA_LADDER                                     BIT(3)          // area contains one or more ladder faces
72 #define AREA_LIQUID                                     BIT(4)          // area contains a liquid
73 #define AREA_CROUCH                                     BIT(5)          // AI cannot walk but can only crouch in this area
74 #define AREA_REACHABLE_WALK                     BIT(6)          // area is reachable by walking or swimming
75 #define AREA_REACHABLE_FLY                      BIT(7)          // area is reachable by flying
76
77 // area contents flags
78 #define AREACONTENTS_SOLID                      BIT(0)          // solid, not a valid area
79 #define AREACONTENTS_WATER                      BIT(1)          // area contains water
80 #define AREACONTENTS_CLUSTERPORTAL      BIT(2)          // area is a cluster portal
81 #define AREACONTENTS_OBSTACLE           BIT(3)          // area contains (part of) a dynamic obstacle
82 #define AREACONTENTS_TELEPORTER         BIT(4)          // area contains (part of) a teleporter trigger
83
84 // bits for different bboxes
85 #define AREACONTENTS_BBOX_BIT           24
86
87 #define MAX_REACH_PER_AREA                      256
88 #define MAX_AAS_TREE_DEPTH                      128
89
90 #define MAX_AAS_BOUNDING_BOXES          4
91
92 // reachability to another area
93 class idReachability {
94 public:
95         int                                                     travelType;                     // type of travel required to get to the area
96         short                                           toAreaNum;                      // number of the reachable area
97         short                                           fromAreaNum;            // number of area the reachability starts
98         idVec3                                          start;                          // start point of inter area movement
99         idVec3                                          end;                            // end point of inter area movement
100         int                                                     edgeNum;                        // edge crossed by this reachability
101         unsigned short                          travelTime;                     // travel time of the inter area movement
102         byte                                            number;                         // reachability number within the fromAreaNum (must be < 256)
103         byte                                            disableCount;           // number of times this reachability has been disabled
104         idReachability *                        next;                           // next reachability in list
105         idReachability *                        rev_next;                       // next reachability in reversed list
106         unsigned short *                        areaTravelTimes;        // travel times within the fromAreaNum from reachabilities that lead towards this area
107 public:
108         void                                            CopyBase( idReachability &reach );
109 };
110
111 class idReachability_Walk : public idReachability {
112 };
113
114 class idReachability_BarrierJump : public idReachability {
115 };
116
117 class idReachability_WaterJump : public idReachability {
118 };
119
120 class idReachability_WalkOffLedge : public idReachability {
121 };
122
123 class idReachability_Swim : public idReachability {
124 };
125
126 class idReachability_Fly : public idReachability {
127 };
128
129 class idReachability_Special : public idReachability {
130 public:
131         idDict                                          dict;
132 };
133
134 // index
135 typedef int aasIndex_t;
136
137 // vertex
138 typedef idVec3 aasVertex_t;
139
140 // edge
141 typedef struct aasEdge_s {
142         int                                                     vertexNum[2];           // numbers of the vertexes of this edge
143 } aasEdge_t;
144
145 // area boundary face
146 typedef struct aasFace_s {
147         unsigned short                          planeNum;                       // number of the plane this face is on
148         unsigned short                          flags;                          // face flags
149         int                                                     numEdges;                       // number of edges in the boundary of the face
150         int                                                     firstEdge;                      // first edge in the edge index
151         short                                           areas[2];                       // area at the front and back of this face
152 } aasFace_t;
153
154 // area with a boundary of faces
155 typedef struct aasArea_s {
156         int                                                     numFaces;                       // number of faces used for the boundary of the area
157         int                                                     firstFace;                      // first face in the face index used for the boundary of the area
158         idBounds                                        bounds;                         // bounds of the area
159         idVec3                                          center;                         // center of the area an AI can move towards
160         unsigned short                          flags;                          // several area flags
161         unsigned short                          contents;                       // contents of the area
162         short                                           cluster;                        // cluster the area belongs to, if negative it's a portal
163         short                                           clusterAreaNum;         // number of the area in the cluster
164         int                                                     travelFlags;            // travel flags for traveling through this area
165         idReachability *                        reach;                          // reachabilities that start from this area
166         idReachability *                        rev_reach;                      // reachabilities that lead to this area
167 } aasArea_t;
168
169 // nodes of the bsp tree
170 typedef struct aasNode_s {
171         unsigned short                          planeNum;                       // number of the plane that splits the subspace at this node
172         int                                                     children[2];            // child nodes, zero is solid, negative is -(area number)
173 } aasNode_t;
174
175 // cluster portal
176 typedef struct aasPortal_s {
177         short                                           areaNum;                        // number of the area that is the actual portal
178         short                                           clusters[2];            // number of cluster at the front and back of the portal
179         short                                           clusterAreaNum[2];      // number of this portal area in the front and back cluster
180         unsigned short                          maxAreaTravelTime;      // maximum travel time through the portal area
181 } aasPortal_t;
182
183 // cluster
184 typedef struct aasCluster_s {
185         int                                                     numAreas;                       // number of areas in the cluster
186         int                                                     numReachableAreas;      // number of areas with reachabilities
187         int                                                     numPortals;                     // number of cluster portals
188         int                                                     firstPortal;            // first cluster portal in the index
189 } aasCluster_t;
190
191 // trace through the world
192 typedef struct aasTrace_s {
193                                                                 // parameters
194         int                                                     flags;                          // areas with these flags block the trace
195         int                                                     travelFlags;            // areas with these travel flags block the trace
196         int                                                     maxAreas;                       // size of the 'areas' array
197         int                                                     getOutOfSolid;          // trace out of solid if the trace starts in solid
198                                                                 // output
199         float                                           fraction;                       // fraction of trace completed
200         idVec3                                          endpos;                         // end position of trace
201         int                                                     planeNum;                       // plane hit
202         int                                                     lastAreaNum;            // number of last area the trace went through
203         int                                                     blockingAreaNum;        // area that could not be entered
204         int                                                     numAreas;                       // number of areas the trace went through
205         int *                                           areas;                          // array to store areas the trace went through
206         idVec3 *                                        points;                         // points where the trace entered each new area
207                                                                 aasTrace_s( void ) { areas = NULL; points = NULL; getOutOfSolid = false; flags = travelFlags = maxAreas = 0; }
208 } aasTrace_t;
209
210 // settings
211 class idAASSettings {
212 public:
213                                                                 // collision settings
214         int                                                     numBoundingBoxes;
215         idBounds                                        boundingBoxes[MAX_AAS_BOUNDING_BOXES];
216         bool                                            usePatches;
217         bool                                            writeBrushMap;
218         bool                                            playerFlood;
219         bool                                            noOptimize;
220         bool                                            allowSwimReachabilities;
221         bool                                            allowFlyReachabilities;
222         idStr                                           fileExtension;
223                                                                 // physics settings
224         idVec3                                          gravity;
225         idVec3                                          gravityDir;
226         idVec3                                          invGravityDir;
227         float                                           gravityValue;
228         float                                           maxStepHeight;
229         float                                           maxBarrierHeight;
230         float                                           maxWaterJumpHeight;
231         float                                           maxFallHeight;
232         float                                           minFloorCos;
233                                                                 // fixed travel times
234         int                                                     tt_barrierJump;
235         int                                                     tt_startCrouching;
236         int                                                     tt_waterJump;
237         int                                                     tt_startWalkOffLedge;
238
239 public:
240                                                                 idAASSettings( void );
241
242         bool                                            FromFile( const idStr &fileName );
243         bool                                            FromParser( idLexer &src );
244         bool                                            FromDict( const char *name, const idDict *dict );
245         bool                                            WriteToFile( idFile *fp ) const;
246         bool                                            ValidForBounds( const idBounds &bounds ) const;
247         bool                                            ValidEntity( const char *classname ) const;
248
249 private:
250         bool                                            ParseBool( idLexer &src, bool &b );
251         bool                                            ParseInt( idLexer &src, int &i );
252         bool                                            ParseFloat( idLexer &src, float &f );
253         bool                                            ParseVector( idLexer &src, idVec3 &vec );
254         bool                                            ParseBBoxes( idLexer &src );
255 };
256
257
258 /*
259
260 -       when a node child is a solid leaf the node child number is zero
261 -       two adjacent areas (sharing a plane at opposite sides) share a face
262         this face is a portal between the areas
263 -       when an area uses a face from the faceindex with a positive index
264         then the face plane normal points into the area
265 -       the face edges are stored counter clockwise using the edgeindex
266 -       two adjacent convex areas (sharing a face) only share One face
267         this is a simple result of the areas being convex
268 -       the areas can't have a mixture of ground and gap faces
269         other mixtures of faces in one area are allowed
270 -       areas with the AREACONTENTS_CLUSTERPORTAL in the settings have
271         the cluster number set to the negative portal number
272 -       edge zero is a dummy
273 -       face zero is a dummy
274 -       area zero is a dummy
275 -       node zero is a dummy
276 -       portal zero is a dummy
277 -       cluster zero is a dummy
278
279 */
280
281
282 class idAASFile {
283 public:
284         virtual                                         ~idAASFile( void ) {}
285
286         const char *                            GetName( void ) const { return name.c_str(); }
287         unsigned int                            GetCRC( void ) const { return crc; }
288
289         int                                                     GetNumPlanes( void ) const { return planeList.Num(); }
290         const idPlane &                         GetPlane( int index ) const { return planeList[index]; }
291         int                                                     GetNumVertices( void ) const { return vertices.Num(); }
292         const aasVertex_t &                     GetVertex( int index ) const { return vertices[index]; }
293         int                                                     GetNumEdges( void ) const { return edges.Num(); }
294         const aasEdge_t &                       GetEdge( int index ) const { return edges[index]; }
295         int                                                     GetNumEdgeIndexes( void ) const { return edgeIndex.Num(); }
296         const aasIndex_t &                      GetEdgeIndex( int index ) const { return edgeIndex[index]; }
297         int                                                     GetNumFaces( void ) const { return faces.Num(); }
298         const aasFace_t &                       GetFace( int index ) const { return faces[index]; }
299         int                                                     GetNumFaceIndexes( void ) const { return faceIndex.Num(); }
300         const aasIndex_t &                      GetFaceIndex( int index ) const { return faceIndex[index]; }
301         int                                                     GetNumAreas( void ) const { return areas.Num(); }
302         const aasArea_t &                       GetArea( int index ) { return areas[index]; }
303         int                                                     GetNumNodes( void ) const { return nodes.Num(); }
304         const aasNode_t &                       GetNode( int index ) const { return nodes[index]; }
305         int                                                     GetNumPortals( void ) const { return portals.Num(); }
306         const aasPortal_t &                     GetPortal( int index ) { return portals[index]; }
307         int                                                     GetNumPortalIndexes( void ) const { return portalIndex.Num(); }
308         const aasIndex_t &                      GetPortalIndex( int index ) const { return portalIndex[index]; }
309         int                                                     GetNumClusters( void ) const { return clusters.Num(); }
310         const aasCluster_t &            GetCluster( int index ) const { return clusters[index]; }
311
312         const idAASSettings &           GetSettings( void ) const { return settings; }
313
314         void                                            SetPortalMaxTravelTime( int index, int time ) { portals[index].maxAreaTravelTime = time; }
315         void                                            SetAreaTravelFlag( int index, int flag ) { areas[index].travelFlags |= flag; }
316         void                                            RemoveAreaTravelFlag( int index, int flag ) { areas[index].travelFlags &= ~flag; }
317
318         virtual idVec3                          EdgeCenter( int edgeNum ) const = 0;
319         virtual idVec3                          FaceCenter( int faceNum ) const = 0;
320         virtual idVec3                          AreaCenter( int areaNum ) const = 0;
321
322         virtual idBounds                        EdgeBounds( int edgeNum ) const = 0;
323         virtual idBounds                        FaceBounds( int faceNum ) const = 0;
324         virtual idBounds                        AreaBounds( int areaNum ) const = 0;
325
326         virtual int                                     PointAreaNum( const idVec3 &origin ) const = 0;
327         virtual int                                     PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags, const int excludeTravelFlags ) const = 0;
328         virtual int                                     BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags, const int excludeTravelFlags ) const = 0;
329         virtual void                            PushPointIntoAreaNum( int areaNum, idVec3 &point ) const = 0;
330         virtual bool                            Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const = 0;
331         virtual void                            PrintInfo( void ) const = 0;
332
333 protected:
334         idStr                                           name;
335         unsigned int                            crc;
336
337         idPlaneSet                                      planeList;
338         idList<aasVertex_t>                     vertices;
339         idList<aasEdge_t>                       edges;
340         idList<aasIndex_t>                      edgeIndex;
341         idList<aasFace_t>                       faces;
342         idList<aasIndex_t>                      faceIndex;
343         idList<aasArea_t>                       areas;
344         idList<aasNode_t>                       nodes;
345         idList<aasPortal_t>                     portals;
346         idList<aasIndex_t>                      portalIndex;
347         idList<aasCluster_t>            clusters;
348         idAASSettings                           settings;
349 };
350
351 #endif /* !__AASFILE_H__ */