player.h 28 KB

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