Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / light_cycle_manager.h
blob45130e7855f8699ff12868bd505e807bef6b6d57
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CL_LIGHT_CYCLE_MANAGER_H
20 #define CL_LIGHT_CYCLE_MANAGER_H
22 /////////////
23 // INCLUDE //
24 /////////////
25 // Misc.
26 #include "nel/misc/types_nl.h"
27 #include "nel/misc/rgba.h"
28 // 3D Interface.
29 #include "nel/3d/u_driver.h"
30 #include "nel/3d/u_light.h"
32 #include "game_share/dir_light_setup.h"
33 #include "ig_enum.h"
35 ///////////
36 // USING //
37 ///////////
39 namespace NL3D
41 class UScene;
45 /// Description of the hours for days / night
46 struct CLightCycleDesc
48 float RealDayLength; // real length of the day, in seconds
49 float NumHours; // number of ryzom hours in a day
50 float NightTransitionStartHour; // start of night transition
51 float NightTransitionEndHour; // end of night transition
52 float DuskRatio; // ratio for dusk transition. e.g. when set to 0.5f, that means that the dusk colors are taken when the day->night transition is at its half
53 float DawnTransitionStartHour; // start of dawn transition
54 float DawnTransitionEndHour; // end of dawn transition
55 uint MaxNumColorSteps; // the max number of color steps
57 float getNightTransitionLength() const;
58 float getDawnTransitionLength() const;
62 class CWeatherManagerClient;
64 /**
65 * This class manage the weather and the time.
66 * \author Guillaume PUZIN
67 * \author Nicolas Vizerie
68 * \author Nevrax France
69 * \date 2001
71 class CLightCycleManager : public IIGObserver
73 public:
74 enum TLightState { Day = 0, Night, DayToNight, NightToDay, StateUnknown };
75 public:
76 /// ctor
77 CLightCycleManager();
78 /** Set the description of the light cycle
79 * This also reset the hour to 0
80 * \param desc description of lighting intervals
81 * \return true If the desc was valid (not overlapping transitions..)
83 bool setLightDesc(const CLightCycleDesc &desc);
84 // get the current light desc
85 const CLightCycleDesc &getLightDesc() const { return _Desc; }
86 /** Set the current hour, and change color if necessary.
87 * The caller can provide an additionnal lightning color if he want
88 * NB : the weather manager is needed if the lighting needs to be overriden in case of bad weather
90 void setHour(float hour, const CWeatherManagerClient &wm, NLMISC::CRGBA lightningColor);
92 float getHour() const { return _Hour; }
93 // Get the last computed light level in a call to setHour (from 0 fro day to 1 for night)
94 float getLightLevel() const { return _LightLevel; }
95 /// Create driver directionnal light light
96 void create();
97 /** Touch the light setup.
98 * The landscape patch are recomputed
100 void touch();
101 /// Get needed landscape update freq (or 0 if the setupped lightDesc was not valid)
102 float getLandscapePatchUpdateFreq() const;
104 /// Returns a string that describ the current state (day, night, ...)
105 std::string getStateString() const;
107 // Returns an enum that describe the current state
108 TLightState getState() const
110 return _State;
113 /// Test if a day->night or night->day transition is currently occuring
114 bool isInTransition() const;
116 /// From IIGObserver
117 virtual void instanceGroupLoaded(NL3D::UInstanceGroup * /* ig */) { }
118 virtual void instanceGroupAdded(NL3D::UInstanceGroup *ig);
119 virtual void instanceGroupRemoved(NL3D::UInstanceGroup * /* ig */) { }
121 /// get the light level at the given hour
122 float getLightLevel(float hour) const;
126 ///////////////////////////////////////////////////////////////////////////////////////////////
127 ///////////////////////////////////////////////////////////////////////////////////////////////
128 private:
129 float _Hour;
130 bool _Touched;
131 bool _ValidDesc;
132 NLMISC::CRGBA _LastDiffuse, _LastAmbient;
133 CLightCycleDesc _Desc;
134 float _LightLevel;
135 float _WeatherLighting, _LastWeatherLighting;
136 float _UpdateFreq;
137 TLightState _State;
138 TLightState _PrevState;
139 private:
140 void getLandscapeLightColor(NLMISC::CRGBA &diffuse, NLMISC::CRGBA &ambiant);
141 static bool isInInterval(float start, float end, float value);
142 static bool isInDayInterval(float startHour, float endHour, float dayDuration, float hour, float &ratio);
143 void setDirLight(const CDirLightSetup &setup0, const CDirLightSetup &setup1, float level, float intensity, NL3D::UScene &scene);
144 // get the number of hours for a landscape patch update
145 float getUpdateDuration() const;
146 /// Set the light to render the canopy or the sky
147 void setupCanopyLight(float intensity);
148 /// Set the light to render the main scene
149 void setupMainLight(float intensity);
150 // Setup light for canopy or main scene
151 void setupDayToNightLight(NL3D::UScene &scene, const CDirLightSetup &dayLight, const CDirLightSetup &duskLight, const CDirLightSetup &nightLight, float lightIntensity);
152 // Update the '_State' field
153 void updateState();
157 #endif // LIGHT_CYCLE_MANAGER
159 /* End of weather.h */