iw4x-client/src/Components/Loader.cpp
2016-10-26 18:57:43 +02:00

141 lines
3.7 KiB
C++

#include "STDInclude.hpp"
namespace Components
{
bool Loader::Pregame = true;
std::vector<Component*> Loader::Components;
bool Loader::IsPregame()
{
return Loader::Pregame;
}
void Loader::Initialize()
{
Loader::Pregame = true;
Loader::Register(new Flags());
Loader::Register(new Singleton());
Loader::Register(new Auth());
Loader::Register(new Bans());
Loader::Register(new Dvar());
Loader::Register(new Lean());
Loader::Register(new Maps());
Loader::Register(new News());
Loader::Register(new Node());
Loader::Register(new RCon());
Loader::Register(new Menus());
Loader::Register(new Toast());
Loader::Register(new Party());
Loader::Register(new Zones());
Loader::Register(new Colors());
Loader::Register(new D3D9Ex());
Loader::Register(new Logger());
Loader::Register(new Script());
Loader::Register(new Weapon());
Loader::Register(new Window());
Loader::Register(new Command());
Loader::Register(new Console());
Loader::Register(new IPCPipe());
Loader::Register(new ModList());
Loader::Register(new Network());
Loader::Register(new Theatre());
Loader::Register(new Download());
Loader::Register(new Playlist());
Loader::Register(new RawFiles());
Loader::Register(new Renderer());
Loader::Register(new UIFeeder());
Loader::Register(new UIScript());
Loader::Register(new AntiCheat());
Loader::Register(new Dedicated());
Loader::Register(new Discovery());
Loader::Register(new Exception());
Loader::Register(new FastFiles());
Loader::Register(new Gametypes());
Loader::Register(new Materials());
#ifndef DISABLE_BITMESSAGE
Loader::Register(new BitMessage());
#endif
Loader::Register(new FileSystem());
Loader::Register(new ModelSurfs());
Loader::Register(new PlayerName());
Loader::Register(new QuickPatch());
Loader::Register(new ServerInfo());
Loader::Register(new ServerList());
Loader::Register(new SlowMotion());
Loader::Register(new ArenaLength());
Loader::Register(new StringTable());
Loader::Register(new ZoneBuilder());
Loader::Register(new AssetHandler());
Loader::Register(new Localization());
Loader::Register(new MusicalTalent());
Loader::Register(new MinidumpUpload());
Loader::Register(new StructuredData());
Loader::Register(new ConnectProtocol());
Loader::Pregame = false;
}
void Loader::Uninitialize()
{
std::reverse(Loader::Components.begin(), Loader::Components.end());
for (auto component : Loader::Components)
{
#ifdef DEBUG
if(!Loader::PerformingUnitTests())
{
Logger::Print("Unregistering component: %s\n", component->GetName());
}
#endif
delete component;
}
Loader::Components.clear();
}
bool Loader::PerformUnitTests()
{
bool result = true;
Logger::Print("Performing unit tests for components:\n");
for (auto component : Loader::Components)
{
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
Logger::Print("Testing '%s'...\n", component->GetName());
#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();
Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error"));
result &= testRes;
}
return result;
}
bool Loader::PerformingUnitTests()
{
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
return Flags::HasFlag("tests");
#else
return false;
#endif
}
void Loader::Register(Component* component)
{
if (component)
{
#ifdef DEBUG
if(!Loader::PerformingUnitTests())
{
Logger::Print("Component registered: %s\n", component->GetName());
}
#endif
Loader::Components.push_back(component);
}
}
}