From 549d1bc670329fe601aafdbc2dff3147ee619602 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Fri, 11 Aug 2017 08:18:16 +0500 Subject: [PATCH] xrCore refactoring --- src/utils/ETools/ETools.cpp | 2 +- src/utils/mp_configs_verifyer/entry_point.cpp | 2 +- src/utils/mp_screenshots_info/entry_point.cpp | 2 +- src/utils/xrAI/xrAI.cpp | 2 +- src/utils/xrCompress/main.cpp | 2 +- src/utils/xrDO_Light/xrDO_Light.cpp | 2 +- src/utils/xrLC/xrLC.cpp | 2 +- src/utils/xrLC_Light/xrLC_Light.cpp | 2 +- src/utils/xrSE_Factory/xrSE_Factory.cpp | 2 +- src/xrCore/xrCore.cpp | 18 ++++++------- src/xrCore/xrCore.h | 26 +++++++++++-------- src/xrCore/xrMemory_subst_msvc.h | 2 ++ src/xrEngine/main.cpp | 2 +- 13 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/utils/ETools/ETools.cpp b/src/utils/ETools/ETools.cpp index de6c115437e..4f7acb049dd 100644 --- a/src/utils/ETools/ETools.cpp +++ b/src/utils/ETools/ETools.cpp @@ -10,7 +10,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved) { case DLL_PROCESS_ATTACH: xrDebug::Initialize(false); - Core._initialize("XRayEditorTools", 0, FALSE); + Core.Initialize("XRayEditorTools", 0, FALSE); // FPU::m64r (); break; case DLL_THREAD_ATTACH: break; diff --git a/src/utils/mp_configs_verifyer/entry_point.cpp b/src/utils/mp_configs_verifyer/entry_point.cpp index 5df125b87d8..bbbda635690 100644 --- a/src/utils/mp_configs_verifyer/entry_point.cpp +++ b/src/utils/mp_configs_verifyer/entry_point.cpp @@ -148,7 +148,7 @@ void run_configs_verifyer_server() void initialize_core() { - Core._initialize("mp_configs_info", LogCallback(xrcore_log_cb, nullptr), TRUE, "fsgame4mpu.ltx"); + Core.Initialize("mp_configs_info", LogCallback(xrcore_log_cb, nullptr), TRUE, "fsgame4mpu.ltx"); string_path fname; FS.update_path(fname, "$game_config$", "system.ltx"); diff --git a/src/utils/mp_screenshots_info/entry_point.cpp b/src/utils/mp_screenshots_info/entry_point.cpp index 002797944b8..229f6edc8ae 100644 --- a/src/utils/mp_screenshots_info/entry_point.cpp +++ b/src/utils/mp_screenshots_info/entry_point.cpp @@ -69,7 +69,7 @@ int main(int argc, char** argv) return EXIT_FAILURE; } printf("Initializing core...\n"); - Core._initialize("mp_screenshots_info", LogCallback(xrcore_log_cb, nullptr), TRUE, "fsgame4mpu.ltx"); + Core.Initialize("mp_screenshots_info", LogCallback(xrcore_log_cb, nullptr), TRUE, "fsgame4mpu.ltx"); #ifdef DEBUG if (strstr(argv[1], "--gen_params")) diff --git a/src/utils/xrAI/xrAI.cpp b/src/utils/xrAI/xrAI.cpp index 40f3d13f228..8521406a657 100644 --- a/src/utils/xrAI/xrAI.cpp +++ b/src/utils/xrAI/xrAI.cpp @@ -197,7 +197,7 @@ Factory_Destroy* destroy_entity = 0; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { xrDebug::Initialize(false); - Core._initialize("xrai", 0); + Core.Initialize("xrai", 0); HMODULE hFactory; LPCSTR g_name = "xrSE_Factory"; Log("Loading DLL:", g_name); diff --git a/src/utils/xrCompress/main.cpp b/src/utils/xrCompress/main.cpp index 81a6eca922d..4caa1012672 100644 --- a/src/utils/xrCompress/main.cpp +++ b/src/utils/xrCompress/main.cpp @@ -8,7 +8,7 @@ extern int ProcessDifference(); int __cdecl main(int argc, char* argv[]) { xrDebug::Initialize(false); - Core._initialize("xrCompress", 0, FALSE); + Core.Initialize("xrCompress", 0, FALSE); printf("\n\n"); LPCSTR params = GetCommandLine(); diff --git a/src/utils/xrDO_Light/xrDO_Light.cpp b/src/utils/xrDO_Light/xrDO_Light.cpp index de4fa5267cf..e454e625912 100644 --- a/src/utils/xrDO_Light/xrDO_Light.cpp +++ b/src/utils/xrDO_Light/xrDO_Light.cpp @@ -90,7 +90,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi { // Initialize debugging xrDebug::Initialize(false); - Core._initialize("xrDO"); + Core.Initialize("xrDO"); Startup(lpCmdLine); return 0; diff --git a/src/utils/xrLC/xrLC.cpp b/src/utils/xrLC/xrLC.cpp index 31eee22d614..39f4c2fa8fe 100644 --- a/src/utils/xrLC/xrLC.cpp +++ b/src/utils/xrLC/xrLC.cpp @@ -155,7 +155,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, { // Initialize debugging xrDebug::Initialize(false); - Core._initialize("xrLC"); + Core.Initialize("xrLC"); if (strstr(Core.Params, "-nosmg")) g_using_smooth_groups = false; diff --git a/src/utils/xrLC_Light/xrLC_Light.cpp b/src/utils/xrLC_Light/xrLC_Light.cpp index f193b0bd335..445502ccb7f 100644 --- a/src/utils/xrLC_Light/xrLC_Light.cpp +++ b/src/utils/xrLC_Light/xrLC_Light.cpp @@ -24,7 +24,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv { xrDebug::Initialize(false); bool init_log = (0 != xr_strcmp(Core.ApplicationName, "XRayEditorTools")); - Core._initialize("xrLC_Light", 0, FALSE); + Core.Initialize("xrLC_Light", 0, FALSE); if (init_log) CreateLog(); diff --git a/src/utils/xrSE_Factory/xrSE_Factory.cpp b/src/utils/xrSE_Factory/xrSE_Factory.cpp index 441ccc6ffeb..2050e3fcbeb 100644 --- a/src/utils/xrSE_Factory/xrSE_Factory.cpp +++ b/src/utils/xrSE_Factory/xrSE_Factory.cpp @@ -54,7 +54,7 @@ BOOL APIENTRY DllMain(HANDLE module_handle, DWORD call_reason, LPVOID reserved) // g_temporary_stuff = &trivial_encryptor::decode; Debug._initialize(false); - Core._initialize("xrSE_Factory", NULL, TRUE, "fsfactory.ltx"); + Core.Initialize("xrSE_Factory", NULL, TRUE, "fsfactory.ltx"); string_path SYSTEM_LTX; FS.update_path(SYSTEM_LTX, "$game_config$", "system.ltx"); pSettings = xr_new(SYSTEM_LTX); diff --git a/src/xrCore/xrCore.cpp b/src/xrCore/xrCore.cpp index 04414780a30..128beb8a3cd 100644 --- a/src/xrCore/xrCore.cpp +++ b/src/xrCore/xrCore.cpp @@ -26,7 +26,7 @@ static u32 init_counter = 0; //. extern xr_vector* LogFile; -void xrCore::_initialize(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs, LPCSTR fs_fname, bool plugin) +void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pcstr fs_fname, bool plugin) { xr_strcpy(ApplicationName, _ApplicationName); if (0 == init_counter) @@ -36,13 +36,13 @@ void xrCore::_initialize(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs, // HRESULT co_res = Params = xr_strdup(GetCommandLine()); if (!strstr(Params, "-editor")) - CoInitializeEx(NULL, COINIT_MULTITHREADED); + CoInitializeEx(nullptr, COINIT_MULTITHREADED); string_path fn, dr, di; // application path GetModuleFileName(GetModuleHandle("xrCore"), fn, sizeof(fn)); - _splitpath(fn, dr, di, 0, 0); + _splitpath(fn, dr, di, nullptr, nullptr); strconcat(sizeof(ApplicationPath), ApplicationPath, dr, di); #ifdef _EDITOR @@ -87,10 +87,10 @@ void xrCore::_initialize(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs, } if (init_fs) { - u32 flags = 0; - if (0 != strstr(Params, "-build")) + u32 flags = 0u; + if (strstr(Params, "-build") != nullptr) flags |= CLocatorAPI::flBuildCopy; - if (0 != strstr(Params, "-ebuild")) + if (strstr(Params, "-ebuild") != nullptr) flags |= CLocatorAPI::flBuildCopy | CLocatorAPI::flEBuildCopy; #ifdef DEBUG if (strstr(Params, "-cache")) @@ -105,11 +105,11 @@ void xrCore::_initialize(LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs, #ifndef _EDITOR #ifndef ELocatorAPIH - if (0 != strstr(Params, "-file_activity")) + if (strstr(Params, "-file_activity") != nullptr) flags |= CLocatorAPI::flDumpFileActivity; #endif #endif - FS._initialize(flags, 0, fs_fname); + FS._initialize(flags, nullptr, fs_fname); CalculateBuildId(); Msg("'%s' build %d, %s\n", "xrCore", buildId, buildDate); EFS._initialize(); @@ -201,7 +201,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpvRese break; case DLL_THREAD_ATTACH: if (!strstr(GetCommandLine(), "-editor")) - CoInitializeEx(NULL, COINIT_MULTITHREADED); + CoInitializeEx(nullptr, COINIT_MULTITHREADED); timeBeginPeriod(1); break; case DLL_THREAD_DETACH: break; diff --git a/src/xrCore/xrCore.h b/src/xrCore/xrCore.h index 9abe8da81ab..56ee71118f9 100644 --- a/src/xrCore/xrCore.h +++ b/src/xrCore/xrCore.h @@ -137,15 +137,15 @@ struct XRCORE_API xr_rtoken { shared_str name; int id; - xr_rtoken(LPCSTR _nm, int _id) + + xr_rtoken(pcstr _nm, int _id) { name = _nm; id = _id; } -public: - void rename(LPCSTR _nm) { name = _nm; } - bool equal(LPCSTR _nm) { return (0 == xr_strcmp(*name, _nm)); } + void rename(pcstr _nm) { name = _nm; } + bool equal(pcstr _nm) const { return (0 == xr_strcmp(*name, _nm)); } }; #pragma pack(push, 1) @@ -157,6 +157,7 @@ struct XRCORE_API xr_shortcut flCtrl = 0x40, flAlt = 0x80, }; + union { struct @@ -166,22 +167,25 @@ struct XRCORE_API xr_shortcut }; u16 hotkey; }; - xr_shortcut(u8 k, BOOL a, BOOL c, BOOL s) : key(k) + + xr_shortcut(u8 k, bool a, bool c, bool s) : key(k) { ext.assign(u8((a ? flAlt : 0) | (c ? flCtrl : 0) | (s ? flShift : 0))); } + xr_shortcut() { ext.zero(); key = 0; } + bool similar(const xr_shortcut& v) const { return ext.equal(v.ext) && (key == v.key); } }; #pragma pack(pop) -DEFINE_VECTOR(shared_str, RStringVec, RStringVecIt); -DEFINE_SET(shared_str, RStringSet, RStringSetIt); -DEFINE_VECTOR(xr_rtoken, RTokenVec, RTokenVecIt); +using RStringVec = xr_vector; +using RStringSet = xr_set; +using RTokenVec = xr_vector; #define xr_pure_interface __interface @@ -210,7 +214,7 @@ class destructor public: destructor(T* p) { ptr = p; } ~destructor() { xr_delete(ptr); } - IC T& operator()() { return *ptr; } + T& operator()() { return *ptr; } }; // ********************************************** The Core definition @@ -229,8 +233,8 @@ class XRCORE_API xrCore DWORD dwFrame; bool PluginMode; - void _initialize( - LPCSTR ApplicationName, LogCallback cb = 0, BOOL init_fs = TRUE, LPCSTR fs_fname = 0, bool plugin = false); + void Initialize( + pcstr ApplicationName, LogCallback cb = nullptr, bool init_fs = true, pcstr fs_fname = nullptr, bool plugin = false); void _destroy(); const char* GetBuildDate() const { return buildDate; } u32 GetBuildId() const { return buildId; } diff --git a/src/xrCore/xrMemory_subst_msvc.h b/src/xrCore/xrMemory_subst_msvc.h index a4817a51f0e..4a733e307a6 100644 --- a/src/xrCore/xrMemory_subst_msvc.h +++ b/src/xrCore/xrMemory_subst_msvc.h @@ -1,3 +1,5 @@ +#pragma once + template struct xr_special_free { diff --git a/src/xrEngine/main.cpp b/src/xrEngine/main.cpp index 3a7a601b484..9e53ad77749 100644 --- a/src/xrEngine/main.cpp +++ b/src/xrEngine/main.cpp @@ -332,7 +332,7 @@ int RunApplication(pcstr commandLine) u32 sz = xr_strlen(fsltx); sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame); } - Core._initialize("xray", NULL, TRUE, *fsgame ? fsgame : nullptr); + Core.Initialize("xray", nullptr, true, *fsgame ? fsgame : nullptr); InitSettings(); // Adjust player & computer name for Asian if (pSettings->line_exist("string_table", "no_native_input"))