iw4x-client/src/Components/Loader.cpp

140 lines
3.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;
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;
}
2015-12-23 08:45:53 -05:00
void Loader::Initialize()
{
2016-09-03 09:52:40 -04:00
Loader::Pregame = true;
2016-01-03 18:00:07 -05:00
Loader::Register(new Flags());
Loader::Register(new Singleton());
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());
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());
2016-01-28 10:19:43 -05:00
Loader::Register(new Node());
2016-02-17 16:21:42 -05:00
Loader::Register(new RCon());
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());
2015-12-23 08:45:53 -05:00
Loader::Register(new Colors());
2016-01-11 18:48:27 -05:00
Loader::Register(new D3D9Ex());
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 IPCPipe());
2016-06-08 11:28:58 -04:00
Loader::Register(new ModList());
2015-12-24 10:55:38 -05:00
Loader::Register(new Network());
2016-01-09 14:56:28 -05:00
Loader::Register(new Theatre());
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());
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-08 14:10:35 -05:00
Loader::Register(new Exception());
2016-01-03 18:00:07 -05:00
Loader::Register(new FastFiles());
Loader::Register(new Gametypes());
2015-12-23 10:56:02 -05:00
Loader::Register(new Materials());
2016-09-04 11:13:06 -04:00
#ifndef DISABLE_BITMESSAGE
Loader::Register(new BitMessage());
#endif
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-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());
2015-12-23 16:21:03 -05:00
Loader::Register(new MusicalTalent());
2016-09-04 11:13:06 -04:00
Loader::Register(new MinidumpUpload());
2016-01-12 19:29:22 -05:00
Loader::Register(new StructuredData());
2015-12-29 18:16:33 -05:00
Loader::Register(new ConnectProtocol());
2016-09-03 09:52:40 -04:00
Loader::Pregame = false;
2015-12-23 08:45:53 -05:00
}
void Loader::Uninitialize()
{
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
2016-09-16 05:04:28 -04:00
if(!Loader::PerformingUnitTests())
{
Logger::Print("Unregistering component: %s\n", component->GetName());
}
2016-08-14 10:18:44 -04:00
#endif
2015-12-23 08:45:53 -05:00
delete component;
}
Loader::Components.clear();
}
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());
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;
}
bool Loader::PerformingUnitTests()
{
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)
{
2016-08-14 10:18:44 -04:00
#ifdef DEBUG
2016-09-16 05:04:28 -04:00
if(!Loader::PerformingUnitTests())
{
Logger::Print("Component registered: %s\n", component->GetName());
}
2016-08-14 10:18:44 -04:00
#endif
2015-12-23 08:45:53 -05:00
Loader::Components.push_back(component);
}
}
}