4b825dc642cb6eb9a060e54bf8d69288fbee490494a6641b73026d662261604d7d192beae70b11dc
 
 
1
#include "system.h"
 
 
2
#include "prototyp.h"
 
 
3
#include "stratdef.h"
 
 
4
#include "kshape.h"
 
 
5
#include "userprofile.h"
 
 
6
#include "bh_types.h"
 
 
7
#include "frustum.h"
 
 
8
 
 
 
9
extern int DrawingAReflection;
 
 
10
 
 
 
11
#define bigint 1<<30            /*  max int size*/
 
 
12
#define smallint -(bigint)      /* smallest int size*/
 
 
13
 
 
 
14
struct KObject2
 
 
15
{
 
 
16
    DISPLAYBLOCK *DispPtr;
 
 
17
    int SortKey;
 
 
18
};
 
 
19
 
 
 
20
static int compare_kobject(const void * void_a, const void *void_b)
 
 
21
{
 
 
22
    const struct KObject * a = void_a;
 
 
23
    const struct KObject * b = void_b;
 
 
24
 
 
 
25
    return (a->SortKey < b->SortKey) ? -1 : (a->SortKey > b->SortKey);
 
 
26
}
 
 
27
 
 
 
28
int PointIsInModule(VECTORCH *pointPtr, MODULE *modulePtr)
 
 
29
{
 
 
30
    VECTORCH position;
 
 
31
    position.vx = pointPtr->vx - modulePtr->m_world.vx;
 
 
32
    position.vy = pointPtr->vy - modulePtr->m_world.vy;
 
 
33
    position.vz = pointPtr->vz - modulePtr->m_world.vz;
 
 
34
 
 
 
35
    return
 
 
36
    (
 
 
37
        (position.vx >= modulePtr->m_minx) 
 
 
38
        &&
 
 
39
        (position.vx <= modulePtr->m_maxx) 
 
 
40
        &&
 
 
41
        (position.vz >= modulePtr->m_minz) 
 
 
42
        &&
 
 
43
        (position.vz <= modulePtr->m_maxz) 
 
 
44
        &&
 
 
45
        (position.vy >= modulePtr->m_miny) 
 
 
46
        &&
 
 
47
        (position.vy <= modulePtr->m_maxy)
 
 
48
    );
 
 
49
}
 
 
50
 
 
 
51
void ReflectObject(DISPLAYBLOCK *dPtr)
 
 
52
{
 
 
53
        dPtr->ObWorld.vx = MirroringAxis - dPtr->ObWorld.vx;
 
 
54
        dPtr->ObMat.mat11 = -dPtr->ObMat.mat11;
 
 
55
        dPtr->ObMat.mat21 = -dPtr->ObMat.mat21;
 
 
56
        dPtr->ObMat.mat31 = -dPtr->ObMat.mat31;
 
 
57
}
 
 
58
 
 
 
59
#define MAX_NUMBER_OF_VISIBLE_MODULES 400
 
 
60
struct KObject VisibleModules[MAX_NUMBER_OF_VISIBLE_MODULES];
 
 
61
struct KObject VisibleObjects[maxobjects];
 
 
62
int numVisMods = 0;
 
 
63
int numVisObjs = 0;
 
 
64
 
 
 
65
void AddShapes()
 
 
66
{
 
 
67
    extern int NumOnScreenBlocks;
 
 
68
    extern DISPLAYBLOCK *OnScreenBlockList[];
 
 
69
    int i;
 
 
70
    numVisMods = 0;
 
 
71
    numVisObjs = 0;
 
 
72
 
 
 
73
    for (i=0; i < NumOnScreenBlocks; i++)
 
 
74
    {
 
 
75
        DISPLAYBLOCK *objectPtr = OnScreenBlockList[i];
 
 
76
        MODULE *modulePtr = objectPtr->Module;
 
 
77
 
 
 
78
        /* if it's a module, which isn't inside another module */
 
 
79
        if (modulePtr && !(modulePtr->m_flags & m_flag_slipped_inside))
 
 
80
        {
 
 
81
             if(PointIsInModule(&Global_VDB.VDB_World, modulePtr))
 
 
82
            {
 
 
83
                VisibleModules[numVisMods].SortKey = smallint;
 
 
84
                //printf("fog is %d in player's module\n", modulePtr->m_flags & MODULEFLAG_FOG);
 
 
85
            }
 
 
86
            else
 
 
87
            {
 
 
88
                VECTORCH position;
 
 
89
                VECTORCH dist;
 
 
90
 
 
 
91
                position.vx = modulePtr->m_world.vx - PlayerStatus.DisplayBlock->ObWorld.vx;
 
 
92
                position.vy = modulePtr->m_world.vy - PlayerStatus.DisplayBlock->ObWorld.vy;
 
 
93
                position.vz = modulePtr->m_world.vz - PlayerStatus.DisplayBlock->ObWorld.vz;
 
 
94
 
 
 
95
                {
 
 
96
                    int minX = modulePtr->m_minx + position.vx;
 
 
97
                    int maxX = modulePtr->m_maxx + position.vx;
 
 
98
 
 
 
99
                    if (maxX < 0) /* outside maxX side */
 
 
100
                    {
 
 
101
                        dist.vx = maxX;
 
 
102
                    }
 
 
103
                    else if (minX > 0) /* outside minX faces */
 
 
104
                    {
 
 
105
                        dist.vx = minX;
 
 
106
                    }
 
 
107
                    else /* between faces */
 
 
108
                    {
 
 
109
                        dist.vx = 0;
 
 
110
                    }
 
 
111
                }
 
 
112
                {
 
 
113
                    int minY = modulePtr->m_miny + position.vy;
 
 
114
                    int maxY = modulePtr->m_maxy + position.vy;
 
 
115
 
 
 
116
                    if (maxY < 0) /* outside maxY side */
 
 
117
                    {
 
 
118
                        dist.vy = maxY;
 
 
119
                    }
 
 
120
                    else if (minY > 0) /* outside minY faces */
 
 
121
                    {
 
 
122
                        dist.vy = minY;
 
 
123
                    }
 
 
124
                    else /* between faces */
 
 
125
                    {
 
 
126
                        dist.vy = 0;
 
 
127
                    }
 
 
128
                }
 
 
129
                {
 
 
130
                    int minZ = modulePtr->m_minz + position.vz;
 
 
131
                    int maxZ = modulePtr->m_maxz + position.vz;
 
 
132
 
 
 
133
                    if (maxZ < 0) /* outside maxZ side */
 
 
134
                    {
 
 
135
                        dist.vz = maxZ;
 
 
136
                    }
 
 
137
                    else if (minZ > 0) /* outside minZ faces */
 
 
138
                    {
 
 
139
                        dist.vz = minZ;
 
 
140
                    }
 
 
141
                    else /* between faces */
 
 
142
                    {
 
 
143
                        dist.vz = 0;
 
 
144
                    }
 
 
145
                }
 
 
146
 
 
 
147
                VisibleModules[numVisMods].SortKey = Magnitude(&dist);
 
 
148
            }
 
 
149
 
 
 
150
            VisibleModules[numVisMods].DispPtr = objectPtr;
 
 
151
 
 
 
152
               if(numVisMods > MAX_NUMBER_OF_VISIBLE_MODULES)
 
 
153
            {
 
 
154
                // outside the environment!
 
 
155
                printf("MAX_NUMBER_OF_VISIBLE_MODULES (%d) exceeded!\n", MAX_NUMBER_OF_VISIBLE_MODULES);
 
 
156
                printf("Possibly outside the environment!\n");
 
 
157
                return;
 
 
158
            }
 
 
159
 
 
 
160
            numVisMods++;
 
 
161
        }
 
 
162
        else //if(!objectPtr->SfxPtr)
 
 
163
        {
 
 
164
            VisibleObjects[numVisObjs].DispPtr = objectPtr;
 
 
165
            /* this sort key defaults to the object not being drawn, ie. a grenade
 
 
166
            behind a closed door (so there is no module behind door) would still be
 
 
167
            in the OnScreenBlockList but need not be drawn. */
 
 
168
            VisibleObjects[numVisObjs++].SortKey = 0x7fffffff;
 
 
169
        }
 
 
170
    }
 
 
171
 
 
 
172
    //printf("numvismods %d\n", numVisMods);
 
 
173
    //printf("numvisobjs %d\n", numVisObjs);
 
 
174
 
 
 
175
    qsort(VisibleModules, numVisMods, sizeof(struct KObject), compare_kobject);
 
 
176
 
 
 
177
    {
 
 
178
        int o = numVisObjs;
 
 
179
 
 
 
180
        while(o--)
 
 
181
        {    
 
 
182
            DISPLAYBLOCK *objectPtr = VisibleObjects[o].DispPtr;
 
 
183
 
 
 
184
            int maxX = objectPtr->ObWorld.vx + objectPtr->extent.radius; 
 
 
185
            int minX = objectPtr->ObWorld.vx - objectPtr->extent.radius; 
 
 
186
            int maxZ = objectPtr->ObWorld.vz + objectPtr->extent.radius; 
 
 
187
            int minZ = objectPtr->ObWorld.vz - objectPtr->extent.radius; 
 
 
188
            int maxY = objectPtr->ObWorld.vy + objectPtr->extent.radius; 
 
 
189
            int minY = objectPtr->ObWorld.vy - objectPtr->extent.radius; 
 
 
190
 
 
 
191
            int numMods = 0;
 
 
192
 
 
 
193
            while(numMods < numVisMods)
 
 
194
            {
 
 
195
                MODULE *modulePtr = VisibleModules[numMods].DispPtr->Module;
 
 
196
 
 
 
197
                if
 
 
198
                (
 
 
199
                    (maxX >= modulePtr->m_minx + modulePtr->m_world.vx) 
 
 
200
                    &&
 
 
201
                    (minX <= modulePtr->m_maxx + modulePtr->m_world.vx) 
 
 
202
                    &&
 
 
203
                    (maxZ >= modulePtr->m_minz + modulePtr->m_world.vz) 
 
 
204
                    &&
 
 
205
                    (minZ <= modulePtr->m_maxz + modulePtr->m_world.vz)
 
 
206
                    &&
 
 
207
                    (maxY >= modulePtr->m_miny + modulePtr->m_world.vy) 
 
 
208
                     &&
 
 
209
                    (minY <= modulePtr->m_maxy + modulePtr->m_world.vy) 
 
 
210
                )
 
 
211
                {
 
 
212
                    VisibleObjects[o].SortKey = numMods;
 
 
213
                    break;
 
 
214
                }
 
 
215
 
 
 
216
                numMods++;
 
 
217
            }
 
 
218
        }
 
 
219
    }
 
 
220
 
 
 
221
    if (CHEATMODE_MOTIONBLUR == UserProfile.active_bonus)
 
 
222
    {
 
 
223
        int numMods;
 
 
224
 
 
 
225
        for (numMods = 0; numMods < numVisMods; numMods++)
 
 
226
        {
 
 
227
            //MODULE *modulePtr = VisibleModules[numMods].DispPtr->Module;
 
 
228
 
 
 
229
            AddModuleShape(VisibleModules[numMods].DispPtr);
 
 
230
 
 
 
231
            if (MirroringActive)
 
 
232
            {
 
 
233
                DISPLAYBLOCK *dptr = VisibleModules[numMods].DispPtr;
 
 
234
                ReflectObject(dptr);
 
 
235
 
 
 
236
                dptr->ObView.vx = dptr->ObWorld.vx - Global_VDB.VDB_World.vx;
 
 
237
                dptr->ObView.vy = dptr->ObWorld.vy - Global_VDB.VDB_World.vy;
 
 
238
                dptr->ObView.vz = dptr->ObWorld.vz - Global_VDB.VDB_World.vz;
 
 
239
 
 
 
240
                RotateVector(&dptr->ObView, &Global_VDB.VDB_Mat);
 
 
241
 
 
 
242
                DrawingAReflection = 1;
 
 
243
                AddModuleShape(dptr);
 
 
244
                DrawingAReflection = 0;
 
 
245
                ReflectObject(dptr);
 
 
246
            }
 
 
247
 
 
 
248
            {
 
 
249
                int o = numVisObjs;
 
 
250
 
 
 
251
                while(o--)
 
 
252
                {
 
 
253
                    if(VisibleObjects[o].SortKey == numMods)
 
 
254
                    {
 
 
255
                        AddShape(VisibleObjects[o].DispPtr);    
 
 
256
 
 
 
257
                        if (MirroringActive && !VisibleObjects[o].DispPtr->HModelControlBlock)
 
 
258
                        {
 
 
259
                            DISPLAYBLOCK *dptr = VisibleObjects[o].DispPtr;
 
 
260
                            ReflectObject(dptr);
 
 
261
 
 
 
262
                            dptr->ObView.vx = dptr->ObWorld.vx - Global_VDB.VDB_World.vx;
 
 
263
                            dptr->ObView.vy = dptr->ObWorld.vy - Global_VDB.VDB_World.vy;
 
 
264
                            dptr->ObView.vz = dptr->ObWorld.vz - Global_VDB.VDB_World.vz;
 
 
265
 
 
 
266
                            RotateVector(&dptr->ObView, &Global_VDB.VDB_Mat);
 
 
267
 
 
 
268
                            DrawingAReflection = 1;
 
 
269
                            AddShape(dptr);
 
 
270
                            DrawingAReflection = 0;
 
 
271
                            ReflectObject(dptr);
 
 
272
                        }
 
 
273
                    }
 
 
274
                }
 
 
275
            }
 
 
276
        }
 
 
277
    }
 
 
278
    else
 
 
279
    {
 
 
280
        int numMods = numVisMods;
 
 
281
 
 
 
282
        while(numMods--)
 
 
283
        {
 
 
284
            //MODULE *modulePtr = VisibleModules[numMods].DispPtr->Module;
 
 
285
            AddModuleShape(VisibleModules[numMods].DispPtr);
 
 
286
 
 
 
287
            if (MirroringActive)
 
 
288
            {
 
 
289
                DISPLAYBLOCK *dptr = VisibleModules[numMods].DispPtr;
 
 
290
 
 
 
291
                ReflectObject(dptr);
 
 
292
 
 
 
293
                dptr->ObView.vx = dptr->ObWorld.vx - Global_VDB.VDB_World.vx;
 
 
294
                dptr->ObView.vy = dptr->ObWorld.vy - Global_VDB.VDB_World.vy;
 
 
295
                dptr->ObView.vz = dptr->ObWorld.vz - Global_VDB.VDB_World.vz;
 
 
296
 
 
 
297
                RotateVector(&dptr->ObView, &Global_VDB.VDB_Mat);
 
 
298
 
 
 
299
                DrawingAReflection = 1;
 
 
300
                AddModuleShape(dptr);
 
 
301
                DrawingAReflection = 0;
 
 
302
                ReflectObject(dptr);
 
 
303
            }
 
 
304
 
 
 
305
            {
 
 
306
                int o = numVisObjs;
 
 
307
 
 
 
308
                while(o--)
 
 
309
                {
 
 
310
                    if(VisibleObjects[o].SortKey == numMods)
 
 
311
                    {
 
 
312
                        if (VisibleObjects[o].DispPtr->HModelControlBlock)
 
 
313
                        {
 
 
314
                            AddShape2(VisibleObjects[o].DispPtr);    
 
 
315
                        }
 
 
316
                        else if(!VisibleObjects[o].DispPtr->SfxPtr)
 
 
317
                        //else
 
 
318
                        {
 
 
319
                            AddShape(VisibleObjects[o].DispPtr);    
 
 
320
 
 
 
321
                            if (MirroringActive)
 
 
322
                            {
 
 
323
                                DISPLAYBLOCK *dptr = VisibleObjects[o].DispPtr;
 
 
324
 
 
 
325
                                ReflectObject(dptr);
 
 
326
 
 
 
327
                                dptr->ObView.vx = dptr->ObWorld.vx - Global_VDB.VDB_World.vx;
 
 
328
                                dptr->ObView.vy = dptr->ObWorld.vy - Global_VDB.VDB_World.vy;
 
 
329
                                dptr->ObView.vz = dptr->ObWorld.vz - Global_VDB.VDB_World.vz;
 
 
330
 
 
 
331
                                RotateVector(&dptr->ObView, &Global_VDB.VDB_Mat);
 
 
332
 
 
 
333
                                DrawingAReflection = 1;
 
 
334
                                AddShape(dptr);
 
 
335
                                DrawingAReflection = 0;
 
 
336
                                ReflectObject(dptr);
 
 
337
                            }
 
 
338
                        }
 
 
339
                    }
 
 
340
                }
 
 
341
            }
 
 
342
        }
 
 
343
    }
 
 
344
}
 
 
345
 
 
 
346
void RenderThisHierarchicalDisplayblock(DISPLAYBLOCK *dPtr)
 
 
347
{
 
 
348
    if(ObjectWithinFrustrum(dPtr))
 
 
349
    {
 
 
350
        AddHierarchicalShape(dPtr);
 
 
351
 
 
 
352
        if (MirroringActive && dPtr->ObStrategyBlock)
 
 
353
        {
 
 
354
            ReflectObject(dPtr);
 
 
355
            dPtr->ObView.vx = dPtr->ObWorld.vx - Global_VDB.VDB_World.vx;
 
 
356
            dPtr->ObView.vy = dPtr->ObWorld.vy - Global_VDB.VDB_World.vy;
 
 
357
            dPtr->ObView.vz = dPtr->ObWorld.vz - Global_VDB.VDB_World.vz;
 
 
358
            RotateVector(&dPtr->ObView, &Global_VDB.VDB_Mat);
 
 
359
            DrawingAReflection = 1;
 
 
360
            AddHierarchicalShape(dPtr);
 
 
361
            DrawingAReflection = 0;
 
 
362
            ReflectObject(dPtr);
 
 
363
        }
 
 
364
    }
 
 
365
}