Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / release.cpp
blobb29683149699aff3f17a10181a62e7d73fec0162
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 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2013-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /////////////
25 // INCLUDE //
26 /////////////
27 #include "stdpch.h"
28 // Misc.
29 #include "nel/misc/debug.h"
30 #include "nel/misc/async_file_manager.h"
31 #include "nel/misc/system_utils.h"
32 #include "nel/misc/streamed_package_manager.h"
33 #include "nel/web/http_package_provider.h"
34 // 3D Interface.
35 #include "nel/3d/bloom_effect.h"
36 #include "nel/3d/fxaa.h"
37 #include "nel/3d/fasthls_modifier.h"
38 #include "nel/3d/particle_system_manager.h"
39 #include "nel/3d/particle_system.h"
40 #include "nel/3d/particle_system_shape.h"
41 #include "nel/3d/u_driver.h"
42 #include "nel/3d/u_scene.h"
43 #include "nel/3d/u_visual_collision_manager.h"
44 #include "nel/3d/u_shape_bank.h"
45 #include "nel/3d/stereo_hmd.h"
46 #include "nel/3d/async_file_manager_3d.h"
47 // Client
48 #include "global.h"
49 #include "release.h"
50 #include "actions.h"
51 #include "ig_client.h"
52 #include "entities.h"
53 #include "net_manager.h"
54 #include "pacs_client.h"
55 #include "world_database_manager.h"
56 #include "continent_manager.h"
57 #include "sound_manager.h"
58 #include "weather.h"
59 #include "weather_manager_client.h"
60 #include "prim_file.h"
61 #include "interface_v3/input_handler_manager.h"
62 #include "interface_v3/interface_manager.h"
63 #include "interface_v3/people_interraction.h"
64 #include "connection.h"
65 #include "commands.h"
66 #include "timed_fx_manager.h"
67 #include "interface_v3/sphrase_manager.h"
68 #include "interface_v3/chat_text_manager.h"
69 #include "interface_v3/dbctrl_sheet.h"
70 #include "projectile_manager.h"
71 #include "init_main_loop.h"
72 #include "fx_manager.h"
73 #include "animation_fx_misc.h"
74 #include "fx_manager.h"
75 #include "micro_life_manager.h"
76 #include "attack_list.h"
77 #include "auto_anim.h"
78 #include "string_manager_client.h"
79 #include "precipitation_clip_grid.h"
80 #include "interface_v3/music_player.h"
81 #include "login.h"
82 #include "actions_client.h"
83 #include "login_progress_post_thread.h"
85 #include "r2/editor.h"
86 #include "nel/misc/big_file.h"
87 #include "nel/net/module_manager.h"
88 #include "game_share/fame.h"
89 #include "interface_v3/sbrick_manager.h"
90 #include "interface_v3/skill_manager.h"
91 #include "sheet_manager.h"
92 #include "interface_v3/macrocmd_manager.h"
93 #include "game_share/scenario_entry_points.h"
94 #include "interface_v3/bar_manager.h"
95 #include "landscape_poly_drawer.h"
96 #include "game_share/visual_slot_manager.h"
97 #include "door_manager.h"
98 #include "interface_v3/encyclopedia_manager.h"
99 #include "faction_war_manager.h"
100 #include "interface_v3/interface_ddx.h"
101 #include "bg_downloader_access.h"
102 #include "nel/gui/lua_manager.h"
103 #include "item_group_manager.h"
104 #include "nel/gui/http_cache.h"
105 #include "nel/gui/http_hsts.h"
107 ///////////
108 // USING //
109 ///////////
110 using namespace NL3D;
111 using namespace NLMISC;
113 #ifdef DEBUG_NEW
114 #define new DEBUG_NEW
115 #endif
117 ////////////
118 // EXTERN //
119 ////////////
120 extern UDriver *Driver;
121 extern UScene *Scene;
122 extern UCloudScape *CloudScape;
123 extern UVisualCollisionManager *CollisionManager;
124 extern CEventsListener EventsListener; // Inputs Manager
125 extern ULandscape *Landscape;
126 extern UCamera MainCam;
127 extern UScene *SceneRoot;
128 extern UScene *SkyScene;
129 extern UInstanceGroup *BackgroundIG;
130 extern bool LastScreenSaverEnabled;
131 extern bool IsInRingSession;
132 extern bool noUserChar;
133 extern bool userChar;
134 extern bool serverReceivedReady;
135 extern bool CharNameValidArrived;
137 extern void releaseContextualCursor();
138 extern void selectTipsOfTheDay (uint tips);
140 ///////////////
141 // FUNCTIONS //
142 ///////////////
144 // ***************************************************************************
145 // Saving ingame resolution when in windowed mode
146 void saveIngameResolution()
148 if (ClientCfg.Windowed)
150 uint32 width, height;
151 Driver->getWindowSize(width, height);
152 ClientCfg.writeInt("Width", std::max((sint)width, 800));
153 ClientCfg.writeInt("Height", std::max((sint)height, 600));
157 // ***************************************************************************
158 // 3D element release, called from both releaseMainLoopReselect() and releaseMainLoop()
159 static void releaseMainLoopScenes()
161 if(!Driver)
162 return;
164 // Delete the main scene
165 if(Scene)
167 // Release water envmap
168 #ifdef USE_WATER_ENV_MAP
169 Driver->deleteWaterEnvMap(WaterEnvMap);
170 #endif
172 // Release FX manager
173 CTimedFXManager::getInstance().reset();
175 WeatherManager.release();
177 // Release the landscape. NB: all pending async loading zones are deleted here
178 if (Landscape)
180 Scene->deleteLandscape (Landscape);
181 Landscape = NULL;
184 // Release the collision manager
185 Scene->deleteVisualCollisionManager(CollisionManager);
186 CollisionManager = NULL;
188 // release cloud scape
189 if (CloudScape)
191 Scene->deleteCloudScape(CloudScape);
192 CloudScape = NULL;
195 // remove the scene from the sound lib
196 if (SoundMngr != NULL)
197 SoundMngr->getMixer()->initClusteredSound((UScene*)NULL, 0.01f, 100.0f, 1.0f);
199 // Stop any async loading. Actually all should have been stop before
200 CAsyncFileManager::terminate();
202 // Release the scene.
203 Driver->deleteScene(Scene);
204 Scene = NULL;
205 MainCam = NULL;
207 // remove scene from bloom
208 CBloomEffect::getInstance().setScene(NULL);
211 // Delete the scene with the Big Root
212 if (SceneRoot)
214 if (BackgroundIG)
216 BackgroundIG->removeFromScene (*SceneRoot);
217 SceneRoot->deleteInstanceGroup (BackgroundIG);
218 BackgroundIG = NULL;
221 Driver->deleteScene(SceneRoot);
222 SceneRoot = NULL;
226 volatile bool TempResetShapeBankOnRetCharSelect = false;
228 // ***************************************************************************
229 // Release all the memory before come back to out game (real thing!)
230 void releaseMainLoopReselect()
232 ProgressBar.release();
234 saveIngameResolution();
236 CInterfaceManager *pIM= CInterfaceManager::getInstance();
238 // save keys loaded and interface cfg (not done in releaseMainLoop() because done at end of mainLoop()...)
239 pIM->uninitInGame0();
240 CItemGroupManager::getInstance()->uninit();
242 // alredy called from farTPMainLoop()
243 // --R2::getEditor().autoConfigRelease(IsInRingSession);
245 // stop any user played music
246 MusicPlayer.stop();
248 // only really needed at exit
249 // --STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
251 // Remove all entities.
252 if (Driver)
254 nldebug("RCSR1: %u textures", Driver->getTotalAsyncTextureSizeAsked());
257 EntitiesMngr.release();
259 if (Driver)
261 nldebug("RCSR2: %u textures", Driver->getTotalAsyncTextureSizeAsked());
264 // Reset Fx manager (must be done after EntitiesMngr.release()) Important because may still point to 3D elements
265 FXMngr.reset();
267 // Interface release
268 CInterfaceManager::getInstance()->uninitInGame1();
270 // Remove key / action / some interface stuff (done through CInterfaceManager::destroy() in releaseMainLoop I think)
271 ActionsContext.removeAllCombos();
272 EditActions.releaseAllKeyNoRunning();
273 Actions.releaseAllKeyNoRunning();
274 CWidgetManager::getInstance()->getParser()->removeAllTemplates();
275 CWidgetManager::getInstance()->setCaptureKeyboard(NULL);
276 CWidgetManager::getInstance()->setCapturePointerLeft(NULL);
277 CWidgetManager::getInstance()->setCapturePointerRight(NULL);
279 // Yoyo: Don't release attack list manager, because I think it only owns static data (and 3D data created from Driver, not Scenes)
280 // Note that in initMainLoop(), CAttackListManager::getInstance().init() will do nothing (since already created and not released here)
281 // --CAttackListManager::getInstance().release();
283 // Still release the AnimFXMisc, because btw will still be released at AnimFXMisc.init() time init initMainLoop()
284 AnimFXMisc.release();
286 // Don't care!
287 // --selectTipsOfTheDay (rand());
289 // Reset the continent manager. NB: btw will be done at initMainLoop() (from preloadSheets)
290 // and important to do before release of timedfx manager
291 ContinentMngr.reset();
293 // Remove all projectile
294 CProjectileManager::getInstance().reset();
296 // Remove micro-life (btw done at each CContinent::unselect())
297 CMicroLifeManager::getInstance().release();
299 // not really needed (static GuildMat Material created from Driver)
300 // --CDBCtrlSheet::release ();
302 // Release the Entities Animation Manager (Yoyo: fuckingly important because keep a pointer
303 // on a _PlayListManager that is created from Scene)
304 if (Driver)
306 nldebug("RCSR3: %u textures", Driver->getTotalAsyncTextureSizeAsked());
309 CEntityAnimationManager::delInstance();
310 EAM= NULL;
312 if (Driver)
314 nldebug("RCSR4: %u textures", Driver->getTotalAsyncTextureSizeAsked());
317 // Not necessary I think because owns only static data (string + function ptrs)
318 // --releaseContextualCursor();
320 // Release 3D components
321 if(Driver)
323 // Release Scene, SceneRoot and their elements
324 // Yoyo: important to do it else leak because recreated/reloaded in initMainLoop() on same pointer (=> old one not released)!!!
325 releaseMainLoopScenes();
327 // release the auto animation (btw done in initMainLoop()...)
328 releaseAutoAnimation();
330 // Don't Release the shape bank! => optimisation: preloading of character/objects shapes will not be redone!
331 if (ClientCfg.ResetShapeBankOnRetCharSelect)
333 Driver->getShapeBank()->reset();
334 nldebug("RCSR5: %u textures", Driver->getTotalAsyncTextureSizeAsked());
339 // Release FX manager
340 CTimedFXManager::getInstance().reset();
342 // Don't Purge memory because PointLight may still be present in other Scenes (sky scene...) for instance
343 // --UDriver::purgeMemory();
345 // String manager: remove all waiting callbacks and removers
346 // (if some interface stuff has not received its string yet, its remover will get useless)
347 STRING_MANAGER::CStringManagerClient::release( false );
349 // release titles info
350 CSkillManager::getInstance()->uninitInGame();
352 // Ugly globals
353 userChar = false;
354 noUserChar = false;
355 serverReceivedReady = false;
356 CharNameValidArrived = false;
357 UserCharPosReceived = false;
358 SabrinaPhraseBookLoaded = false;
360 // Unlink the net manager
361 NetMngr.setDataBase (NULL);
363 // reset the client database and clear all observers. must do this while we are disconnected!
364 // First remove the auto copy observers
365 pIM->releaseServerToLocalAutoCopyObservers();
366 // Then remove the SERVER and LOCAL database (NB: "UI" node was removed by uninitIngame1())
367 ICDBNode::CTextId serverId("SERVER"), localId("LOCAL");
368 NLGUI::CDBManager::getInstance()->getDB()->removeNode(serverId);
369 NLGUI::CDBManager::getInstance()->getDB()->removeNode(localId);
370 nlassert(IngameDbMngr.getNodePtr()==NULL); // actually it is the "SERVER" node kept by CRefPtr => should be NULL
371 IngameDbMngr.clear(); // still important for CDBBranch statics data release
372 // NB: "SERVER" and "LOCAL" node will be recreated by initMainLoop
375 // Don't destroy the whole interface manager. Hope it is not important....
376 // --CInterfaceManager::destroy ();
378 // Leave Connection stuff to farTPMainLoop
379 // --NetMngr.....
383 // ***************************************************************************
384 // Release all the memory before come back to out game.
385 // Yoyo: actually, because of change by AJM, this method is called only when the user quit the app.
386 // see releaseMainLoopReselect() for the actual method called for reselection
387 // Btw the 2 methods should have strong similarities
388 void releaseMainLoop(bool closeConnection)
390 ProgressBar.release();
392 // Release R2 editor if applicable
393 R2::getEditor().autoConfigRelease(IsInRingSession);
395 // stop any user played music
396 MusicPlayer.stop();
398 // flush the server string cache
399 STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
401 // Remove all entities.
402 EntitiesMngr.release();
404 // Reset Fx manager (must be done after EntitiesMngr.release())
405 FXMngr.reset();
407 // Interface release
408 CInterfaceManager::getInstance()->uninitInGame1();
410 // release attack list manager
411 CAttackListManager::getInstance().release();
413 AnimFXMisc.release();
415 // Change the tips
416 selectTipsOfTheDay (rand());
418 // Reset the continent manager
419 ContinentMngr.reset();
421 // Remove all projectile
422 CProjectileManager::getInstance().reset();
424 if (Landscape)
426 //Landscape->removeTileCallback(&HeightGrid);
429 // Remove micro-life
430 CMicroLifeManager::getInstance().release();
432 // CCtrlSheetInfo release
433 CDBCtrlSheet::release ();
435 // Release the Entities Animation Manager
436 CEntityAnimationManager::delInstance();
437 EAM= NULL;
439 // Release the cursors
440 releaseContextualCursor();
443 // Release 3D
444 if(Driver)
446 // Release Scene, SceneRoot and their elements
447 releaseMainLoopScenes();
449 // release the auto animation
450 releaseAutoAnimation();
452 // Release the shape bank
453 Driver->getShapeBank()->reset();
456 // Release FX manager
457 CTimedFXManager::getInstance().reset();
459 // Purge memory
460 UDriver::purgeMemory();
462 // Unlink the net manager
463 NetMngr.setDataBase (NULL);
465 // Send a msg to server
466 if(!ClientCfg.Local)
468 if (closeConnection)
469 NetMngr.disconnect();
470 else
471 NetMngr.quit();
473 // Quit game, return to select character
474 CBitMemStream out;
475 if(GenericMsgHeaderMngr.pushNameToStream("CONNECTION:QUIT_GAME", out))
477 NetMngr.push(out);
479 else
480 nlwarning(" unknown message name 'CONNECTION:QUIT_GAME'");
483 // to be sure server crash is not fault of client
484 ConnectionReadySent= false;
487 }// release //
489 // ***************************************************************************
490 // Called when Quit from OutGame
491 void releaseOutGame()
493 #ifdef RYZOM_BG_DOWNLOADER
494 CBGDownloaderAccess::getInstance().release();
495 #endif
497 ProgressBar.release();
499 // flush the server string cache
500 STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
502 // Disconnect the client from the server.
503 NetMngr.disconnect();
505 // Interface release
506 CInterfaceManager::getInstance()->uninitOutGame();
508 // delete the sound manager
509 if(SoundMngr)
511 delete SoundMngr;
512 SoundMngr = NULL;
515 // Delete the driver.
516 if(Driver)
518 // Stop any async loading. Actually nohting should be async loaded in outgame.
519 CAsyncFileManager::terminate();
521 // If there is a scene.
522 if(Scene)
524 // Release the scene.
525 Driver->deleteScene(Scene);
526 Scene = 0;
529 // Remove the Actions listener from the Events Server.
530 EventsListener.removeFromServer(CInputHandlerManager::getInstance()->FilteredEventServer);
532 // Release effects
533 delete FXAA; FXAA = NULL;
534 CBloomEffect::releaseInstance();
536 // Release Scene, textcontexts, materials, ...
537 Driver->release();
539 // Delete the driver.
540 delete Driver;
541 Driver = 0;
544 ContinentMngr.reset();
547 void releaseStereoDisplayDevice()
549 if (StereoDisplay)
551 StereoDisplay->getOriginalFrustum(0, &MainCam);
552 if (SceneRoot)
554 UCamera cam = SceneRoot->getCam();
555 StereoDisplay->getOriginalFrustum(1, &cam);
557 nlassert(Driver);
558 Driver->setViewport(NL3D::CViewport());
559 nlassert(Scene);
560 Scene->setViewport(NL3D::CViewport());
561 delete StereoDisplay;
562 StereoDisplay = NULL;
563 StereoHMD = NULL;
565 IStereoDisplay::releaseAllLibraries();
568 // ***************************************************************************
569 // final release : Release before exit.
570 void release()
572 if (StartPlayTime != 0)
574 CLoginProgressPostThread::getInstance().step(CLoginStep(LoginStep_GameExit, "login_step_game_exit&play_time=" + toString((NLMISC::CTime::getLocalTime() - StartPlayTime) / 1000)));
577 setCrashCallback(NULL);
579 #ifdef RYZOM_BG_DOWNLOADER
580 CBGDownloaderAccess::getInstance().release();
581 #endif
583 ProgressBar.release();
585 R2::CEditor::releaseInstance();
587 // flush the server string cache
588 STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
589 STRING_MANAGER::CStringManagerClient::release(true);
591 // restore screensaver state
592 CSystemUtils::enableScreensaver(LastScreenSaverEnabled);
593 CSystemUtils::uninit();
595 // release PACS primitives
596 deletePrimitiveBlocks();
598 // Release the commands
599 releaseCommands();
601 // Exit config file stuff
602 ClientCfg.release();
604 // Disconnect the client from the server.
605 NetMngr.disconnect();
607 // delete the sound manager
608 if (SoundMngr)
610 delete SoundMngr;
611 SoundMngr = NULL;
614 // Release the Entities Animation Manager
615 CEntityAnimationManager::delInstance();
616 EAM = NULL;
618 nldebug("VR [C]: VR Shutting down");
619 releaseStereoDisplayDevice();
621 // Delete the driver.
622 if (Driver)
624 // Release the prim
625 PrimFiles.release(*Driver);
627 if (TextContext != NULL)
628 Driver->deleteTextContext(TextContext);
629 TextContext = NULL;
631 // Release effects
632 delete FXAA; FXAA = NULL;
633 CBloomEffect::releaseInstance();
635 // Release texture
636 endLoading();
638 // Release Scene, textcontexts, materials, ...
639 Driver->release();
641 // Delete the driver.
642 delete Driver;
643 Driver = NULL;
646 NetMngr.getConnection().close();
647 HttpClient.disconnect();
649 // Remove the Actions listener from the Events Server.
650 EventsListener.removeFromServer(CInputHandlerManager::getInstance()->FilteredEventServer);
652 IDisplayer *clientLogDisplayer = ErrorLog->getDisplayer("CLIENT.LOG");
653 if (clientLogDisplayer)
655 DebugLog->removeDisplayer(clientLogDisplayer);
656 InfoLog->removeDisplayer(clientLogDisplayer);
657 WarningLog->removeDisplayer(clientLogDisplayer);
658 ErrorLog->removeDisplayer(clientLogDisplayer);
659 AssertLog->removeDisplayer(clientLogDisplayer);
660 delete clientLogDisplayer;
663 CSheetId::uninit();
665 // shutdown a few other singletons
666 CLoginProgressPostThread::releaseInstance();
667 CAttackListManager::releaseInstance();
668 CFactionWarManager::release();
669 CEncyclopediaManager::releaseInstance();
670 CDoorManager::releaseInstance();
671 NL3D::CParticleSystemManager::release();
672 CUserCommand::release();
673 CStaticFames::releaseInstance();
674 CSPhraseManager::releaseInstance(); // must release before BrickManager, SkillManager
675 CSBrickManager::releaseInstance();
676 CSkillManager::releaseInstance();
677 CVisualSlotManager::releaseInstance();
678 CEntityAnimationManager::delInstance();
679 CBarManager::releaseInstance();
680 CInterfaceManager::destroy();
681 CDDXManager::releaseInstance();
682 R2::CObjectSerializer::releaseInstance();
683 NLMISC::CBigFile::getInstance().removeAll();
684 NLMISC::CBigFile::releaseInstance();
685 NLMISC::CStreamedPackageManager::releaseInstance();
686 delete HttpPackageProvider;
687 HttpPackageProvider = NULL;
688 NL3D::CFastHLSModifier::releaseInstance();
689 CLandscapePolyDrawer::releaseInstance();
690 NL3D::CParticleSystemShape::releaseInstance();
691 NLMISC::CPath::releaseInstance();
692 SheetMngr.release();
693 // releaseWeather(); // AJM FIXME conflicting ownership with SheetManager
694 R2::CScenarioEntryPoints::releaseInstance();
695 CMacroCmdManager::releaseInstance();
696 CInputHandlerManager::releaseInstance();
697 ICDBNode::releaseStringMapper();
698 CClassRegistry::release();
699 CReflectSystem::release();
700 CInterfaceExpr::release();
701 CPdrTokenRegistry::releaseInstance();
702 NLNET::IModuleManager::releaseInstance();
703 CLuaManager::releaseInstance();
704 NLGUI::CDBManager::release();
705 CWidgetManager::release();
706 CViewRenderer::release();
707 CIXml::releaseLibXml();
708 CHttpCache::release();
709 CStrictTransportSecurity::release();
710 CAsyncFileManager3D::releaseInstance();
712 #if FINAL_VERSION
713 // openURL ("http://ryzom.com/exit/");
714 #endif
716 }// release //