-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
player.cpp
7162 lines (6078 loc) · 238 KB
/
player.cpp
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "T3D/player.h"
#include "platform/profiler.h"
#include "math/mMath.h"
#include "math/mathIO.h"
#include "core/resourceManager.h"
#include "core/stringTable.h"
#include "core/volume.h"
#include "core/stream/bitStream.h"
#include "console/consoleTypes.h"
#include "console/engineAPI.h"
#include "collision/extrudedPolyList.h"
#include "collision/clippedPolyList.h"
#include "collision/earlyOutPolyList.h"
#include "ts/tsShapeInstance.h"
#include "sfx/sfxSystem.h"
#include "sfx/sfxTrack.h"
#include "sfx/sfxSource.h"
#include "sfx/sfxTypes.h"
#include "scene/sceneManager.h"
#include "scene/sceneRenderState.h"
#include "T3D/gameBase/gameConnection.h"
#include "T3D/trigger.h"
#include "T3D/physicalZone.h"
#include "T3D/item.h"
#include "T3D/missionArea.h"
#include "T3D/fx/particleEmitter.h"
#include "T3D/fx/cameraFXMgr.h"
#include "T3D/fx/splash.h"
#include "T3D/tsStatic.h"
#include "T3D/physics/physicsPlugin.h"
#include "T3D/physics/physicsPlayer.h"
#include "T3D/decal/decalManager.h"
#include "T3D/decal/decalData.h"
#include "materials/baseMatInstance.h"
#ifdef TORQUE_EXTENDED_MOVE
#include "T3D/gameBase/extended/extendedMove.h"
#endif
// Amount of time if takes to transition to a new action sequence.
static F32 sAnimationTransitionTime = 0.25f;
static bool sUseAnimationTransitions = true;
static F32 sLandReverseScale = 0.25f;
static F32 sSlowStandThreshSquared = 1.69f;
static S32 sRenderMyPlayer = true;
static S32 sRenderMyItems = true;
static bool sRenderPlayerCollision = false;
// Chooses new action animations every n ticks.
static const F32 sNewAnimationTickTime = 4.0f;
static const F32 sMountPendingTickWait = 13.0f * F32(TickMs);
// Number of ticks before we pick non-contact animations
static const S32 sContactTickTime = 10;
// Movement constants
static F32 sVerticalStepDot = 0.173f; // 80
static F32 sMinFaceDistance = 0.01f;
static F32 sTractionDistance = 0.04f;
static F32 sNormalElasticity = 0.01f;
static U32 sMoveRetryCount = 5;
static F32 sMaxImpulseVelocity = 200.0f;
// Move triggers
static S32 sJumpTrigger = 2;
static S32 sCrouchTrigger = 3;
static S32 sProneTrigger = 4;
static S32 sSprintTrigger = 5;
static S32 sImageTrigger0 = 0;
static S32 sImageTrigger1 = 1;
static S32 sJumpJetTrigger = 1;
static S32 sVehicleDismountTrigger = 2;
// Client prediction
static F32 sMinWarpTicks = 0.5f; // Fraction of tick at which instant warp occurs
static S32 sMaxWarpTicks = 3; // Max warp duration in ticks
static S32 sMaxPredictionTicks = 30; // Number of ticks to predict
S32 Player::smExtendedMoveHeadPosRotIndex = 0; // The ExtendedMove position/rotation index used for head movements
// Anchor point compression
const F32 sAnchorMaxDistance = 32.0f;
//
static U32 sCollisionMoveMask = TerrainObjectType |
WaterObjectType |
PlayerObjectType |
StaticShapeObjectType |
VehicleObjectType |
PhysicalZoneObjectType;
static U32 sServerCollisionContactMask = sCollisionMoveMask |
ItemObjectType |
TriggerObjectType |
CorpseObjectType;
static U32 sClientCollisionContactMask = sCollisionMoveMask |
TriggerObjectType;
enum PlayerConstants {
JumpSkipContactsMax = 8
};
//----------------------------------------------------------------------------
// Player shape animation sequences:
// Action Animations:
PlayerData::ActionAnimationDef PlayerData::ActionAnimationList[NumTableActionAnims] =
{
// *** WARNING ***
// This array is indexed using the enum values defined in player.h
// Root is the default animation
{ "root" }, // RootAnim,
// These are selected in the move state based on velocity
{ "run", { 0.0f, 1.0f, 0.0f } }, // RunForwardAnim,
{ "back", { 0.0f,-1.0f, 0.0f } }, // BackBackwardAnim
{ "side", {-1.0f, 0.0f, 0.0f } }, // SideLeftAnim,
{ "side_right", { 1.0f, 0.0f, 0.0f } }, // SideRightAnim,
{ "sprint_root" },
{ "sprint_forward", { 0.0f, 1.0f, 0.0f } },
{ "sprint_backward", { 0.0f,-1.0f, 0.0f } },
{ "sprint_side", {-1.0f, 0.0f, 0.0f } },
{ "sprint_right", { 1.0f, 0.0f, 0.0f } },
{ "crouch_root" },
{ "crouch_forward", { 0.0f, 1.0f, 0.0f } },
{ "crouch_backward", { 0.0f,-1.0f, 0.0f } },
{ "crouch_side", {-1.0f, 0.0f, 0.0f } },
{ "crouch_right", { 1.0f, 0.0f, 0.0f } },
{ "prone_root" },
{ "prone_forward", { 0.0f, 1.0f, 0.0f } },
{ "prone_backward", { 0.0f,-1.0f, 0.0f } },
{ "swim_root" },
{ "swim_forward", { 0.0f, 1.0f, 0.0f } },
{ "swim_backward", { 0.0f,-1.0f, 0.0f } },
{ "swim_left", {-1.0f, 0.0f, 0.0f } },
{ "swim_right", { 1.0f, 0.0f, 0.0f } },
// These are set explicitly based on player actions
{ "fall" }, // FallAnim
{ "jump" }, // JumpAnim
{ "standjump" }, // StandJumpAnim
{ "land" }, // LandAnim
{ "jet" }, // JetAnim
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
IMPLEMENT_CO_DATABLOCK_V1(PlayerData);
ConsoleDocClass( PlayerData,
"@brief Defines properties for a Player object.\n\n"
"@see Player\n"
"@ingroup gameObjects\n"
);
IMPLEMENT_CALLBACK( PlayerData, onPoseChange, void, ( Player* obj, const char* oldPose, const char* newPose ), ( obj, oldPose, newPose ),
"@brief Called when the player changes poses.\n\n"
"@param obj The Player object\n"
"@param oldPose The pose the player is switching from.\n"
"@param newPose The pose the player is switching to.\n");
IMPLEMENT_CALLBACK( PlayerData, onStartSwim, void, ( Player* obj ), ( obj ),
"@brief Called when the player starts swimming.\n\n"
"@param obj The Player object\n" );
IMPLEMENT_CALLBACK( PlayerData, onStopSwim, void, ( Player* obj ), ( obj ),
"@brief Called when the player stops swimming.\n\n"
"@param obj The Player object\n" );
IMPLEMENT_CALLBACK( PlayerData, onStartSprintMotion, void, ( Player* obj ), ( obj ),
"@brief Called when the player starts moving while in a Sprint pose.\n\n"
"@param obj The Player object\n" );
IMPLEMENT_CALLBACK( PlayerData, onStopSprintMotion, void, ( Player* obj ), ( obj ),
"@brief Called when the player stops moving while in a Sprint pose.\n\n"
"@param obj The Player object\n" );
IMPLEMENT_CALLBACK( PlayerData, doDismount, void, ( Player* obj ), ( obj ),
"@brief Called when attempting to dismount the player from a vehicle.\n\n"
"It is up to the doDismount() method to actually perform the dismount. Often "
"there are some conditions that prevent this, such as the vehicle moving too fast.\n"
"@param obj The Player object\n" );
IMPLEMENT_CALLBACK( PlayerData, onEnterLiquid, void, ( Player* obj, F32 coverage, const char* type ), ( obj, coverage, type ),
"@brief Called when the player enters a liquid.\n\n"
"@param obj The Player object\n"
"@param coverage Percentage of the player's bounding box covered by the liquid\n"
"@param type The type of liquid the player has entered\n" );
IMPLEMENT_CALLBACK( PlayerData, onLeaveLiquid, void, ( Player* obj, const char* type ), ( obj, type ),
"@brief Called when the player leaves a liquid.\n\n"
"@param obj The Player object\n"
"@param type The type of liquid the player has left\n" );
IMPLEMENT_CALLBACK( PlayerData, animationDone, void, ( Player* obj ), ( obj ),
"@brief Called on the server when a scripted animation completes.\n\n"
"@param obj The Player object\n"
"@see Player::setActionThread() for setting a scripted animation and its 'hold' parameter to "
"determine if this callback is used.\n" );
IMPLEMENT_CALLBACK( PlayerData, onEnterMissionArea, void, ( Player* obj ), ( obj ),
"@brief Called when the player enters the mission area.\n\n"
"@param obj The Player object\n"
"@see MissionArea\n" );
IMPLEMENT_CALLBACK( PlayerData, onLeaveMissionArea, void, ( Player* obj ), ( obj ),
"@brief Called when the player leaves the mission area.\n"
"@param obj The Player object\n"
"@see MissionArea\n" );
PlayerData::PlayerData()
{
shadowEnable = true;
shadowSize = 256;
shadowProjectionDistance = 14.0f;
renderFirstPerson = true;
firstPersonShadows = false;
// Used for third person image rendering
imageAnimPrefix = StringTable->insert("");
allowImageStateAnimation = false;
// Used for first person image rendering
imageAnimPrefixFP = StringTable->insert("");
for (U32 i=0; i<ShapeBase::MaxMountedImages; ++i)
{
shapeNameFP[i] = StringTable->insert("");
mCRCFP[i] = 0;
mValidShapeFP[i] = false;
}
pickupRadius = 0.0f;
minLookAngle = -1.4f;
maxLookAngle = 1.4f;
maxFreelookAngle = 3.0f;
maxTimeScale = 1.5f;
mass = 9.0f; // from ShapeBase
maxEnergy = 60.0f; // from ShapeBase
drag = 0.3f; // from ShapeBase
density = 1.1f; // from ShapeBase
maxStepHeight = 1.0f;
runSurfaceAngle = 80.0f;
fallingSpeedThreshold = -10.0f;
recoverDelay = 30;
recoverRunForceScale = 1.0f;
landSequenceTime = 0.0f;
transitionToLand = false;
// Running/Walking
runForce = 40.0f * 9.0f;
runEnergyDrain = 0.0f;
minRunEnergy = 0.0f;
maxForwardSpeed = 10.0f;
maxBackwardSpeed = 10.0f;
maxSideSpeed = 10.0f;
// Jumping
jumpForce = 75.0f;
jumpEnergyDrain = 0.0f;
minJumpEnergy = 0.0f;
jumpSurfaceAngle = 78.0f;
jumpDelay = 30;
minJumpSpeed = 500.0f;
maxJumpSpeed = 2.0f * minJumpSpeed;
// Sprinting
sprintForce = 50.0f * 9.0f;
sprintEnergyDrain = 0.0f;
minSprintEnergy = 0.0f;
maxSprintForwardSpeed = 15.0f;
maxSprintBackwardSpeed = 10.0f;
maxSprintSideSpeed = 10.0f;
sprintStrafeScale = 1.0f;
sprintYawScale = 1.0f;
sprintPitchScale = 1.0f;
sprintCanJump = true;
// Swimming
swimForce = 55.0f * 9.0f;
maxUnderwaterForwardSpeed = 6.0f;
maxUnderwaterBackwardSpeed = 6.0f;
maxUnderwaterSideSpeed = 6.0f;
// Crouching
crouchForce = 45.0f * 9.0f;
maxCrouchForwardSpeed = 4.0f;
maxCrouchBackwardSpeed = 4.0f;
maxCrouchSideSpeed = 4.0f;
// Prone
proneForce = 45.0f * 9.0f;
maxProneForwardSpeed = 2.0f;
maxProneBackwardSpeed = 2.0f;
maxProneSideSpeed = 0.0f;
// Jetting
jetJumpForce = 0;
jetJumpEnergyDrain = 0;
jetMinJumpEnergy = 0;
jetJumpSurfaceAngle = 78;
jetMinJumpSpeed = 20;
jetMaxJumpSpeed = 100;
horizMaxSpeed = 80.0f;
horizResistSpeed = 38.0f;
horizResistFactor = 1.0f;
upMaxSpeed = 80.0f;
upResistSpeed = 38.0f;
upResistFactor = 1.0f;
minImpactSpeed = 25.0f;
minLateralImpactSpeed = 25.0f;
decalData = NULL;
decalID = 0;
decalOffset = 0.0f;
actionCount = 0;
lookAction = 0;
// size of bounding box
boxSize.set(1.0f, 1.0f, 2.3f);
crouchBoxSize.set(1.0f, 1.0f, 2.0f);
proneBoxSize.set(1.0f, 2.3f, 1.0f);
swimBoxSize.set(1.0f, 2.3f, 1.0f);
// location of head, torso, legs
boxHeadPercentage = 0.85f;
boxTorsoPercentage = 0.55f;
// damage locations
boxHeadLeftPercentage = 0;
boxHeadRightPercentage = 1;
boxHeadBackPercentage = 0;
boxHeadFrontPercentage = 1;
for (S32 i = 0; i < MaxSounds; i++)
sound[i] = NULL;
footPuffEmitter = NULL;
footPuffID = 0;
footPuffNumParts = 15;
footPuffRadius = .25f;
dustEmitter = NULL;
dustID = 0;
splash = NULL;
splashId = 0;
splashVelocity = 1.0f;
splashAngle = 45.0f;
splashFreqMod = 300.0f;
splashVelEpsilon = 0.25f;
bubbleEmitTime = 0.4f;
medSplashSoundVel = 2.0f;
hardSplashSoundVel = 3.0f;
exitSplashSoundVel = 2.0f;
footSplashHeight = 0.1f;
dMemset( splashEmitterList, 0, sizeof( splashEmitterList ) );
dMemset( splashEmitterIDList, 0, sizeof( splashEmitterIDList ) );
groundImpactMinSpeed = 10.0f;
groundImpactShakeFreq.set( 10.0f, 10.0f, 10.0f );
groundImpactShakeAmp.set( 20.0f, 20.0f, 20.0f );
groundImpactShakeDuration = 1.0f;
groundImpactShakeFalloff = 10.0f;
// Air control
airControl = 0.0f;
jumpTowardsNormal = true;
physicsPlayerType = StringTable->insert("");
dMemset( actionList, 0, sizeof(actionList) );
}
bool PlayerData::preload(bool server, String &errorStr)
{
if(!Parent::preload(server, errorStr))
return false;
// Resolve objects transmitted from server
if( !server )
{
for( U32 i = 0; i < MaxSounds; ++ i )
{
String sfxErrorStr;
if( !sfxResolve( &sound[ i ], sfxErrorStr ) )
Con::errorf( "PlayerData::preload: %s", sfxErrorStr.c_str() );
}
}
//
runSurfaceCos = mCos(mDegToRad(runSurfaceAngle));
jumpSurfaceCos = mCos(mDegToRad(jumpSurfaceAngle));
if (minJumpEnergy < jumpEnergyDrain)
minJumpEnergy = jumpEnergyDrain;
// Jetting
if (jetMinJumpEnergy < jetJumpEnergyDrain)
jetMinJumpEnergy = jetJumpEnergyDrain;
// Validate some of the data
if (fallingSpeedThreshold > 0.0f)
Con::printf("PlayerData:: Falling speed threshold should be downwards (negative)");
if (recoverDelay > (1 << RecoverDelayBits) - 1) {
recoverDelay = (1 << RecoverDelayBits) - 1;
Con::printf("PlayerData:: Recover delay exceeds range (0-%d)",recoverDelay);
}
if (jumpDelay > (1 << JumpDelayBits) - 1) {
jumpDelay = (1 << JumpDelayBits) - 1;
Con::printf("PlayerData:: Jump delay exceeds range (0-%d)",jumpDelay);
}
// If we don't have a shape don't crash out trying to
// setup animations and sequences.
if ( mShape )
{
// Go ahead a pre-load the player shape
TSShapeInstance* si = new TSShapeInstance(mShape, false);
TSThread* thread = si->addThread();
// Extract ground transform velocity from animations
// Get the named ones first so they can be indexed directly.
ActionAnimation *dp = &actionList[0];
for (S32 i = 0; i < NumTableActionAnims; i++,dp++)
{
ActionAnimationDef *sp = &ActionAnimationList[i];
dp->name = sp->name;
dp->dir.set(sp->dir.x,sp->dir.y,sp->dir.z);
dp->sequence = mShape->findSequence(sp->name);
// If this is a sprint action and is missing a sequence, attempt to use
// the standard run ones.
if(dp->sequence == -1 && i >= SprintRootAnim && i <= SprintRightAnim)
{
S32 offset = i-SprintRootAnim;
ActionAnimationDef *standDef = &ActionAnimationList[RootAnim+offset];
dp->sequence = mShape->findSequence(standDef->name);
}
dp->velocityScale = true;
dp->death = false;
if (dp->sequence != -1)
getGroundInfo(si,thread,dp);
}
for (S32 b = 0; b < mShape->sequences.size(); b++)
{
if (!isTableSequence(b))
{
dp->sequence = b;
dp->name = mShape->getName(mShape->sequences[b].nameIndex);
dp->velocityScale = false;
getGroundInfo(si,thread,dp++);
}
}
actionCount = dp - actionList;
AssertFatal(actionCount <= NumActionAnims, "Too many action animations!");
delete si;
// Resolve lookAction index
dp = &actionList[0];
String lookName("look");
for (S32 c = 0; c < actionCount; c++,dp++)
if( dStricmp( dp->name, lookName ) == 0 )
lookAction = c;
// Resolve spine
spineNode[0] = mShape->findNode("Bip01 Pelvis");
spineNode[1] = mShape->findNode("Bip01 Spine");
spineNode[2] = mShape->findNode("Bip01 Spine1");
spineNode[3] = mShape->findNode("Bip01 Spine2");
spineNode[4] = mShape->findNode("Bip01 Neck");
spineNode[5] = mShape->findNode("Bip01 Head");
// Recoil animations
recoilSequence[0] = mShape->findSequence("light_recoil");
recoilSequence[1] = mShape->findSequence("medium_recoil");
recoilSequence[2] = mShape->findSequence("heavy_recoil");
}
// Convert pickupRadius to a delta of boundingBox
//
// NOTE: it is not really correct to precalculate a pickupRadius based
// on boxSize since the actual player's bounds can vary by "pose".
//
F32 dr = (boxSize.x > boxSize.y)? boxSize.x: boxSize.y;
if (pickupRadius < dr)
pickupRadius = dr;
else
if (pickupRadius > 2.0f * dr)
pickupRadius = 2.0f * dr;
pickupDelta = (S32)(pickupRadius - dr);
// Validate jump speed
if (maxJumpSpeed <= minJumpSpeed)
maxJumpSpeed = minJumpSpeed + 0.1f;
// Load up all the emitters
if (!footPuffEmitter && footPuffID != 0)
if (!Sim::findObject(footPuffID, footPuffEmitter))
Con::errorf(ConsoleLogEntry::General, "PlayerData::preload - Invalid packet, bad datablockId(footPuffEmitter): 0x%x", footPuffID);
if (!decalData && decalID != 0 )
if (!Sim::findObject(decalID, decalData))
Con::errorf(ConsoleLogEntry::General, "PlayerData::preload Invalid packet, bad datablockId(decalData): 0x%x", decalID);
if (!dustEmitter && dustID != 0 )
if (!Sim::findObject(dustID, dustEmitter))
Con::errorf(ConsoleLogEntry::General, "PlayerData::preload - Invalid packet, bad datablockId(dustEmitter): 0x%x", dustID);
for (S32 i=0; i<NUM_SPLASH_EMITTERS; i++)
if( !splashEmitterList[i] && splashEmitterIDList[i] != 0 )
if( Sim::findObject( splashEmitterIDList[i], splashEmitterList[i] ) == false)
Con::errorf(ConsoleLogEntry::General, "PlayerData::onAdd - Invalid packet, bad datablockId(particle emitter): 0x%x", splashEmitterIDList[i]);
// First person mounted image shapes.
for (U32 i=0; i<ShapeBase::MaxMountedImages; ++i)
{
bool shapeError = false;
if (shapeNameFP[i] && shapeNameFP[i][0])
{
mShapeFP[i] = ResourceManager::get().load(shapeNameFP[i]);
if (bool(mShapeFP[i]) == false)
{
errorStr = String::ToString("PlayerData: Couldn't load mounted image %d shape \"%s\"",i,shapeNameFP[i]);
return false;
}
if(!server && !mShapeFP[i]->preloadMaterialList(mShapeFP[i].getPath()) && NetConnection::filesWereDownloaded())
shapeError = true;
if(computeCRC)
{
Con::printf("Validation required for mounted image %d shape: %s", i, shapeNameFP[i]);
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(mShapeFP[i].getPath());
if (!fileRef)
{
errorStr = String::ToString("PlayerData: Mounted image %d loading failed, shape \"%s\" is not found.",i,mShapeFP[i].getPath().getFullPath().c_str());
return false;
}
if(server)
mCRCFP[i] = fileRef->getChecksum();
else if(mCRCFP[i] != fileRef->getChecksum())
{
errorStr = String::ToString("PlayerData: Mounted image %d shape \"%s\" does not match version on server.",i,shapeNameFP[i]);
return false;
}
}
mValidShapeFP[i] = true;
}
}
return true;
}
void PlayerData::getGroundInfo(TSShapeInstance* si, TSThread* thread,ActionAnimation *dp)
{
dp->death = !dStrnicmp(dp->name, "death", 5);
if (dp->death)
{
// Death animations use roll frame-to-frame changes in ground transform into position
dp->speed = 0.0f;
dp->dir.set(0.0f, 0.0f, 0.0f);
// Death animations MUST define ground transforms, so add dummy ones if required
if (si->getShape()->sequences[dp->sequence].numGroundFrames == 0)
si->getShape()->setSequenceGroundSpeed(dp->name, Point3F(0, 0, 0), Point3F(0, 0, 0));
}
else
{
VectorF save = dp->dir;
si->setSequence(thread,dp->sequence,0);
si->animate();
si->advanceTime(1);
si->animateGround();
si->getGroundTransform().getColumn(3,&dp->dir);
if ((dp->speed = dp->dir.len()) < 0.01f)
{
// No ground displacement... In this case we'll use the
// default table entry, if there is one.
if (save.len() > 0.01f)
{
dp->dir = save;
dp->speed = 1.0f;
dp->velocityScale = false;
}
else
dp->speed = 0.0f;
}
else
dp->dir *= 1.0f / dp->speed;
}
}
bool PlayerData::isTableSequence(S32 seq)
{
// The sequences from the table must already have
// been loaded for this to work.
for (S32 i = 0; i < NumTableActionAnims; i++)
if (actionList[i].sequence == seq)
return true;
return false;
}
bool PlayerData::isJumpAction(U32 action)
{
return (action == JumpAnim || action == StandJumpAnim);
}
void PlayerData::initPersistFields()
{
addField( "pickupRadius", TypeF32, Offset(pickupRadius, PlayerData),
"@brief Radius around the player to collide with Items in the scene (on server).\n\n"
"Internally the pickupRadius is added to the larger side of the initial bounding box "
"to determine the actual distance, to a maximum of 2 times the bounding box size. The "
"initial bounding box is that used for the root pose, and therefore doesn't take into "
"account the change in pose.\n");
addField( "maxTimeScale", TypeF32, Offset(maxTimeScale, PlayerData),
"@brief Maximum time scale for action animations.\n\n"
"If an action animation has a defined ground frame, it is automatically scaled to match the "
"player's ground velocity. This field limits the maximum time scale used even if "
"the player's velocity exceeds it." );
addGroup( "Camera" );
addField( "renderFirstPerson", TypeBool, Offset(renderFirstPerson, PlayerData),
"@brief Flag controlling whether to render the player shape in first person view.\n\n" );
addField( "firstPersonShadows", TypeBool, Offset(firstPersonShadows, PlayerData),
"@brief Forces shadows to be rendered in first person when renderFirstPerson is disabled. Defaults to false.\n\n" );
addField( "minLookAngle", TypeF32, Offset(minLookAngle, PlayerData),
"@brief Lowest angle (in radians) the player can look.\n\n"
"@note An angle of zero is straight ahead, with positive up and negative down." );
addField( "maxLookAngle", TypeF32, Offset(maxLookAngle, PlayerData),
"@brief Highest angle (in radians) the player can look.\n\n"
"@note An angle of zero is straight ahead, with positive up and negative down." );
addField( "maxFreelookAngle", TypeF32, Offset(maxFreelookAngle, PlayerData),
"@brief Defines the maximum left and right angles (in radians) the player can "
"look in freelook mode.\n\n" );
endGroup( "Camera" );
addGroup( "Movement" );
addField( "maxStepHeight", TypeF32, Offset(maxStepHeight, PlayerData),
"@brief Maximum height the player can step up.\n\n"
"The player will automatically step onto changes in ground height less "
"than maxStepHeight. The player will collide with ground height changes "
"greater than this." );
addField( "runForce", TypeF32, Offset(runForce, PlayerData),
"@brief Force used to accelerate the player when running.\n\n" );
addField( "runEnergyDrain", TypeF32, Offset(runEnergyDrain, PlayerData),
"@brief Energy value drained each tick that the player is moving.\n\n"
"The player will not be able to move when his energy falls below "
"minRunEnergy.\n"
"@note Setting this to zero will disable any energy drain.\n"
"@see minRunEnergy\n");
addField( "minRunEnergy", TypeF32, Offset(minRunEnergy, PlayerData),
"@brief Minimum energy level required to run or swim.\n\n"
"@see runEnergyDrain\n");
addField( "maxForwardSpeed", TypeF32, Offset(maxForwardSpeed, PlayerData),
"@brief Maximum forward speed when running." );
addField( "maxBackwardSpeed", TypeF32, Offset(maxBackwardSpeed, PlayerData),
"@brief Maximum backward speed when running." );
addField( "maxSideSpeed", TypeF32, Offset(maxSideSpeed, PlayerData),
"@brief Maximum sideways speed when running." );
addField( "runSurfaceAngle", TypeF32, Offset(runSurfaceAngle, PlayerData),
"@brief Maximum angle from vertical (in degrees) the player can run up.\n\n" );
addField( "minImpactSpeed", TypeF32, Offset(minImpactSpeed, PlayerData),
"@brief Minimum impact speed to apply falling damage.\n\n"
"This field also sets the minimum speed for the onImpact callback "
"to be invoked.\n"
"@see ShapeBaseData::onImpact()\n");
addField( "minLateralImpactSpeed", TypeF32, Offset(minLateralImpactSpeed, PlayerData),
"@brief Minimum impact speed to apply non-falling damage.\n\n"
"This field also sets the minimum speed for the onLateralImpact callback "
"to be invoked.\n"
"@see ShapeBaseData::onLateralImpact()\n");
addField( "horizMaxSpeed", TypeF32, Offset(horizMaxSpeed, PlayerData),
"@brief Maximum horizontal speed.\n\n"
"@note This limit is only enforced if the player's horizontal speed "
"exceeds horizResistSpeed.\n"
"@see horizResistSpeed\n"
"@see horizResistFactor\n" );
addField( "horizResistSpeed", TypeF32, Offset(horizResistSpeed, PlayerData),
"@brief Horizontal speed at which resistence will take place.\n\n"
"@see horizMaxSpeed\n"
"@see horizResistFactor\n" );
addField( "horizResistFactor", TypeF32, Offset(horizResistFactor, PlayerData),
"@brief Factor of resistence once horizResistSpeed has been reached.\n\n"
"@see horizMaxSpeed\n"
"@see horizResistSpeed\n" );
addField( "upMaxSpeed", TypeF32, Offset(upMaxSpeed, PlayerData),
"@brief Maximum upwards speed.\n\n"
"@note This limit is only enforced if the player's upward speed exceeds "
"upResistSpeed.\n"
"@see upResistSpeed\n"
"@see upResistFactor\n" );
addField( "upResistSpeed", TypeF32, Offset(upResistSpeed, PlayerData),
"@brief Upwards speed at which resistence will take place.\n\n"
"@see upMaxSpeed\n"
"@see upResistFactor\n" );
addField( "upResistFactor", TypeF32, Offset(upResistFactor, PlayerData),
"@brief Factor of resistence once upResistSpeed has been reached.\n\n"
"@see upMaxSpeed\n"
"@see upResistSpeed\n" );
endGroup( "Movement" );
addGroup( "Movement: Jumping" );
addField( "jumpForce", TypeF32, Offset(jumpForce, PlayerData),
"@brief Force used to accelerate the player when a jump is initiated.\n\n" );
addField( "jumpEnergyDrain", TypeF32, Offset(jumpEnergyDrain, PlayerData),
"@brief Energy level drained each time the player jumps.\n\n"
"@note Setting this to zero will disable any energy drain\n"
"@see minJumpEnergy\n");
addField( "minJumpEnergy", TypeF32, Offset(minJumpEnergy, PlayerData),
"@brief Minimum energy level required to jump.\n\n"
"@see jumpEnergyDrain\n");
addField( "minJumpSpeed", TypeF32, Offset(minJumpSpeed, PlayerData),
"@brief Minimum speed needed to jump.\n\n"
"If the player's own z velocity is greater than this, then it is used to scale "
"the jump speed, up to maxJumpSpeed.\n"
"@see maxJumpSpeed\n");
addField( "maxJumpSpeed", TypeF32, Offset(maxJumpSpeed, PlayerData),
"@brief Maximum vertical speed before the player can no longer jump.\n\n" );
addField( "jumpSurfaceAngle", TypeF32, Offset(jumpSurfaceAngle, PlayerData),
"@brief Angle from vertical (in degrees) where the player can jump.\n\n" );
addField( "jumpDelay", TypeS32, Offset(jumpDelay, PlayerData),
"@brief Delay time in number of ticks ticks between jumps.\n\n" );
addField( "airControl", TypeF32, Offset(airControl, PlayerData),
"@brief Amount of movement control the player has when in the air.\n\n"
"This is applied as a multiplier to the player's x and y motion.\n");
addField( "jumpTowardsNormal", TypeBool, Offset(jumpTowardsNormal, PlayerData),
"@brief Controls the direction of the jump impulse.\n"
"When false, jumps are always in the vertical (+Z) direction. When true "
"jumps are in the direction of the ground normal so long as the player is not "
"directly facing the surface. If the player is directly facing the surface, then "
"they will jump straight up.\n" );
endGroup( "Movement: Jumping" );
addGroup( "Movement: Sprinting" );
addField( "sprintForce", TypeF32, Offset(sprintForce, PlayerData),
"@brief Force used to accelerate the player when sprinting.\n\n" );
addField( "sprintEnergyDrain", TypeF32, Offset(sprintEnergyDrain, PlayerData),
"@brief Energy value drained each tick that the player is sprinting.\n\n"
"The player will not be able to move when his energy falls below "
"sprintEnergyDrain.\n"
"@note Setting this to zero will disable any energy drain.\n"
"@see minSprintEnergy\n");
addField( "minSprintEnergy", TypeF32, Offset(minSprintEnergy, PlayerData),
"@brief Minimum energy level required to sprint.\n\n"
"@see sprintEnergyDrain\n");
addField( "maxSprintForwardSpeed", TypeF32, Offset(maxSprintForwardSpeed, PlayerData),
"@brief Maximum forward speed when sprinting." );
addField( "maxSprintBackwardSpeed", TypeF32, Offset(maxSprintBackwardSpeed, PlayerData),
"@brief Maximum backward speed when sprinting." );
addField( "maxSprintSideSpeed", TypeF32, Offset(maxSprintSideSpeed, PlayerData),
"@brief Maximum sideways speed when sprinting." );
addField( "sprintStrafeScale", TypeF32, Offset(sprintStrafeScale, PlayerData),
"@brief Amount to scale strafing motion vector while sprinting." );
addField( "sprintYawScale", TypeF32, Offset(sprintYawScale, PlayerData),
"@brief Amount to scale yaw motion while sprinting." );
addField( "sprintPitchScale", TypeF32, Offset(sprintPitchScale, PlayerData),
"@brief Amount to scale pitch motion while sprinting." );
addField( "sprintCanJump", TypeBool, Offset(sprintCanJump, PlayerData),
"@brief Can the player jump while sprinting." );
endGroup( "Movement: Sprinting" );
addGroup( "Movement: Swimming" );
addField( "swimForce", TypeF32, Offset(swimForce, PlayerData),
"@brief Force used to accelerate the player when swimming.\n\n" );
addField( "maxUnderwaterForwardSpeed", TypeF32, Offset(maxUnderwaterForwardSpeed, PlayerData),
"@brief Maximum forward speed when underwater.\n\n" );
addField( "maxUnderwaterBackwardSpeed", TypeF32, Offset(maxUnderwaterBackwardSpeed, PlayerData),
"@brief Maximum backward speed when underwater.\n\n" );
addField( "maxUnderwaterSideSpeed", TypeF32, Offset(maxUnderwaterSideSpeed, PlayerData),
"@brief Maximum sideways speed when underwater.\n\n" );
endGroup( "Movement: Swimming" );
addGroup( "Movement: Crouching" );
addField( "crouchForce", TypeF32, Offset(crouchForce, PlayerData),
"@brief Force used to accelerate the player when crouching.\n\n" );
addField( "maxCrouchForwardSpeed", TypeF32, Offset(maxCrouchForwardSpeed, PlayerData),
"@brief Maximum forward speed when crouching.\n\n" );
addField( "maxCrouchBackwardSpeed", TypeF32, Offset(maxCrouchBackwardSpeed, PlayerData),
"@brief Maximum backward speed when crouching.\n\n" );
addField( "maxCrouchSideSpeed", TypeF32, Offset(maxCrouchSideSpeed, PlayerData),
"@brief Maximum sideways speed when crouching.\n\n" );
endGroup( "Movement: Crouching" );
addGroup( "Movement: Prone" );
addField( "proneForce", TypeF32, Offset(proneForce, PlayerData),
"@brief Force used to accelerate the player when prone (laying down).\n\n" );
addField( "maxProneForwardSpeed", TypeF32, Offset(maxProneForwardSpeed, PlayerData),
"@brief Maximum forward speed when prone (laying down).\n\n" );
addField( "maxProneBackwardSpeed", TypeF32, Offset(maxProneBackwardSpeed, PlayerData),
"@brief Maximum backward speed when prone (laying down).\n\n" );
addField( "maxProneSideSpeed", TypeF32, Offset(maxProneSideSpeed, PlayerData),
"@brief Maximum sideways speed when prone (laying down).\n\n" );
endGroup( "Movement: Prone" );
addGroup( "Movement: Jetting" );
addField( "jetJumpForce", TypeF32, Offset(jetJumpForce, PlayerData),
"@brief Force used to accelerate the player when a jet jump is initiated.\n\n" );
addField( "jetJumpEnergyDrain", TypeF32, Offset(jetJumpEnergyDrain, PlayerData),
"@brief Energy level drained each time the player jet jumps.\n\n"
"@note Setting this to zero will disable any energy drain\n"
"@see jetMinJumpEnergy\n");
addField( "jetMinJumpEnergy", TypeF32, Offset(jetMinJumpEnergy, PlayerData),
"@brief Minimum energy level required to jet jump.\n\n"
"@see jetJumpEnergyDrain\n");
addField( "jetMinJumpSpeed", TypeF32, Offset(jetMinJumpSpeed, PlayerData),
"@brief Minimum speed needed to jet jump.\n\n"
"If the player's own z velocity is greater than this, then it is used to scale "
"the jet jump speed, up to jetMaxJumpSpeed.\n"
"@see jetMaxJumpSpeed\n");
addField( "jetMaxJumpSpeed", TypeF32, Offset(jetMaxJumpSpeed, PlayerData),
"@brief Maximum vertical speed before the player can no longer jet jump.\n\n" );
addField( "jetJumpSurfaceAngle", TypeF32, Offset(jetJumpSurfaceAngle, PlayerData),
"@brief Angle from vertical (in degrees) where the player can jet jump.\n\n" );
endGroup( "Movement: Jetting" );
addGroup( "Falling" );
addField( "fallingSpeedThreshold", TypeF32, Offset(fallingSpeedThreshold, PlayerData),
"@brief Downward speed at which we consider the player falling.\n\n" );
addField( "recoverDelay", TypeS32, Offset(recoverDelay, PlayerData),
"@brief Number of ticks for the player to recover from falling.\n\n" );
addField( "recoverRunForceScale", TypeF32, Offset(recoverRunForceScale, PlayerData),
"@brief Scale factor applied to runForce while in the recover state.\n\n"
"This can be used to temporarily slow the player's movement after a fall, or "
"prevent the player from moving at all if set to zero.\n" );
addField( "landSequenceTime", TypeF32, Offset(landSequenceTime, PlayerData),
"@brief Time of land sequence play back when using new recover system.\n\n"
"If greater than 0 then the legacy fall recovery system will be bypassed "
"in favour of just playing the player's land sequence. The time to "
"recover from a fall then becomes this parameter's time and the land "
"sequence's playback will be scaled to match.\n"
"@see transitionToLand\n" );
addField( "transitionToLand", TypeBool, Offset(transitionToLand, PlayerData),
"@brief When going from a fall to a land, should we transition between the two.\n\n"
"@note Only takes affect when landSequenceTime is greater than 0.\n"
"@see landSequenceTime\n" );
endGroup( "Falling" );
addGroup( "Collision" );
addField( "boundingBox", TypePoint3F, Offset(boxSize, PlayerData),
"@brief Size of the bounding box used by the player for collision.\n\n"
"Dimensions are given as \"width depth height\"." );
addField( "crouchBoundingBox", TypePoint3F, Offset(crouchBoxSize, PlayerData),
"@brief Collision bounding box used when the player is crouching.\n\n"
"@see boundingBox" );
addField( "proneBoundingBox", TypePoint3F, Offset(proneBoxSize, PlayerData),
"@brief Collision bounding box used when the player is prone (laying down).\n\n"
"@see boundingBox" );
addField( "swimBoundingBox", TypePoint3F, Offset(swimBoxSize, PlayerData),
"@brief Collision bounding box used when the player is swimming.\n\n"
"@see boundingBox" );
addField( "boxHeadPercentage", TypeF32, Offset(boxHeadPercentage, PlayerData),
"@brief Percentage of the player's bounding box height that represents the head.\n\n"
"Used when computing the damage location.\n"
"@see Player::getDamageLocation" );
addField( "boxTorsoPercentage", TypeF32, Offset(boxTorsoPercentage, PlayerData),
"@brief Percentage of the player's bounding box height that represents the torso.\n\n"
"Used when computing the damage location.\n"
"@see Player::getDamageLocation" );
addField( "boxHeadLeftPercentage", TypeF32, Offset(boxHeadLeftPercentage, PlayerData),
"@brief Percentage of the player's bounding box width that represents the left side of the head.\n\n"
"Used when computing the damage location.\n"
"@see Player::getDamageLocation" );
addField( "boxHeadRightPercentage", TypeF32, Offset(boxHeadRightPercentage, PlayerData),
"@brief Percentage of the player's bounding box width that represents the right side of the head.\n\n"
"Used when computing the damage location.\n"
"@see Player::getDamageLocation" );
addField( "boxHeadBackPercentage", TypeF32, Offset(boxHeadBackPercentage, PlayerData),
"@brief Percentage of the player's bounding box depth that represents the back side of the head.\n\n"
"Used when computing the damage location.\n"
"@see Player::getDamageLocation" );
addField( "boxHeadFrontPercentage", TypeF32, Offset(boxHeadFrontPercentage, PlayerData),
"@brief Percentage of the player's bounding box depth that represents the front side of the head.\n\n"
"Used when computing the damage location.\n"
"@see Player::getDamageLocation" );
endGroup( "Collision" );
addGroup( "Interaction: Footsteps" );
addField( "footPuffEmitter", TYPEID< ParticleEmitterData >(), Offset(footPuffEmitter, PlayerData),
"@brief Particle emitter used to generate footpuffs (particles created as the player "
"walks along the ground).\n\n"
"@note The generation of foot puffs requires the appropriate triggeres to be defined in the "
"player's animation sequences. Without these, no foot puffs will be generated.\n");
addField( "footPuffNumParts", TypeS32, Offset(footPuffNumParts, PlayerData),
"@brief Number of footpuff particles to generate each step.\n\n"
"Each foot puff is randomly placed within the defined foot puff radius. This "
"includes having footPuffNumParts set to one.\n"
"@see footPuffRadius\n");
addField( "footPuffRadius", TypeF32, Offset(footPuffRadius, PlayerData),
"@brief Particle creation radius for footpuff particles.\n\n"
"This is applied to each foot puff particle, even if footPuffNumParts is set to one. So "
"set this value to zero if you want a single foot puff placed at exactly the same location "
"under the player each time.\n");
addField( "dustEmitter", TYPEID< ParticleEmitterData >(), Offset(dustEmitter, PlayerData),
"@brief Emitter used to generate dust particles.\n\n"
"@note Currently unused." );
addField( "decalData", TYPEID< DecalData >(), Offset(decalData, PlayerData),
"@brief Decal to place on the ground for player footsteps.\n\n" );
addField( "decalOffset",TypeF32, Offset(decalOffset, PlayerData),
"@brief Distance from the center of the model to the right foot.\n\n"
"While this defines the distance to the right foot, it is also used to place "
"the left foot decal as well. Just on the opposite side of the player." );