Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / misc.h
blob6ac9c17300aaa276c040b62657f86e8322460f2c
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) 2015-2020 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_MISC_H
24 #define CL_MISC_H
27 /////////////
28 // INCLUDE //
29 /////////////
30 // Misc
31 #include "nel/misc/types_nl.h"
32 #include "nel/misc/quat.h"
33 #include "nel/misc/rgba.h"
34 #include "nel/3d/u_instance.h"
35 #include "nel/3d/u_driver.h"
36 #include "game_share/slot_types.h"
37 #include "game_share/mode_and_behaviour.h"
40 ////////////
41 // DEFINE //
42 ////////////
43 #define _MOVIE_SHOOTER_ON_ //
45 // They want profile functions in final version
46 #define _PROFILE_ON_
48 ///////////
49 // CLASS //
50 ///////////
51 namespace NL3D
53 class UInstance;
54 class UScene;
57 namespace NLMISC
59 class CNoiseValue;
60 class CVector;
61 class CBitmap;
64 struct SPropVisualA;
65 struct SPropVisualB;
66 class CPlayerSheet;
68 enum TLightGroup
70 LightGroupAlways = 0,
71 LightGroupLandscapeDiffuse = 1,
72 LightGroupNightCycle = 2,
73 LightGroupDayCycle = 3,
74 LightGroupLandscapeAmbient = 4,
75 LightGroupFireworks
78 class CSeeds;
80 //////////////
81 // FUNCTION //
82 //////////////
83 double keepIn_NegPi_Pi(double angle);
85 double angleBetween2Vect(const NLMISC::CVectorD &from, const NLMISC::CVectorD &to);
87 /**
88 * \param face : pointer on the face to make up (must not be null).
89 * \param idMakeUp : index of the make-up to apply.
90 * \warning This function does not check if 'face' is valid.
92 void makeUp(NL3D::UInstance face, sint idMakeUp);
94 /**
95 * qStart is the quaterion at t=0,
96 * qEnd is the quaterion at t=TAnimEnd,
97 * time is between 0 and 1. (1=> TAnimEnd)
99 NLMISC::CQuat applyRotationFactor(NLMISC::CQuat in, float rotFactor, NLMISC::CQuat qStart, NLMISC::CQuat qEnd, float time);
101 /** Compute the angle between a source and a destination using the shortest way.
102 * \param from : angle between -Pi and Pi;
103 * \param to : angle between -Pi and Pi;
105 double computeShortestAngle(double from, double to);
107 /** Return the animset base name corresponding to the mode.
108 * \param mode : the mode to convert.
109 * \param result : this will be filed with the mode animset name.
110 * \return bool : 'true' if 'result' is filled, 'false' if left untouched.
112 bool mode2Anim(MBEHAV::EMode mode, std::string &result);
114 /** Compute the animation set to use according to weapons, mode and race.
115 * \param animSet : result pointer.
116 * \param mode : the mode.
117 * \param animSetBaseName : basic name to construc the complet name of the animSet.
118 * \param leftHand : animSet name for the left hand.
119 * \param rightHand : animSet name for the right hand.
120 * \param lookAtItemsInHands : compute animset according to items in hands or not.
121 * \return bool : 'true' if the new animation set is the right one. 'false' if the one choosen is not the right one.
123 bool computeAnimSet(const class CAnimationSet *&animSet, MBEHAV::EMode mode, const std::string &animSetBaseName, const class CItemSheet *itemLeftHand, const CItemSheet *itemRightHand, bool lookAtItemsInHands);
125 /** Create a file with the current state of the client (good to report a bug).
127 void dump(const std::string &name);
129 /** Create a file with the current state of the client (good to report a bug).
131 void loadDump(const std::string &name);
133 /** Get the lod character id from the scene, according to LodCharacterName. Cached.
134 * -1 if id not found.
136 sint getLodCharacterId(NL3D::UScene &scene, const std::string &lodCharacterName);
138 CItemSheet *getItem(const struct CGenderInfo &genderInfo, SLOTTYPE::EVisualSlot slot);
139 sint getColorIndex(const CGenderInfo &genderInfo, SLOTTYPE::EVisualSlot slot);
140 SPropVisualA buildPropVisualA(const CGenderInfo &genderInfo);
141 SPropVisualB buildPropVisualB(const CGenderInfo &genderInfo);
143 // Test whether user color is supported for a given visual slot
144 bool isUserColorSupported(const CPlayerSheet &playerSheet, SLOTTYPE::EVisualSlot vs);
145 SPropVisualA buildPropVisualA(const CPlayerSheet &playerSheet);
146 SPropVisualB buildPropVisualB(const CPlayerSheet &playerSheet);
148 // Draw a Box from 2 vectors.
149 void drawBox(const NLMISC::CVector &vMin, const NLMISC::CVector &vMax, const NLMISC::CRGBA &color);
151 // Draw a Wired Sphere
152 void drawSphere(const NLMISC::CVector &center, float radius, const NLMISC::CRGBA &color);
154 void getSeedsFromDB(CSeeds &dest);
157 /** Change a 'direction' vector.
158 * \param vectToChange : the vector to change.
159 * \param vect : new vector to use.
160 * \param compute : adjust the param 'vect' to be valid or leave the old one unchanged if impossible.
161 * \param check : warning if the param 'vect' is not valid (vector Null) even with compute=true.
162 * \return bool : 'true' if the vectToChange has been filled, else 'false'.
164 bool setVect(NLMISC::CVector &vectToChange, const NLMISC::CVector &vect, bool compute, bool check);
167 // read color from client cfg system info colors
168 NLMISC::CRGBA interpClientCfgColor(const std::string &src, std::string &dest);
169 // Get the category from the string (src="&SYS&Who are you?" and dest="Who are you?" and return "SYS"), if no category, return "SYS"
170 std::string getStringCategory(const std::string &src, std::string &dest, bool alwaysAddSysByDefault = true);
171 // Get the category from the string (src="&SYS&Who are you?" and dest="Who are you?" and return "SYS"), if no category, return ""
172 std::string getStringCategoryIfAny(const std::string &src, std::string &dest);
174 bool getRelativeFloatFromString(const std::string src, float &dst);
175 void updateVector(const std::string part, NLMISC::CVector &dst, float value, bool add = false);
177 // Number of shortcut
178 #define RYZOM_MAX_SHORTCUT 20
180 // Number of render filters
181 enum TFilter3d
183 FilterMeshNoVP=0,
184 FilterMeshVP,
185 FilterFXs,
186 FilterLandscape,
187 FilterVegetable,
188 FilterSkeleton,
189 FilterWater,
190 FilterCloud,
191 FilterCoarseMesh,
192 FilterSky,
193 RYZOM_MAX_FILTER_3D,
196 // compare 2 ucstring s0 and s1, without regard to case. give start and size for sequence p0 // OLD
197 sint ucstrnicmp(const ucstring &s0, uint p0, uint n0, const ucstring &s1); // OLD
199 /** Compute a non-continuous noise with uniform repartition in [0, 1], with the given noise object
200 * By default repartition is not uniform for noise
202 float computeUniformNoise(const NLMISC::CNoiseValue &nv, const NLMISC::CVector &pos);
205 // ***************************************************************************
206 void computeCurrentFovAspectRatio(float &fov, float &ar);
208 /** draw a disc in a bitmap
209 * \TODO : find a place for this in NLMISC
211 void drawDisc(NLMISC::CBitmap &dest, float x, float y, float radius, const NLMISC::CRGBA &color, bool additif = false, uint numSegs = 127);
214 // helper : get pointer to the current sky scene (new sky code, or fallback on old sky scene for continent that do not use the new system)
215 NL3D::UScene *getSkyScene();
217 // set emissive on all material of an instance (alpha is left unmodified)
218 void setEmissive(NL3D::UInstance instance, const NLMISC::CRGBA &color);
220 // set diffuse on all material of an instance (not including alpha)
221 void setDiffuse(NL3D::UInstance instance, bool onOff, const NLMISC::CRGBA &color);
223 // make an instance transparent (uses values from the shape material as a reference)
224 void makeInstanceTransparent(NL3D::UInstance &inst, uint8 opacity, bool disableZWrite);
227 // change the video mode, possibly centering the software mouse cursor if going to fullscreen
228 void setVideoMode(const NL3D::UDriver::CMode &mode);
230 // Get the current color depth (8, 16, or 32). In windowed mode, this will be the desktop color depth, in fullscreen mode, the color depth of the framebuffer.
231 uint getCurrentColorDepth();
233 // get maximized
234 bool isWindowMaximized();
236 // get all supported video modes
237 bool getRyzomModes(std::vector<NL3D::UDriver::CMode> &videoModes, std::vector<std::string> &stringModeList, std::vector<std::string> &stringFreqList, sint &nFoundMode, sint &nFoundFreq);
239 #endif // CL_MISC_H
241 /* End of misc.h */