]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/game/physics/Physics_Player.h
hello world
[icculus/iodoom3.git] / neo / game / physics / Physics_Player.h
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 /*
33 ===================================================================================
34
35         Player physics
36
37         Simulates the motion of a player through the environment. Input from the
38         player is used to allow a certain degree of control over the motion.
39
40 ===================================================================================
41 */
42
43 // movementType
44 typedef enum {
45         PM_NORMAL,                              // normal physics
46         PM_DEAD,                                // no acceleration or turning, but free falling
47         PM_SPECTATOR,                   // flying without gravity but with collision detection
48         PM_FREEZE,                              // stuck in place without control
49         PM_NOCLIP                               // flying without collision detection nor gravity
50 } pmtype_t;
51
52 typedef enum {
53         WATERLEVEL_NONE,
54         WATERLEVEL_FEET,
55         WATERLEVEL_WAIST,
56         WATERLEVEL_HEAD
57 } waterLevel_t;
58
59 #define MAXTOUCH                                        32
60
61 typedef struct playerPState_s {
62         idVec3                                  origin;
63         idVec3                                  velocity;
64         idVec3                                  localOrigin;
65         idVec3                                  pushVelocity;
66         float                                   stepUp;
67         int                                             movementType;
68         int                                             movementFlags;
69         int                                             movementTime;
70 } playerPState_t;
71
72 class idPhysics_Player : public idPhysics_Actor {
73
74 public:
75         CLASS_PROTOTYPE( idPhysics_Player );
76
77                                                         idPhysics_Player( void );
78
79         void                                    Save( idSaveGame *savefile ) const;
80         void                                    Restore( idRestoreGame *savefile );
81
82                                                         // initialisation
83         void                                    SetSpeed( const float newWalkSpeed, const float newCrouchSpeed );
84         void                                    SetMaxStepHeight( const float newMaxStepHeight );
85         float                                   GetMaxStepHeight( void ) const;
86         void                                    SetMaxJumpHeight( const float newMaxJumpHeight );
87         void                                    SetMovementType( const pmtype_t type );
88         void                                    SetPlayerInput( const usercmd_t &cmd, const idAngles &newViewAngles );
89         void                                    SetKnockBack( const int knockBackTime );
90         void                                    SetDebugLevel( bool set );
91                                                         // feed back from last physics frame
92         waterLevel_t                    GetWaterLevel( void ) const;
93         int                                             GetWaterType( void ) const;
94         bool                                    HasJumped( void ) const;
95         bool                                    HasSteppedUp( void ) const;
96         float                                   GetStepUp( void ) const;
97         bool                                    IsCrouching( void ) const;
98         bool                                    OnLadder( void ) const;
99         const idVec3 &                  PlayerGetOrigin( void ) const;  // != GetOrigin
100
101 public: // common physics interface
102         bool                                    Evaluate( int timeStepMSec, int endTimeMSec );
103         void                                    UpdateTime( int endTimeMSec );
104         int                                             GetTime( void ) const;
105
106         void                                    GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
107         void                                    ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
108         bool                                    IsAtRest( void ) const;
109         int                                             GetRestStartTime( void ) const;
110
111         void                                    SaveState( void );
112         void                                    RestoreState( void );
113
114         void                                    SetOrigin( const idVec3 &newOrigin, int id = -1 );
115         void                                    SetAxis( const idMat3 &newAxis, int id = -1 );
116
117         void                                    Translate( const idVec3 &translation, int id = -1 );
118         void                                    Rotate( const idRotation &rotation, int id = -1 );
119
120         void                                    SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
121
122         const idVec3 &                  GetLinearVelocity( int id = 0 ) const;
123
124         void                                    SetPushed( int deltaTime );
125         const idVec3 &                  GetPushedLinearVelocity( const int id = 0 ) const;
126         void                                    ClearPushedVelocity( void );
127
128         void                                    SetMaster( idEntity *master, const bool orientated = true );
129
130         void                                    WriteToSnapshot( idBitMsgDelta &msg ) const;
131         void                                    ReadFromSnapshot( const idBitMsgDelta &msg );
132
133 private:
134         // player physics state
135         playerPState_t                  current;
136         playerPState_t                  saved;
137
138         // properties
139         float                                   walkSpeed;
140         float                                   crouchSpeed;
141         float                                   maxStepHeight;
142         float                                   maxJumpHeight;
143         int                                             debugLevel;                             // if set, diagnostic output will be printed
144
145         // player input
146         usercmd_t                               command;
147         idAngles                                viewAngles;
148
149         // run-time variables
150         int                                             framemsec;
151         float                                   frametime;
152         float                                   playerSpeed;
153         idVec3                                  viewForward;
154         idVec3                                  viewRight;
155
156         // walk movement
157         bool                                    walking;
158         bool                                    groundPlane;
159         trace_t                                 groundTrace;
160         const idMaterial *              groundMaterial;
161
162         // ladder movement
163         bool                                    ladder;
164         idVec3                                  ladderNormal;
165
166         // results of last evaluate
167         waterLevel_t                    waterLevel;
168         int                                             waterType;
169
170 private:
171         float                                   CmdScale( const usercmd_t &cmd ) const;
172         void                                    Accelerate( const idVec3 &wishdir, const float wishspeed, const float accel );
173         bool                                    SlideMove( bool gravity, bool stepUp, bool stepDown, bool push );
174         void                                    Friction( void );
175         void                                    WaterJumpMove( void );
176         void                                    WaterMove( void );
177         void                                    FlyMove( void );
178         void                                    AirMove( void );
179         void                                    WalkMove( void );
180         void                                    DeadMove( void );
181         void                                    NoclipMove( void );
182         void                                    SpectatorMove( void );
183         void                                    LadderMove( void );
184         void                                    CorrectAllSolid( trace_t &trace, int contents );
185         void                                    CheckGround( void );
186         void                                    CheckDuck( void );
187         void                                    CheckLadder( void );
188         bool                                    CheckJump( void );
189         bool                                    CheckWaterJump( void );
190         void                                    SetWaterLevel( void );
191         void                                    DropTimers( void );
192         void                                    MovePlayer( int msec );
193 };
194
195 #endif /* !__PHYSICS_PLAYER_H__ */