2022-01-27 03:55:47 +01:00
//=============================================================================//
//
// Purpose: IApplication methods
//
//=============================================================================//
2021-12-25 22:36:38 +01:00
# include "core/stdafx.h"
2022-08-19 21:33:31 +02:00
# include "tier0/frametask.h"
2022-08-13 20:21:32 +02:00
# include "tier0/commandline.h"
2022-04-09 16:16:40 +02:00
# include "tier1/cvar.h"
2022-04-09 00:59:42 +02:00
# include "vpc/interfaces.h"
2022-08-29 01:14:53 +02:00
# include "appframework/engine_launcher_api.h"
2021-12-25 22:36:38 +01:00
# include "launcher/IApplication.h"
2022-08-21 00:59:55 +02:00
# include "pluginsystem/pluginsystem.h"
2021-12-25 22:36:38 +01:00
# include "ebisusdk/EbisuSDK.h"
2022-05-27 02:08:51 +02:00
# include "engine/cmodel_bsp.h"
2022-01-23 18:26:48 +01:00
# include "engine/sys_engine.h"
# include "engine/sys_dll2.h"
2023-03-18 21:42:30 +01:00
# include "engine/sdk_dll.h"
2022-01-23 18:26:48 +01:00
# include "engine/host_cmd.h"
2023-02-05 19:19:03 +01:00
# include "engine/enginetrace.h"
2022-05-20 11:52:19 +02:00
# include "engine/server/sv_main.h"
2023-01-18 01:40:24 +01:00
# ifndef CLIENT_DLL
2022-04-02 12:27:35 +02:00
# include "server/vengineserver_impl.h"
2023-01-16 21:09:21 +01:00
# include "game/server/gameinterface.h"
# endif // !CLIENT_DLL
2022-04-26 20:24:51 +02:00
# ifndef DEDICATED
2023-02-05 19:19:03 +01:00
# include "client/cdll_engine_int.h"
2023-01-20 00:28:49 +01:00
# include "game/client/cliententitylist.h"
2022-04-26 20:24:51 +02:00
# include "gameui/IConsole.h"
2023-01-30 20:18:11 +01:00
# include "windows/id3dx.h"
# include "windows/input.h"
2022-04-26 20:24:51 +02:00
# endif // !DEDICATED
2023-01-22 13:08:02 +01:00
# include "public/idebugoverlay.h"
2021-12-25 22:36:38 +01:00
//-----------------------------------------------------------------------------
2022-01-26 23:43:16 +01:00
// Purpose:
2021-12-25 22:36:38 +01:00
//-----------------------------------------------------------------------------
2022-04-14 19:18:59 +02:00
int CModAppSystemGroup : : Main ( CModAppSystemGroup * pModAppSystemGroup )
2021-12-25 22:36:38 +01:00
{
2023-03-18 21:42:30 +01:00
std : : thread fixed ( & CEngineSDK : : FixedFrame , g_EngineSDK ) ;
fixed . detach ( ) ;
2022-02-22 02:45:40 +01:00
int nRunResult = RUN_OK ;
2022-01-23 18:26:48 +01:00
HEbisuSDK_Init ( ) ; // Not here in retail. We init EbisuSDK here though.
2022-03-07 13:15:45 +01:00
# if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) // !TODO: rebuild does not work for S1 (CModAppSystemGroup and CEngine member offsets do align with all other builds).
2022-04-19 00:00:45 +02:00
return CModAppSystemGroup_Main ( pModAppSystemGroup ) ;
2022-03-07 13:15:45 +01:00
# elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
2022-04-14 19:18:59 +02:00
2022-08-09 11:53:33 +02:00
g_pEngine - > SetQuitting ( IEngine : : QUIT_NOTQUITTING ) ;
2022-04-14 19:18:59 +02:00
if ( g_pEngine - > Load ( pModAppSystemGroup - > IsServerOnly ( ) , g_pEngineParms - > baseDirectory ) )
2022-01-23 18:26:48 +01:00
{
2022-04-14 19:18:59 +02:00
if ( CEngineAPI_MainLoop ( ) )
2022-01-23 18:26:48 +01:00
{
2022-04-14 19:18:59 +02:00
nRunResult = RUN_RESTART ;
2022-01-23 18:26:48 +01:00
}
2022-04-14 19:18:59 +02:00
g_pEngine - > Unload ( ) ;
SV_ShutdownGameDLL ( ) ;
2022-01-23 18:26:48 +01:00
}
return nRunResult ;
2022-03-07 13:15:45 +01:00
# endif
2021-12-25 22:36:38 +01:00
}
//-----------------------------------------------------------------------------
2022-01-26 23:43:16 +01:00
// Purpose: Instantiate all main libraries
2021-12-25 22:36:38 +01:00
//-----------------------------------------------------------------------------
2022-04-14 19:18:59 +02:00
bool CModAppSystemGroup : : Create ( CModAppSystemGroup * pModAppSystemGroup )
2021-12-25 22:36:38 +01:00
{
2022-11-18 22:10:20 +01:00
ConCommand : : Init ( ) ;
2021-12-30 17:20:41 +01:00
# ifdef DEDICATED
2022-04-14 19:18:59 +02:00
pModAppSystemGroup - > SetServerOnly ( ) ;
2023-01-31 22:40:15 +01:00
* m_bIsDedicated = true ;
2021-12-30 17:20:41 +01:00
# endif // DEDICATED
2022-04-09 00:59:42 +02:00
g_pFactory - > GetFactoriesFromRegister ( ) ;
2022-08-21 00:59:55 +02:00
g_pFactory - > AddFactory ( FACTORY_INTERFACE_VERSION , g_pFactory ) ;
g_pFactory - > AddFactory ( INTERFACEVERSION_PLUGINSYSTEM , g_pPluginSystem ) ;
2022-12-12 17:16:39 +01:00
//InitPluginSystem(pModAppSystemGroup);
//CALL_PLUGIN_CALLBACKS(g_pPluginSystem->GetCreateCallbacks(), pModAppSystemGroup);
2022-08-21 00:59:55 +02:00
2023-01-22 13:08:02 +01:00
g_pDebugOverlay = g_pFactory - > GetFactoryPtr ( VDEBUG_OVERLAY_INTERFACE_VERSION , false ) . RCast < CIVDebugOverlay * > ( ) ;
2023-01-16 21:09:21 +01:00
# ifndef CLIENT_DLL
g_pServerGameDLL = g_pFactory - > GetFactoryPtr ( INTERFACEVERSION_SERVERGAMEDLL , false ) . RCast < CServerGameDLL * > ( ) ;
g_pServerGameClients = g_pFactory - > GetFactoryPtr ( INTERFACEVERSION_SERVERGAMECLIENTS_NEW , false ) . RCast < CServerGameClients * > ( ) ;
if ( ! g_pServerGameClients )
g_pServerGameClients = g_pFactory - > GetFactoryPtr ( INTERFACEVERSION_SERVERGAMECLIENTS , false ) . RCast < CServerGameClients * > ( ) ;
g_pServerGameEntities = g_pFactory - > GetFactoryPtr ( INTERFACEVERSION_SERVERGAMEENTS , false ) . RCast < CServerGameEnts * > ( ) ;
2023-01-22 13:08:02 +01:00
# endif // !CLIENT_DLL
2022-04-26 20:24:51 +02:00
# ifndef DEDICATED
2023-01-20 00:28:49 +01:00
g_pClientEntityList = g_pFactory - > GetFactoryPtr ( VCLIENTENTITYLIST_INTERFACE_VERSION , false ) . RCast < CClientEntityList * > ( ) ;
2023-01-21 16:24:36 +01:00
g_pEngineTraceClient = g_pFactory - > GetFactoryPtr ( INTERFACEVERSION_ENGINETRACE_CLIENT , false ) . RCast < CEngineTraceClient * > ( ) ;
2022-07-24 13:40:37 +02:00
2022-11-24 10:45:42 +01:00
g_pImGuiConfig - > Load ( ) ; // Load ImGui configs.
2022-01-17 23:20:03 +01:00
for ( auto & map : g_pCVar - > DumpToMap ( ) )
{
2022-05-27 02:46:13 +02:00
g_pConsole - > m_vsvCommandBases . push_back (
2022-08-11 11:07:45 +02:00
CSuggest ( map . first , map . second - > GetFlags ( ) ) ) ;
2022-01-17 23:20:03 +01:00
}
2023-01-30 20:18:11 +01:00
DirectX_Init ( ) ;
2022-08-17 02:02:44 +02:00
# endif // !DEDICATED
2022-08-13 20:21:32 +02:00
if ( CommandLine ( ) - > CheckParm ( " -devsdk " ) )
{
cv - > EnableDevCvars ( ) ;
}
2022-01-27 03:55:47 +01:00
2022-08-27 18:57:56 +02:00
g_FrameTasks . push_back ( std : : move ( g_TaskScheduler ) ) ;
2022-04-09 00:59:42 +02:00
g_bAppSystemInit = true ;
2022-08-19 21:33:31 +02:00
2022-04-09 06:05:47 +02:00
return CModAppSystemGroup_Create ( pModAppSystemGroup ) ;
2021-12-25 22:36:38 +01:00
}
2023-01-30 21:22:17 +01:00
2022-12-12 17:16:39 +01:00
//-----------------------------------------------------------------------------
// Purpose: Initialize plugin system
//-----------------------------------------------------------------------------
void CModAppSystemGroup : : InitPluginSystem ( CModAppSystemGroup * pModAppSystemGroup )
{
// DEBUG CODE FOR PLUGINS
g_pPluginSystem - > PluginSystem_Init ( ) ;
for ( auto & it : g_pPluginSystem - > GetPluginInstances ( ) )
{
if ( g_pPluginSystem - > LoadPluginInstance ( it ) )
2023-01-20 00:42:13 +01:00
DevMsg ( eDLL_T : : ENGINE , " Loaded plugin: '%s' \n " , it . m_svPluginName . c_str ( ) ) ;
else
Warning ( eDLL_T : : ENGINE , " Failed loading plugin: '%s' \n " , it . m_svPluginName . c_str ( ) ) ;
2022-12-12 17:16:39 +01:00
}
}