2016-01-04 14:58:00 -05:00
# 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 ;
2017-01-23 16:06:50 -05:00
bool Loader : : Postgame = false ;
2017-06-04 07:46:50 -04:00
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 ;
}
2017-06-04 07:46:50 -04:00
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 ;
2017-01-23 16:06:50 -05:00
Loader : : Postgame = false ;
2017-06-04 07:46:50 -04:00
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 ( ) ) ;
2015-12-31 07:37:25 -05:00
Loader : : Register ( new Singleton ( ) ) ;
2017-02-09 16:16:49 -05:00
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 ( ) ) ;
2016-11-27 09:43:37 -05:00
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 ( ) ) ;
2017-02-25 19:36:37 -05:00
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 ( ) ) ;
2015-12-23 08:45:53 -05:00
Loader : : Register ( new Colors ( ) ) ;
2016-01-11 18:48:27 -05:00
Loader : : Register ( new D3D9Ex ( ) ) ;
2017-09-03 14:31:58 -04:00
# 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 ( ) ) ;
2017-01-25 16:39:00 -05:00
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 ( ) ) ;
2017-02-25 09:32:15 -05:00
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 ( ) ) ;
2017-06-14 06:06:04 -04:00
//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 ( ) ) ;
2017-01-14 07:33:43 -05:00
Loader : : Register ( new FrameTime ( ) ) ;
2016-10-17 14:42:15 -04:00
Loader : : Register ( new Gametypes ( ) ) ;
2015-12-23 10:56:02 -05:00
Loader : : Register ( new Materials ( ) ) ;
2017-06-01 04:54:16 -04:00
Loader : : Register ( new Scheduler ( ) ) ;
2016-12-05 14:43:16 -05:00
Loader : : Register ( new Threading ( ) ) ;
2017-05-30 07:45:19 -04:00
Loader : : Register ( new CardTitles ( ) ) ;
2015-12-23 21:26:46 -05:00
Loader : : Register ( new FileSystem ( ) ) ;
2016-09-13 14:55:10 -04:00
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 ( ) ) ;
2016-10-21 19:14:00 -04:00
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());
2017-05-30 08:29:09 -04:00
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 ( ) ) ;
2017-01-30 21:57:31 -05:00
Loader : : Register ( new StartupMessages ( ) ) ;
2016-09-03 09:52:40 -04:00
2020-07-22 23:36:52 -04:00
Loader : : Register ( new Client ( ) ) ;
2021-01-02 01:49:45 -05:00
Loader : : Register ( new XInput ( ) ) ;
2020-07-22 23:36:52 -04:00
2016-09-03 09:52:40 -04:00
Loader : : Pregame = false ;
2015-12-23 08:45:53 -05:00
}
void Loader : : Uninitialize ( )
{
2017-06-04 07:46:50 -04:00
Loader : : Uninitializing = true ;
2017-02-24 07:30:31 -05:00
Loader : : PreDestroyNoPostGame ( ) ;
2017-01-23 16:06:50 -05:00
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
{
2017-05-31 06:02:14 -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 ( ) ;
2017-06-04 07:46:50 -04:00
Loader : : Uninitializing = false ;
2015-12-23 08:45:53 -05:00
}
2017-01-23 16:06:50 -05:00
void Loader : : PreDestroy ( )
{
2017-06-14 06:06:04 -04:00
if ( ! Loader : : Postgame )
2017-01-23 16:06:50 -05:00
{
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 )
2017-01-23 16:06:50 -05:00
{
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 ;
}
}
2016-02-04 15:58:49 -05:00
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)
2017-05-31 06:02:14 -04:00
Logger : : Print ( " Testing '%s'... \n " , component - > getName ( ) . data ( ) ) ;
2016-08-15 11:07:32 -04:00
# endif
2016-02-04 15:58:49 -05:00
auto startTime = std : : chrono : : high_resolution_clock : : now ( ) ;
2016-11-20 08:09:07 -05:00
bool testRes = component - > unitTest ( ) ;
2016-02-04 15:58:49 -05:00
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 " ) ) ;
2016-02-04 15:58:49 -05:00
result & = testRes ;
}
return result ;
}
2017-07-12 05:37:23 -04:00
bool Loader : : IsPerformingUnitTests ( )
2016-02-04 15:58:49 -05:00
{
2016-02-19 17:57:06 -05:00
# if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
2016-02-04 15:58:49 -05:00
return Flags : : HasFlag ( " tests " ) ;
# else
return false ;
# endif
}
2015-12-23 08:45:53 -05:00
void Loader : : Register ( Component * component )
{
if ( component )
{
2017-06-12 13:54:11 -04:00
# 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
{
2017-05-31 06:02:14 -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 ) ;
}
}
}