forked from stuart73/Onslaught
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactor.cpp
More file actions
367 lines (295 loc) · 9.05 KB
/
Copy pathactor.cpp
File metadata and controls
367 lines (295 loc) · 9.05 KB
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
#include "common.h"
#include "map.h"
#include "actor.h"
#include "debuglog.h"
#include "mapwho.h"
#include "mapwhoentry.h"
#include "collisionseekingthing.h"
#include "eventmanager.h"
#include "Profile.h"
#include "game.h"
#include "cliparams.h"
//******************************************************************************************
void CActor::Init(CInitThing* init)
{
mLastTimeOnGround=-100.f;
mLastTimeInWater=-100.f;
mLastTimeOnObject=-100.0f;
mLastMoveTime = EVENT_MANAGER.GetTime() ;
// SRG when initalising collision stuff in Thing::Init is may call GetVelocity()
// so setting up the attribute here
mVelocity = init->mVelocity ;
// SRG collision stuff also needs oldPos to be sensible aswell
mOldPos = init->mPos;
if (init->mOrientationType == EULER_ANGLES)
mOldOrientation = FMatrix(init->mYaw, init->mPitch, init->mRoll);
else if (init->mOrientationType == DIRECTION_COSINE_MATRIX)
mOldOrientation = init->mOrientation;
SUPERTYPE::Init(init);
int r = (int)GetMoveMultiplier() ;
mDoFullMoveCount = GAME.Random() % r ;
AddMoveEvent(NULL);
}
//******************************************************************************************
CActor::~CActor()
{
}
//******************************************************************************************
// don't add to this without my say so (SRG)
// A basic low fidelity move function which has to be called every frame which the normal
// move function was not called on. This is here in order for the collision to work properly.
void CActor::LowFidelityMove()
{
PROFILE_FN(ActorLFMove);
mOldPos = mPos;
mPos+=mVelocity;
if (ClipToGround())
{
float alt=MAP.Collide(mPos)-COfGHeight();
if (alt <=mPos.Z)
{
mPos.Z=alt;
mLastTimeOnGround = EVENT_MANAGER.GetTime();
}
}
}
//******************************************************************************************
void CActor::Move()
{
PROFILE_FN(ActorMove);
mLastMoveTime = EVENT_MANAGER.GetTime();
// store old position
mOldPos = mPos;
mOldOrientation = mOrientation;
CSector previous_sector;
if (GetMapWhoEntry())
previous_sector=mMapWhoEntry.GetSectorIn();
if (CLIPARAMS.mDeveloperMode)
{
// ### TEMP debug check to make sure we don't go above max velocity
if (IsA(THING_TYPE_UNIT))
{
float m=mVelocity.MagnitudeXY();
float mv=GetMaxVelocity()/GAME_FR;
if (m>(mv+0.001f))
{
// LOG.AddMessage("Warning object %s travling beyond max velocity (%2.8f per sec) mv/s = %2.8f", _GetClassName(), (m-mv) * GAME_FR, GetMaxVelocity() ) ;
}
}
else
{
float m=mVelocity.Magnitude();
float mv=GetMaxVelocity()/GAME_FR;
if (m>(mv+0.001f))
{
// LOG.AddMessage("Warning object %s travling beyond max velocity (%2.8f per sec) mv/s = %2.8f", _GetClassName(), (m-mv) * GAME_FR, GetMaxVelocity() ) ;
}
}
}
// SRG end temp check
mPos+=mVelocity;
float water_height = MAP.GetWaterLevel()-COfGHeight();
if (ClipToGround())
{
float alt=MAP.Collide(mPos)-COfGHeight();
if (alt <=mPos.Z)
{
mPos.Z=alt;
// sorry last minute hack stops you bouncing down hills
if (mFlags & TF_SLIDE)
{
// slide like you did in moho
FVector slidePlaneNormal = MAP.Normal(mPos) ;
float backoff = (mVelocity * slidePlaneNormal);
mVelocity -=slidePlaneNormal*backoff;
// not on ground !
}
else
{
DeclareOnGround();
if (fabsf(mVelocity.Z)>Gravity()+0.05f)
mVelocity.Z=-mVelocity.Z*BounceFactor();
else
mVelocity.Z=0;
}
}
//if (water_height <= mPos.Z) mPos.Z = water_height
if (water_height <= mPos.Z)
DeclareInWater();
}
if (GetMapWhoEntry())
{
if (mMapWhoEntry.UpdateEntry(mOldPos) && mCollisionSeekingThing)
{
mCollisionSeekingThing->MovedSector(previous_sector, mMapWhoEntry.GetSectorIn()) ;
}
}
/*
// If we've moved, remove some snow
if ((mOldPos!=mPos) || (mOldOrientation!=mOldOrientation))
{
mSnowDensity-=8; // Needs to be greater than the snow addition value as snow will still be added!
if (mSnowDensity<0)
mSnowDensity=0;
}
*/
}
//******************************************************************************************
// used by collsion etc ( resets where the thing has moved over the frame )
void CActor::MoveTo(const FVector& pos)
{
// mOldPos = mPos ;
SUPERTYPE::MoveTo(pos) ;
}
//******************************************************************************************
void CActor::Teleport(const FVector& pos)
{
CSector previous_sector;
if (GetMapWhoEntry())
previous_sector=mMapWhoEntry.GetSectorIn();
mOldPos = pos ;
SUPERTYPE::Teleport(pos) ;
if (GetMapWhoEntry())
{
if (mMapWhoEntry.UpdateEntry(mOldPos) && mCollisionSeekingThing)
{
mCollisionSeekingThing->MovedSector(previous_sector, mMapWhoEntry.GetSectorIn()) ;
}
}
}
//******************************************************************************************
void CActor::TeleportOrientation(const FMatrix& orientation)
{
mOldOrientation=orientation;
SUPERTYPE::TeleportOrientation(orientation);
}
//******************************************************************************************
void CActor::AddMoveEvent(CEvent* event)
{
if (!(mFlags & TF_DECLARED_SHUTDOWN))
{
mDoFullMoveCount-- ;
ActorEvent m_event = LF_MOVE ;
if (mDoFullMoveCount <=0)
{
m_event = MOVE ;
mDoFullMoveCount = (int)GetMoveMultiplier() ;
}
EVENT_MANAGER.AddEvent((int)m_event, this, NEXT_FRAME, START_OF_FRAME, NULL, (CScheduledEvent*)event);
}
}
//******************************************************************************************
void CActor::HandleEvent(CEvent* event)
{
switch( (ActorEvent)event->GetEventNum() )
{
case MOVE:
{
PROFILE_START(MoveThings) ;
Move() ;
AddMoveEvent(event);
PROFILE_END(MoveThings) ;
break ;
}
case LF_MOVE:
{
PROFILE_START(MoveThings) ;
LowFidelityMove();
AddMoveEvent(event);
PROFILE_END(MoveThings) ;
break ;
}
default:
{
SUPERTYPE::HandleEvent(event) ;
}
}
}
//******************************************************************************************
float CActor::GetFractionTime()
{
float mm = GetMoveMultiplier() ;
if ( mm > 1.0f)
{
float t = EVENT_MANAGER.GetTime() - mLastMoveTime ;
float step = 1 / GetMoveMultiplier() ;
float fraction = step * t * GAME_FR;
fraction += step * GAME.GetFrameRenderFraction();
if (fraction< 0.0f) fraction = 0.0f ;
if (fraction> 1.0f) fraction = 1.0f;
return fraction ;
}
return GAME.GetFrameRenderFraction() ;
}
//******************************************************************************************
FVector CActor::GetRenderPos()
{
return mOldPos+((mPos-mOldPos) * GAME.GetFrameRenderFraction()) ;
}
//******************************************************************************************
FMatrix CActor::GetRenderOrientation()
{
FMatrix newori;
#if TARGET == PS2
asm __volatile__
(
"
qmtc2 %9,vf31 \n
vsub %0,%3,%6 \n
vsub %1,%4,%7 \n
vsub %2,%5,%8 \n
vmulax ACC,%0,vf31 \n
vmaddw %0,%6,vf00 \n
vmulax ACC,%1,vf31 \n
vmaddw %1,%7,vf00 \n
vmulax ACC,%2,vf31 \n
vmaddw %2,%8,vf00 \n
"
: "=&j" (newori.Row[0].lVec), "=&j" (newori.Row[1].lVec), "=&j" (newori.Row[2].lVec)
: "j" (mOrientation.Row[0].lVec), "j" (mOrientation.Row[1].lVec), "j" (mOrientation.Row[2].lVec),
"j" (mOldOrientation.Row[0].lVec), "j" (mOldOrientation.Row[1].lVec), "j" (mOldOrientation.Row[2].lVec),
"r" (GetFractionTime())
: "vf31"
);
#else
newori = mOldOrientation+((mOrientation-mOldOrientation) * GetFractionTime());
#endif
// newori.Normalise();
return newori;
}
//******************************************************************************************
BOOL CActor::IsOnGround()
{
return (EVENT_MANAGER.GetTime() - mLastTimeOnGround < 0.15f);
}
//******************************************************************************************
BOOL CActor::IsInWater()
{
return (EVENT_MANAGER.GetTime() - mLastTimeInWater < 0.25f);
}
//******************************************************************************************
BOOL CActor::IsOnObject()
{
return (EVENT_MANAGER.GetTime() - mLastTimeOnObject < 0.15f);
}
//******************************************************************************************
void CActor::DeclareOnGround()
{
mLastTimeOnGround = EVENT_MANAGER.GetTime();
}
//******************************************************************************************
void CActor::DeclareInWater()
{
mLastTimeInWater = EVENT_MANAGER.GetTime();
}
//******************************************************************************************
void CActor::DeclareOnObject(CThing* on_object)
{
mLastTimeOnObject = EVENT_MANAGER.GetTime();
}
//******************************************************************************************
void CActor::StickToGround()
{
SUPERTYPE::StickToGround();
mOldPos=mPos;
}