Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / motion / user_controls.h
blobb607ab18029cddafb1f756376f674884a712bf4b
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 public:
155 /// Constructor
156 CUserControls();
158 void reset();
160 /// Return the string associated to the motion Mode.
161 std::string modeStr() const;
162 /// Return the motion Mode.
163 TMoveMode mode() const {return _Mode;}
164 /// Change the current motion Mode.
165 void mode(const TMoveMode mode);
167 /// Update the motion.
168 void update();
170 /// Lock or unlock the motion.
171 void locked(bool l) {_Locked = l;}
172 bool locked() {return _Locked;}
174 /// Begin Free Look. Additionaly, cancel any follow/moteTo of the user
175 void startFreeLook();
177 /// Stop Free Look (can be called multiple times if needed). Additionaly, the mouse/pointer is restored
178 void stopFreeLook();
180 /// Is the camera inside the character.
181 bool isInternalView() {return _InternalView;}
183 /// Update keyboard rotation
184 void keyboardRotationLR (bool left, bool right);
185 void keyboardRotationUD (bool up, bool down);
186 void keyboardRotationCameraLR (bool left, bool right);
188 void startCombat() {_CameraAuto = true;}
190 /// Enable/Disable Autowalk
191 void autowalkState(bool enable);
192 /// Return the autowalk state ('true'=enable).
193 bool autowalkState() const {return ((_DirectionMove & autowalk)!=0);}
195 /// Update velocity
196 static void updateVelocity (float deltaTime, float acceleration, float brake, float speedMax, float &speed);
199 // get the camera Delta Yaw
200 float getCameraDeltaYaw() const {return _UserCameraDeltaYaw;}
202 // just reset the camera Delta Yaw (instantaneously)
203 void resetCameraDeltaYaw();
205 // reset the camera Delta Yaw (smooth over time, canceled by user)
206 void resetSmoothCameraDeltaYaw();
208 // append to the camera Delta Yaw (NB: any smooth reset is then canceled)
209 void appendCameraDeltaYaw(float dYaw);
211 // reset the camera Delta Yaw and change the user front so the final Yaw remains the same
212 void applyCameraDeltaYawToUser();
214 // true if there is currently a smooth reset of the cameraDeltaYaw (in force mode)
215 bool isResetSmoothCDYForced() const {return _ResetSmoothCameraDeltaYaw==ResetCDYForced;}
217 // capture the mouse, prevent the free look from being trigger on a long click
218 void captureMouse() { _MouseCaptured = true; }
219 void releaseMouse() { _MouseCaptured = false; }
220 bool isMouseCaptured() { return _MouseCaptured; }
222 /// user has to release forward key before he can go forward again
223 void needReleaseForward();
225 /// return true if user do forward or backward move action with key or mouth
226 bool isMoving() { return _DirectionMove != none; }
228 private:
230 bool _MouseCaptured; // no free look allowed when mouse is captures
232 // Is the camera controled by the user or not.
233 bool _CameraAuto;
235 bool _LastFrameForward;
236 bool _LastFrameBackward;
237 bool _LastFrameAutowalk;
238 bool _LastFrameStrafeLeft;
239 bool _LastFrameStrafeRight;
240 bool _LastFrameTurnLeft;
241 bool _LastFrameTurnRight;
242 bool _LastFrameLeftButtonDown;
243 // NB: modified only when not in freelook mode
244 float _LastFrameMousePosX;
245 float _LastFrameMousePosY;
246 bool _CurrentFrameFreeLookCalled;
247 /// Used to lock motion.
248 bool _Locked;
250 /// Are we in displacement or not ?
251 uint32 _DirectionMove;
253 /// moving mode
254 TMoveMode _Mode;
255 /// last moving mode
256 TMoveMode _LastMode;
258 /// speed in translation
259 float _TransSpeed;
261 /// fly velocity
262 float _FlyVerticalVelocity;
263 float _FlyFrontVelocity;
264 float _FlyLateralVelocity;
265 float _RotateUserLRVelocity;
266 float _RotateUserUDVelocity;
267 float _RotateCameraLRVelocity;
270 bool _UpdateView;
273 NLMISC::CVector _Start;
275 NLMISC::CVector _Destination;
278 float _Acc;
279 float _T0;
280 float _T;
281 float _V0;
284 float _ZOscil;
287 float _Dist;
288 float _PrevDist;
291 bool _TurnBack;
293 /// "true" if the character has a destination to go.
294 bool _ClickMove;
297 float _T0View;
298 float _TView;
299 float _ViewSpeed;
301 bool _FreeLook;
303 bool _InternalView;
305 // User Camera Yaw
306 float _UserCameraDeltaYaw;
307 // Forced mode is related to moveTo/follow feature
308 enum TResetCDY {ResetCDYOff=0, ResetCDYOn, ResetCDYForced};
309 TResetCDY _ResetSmoothCameraDeltaYaw;
311 /// when true user has to release forward key before he can go forward again
312 bool _NeedReleaseForward;
314 /// when true the next forward action will cancel any moveto
315 bool _NextForwardCancelMoveTo;
317 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _UiVarMkMoveDB;
320 /// User Controls (mouse, keyboard, interfaces, ...)
321 extern CUserControls UserControls;
324 #endif // CL_USER_CONTROLS_H
326 /* End of user_controls.h */