summaryrefslogtreecommitdiffstats
path: root/sdk/rwsdk/include/d3d8/rppvs.h
blob: 29fc234331dcf0e05c0d08e3ac152e8ae41a25f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*
 * Potentially Visible Set plug-in
 */

/**********************************************************************
 *
 * file :     rppvs.h
 *
 * abstract : handle culling of worldsectors in RenderWare
 *
 **********************************************************************
 *
 * This file is a product of Criterion Software Ltd.
 *
 * This file is provided as is with no warranties of any kind and is
 * provided without any obligation on Criterion Software Ltd. or
 * Canon Inc. to assist in its use or modification.
 *
 * Criterion Software Ltd. will not, under any
 * circumstances, be liable for any lost revenue or other damages arising
 * from the use of this file.
 *
 * Copyright (c) 2001 Criterion Software Ltd.
 * All Rights Reserved.
 *
 * RenderWare is a trademark of Canon Inc.
 *
 ************************************************************************/

#ifndef _RPPVS_H
#define _RPPVS_H

/**
 * \defgroup rppvs RpPVS
 * \ingroup rpplugin
 *
 * Geometric Potentially Visible Set Plugin for RenderWare Graphics.
 */

/****************************************************************************
 Defines
 */

typedef RwUInt8     RpPVSVisMap;

#define PVSFROMWORLDSECTOR(sector) \
    ((RpPVS *)(((char *)(sector))+rpPVSGlobals.sectorOffset))

#define WORLDSECTORFROMPVS(pvs)    \
    ((RpWorldSector *)(((char *)(pvs))-rpPVSGlobals.sectorOffset))

#define PVSFROMCONSTWORLDSECTOR(sector) \
    ((const RpPVS *)(((const char *)(sector))+rpPVSGlobals.sectorOffset))


#define PVSCACHEFROMWORLD(world) \
    ((RpPVSCache *)(((char *)(world))+rpPVSGlobals.worldOffset))
#define PVSCACHEFROMCONSTWORLD(world) \
    ((const RpPVSCache *)(((const char *)(world))+rpPVSGlobals.worldOffset))

#define PVSVISMAPSETSECTOR(_vismap, _id)        \
    (_vismap)[(_id) >> 3] |= (1 << ((_id) & 7))

#define PVSVISMAPUNSETSECTOR(_vismap, _id)        \
    (_vismap)[(_id) >> 3] ^= (1 << ((_id) & 7))

#define PVSVISMAPGETSECTOR(_vismap, _id)        \
    ((_vismap)[(_id) >> 3] & (1 << ((_id) & 7)))

#define PVSVISMAPLENGTH(_vismaplength, _nosectors) \
    (_vismaplength) = ((_nosectors + 7) >> 3)


/* Progress callback message types */
#define rpPVSPROGRESSSTART              20
#define rpPVSPROGRESSUPDATE             12
#define rpPVSPROGRESSEND                22

/**
 * \ingroup rppvs
 * \ref RpPVSProgressCallBack
 * This typedef sets the callback function for sampling within a world sector.
 *
 * \param value     A value between 0.0 and 100.0 to represent the percentage completion.
 * \param msg       The message may take one of the following:
 *
 * \li rpPVSPROGRESSSTART
 * The PVS creation process is about to start.  The argument value is equal to 0.0.
 *
 * \li rpPVSPROGRESSUPDATE
 * The PVS creation process has finished processing a subsection of the world.
 * The argument value is equal to the percentage of the world processed up to this point.
 *
 * \li rpPVSPROGRESSEND
 * The PVS creation process has ended.  All world sectors have been processed.
 * The argument value is equal to 100.0.
 *
 * The progress callback may return FALSE to indicate that the generation of PVS data
 * should terminate. Otherwise, return TRUE to continue.
 *
 * The PVS plugin must be attached before using this function.
 *
 *
 */
typedef             RwBool(*RpPVSProgressCallBack) (RwInt32 msg,
                                                     RwReal value);


/**
 * \ingroup rppvs
 * \ref RpPVSCallBack
 * This typedef sets the callback function for sampling within a world sector.
 *
 * \param worldSector       A pointer to the \ref RpWorldSector being sampled.
 * \param box               The bounding box of the region being sampled.
 * \param pData             A pointer to private data for the sampling function.
 */
typedef RpWorldSector *(*RpPVSCallBack) (RpWorldSector * worldSector,
                                         const RwBBox * box,
                                         void *pData);

#define RpPVSCallback                   RpPVSCallBack

typedef struct _RpPVSCallBack _RpPVSCallBack;
struct _RpPVSCallBack
{
    RpPVSCallBack      callback;
    void               *data;
};

enum _rpPVSPartitionId
{
    rpNAPVSPARTITIONID = 0,
    rpPVSFRONT,
    rpPVSBACK,
    rpPVSSPLIT,
    rpPVSCOPLANAR,
    rpPVSPARTITIONIDFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
};
typedef enum _rpPVSPartitionId _rpPVSPartitionId;

typedef struct _rpPVSPolyList _rpPVSPolyList;
typedef struct _rpPVSPolyList *_rpPVSPolyListPtr;

typedef struct _rpPVSPoly _rpPVSPoly;
typedef struct _rpPVSPoly *_rpPVSPolyPtr;

typedef struct _rpPVSPlaneEq _rpPVSPlaneEq;
struct _rpPVSPlaneEq
{
    RwReal              x;
    RwReal              y;
    RwReal              z;
    RwReal              w;

    RwReal              l;      /* recip of length of the normal */

    _rpPVSPartitionId         lastresult; /* temp: stores result of last polygon wrt this plane */
};

typedef struct
{
    RwInt32 x;
    RwInt32 y;
    RwInt32 z;
}RwV3i;

typedef struct _rpPVSPolyRecord _rpPVSPolyRecord;
struct _rpPVSPolyRecord
{
    RwBool              original; /* True if not a fragment */
    RwReal              priority; /* Used for sorting, lower values higher priority */
    _rpPVSPolyListPtr         parent; /* Unique pointer to original parent */
    _rpPVSPolyPtr             geom;   /* corners of the poly */
    _rpPVSPlaneEq             plane;  /* plane equation of the poly */
    RwInt32             home;   /* world sector id in range 0..numsectors */
    RpWorldSector      *homeaddr; /* world sector pointer */
    RwBool              translucent;

    RwBool              hasbeenclipper; /* Used during WA creation */

    /* used by proximity culling, calculated once */
    RwV3d               centroid;
    RwReal              radius;
    RwV3d               extreme; /* the vertex furthest away from the centroid */

    RwReal              coneRadius; /* Used during clipping only */

};

struct _rpPVSPoly
{
    RwV3d               v;
    _rpPVSPoly               *next;

    RwInt32             pscalar; /* Used during clipping only */
    RwReal              scalar; /* Used during clipping only */
    _rpPVSPlaneEq             shadowPlane; /* Used during clipping only */
};

struct _rpPVSPolyList
{
    _rpPVSPolyRecord          data;
    _rpPVSPolyList           *next;
};

typedef struct RpPVS RpPVS;
struct RpPVS
{
    RwInt32             sectorID;       /* Id of the sector */
    RwInt32             vismaplength;   /* Length of vismap */
    RwInt32             sampleKey;      /* Currently unused, for future use */

    RpPVSVisMap        *vismap;

    _rpPVSPolyListPtr         sectailpoly;    /* Pointer to last polygon in polygons list that is in this sector */

    _rpPVSPartitionId         potential;      /* temp: is sector in out or split from current shadow volume  - for heirarchical clip */
    RwUInt32            numpols;
    RwBBox              sbox;           /* Bounding box of the sector */
    RwBBox              gbox;           /* Bounding box of the geometry of the sector */
    RwReal              diagonal;       /* Diagonal size of bounding box of the sector */
    RwV3d               centre;         /* Centre of the sector */
    RwInt32             axessig[3];     /* sampling significance of the axes of the gbox */
};

typedef struct RpPVSCache RpPVSCache;
struct RpPVSCache
{
    RwBool              processed; /* flag to indicate exisiting PVS data for the world */
    RwBool              formatted; /* flag to indicate exisiting intermediate polygonal data for PVS generation */

    /* stats collection */
    RwInt32             ptotal;
    RwInt32             paccept;

    /* pipeline hooking */
    RwBool              hooked;

    /* used during vismap allocation */
    RwUInt32            nextID;

    RwInt32             viscount;

    /* Used during construction */
    RpPVSProgressCallBack progressCallBack;

    _rpPVSPolyListPtr         polygons; /* A copy of the input data set of all world polygons */

    RpWorldSectorCallBackRender     renderCallBack;
};

typedef struct RpPVSGlobalVars RpPVSGlobalVars;
struct RpPVSGlobalVars
{
    RpWorld            *World;

    RwInt32             worldOffset; /* Offset into global data */
    RwInt32             sectorOffset; /* Offset into global data */

    RwBool              collis; /* Collision detection */
    RwBool              bfc; /* Backface culling */

    RwInt32             NumWorldSectors;

    RwInt32             progress_count;
    RwReal              diagonal;

    RwReal              gran;

    RwInt32             InSector; /* Current sector id */
    RwV3d               ViewPos; /* Current view pos */
    RpPVS             *CurrPVS; /* Current PVS sector */
};


/****************************************************************************
 Function prototypes
 */

#ifdef    __cplusplus
extern              "C"
{
#endif                          /* __cplusplus */

extern RpPVSGlobalVars    rpPVSGlobals;

extern RpWorld *
RpPVSSetProgressCallBack(RpWorld * wpWorld,
                         RpPVSProgressCallBack
                         callback);

extern RpWorldSector *
RpPVSSetViewPosition(RpWorld * wpWorld,
                     RwV3d * pos);

extern RpWorldSector *
RpPVSSetViewSector(RpWorld * wpWorld, RpWorldSector * spSect);

extern RpWorldSector *
RpPVSSetWorldSectorPairedVisibility(RpWorldSector * spSectA,
                                    RpWorldSector * spSectB,
                                    RwBool visible,
                                    RwBool mutual);

extern RpWorld *
RpPVSDestroy(RpWorld * wpWorld);

extern RwBool
RpPVSWorldSectorVisible(RpWorldSector * spSect);

extern RwBool
RpPVSPluginAttach(void);

extern RwBool
RpPVSQuery(RpWorld * wpWorld);

extern RwBool
RpPVSAtomicVisible(RpAtomic * atom);

extern RpWorld *
RpPVSStatisticsGet(RpWorld * wpWorld,
                   RwInt32 * ptotal,
                   RwInt32 * paccept);

extern RpPVSProgressCallBack
RpPVSGetProgressCallBack(RpWorld *
                         wpWorld);

extern RpWorld *
RpPVSConstruct(RpWorld * wpWorld,
            RpPVSCallBack callback,
            void *pData);

extern RpWorld*
RpPVSConstructSector(RpWorld * wpWorld,
            RpWorldSector * spSector,
            RpPVSCallBack callback,
            void *pData);


extern RpWorldSector *
RpPVSGeneric(RpWorldSector * spSect,
             const RwBBox __RWUNUSED__ * box,
             void *data);

extern RwBool
RpPVSSetCollisionDetection(RwBool collis);

extern RwBool
RpPVSSetBackFaceCulling(RwBool bfc);

extern RpWorld *
RpPVSUnhook(RpWorld * wpWorld);

extern RpWorld *
RpPVSHook(RpWorld * wpWorld);

extern RpWorldSector *
RpPVSSetWorldSectorVisibility(RpWorldSector * spSect,
                              RwBool visible);

extern RwBool
RpPVSSamplePOV(RwV3d * pos,
               RwBool colltest);

extern RxNodeDefinition *
RxNodeDefinitionGetPVSWorldSectorCSL(void);

#ifdef    __cplusplus
}
#endif                          /* __cplusplus */

/* These functions are added for backwards compatibility... */
#define RpPVSCreate(_wpWorld,                               \
            _raster, _zraster, _mindist,                    \
            _maxdist, _maxdepth, _callback, _pData)         \
            RpPVSConstruct(_wpWorld, _callback, _pData)

#define RpPVSAddPOV(_pos) \
    RpPVSSamplePOV(_pos, FALSE)

#define RpPVSAddWorldSector(_sector) \
    RpPVSSetWorldSectorVisibility(_sector, TRUE)

#define RpPVSAddExtraPOV(_world, _raster, _zraster, _mindist, _mazdist, _matrix) \
MACRO_START                                     \
{                                               \
    rpPVSGlobals.World = (_world);              \
    RpPVSSamplePOV(&((_matrix)->pos), TRUE);    \
}                                               \
MACRO_STOP


#endif /*  _RPPVS_H */