1 /* 2 =========================================================================== 3 4 Doom 3 GPL Source Code 5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). 8 9 Doom 3 Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #ifndef __PHYSICS_PLAYER_H__ 30 #define __PHYSICS_PLAYER_H__ 31 32 #include "physics/Physics_Actor.h" 33 34 /* 35 =================================================================================== 36 37 Player physics 38 39 Simulates the motion of a player through the environment. Input from the 40 player is used to allow a certain degree of control over the motion. 41 42 =================================================================================== 43 */ 44 45 // movementType 46 typedef enum { 47 PM_NORMAL, // normal physics 48 PM_DEAD, // no acceleration or turning, but free falling 49 PM_SPECTATOR, // flying without gravity but with collision detection 50 PM_FREEZE, // stuck in place without control 51 PM_NOCLIP // flying without collision detection nor gravity 52 } pmtype_t; 53 54 typedef enum { 55 WATERLEVEL_NONE, 56 WATERLEVEL_FEET, 57 WATERLEVEL_WAIST, 58 WATERLEVEL_HEAD 59 } waterLevel_t; 60 61 #define MAXTOUCH 32 62 63 typedef struct playerPState_s { 64 idVec3 origin; 65 idVec3 velocity; 66 idVec3 localOrigin; 67 idVec3 pushVelocity; 68 float stepUp; 69 int movementType; 70 int movementFlags; 71 int movementTime; 72 } playerPState_t; 73 74 class idPhysics_Player : public idPhysics_Actor { 75 76 public: 77 CLASS_PROTOTYPE( idPhysics_Player ); 78 79 idPhysics_Player( void ); 80 81 void Save( idSaveGame *savefile ) const; 82 void Restore( idRestoreGame *savefile ); 83 84 // initialisation 85 void SetSpeed( const float newWalkSpeed, const float newCrouchSpeed ); 86 void SetMaxStepHeight( const float newMaxStepHeight ); 87 float GetMaxStepHeight( void ) const; 88 void SetMaxJumpHeight( const float newMaxJumpHeight ); 89 void SetMovementType( const pmtype_t type ); 90 void SetPlayerInput( const usercmd_t &cmd, const idAngles &newViewAngles ); 91 void SetKnockBack( const int knockBackTime ); 92 void SetDebugLevel( bool set ); 93 // feed back from last physics frame 94 waterLevel_t GetWaterLevel( void ) const; 95 int GetWaterType( void ) const; 96 bool HasJumped( void ) const; 97 bool HasSteppedUp( void ) const; 98 float GetStepUp( void ) const; 99 bool IsCrouching( void ) const; 100 bool OnLadder( void ) const; 101 const idVec3 & PlayerGetOrigin( void ) const; // != GetOrigin 102 103 public: // common physics interface 104 bool Evaluate( int timeStepMSec, int endTimeMSec ); 105 void UpdateTime( int endTimeMSec ); 106 int GetTime( void ) const; 107 108 void GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const; 109 void ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse ); 110 bool IsAtRest( void ) const; 111 int GetRestStartTime( void ) const; 112 113 void SaveState( void ); 114 void RestoreState( void ); 115 116 void SetOrigin( const idVec3 &newOrigin, int id = -1 ); 117 void SetAxis( const idMat3 &newAxis, int id = -1 ); 118 119 void Translate( const idVec3 &translation, int id = -1 ); 120 void Rotate( const idRotation &rotation, int id = -1 ); 121 122 void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 ); 123 124 const idVec3 & GetLinearVelocity( int id = 0 ) const; 125 126 void SetPushed( int deltaTime ); 127 const idVec3 & GetPushedLinearVelocity( const int id = 0 ) const; 128 void ClearPushedVelocity( void ); 129 130 void SetMaster( idEntity *master, const bool orientated = true ); 131 132 void WriteToSnapshot( idBitMsgDelta &msg ) const; 133 void ReadFromSnapshot( const idBitMsgDelta &msg ); 134 135 private: 136 // player physics state 137 playerPState_t current; 138 playerPState_t saved; 139 140 // properties 141 float walkSpeed; 142 float crouchSpeed; 143 float maxStepHeight; 144 float maxJumpHeight; 145 int debugLevel; // if set, diagnostic output will be printed 146 147 // player input 148 usercmd_t command; 149 idAngles viewAngles; 150 151 // run-time variables 152 int framemsec; 153 float frametime; 154 float playerSpeed; 155 idVec3 viewForward; 156 idVec3 viewRight; 157 158 // walk movement 159 bool walking; 160 bool groundPlane; 161 trace_t groundTrace; 162 const idMaterial * groundMaterial; 163 164 // ladder movement 165 bool ladder; 166 idVec3 ladderNormal; 167 168 // results of last evaluate 169 waterLevel_t waterLevel; 170 int waterType; 171 172 private: 173 float CmdScale( const usercmd_t &cmd ) const; 174 void Accelerate( const idVec3 &wishdir, const float wishspeed, const float accel ); 175 bool SlideMove( bool gravity, bool stepUp, bool stepDown, bool push ); 176 void Friction( void ); 177 void WaterJumpMove( void ); 178 void WaterMove( void ); 179 void FlyMove( void ); 180 void AirMove( void ); 181 void WalkMove( void ); 182 void DeadMove( void ); 183 void NoclipMove( void ); 184 void SpectatorMove( void ); 185 void LadderMove( void ); 186 void CorrectAllSolid( trace_t &trace, int contents ); 187 void CheckGround( void ); 188 void CheckDuck( void ); 189 void CheckLadder( void ); 190 bool CheckJump( void ); 191 bool CheckWaterJump( void ); 192 void SetWaterLevel( void ); 193 void DropTimers( void ); 194 void MovePlayer( int msec ); 195 }; 196 197 #endif /* !__PHYSICS_PLAYER_H__ */ 198