]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/renderer/RenderWorld_local.h
Use the same OpenAL headers on all platforms.
[icculus/iodoom3.git] / neo / renderer / RenderWorld_local.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 __RENDERWORLDLOCAL_H__
30 #define __RENDERWORLDLOCAL_H__
31
32 // assume any lightDef or entityDef index above this is an internal error
33 const int LUDICROUS_INDEX       = 10000;
34
35
36 typedef struct portal_s {
37         int                                             intoArea;               // area this portal leads to
38         idWinding *                             w;                              // winding points have counter clockwise ordering seen this area
39         idPlane                                 plane;                  // view must be on the positive side of the plane to cross
40         struct portal_s *               next;                   // next portal of the area
41         struct doublePortal_s * doublePortal;
42 } portal_t;
43
44
45 typedef struct doublePortal_s {
46         struct portal_s *               portals[2];
47         int                                             blockingBits;   // PS_BLOCK_VIEW, PS_BLOCK_AIR, etc, set by doors that shut them off
48
49         // A portal will be considered closed if it is past the
50         // fog-out point in a fog volume.  We only support a single
51         // fog volume over each portal.
52         idRenderLightLocal *            fogLight;
53         struct doublePortal_s * nextFoggedPortal;
54 } doublePortal_t;
55
56
57 typedef struct portalArea_s {
58         int                             areaNum;
59         int                             connectedAreaNum[NUM_PORTAL_ATTRIBUTES];        // if two areas have matching connectedAreaNum, they are
60                                                                         // not separated by a portal with the apropriate PS_BLOCK_* blockingBits
61         int                             viewCount;              // set by R_FindViewLightsAndEntities
62         portal_t *              portals;                // never changes after load
63         areaReference_t entityRefs;             // head/tail of doubly linked list, may change
64         areaReference_t lightRefs;              // head/tail of doubly linked list, may change
65 } portalArea_t;
66
67
68 static const int        CHILDREN_HAVE_MULTIPLE_AREAS = -2;
69 static const int        AREANUM_SOLID = -1;
70 typedef struct {
71         idPlane                 plane;
72         int                             children[2];            // negative numbers are (-1 - areaNumber), 0 = solid
73         int                             commonChildrenArea;     // if all children are either solid or a single area,
74                                                                                 // this is the area number, else CHILDREN_HAVE_MULTIPLE_AREAS
75 } areaNode_t;
76
77
78 class idRenderWorldLocal : public idRenderWorld {
79 public:
80                                                         idRenderWorldLocal();
81         virtual                                 ~idRenderWorldLocal();
82
83         virtual qhandle_t               AddEntityDef( const renderEntity_t *re );
84         virtual void                    UpdateEntityDef( qhandle_t entityHandle, const renderEntity_t *re );
85         virtual void                    FreeEntityDef( qhandle_t entityHandle );
86         virtual const renderEntity_t *GetRenderEntity( qhandle_t entityHandle ) const;
87
88         virtual qhandle_t               AddLightDef( const renderLight_t *rlight );
89         virtual void                    UpdateLightDef( qhandle_t lightHandle, const renderLight_t *rlight );
90         virtual void                    FreeLightDef( qhandle_t lightHandle );
91         virtual const renderLight_t *GetRenderLight( qhandle_t lightHandle ) const;
92
93         virtual bool                    CheckAreaForPortalSky( int areaNum );
94
95         virtual void                    GenerateAllInteractions();
96         virtual void                    RegenerateWorld();
97
98         virtual void                    ProjectDecalOntoWorld( const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
99         virtual void                    ProjectDecal( qhandle_t entityHandle, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
100         virtual void                    ProjectOverlay( qhandle_t entityHandle, const idPlane localTextureAxis[2], const idMaterial *material );
101         virtual void                    RemoveDecals( qhandle_t entityHandle );
102
103         virtual void                    SetRenderView( const renderView_t *renderView );
104         virtual void                    RenderScene( const renderView_t *renderView );
105
106         virtual int                             NumAreas( void ) const;
107         virtual int                             PointInArea( const idVec3 &point ) const;
108         virtual int                             BoundsInAreas( const idBounds &bounds, int *areas, int maxAreas ) const;
109         virtual int                             NumPortalsInArea( int areaNum );
110         virtual exitPortal_t    GetPortal( int areaNum, int portalNum );
111
112         virtual guiPoint_t              GuiTrace( qhandle_t entityHandle, const idVec3 start, const idVec3 end ) const;
113         virtual bool                    ModelTrace( modelTrace_t &trace, qhandle_t entityHandle, const idVec3 &start, const idVec3 &end, const float radius ) const;
114         virtual bool                    Trace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end, const float radius, bool skipDynamic = true, bool skipPlayer = false ) const;
115         virtual bool                    FastWorldTrace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end ) const;
116
117         virtual void                    DebugClearLines( int time );
118         virtual void                    DebugLine( const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime = 0, const bool depthTest = false );
119         virtual void                    DebugArrow( const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime = 0 );
120         virtual void                    DebugWinding( const idVec4 &color, const idWinding &w, const idVec3 &origin, const idMat3 &axis, const int lifetime = 0, const bool depthTest = false );
121         virtual void                    DebugCircle( const idVec4 &color, const idVec3 &origin, const idVec3 &dir, const float radius, const int numSteps, const int lifetime = 0, const bool depthTest = false );
122         virtual void                    DebugSphere( const idVec4 &color, const idSphere &sphere, const int lifetime = 0, bool depthTest = false );
123         virtual void                    DebugBounds( const idVec4 &color, const idBounds &bounds, const idVec3 &org = vec3_origin, const int lifetime = 0 );
124         virtual void                    DebugBox( const idVec4 &color, const idBox &box, const int lifetime = 0 );
125         virtual void                    DebugFrustum( const idVec4 &color, const idFrustum &frustum, const bool showFromOrigin = false, const int lifetime = 0 );
126         virtual void                    DebugCone( const idVec4 &color, const idVec3 &apex, const idVec3 &dir, float radius1, float radius2, const int lifetime = 0 );
127         virtual void                    DebugScreenRect( const idVec4 &color, const idScreenRect &rect, const viewDef_t *viewDef, const int lifetime = 0 );
128         virtual void                    DebugAxis( const idVec3 &origin, const idMat3 &axis );
129
130         virtual void                    DebugClearPolygons( int time );
131         virtual void                    DebugPolygon( const idVec4 &color, const idWinding &winding, const int lifeTime = 0, const bool depthTest = false );
132
133         virtual void                    DrawText( const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align = 1, const int lifetime = 0, bool depthTest = false );
134
135         //-----------------------
136
137         idStr                                   mapName;                                // ie: maps/tim_dm2.proc, written to demoFile
138         ID_TIME_T                                       mapTimeStamp;                   // for fast reloads of the same level
139
140         areaNode_t *                    areaNodes;
141         int                                             numAreaNodes;
142
143         portalArea_t *                  portalAreas;
144         int                                             numPortalAreas;
145         int                                             connectedAreaNum;               // incremented every time a door portal state changes
146
147         idScreenRect *                  areaScreenRect;
148
149         doublePortal_t *                doublePortals;
150         int                                             numInterAreaPortals;
151
152         idList<idRenderModel *> localModels;
153
154         idList<idRenderEntityLocal*>    entityDefs;
155         idList<idRenderLightLocal*>             lightDefs;
156
157         idBlockAlloc<areaReference_t, 1024> areaReferenceAllocator;
158         idBlockAlloc<idInteraction, 256>        interactionAllocator;
159         idBlockAlloc<areaNumRef_t, 1024>        areaNumRefAllocator;
160
161         // all light / entity interactions are referenced here for fast lookup without
162         // having to crawl the doubly linked lists.  EnntityDefs are sequential for better
163         // cache access, because the table is accessed by light in idRenderWorldLocal::CreateLightDefInteractions()
164         // Growing this table is time consuming, so we add a pad value to the number
165         // of entityDefs and lightDefs
166         idInteraction **                interactionTable;
167         int                                             interactionTableWidth;          // entityDefs
168         int                                             interactionTableHeight;         // lightDefs
169
170
171         bool                                    generateAllInteractionsCalled;
172
173         //-----------------------
174         // RenderWorld_load.cpp
175
176         idRenderModel *                 ParseModel( idLexer *src );
177         idRenderModel *                 ParseShadowModel( idLexer *src );
178         void                                    SetupAreaRefs();
179         void                                    ParseInterAreaPortals( idLexer *src );
180         void                                    ParseNodes( idLexer *src );
181         int                                             CommonChildrenArea_r( areaNode_t *node );
182         void                                    FreeWorld();
183         void                                    ClearWorld();
184         void                                    FreeDefs();
185         void                                    TouchWorldModels( void );
186         void                                    AddWorldModelEntities();
187         void                                    ClearPortalStates();
188         virtual bool                    InitFromMap( const char *mapName );
189
190         //--------------------------
191         // RenderWorld_portals.cpp
192
193         idScreenRect                    ScreenRectFromWinding( const idWinding *w, viewEntity_t *space );
194         bool                                    PortalIsFoggedOut( const portal_t *p );
195         void                                    FloodViewThroughArea_r( const idVec3 origin, int areaNum, const struct portalStack_s *ps );
196         void                                    FlowViewThroughPortals( const idVec3 origin, int numPlanes, const idPlane *planes );
197         void                                    FloodLightThroughArea_r( idRenderLightLocal *light, int areaNum, const struct portalStack_s *ps );
198         void                                    FlowLightThroughPortals( idRenderLightLocal *light );
199         areaNumRef_t *                  FloodFrustumAreas_r( const idFrustum &frustum, const int areaNum, const idBounds &bounds, areaNumRef_t *areas );
200         areaNumRef_t *                  FloodFrustumAreas( const idFrustum &frustum, areaNumRef_t *areas );
201         bool                                    CullEntityByPortals( const idRenderEntityLocal *entity, const struct portalStack_s *ps );
202         void                                    AddAreaEntityRefs( int areaNum, const struct portalStack_s *ps );
203         bool                                    CullLightByPortals( const idRenderLightLocal *light, const struct portalStack_s *ps );
204         void                                    AddAreaLightRefs( int areaNum, const struct portalStack_s *ps );
205         void                                    AddAreaRefs( int areaNum, const struct portalStack_s *ps );
206         void                                    BuildConnectedAreas_r( int areaNum );
207         void                                    BuildConnectedAreas( void );
208         void                                    FindViewLightsAndEntities( void );
209
210         int                                             NumPortals( void ) const;
211         qhandle_t                               FindPortal( const idBounds &b ) const;
212         void                                    SetPortalState( qhandle_t portal, int blockingBits );
213         int                                             GetPortalState( qhandle_t portal );
214         bool                                    AreasAreConnected( int areaNum1, int areaNum2, portalConnection_t connection );
215         void                                    FloodConnectedAreas( portalArea_t *area, int portalAttributeIndex );
216         idScreenRect &                  GetAreaScreenRect( int areaNum ) const { return areaScreenRect[areaNum]; }
217         void                                    ShowPortals();
218
219         //--------------------------
220         // RenderWorld_demo.cpp
221
222         void                                    StartWritingDemo( idDemoFile *demo );
223         void                                    StopWritingDemo();
224         bool                                    ProcessDemoCommand( idDemoFile *readDemo, renderView_t *demoRenderView, int *demoTimeOffset );
225
226         void                                    WriteLoadMap();
227         void                                    WriteRenderView( const renderView_t *renderView );
228         void                                    WriteVisibleDefs( const viewDef_t *viewDef );
229         void                                    WriteFreeLight( qhandle_t handle );
230         void                                    WriteFreeEntity( qhandle_t handle );
231         void                                    WriteRenderLight( qhandle_t handle, const renderLight_t *light );
232         void                                    WriteRenderEntity( qhandle_t handle, const renderEntity_t *ent );
233         void                                    ReadRenderEntity();
234         void                                    ReadRenderLight();
235         
236
237         //--------------------------
238         // RenderWorld.cpp
239
240         void                                    ResizeInteractionTable();
241
242         void                                    AddEntityRefToArea( idRenderEntityLocal *def, portalArea_t *area );
243         void                                    AddLightRefToArea( idRenderLightLocal *light, portalArea_t *area );
244
245         void                                    RecurseProcBSP_r( modelTrace_t *results, int parentNodeNum, int nodeNum, float p1f, float p2f, const idVec3 &p1, const idVec3 &p2 ) const;
246
247         void                                    BoundsInAreas_r( int nodeNum, const idBounds &bounds, int *areas, int *numAreas, int maxAreas ) const;
248
249         float                                   DrawTextLength( const char *text, float scale, int len = 0 );
250
251         void                                    FreeInteractions();
252
253         void                                    PushVolumeIntoTree_r( idRenderEntityLocal *def, idRenderLightLocal *light, const idSphere *sphere, int numPoints, const idVec3 (*points), int nodeNum );
254
255         void                                    PushVolumeIntoTree( idRenderEntityLocal *def, idRenderLightLocal *light, int numPoints, const idVec3 (*points) );
256
257         //-------------------------------
258         // tr_light.c
259         void                                    CreateLightDefInteractions( idRenderLightLocal *ldef );
260 };
261
262 #endif /* !__RENDERWORLDLOCAL_H__ */