Merge branch '164-crash-on-patching-and-possibly-right-after-login' into main/gingo...
[ryzomcore.git] / ryzom / client / src / motion / user_controls.h
blob7f09ef7f290410ecef371c36650843e166081a2f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef CL_USER_CONTROLS_H
24 #define CL_USER_CONTROLS_H
27 /////////////
28 // INCLUDE //
29 /////////////
30 // Misc.
31 #include "nel/misc/types_nl.h"
32 #include "nel/misc/time_nl.h"
33 #include "nel/misc/vector.h"
34 // Std.
35 #include <string>
37 namespace NLMISC {
38 class CCDBNodeLeaf;
41 ///////////
42 // CLASS //
43 ///////////
44 /**
45 * Class to manage the motion.
46 * \author Guillaume PUZIN
47 * \author Nevrax France
48 * \date 2001
50 class CUserControls
52 friend class CAHForward;
53 friend class CAHBackward;
54 friend class CAHToggleAutoWalk;
55 public:
56 /// moving modes
57 enum TMoveMode
59 InterfaceMode = 0, // Interface Mode (with mouse displayed)
60 AIMode, // Mode for the AI.
61 DeathMode, // Mode for the Death.
62 MountMode, // Mode for the Mount.
63 ThirdMode, // Third Person View Mode
65 nbMode // Not really a mode, just here to know how many modes are there.
68 enum TDirectionMove
70 none = 0x00,
71 forward = 0x01,
72 backward = 0x02,
73 left = 0x04,
74 right = 0x08,
75 autowalk = 0x10
78 protected:
79 NLMISC::TTime _LeftClickStart;
80 NLMISC::TTime _LeftClickEnd;
81 NLMISC::TTime _RightClickStart;
82 NLMISC::TTime _RightClickEnd;
83 NLMISC::TTime _TimeBeforeMouseSlide;
84 NLMISC::TTime _TimeLongClick;
86 private:
87 /// Initialize all the components.
88 void init();
90 /// Just manage the free look.
91 void freeLook(bool fullMode);
92 /// Just manage the camera look
93 void cameraLook(bool fullMode);
94 /// common to freeLook and cameraLook
95 void getMouseAngleMove(float &dx, float &dy);
97 /// Manage interactions in interactive mode (start).
98 void interfaceModeStart();
99 /// Manage interactions in interactive mode (stop).
100 void interfaceModeStop();
101 /// Manage interactions in interactive mode.
102 void interfaceMode();
104 /// Manage the AI Mode (start).
105 void aiModeStart();
106 /// Manage the AI Mode (stop).
107 void aiModeStop();
108 /// Manage the AI Mode.
109 void aiMode();
111 /// Manage the Death Mode (start).
112 void deathModeStart();
113 /// Manage the Death Mode (stop).
114 void deathModeStop();
115 /// Manage the Death Mode.
116 void deathMode();
118 /// Manage the Mount Mode (start).
119 void mountModeStart();
120 /// Manage the Mount Mode (stop).
121 void mountModeStop();
122 /// Manage the Mount Mode.
123 void mountMode();
125 /// Manage the Third Person View Mode (start).
126 void thirdModeStart();
127 /// Manage the Third Person View Mode (stop).
128 void thirdModeStop();
129 /// Manage the Third Person View Mode.
130 void thirdMode();
132 /// Manage some common actions.
133 void commonMove();
134 /// Move the caracter according to the inputs
135 void move();
136 /// Calculate the destination point when clicking on the ground in "Free Head" Mode.
137 void findDestination(float x, float y);
138 /// ...
139 void turnBack();
140 /// Update the cursor position.
141 void updateCursorPosition();
142 /// Manage some common view setup.
143 void commonSetView();
145 // Execute action depending on the cursor position (left/right click).
146 void execActionCursorPos(bool rightClick, bool dblClick);
148 // test merge the camera Yaw and user Yaw. Only in some cases
149 void testApplyCameraYawToUser();
151 /// when user moves, some actions must be cancelled
152 void cancelActionsWhenMoving();
154 /// when user moves and speed factor is 0, show warning message
155 void checkSpeedFactor();
156 public:
157 /// Constructor
158 CUserControls();
160 void reset();
162 /// Return the string associated to the motion Mode.
163 std::string modeStr() const;
164 /// Return the motion Mode.
165 TMoveMode mode() const {return _Mode;}
166 /// Change the current motion Mode.
167 void mode(const TMoveMode mode);
169 /// Update the motion.
170 void update();
172 /// Lock or unlock the motion.
173 void locked(bool l) {_Locked = l;}
174 bool locked() {return _Locked;}
176 /// Begin Free Look. Additionaly, cancel any follow/moteTo of the user
177 void startFreeLook();
179 /// Stop Free Look (can be called multiple times if needed). Additionaly, the mouse/pointer is restored
180 void stopFreeLook();
182 bool getFreeLook() const { return _FreeLook; }
184 /// Is the camera inside the character.
185 bool isInternalView() {return _InternalView;}
187 /// Update keyboard rotation
188 void keyboardRotationLR (bool left, bool right);
189 void keyboardRotationUD (bool up, bool down);
190 void keyboardRotationCameraLR (bool left, bool right);
192 void startCombat() {_CameraAuto = true;}
194 /// Enable/Disable Autowalk
195 void autowalkState(bool enable);
196 /// Return the autowalk state ('true'=enable).
197 bool autowalkState() const {return ((_DirectionMove & autowalk)!=0);}
199 /// Update velocity
200 static void updateVelocity (float deltaTime, float acceleration, float brake, float speedMax, float &speed);
203 // get the camera Delta Yaw
204 float getCameraDeltaYaw() const {return _UserCameraDeltaYaw;}
206 // just reset the camera Delta Yaw (instantaneously)
207 void resetCameraDeltaYaw();
209 // reset the camera Delta Yaw (smooth over time, canceled by user)
210 void resetSmoothCameraDeltaYaw();
212 // append to the camera Delta Yaw (NB: any smooth reset is then canceled)
213 void appendCameraDeltaYaw(float dYaw);
215 // reset the camera Delta Yaw and change the user front so the final Yaw remains the same
216 void applyCameraDeltaYawToUser();
218 // true if there is currently a smooth reset of the cameraDeltaYaw (in force mode)
219 bool isResetSmoothCDYForced() const {return _ResetSmoothCameraDeltaYaw==ResetCDYForced;}
221 // capture the mouse, prevent the free look from being trigger on a long click
222 void captureMouse() { _MouseCaptured = true; }
223 void releaseMouse() { _MouseCaptured = false; }
224 bool isMouseCaptured() { return _MouseCaptured; }
226 /// user has to release forward key before he can go forward again
227 void needReleaseForward();
229 /// return true if user do forward or backward move action with key or mouth
230 bool isMoving() { return _DirectionMove != none; }
232 private:
234 bool _MouseCaptured; // no free look allowed when mouse is captures
236 // Is the camera controled by the user or not.
237 bool _CameraAuto;
239 bool _LastFrameForward;
240 bool _LastFrameBackward;
241 bool _LastFrameAutowalk;
242 bool _LastFrameStrafeLeft;
243 bool _LastFrameStrafeRight;
244 bool _LastFrameTurnLeft;
245 bool _LastFrameTurnRight;
246 bool _LastFrameLeftButtonDown;
247 // NB: modified only when not in freelook mode
248 float _LastFrameMousePosX;
249 float _LastFrameMousePosY;
250 bool _CurrentFrameFreeLookCalled;
251 /// Used to lock motion.
252 bool _Locked;
254 /// Are we in displacement or not ?
255 uint32 _DirectionMove;
257 /// moving mode
258 TMoveMode _Mode;
259 /// last moving mode
260 TMoveMode _LastMode;
262 /// speed in translation
263 float _TransSpeed;
265 /// fly velocity
266 float _FlyVerticalVelocity;
267 float _FlyFrontVelocity;
268 float _FlyLateralVelocity;
269 float _RotateUserLRVelocity;
270 float _RotateUserUDVelocity;
271 float _RotateCameraLRVelocity;
274 bool _UpdateView;
277 NLMISC::CVector _Start;
279 NLMISC::CVector _Destination;
282 float _Acc;
283 float _T0;
284 float _T;
285 float _V0;
288 float _ZOscil;
291 float _Dist;
292 float _PrevDist;
295 bool _TurnBack;
297 /// "true" if the character has a destination to go.
298 bool _ClickMove;
301 float _T0View;
302 float _TView;
303 float _ViewSpeed;
305 bool _FreeLook;
307 bool _InternalView;
309 // User Camera Yaw
310 float _UserCameraDeltaYaw;
311 // Forced mode is related to moveTo/follow feature
312 enum TResetCDY {ResetCDYOff=0, ResetCDYOn, ResetCDYForced};
313 TResetCDY _ResetSmoothCameraDeltaYaw;
315 /// when true user has to release forward key before he can go forward again
316 bool _NeedReleaseForward;
318 /// when true the next forward action will cancel any moveto
319 bool _NextForwardCancelMoveTo;
321 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _UiVarMkMoveDB;
324 /// User Controls (mouse, keyboard, interfaces, ...)
325 extern CUserControls UserControls;
328 #endif // CL_USER_CONTROLS_H
330 /* End of user_controls.h */