diff --git a/src/Layers/xrRender/WallmarksEngine.cpp b/src/Layers/xrRender/WallmarksEngine.cpp index 80da1ba2811..a2b9ca9c1fb 100644 --- a/src/Layers/xrRender/WallmarksEngine.cpp +++ b/src/Layers/xrRender/WallmarksEngine.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "WallmarksEngine.h" #include "xrEngine/xr_object.h" -#include "xrEngine/x_ray.h" #include "xrEngine/GameFont.h" #include "SkeletonCustom.h" diff --git a/src/Layers/xrRenderPC_R1/FStaticRender_Loader.cpp b/src/Layers/xrRenderPC_R1/FStaticRender_Loader.cpp index 6d2770a126e..b1a7d3f5c55 100644 --- a/src/Layers/xrRenderPC_R1/FStaticRender_Loader.cpp +++ b/src/Layers/xrRenderPC_R1/FStaticRender_Loader.cpp @@ -3,7 +3,6 @@ #include "xrCore/FMesh.hpp" #include "Common/LevelStructure.hpp" #include "Common/OGF_GContainer_Vertices.hpp" -#include "xrEngine/x_ray.h" #include "xrEngine/IGame_Persistent.h" #include "xrCore/stream_reader.h" diff --git a/src/Layers/xrRenderPC_R1/GlowManager.cpp b/src/Layers/xrRenderPC_R1/GlowManager.cpp index 022f6c05fcf..9908d7dfe3f 100644 --- a/src/Layers/xrRenderPC_R1/GlowManager.cpp +++ b/src/Layers/xrRenderPC_R1/GlowManager.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "xrEngine/IGame_Persistent.h" #include "xrEngine/Environment.h" -#include "xrEngine/x_ray.h" #include "xrEngine/GameFont.h" #include "GlowManager.h" #include "xrEngine/xr_object.h" diff --git a/src/Layers/xrRender_R2/r2_loader.cpp b/src/Layers/xrRender_R2/r2_loader.cpp index c63da2c5039..7a894fbfa7e 100644 --- a/src/Layers/xrRender_R2/r2_loader.cpp +++ b/src/Layers/xrRender_R2/r2_loader.cpp @@ -4,7 +4,6 @@ #include "Layers/xrRender/FBasicVisual.h" #include "xrCore/FMesh.hpp" #include "Common/LevelStructure.hpp" -#include "xrEngine/x_ray.h" #include "xrEngine/IGame_Persistent.h" #include "xrCore/stream_reader.h" diff --git a/src/xrEngine/CameraManager.cpp b/src/xrEngine/CameraManager.cpp index 113ae67ff87..6bb1cf01cd4 100644 --- a/src/xrEngine/CameraManager.cpp +++ b/src/xrEngine/CameraManager.cpp @@ -12,7 +12,6 @@ #include "Effector.h" #include "EffectorPP.h" -#include "x_ray.h" #include "GameFont.h" #include "Render.h" diff --git a/src/xrEngine/IGame_Level.cpp b/src/xrEngine/IGame_Level.cpp index 72877c76f79..de72bb7438c 100644 --- a/src/xrEngine/IGame_Level.cpp +++ b/src/xrEngine/IGame_Level.cpp @@ -2,8 +2,6 @@ #include "IGame_Level.h" #include "IGame_Persistent.h" -#include "x_ray.h" -#include "std_classes.h" #include "CustomHUD.h" #include "Render.h" #include "GameFont.h" diff --git a/src/xrEngine/IGame_Persistent.cpp b/src/xrEngine/IGame_Persistent.cpp index ca78fa418b1..8d3359295a9 100644 --- a/src/xrEngine/IGame_Persistent.cpp +++ b/src/xrEngine/IGame_Persistent.cpp @@ -11,7 +11,6 @@ #ifndef _EDITOR #include "Environment.h" -#include "x_ray.h" #include "IGame_Level.h" #include "XR_IOConsole.h" #include "Render.h" diff --git a/src/xrEngine/Text_Console.cpp b/src/xrEngine/Text_Console.cpp index afcf28d8d81..0784f1e91a7 100644 --- a/src/xrEngine/Text_Console.cpp +++ b/src/xrEngine/Text_Console.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "Text_Console.h" #include "line_editor.h" -#include "x_ray.h" #include diff --git a/src/xrEngine/XR_IOConsole.cpp b/src/xrEngine/XR_IOConsole.cpp index b9d5e2b80a9..72d24c10991 100644 --- a/src/xrEngine/XR_IOConsole.cpp +++ b/src/xrEngine/XR_IOConsole.cpp @@ -8,7 +8,6 @@ #include "IGame_Level.h" #include "IGame_Persistent.h" -#include "x_ray.h" #include "xr_input.h" #include "xr_ioc_cmd.h" #include "GameFont.h" diff --git a/src/xrEngine/main.cpp b/src/xrEngine/main.cpp index 9ead4c77a0c..513f339a7be 100644 --- a/src/xrEngine/main.cpp +++ b/src/xrEngine/main.cpp @@ -1,303 +1,47 @@ -// Entry point is in xr_3da/entry_point.cpp #include "stdafx.h" -#include "main.h" -#if defined(XR_PLATFORM_WINDOWS) -#include -#endif - -#include "IGame_Persistent.h" -#include "xrNetServer/NET_AuthCheck.h" -#include "xr_input.h" #include "XR_IOConsole.h" -#include "x_ray.h" -#include "std_classes.h" - -#include "LightAnimLibrary.h" -#include "xrCDB/ISpatial.h" -#if defined(XR_PLATFORM_WINDOWS) -#include "Text_Console.h" -#elif defined(XR_PLATFORM_LINUX) || defined(XR_PLATFORM_BSD) || defined(XR_PLATFORM_APPLE) -#define CTextConsole CConsole -#pragma todo("Implement text console or it's alternative") -#endif #include "xrSASH.h" -#include "xr_ioc_cmd.h" - -#include "xrCore/Threading/TaskManager.hpp" // global variables -ENGINE_API CInifile* pGameIni = nullptr; ENGINE_API bool g_bBenchmark = false; string512 g_sBenchmarkName; -ENGINE_API string512 g_sLaunchOnExit_params; -ENGINE_API string512 g_sLaunchOnExit_app; -ENGINE_API string_path g_sLaunchWorkingFolder; - -ENGINE_API bool CallOfPripyatMode = false; -ENGINE_API bool ClearSkyMode = false; -ENGINE_API bool ShadowOfChernobylMode = false; namespace { -bool CheckBenchmark(); -void RunBenchmark(pcstr name); -} - -namespace -{ -struct PathIncludePred -{ -private: - const xr_auth_strings_t* ignored; - -public: - explicit PathIncludePred(const xr_auth_strings_t* ignoredPaths) : ignored(ignoredPaths) {} - bool IsIncluded(pcstr path) - { - if (!ignored) - return true; - - return allow_to_include_path(*ignored, path); - } -}; -} - -template -void InitConfig(T& config, pcstr name, bool fatal = true, - bool readOnly = true, bool loadAtStart = true, bool saveAtEnd = true, - u32 sectCount = 0, const CInifile::allow_include_func_t& allowIncludeFunc = nullptr) -{ - string_path fname; - FS.update_path(fname, "$game_config$", name); - config = xr_new(fname, readOnly, loadAtStart, saveAtEnd, sectCount, allowIncludeFunc); - - CHECK_OR_EXIT(config->section_count() || !fatal, - make_string("Cannot find file %s.\nReinstalling application may fix this problem.", fname)); -} - -// XXX: make it more fancy -// некрасиво слишком -void set_shoc_mode() -{ - CallOfPripyatMode = false; - ShadowOfChernobylMode = true; - ClearSkyMode = false; -} - -void set_cs_mode() -{ - CallOfPripyatMode = false; - ShadowOfChernobylMode = false; - ClearSkyMode = true; -} - -void set_cop_mode() -{ - CallOfPripyatMode = true; - ShadowOfChernobylMode = false; - ClearSkyMode = false; -} - -void set_free_mode() -{ - CallOfPripyatMode = false; - ShadowOfChernobylMode = false; - ClearSkyMode = false; -} - -ENGINE_API void InitSettings() -{ - xr_auth_strings_t ignoredPaths, checkedPaths; - fill_auth_check_params(ignoredPaths, checkedPaths); //TODO port xrNetServer to Linux - PathIncludePred includePred(&ignoredPaths); - CInifile::allow_include_func_t includeFilter; - includeFilter.bind(&includePred, &PathIncludePred::IsIncluded); - - InitConfig(pSettings, "system.ltx"); - InitConfig(pSettingsAuth, "system.ltx", true, true, true, false, 0, includeFilter); - InitConfig(pSettingsOpenXRay, "openxray.ltx", false, true, true, false); - InitConfig(pGameIni, "game.ltx"); - - if (strstr(Core.Params, "-shoc") || strstr(Core.Params, "-soc")) - set_shoc_mode(); - else if (strstr(Core.Params, "-cs")) - set_cs_mode(); - else if (strstr(Core.Params, "-cop")) - set_cop_mode(); - else if (strstr(Core.Params, "-unlock_game_mode")) - set_free_mode(); - else - { - pcstr gameMode = READ_IF_EXISTS(pSettingsOpenXRay, r_string, "compatibility", "game_mode", "cop"); - if (xr_strcmpi("cop", gameMode) == 0) - set_cop_mode(); - else if (xr_strcmpi("cs", gameMode) == 0) - set_cs_mode(); - else if (xr_strcmpi("shoc", gameMode) == 0 || xr_strcmpi("soc", gameMode) == 0) - set_shoc_mode(); - else if (xr_strcmpi("unlock", gameMode) == 0) - set_free_mode(); - } -} - -ENGINE_API void InitConsole() -{ - if (GEnv.isDedicatedServer) - Console = xr_new(); - else - Console = xr_new(); - - Console->Initialize(); - xr_strcpy(Console->ConfigFile, "user.ltx"); - if (strstr(Core.Params, "-ltx ")) - { - string64 c_name; - sscanf(strstr(Core.Params, "-ltx ") + strlen("-ltx "), "%[^ ] ", c_name); - xr_strcpy(Console->ConfigFile, c_name); - } -} - -ENGINE_API void InitInput() -{ - bool captureInput = !strstr(Core.Params, "-i"); - pInput = xr_new(captureInput); -} - -ENGINE_API void destroyInput() { xr_delete(pInput); } -ENGINE_API void InitSoundDeviceList() { Engine.Sound.CreateDevicesList(); } -ENGINE_API void InitSound() { Engine.Sound.Create(); } -ENGINE_API void destroySound() { Engine.Sound.Destroy(); } -ENGINE_API void destroySettings() -{ - auto s = const_cast(&pSettings); - xr_delete(*s); - - auto sa = const_cast(&pSettingsAuth); - xr_delete(*sa); - - auto so = const_cast(&pSettingsOpenXRay); - xr_delete(*so); - - xr_delete(pGameIni); -} - -ENGINE_API void destroyConsole() -{ - Console->Execute("cfg_save"); - Console->Destroy(); - xr_delete(Console); -} - -void execUserScript() -{ - Console->Execute("default_controls"); - Console->ExecuteScript(Console->ConfigFile); -} - -ENGINE_API void Startup() -{ - InitSoundDeviceList(); - execUserScript(); - InitSound(); - - // ...command line for auto start - pcstr startArgs = strstr(Core.Params, "-start "); - if (startArgs) - Console->Execute(startArgs + 1); - pcstr loadArgs = strstr(Core.Params, "-load "); - if (loadArgs) - Console->Execute(loadArgs + 1); - - // Initialize APP - const auto& createLightAnim = TaskScheduler->AddTask("LALib.OnCreate()", [](Task&, void*) - { - LALib.OnCreate(); - }); - - Device.Create(); - TaskScheduler->Wait(createLightAnim); - - g_pGamePersistent = dynamic_cast(NEW_INSTANCE(CLSID_GAME_PERSISTANT)); - R_ASSERT(g_pGamePersistent || Engine.External.CanSkipGameModuleLoading()); - if (!g_pGamePersistent) - Console->Show(); - - // Main cycle - Device.Run(); - - // Destroy APP - DEL_INSTANCE(g_pGamePersistent); - Engine.Event.Dump(); - - // Destroying - destroyInput(); - if (!g_bBenchmark && !g_SASH.IsRunning()) - destroySettings(); - - LALib.OnDestroy(); - - if (!g_bBenchmark && !g_SASH.IsRunning()) - destroyConsole(); - else - Console->Destroy(); - - Device.CleanupVideoModes(); - destroySound(); -} - -ENGINE_API int RunApplication() +void RunBenchmark(pcstr name) { - R_ASSERT2(Core.Params, "Core must be initialized"); - - *g_sLaunchOnExit_app = 0; - *g_sLaunchOnExit_params = 0; - - InitSettings(); - // Adjust player & computer name for Asian - if (pSettings->line_exist("string_table", "no_native_input")) - { - xr_strcpy(Core.UserName, sizeof(Core.UserName), "Player"); - xr_strcpy(Core.CompName, sizeof(Core.CompName), "Computer"); - } - - FPU::m24r(); - - Device.FillVideoModes(); - InitInput(); - InitConsole(); - - Engine.Initialize(); - Device.Initialize(); - - Console->OnDeviceInitialize(); - - //if (CheckBenchmark()) - // return 0; - - Startup(); - - Device.Destroy(); - Engine.Destroy(); - - // check for need to execute something external - if (/*xr_strlen(g_sLaunchOnExit_params) && */ xr_strlen(g_sLaunchOnExit_app)) + g_bBenchmark = true; + string_path cfgPath; + FS.update_path(cfgPath, "$app_data_root$", name); + CInifile ini(cfgPath); + const u32 benchmarkCount = ini.line_count("benchmark"); + const size_t hyphenLtxLen = xr_strlen("-ltx "); + for (u32 i = 0; i < benchmarkCount; i++) { -#if defined(XR_PLATFORM_WINDOWS) - // CreateProcess need to return results to next two structures - STARTUPINFO si = {}; - si.cb = sizeof(si); - PROCESS_INFORMATION pi = {}; - // We use CreateProcess to setup working folder - pcstr tempDir = xr_strlen(g_sLaunchWorkingFolder) ? g_sLaunchWorkingFolder : nullptr; - CreateProcess(g_sLaunchOnExit_app, g_sLaunchOnExit_params, nullptr, nullptr, FALSE, 0, nullptr, tempDir, &si, &pi); -#endif + pcstr benchmarkName, t; + ini.r_line("benchmark", i, &benchmarkName, &t); + xr_strcpy(g_sBenchmarkName, benchmarkName); + shared_str benchmarkCommand = ini.r_string_wb("benchmark", benchmarkName); + const auto cmdSize = benchmarkCommand.size() + 1; + Core.Params = (char*)xr_realloc(Core.Params, cmdSize); + xr_strcpy(Core.Params, cmdSize, benchmarkCommand.c_str()); + xr_strlwr(Core.Params); + //InitInput(); + Engine.External.Initialize(); + //if (i) + // InitEngine(); + xr_strcpy(Console->ConfigFile, "user.ltx"); + if (strstr(Core.Params, "-ltx ")) + { + string64 cfgName; + sscanf(strstr(Core.Params, "-ltx ") + hyphenLtxLen, "%[^ ] ", cfgName); + xr_strcpy(Console->ConfigFile, cfgName); + } + //Startup(); } - return 0; } -namespace -{ bool CheckBenchmark() { pcstr benchName = "-batch_benchmark "; @@ -325,36 +69,4 @@ bool CheckBenchmark() return false; } -void RunBenchmark(pcstr name) -{ - g_bBenchmark = true; - string_path cfgPath; - FS.update_path(cfgPath, "$app_data_root$", name); - CInifile ini(cfgPath); - const u32 benchmarkCount = ini.line_count("benchmark"); - const size_t hyphenLtxLen = xr_strlen("-ltx "); - for (u32 i = 0; i < benchmarkCount; i++) - { - pcstr benchmarkName, t; - ini.r_line("benchmark", i, &benchmarkName, &t); - xr_strcpy(g_sBenchmarkName, benchmarkName); - shared_str benchmarkCommand = ini.r_string_wb("benchmark", benchmarkName); - const auto cmdSize = benchmarkCommand.size() + 1; - Core.Params = (char*)xr_realloc(Core.Params, cmdSize); - xr_strcpy(Core.Params, cmdSize, benchmarkCommand.c_str()); - xr_strlwr(Core.Params); - InitInput(); - Engine.External.Initialize(); - //if (i) - // InitEngine(); - xr_strcpy(Console->ConfigFile, "user.ltx"); - if (strstr(Core.Params, "-ltx ")) - { - string64 cfgName; - sscanf(strstr(Core.Params, "-ltx ") + hyphenLtxLen, "%[^ ] ", cfgName); - xr_strcpy(Console->ConfigFile, cfgName); - } - Startup(); - } -} } diff --git a/src/xrEngine/main.h b/src/xrEngine/main.h deleted file mode 100644 index 952c1b67c61..00000000000 --- a/src/xrEngine/main.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -ENGINE_API void InitSettings(); -ENGINE_API void destroySettings(); - -ENGINE_API void InitConsole(); -ENGINE_API void destroyConsole(); - -ENGINE_API void InitInput(); -ENGINE_API void destroyInput(); - -ENGINE_API void InitSoundDeviceList(); -ENGINE_API void InitSound(); -ENGINE_API void destroySound(); - -ENGINE_API void Startup(); -ENGINE_API int RunApplication(); diff --git a/src/xrEngine/x_ray.cpp b/src/xrEngine/x_ray.cpp index 616b1ac5d86..9e3d284a9a0 100644 --- a/src/xrEngine/x_ray.cpp +++ b/src/xrEngine/x_ray.cpp @@ -9,18 +9,194 @@ #include "x_ray.h" -#include "main.h" #include "AccessibilityShortcuts.hpp" #include "embedded_resources_management.h" +#include "xrCore/Threading/TaskManager.hpp" +#include "xrNetServer/NET_AuthCheck.h" + +#include "std_classes.h" +#include "IGame_Persistent.h" +#include "LightAnimLibrary.h" +#include "XR_IOConsole.h" +#include "xrSASH.h" + +#if defined(XR_PLATFORM_WINDOWS) +#include "Text_Console.h" +#elif defined(XR_PLATFORM_LINUX) || defined(XR_PLATFORM_BSD) || defined(XR_PLATFORM_APPLE) +#define CTextConsole CConsole +#pragma todo("Implement text console or it's alternative") +#endif + //#define PROFILE_TASK_SYSTEM #ifdef PROFILE_TASK_SYSTEM #include "xrCore/Threading/ParallelForEach.hpp" #endif +// global variables constexpr u32 SPLASH_FRAMERATE = 30; +ENGINE_API CInifile* pGameIni = nullptr; +ENGINE_API bool CallOfPripyatMode = false; +ENGINE_API bool ClearSkyMode = false; +ENGINE_API bool ShadowOfChernobylMode = false; + +ENGINE_API string512 g_sLaunchOnExit_params; +ENGINE_API string512 g_sLaunchOnExit_app; +ENGINE_API string_path g_sLaunchWorkingFolder; + +namespace +{ +struct PathIncludePred +{ +private: + const xr_auth_strings_t* ignored; + +public: + explicit PathIncludePred(const xr_auth_strings_t* ignoredPaths) : ignored(ignoredPaths) {} + bool IsIncluded(pcstr path) + { + if (!ignored) + return true; + + return allow_to_include_path(*ignored, path); + } +}; +} + +template +void InitConfig(T& config, pcstr name, bool fatal = true, + bool readOnly = true, bool loadAtStart = true, bool saveAtEnd = true, + u32 sectCount = 0, const CInifile::allow_include_func_t& allowIncludeFunc = nullptr) +{ + string_path fname; + FS.update_path(fname, "$game_config$", name); + config = xr_new(fname, readOnly, loadAtStart, saveAtEnd, sectCount, allowIncludeFunc); + + CHECK_OR_EXIT(config->section_count() || !fatal, + make_string("Cannot find file %s.\nReinstalling application may fix this problem.", fname)); +} + +// XXX: make it more fancy +// некрасиво слишком +void set_shoc_mode() +{ + CallOfPripyatMode = false; + ShadowOfChernobylMode = true; + ClearSkyMode = false; +} + +void set_cs_mode() +{ + CallOfPripyatMode = false; + ShadowOfChernobylMode = false; + ClearSkyMode = true; +} + +void set_cop_mode() +{ + CallOfPripyatMode = true; + ShadowOfChernobylMode = false; + ClearSkyMode = false; +} + +void set_free_mode() +{ + CallOfPripyatMode = false; + ShadowOfChernobylMode = false; + ClearSkyMode = false; +} + +void InitSettings() +{ + xr_auth_strings_t ignoredPaths, checkedPaths; + fill_auth_check_params(ignoredPaths, checkedPaths); //TODO port xrNetServer to Linux + PathIncludePred includePred(&ignoredPaths); + CInifile::allow_include_func_t includeFilter; + includeFilter.bind(&includePred, &PathIncludePred::IsIncluded); + + InitConfig(pSettings, "system.ltx"); + InitConfig(pSettingsAuth, "system.ltx", true, true, true, false, 0, includeFilter); + InitConfig(pSettingsOpenXRay, "openxray.ltx", false, true, true, false); + InitConfig(pGameIni, "game.ltx"); + + if (strstr(Core.Params, "-shoc") || strstr(Core.Params, "-soc")) + set_shoc_mode(); + else if (strstr(Core.Params, "-cs")) + set_cs_mode(); + else if (strstr(Core.Params, "-cop")) + set_cop_mode(); + else if (strstr(Core.Params, "-unlock_game_mode")) + set_free_mode(); + else + { + pcstr gameMode = READ_IF_EXISTS(pSettingsOpenXRay, r_string, "compatibility", "game_mode", "cop"); + if (xr_strcmpi("cop", gameMode) == 0) + set_cop_mode(); + else if (xr_strcmpi("cs", gameMode) == 0) + set_cs_mode(); + else if (xr_strcmpi("shoc", gameMode) == 0 || xr_strcmpi("soc", gameMode) == 0) + set_shoc_mode(); + else if (xr_strcmpi("unlock", gameMode) == 0) + set_free_mode(); + } +} + +void InitConsole() +{ + if (GEnv.isDedicatedServer) + Console = xr_new(); + else + Console = xr_new(); + + Console->Initialize(); + xr_strcpy(Console->ConfigFile, "user.ltx"); + if (strstr(Core.Params, "-ltx ")) + { + string64 c_name; + sscanf(strstr(Core.Params, "-ltx ") + strlen("-ltx "), "%[^ ] ", c_name); + xr_strcpy(Console->ConfigFile, c_name); + } +} + +void InitInput() +{ + bool captureInput = !strstr(Core.Params, "-i"); + pInput = xr_new(captureInput); +} + +void destroyInput() { xr_delete(pInput); } +void InitSoundDeviceList() { Engine.Sound.CreateDevicesList(); } +void InitSound() { Engine.Sound.Create(); } +void destroySound() { Engine.Sound.Destroy(); } +void destroySettings() +{ + auto s = const_cast(&pSettings); + xr_delete(*s); + + auto sa = const_cast(&pSettingsAuth); + xr_delete(*sa); + + auto so = const_cast(&pSettingsOpenXRay); + xr_delete(*so); + + xr_delete(pGameIni); +} + +void destroyConsole() +{ + Console->Execute("cfg_save"); + Console->Destroy(); + xr_delete(Console); +} + +void execUserScript() +{ + Console->Execute("default_controls"); + Console->ExecuteScript(Console->ConfigFile); +} + CApplication::CApplication(pcstr commandLine) { xrDebug::Initialize(commandLine); @@ -75,11 +251,101 @@ CApplication::CApplication(pcstr commandLine) } Msg("Time min: %f microseconds", float(min) / 1000.f); Msg("Time average: %f microseconds", float(average) / float(iterations)); + + return; #endif + *g_sLaunchOnExit_app = 0; + *g_sLaunchOnExit_params = 0; + + InitSettings(); + // Adjust player & computer name for Asian + if (pSettings->line_exist("string_table", "no_native_input")) + { + xr_strcpy(Core.UserName, sizeof(Core.UserName), "Player"); + xr_strcpy(Core.CompName, sizeof(Core.CompName), "Computer"); + } + + FPU::m24r(); + + Device.FillVideoModes(); + InitInput(); + InitConsole(); + + Engine.Initialize(); + Device.Initialize(); + + Console->OnDeviceInitialize(); + + //if (CheckBenchmark()) + // return 0; + + InitSoundDeviceList(); + execUserScript(); + InitSound(); + + // ...command line for auto start + pcstr startArgs = strstr(Core.Params, "-start "); + if (startArgs) + Console->Execute(startArgs + 1); + pcstr loadArgs = strstr(Core.Params, "-load "); + if (loadArgs) + Console->Execute(loadArgs + 1); + + // Initialize APP + const auto& createLightAnim = TaskScheduler->AddTask("LALib.OnCreate()", [](Task&, void*) + { + LALib.OnCreate(); + }); + + Device.Create(); + TaskScheduler->Wait(createLightAnim); + + g_pGamePersistent = dynamic_cast(NEW_INSTANCE(CLSID_GAME_PERSISTANT)); + R_ASSERT(g_pGamePersistent || Engine.External.CanSkipGameModuleLoading()); + if (!g_pGamePersistent) + Console->Show(); } CApplication::~CApplication() { +#ifndef PROFILE_TASK_SYSTEM + // Destroy APP + DEL_INSTANCE(g_pGamePersistent); + Engine.Event.Dump(); + + // Destroying + destroyInput(); + if (!g_bBenchmark && !g_SASH.IsRunning()) + destroySettings(); + + LALib.OnDestroy(); + + if (!g_bBenchmark && !g_SASH.IsRunning()) + destroyConsole(); + else + Console->Destroy(); + + Device.CleanupVideoModes(); + destroySound(); + + Device.Destroy(); + Engine.Destroy(); + + // check for need to execute something external + if (/*xr_strlen(g_sLaunchOnExit_params) && */ xr_strlen(g_sLaunchOnExit_app)) + { +#if defined(XR_PLATFORM_WINDOWS) + // CreateProcess need to return results to next two structures + STARTUPINFO si = {}; + si.cb = sizeof(si); + PROCESS_INFORMATION pi = {}; + // We use CreateProcess to setup working folder + pcstr tempDir = xr_strlen(g_sLaunchWorkingFolder) ? g_sLaunchWorkingFolder : nullptr; + CreateProcess(g_sLaunchOnExit_app, g_sLaunchOnExit_params, nullptr, nullptr, FALSE, 0, nullptr, tempDir, &si, &pi); +#endif + } +#endif // PROFILE_TASK_SYSTEM + Core._destroy(); SDL_Quit(); } @@ -89,8 +355,12 @@ int CApplication::Run() #ifdef PROFILE_TASK_SYSTEM return 0; #endif + + // Main cycle HideSplash(); - return RunApplication(); + Device.Run(); + + return 0; } void CApplication::ShowSplash(bool topmost) diff --git a/src/xrEngine/x_ray.h b/src/xrEngine/x_ray.h index 9612d162a19..076ca6f9ae0 100644 --- a/src/xrEngine/x_ray.h +++ b/src/xrEngine/x_ray.h @@ -1,6 +1,11 @@ #ifndef __X_RAY_H__ #define __X_RAY_H__ +#include "xrCore/Threading/Event.hpp" + +struct SDL_Window; +struct SDL_Surface; + // definition class ENGINE_API CApplication final { @@ -25,5 +30,4 @@ class ENGINE_API CApplication final int Run(); }; - #endif //__XR_BASE_H__ diff --git a/src/xrEngine/xrEngine.vcxproj b/src/xrEngine/xrEngine.vcxproj index 8d9047eed80..73ce634812f 100644 --- a/src/xrEngine/xrEngine.vcxproj +++ b/src/xrEngine/xrEngine.vcxproj @@ -71,7 +71,6 @@ - diff --git a/src/xrEngine/xrEngine.vcxproj.filters b/src/xrEngine/xrEngine.vcxproj.filters index 03c7eab12f7..d785264fba7 100644 --- a/src/xrEngine/xrEngine.vcxproj.filters +++ b/src/xrEngine/xrEngine.vcxproj.filters @@ -360,9 +360,6 @@ Render\Visibility - - General - Interfaces\ILoadingScreen diff --git a/src/xrEngine/xrSASH.cpp b/src/xrEngine/xrSASH.cpp index 802ecf7c4af..d1dd322a35f 100644 --- a/src/xrEngine/xrSASH.cpp +++ b/src/xrEngine/xrSASH.cpp @@ -4,8 +4,6 @@ #include "XR_IOConsole.h" #include "xr_ioc_cmd.h" -#include "main.h" - xrSASH ENGINE_API g_SASH; xrSASH::~xrSASH() @@ -434,15 +432,13 @@ void xrSASH::GetBenchmarks() } #endif -void Startup(); - void xrSASH::RunBenchmark(pcstr pszName) { Msg("SASH:: RunBenchmark."); TryInitEngine(false); - Startup(); + //Startup(); m_bReinitEngine = true; @@ -489,12 +485,12 @@ void xrSASH::TryInitEngine(bool bNoRun) xr_delete(pTmp); } - InitInput(); + //InitInput(); Engine.External.Initialize(); - if (bNoRun) - InitSoundDeviceList(); + //if (bNoRun) + // InitSoundDeviceList(); Console->Execute("unbindall"); Console->ExecuteScript(Console->ConfigFile); @@ -507,7 +503,7 @@ void xrSASH::TryInitEngine(bool bNoRun) if (bNoRun) { - InitSound(); + //InitSound(); Device.Create(); } } @@ -516,10 +512,10 @@ void xrSASH::ReleaseEngine() { m_bReinitEngine = true; - destroyInput(); + //destroyInput(); Console->Destroy(); Device.CleanupVideoModes(); - destroySound(); + //destroySound(); //destroyEngine(); } diff --git a/src/xrEngine/xr_collide_form.cpp b/src/xrEngine/xr_collide_form.cpp index 4cc385296f7..97f901b5392 100644 --- a/src/xrEngine/xr_collide_form.cpp +++ b/src/xrEngine/xr_collide_form.cpp @@ -3,7 +3,6 @@ #include "xr_collide_form.h" #include "xr_object.h" #include "xrCDB/xr_area.h" -#include "x_ray.h" #include "Common/LevelStructure.hpp" #include "xrCore/FMesh.hpp" #include "xrCDB/Frustum.h" diff --git a/src/xrEngine/xr_ioc_cmd.cpp b/src/xrEngine/xr_ioc_cmd.cpp index 79387aa9aa9..5ba8e794ec9 100644 --- a/src/xrEngine/xr_ioc_cmd.cpp +++ b/src/xrEngine/xr_ioc_cmd.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "IGame_Level.h" -#include "x_ray.h" #include "XR_IOConsole.h" #include "xr_ioc_cmd.h" #include "xrSASH.h" diff --git a/src/xrGame/Level_GameSpy_Funcs.cpp b/src/xrGame/Level_GameSpy_Funcs.cpp index 9ec86f542fb..a9090de36ab 100644 --- a/src/xrGame/Level_GameSpy_Funcs.cpp +++ b/src/xrGame/Level_GameSpy_Funcs.cpp @@ -1,7 +1,6 @@ #include "StdAfx.h" #include "Level.h" #include "xrMessages.h" -#include "xrEngine/x_ray.h" #include "xrGameSpy/GameSpy_GCD_Client.h" #include "xrEngine/IGame_Persistent.h" #include "ui/UICDkey.h" diff --git a/src/xrGame/Level_load.cpp b/src/xrGame/Level_load.cpp index 46464bbfdbe..4ee77204890 100644 --- a/src/xrGame/Level_load.cpp +++ b/src/xrGame/Level_load.cpp @@ -6,7 +6,6 @@ #include "xrScriptEngine/script_engine.hpp" #include "Level.h" #include "game_cl_base.h" -#include "xrEngine/x_ray.h" #include "xrMaterialSystem/GameMtlLib.h" #include "xrPhysics/PhysicsCommon.h" #include "level_sounds.h" diff --git a/src/xrGame/Level_network_start_client.cpp b/src/xrGame/Level_network_start_client.cpp index 566c3af90ec..76252367f92 100644 --- a/src/xrGame/Level_network_start_client.cpp +++ b/src/xrGame/Level_network_start_client.cpp @@ -1,7 +1,6 @@ #include "StdAfx.h" #include "Level.h" -#include "xrEngine/x_ray.h" #include "xrEngine/IGame_Persistent.h" #include "ai_space.h" diff --git a/src/xrGame/Level_start.cpp b/src/xrGame/Level_start.cpp index 21026f3194e..4336437b26e 100644 --- a/src/xrGame/Level_start.cpp +++ b/src/xrGame/Level_start.cpp @@ -5,7 +5,6 @@ #include "game_cl_base.h" #include "xrMessages.h" #include "xrGameSpyServer.h" -#include "xrEngine/x_ray.h" #include "xrEngine/device.h" #include "xrEngine/IGame_Persistent.h" #include "xrEngine/XR_IOConsole.h" diff --git a/src/xrGame/UIGameCustom.cpp b/src/xrGame/UIGameCustom.cpp index 02c2035a755..619f532468b 100644 --- a/src/xrGame/UIGameCustom.cpp +++ b/src/xrGame/UIGameCustom.cpp @@ -15,8 +15,6 @@ #include "Inventory.h" #include "game_cl_base.h" -#include "xrEngine/x_ray.h" - #include "ui/UICellItem.h" //Alundaio //#include "script_game_object.h" //Alundaio diff --git a/src/xrGame/alife_graph_registry.cpp b/src/xrGame/alife_graph_registry.cpp index 2e1dc371bef..c16986cdc4b 100644 --- a/src/xrGame/alife_graph_registry.cpp +++ b/src/xrGame/alife_graph_registry.cpp @@ -8,7 +8,6 @@ #include "StdAfx.h" #include "alife_graph_registry.h" -#include "xrEngine/x_ray.h" #include "xrServerEntities/xrMessages.h" using namespace ALife; diff --git a/src/xrGame/alife_storage_manager.cpp b/src/xrGame/alife_storage_manager.cpp index 1f977492db7..611d898f161 100644 --- a/src/xrGame/alife_storage_manager.cpp +++ b/src/xrGame/alife_storage_manager.cpp @@ -17,7 +17,6 @@ #include "alife_registry_container.h" #include "xrServer.h" #include "Level.h" -#include "xrEngine/x_ray.h" #include "saved_game_wrapper.h" #include "xrEngine/IGame_Persistent.h" #include "autosave_manager.h" diff --git a/src/xrGame/alife_update_manager.cpp b/src/xrGame/alife_update_manager.cpp index 2d10fda3634..339bbfeb8f8 100644 --- a/src/xrGame/alife_update_manager.cpp +++ b/src/xrGame/alife_update_manager.cpp @@ -18,7 +18,6 @@ #include "xrServer.h" #include "Level.h" #include "xrAICore/Navigation/graph_engine.h" -#include "xrEngine/x_ray.h" #include "restriction_space.h" #include "xrEngine/profiler.h" #include "mt_config.h" diff --git a/src/xrGame/game_sv_single.cpp b/src/xrGame/game_sv_single.cpp index d4a3b05a27a..c7be6bc8d7b 100644 --- a/src/xrGame/game_sv_single.cpp +++ b/src/xrGame/game_sv_single.cpp @@ -8,7 +8,6 @@ #include "Common/object_broker.h" #include "GamePersistent.h" #include "xrServer.h" -#include "xrEngine/x_ray.h" game_sv_Single::game_sv_Single() { diff --git a/src/xrGame/script_render_device_script.cpp b/src/xrGame/script_render_device_script.cpp index 409b802457f..21e342223dc 100644 --- a/src/xrGame/script_render_device_script.cpp +++ b/src/xrGame/script_render_device_script.cpp @@ -8,7 +8,6 @@ #include "pch_script.h" #include "xrScriptEngine/ScriptExporter.hpp" -#include "xrEngine/x_ray.h" bool is_device_paused(CRenderDevice* d) { return !!Device.Paused(); } void set_device_paused(CRenderDevice* d, bool b) { Device.Pause(b, TRUE, FALSE, "set_device_paused_script"); } diff --git a/src/xrGame/ui/UILoadingScreen.cpp b/src/xrGame/ui/UILoadingScreen.cpp index 32db07cd000..6caea14ed93 100644 --- a/src/xrGame/ui/UILoadingScreen.cpp +++ b/src/xrGame/ui/UILoadingScreen.cpp @@ -11,8 +11,6 @@ #include "UILoadingScreen.h" #include "UILoadingScreenHardcoded.h" -#include "xrEngine/x_ray.h" -#include "xrEngine/GameFont.h" #include "UIHelper.h" #include "xrUICore/XML/UITextureMaster.h" diff --git a/src/xrGame/xrServer_Connect.cpp b/src/xrGame/xrServer_Connect.cpp index f9cf35b3725..e94ad899980 100644 --- a/src/xrGame/xrServer_Connect.cpp +++ b/src/xrGame/xrServer_Connect.cpp @@ -8,7 +8,6 @@ #include "game_cl_artefacthunt.h" #include "game_cl_single.h" #include "MainMenu.h" -#include "xrEngine/x_ray.h" #include "file_transfer.h" #include "screenshot_server.h" #include "xrNetServer/NET_AuthCheck.h" diff --git a/src/xrSound/MusicStream.cpp b/src/xrSound/MusicStream.cpp index 9ddbfb2c6b0..1bc1e98474d 100644 --- a/src/xrSound/MusicStream.cpp +++ b/src/xrSound/MusicStream.cpp @@ -6,9 +6,6 @@ #include "MusicStream.h" #include "xr_streamsnd.h" -#if defined(WINDOWS) -#include "x_ray.h" -#endif #include "GameFont.h" //////////////////////////////////////////////////////////////////////