iw4x-client/src/Components/Loader.cpp

211 lines
5.6 KiB
C++
Raw Normal View History

#include "STDInclude.hpp"
2015-12-23 08:45:53 -05:00
namespace Components
{
2016-09-03 09:52:40 -04:00
bool Loader::Pregame = true;
bool Loader::Postgame = false;
bool Loader::Uninitializing = false;
2015-12-23 08:45:53 -05:00
std::vector<Component*> Loader::Components;
2016-09-03 09:52:40 -04:00
bool Loader::IsPregame()
{
return Loader::Pregame;
}
2017-02-24 07:30:31 -05:00
bool Loader::IsPostgame()
{
return Loader::Postgame;
}
bool Loader::IsUninitializing()
{
return Loader::Uninitializing;
}
2015-12-23 08:45:53 -05:00
void Loader::Initialize()
{
2016-09-03 09:52:40 -04:00
Loader::Pregame = true;
Loader::Postgame = false;
Loader::Uninitializing = false;
2017-06-02 09:36:20 -04:00
Utils::Memory::GetAllocator()->clear();
2016-09-03 09:52:40 -04:00
2016-01-03 18:00:07 -05:00
Loader::Register(new Flags());
Loader::Register(new Singleton());
Loader::Register(new Exception()); // install our exception handler as early as posssible to get better debug dumps from startup crashes
2015-12-27 14:05:43 -05:00
2016-02-21 13:57:56 -05:00
Loader::Register(new Auth());
2016-08-15 10:40:30 -04:00
Loader::Register(new Bans());
Loader::Register(new Bots());
2015-12-23 08:45:53 -05:00
Loader::Register(new Dvar());
2016-08-16 14:36:52 -04:00
Loader::Register(new Lean());
2015-12-25 20:51:58 -05:00
Loader::Register(new Maps());
2015-12-30 18:55:08 -05:00
Loader::Register(new News());
2018-10-09 04:53:15 -04:00
Loader::Register(new Node());
2016-02-17 16:21:42 -05:00
Loader::Register(new RCon());
Loader::Register(new Stats());
2015-12-23 16:21:03 -05:00
Loader::Register(new Menus());
2016-06-24 08:49:46 -04:00
Loader::Register(new Toast());
2015-12-25 15:42:35 -05:00
Loader::Register(new Party());
2016-09-18 09:10:23 -04:00
Loader::Register(new Zones());
2016-01-11 18:48:27 -05:00
Loader::Register(new D3D9Ex());
#if (!defined(VLD_RPTHOOK_INSTALL) || defined(VLDEnable)) && defined(COMPILE_IW4MVM) // IW4MVM uses detours which produces memory leaks, but those are not really relevant
2017-07-05 11:57:52 -04:00
Loader::Register(new IW4MVM());
#endif
2015-12-23 16:21:03 -05:00
Loader::Register(new Logger());
2016-05-29 10:16:15 -04:00
Loader::Register(new Script());
2016-01-12 08:27:48 -05:00
Loader::Register(new Weapon());
2015-12-23 08:45:53 -05:00
Loader::Register(new Window());
Loader::Register(new Command());
Loader::Register(new Console());
Loader::Register(new Friends());
2017-02-12 13:38:56 -05:00
Loader::Register(new IPCPipe());
2019-12-28 05:43:41 -05:00
Loader::Register(new MapDump());
2016-06-08 11:28:58 -04:00
Loader::Register(new ModList());
Loader::Register(new Monitor());
2015-12-24 10:55:38 -05:00
Loader::Register(new Network());
2018-10-09 04:53:15 -04:00
Loader::Register(new Session());
2016-01-09 14:56:28 -05:00
Loader::Register(new Theatre());
//Loader::Register(new ClanTags());
2016-01-08 21:21:59 -05:00
Loader::Register(new Download());
2016-01-01 20:28:09 -05:00
Loader::Register(new Playlist());
2015-12-23 08:45:53 -05:00
Loader::Register(new RawFiles());
2015-12-23 10:56:02 -05:00
Loader::Register(new Renderer());
2015-12-28 08:08:46 -05:00
Loader::Register(new UIFeeder());
Loader::Register(new UIScript());
2016-02-29 08:47:21 -05:00
Loader::Register(new AntiCheat());
2017-02-04 12:42:12 -05:00
Loader::Register(new Changelog());
2016-01-03 18:00:07 -05:00
Loader::Register(new Dedicated());
2016-01-03 13:28:47 -05:00
Loader::Register(new Discovery());
2016-01-03 18:00:07 -05:00
Loader::Register(new FastFiles());
Loader::Register(new FrameTime());
Loader::Register(new Gametypes());
2015-12-23 10:56:02 -05:00
Loader::Register(new Materials());
Loader::Register(new Scheduler());
Loader::Register(new Threading());
Loader::Register(new CardTitles());
2015-12-23 21:26:46 -05:00
Loader::Register(new FileSystem());
Loader::Register(new ModelSurfs());
2016-09-05 13:55:47 -04:00
Loader::Register(new PlayerName());
2015-12-23 08:45:53 -05:00
Loader::Register(new QuickPatch());
2016-01-07 20:20:55 -05:00
Loader::Register(new ServerInfo());
2015-12-27 22:02:30 -05:00
Loader::Register(new ServerList());
Loader::Register(new SlowMotion());
2016-10-26 12:57:43 -04:00
Loader::Register(new ArenaLength());
2016-01-12 15:17:55 -05:00
Loader::Register(new StringTable());
2016-01-04 18:49:34 -05:00
Loader::Register(new ZoneBuilder());
2015-12-23 16:21:03 -05:00
Loader::Register(new AssetHandler());
2015-12-25 17:17:29 -05:00
Loader::Register(new Localization());
2017-06-18 06:36:19 -04:00
//Loader::Register(new MusicalTalent());
Loader::Register(new ServerCommands());
2016-01-12 19:29:22 -05:00
Loader::Register(new StructuredData());
2015-12-29 18:16:33 -05:00
Loader::Register(new ConnectProtocol());
Loader::Register(new StartupMessages());
2021-08-13 18:27:19 -04:00
Loader::Register(new SoundMutexFix());
Loader::Register(new Gamepad());
Loader::Register(new Chat());
Loader::Register(new TextRenderer());
2016-09-03 09:52:40 -04:00
Loader::Register(new Client());
2016-09-03 09:52:40 -04:00
Loader::Pregame = false;
2015-12-23 08:45:53 -05:00
}
void Loader::Uninitialize()
{
Loader::Uninitializing = true;
2017-02-24 07:30:31 -05:00
Loader::PreDestroyNoPostGame();
2016-01-28 15:37:48 -05:00
std::reverse(Loader::Components.begin(), Loader::Components.end());
2015-12-23 08:45:53 -05:00
for (auto component : Loader::Components)
{
2016-08-14 10:18:44 -04:00
#ifdef DEBUG
2017-07-03 09:40:32 -04:00
if (!Loader::IsPerformingUnitTests())
2016-09-16 05:04:28 -04:00
{
Logger::Print("Unregistering component: %s\n", component->getName().data());
2016-09-16 05:04:28 -04:00
}
2016-08-14 10:18:44 -04:00
#endif
2015-12-23 08:45:53 -05:00
delete component;
}
Loader::Components.clear();
2017-06-02 09:36:20 -04:00
Utils::Memory::GetAllocator()->clear();
Loader::Uninitializing = false;
2015-12-23 08:45:53 -05:00
}
void Loader::PreDestroy()
{
if (!Loader::Postgame)
{
Loader::Postgame = true;
2017-02-24 07:30:31 -05:00
auto components = Loader::Components;
std::reverse(components.begin(), components.end());
for (auto component : components)
{
component->preDestroy();
}
}
}
2017-02-24 07:30:31 -05:00
void Loader::PreDestroyNoPostGame()
{
if (!Loader::Postgame)
{
auto components = Loader::Components;
std::reverse(components.begin(), components.end());
for (auto component : components)
{
component->preDestroy();
}
Loader::Postgame = true;
}
}
bool Loader::PerformUnitTests()
{
bool result = true;
Logger::Print("Performing unit tests for components:\n");
for (auto component : Loader::Components)
{
2016-09-16 05:04:28 -04:00
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
Logger::Print("Testing '%s'...\n", component->getName().data());
2016-08-15 11:07:32 -04:00
#endif
auto startTime = std::chrono::high_resolution_clock::now();
bool testRes = component->unitTest();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
2016-02-18 15:33:19 -05:00
Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error"));
result &= testRes;
}
return result;
}
2017-07-12 05:37:23 -04:00
bool Loader::IsPerformingUnitTests()
{
2016-02-19 17:57:06 -05:00
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
return Flags::HasFlag("tests");
#else
return false;
#endif
}
2015-12-23 08:45:53 -05:00
void Loader::Register(Component* component)
{
if (component)
{
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
2017-07-03 09:40:32 -04:00
if (!Loader::IsPerformingUnitTests())
2016-09-16 05:04:28 -04:00
{
Logger::Print("Component registered: %s\n", component->getName().data());
2016-09-16 05:04:28 -04:00
}
2016-08-14 10:18:44 -04:00
#endif
2015-12-23 08:45:53 -05:00
Loader::Components.push_back(component);
}
}
}