Planeshift
psmovement.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
3  *
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation (version 2 of the License)
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  */
17 
18 #ifndef __PSMOVEMENT_H__
19 #define __PSMOVEMENT_H__
20 
21 #include <csutil/parray.h>
22 #include <csutil/csstring.h>
23 #include <csgeom/vector3.h>
24 
25 #include "pscelclient.h"
26 #include "net/cmdbase.h"
27 
28 class psControlManager;
29 struct psPoint;
30 
36 struct psVelocity
37 {
38  psVelocity() : move(0.0f), rotate(0.0f) {}
39  psVelocity(csVector3 m, csVector3 r) : move(m), rotate(r) {}
40 
41  csVector3 move;
42  csVector3 rotate;
43 
49 };
50 
51 
53 struct psCharMode
54 {
55  uint32 id;
56  csString name;
58  csString idle_anim;
59 };
60 
62 struct psMovement
63 {
64  uint32 id;
65  csString name;
67 };
68 
71 {
73  bool autoMove;
74  bool sneaking;
75 };
76 
85 {
86 protected:
87  csPDelArray<psCharMode> modes;
88  csPDelArray<psMovement> moves;
89 
91 
93 
95  bool onGround;
96  uint activeMoves;
98 
99  void SetupMovements(psMovementInfoMessage& msg);
100  void SetupControls();
101  bool ready;
102  bool locked;
103 
105 
106  void UpdateVelocity();
107 
108  void SetActorMode(const psCharMode* mode);
109 
110  // Movement modifier handling
111  void HandleMod(psMoveModMsg& msg);
112  void ApplyMod(psVelocity& vel);
115 
116  bool autoMove;
117  bool toggleRun;
118  bool mouseLook;
120  bool mouseZoom;
121  bool mouseMove;
122  bool sneaking;
125  float lastDist;
126  csVector3 runToDiff;
127 
128  // Mouse settings
129  float sensY;
130  float sensX;
132  float lastDeltaX;
133  float lastDeltaY;
134 
135  csEventID event_frame;
136  csEventID event_mousemove;
137 
140  const psCharMode* run;
141  const psCharMode* walk;
142 
143  uint kbdRotate;
144 
145 public:
146  psMovementManager(iEventNameRegistry* eventname_reg, psControlManager* controls);
148 
149  void HandleMessage(MsgEntry* me);
150  bool HandleEvent(iEvent& event);
151 
152  void SetActor(GEMClientActor* actor);
153  GEMClientActor* ControlledActor() { return actor; }
154 
155  // Functions to find movement and mode info
156  const char* GetModeIdleAnim(size_t id) const { return modes[id]->idle_anim; }
157  const psCharMode* FindCharMode(size_t id) const { return modes[id]; }
158  const psCharMode* FindCharMode(const char* name) const;
159  const psMovement* FindMovement(const char* name) const;
160 
161  bool IsReady() { return ready; }
162  bool IsLocked() { return locked; }
163  void LockMoves(bool v);
164 
165  // Movements
166  void Start(const psCharMode* mode);
167  void Stop(const psCharMode* mode);
168  void Start(const psMovement* move);
169  void Stop(const psMovement* move);
170  void Push(const psMovement* move);
171 
173  void StopAllMovement();
174 
176  void StopControlledMovement();
177 
178  // Mouse settings
179  void SetMouseSensX(float v) { sensX = v; }
180  void SetMouseSensY(float v) { sensY = v; }
181  void SetInvertedMouse(bool v) { invertedMouse = v; }
182  bool GetInvertedMouse() { return invertedMouse; }
183  void LoadMouseSettings();
184 
185  void MouseLookCanAct(bool v);
186  bool MouseLookCanAct(){ return mouseLookCanAct; }
187 
188  void MouseLook(bool v);
189  bool MouseLook() { return mouseLook; }
190  void MouseLook(iEvent& ev);
191  void UpdateMouseLook();
192 
193  void MouseZoom(bool v) { mouseZoom = v; }
194  bool MouseZoom() { return mouseZoom; }
195  void MouseZoom(iEvent& ev);
196 
197  void SetMouseMove(bool v) { mouseMove = v; }
198  bool MouseMove() { return mouseMove; }
199  void SetRunToPos(psPoint& mouse);
200  void CancelRunTo();
201  void UpdateRunTo();
202 
203  void ToggleAutoMove();
204 
209  bool ToggleRun();
210 
217  bool SetRun(bool runState);
218 
219  void SetSneaking(bool v) { sneaking = v; }
220  bool Sneaking() { return sneaking; }
221 
223  {
224  state.activeMoves = activeMoves;
225  state.autoMove = autoMove;
226  state.sneaking = sneaking;
227  }
228 
230  {
231  return state.activeMoves != activeMoves ||
232  state.autoMove != autoMove ||
233  state.sneaking != sneaking;
234  }
235 };
236 
237 #endif
238 
psVelocity & operator-=(const psVelocity &v)
Manages main character movements.
Definition: psmovement.h:84
uint32 id
ID of this movement type from server DB.
Definition: psmovement.h:64
csString idle_anim
Base animation for this mode.
Definition: psmovement.h:58
This is a player or another &#39;alive&#39; entity on the client.
Definition: pscelclient.h:554
const psCharMode * defaultmode
Default actor mode.
Definition: psmovement.h:90
bool IsReady()
Ready to receive events?
Definition: psmovement.h:161
csVector3 runToDiff
Definition: psmovement.h:126
Manages button functions and triggers.
bool sneaking
Definition: psmovement.h:74
csVector3 rotate
Angular velocity.
Definition: psmovement.h:42
bool GetInvertedMouse()
Definition: psmovement.h:182
csPDelArray< psMovement > moves
All available movement types.
Definition: psmovement.h:88
const psCharMode * actormode
Current active mode.
Definition: psmovement.h:94
const psMovement * backward
Definition: psmovement.h:139
bool onGround
Is actor on ground or airborne?
Definition: psmovement.h:95
void SetMouseSensY(float v)
Definition: psmovement.h:180
A character movement and its properties.
Definition: psmovement.h:62
void MouseZoom(bool v)
Definition: psmovement.h:193
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
uint activeMoves
Bit mask for active moves.
Definition: psmovement.h:96
psVelocity modifier
Velocity multiplier for this mode.
Definition: psmovement.h:57
uint32 id
ID of this character mode from server DB.
Definition: psmovement.h:55
csString name
Name of this movement.
Definition: psmovement.h:65
void SetSneaking(bool v)
Definition: psmovement.h:219
uint activeMoves
Definition: psmovement.h:72
Used to save movement state to detect changes.
Definition: psmovement.h:70
GEMClientActor * ControlledActor()
Definition: psmovement.h:153
psVelocity move_total
Current total of all active move velocities.
Definition: psmovement.h:97
psVelocity & operator=(const psVelocity &v)
bool ready
Have movements been setup?
Definition: psmovement.h:101
bool MouseLookCanAct()
Definition: psmovement.h:186
csEventID event_frame
Definition: psmovement.h:135
csVector3 move
Translational velocity.
Definition: psmovement.h:41
csString name
Name of this mode.
Definition: psmovement.h:56
psVelocity & operator/=(const psVelocity &v)
bool autoMove
Definition: psmovement.h:73
bool locked
Is this player allowed to move?
Definition: psmovement.h:102
csEventID event_mousemove
Definition: psmovement.h:136
void SetMouseMove(bool v)
Definition: psmovement.h:197
void SetMouseSensX(float v)
Definition: psmovement.h:179
const psMovement * forward
Definition: psmovement.h:138
psVelocity(csVector3 m, csVector3 r)
Definition: psmovement.h:39
const psCharMode * walk
Definition: psmovement.h:141
bool MoveStateChanged(psMoveState &state)
Definition: psmovement.h:229
An entity&#39;s translational and angular velocity.
Definition: psmovement.h:36
A character mode and its properties.
Definition: psmovement.h:53
psVelocity & operator*=(const psVelocity &v)
void SaveMoveState(psMoveState &state)
Definition: psmovement.h:222
const psCharMode * run
Definition: psmovement.h:140
csPDelArray< psCharMode > modes
All available character modes.
Definition: psmovement.h:87
psVelocity activeMod
Definition: psmovement.h:114
psVelocity & operator+=(const psVelocity &v)
psMoveModMsg::ModType activeModType
Definition: psmovement.h:113
psVelocity motion
Motion aplied for this movement.
Definition: psmovement.h:66
const char * GetModeIdleAnim(size_t id) const
Definition: psmovement.h:156
const psCharMode * FindCharMode(size_t id) const
Definition: psmovement.h:157
void SetInvertedMouse(bool v)
Definition: psmovement.h:181
psControlManager * controls
Definition: psmovement.h:104
GEMClientActor * actor
Actor we&#39;re moving here.
Definition: psmovement.h:92