#include "tier2/ifilesystem.h" #include "materialsystem/igamewindow.h" #include "materialsystem/imaterialsystem.h" #include "tier1/interface.h" #include "tier0/commandline.h" #include "tier0/mem.h" #include "sv_dll.h" #include "cl_dll.h" #include "inetworkserver.h" #include "inetworkclient.h" #include "ihumandevice.h" #ifdef STEAM #include "steam/steam_api.h" #include "steam/steam_gameserver.h" #endif IRenderContext *g_pRenderContext; IFileSystem *filesystem; IGameWindowManager *g_pWindowManager; CServerGameDLL *g_pServerGame; CClientGameDLL *g_pClientGame; static void CallKeyEvent( EInputDeviceType eDevice, EInputButton eButton, bool bIsPressed ) { if (bIsPressed) g_pHumanDeviceManager->SetButtonPressed(eButton); else g_pHumanDeviceManager->SetButtonUnpressed(eButton); } static void CallAxisEvent( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) { g_pHumanDeviceManager->AxisEventRelative(eDevice, eAxis, fValue ); } extern "C" void __cdecl SteamAPIDebug( ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg ) { V_printf("STEAM: %s\n", pszMsg); } extern "C" void FunnyMain( int argc, char **argv ) { #ifdef __WIN32__ CUtlString szPath = Plat_GetExecutablePath(); szPath = szPath.GetDirectory(); CUtlString szEnv = Plat_GetEnv("PATH"); szEnv.AppendTail(":"); szEnv.AppendTail(szPath); Plat_SetEnv("PATH", szEnv); #endif CommandLine()->CreateCommandLine(argc, argv); EngineConsts_t stConstants = {}; V_printf("------------ 1\n"); #ifdef STEAM V_printf("Steam :)\n"); if(SteamAPI_RestartAppIfNecessary(480)) { V_printf("Mshallah we are doing reboot\n"); Plat_Exit(0); } stConstants.m_bIsSteam = true; if (!SteamAPI_Init()) { V_printf("Steam :()\n"); stConstants.m_bIsSteam = false; } stConstants.LaunchServer = LaunchServerAtSteamRelay; stConstants.ConnectSteamServer = ConnectBySteamID; //SteamNetworkingUtils()->SetDebugOutputFunction(k_ESteamNetworkingSocketsDebugOutputType_Debug, SteamAPIDebug); #endif stConstants.m_bIsDedicated = CommandLine()->CheckParam("-dedicated"); stConstants.LaunchLocalBridge = LaunchLocalBridge; stConstants.ConnectLocalBridge = ConnectByLocalBridge; CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std"); CreateInterfaceFn pMaterialSystemFactory = Sys_GetFactory("MaterialSystem"); CreateInterfaceFn pRenderSystemFactory = Sys_GetFactory("RenderSystemVulkan"); IGameWindow *pWindow; filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); filesystem->Init(); if (!stConstants.m_bIsDedicated) { g_pWindowManager = (IGameWindowManager*)pRenderSystemFactory(GAME_WINDOW_MANAGER_INTERFACE_VERSION, NULL); g_pWindowManager->Init(); pWindow = g_pWindowManager->CreateWindow(); pWindow->Init(); pWindow->SetKeyCallback(CallKeyEvent); pWindow->SetAxisCallback(CallAxisEvent); g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL); g_pRenderContext->SetMainWindowManager(g_pWindowManager); g_pRenderContext->Init(); g_pRenderContext->RegisterGameWindow(pWindow); } g_pServerGame = new CServerGameDLL; g_pServerGame->m_pEngineConsts = &stConstants; g_pServerGame->Init(); if (!stConstants.m_bIsDedicated) { g_pClientGame = new CClientGameDLL; g_pClientGame->m_pGameWindow = pWindow; g_pClientGame->m_pRenderContext = g_pRenderContext; g_pClientGame->m_pEngineConsts = &stConstants; g_pClientGame->Init(); } Console()->Execute(); double fPrevious = Plat_GetTime(); for (;;) { #ifdef STEAM SteamAPI_RunCallbacks(); #endif double fCurrent = Plat_GetTime(); double fStart = Plat_GetTime(); double fDelta = fCurrent-fPrevious; fPrevious = fCurrent; g_pHumanDeviceManager->Frame(); g_pServerGame->m_pBridge->Frame(fDelta); fCurrent = Plat_GetTime(); if (!stConstants.m_bIsDedicated) { g_pWindowManager->Frame(fDelta); g_pClientGame->m_pBridge->Frame(fDelta); g_pRenderContext->Frame(fDelta); fCurrent = Plat_GetTime(); } Console()->Execute(); fCurrent = Plat_GetTime(); }; };