player.h
Classes:
class
class
class
class
class
Client interpolation/warp data.
class
class
Animation and other data initialized in onAdd.
Public Typedefs
PlayerPose
Public Functions
Detailed Description
Public Typedefs
typedef Player::Pose PlayerPose
Public Functions
DefineEnumType(PlayerPose )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _PLAYER_H_ 25#define _PLAYER_H_ 26 27#ifndef _SHAPEBASE_H_ 28#include "T3D/shapeBase.h" 29#endif 30#ifndef _BOXCONVEX_H_ 31#include "collision/boxConvex.h" 32#endif 33 34#include "T3D/gameBase/gameProcess.h" 35 36class Material; 37class ParticleEmitter; 38class ParticleEmitterData; 39class DecalData; 40class SplashData; 41class PhysicsPlayer; 42class Player; 43 44#ifdef TORQUE_OPENVR 45class OpenVRTrackedObject; 46#endif 47 48//---------------------------------------------------------------------------- 49 50struct PlayerData: public ShapeBaseData { 51 typedef ShapeBaseData Parent; 52 enum Constants { 53 RecoverDelayBits = 7, 54 JumpDelayBits = 7, 55 NumSpineNodes = 6, 56 ImpactBits = 3, 57 NUM_SPLASH_EMITTERS = 3, 58 BUBBLE_EMITTER = 2, 59 }; 60 bool renderFirstPerson; ///< Render the player shape in first person 61 62 /// Render shadows while in first person when 63 /// renderFirstPerson is disabled. 64 bool firstPersonShadows; 65 66 StringTableEntry imageAnimPrefix; ///< Passed along to mounted images to modify 67 /// animation sequences played in third person. [optional] 68 bool allowImageStateAnimation; ///< When true a new thread is added to the player to allow for 69 /// mounted images to request a sequence be played on the player 70 /// through the image's state machine. It is only optional so 71 /// that we don't create a TSThread on the player if we don't 72 /// need to. 73 74 StringTableEntry shapeNameFP[ShapeBase::MaxMountedImages]; ///< Used to render with mounted images in first person [optional] 75 StringTableEntry imageAnimPrefixFP; ///< Passed along to mounted images to modify 76 /// animation sequences played in first person. [optional] 77 Resource<TSShape> mShapeFP[ShapeBase::MaxMountedImages]; ///< First person mounted image shape resources [optional] 78 U32 mCRCFP[ShapeBase::MaxMountedImages]; ///< Computed CRC values for the first person mounted image shapes 79 /// Depends on the ShapeBaseData computeCRC field. 80 bool mValidShapeFP[ShapeBase::MaxMountedImages]; ///< Indicates that there is a valid first person mounted image shape 81 82 F32 pickupRadius; ///< Radius around player for items (on server) 83 F32 maxTimeScale; ///< Max timeScale for action animations 84 85 F32 minLookAngle; ///< Lowest angle (radians) the player can look 86 F32 maxLookAngle; ///< Highest angle (radians) the player can look 87 F32 maxFreelookAngle; ///< Max left/right angle the player can look 88 89 /// @name Physics constants 90 /// @{ 91 92 F32 maxStepHeight; ///< Maximum height the player can step up 93 F32 runSurfaceAngle; ///< Maximum angle from vertical in degrees the player can run up 94 95 F32 horizMaxSpeed; ///< Max speed attainable in the horizontal 96 F32 horizResistSpeed; ///< Speed at which resistance will take place 97 F32 horizResistFactor; ///< Factor of resistance once horizResistSpeed has been reached 98 99 F32 upMaxSpeed; ///< Max vertical speed attainable 100 F32 upResistSpeed; ///< Speed at which resistance will take place 101 F32 upResistFactor; ///< Factor of resistance once upResistSpeed has been reached 102 103 F32 fallingSpeedThreshold; ///< Downward speed at which we consider the player falling 104 105 S32 recoverDelay; ///< # tick 106 F32 recoverRunForceScale; ///< RunForce multiplier in recover state 107 F32 landSequenceTime; ///< If greater than 0 then the legacy fall recovery system will be bypassed 108 /// in favour of just playing the player's land sequence. The time to 109 /// recover from a fall then becomes this parameter's time and the land 110 /// sequence's playback will be scaled to match. 111 bool transitionToLand; ///< When going from a fall to a land, should we transition between the two? 112 113 // Running/Walking 114 F32 runForce; ///< Force used to accelerate player 115 F32 runEnergyDrain; ///< Energy drain/tick 116 F32 minRunEnergy; ///< Minimum energy required to run 117 F32 maxForwardSpeed; ///< Maximum forward speed when running 118 F32 maxBackwardSpeed; ///< Maximum backward speed when running 119 F32 maxSideSpeed; ///< Maximum side speed when running 120 121 // Jumping 122 F32 jumpForce; ///< Force exerted per jump 123 F32 jumpEnergyDrain; ///< Energy drained per jump 124 F32 minJumpEnergy; ///< Minimum energy required to jump 125 F32 minJumpSpeed; ///< Minimum speed needed to jump 126 F32 maxJumpSpeed; ///< Maximum speed before the player can no longer jump 127 F32 jumpSurfaceAngle; ///< Angle from vertical in degrees where the player can jump 128 S32 jumpDelay; ///< Delay time in ticks between jumps 129 130 // Sprinting 131 F32 sprintForce; ///< Force used to accelerate player 132 F32 sprintEnergyDrain; ///< Energy drain/tick 133 F32 minSprintEnergy; ///< Minimum energy required to sprint 134 F32 maxSprintForwardSpeed; ///< Maximum forward speed when sprinting 135 F32 maxSprintBackwardSpeed; ///< Maximum backward speed when sprinting 136 F32 maxSprintSideSpeed; ///< Maximum side speed when sprinting 137 F32 sprintStrafeScale; ///< Amount to scale strafing motion vector while sprinting 138 F32 sprintYawScale; ///< Amount to scale yaw motion while sprinting 139 F32 sprintPitchScale; ///< Amount to scale pitch motion while sprinting 140 bool sprintCanJump; ///< Can the player jump while sprinting 141 142 // Swimming 143 F32 swimForce; ///< Force used to accelerate player while swimming 144 F32 maxUnderwaterForwardSpeed; ///< Maximum underwater forward speed when running 145 F32 maxUnderwaterBackwardSpeed; ///< Maximum underwater backward speed when running 146 F32 maxUnderwaterSideSpeed; ///< Maximum underwater side speed when running 147 148 // Crouching 149 F32 crouchForce; ///< Force used to accelerate player while crouching 150 F32 maxCrouchForwardSpeed; ///< Maximum forward speed when crouching 151 F32 maxCrouchBackwardSpeed; ///< Maximum backward speed when crouching 152 F32 maxCrouchSideSpeed; ///< Maximum side speed when crouching 153 154 // Prone 155 F32 proneForce; ///< Force used to accelerate player while prone 156 F32 maxProneForwardSpeed; ///< Maximum forward speed when prone 157 F32 maxProneBackwardSpeed; ///< Maximum backward speed when prone 158 F32 maxProneSideSpeed; ///< Maximum side speed when prone 159 160 // Jetting 161 F32 jetJumpForce; 162 F32 jetJumpEnergyDrain; ///< Energy per jump 163 F32 jetMinJumpEnergy; 164 F32 jetMinJumpSpeed; 165 F32 jetMaxJumpSpeed; 166 F32 jetJumpSurfaceAngle; ///< Angle vertical degrees 167 /// @} 168 169 /// @name Hitboxes 170 /// @{ 171 172 F32 boxHeadPercentage; 173 F32 boxTorsoPercentage; 174 175 F32 boxHeadLeftPercentage; 176 F32 boxHeadRightPercentage; 177 F32 boxHeadBackPercentage; 178 F32 boxHeadFrontPercentage; 179 /// @} 180 181 F32 minImpactSpeed; ///< Minimum impact speed required to apply fall damage 182 F32 minLateralImpactSpeed; ///< Minimum impact speed required to apply non-falling damage. 183 184 F32 decalOffset; 185 186 F32 groundImpactMinSpeed; ///< Minimum impact speed required to apply fall damage with the ground 187 VectorF groundImpactShakeFreq; ///< Frequency in each direction for the camera to shake 188 VectorF groundImpactShakeAmp; ///< How much to shake 189 F32 groundImpactShakeDuration; ///< How long to shake 190 F32 groundImpactShakeFalloff; ///< How fast the shake disapates 191 192 /// Zounds! 193 enum Sounds { 194 FootSoft, 195 FootHard, 196 FootMetal, 197 FootSnow, 198 MaxSoundOffsets, 199 FootShallowSplash, 200 FootWading, 201 FootUnderWater, 202 FootBubbles, 203 MoveBubbles, 204 WaterBreath, 205 ImpactStart, 206 ImpactSoft = ImpactStart, 207 ImpactHard, 208 ImpactMetal, 209 ImpactSnow, 210 ImpactWaterEasy, 211 ImpactWaterMedium, 212 ImpactWaterHard, 213 ExitWater, 214 MaxSounds 215 }; 216 SFXTrack* sound[MaxSounds]; 217 218 Point3F boxSize; ///< Width, depth, height 219 Point3F crouchBoxSize; 220 Point3F proneBoxSize; 221 Point3F swimBoxSize; 222 223 /// Animation and other data initialized in onAdd 224 struct ActionAnimationDef { 225 const char* name; ///< Sequence name 226 struct Vector { 227 F32 x,y,z; 228 } dir; ///< Default direction 229 }; 230 struct ActionAnimation { 231 const char* name; ///< Sequence name 232 S32 sequence; ///< Sequence index 233 VectorF dir; ///< Dir of animation ground transform 234 F32 speed; ///< Speed in m/s 235 bool velocityScale; ///< Scale animation by velocity 236 bool death; ///< Are we dying? 237 }; 238 enum { 239 // *** WARNING *** 240 // These enum values are used to index the ActionAnimationList 241 // array instantiated in player.cc 242 // The first several are selected in the move state based on velocity 243 RootAnim, 244 RunForwardAnim, 245 BackBackwardAnim, 246 SideLeftAnim, 247 SideRightAnim, 248 249 SprintRootAnim, 250 SprintForwardAnim, 251 SprintBackwardAnim, 252 SprintLeftAnim, 253 SprintRightAnim, 254 255 CrouchRootAnim, 256 CrouchForwardAnim, 257 CrouchBackwardAnim, 258 CrouchLeftAnim, 259 CrouchRightAnim, 260 261 ProneRootAnim, 262 ProneForwardAnim, 263 ProneBackwardAnim, 264 265 SwimRootAnim, 266 SwimForwardAnim, 267 SwimBackwardAnim, 268 SwimLeftAnim, 269 SwimRightAnim, 270 271 // These are set explicitly based on player actions 272 FallAnim, 273 JumpAnim, 274 StandJumpAnim, 275 LandAnim, 276 JetAnim, 277 278 // 279 NumTableActionAnims = JetAnim + 1, 280 281 NumExtraActionAnims = 512 - NumTableActionAnims, 282 NumActionAnims = NumTableActionAnims + NumExtraActionAnims, 283 ActionAnimBits = 9, 284 NullAnimation = (1 << ActionAnimBits) - 1 285 }; 286 287 static ActionAnimationDef ActionAnimationList[NumTableActionAnims]; 288 ActionAnimation actionList[NumActionAnims]; 289 U32 actionCount; 290 U32 lookAction; 291 S32 spineNode[NumSpineNodes]; 292 S32 pickupDelta; ///< Base off of pcikupRadius 293 F32 runSurfaceCos; ///< Angle from vertical in cos(runSurfaceAngle) 294 F32 jumpSurfaceCos; ///< Angle from vertical in cos(jumpSurfaceAngle) 295 296 enum Impacts { 297 ImpactNone, 298 ImpactNormal, 299 }; 300 301 enum Recoil { 302 LightRecoil, 303 MediumRecoil, 304 HeavyRecoil, 305 NumRecoilSequences 306 }; 307 S32 recoilSequence[NumRecoilSequences]; 308 309 /// @name Particles 310 /// All of the data relating to environmental effects 311 /// @{ 312 313 ParticleEmitterData * footPuffEmitter; 314 S32 footPuffID; 315 S32 footPuffNumParts; 316 F32 footPuffRadius; 317 318 DecalData* decalData; 319 S32 decalID; 320 321 ParticleEmitterData * dustEmitter; 322 S32 dustID; 323 324 SplashData* splash; 325 S32 splashId; 326 F32 splashVelocity; 327 F32 splashAngle; 328 F32 splashFreqMod; 329 F32 splashVelEpsilon; 330 F32 bubbleEmitTime; 331 332 F32 medSplashSoundVel; 333 F32 hardSplashSoundVel; 334 F32 exitSplashSoundVel; 335 F32 footSplashHeight; 336 337 // Air control 338 F32 airControl; 339 340 // Jump off surfaces at their normal rather than straight up 341 bool jumpTowardsNormal; 342 343 // For use if/when mPhysicsPlayer is created 344 StringTableEntry physicsPlayerType; 345 346 ParticleEmitterData* splashEmitterList[NUM_SPLASH_EMITTERS]; 347 S32 splashEmitterIDList[NUM_SPLASH_EMITTERS]; 348 /// @} 349 350 // 351 DECLARE_CONOBJECT(PlayerData); 352 PlayerData(); 353 bool preload(bool server, String &errorStr); 354 void getGroundInfo(TSShapeInstance*,TSThread*,ActionAnimation*); 355 bool isTableSequence(S32 seq); 356 bool isJumpAction(U32 action); 357 358 static void initPersistFields(); 359 virtual void packData(BitStream* stream); 360 virtual void unpackData(BitStream* stream); 361 362 /// @name Callbacks 363 /// @{ 364 DECLARE_CALLBACK( void, onPoseChange, ( Player* obj, const char* oldPose, const char* newPose ) ); 365 DECLARE_CALLBACK( void, onStartSwim, ( Player* obj ) ); 366 DECLARE_CALLBACK( void, onStopSwim, ( Player* obj ) ); 367 DECLARE_CALLBACK( void, onStartSprintMotion, ( Player* obj ) ); 368 DECLARE_CALLBACK( void, onStopSprintMotion, ( Player* obj ) ); 369 DECLARE_CALLBACK( void, doDismount, ( Player* obj ) ); 370 DECLARE_CALLBACK( void, onEnterLiquid, ( Player* obj, F32 coverage, const char* type ) ); 371 DECLARE_CALLBACK( void, onLeaveLiquid, ( Player* obj, const char* type ) ); 372 DECLARE_CALLBACK( void, animationDone, ( Player* obj ) ); 373 DECLARE_CALLBACK( void, onEnterMissionArea, ( Player* obj ) ); 374 DECLARE_CALLBACK( void, onLeaveMissionArea, ( Player* obj ) ); 375 /// @} 376}; 377 378 379//---------------------------------------------------------------------------- 380 381class Player: public ShapeBase 382{ 383 typedef ShapeBase Parent; 384 385public: 386 enum Pose { 387 StandPose = 0, 388 SprintPose, 389 CrouchPose, 390 PronePose, 391 SwimPose, 392 NumPoseBits = 3 393 }; 394 395 /// The ExtendedMove position/rotation index used for head movements 396 static S32 smExtendedMoveHeadPosRotIndex; 397 398protected: 399 400 /// Bit masks for different types of events 401 enum MaskBits { 402 ActionMask = Parent::NextFreeMask << 0, 403 MoveMask = Parent::NextFreeMask << 1, 404 ImpactMask = Parent::NextFreeMask << 2, 405 NextFreeMask = Parent::NextFreeMask << 3 406 }; 407 408 SimObjectPtr<ParticleEmitter> mSplashEmitter[PlayerData::NUM_SPLASH_EMITTERS]; 409 F32 mBubbleEmitterTime; 410 411 /// Client interpolation/warp data 412 struct StateDelta { 413 Move move; ///< Last move from server 414 F32 dt; ///< Last interpolation time 415 /// @name Interpolation data 416 /// @{ 417 418 Point3F pos; 419 Point3F rot; 420 Point3F head; 421 VectorF posVec; 422 VectorF rotVec; 423 VectorF headVec; 424 /// @} 425 426 /// @name Warp data 427 /// @{ 428 429 S32 warpTicks; 430 Point3F warpOffset; 431 Point3F rotOffset; 432 /// @} 433 }; 434 StateDelta delta; ///< Used for interpolation on the client. @see StateDelta 435 S32 mPredictionCount; ///< Number of ticks to predict 436 437 // Current pos, vel etc. 438 Point3F mHead; ///< Head rotation, uses only x & z 439 Point3F mRot; ///< Body rotation, uses only z 440 VectorF mVelocity; ///< Velocity 441 Point3F mAnchorPoint; ///< Pos compression anchor 442 static F32 mGravity; ///< Gravity 443 S32 mImpactSound; 444 445 bool mUseHeadZCalc; ///< Including mHead.z in transform calculations 446 447 F32 mLastAbsoluteYaw; ///< Stores that last absolute yaw value as passed in by ExtendedMove 448 F32 mLastAbsolutePitch; ///< Stores that last absolute pitch value as passed in by ExtendedMove 449 F32 mLastAbsoluteRoll; ///< Stores that last absolute roll value as passed in by ExtendedMove 450 451 S32 mMountPending; ///< mMountPending suppresses tickDelay countdown so players will sit until 452 ///< their mount, or another animation, comes through (or 13 seconds elapses). 453 454 /// Main player state 455 enum ActionState { 456 NullState, 457 MoveState, 458 RecoverState, 459 NumStateBits = 3 460 }; 461 ActionState mState; ///< What is the player doing? @see ActionState 462 bool mFalling; ///< Falling in mid-air? 463 S32 mJumpDelay; ///< Delay till next jump 464 465 Pose mPose; 466 bool mAllowJumping; 467 bool mAllowJetJumping; 468 bool mAllowSprinting; 469 bool mAllowCrouching; 470 bool mAllowProne; 471 bool mAllowSwimming; 472 473 S32 mContactTimer; ///< Ticks since last contact 474 475 Point3F mJumpSurfaceNormal; ///< Normal of the surface the player last jumped on 476 U32 mJumpSurfaceLastContact; ///< How long it's been since the player landed (ticks) 477 F32 mWeaponBackFraction; ///< Amount to slide the weapon back (if it's up against something) 478 479 SFXSource* mMoveBubbleSound; ///< Sound for moving bubbles 480 SFXSource* mWaterBreathSound; ///< Sound for underwater breath 481 482 SimObjectPtr<ShapeBase> mControlObject; ///< Controlling object 483 484 /// @name Animation threads & data 485 /// @{ 486 487 struct ActionAnimation { 488 S32 action; 489 TSThread* thread; 490 S32 delayTicks; // before picking another. 491 bool forward; 492 bool firstPerson; 493 bool waitForEnd; 494 bool holdAtEnd; 495 bool animateOnServer; 496 bool atEnd; 497 } mActionAnimation; 498 499 struct ArmAnimation { 500 U32 action; 501 TSThread* thread; 502 } mArmAnimation; 503 TSThread* mArmThread; 504 505 TSThread* mHeadVThread; 506 TSThread* mHeadHThread; 507 TSThread* mRecoilThread; 508 TSThread* mImageStateThread; 509 /// @} 510 511 bool mInMissionArea; ///< Are we in the mission area? 512 // 513 S32 mRecoverTicks; ///< same as recoverTicks in the player datablock 514 U32 mReversePending; 515 F32 mRecoverDelay; ///< When bypassing the legacy recover system and only using the land sequence, 516 /// this is how long the player will be in the land sequence. 517 518 bool mInWater; ///< Is true if WaterCoverage is greater than zero 519 bool mSwimming; ///< Is true if WaterCoverage is above the swimming threshold 520 // 521 PlayerData* mDataBlock; ///< MMmmmmm...datablock... 522 523 Point3F mLastPos; ///< Holds the last position for physics updates 524 Point3F mLastWaterPos; ///< Same as mLastPos, but for water 525 526#ifdef TORQUE_OPENVR 527 SimObjectPtr<OpenVRTrackedObject> mControllers[2]; 528#endif 529 530 struct ContactInfo 531 { 532 bool contacted, jump, run; 533 SceneObject *contactObject; 534 VectorF contactNormal; 535 536 void clear() 537 { 538 contacted=<a href="/coding/class/structplayer_1_1contactinfo/#structplayer_1_1contactinfo_1ab93456a3bd9f64080afed2c164e0fd4a">jump</a>=<a href="/coding/class/structplayer_1_1contactinfo/#structplayer_1_1contactinfo_1a9f358023586e2989549d20c72ee0bd64">run</a>=false; 539 contactObject = NULL; 540 contactNormal.set(1,1,1); 541 } 542 543 ContactInfo() { clear(); } 544 545 } mContactInfo; 546 547 struct Death { 548 F32 lastPos; 549 Point3F posAdd; 550 VectorF rotate; 551 VectorF curNormal; 552 F32 curSink; 553 void clear() {dMemset(this, 0, sizeof(*this)); initFall();} 554 VectorF getPosAdd() {VectorF ret(posAdd); posAdd.set(0,0,0); return ret;} 555 bool haveVelocity() {return posAdd.x != 0 || posAdd.y != 0;} 556 void initFall() {curNormal.set(0,0,1); curSink = 0;} 557 Death() {clear();} 558 MatrixF* fallToGround(F32 adjust, const Point3F& pos, F32 zrot, F32 boxRad); 559 } mDeath; 560 561 PhysicsPlayer *mPhysicsRep; 562 563 // First person mounted image shapes 564 TSShapeInstance* mShapeFPInstance[ShapeBase::MaxMountedImages]; 565 TSThread *mShapeFPAmbientThread[ShapeBase::MaxMountedImages]; 566 TSThread *mShapeFPVisThread[ShapeBase::MaxMountedImages]; 567 TSThread *mShapeFPAnimThread[ShapeBase::MaxMountedImages]; 568 TSThread *mShapeFPFlashThread[ShapeBase::MaxMountedImages]; 569 TSThread *mShapeFPSpinThread[ShapeBase::MaxMountedImages]; 570 571 572 public: 573 574 // New collision 575 OrthoBoxConvex mConvex; 576 Box3F mWorkingQueryBox; 577 578 /// Standing / Crouched / Prone or Swimming 579 Pose getPose() const { return mPose; } 580 virtual const char* getPoseName() const; 581 582 /// Setting this from script directly might not actually work, 583 /// This is really just a helper for the player class so that its bounding box 584 /// will get resized appropriately when the pose changes 585 void setPose( Pose pose ); 586 587 PhysicsPlayer* getPhysicsRep() const { return mPhysicsRep; } 588 589#ifdef TORQUE_OPENVR 590 void setControllers(Vector<OpenVRTrackedObject*> controllerList); 591#endif 592 593 protected: 594 virtual void reSkin(); 595 596 void setState(ActionState state, U32 ticks=0); 597 void updateState(); 598 599 600 // Jetting 601 bool mJetting; 602 603 ///Update the movement 604 virtual void updateMove(const Move *move); 605 606 ///Interpolate movement 607 Point3F _move( const F32 travelTime, Collision *outCol ); 608 F32 _doCollisionImpact( const Collision *collision, bool fallingCollision); 609 void _handleCollision( const Collision &collision ); 610 virtual bool updatePos(const F32 travelTime = TickSec); 611 612 ///Update head animation 613 void updateLookAnimation(F32 dT = 0.f); 614 615 ///Update other animations 616 void updateAnimation(F32 dt); 617 void updateAnimationTree(bool firstPerson); 618 bool step(Point3F *pos,F32 *maxStep,F32 time); 619 620 ///See if the player is still in the mission area 621 void checkMissionArea(); 622 623 virtual U32 getArmAction() const { return mArmAnimation.action; } 624 virtual bool setArmThread(U32 action); 625 virtual void setActionThread(U32 action,bool forward,bool hold = false,bool wait = false,bool fsp = false, bool forceSet = false); 626 virtual void updateActionThread(); 627 virtual void pickBestMoveAction(U32 startAnim, U32 endAnim, U32 * action, bool * forward) const; 628 virtual void pickActionAnimation(); 629 630 /// @name Mounted objects 631 /// @{ 632 virtual void onUnmount( SceneObject *obj, S32 node ); 633 virtual void unmount(); 634 /// @} 635 636 void setPosition(const Point3F& pos,const Point3F& viewRot); 637 void setRenderPosition(const Point3F& pos,const Point3F& viewRot,F32 dt=-1); 638 void _findContact( SceneObject **contactObject, VectorF *contactNormal, Vector<SceneObject*> *outOverlapObjects ); 639 void findContact( bool *run, bool *jump, VectorF *contactNormal ); 640 641 void buildImagePrefixPaths(String* prefixPaths); 642 S32 findPrefixSequence(String* prefixPaths, const String& baseSeq); 643 S32 convertActionToImagePrefix(U32 action); 644 645 virtual void onImage(U32 imageSlot, bool unmount); 646 virtual void onImageRecoil(U32 imageSlot,ShapeBaseImageData::StateData::RecoilState); 647 virtual void onImageStateAnimation(U32 imageSlot, const char* seqName, bool direction, bool scaleToState, F32 stateTimeOutValue); 648 virtual const char* getImageAnimPrefix(U32 imageSlot, S32 imageShapeIndex); 649 virtual void onImageAnimThreadChange(U32 imageSlot, S32 imageShapeIndex, ShapeBaseImageData::StateData* lastState, const char* anim, F32 pos, F32 timeScale, bool reset=false); 650 virtual void onImageAnimThreadUpdate(U32 imageSlot, S32 imageShapeIndex, F32 dt); 651 652 virtual void updateDamageLevel(); 653 virtual void updateDamageState(); 654 /// Set which client is controlling this player 655 void setControllingClient(GameConnection* client); 656 657 void calcClassRenderData(); 658 659 /// Play sound for foot contact. 660 /// 661 /// @param triggeredLeft If true, left foot hit; right otherwise. 662 /// @param contactMaterial Material onto which the player stepped; may be NULL. 663 /// @param contactObject Object onto which the player stepped; may be NULL. 664 void playFootstepSound( bool triggeredLeft, Material* contactMaterial, SceneObject* contactObject ); 665 666 /// Play an impact sound. 667 void playImpactSound(); 668 669 /// Are we in the process of dying? 670 bool inDeathAnim(); 671 F32 deathDelta(Point3F &delta); 672 void updateDeathOffsets(); 673 bool inSittingAnim(); 674 675 /// @name Water 676 /// @{ 677 678 void updateSplash(); ///< Update the splash effect 679 void updateFroth( F32 dt ); ///< Update any froth 680 void updateWaterSounds( F32 dt ); ///< Update water sounds 681 void createSplash( Point3F &pos, F32 speed ); ///< Creates a splash 682 bool collidingWithWater( Point3F &waterHeight ); ///< Are we colliding with water? 683 /// @} 684 685 void disableHeadZCalc() { mUseHeadZCalc = false; } 686 void enableHeadZCalc() { mUseHeadZCalc = true; } 687 688public: 689 DECLARE_CONOBJECT(Player); 690 691 Player(); 692 ~Player(); 693 static void consoleInit(); 694 695 /// @name Transforms 696 /// @{ 697 698 void setTransform(const MatrixF &mat); 699 void getEyeTransform(MatrixF* mat); 700 void getEyeBaseTransform(MatrixF* mat, bool includeBank); 701 void getRenderEyeTransform(MatrixF* mat); 702 void getRenderEyeBaseTransform(MatrixF* mat, bool includeBank); 703 void getCameraParameters(F32 *min, F32 *max, Point3F *offset, MatrixF *rot); 704 void getMuzzleTransform(U32 imageSlot,MatrixF* mat); 705 void getRenderMuzzleTransform(U32 imageSlot,MatrixF* mat); 706 707 virtual void getMuzzleVector(U32 imageSlot,VectorF* vec); 708 /// @} 709 710 F32 getSpeed() const; 711 Point3F getVelocity() const; 712 void setVelocity(const VectorF& vel); 713 /// Apply an impulse at the given point, with magnitude/direction of vec 714 void applyImpulse(const Point3F& pos,const VectorF& vec); 715 /// Get the rotation of the player 716 const Point3F& getRotation() { return mRot; } 717 /// Get the rotation of the head of the player 718 const Point3F& getHeadRotation() { return mHead; } 719 void getDamageLocation(const Point3F& in_rPos, const char *&out_rpVert, const char *&out_rpQuad); 720 721 void allowAllPoses(); 722 void allowJumping(bool state) { mAllowJumping = state; } 723 void allowJetJumping(bool state) { mAllowJetJumping = state; } 724 void allowSprinting(bool state) { mAllowSprinting = state; } 725 void allowCrouching(bool state) { mAllowCrouching = state; } 726 void allowProne(bool state) { mAllowProne = state; } 727 void allowSwimming(bool state) { mAllowSwimming = state; } 728 729 bool canJump(); ///< Can the player jump? 730 bool canJetJump(); ///< Can the player jet? 731 bool canSwim(); ///< Can the player swim? 732 bool canCrouch(); 733 bool canStand(); 734 bool canProne(); 735 bool canSprint(); 736 bool haveContact() const { return !mContactTimer; } ///< Is it in contact with something 737 void getMuzzlePointAI( U32 imageSlot, Point3F *point ); 738 F32 getMaxForwardVelocity() const { return (mDataBlock != NULL ? mDataBlock->maxForwardSpeed : 0); } 739 740 virtual bool isDisplacable() const; 741 virtual Point3F getMomentum() const; 742 virtual void setMomentum(const Point3F &momentum); 743 virtual bool displaceObject(const Point3F& displaceVector); 744 virtual bool getAIMove(Move*); 745 746 bool checkDismountPosition(const MatrixF& oldPos, const MatrixF& newPos); ///< Is it safe to dismount here? 747 748 // 749 bool onAdd(); 750 void onRemove(); 751 bool onNewDataBlock( GameBaseData *dptr, bool reload ); 752 void onScaleChanged(); 753 Box3F mScaledBox; 754 755 // Animation 756 const char* getStateName(); 757 bool setActionThread(const char* sequence,bool hold,bool wait,bool fsp = false); 758 const String& getArmThread() const; 759 bool setArmThread(const char* sequence); 760 761 // Object control 762 void setControlObject(ShapeBase *obj); 763 ShapeBase* getControlObject(); 764 765 // 766 void updateWorkingCollisionSet(); 767 virtual void processTick(const Move *move); 768 void interpolateTick(F32 delta); 769 void advanceTime(F32 dt); 770 bool castRay(const Point3F &start, const Point3F &end, RayInfo* info); 771 bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere); 772 void buildConvex(const Box3F& box, Convex* convex); 773 bool isControlObject(); 774 775 void onCameraScopeQuery(NetConnection *cr, CameraScopeQuery *); 776 void writePacketData(GameConnection *conn, BitStream *stream); 777 void readPacketData (GameConnection *conn, BitStream *stream); 778 U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream); 779 void unpackUpdate(NetConnection *conn, BitStream *stream); 780 781 virtual void prepRenderImage( SceneRenderState* state ); 782 virtual void renderConvex( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat ); 783 virtual void renderMountedImage( U32 imageSlot, TSRenderState &rstate, SceneRenderState *state ); 784}; 785 786typedef Player::Pose PlayerPose; 787 788DefineEnumType( PlayerPose ); 789 790#endif 791
