4b825dc642cb6eb9a060e54bf8d69288fbee4904ebd360ec63ec976c05699f3180e866b3f69e5472
 
 
1
#include "system.h"
 
 
2
#include "dynblock.h"
 
 
3
#include <stdio.h>
 
 
4
#include <assert.h>
 
 
5
 
 
 
6
static const DYNAMICSBLOCK DynamicsTemplate[]=
 
 
7
{
 
 
8
    /* DYNAMICS_TEMPLATE_DEFAULT*/
 
 
9
    {
 
 
10
        {0,0,0},/* EULER OrientEuler - Euler Orientation */
 
 
11
        {0,0,0,0,0,0,0,0,0},/* MATRIXCH    OrientMat - Local -> World Orientation Matrix */
 
 
12
        {0,0,0},/* EULER PrevOrientEuler - Euler Orientation */
 
 
13
        {65536,0,0,0,65536,0,0,0,65536},/* MATRIXCH    PrevOrientMat - Local -> World Orientation Matrix */
 
 
14
 
 
 
15
        {0,0,0},/* VECTORCH    Position */
 
 
16
        {0,0,0},/* VECTORCH    PrevPosition */
 
 
17
 
 
 
18
        {0,0,0},/* VECTORCH    LinVelocity */
 
 
19
        {0,0,0},/* VECTORCH LinImpulse */
 
 
20
 
 
 
21
        {0,0,0},/* EULER AngVelocity */
 
 
22
 
 
 
23
        NULL, /* struct collisionreport *CollisionReportPtr; */
 
 
24
 
 
 
25
        {0,65536,0},/* VECTORCH    GravityDirection */
 
 
26
        0, /* int TimeNotInContactWithFloor */
 
 
27
 
 
 
28
        0,/* int Friction; */
 
 
29
        0,/* int Elasticity; */
 
 
30
        80, /* int Mass */
 
 
31
 
 
 
32
        DYN_TYPE_NRBB_COLLISIONS,
 
 
33
        TOPPLE_FORCE_NONE,
 
 
34
 
 
 
35
        1,/* GravityOn :1; */
 
 
36
        1,/* UseStandardGravity :1 - ie. in direction of increasing Y */
 
 
37
        0,/* StopOnCollision :1; */
 
 
38
        1,/* CanClimbStairs :1; */
 
 
39
        0,/* IsStatic :1; */
 
 
40
        0,/* OnlyCollideWithObjects :1; */
 
 
41
        0,/* IsNetGhost :1; */
 
 
42
        0,/* IgnoreSameObjectsAsYou :1; */
 
 
43
        0,/* IgnoreThePlayer :1; */
 
 
44
        0,/* UseDisplacement :1; */
 
 
45
        0,/* OnlyCollideWithEnvironment :1; */
 
 
46
        0,/* IsInContactWithFloor :1 */
 
 
47
        0,/* IsInContactWithNearlyFlatFloor */
 
 
48
        0,/* IsFloating :1 */
 
 
49
        0,/* IsPickupObject :1 */
 
 
50
        0,/* IsInanimate :1; */
 
 
51
        0,/* IgnoresNotVisPolys :1; */
 
 
52
        0,
 
 
53
        0,
 
 
54
        {0,0,0},
 
 
55
    },
 
 
56
        /* DYNAMICS_TEMPLATE_GRENADE */
 
 
57
    {
 
 
58
        {0,0,0},/* EULER OrientEuler - Euler Orientation */
 
 
59
        {0,0,0,0,0,0,0,0,0},/* MATRIXCH    OrientMat - Local -> World Orientation Matrix */
 
 
60
        {0,0,0},/* EULER PrevOrientEuler - Euler Orientation */
 
 
61
        {65536,0,0,0,65536,0,0,0,65536},/* MATRIXCH    PrevOrientMat - Local -> World Orientation Matrix */
 
 
62
 
 
 
63
        {0,0,0},/* VECTORCH    Position */
 
 
64
        {0,0,0},/* VECTORCH    PrevPosition */
 
 
65
 
 
 
66
        {0,0,0},/* VECTORCH    LinVelocity */
 
 
67
        {0,0,0},/* VECTORCH LinImpulse */
 
 
68
 
 
 
69
        {0,0,0},/* EULER AngVelocity */
 
 
70
 
 
 
71
        NULL, /* struct collisionreport *CollisionReportPtr; */
 
 
72
 
 
 
73
        {0,0,0},/* VECTORCH    GravityDirection */
 
 
74
        0, /* int TimeNotInContactWithFloor */
 
 
75
 
 
 
76
        0,/* int Friction; */
 
 
77
        32768/2,/* int Elasticity; */
 
 
78
        1, /* int Mass */
 
 
79
 
 
 
80
        DYN_TYPE_NRBB_COLLISIONS,
 
 
81
        TOPPLE_FORCE_FULL,
 
 
82
 
 
 
83
        1,/* GravityOn :1; */
 
 
84
        1,/* UseStandardGravity :1 - ie. in direction of increasing Y */
 
 
85
        0,/* StopOnCollision :1; */
 
 
86
        0,/* CanClimbStairs :1; */
 
 
87
        0,/* IsStatic :1; */
 
 
88
        0,/* OnlyCollideWithObjects :1; */
 
 
89
        0,/* IsNetGhost :1; */
 
 
90
        0,/* IgnoreSameObjectsAsYou :1; */
 
 
91
        1,/* IgnoreThePlayer :1; */
 
 
92
        0,/* UseDisplacement :1; */
 
 
93
        0,/* OnlyCollideWithEnvironment :1; */
 
 
94
        0,/* IsInContactWithFloor :1 */
 
 
95
        0,/* IsInContactWithNearlyFlatFloor */
 
 
96
        0,/* IsFloating :1 */
 
 
97
        0,/* IsPickupObject :1 */
 
 
98
        0,/* IsInanimate :1; */
 
 
99
        0,/* IgnoresNotVisPolys :1; */
 
 
100
        0,
 
 
101
        0,
 
 
102
        {0,0,0},
 
 
103
    },
 
 
104
        /* DYNAMICS_TEMPLATE_ROCKET & predator disc weapon */
 
 
105
    {
 
 
106
        {0,0,0},/* EULER OrientEuler - Euler Orientation */
 
 
107
        {0,0,0,0,0,0,0,0,0},/* MATRIXCH    OrientMat - Local -> World Orientation Matrix */
 
 
108
        {0,0,0},/* EULER PrevOrientEuler - Euler Orientation */
 
 
109
        {65536,0,0,0,65536,0,0,0,65536},/* MATRIXCH    PrevOrientMat - Local -> World Orientation Matrix */
 
 
110
 
 
 
111
        {0,0,0},/* VECTORCH    Position */
 
 
112
        {0,0,0},/* VECTORCH    PrevPosition */
 
 
113
 
 
 
114
        {0,0,0},/* VECTORCH    LinVelocity */
 
 
115
        {0,0,0},/* VECTORCH LinImpulse */
 
 
116
 
 
 
117
        {0,0,0},/* EULER AngVelocity */
 
 
118
 
 
 
119
        NULL, /* struct collisionreport *CollisionReportPtr; */
 
 
120
 
 
 
121
        {0,0,0},/* VECTORCH    GravityDirection */
 
 
122
        0, /* int TimeNotInContactWithFloor */
 
 
123
 
 
 
124
        0,/* int Friction; */
 
 
125
        65536,/* int Elasticity; */
 
 
126
        5, /* int Mass */
 
 
127
 
 
 
128
        DYN_TYPE_NRBB_COLLISIONS,
 
 
129
        TOPPLE_FORCE_NONE,
 
 
130
 
 
 
131
        0,/* GravityOn :1; */
 
 
132
        0,/* UseStandardGravity :1 - ie. in direction of increasing Y */
 
 
133
        1,/* StopOnCollision :1; */
 
 
134
        0,/* CanClimbStairs :1; */
 
 
135
        0,/* IsStatic :1; */
 
 
136
        0,/* OnlyCollideWithObjects :1; */
 
 
137
        0,/* IsNetGhost :1; */
 
 
138
        0,/* IgnoreSameObjectsAsYou :1; */
 
 
139
        1,/* IgnoreThePlayer :1; */
 
 
140
        0,/* UseDisplacement :1; */
 
 
141
        0,/* OnlyCollideWithEnvironment :1; */
 
 
142
        0,/* IsInContactWithFloor :1 */
 
 
143
        0,/* IsInContactWithNearlyFlatFloor */
 
 
144
        0,/* IsFloating :1 */
 
 
145
        0,/* IsPickupObject :1 */
 
 
146
        0,/* IsInanimate :1; */
 
 
147
        0,/* IgnoresNotVisPolys :1; */
 
 
148
        0,
 
 
149
        0,
 
 
150
        {0,0,0},
 
 
151
    },
 
 
152
        /* DYNAMICS_TEMPLATE_STATIC */
 
 
153
    {
 
 
154
        {0,0,0},/* EULER OrientEuler - Euler Orientation */
 
 
155
        {65536,0,0,0,65536,0,0,0,65536},/* MATRIXCH    OrientMat - Local -> World Orientation Matrix */
 
 
156
        {0,0,0},/* EULER PrevOrientEuler - Euler Orientation */
 
 
157
        {65536,0,0,0,65536,0,0,0,65536},/* MATRIXCH    PrevOrientMat - Local -> World Orientation Matrix */
 
 
158
 
 
 
159
        {0,0,0},/* VECTORCH    Position */
 
 
160
        {0,0,0},/* VECTORCH    PrevPosition */
 
 
161
 
 
 
162
        {0,0,0},/* VECTORCH    LinVelocity */
 
 
163
        {0,0,0},/* VECTORCH LinImpulse */
 
 
164
 
 
 
165
        {0,0,0},/* EULER AngVelocity */
 
 
166
 
 
 
167
        NULL, /* struct collisionreport *CollisionReportPtr; */
 
 
168
 
 
 
169
        {0,0,0},/* VECTORCH    GravityDirection */
 
 
170
        0, /* int TimeNotInContactWithFloor */
 
 
171
 
 
 
172
        0,/* int Friction; */
 
 
173
        0,/* int Elasticity;    */
 
 
174
        100, /* int Mass */
 
 
175
 
 
 
176
        DYN_TYPE_NRBB_COLLISIONS,
 
 
177
        TOPPLE_FORCE_NONE,
 
 
178
 
 
 
179
        1,/* GravityOn :1; */
 
 
180
        1,/* UseStandardGravity :1 - ie. in direction of increasing Y */
 
 
181
        0,/* StopOnCollision :1; */
 
 
182
        0,/* CanClimbStairs :1; */
 
 
183
        1,/* IsStatic :1; */
 
 
184
        0,/* OnlyCollideWithObjects :1; */
 
 
185
        0,/* IsNetGhost :1; */
 
 
186
        0,/* IgnoreSameObjectsAsYou :1; */
 
 
187
        0,/* IgnoreThePlayer :1; */
 
 
188
        0,/* UseDisplacement :1; */
 
 
189
        0,/* OnlyCollideWithEnvironment :1; */
 
 
190
        0,/* IsInContactWithFloor :1 */
 
 
191
        0,/* IsInContactWithNearlyFlatFloor */
 
 
192
        0,/* IsFloating :1 */
 
 
193
        0,/* IsPickupObject :1 */
 
 
194
        0,/* IsInanimate :1; */
 
 
195
        0,/* IgnoresNotVisPolys :1; */
 
 
196
        0,
 
 
197
        0,
 
 
198
        {0,0,0},
 
 
199
    }
 
 
200
};
 
 
201
 
 
 
202
static int NumFreeDynBlocks = MAX_NO_OF_DYNAMICS_BLOCKS;
 
 
203
static DYNAMICSBLOCK **FreeDynBlockListPtr = NULL;
 
 
204
 
 
 
205
void InitialiseDynamicsBlocks()
 
 
206
{
 
 
207
    static DYNAMICSBLOCK DynBlockStorage[MAX_NO_OF_DYNAMICS_BLOCKS];
 
 
208
    static DYNAMICSBLOCK *FreeDynBlockList[MAX_NO_OF_DYNAMICS_BLOCKS];
 
 
209
    int blk;
 
 
210
 
 
 
211
    for(blk = 0; blk < MAX_NO_OF_DYNAMICS_BLOCKS; blk++)
 
 
212
        FreeDynBlockList[blk] = &DynBlockStorage[blk];
 
 
213
 
 
 
214
    FreeDynBlockListPtr = &FreeDynBlockList[MAX_NO_OF_DYNAMICS_BLOCKS - 1];
 
 
215
    NumFreeDynBlocks = MAX_NO_OF_DYNAMICS_BLOCKS;
 
 
216
}
 
 
217
 
 
 
218
DYNAMICSBLOCK* AllocateDynamicsBlock(enum DYNAMICS_TEMPLATE_ID templateID)
 
 
219
{
 
 
220
    if (NumFreeDynBlocks)
 
 
221
    {
 
 
222
        DYNAMICSBLOCK *dynPtr = *FreeDynBlockListPtr--;
 
 
223
        *dynPtr = DynamicsTemplate[templateID];
 
 
224
        NumFreeDynBlocks--;
 
 
225
        return dynPtr;
 
 
226
    }
 
 
227
 
 
 
228
return NULL;
 
 
229
}
 
 
230
 
 
 
231
void DeallocateDynamicsBlock(DYNAMICSBLOCK *dynPtr)
 
 
232
{
 
 
233
    *(++FreeDynBlockListPtr) = dynPtr;
 
 
234
    NumFreeDynBlocks++;
 
 
235
}
 
 
236
 
 
 
237
int DynamicObjectIsMoving(const DYNAMICSBLOCK *dynPtr)
 
 
238
{
 
 
239
    return ( (dynPtr->Position.vx != dynPtr->PrevPosition.vx)
 
 
240
        ||
 
 
241
        (dynPtr->Position.vy != dynPtr->PrevPosition.vy)
 
 
242
        || 
 
 
243
        (dynPtr->Position.vz != dynPtr->PrevPosition.vz));
 
 
244
}