player.h 29 KB

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