1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
21 #include "main_loop_utilities.h"
23 #include <nel/3d/u_driver.h>
24 #include <nel/3d/u_cloud_scape.h>
25 #include <nel/3d/fxaa.h>
26 #include <nel/3d/stereo_display.h>
28 #include "game_share/scenario_entry_points.h"
30 #include "client_cfg.h"
33 #include "world_database_manager.h"
34 #include "continent_manager.h"
35 #include "user_entity.h"
37 #include "ig_client.h"
40 #include "sound_manager.h"
42 #include "interface_v3/interface_manager.h"
44 using namespace NLMISC
;
47 void updateVRDevicesComboUI(); // from action_handler_game.cpp
48 void initStereoDisplayDevice(); // from init.cpp
49 void releaseStereoDisplayDevice(); // from release.cpp
51 //---------------------------------------------------
52 // Compare ClientCfg and LastClientCfg to know what we must update
53 //---------------------------------------------------
54 void updateFromClientCfg()
56 CClientConfig::setValues();
57 ClientCfg
.IsInvalidated
= false;
59 if ((ClientCfg
.VREnable
!= LastClientCfg
.VREnable
)
60 || (ClientCfg
.VREnable
&& (
61 ClientCfg
.VRDisplayDevice
!= LastClientCfg
.VRDisplayDevice
62 || ClientCfg
.VRDisplayDeviceId
!= LastClientCfg
.VRDisplayDeviceId
65 nldebug("Apply VR device change");
66 // detach display mode
67 if (StereoDisplay
&& StereoDisplayAttached
)
68 StereoDisplay
->detachFromDisplay();
69 StereoDisplayAttached
= false;
71 releaseStereoDisplayDevice();
72 initStereoDisplayDevice();
73 // try attach display mode
75 StereoDisplayAttached
= StereoDisplay
->attachToDisplay();
76 // set latest config display mode if not attached
77 if (!StereoDisplayAttached
)
78 setVideoMode(UDriver::CMode(ClientCfg
.Width
, ClientCfg
.Height
, (uint8
)ClientCfg
.Depth
,
79 ClientCfg
.Windowed
, ClientCfg
.Frequency
));
80 // force software cursor when attached
81 InitMouseWithCursor(ClientCfg
.HardwareCursor
&& !StereoDisplayAttached
);
85 //---------------------------------------------------
86 if ((ClientCfg
.Windowed
!= LastClientCfg
.Windowed
) ||
87 (ClientCfg
.Width
!= LastClientCfg
.Width
) ||
88 (ClientCfg
.Height
!= LastClientCfg
.Height
) ||
89 (ClientCfg
.Depth
!= LastClientCfg
.Depth
) ||
90 (ClientCfg
.Frequency
!= LastClientCfg
.Frequency
))
92 if (!StereoDisplayAttached
)
94 setVideoMode(UDriver::CMode(ClientCfg
.Width
, ClientCfg
.Height
, (uint8
)ClientCfg
.Depth
,
95 ClientCfg
.Windowed
, ClientCfg
.Frequency
));
99 if (ClientCfg
.DivideTextureSizeBy2
!= LastClientCfg
.DivideTextureSizeBy2
)
101 if (ClientCfg
.DivideTextureSizeBy2
)
102 Driver
->forceTextureResize(2);
104 Driver
->forceTextureResize(1);
107 if (ClientCfg
.InterfaceScale
!= LastClientCfg
.InterfaceScale
)
108 CInterfaceManager::getInstance()->setInterfaceScale(ClientCfg
.InterfaceScale
);
110 if (ClientCfg
.BilinearUI
!= LastClientCfg
.BilinearUI
)
111 CViewRenderer::getInstance()->setBilinearFiltering(ClientCfg
.BilinearUI
);
113 CWidgetManager::getInstance()->setWindowSnapInvert(ClientCfg
.WindowSnapInvert
);
114 CWidgetManager::getInstance()->setWindowSnapDistance(ClientCfg
.WindowSnapDistance
);
116 //---------------------------------------------------
117 if (ClientCfg
.WaitVBL
!= LastClientCfg
.WaitVBL
)
119 if(ClientCfg
.WaitVBL
)
120 Driver
->setSwapVBLInterval(1);
122 Driver
->setSwapVBLInterval(0);
125 // GRAPHICS - LANDSCAPE
126 //---------------------------------------------------
127 if (ClientCfg
.LandscapeThreshold
!= LastClientCfg
.LandscapeThreshold
)
129 if (Landscape
) Landscape
->setThreshold(ClientCfg
.getActualLandscapeThreshold());
132 //---------------------------------------------------
133 if (ClientCfg
.LandscapeTileNear
!= LastClientCfg
.LandscapeTileNear
)
135 if (Landscape
) Landscape
->setTileNear(ClientCfg
.LandscapeTileNear
);
138 //---------------------------------------------------
141 if (ClientCfg
.Vision
!= LastClientCfg
.Vision
)
143 if (!ClientCfg
.Light
)
145 // Not in an indoor ?
146 if (ContinentMngr
.cur() && !ContinentMngr
.cur()->Indoor
)
148 // Refresh All Zone in streaming according to the refine position
149 std::vector
<string
> zonesAdded
;
150 std::vector
<string
> zonesRemoved
;
151 const R2::CScenarioEntryPoints::CCompleteIsland
*ci
= R2::CScenarioEntryPoints::getInstance().getCompleteIslandFromCoords(CVector2f((float) UserEntity
->pos().x
, (float) UserEntity
->pos().y
));
152 Landscape
->refreshAllZonesAround(View
.refinePos(), ClientCfg
.Vision
+ ExtraZoneLoadingVision
, zonesAdded
, zonesRemoved
, ProgressBar
, ci
? &(ci
->ZoneIDs
) : NULL
);
153 LandscapeIGManager
.unloadArrayZoneIG(zonesRemoved
);
154 LandscapeIGManager
.loadArrayZoneIG(zonesAdded
);
160 //---------------------------------------------------
161 if (ClientCfg
.Vision
!= LastClientCfg
.Vision
|| ClientCfg
.FoV
!=LastClientCfg
.FoV
||
162 ClientCfg
.Windowed
!= LastClientCfg
.Windowed
|| ClientCfg
.ScreenAspectRatio
!= LastClientCfg
.ScreenAspectRatio
)
164 updateCameraPerspective();
167 //---------------------------------------------------
170 if (ClientCfg
.MicroVeget
!= LastClientCfg
.MicroVeget
)
172 if(ClientCfg
.MicroVeget
)
174 // if configured, enable the vegetable and load the texture.
175 Landscape
->enableVegetable(true);
176 // Default setup. TODO later by gameDev.
177 Landscape
->setVegetableWind(CVector(0.5, 0.5, 0).normed(), 0.5, 1, 0);
178 // Default setup. should work well for night/day transition in 30 minutes.
179 // Because all vegetables will be updated every 20 seconds => 90 steps.
180 Landscape
->setVegetableUpdateLightingFrequency(1/20.f
);
181 // Density (percentage to ratio)
182 Landscape
->setVegetableDensity(ClientCfg
.MicroVegetDensity
/100.f
);
186 Landscape
->enableVegetable(false);
191 //---------------------------------------------------
192 if (ClientCfg
.MicroVegetDensity
!= LastClientCfg
.MicroVegetDensity
)
194 // Density (percentage to ratio)
195 if (Landscape
) Landscape
->setVegetableDensity(ClientCfg
.MicroVegetDensity
/100.f
);
198 // GRAPHICS - SPECIAL EFFECTS
199 //---------------------------------------------------
200 if (ClientCfg
.FxNbMaxPoly
!= LastClientCfg
.FxNbMaxPoly
)
202 if (Scene
->getGroupLoadMaxPolygon("Fx") != ClientCfg
.FxNbMaxPoly
)
203 Scene
->setGroupLoadMaxPolygon("Fx", ClientCfg
.FxNbMaxPoly
);
206 //---------------------------------------------------
207 if (ClientCfg
.Cloud
!= LastClientCfg
.Cloud
)
211 InitCloudScape
= true;
212 CloudScape
= Scene
->createCloudScape();
216 if (CloudScape
!= NULL
)
217 Scene
->deleteCloudScape(CloudScape
);
222 //---------------------------------------------------
223 if (ClientCfg
.CloudQuality
!= LastClientCfg
.CloudQuality
)
225 if (CloudScape
!= NULL
)
226 CloudScape
->setQuality(ClientCfg
.CloudQuality
);
229 //---------------------------------------------------
230 if (ClientCfg
.CloudUpdate
!= LastClientCfg
.CloudUpdate
)
232 if (CloudScape
!= NULL
)
233 CloudScape
->setNbCloudToUpdateIn80ms(ClientCfg
.CloudUpdate
);
236 //---------------------------------------------------
237 if (ClientCfg
.Shadows
!= LastClientCfg
.Shadows
)
239 // Enable/Disable Receive on Landscape
242 Landscape
->enableReceiveShadowMap(ClientCfg
.Shadows
);
244 // Enable/Disable Cast for all entities
245 for(uint i
=0;i
<EntitiesMngr
.entities().size();i
++)
247 CEntityCL
*ent
= EntitiesMngr
.entities()[i
];
249 ent
->updateCastShadowMap();
253 //---------------------------------------------------
254 if (ClientCfg
.AnisotropicFilter
!= LastClientCfg
.AnisotropicFilter
)
256 Driver
->setAnisotropicFilter(ClientCfg
.AnisotropicFilter
);
259 //---------------------------------------------------
260 if (ClientCfg
.FXAA
!= LastClientCfg
.FXAA
)
265 FXAA
= new NL3D::CFXAA(Driver
);
275 // GRAPHICS - CHARACTERS
276 //---------------------------------------------------
277 if (ClientCfg
.SkinNbMaxPoly
!= LastClientCfg
.SkinNbMaxPoly
)
279 if (Scene
->getGroupLoadMaxPolygon("Skin") != ClientCfg
.SkinNbMaxPoly
)
280 Scene
->setGroupLoadMaxPolygon("Skin", ClientCfg
.SkinNbMaxPoly
);
283 //---------------------------------------------------
284 if (ClientCfg
.NbMaxSkeletonNotCLod
!= LastClientCfg
.NbMaxSkeletonNotCLod
)
286 Scene
->setMaxSkeletonsInNotCLodForm(ClientCfg
.NbMaxSkeletonNotCLod
);
289 //---------------------------------------------------
290 if (ClientCfg
.CharacterFarClip
!= LastClientCfg
.CharacterFarClip
)
295 //---------------------------------------------------
296 if (ClientCfg
.HDEntityTexture
!= LastClientCfg
.HDEntityTexture
)
298 // Don't reload Texture, will be done at next Game Start
305 //---------------------------------------------------
306 if (ClientCfg
.CursorSpeed
!= LastClientCfg
.CursorSpeed
)
307 SetMouseSpeed (ClientCfg
.CursorSpeed
);
309 if (ClientCfg
.CursorAcceleration
!= LastClientCfg
.CursorAcceleration
)
310 SetMouseAcceleration (ClientCfg
.CursorAcceleration
);
312 if (ClientCfg
.HardwareCursor
!= LastClientCfg
.HardwareCursor
)
314 if (ClientCfg
.HardwareCursor
!= IsMouseCursorHardware())
316 InitMouseWithCursor (ClientCfg
.HardwareCursor
&& !StereoDisplayAttached
);
322 //---------------------------------------------------
323 bool mustReloadSoundMngrContinent
= false;
325 // disable/enable sound?
326 if (ClientCfg
.SoundOn
!= LastClientCfg
.SoundOn
)
328 if (SoundMngr
&& !ClientCfg
.SoundOn
)
330 nlwarning("Deleting sound manager...");
334 else if (SoundMngr
== NULL
&& ClientCfg
.SoundOn
)
336 nlwarning("Creating sound manager...");
337 SoundMngr
= new CSoundManager();
340 SoundMngr
->init(NULL
);
342 catch(const Exception
&e
)
344 nlwarning("init : Error when creating 'SoundMngr' : %s", e
.what());
349 // re-init with good SFX/Music Volume
352 SoundMngr
->setSFXVolume(ClientCfg
.SoundSFXVolume
);
353 SoundMngr
->setGameMusicVolume(ClientCfg
.SoundGameMusicVolume
);
358 nlwarning("Sound config error !");
361 mustReloadSoundMngrContinent
= true;
365 if ( SoundMngr
&& LastClientCfg
.SoundOn
&&
366 (ClientCfg
.UseEax
!= LastClientCfg
.UseEax
) )
370 mustReloadSoundMngrContinent
= true;
373 // change SoundForceSoftwareBuffer?
374 if ( SoundMngr
&& LastClientCfg
.SoundOn
&&
375 (ClientCfg
.SoundForceSoftwareBuffer
!= LastClientCfg
.SoundForceSoftwareBuffer
) )
379 mustReloadSoundMngrContinent
= true;
382 // change MaxTrack? don't reset
383 if ( SoundMngr
&& LastClientCfg
.SoundOn
&&
384 (ClientCfg
.MaxTrack
!= LastClientCfg
.MaxTrack
))
386 SoundMngr
->getMixer()->changeMaxTrack(ClientCfg
.MaxTrack
);
389 // change SoundFX Volume? don't reset
390 if (SoundMngr
&& ClientCfg
.SoundSFXVolume
!= LastClientCfg
.SoundSFXVolume
)
392 SoundMngr
->setSFXVolume(ClientCfg
.SoundSFXVolume
);
395 // change Game Music Volume? don't reset
396 if (SoundMngr
&& ClientCfg
.SoundGameMusicVolume
!= LastClientCfg
.SoundGameMusicVolume
)
398 SoundMngr
->setGameMusicVolume(ClientCfg
.SoundGameMusicVolume
);
401 // reload only if active and reseted
402 if (mustReloadSoundMngrContinent
&& SoundMngr
&& ContinentMngr
.cur() && !ContinentMngr
.cur()->Indoor
&& UserEntity
)
404 SoundMngr
->loadContinent(ContinentMngr
.getCurrentContinentSelectName(), UserEntity
->pos());
407 // Ok backup the new clientcfg
408 LastClientCfg
= ClientCfg
;