diff --git a/code/engine/xrCore/FS.cpp b/code/engine/xrCore/FS.cpp index fe3c7a843..423a3db81 100644 --- a/code/engine/xrCore/FS.cpp +++ b/code/engine/xrCore/FS.cpp @@ -366,6 +366,11 @@ void IReader::r_stringZ(xr_string& dest) { Pos += int(dest.size() + 1); } +void IReader::r_stringZ(std::string& dest) { + dest = data + Pos; + Pos += int(dest.size() + 1); +} + void IReader::skip_stringZ() { char* src = data; while ((src[Pos] != 0) && !eof()) diff --git a/code/engine/xrCore/FS.h b/code/engine/xrCore/FS.h index 7654971ad..2dd3d8d19 100644 --- a/code/engine/xrCore/FS.h +++ b/code/engine/xrCore/FS.h @@ -60,9 +60,15 @@ class XRCORE_API IWriter { } void w_stringZ(const xr_string& p) { - w(p.c_str() ? p.c_str() : "", p.size()); + w(p.c_str(), p.size()); w_u8(0); } + + void w_stringZ(const std::string& p) { + w(p.c_str(), p.size()); + w_u8(0); + } + void w_fcolor(const Fcolor& v) { w(&v, sizeof(Fcolor)); } void w_fvector4(const Fvector4& v) { w(&v, sizeof(Fvector4)); } void w_fvector3(const Fvector3& v) { w(&v, sizeof(Fvector3)); } @@ -380,6 +386,7 @@ class XRCORE_API IReader : public IReaderBase { void r_stringZ(char* dest, const size_t tgt_sz); void r_stringZ(shared_str& dest); void r_stringZ(xr_string& dest); + void r_stringZ(std::string& dest); void close(); diff --git a/code/engine/xrCore/xrstring.h b/code/engine/xrCore/xrstring.h index 3b7551de0..fcb402560 100644 --- a/code/engine/xrCore/xrstring.h +++ b/code/engine/xrCore/xrstring.h @@ -162,11 +162,18 @@ IC int xr_strcmp(const shared_str& a, const shared_str& b) { else return xr_strcmp(*a, *b); } -IC void xr_strlwr(xr_string& src) { - for (xr_string::iterator it = src.begin(); it != src.end(); it++) - *it = xr_string::value_type(tolower(*it)); + +[[deprecated]] +inline void xr_strlwr(xr_string& src) { + _strlwr(src.data()); +} + +[[deprecated]] +inline void xr_strlwr(std::string& src) { + _strlwr(src.data()); } -IC void xr_strlwr(shared_str& src) { + +inline void xr_strlwr(shared_str& src) { if (*src) { LPSTR lp = xr_strdup(*src); xr_strlwr(lp); diff --git a/code/engine/xrEngine/Environment_misc.cpp b/code/engine/xrEngine/Environment_misc.cpp index f5aa398f9..5726c59d4 100644 --- a/code/engine/xrEngine/Environment_misc.cpp +++ b/code/engine/xrEngine/Environment_misc.cpp @@ -501,9 +501,10 @@ void CEnvironment::mods_load() { void CEnvironment::mods_unload() { Modifiers.clear(); } void CEnvironment::load_level_specific_ambients() { - const shared_str level_name = g_pGameLevel->name(); + const auto& level_name = g_pGameLevel->name(); string_path path; + // TODO: [imdex] use string_view strconcat(sizeof(path), path, "environment\\ambients\\", level_name.c_str(), ".ltx"); string_path full_path; diff --git a/code/engine/xrEngine/FDemoRecord.cpp b/code/engine/xrEngine/FDemoRecord.cpp index a3d57c64e..32c10b008 100644 --- a/code/engine/xrEngine/FDemoRecord.cpp +++ b/code/engine/xrEngine/FDemoRecord.cpp @@ -187,9 +187,11 @@ void CDemoRecord::MakeLevelMapProcess() { string_path tmp; if (m_iLMScreenshotFragment == -1) - xr_sprintf(tmp, sizeof(tmp), "map_%s", *g_pGameLevel->name()); + // TODO: [imdex] use string_view + xr_sprintf(tmp, sizeof(tmp), "map_%s", g_pGameLevel->name().c_str()); else - xr_sprintf(tmp, sizeof(tmp), "map_%s#%d", *g_pGameLevel->name(), + // TODO: [imdex] use string_view + xr_sprintf(tmp, sizeof(tmp), "map_%s#%d", g_pGameLevel->name().c_str(), m_iLMScreenshotFragment); if (m_iLMScreenshotFragment != -1) { diff --git a/code/engine/xrEngine/IGame_Level.h b/code/engine/xrEngine/IGame_Level.h index 2a0b9b7b3..771c0489a 100644 --- a/code/engine/xrEngine/IGame_Level.h +++ b/code/engine/xrEngine/IGame_Level.h @@ -83,7 +83,7 @@ class ENGINE_API IGame_Level : public DLL_Pure, IGame_Level(); virtual ~IGame_Level(); - virtual shared_str name() const = 0; + virtual const std::string& name() const = 0; virtual void GetLevelInfo(CServerInfo* si) = 0; virtual BOOL net_Start(LPCSTR op_server, LPCSTR op_client) = 0; diff --git a/code/engine/xrEngine/XR_IOConsole.cpp b/code/engine/xrEngine/XR_IOConsole.cpp index 88c625525..d0a8c45ca 100644 --- a/code/engine/xrEngine/XR_IOConsole.cpp +++ b/code/engine/xrEngine/XR_IOConsole.cpp @@ -127,12 +127,12 @@ CConsole::CConsole() : m_hShader_back(NULL) { void CConsole::Initialize() { scroll_delta = 0; bVisible = false; - pFont = NULL; - pFont2 = NULL; + pFont = nullptr; + pFont2 = nullptr; m_mouse_pos.x = 0; m_mouse_pos.y = 0; - m_last_cmd = NULL; + m_last_cmd.clear(); m_cmd_history.reserve(m_cmd_history_max + 2); m_cmd_history.clear(); @@ -145,7 +145,7 @@ void CConsole::Initialize() { m_tips_mode = 0; m_prev_length_str = 0; - m_cur_cmd = NULL; + m_cur_cmd.clear(); reset_selected_tip(); // Commands @@ -529,7 +529,7 @@ void CConsole::ExecuteCommand(LPCSTR cmd_str, bool record_cmd) { c[0] = mark2; c[1] = 0; - if (m_last_cmd.c_str() == 0 || xr_strcmp(m_last_cmd, edt) != 0) { + if (m_last_cmd.empty() || m_last_cmd != edt) { Log(c, edt); add_cmd_history(edt); m_last_cmd = edt; @@ -637,7 +637,7 @@ void CConsole::ExecuteScript(LPCSTR str) { // ------------------------------------------------------------------------------------------------- -IConsole_Command* CConsole::find_next_cmd(LPCSTR in_str, shared_str& out_str) { +IConsole_Command* CConsole::find_next_cmd(LPCSTR in_str, std::string& out_str) { LPCSTR radmin_cmd_name = "ra "; bool b_ra = (in_str == strstr(in_str, radmin_cmd_name)); u32 offset = (b_ra) ? xr_strlen(radmin_cmd_name) : 0; @@ -655,10 +655,10 @@ IConsole_Command* CConsole::find_next_cmd(LPCSTR in_str, shared_str& out_str) { xr_strcpy(new_str, offset + name_cmd_size + 2, (b_ra) ? radmin_cmd_name : ""); xr_strcat(new_str, offset + name_cmd_size + 2, name_cmd); - out_str._set((LPCSTR)new_str); + out_str = (LPCSTR)new_str; return cc; } - return NULL; + return nullptr; } bool CConsole::add_next_cmds(LPCSTR in_str, vecTipsEx& out_v) { @@ -670,7 +670,7 @@ bool CConsole::add_next_cmds(LPCSTR in_str, vecTipsEx& out_v) { LPSTR t2; STRCONCAT(t2, in_str, " "); - shared_str temp; + std::string temp; IConsole_Command* cc = find_next_cmd(t2, temp); if (!cc || temp.size() == 0) { return false; @@ -679,11 +679,10 @@ bool CConsole::add_next_cmds(LPCSTR in_str, vecTipsEx& out_v) { bool res = false; for (u32 i = cur_count; i < MAX_TIPS_COUNT * 2; ++i) // fake=protect { - temp._set(cc->Name()); - bool dup = (std::find(out_v.begin(), out_v.end(), temp) != out_v.end()); + temp = cc->Name(); + const bool dup = (std::find(out_v.begin(), out_v.end(), temp) != out_v.end()); if (!dup) { - TipString ts(temp); - out_v.push_back(ts); + out_v.push_back(TipString(temp)); res = true; } if (out_v.size() >= MAX_TIPS_COUNT) { @@ -720,11 +719,10 @@ bool CConsole::add_internal_cmds(LPCSTR in_str, vecTipsEx& out_v) { name2[in_sz] = 0; if (!stricmp(name2, in_str)) { - shared_str temp; - temp._set(name); - bool dup = (std::find(out_v.begin(), out_v.end(), temp) != out_v.end()); + std::string temp(name); + const bool dup = std::find(out_v.begin(), out_v.end(), temp) != out_v.end(); if (!dup) { - out_v.push_back(TipString(temp, 0, in_sz)); + out_v.push_back(TipString(std::move(temp), 0, in_sz)); res = true; } } @@ -742,13 +740,12 @@ bool CConsole::add_internal_cmds(LPCSTR in_str, vecTipsEx& out_v) { LPCSTR name = itb->first; LPCSTR fd_str = strstr(name, in_str); if (fd_str) { - shared_str temp; - temp._set(name); + std::string temp(name); bool dup = (std::find(out_v.begin(), out_v.end(), temp) != out_v.end()); if (!dup) { - u32 name_sz = xr_strlen(name); - int fd_sz = name_sz - xr_strlen(fd_str); - out_v.push_back(TipString(temp, fd_sz, fd_sz + in_sz)); + const u32 name_sz = xr_strlen(name); + const int fd_sz = name_sz - xr_strlen(fd_str); + out_v.push_back(TipString(std::move(temp), fd_sz, fd_sz + in_sz)); res = true; } } @@ -764,7 +761,7 @@ void CConsole::update_tips() { m_temp_tips.clear(); m_tips.clear(); - m_cur_cmd = NULL; + m_cur_cmd.clear(); if (!bVisible) { return; } @@ -808,7 +805,7 @@ void CConsole::update_tips() { cc->fill_tips(m_temp_tips, mode); m_tips_mode = 2; - m_cur_cmd._set(first); + m_cur_cmd = first; select_for_filter(last, m_temp_tips, m_tips); if (m_tips.size() == 0) { @@ -838,27 +835,24 @@ void CConsole::update_tips() { } } -void CConsole::select_for_filter(LPCSTR filter_str, vecTips& in_v, vecTipsEx& out_v) { +void CConsole::select_for_filter(const char* filter_str, vecTips& in_v, vecTipsEx& out_v) const { out_v.clear(); - u32 in_count = in_v.size(); - if (in_count == 0 || !filter_str) { + if (in_v.empty() || !filter_str) { return; } - bool all = (xr_strlen(filter_str) == 0); + const std::string_view filter = filter_str; + const bool all = filter.empty(); - vecTips::iterator itb = in_v.begin(); - vecTips::iterator ite = in_v.end(); - for (; itb != ite; ++itb) { - shared_str const& str = (*itb); + for (const auto& str : in_v) { if (all) { out_v.push_back(TipString(str)); } else { - LPCSTR fd_str = strstr(str.c_str(), filter_str); - if (fd_str) { - int fd_sz = str.size() - xr_strlen(fd_str); - TipString ts(str, fd_sz, fd_sz + xr_strlen(filter_str)); - out_v.push_back(ts); + const auto pos = str.find(filter); + if (pos != std::string::npos) { + const int fd_sz = str.size() - pos; + TipString ts(str, fd_sz, fd_sz + filter.size()); + out_v.push_back(std::move(ts)); } } } // for diff --git a/code/engine/xrEngine/XR_IOConsole.h b/code/engine/xrEngine/XR_IOConsole.h index 3340d5cc1..aaed57ae4 100644 --- a/code/engine/xrEngine/XR_IOConsole.h +++ b/code/engine/xrEngine/XR_IOConsole.h @@ -17,31 +17,23 @@ class line_edit_control; }; // namespace text_editor struct TipString { - shared_str text; + std::string text; int HL_start; // Highlight int HL_finish; - TipString() { - text._set(""); - HL_start = 0; - HL_finish = 0; - } - TipString(shared_str const& tips_text, int start_pos, int finish_pos) { - text._set(tips_text); - HL_start = start_pos; - HL_finish = finish_pos; - } - TipString(LPCSTR tips_text, int start_pos, int finish_pos) { - text._set(tips_text); - HL_start = start_pos; - HL_finish = finish_pos; - } - TipString(shared_str const& tips_text) { - text._set(tips_text); - HL_start = 0; - HL_finish = 0; - } - IC bool operator==(shared_str const& tips_text) { return (text == tips_text); } + TipString() = default; + + TipString(std::string tips_text, const int start_pos = 0, const int finish_pos = 0) + : text(std::move(tips_text)), + HL_start(start_pos), + HL_finish(finish_pos) + {} + + TipString(const std::string_view tips_text, const int start_pos, const int finish_pos) + : TipString(std::string(tips_text), start_pos, finish_pos) + {} + + bool operator==(const std::string_view tips_text) { return text == tips_text; } }; class ENGINE_API CConsole : public pureRender, @@ -55,8 +47,8 @@ class ENGINE_API CConsole : public pureRender, typedef vecCMD::iterator vecCMD_IT; typedef vecCMD::const_iterator vecCMD_CIT; typedef fastdelegate::FastDelegate0 Callback; - typedef xr_vector vecHistory; - typedef xr_vector vecTips; + typedef xr_vector vecHistory; + typedef xr_vector vecTips; typedef xr_vector vecTipsEx; enum { CONSOLE_BUF_SIZE = 1024 }; @@ -77,13 +69,13 @@ class ENGINE_API CConsole : public pureRender, vecHistory m_cmd_history; u32 m_cmd_history_max; int m_cmd_history_idx; - shared_str m_last_cmd; + std::string m_last_cmd; BENCH_SEC_SCRAMBLEMEMBER1 vecTips m_temp_tips; vecTipsEx m_tips; u32 m_tips_mode; - shared_str m_cur_cmd; + std::string m_cur_cmd; int m_select_tip; int m_start_tip; u32 m_prev_length_str; @@ -178,7 +170,7 @@ class ENGINE_API CConsole : public pureRender, void xr_stdcall GamePause(); protected: - void add_cmd_history(shared_str const& str); + void add_cmd_history(std::string str); void next_cmd_history_idx(); void prev_cmd_history_idx(); void reset_cmd_history_idx(); @@ -189,12 +181,12 @@ class ENGINE_API CConsole : public pureRender, void check_prev_selected_tip(); void reset_selected_tip(); - IConsole_Command* find_next_cmd(LPCSTR in_str, shared_str& out_str); + IConsole_Command* find_next_cmd(LPCSTR in_str, std::string& out_str); bool add_next_cmds(LPCSTR in_str, vecTipsEx& out_v); bool add_internal_cmds(LPCSTR in_str, vecTipsEx& out_v); void update_tips(); - void select_for_filter(LPCSTR filter_str, vecTips& in_v, vecTipsEx& out_v); + void select_for_filter(const char* filter_str, vecTips& in_v, vecTipsEx& out_v) const; }; // class CConsole diff --git a/code/engine/xrEngine/XR_IOConsole_callback.cpp b/code/engine/xrEngine/XR_IOConsole_callback.cpp index bcf4f5204..c83f2a457 100644 --- a/code/engine/xrEngine/XR_IOConsole_callback.cpp +++ b/code/engine/xrEngine/XR_IOConsole_callback.cpp @@ -68,11 +68,11 @@ void CConsole::End_log() // PAGE_DOWN+Ctrl void CConsole::Find_cmd() // DIK_TAB { - shared_str out_str; + std::string out_str; IConsole_Command* cc = find_next_cmd(ec().str_edit(), out_str); - if (cc && out_str.size()) { - ec().set_edit(out_str.c_str()); + if (cc && !out_str.empty()) { + ec().set_edit(out_str.c_str()); // TODO: [imdex] use string_view } } @@ -153,14 +153,14 @@ void CConsole::PageDown_tips() { void CConsole::Execute_cmd() // DIK_RETURN, DIK_NUMPADENTER { if (0 <= m_select_tip && m_select_tip < (int)m_tips.size()) { - shared_str const& str = m_tips[m_select_tip].text; + const auto& str = m_tips[m_select_tip].text; if (m_tips_mode == 1) { LPSTR buf; - STRCONCAT(buf, str.c_str(), " "); + STRCONCAT(buf, str.c_str(), " "); // TODO: [imdex] use string_view ec().set_edit(buf); } else if (m_tips_mode == 2) { LPSTR buf; - STRCONCAT(buf, m_cur_cmd.c_str(), " ", str.c_str()); + STRCONCAT(buf, m_cur_cmd.c_str(), " ", str.c_str()); // TODO: [imdex] use string_view ec().set_edit(buf); } reset_selected_tip(); diff --git a/code/engine/xrEngine/XR_IOConsole_control.cpp b/code/engine/xrEngine/XR_IOConsole_control.cpp index a3756de64..02f46df30 100644 --- a/code/engine/xrEngine/XR_IOConsole_control.cpp +++ b/code/engine/xrEngine/XR_IOConsole_control.cpp @@ -8,11 +8,11 @@ #include "stdafx.h" #include "XR_IOConsole.h" -void CConsole::add_cmd_history(shared_str const& str) { - if (str.size() == 0) { +void CConsole::add_cmd_history(std::string str) { + if (str.empty()) { return; } - m_cmd_history.push_back(str); + m_cmd_history.push_back(std::move(str)); if (m_cmd_history.size() > m_cmd_history_max) { m_cmd_history.erase(m_cmd_history.begin()); } diff --git a/code/engine/xrEngine/editor_environment_ambients_ambient.hpp b/code/engine/xrEngine/editor_environment_ambients_ambient.hpp index e80ddaf4a..937fde7e4 100644 --- a/code/engine/xrEngine/editor_environment_ambients_ambient.hpp +++ b/code/engine/xrEngine/editor_environment_ambients_ambient.hpp @@ -6,8 +6,7 @@ // Description : editor environment ambients ambient class //////////////////////////////////////////////////////////////////////////// -#ifndef EDITOR_WEATHER_AMBIENTS_AMBIENT_HPP_INCLUDED -#define EDITOR_WEATHER_AMBIENTS_AMBIENT_HPP_INCLUDED +#pragma once #ifdef INGAME_EDITOR @@ -33,7 +32,6 @@ class effect_id; class sound_id; class ambient : public CEnvAmbient, public editor::property_holder_holder { -private: typedef CEnvAmbient inherited; public: @@ -88,6 +86,4 @@ class ambient : public CEnvAmbient, public editor::property_holder_holder { } // namespace environment } // namespace editor -#endif // #ifdef INGAME_EDITOR - -#endif // ifndef EDITOR_WEATHER_AMBIENTS_AMBIENT_HPP_INCLUDED \ No newline at end of file +#endif // #ifdef INGAME_EDITOR \ No newline at end of file diff --git a/code/engine/xrEngine/property_collection.hpp b/code/engine/xrEngine/property_collection.hpp index d740b05c4..91b5532fa 100644 --- a/code/engine/xrEngine/property_collection.hpp +++ b/code/engine/xrEngine/property_collection.hpp @@ -6,8 +6,7 @@ // Description : property collection template class //////////////////////////////////////////////////////////////////////////// -#ifndef PROPERTY_COLLECTION_HPP_INCLUDED -#define PROPERTY_COLLECTION_HPP_INCLUDED +#pragma once #include "editor/property_holder.hpp" #include "../xrServerEntities/object_broker.h" @@ -39,7 +38,7 @@ class property_collection : public editor::property_holder_collection { public: bool unique_id(LPCSTR id) const; - shared_str generate_unique_id(LPCSTR prefix) const; + std::string generate_unique_id(const std::string_view prefix) const; private: inline void make_state_changed(); @@ -66,6 +65,4 @@ class property_collection : public editor::property_holder_collection { bool* m_changed; }; // class property_collection -#include "property_collection_inline.hpp" - -#endif // #ifndef PROPERTY_COLLECTION_HPP_INCLUDED \ No newline at end of file +#include "property_collection_inline.hpp" \ No newline at end of file diff --git a/code/engine/xrEngine/property_collection_inline.hpp b/code/engine/xrEngine/property_collection_inline.hpp index cf9f82dc7..182cc5899 100644 --- a/code/engine/xrEngine/property_collection_inline.hpp +++ b/code/engine/xrEngine/property_collection_inline.hpp @@ -6,8 +6,7 @@ // Description : property collection template class inline functions //////////////////////////////////////////////////////////////////////////// -#ifndef PROPERTY_COLLECTION_INLINE_HPP_INCLUDED -#define PROPERTY_COLLECTION_INLINE_HPP_INCLUDED +#pragma once #define SPECIALIZATION template #define PROPERTY_COLLECTION property_collection @@ -109,19 +108,15 @@ bool PROPERTY_COLLECTION::unique_id(LPCSTR id) const { } SPECIALIZATION -shared_str PROPERTY_COLLECTION::generate_unique_id(LPCSTR prefix) const { - for (u32 i = 0;; ++i) { - string_path result; - xr_strcpy(result, prefix); +std::string PROPERTY_COLLECTION::generate_unique_id(const std::string_view prefix) const { + for (size_t i = 0;; ++i) { + XrWriterAs writer; + writer.write("{0}{1}", prefix, i); - string_path number; - R_ASSERT(!_itoa_s(i, number, 10)); - xr_strcat(result, number); - - if (!unique_id(result)) + if (!unique_id(writer.c_str())) continue; - return (result); + return writer.str(); } } @@ -134,6 +129,4 @@ inline void PROPERTY_COLLECTION::make_state_changed() { } #undef PROPERTY_COLLECTION -#undef SPECIALIZATION - -#endif // #ifndef PROPERTY_COLLECTION_INLINE_HPP_INCLUDED \ No newline at end of file +#undef SPECIALIZATION \ No newline at end of file diff --git a/code/engine/xrEngine/xr_ioc_cmd.cpp b/code/engine/xrEngine/xr_ioc_cmd.cpp index 40538c8a4..5b47105b5 100644 --- a/code/engine/xrEngine/xr_ioc_cmd.cpp +++ b/code/engine/xrEngine/xr_ioc_cmd.cpp @@ -15,19 +15,19 @@ #include "xr_object.h" -xr_token* vid_quality_token = NULL; +xr_token* vid_quality_token = nullptr; xr_token vid_bpp_token[] = { { "16", 16 }, { "32", 32 }, { 0, 0 } }; //----------------------------------------------------------------------- -void IConsole_Command::add_to_LRU(shared_str const& arg) { - if (arg.size() == 0 || bEmptyArgsHandled) { +void IConsole_Command::add_to_LRU(std::string arg) { + if (arg.empty() || bEmptyArgsHandled) { return; } - bool dup = (std::find(m_LRU.begin(), m_LRU.end(), arg) != m_LRU.end()); + const bool dup = std::find(m_LRU.begin(), m_LRU.end(), arg) != m_LRU.end(); if (!dup) { - m_LRU.push_back(arg); + m_LRU.push_back(std::move(arg)); if (m_LRU.size() > LRU_MAX_COUNT) { m_LRU.erase(m_LRU.begin()); } @@ -35,10 +35,9 @@ void IConsole_Command::add_to_LRU(shared_str const& arg) { } void IConsole_Command::add_LRU_to_tips(vecTips& tips) { - vecLRU::reverse_iterator it_rb = m_LRU.rbegin(); - vecLRU::reverse_iterator it_re = m_LRU.rend(); - for (; it_rb != it_re; ++it_rb) { - tips.push_back((*it_rb)); + tips.reserve(m_LRU.size()); + for (auto it_rb = m_LRU.rbegin(); it_rb != m_LRU.rend(); ++it_rb) { + tips.push_back(*it_rb); } } @@ -354,7 +353,7 @@ class CCC_VidMode : public CCC_Token { psCurrentVidMode[0] = _w; psCurrentVidMode[1] = _h; } else { - Msg("! Wrong video mode [%s]", args); + LogMsg("! Wrong video mode [{}]", args); return; } } diff --git a/code/engine/xrEngine/xr_ioc_cmd.h b/code/engine/xrEngine/xr_ioc_cmd.h index a27d02a53..49e532815 100644 --- a/code/engine/xrEngine/xr_ioc_cmd.h +++ b/code/engine/xrEngine/xr_ioc_cmd.h @@ -31,8 +31,8 @@ class ENGINE_API IConsole_Command { friend class CConsole; typedef char TInfo[256]; typedef char TStatus[256]; - typedef xr_vector vecTips; - typedef xr_vector vecLRU; + typedef xr_vector vecTips; + typedef xr_vector vecLRU; protected: LPCSTR cName; @@ -42,13 +42,13 @@ class ENGINE_API IConsole_Command { vecLRU m_LRU; - enum { LRU_MAX_COUNT = 10 }; + static constexpr size_t LRU_MAX_COUNT = 10; - IC bool EQ(LPCSTR S1, LPCSTR S2) { return xr_strcmp(S1, S2) == 0; } + bool EQ(LPCSTR S1, LPCSTR S2) { return xr_strcmp(S1, S2) == 0; } public: IConsole_Command(LPCSTR N BENCH_SEC_SIGN) - : cName(N), bEnabled(TRUE), bLowerCaseArgs(TRUE), bEmptyArgsHandled(FALSE) { + : cName(N), bEnabled(true), bLowerCaseArgs(true), bEmptyArgsHandled(false) { m_LRU.reserve(LRU_MAX_COUNT + 1); m_LRU.clear(); } @@ -80,7 +80,7 @@ class ENGINE_API IConsole_Command { virtual void fill_tips(vecTips& tips, u32 mode) { add_LRU_to_tips(tips); } // vecLRU& LRU () { return m_LRU; } - virtual void add_to_LRU(shared_str const& arg); + virtual void add_to_LRU(std::string arg); void add_LRU_to_tips(vecTips& tips); }; // class IConsole_Command diff --git a/code/engine/xrGame/ActorCondition.cpp b/code/engine/xrGame/ActorCondition.cpp index 46a9000f1..e2bc0fd99 100644 --- a/code/engine/xrGame/ActorCondition.cpp +++ b/code/engine/xrGame/ActorCondition.cpp @@ -239,11 +239,13 @@ void CActorCondition::UpdateCondition() { } string512 pp_sect_name; - shared_str ln = Level().name(); - if (ln.size()) { + // TODO: [imdex] use string_view + const auto& ln = Level().name(); + if (!ln.empty()) { CEffectorPP* ppe = object().Cameras().GetPPEffector((EEffectorPPType)effPsyHealth); - strconcat(sizeof(pp_sect_name), pp_sect_name, "effector_psy_health", "_", *ln); + // TODO: [imdex] use string_view + strconcat(sizeof(pp_sect_name), pp_sect_name, "effector_psy_health", "_", ln.c_str()); if (!pSettings->section_exist(pp_sect_name)) xr_strcpy(pp_sect_name, "effector_psy_health"); diff --git a/code/engine/xrGame/DemoInfo.cpp b/code/engine/xrGame/DemoInfo.cpp index 30e272156..63904327a 100644 --- a/code/engine/xrGame/DemoInfo.cpp +++ b/code/engine/xrGame/DemoInfo.cpp @@ -91,7 +91,8 @@ void demo_info::sort_players(sorting_less_comparator sorting_comparator) { } void demo_info::load_from_game() { - m_map_name = Level().name(); + // TODO: [imdex] remove shared_str + m_map_name = shared_str(Level().name().c_str()); m_map_version = Level().version(); m_game_type = GameTypeToString(Game().Type(), true); m_game_score = ""; diff --git a/code/engine/xrGame/Level.cpp b/code/engine/xrGame/Level.cpp index eb1fcdd7b..dcbd9cc50 100644 --- a/code/engine/xrGame/Level.cpp +++ b/code/engine/xrGame/Level.cpp @@ -274,7 +274,7 @@ CLevel::~CLevel() { deinit_compression(); } -shared_str CLevel::name() const { return (map_data.m_name); } +const std::string& CLevel::name() const { return map_data.m_name; } void CLevel::GetLevelInfo(CServerInfo* si) { if (Server && game) { diff --git a/code/engine/xrGame/Level.h b/code/engine/xrGame/Level.h index 06910947d..dc3e6a276 100644 --- a/code/engine/xrGame/Level.h +++ b/code/engine/xrGame/Level.h @@ -300,7 +300,7 @@ class CLevel : public IGame_Level, public IPureClient { virtual ~CLevel(); //названияе текущего уровня - virtual shared_str name() const; + virtual const std::string& name() const; shared_str version() const { return map_data.m_map_version.c_str(); } // this method can be used ONLY from CCC_ChangeGameType diff --git a/code/engine/xrGame/Level_network_map_sync.cpp b/code/engine/xrGame/Level_network_map_sync.cpp index 832f41a8e..44d57c166 100644 --- a/code/engine/xrGame/Level_network_map_sync.cpp +++ b/code/engine/xrGame/Level_network_map_sync.cpp @@ -9,7 +9,7 @@ static const u32 r_buffer_size = 131072; // 128 Kb void CLevel::CalculateLevelCrc32() { void* read_buffer = _alloca(r_buffer_size); - Msg("* calculating checksum of level.geom"); + Log("* calculating checksum of level.geom"); CStreamReader* geom = FS.rs_open("$level$", "level.geom"); R_ASSERT2(geom, "failed to open level.geom file"); u32 remaind = geom->elapsed(); diff --git a/code/engine/xrGame/Level_network_map_sync.h b/code/engine/xrGame/Level_network_map_sync.h index 39aefa3db..15a344c00 100644 --- a/code/engine/xrGame/Level_network_map_sync.h +++ b/code/engine/xrGame/Level_network_map_sync.h @@ -1,13 +1,12 @@ -#ifndef LEVEL_NETWORK_MAP_SYNC_H -#define LEVEL_NETWORK_MAP_SYNC_H +#pragma once struct LevelMapSyncData { bool m_sended_map_name_request; bool m_map_sync_received; bool m_map_loaded; - shared_str m_name; // map name that currently loaded - shared_str m_map_version; // map version that currently loaded - shared_str m_map_download_url; + std::string m_name; // map name that currently loaded + std::string m_map_version; // map version that currently loaded + std::string m_map_download_url; u32 m_level_geom_crc32; u32 m_wait_map_time; @@ -31,6 +30,4 @@ struct LevelMapSyncData { inline bool IsInvalidMapOrVersion() { return invalid_map_or_version; } inline bool IsInvalidClientChecksum() { return invalid_geom_checksum; } -}; // class LevelMapSyncData - -#endif \ No newline at end of file +}; // class LevelMapSyncData \ No newline at end of file diff --git a/code/engine/xrGame/Level_network_start_client.cpp b/code/engine/xrGame/Level_network_start_client.cpp index a8118680b..0bb9e689b 100644 --- a/code/engine/xrGame/Level_network_start_client.cpp +++ b/code/engine/xrGame/Level_network_start_client.cpp @@ -61,20 +61,24 @@ bool CLevel::net_start_client2() { bool CLevel::net_start_client3() { if (connected_to_server) { - LPCSTR level_name = NULL; - LPCSTR level_ver = NULL; - LPCSTR download_url = NULL; + LPCSTR level_name = ""; + LPCSTR level_ver = ""; + LPCSTR download_url = ""; shared_str const& server_options = Server->GetConnectOptions(); + // TODO: [imdex] remove shared_str level_name = name().c_str(); // Server->level_name (server_options).c_str(); + level_name = level_name ? level_name : ""; + // TODO: [imdex] remove shared_str level_ver = Server->level_version(server_options).c_str(); // 1.0 + level_ver = level_ver ? level_ver : ""; // Determine internal level-ID int level_id = pApp->Level_ID(level_name, level_ver, true); if (level_id == -1) { Disconnect(); connected_to_server = FALSE; - Msg("! Level (name:%s), (version:%s), not found, try to download from:%s", level_name, + LogMsg("! Level (name:{0}), (version:{1}), not found, try to download from:{2}", level_name, level_ver, download_url); map_data.m_name = level_name; map_data.m_map_version = level_ver; @@ -83,7 +87,7 @@ bool CLevel::net_start_client3() { return false; } #ifdef DEBUG - Msg("--- net_start_client3: level_id [%d], level_name[%s], level_version[%s]", level_id, + LogMsg("--- net_start_client3: level_id [{0}], level_name[{1}], level_version[{2}]", level_id, level_name, level_ver); #endif // #ifdef DEBUG map_data.m_name = level_name; diff --git a/code/engine/xrGame/Level_start.cpp b/code/engine/xrGame/Level_start.cpp index ff43024b8..8ebc7c9c6 100644 --- a/code/engine/xrGame/Level_start.cpp +++ b/code/engine/xrGame/Level_start.cpp @@ -105,7 +105,8 @@ bool CLevel::net_start1() { map_data.m_name = game_sv_GameState::parse_level_name(m_caServerOptions); - g_pGamePersistent->LoadTitle(true, map_data.m_name); + // TODO: [imdex] remove shared_str + g_pGamePersistent->LoadTitle(true, shared_str(map_data.m_name.c_str())); int id = pApp->Level_ID(map_data.m_name.c_str(), l_ver.c_str(), true); @@ -127,12 +128,12 @@ bool CLevel::net_start2() { if ((m_connect_server_err = Server->Connect(m_caServerOptions, game_descr)) != xrServer::ErrNoError) { net_start_result_total = false; - Msg("! Failed to start server."); + Log("! Failed to start server."); return true; } Server->SLS_Default(); map_data.m_name = Server->level_name(m_caServerOptions); - g_pGamePersistent->LoadTitle(true, map_data.m_name); + g_pGamePersistent->LoadTitle(true, shared_str(map_data.m_name.c_str())); } return true; } @@ -229,12 +230,13 @@ bool CLevel::net_start6() { m_bConnectResult) // if (map_data.m_name == "") - level not loaded, see // CLevel::net_start_client3 { - LPCSTR level_id_string = NULL; - LPCSTR dialog_string = NULL; - LPCSTR download_url = - !!map_data.m_map_download_url ? map_data.m_map_download_url.c_str() : ""; + LPCSTR level_id_string = nullptr; + LPCSTR dialog_string = nullptr; + // TODO: [imdex] use string_view + LPCSTR download_url = map_data.m_map_download_url.c_str(); CStringTable st; - LPCSTR tmp_map_ver = !!map_data.m_map_version ? map_data.m_map_version.c_str() : ""; + // TODO: [imdex] use string_view + LPCSTR tmp_map_ver = map_data.m_map_version.c_str(); STRCONCAT(level_id_string, st.translate("st_level"), ":", map_data.m_name.c_str(), "(", tmp_map_ver, "). "); @@ -246,12 +248,13 @@ bool CLevel::net_start6() { MainMenu()->SwitchToMultiplayerMenu(); MainMenu()->Show_DownloadMPMap(dialog_string, download_url); } else if (map_data.IsInvalidClientChecksum()) { - LPCSTR level_id_string = NULL; - LPCSTR dialog_string = NULL; - LPCSTR download_url = - !!map_data.m_map_download_url ? map_data.m_map_download_url.c_str() : ""; + LPCSTR level_id_string = nullptr; + LPCSTR dialog_string = nullptr; + // TODO: [imdex] use string_view + LPCSTR download_url = map_data.m_map_download_url.c_str(); CStringTable st; - LPCSTR tmp_map_ver = !!map_data.m_map_version ? map_data.m_map_version.c_str() : ""; + // TODO: [imdex] use string_view + LPCSTR tmp_map_ver = map_data.m_map_version.c_str(); STRCONCAT(level_id_string, st.translate("st_level"), ":", map_data.m_name.c_str(), "(", tmp_map_ver, "). "); diff --git a/code/engine/xrGame/Torch.cpp b/code/engine/xrGame/Torch.cpp index 445e450d1..05afa8995 100644 --- a/code/engine/xrGame/Torch.cpp +++ b/code/engine/xrGame/Torch.cpp @@ -100,7 +100,8 @@ void CTorch::SwitchNightVision(bool vision_on, bool use_sounds) { m_night_vision = xr_new(cNameSect()); LPCSTR disabled_names = pSettings->r_string(cNameSect(), "disabled_maps"); - LPCSTR curr_map = *Level().name(); + // TODO: [imdex] use string_view + LPCSTR curr_map = Level().name().c_str(); u32 cnt = _GetItemCount(disabled_names); bool b_allow = true; string512 tmp; diff --git a/code/engine/xrGame/alife_graph_registry.cpp b/code/engine/xrGame/alife_graph_registry.cpp index efd019f9e..7ec579747 100644 --- a/code/engine/xrGame/alife_graph_registry.cpp +++ b/code/engine/xrGame/alife_graph_registry.cpp @@ -82,9 +82,11 @@ void CALifeGraphRegistry::setup_current_level() { ai().game_graph().vertex(actor()->m_tGraphID)->level_id()); R_ASSERT2(ai().game_graph().header().levels().end() != I, "Graph point level ID not found!"); - int id = pApp->Level_ID(*(*I).second.name(), "1.0", true); + // TODO: [imdex] use string_view + int id = pApp->Level_ID((*I).second.name().c_str(), "1.0", true); VERIFY3(id >= 0, "Level is corrupted or doesn't exist", *(*I).second.name()); - ai().load(*(*I).second.name()); + // TODO: [imdex] use string_view + ai().load((*I).second.name().c_str()); } void CALifeGraphRegistry::attach(CSE_Abstract& object, CSE_ALifeInventoryItem* item, diff --git a/code/engine/xrGame/alife_simulator_base.cpp b/code/engine/xrGame/alife_simulator_base.cpp index db1d2f077..a8dc80c0e 100644 --- a/code/engine/xrGame/alife_simulator_base.cpp +++ b/code/engine/xrGame/alife_simulator_base.cpp @@ -345,6 +345,6 @@ void CALifeSimulatorBase::assign_death_position(CSE_ALifeCreatureAbstract* tpALi l_tpALifeMonsterAbstract->m_tGraphID; } -shared_str CALifeSimulatorBase::level_name() const { - return (ai().game_graph().header().level(ai().level_graph().level_id()).name()); +const std::string& CALifeSimulatorBase::level_name() const { + return ai().game_graph().header().level(ai().level_graph().level_id()).name(); } diff --git a/code/engine/xrGame/alife_simulator_base.h b/code/engine/xrGame/alife_simulator_base.h index 43bde7131..85dea07ab 100644 --- a/code/engine/xrGame/alife_simulator_base.h +++ b/code/engine/xrGame/alife_simulator_base.h @@ -118,7 +118,7 @@ class CALifeSimulatorBase : public IPureDestroyableObject { GameGraph::_GRAPH_ID game_vertex_id, u16 parent_id, bool registration = true); void append_item_vector(ALife::OBJECT_VECTOR& tObjectVector, ALife::ITEM_P_VECTOR& tItemList); - shared_str level_name() const; + const std::string& level_name() const; void on_death(CSE_Abstract* killed, CSE_Abstract* killer); public: diff --git a/code/engine/xrGame/alife_simulator_script.cpp b/code/engine/xrGame/alife_simulator_script.cpp index 0ae8195e2..854e9a040 100644 --- a/code/engine/xrGame/alife_simulator_script.cpp +++ b/code/engine/xrGame/alife_simulator_script.cpp @@ -266,8 +266,8 @@ void CALifeSimulator__release(CALifeSimulator* self, CSE_Abstract* object, bool) } LPCSTR get_level_name(const CALifeSimulator* self, int level_id) { - LPCSTR result = *ai().game_graph().header().level((GameGraph::_LEVEL_ID)level_id).name(); - return (result); + // TODO: [imdex] use string_view + return ai().game_graph().header().level((GameGraph::_LEVEL_ID)level_id).name().c_str(); } CSE_ALifeCreatureActor* get_actor(const CALifeSimulator* self) { diff --git a/code/engine/xrGame/alife_update_manager.cpp b/code/engine/xrGame/alife_update_manager.cpp index 93918f96a..2a92c50cb 100644 --- a/code/engine/xrGame/alife_update_manager.cpp +++ b/code/engine/xrGame/alife_update_manager.cpp @@ -251,11 +251,12 @@ void CALifeUpdateManager::load(LPCSTR game_name, bool no_assert, bool new_only) Level().OnAlifeSimulatorLoaded(); #ifdef DEBUG - Msg("* Loading alife simulator is successfully completed (%7.3f Mb)", + LogMsg("* Loading alife simulator is successfully completed ({:7.3f} Mb)", float(Memory.mem_usage() - memory_usage) / 1048576.0); #endif // g_pGamePersistent->LoadTitle ("st_server_connecting"); - g_pGamePersistent->LoadTitle(true, g_pGameLevel->name()); + // TODO: [imdex] remove shared_str + g_pGamePersistent->LoadTitle(true, shared_str(g_pGameLevel->name().c_str())); } void CALifeUpdateManager::reload(LPCSTR section) { diff --git a/code/engine/xrGame/console_commands.cpp b/code/engine/xrGame/console_commands.cpp index a5f8bce42..05c32ecda 100644 --- a/code/engine/xrGame/console_commands.cpp +++ b/code/engine/xrGame/console_commands.cpp @@ -454,7 +454,7 @@ bool valid_saved_game_name(LPCSTR file_name) { return (true); } -void get_files_list(xr_vector& files, LPCSTR dir, LPCSTR file_ext) { +void get_files_list(xr_vector& files, LPCSTR dir, LPCSTR file_ext) { VERIFY(dir && file_ext); files.clear(); @@ -1080,14 +1080,13 @@ struct CCC_JumpToLevel : public IConsole_Command { return; } - GameGraph::LEVEL_MAP::const_iterator I = ai().game_graph().header().levels().begin(); - GameGraph::LEVEL_MAP::const_iterator E = ai().game_graph().header().levels().end(); - for (; I != E; ++I) - if (!xr_strcmp((*I).second.name(), level)) { + for (const auto& I : ai().game_graph().header().levels()) { + if (I.second.name() == level) { ai().alife().jump_to_level(level); return; } - Msg("! There is no level \"%s\" in the game graph!", level); + } + LogMsg(R"(! There is no level "{}" in the game graph!)", level); } virtual void Save(IWriter* F){} @@ -1097,10 +1096,8 @@ struct CCC_JumpToLevel : public IConsole_Command { return; } - GameGraph::LEVEL_MAP::const_iterator itb = ai().game_graph().header().levels().begin(); - GameGraph::LEVEL_MAP::const_iterator ite = ai().game_graph().header().levels().end(); - for (; itb != ite; ++itb) { - tips.push_back((*itb).second.name()); + for (const auto& level : ai().game_graph().header().levels()) { + tips.push_back(std::string(level.second.name())); } } }; diff --git a/code/engine/xrGame/game_graph_inline.h b/code/engine/xrGame/game_graph_inline.h index 15055b51a..d8ed90018 100644 --- a/code/engine/xrGame/game_graph_inline.h +++ b/code/engine/xrGame/game_graph_inline.h @@ -124,14 +124,13 @@ IC const GameGraph::SLevel& GameGraph::CHeader::level(const _LEVEL_ID& id) const } IC const GameGraph::SLevel& GameGraph::CHeader::level(LPCSTR level_name) const { - LEVEL_MAP::const_iterator I = levels().begin(); - LEVEL_MAP::const_iterator E = levels().end(); - for (; I != E; ++I) - if (!xr_strcmp((*I).second.name(), level_name)) - return ((*I).second); + for (const auto& l : levels()) { + if (l.second.name() == level_name) + return l.second; + } #ifdef DEBUG - Msg("! There is no specified level %s in the game graph!", level_name); + LogMsg("! There is no specified level {} in the game graph!", level_name); return (levels().begin()->second); #else R_ASSERT3(false, "There is no specified level in the game graph!", level_name); @@ -140,13 +139,11 @@ IC const GameGraph::SLevel& GameGraph::CHeader::level(LPCSTR level_name) const { } IC const GameGraph::SLevel* GameGraph::CHeader::level(LPCSTR level_name, bool) const { - LEVEL_MAP::const_iterator I = levels().begin(); - LEVEL_MAP::const_iterator E = levels().end(); - for (; I != E; ++I) - if (!xr_strcmp((*I).second.name(), level_name)) - return (&(*I).second); - - return (0); + for (const auto& l : levels()) { + if (l.second.name() == level_name) + return &(l.second); + } + return nullptr; } IC const xrGUID& CGameGraph::CHeader::guid() const { return (m_guid); } diff --git a/code/engine/xrGame/game_sv_base.cpp b/code/engine/xrGame/game_sv_base.cpp index 0a10659e9..6c374075d 100644 --- a/code/engine/xrGame/game_sv_base.cpp +++ b/code/engine/xrGame/game_sv_base.cpp @@ -871,7 +871,7 @@ void game_sv_GameState::SaveMapList() { FS.w_close(fs); }; -shared_str game_sv_GameState::level_name(const shared_str& server_options) const { +std::string game_sv_GameState::level_name(const shared_str& server_options) const { return parse_level_name(server_options); } @@ -893,10 +893,10 @@ shared_str game_sv_GameState::parse_level_version(const shared_str& server_optio return shared_str(result_version); } -shared_str game_sv_GameState::parse_level_name(const shared_str& server_options) { +std::string game_sv_GameState::parse_level_name(const shared_str& server_options) { string64 l_name = ""; VERIFY(_GetItemCount(*server_options, '/')); - return (_GetItem(*server_options, 0, l_name, '/')); + return _GetItem(*server_options, 0, l_name, '/'); } void game_sv_GameState::on_death(CSE_Abstract* e_dest, CSE_Abstract* e_src) { diff --git a/code/engine/xrGame/game_sv_base.h b/code/engine/xrGame/game_sv_base.h index 238d23df8..45686a446 100644 --- a/code/engine/xrGame/game_sv_base.h +++ b/code/engine/xrGame/game_sv_base.h @@ -188,9 +188,9 @@ class game_sv_GameState : public game_GameState { virtual void remove_all_restrictions(NET_Packet& packet, u16 id); virtual bool custom_sls_default() { return false; }; virtual void sls_default(){}; - virtual shared_str level_name(const shared_str& server_options) const; + virtual std::string level_name(const shared_str& server_options) const; - static shared_str parse_level_name(const shared_str& server_options); + static std::string parse_level_name(const shared_str& server_options); static shared_str parse_level_version(const shared_str& server_options); virtual void on_death(CSE_Abstract* e_dest, CSE_Abstract* e_src); diff --git a/code/engine/xrGame/game_sv_single.cpp b/code/engine/xrGame/game_sv_single.cpp index 339102a70..b537f7449 100644 --- a/code/engine/xrGame/game_sv_single.cpp +++ b/code/engine/xrGame/game_sv_single.cpp @@ -288,10 +288,10 @@ void game_sv_Single::remove_all_restrictions(NET_Packet& packet, u16 id) { void game_sv_Single::sls_default() { alife().update_switch(); } -shared_str game_sv_Single::level_name(const shared_str& server_options) const { +std::string game_sv_Single::level_name(const shared_str& server_options) const { if (!ai().get_alife()) return (inherited::level_name(server_options)); - return (alife().level_name()); + return alife().level_name(); } void game_sv_Single::on_death(CSE_Abstract* e_dest, CSE_Abstract* e_src) { diff --git a/code/engine/xrGame/game_sv_single.h b/code/engine/xrGame/game_sv_single.h index 6558b47d4..33e6ec621 100644 --- a/code/engine/xrGame/game_sv_single.h +++ b/code/engine/xrGame/game_sv_single.h @@ -47,7 +47,7 @@ class game_sv_Single : public game_sv_GameState { virtual void remove_all_restrictions(NET_Packet& packet, u16 id); virtual bool custom_sls_default() { return !!m_alife_simulator; }; virtual void sls_default(); - virtual shared_str level_name(const shared_str& server_options) const; + virtual std::string level_name(const shared_str& server_options) const; virtual void on_death(CSE_Abstract* e_dest, CSE_Abstract* e_src); void restart_simulator(LPCSTR saved_game_name); diff --git a/code/engine/xrGame/level_script.cpp b/code/engine/xrGame/level_script.cpp index 9d59568d4..0aa8cd728 100644 --- a/code/engine/xrGame/level_script.cpp +++ b/code/engine/xrGame/level_script.cpp @@ -246,7 +246,8 @@ bool patrol_path_exists(LPCSTR patrol_path) { return (!!ai().patrol_paths().path(patrol_path, true)); } -LPCSTR get_name() { return (*Level().name()); } +// TODO: [imdex] use string_view +LPCSTR get_name() { return Level().name().c_str(); } void prefetch_sound(LPCSTR name) { Level().PrefetchSound(name); } diff --git a/code/engine/xrGame/level_sounds.cpp b/code/engine/xrGame/level_sounds.cpp index 8af2ae883..12b0f95c6 100644 --- a/code/engine/xrGame/level_sounds.cpp +++ b/code/engine/xrGame/level_sounds.cpp @@ -140,9 +140,12 @@ void CLevelSoundManager::Load() { CInifile& gameLtx = *pGameIni; - if (gameLtx.section_exist(Level().name())) { - if (gameLtx.line_exist(Level().name(), "music_tracks")) { - LPCSTR music_sect = gameLtx.r_string(Level().name(), "music_tracks"); + // TODO: [imdex] use string_view + if (gameLtx.section_exist(Level().name().c_str())) { + // TODO: [imdex] use string_view + if (gameLtx.line_exist(Level().name().c_str(), "music_tracks")) { + // TODO: [imdex] use string_view + LPCSTR music_sect = gameLtx.r_string(Level().name().c_str(), "music_tracks"); if (music_sect && music_sect[0]) { #ifdef DEBUG Msg("- Loading music tracks from '%s'...", music_sect); diff --git a/code/engine/xrGame/map_location.cpp b/code/engine/xrGame/map_location.cpp index c5c0acbbc..9fa6980ee 100644 --- a/code/engine/xrGame/map_location.cpp +++ b/code/engine/xrGame/map_location.cpp @@ -395,28 +395,28 @@ void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp) { //} static bool bbb = false; if (!bDone && bbb) { - Msg("! Error. Path from actor to selected map spot does not contain level changer " + Log("! Error. Path from actor to selected map spot does not contain level changer " ":("); - Msg("Path:"); + Log("Path:"); xr_vector::iterator it = map_point_path.begin(); xr_vector::iterator it_e = map_point_path.end(); for (; it != it_e; ++it) { // Msg("%d-%s",(*it),ai().game_graph().vertex(*it)); - Msg("[%d] level[%s]", (*it), - *ai().game_graph() + LogMsg("[{0}] level[{1}]", (*it), + ai().game_graph() .header() .level(ai().game_graph().vertex(*it)->level_id()) .name()); } - Msg("- Available LevelChangers:"); + Log("- Available LevelChangers:"); xr_vector::iterator lit, lit_e; lit_e = g_lchangers.end(); for (lit = g_lchangers.begin(); lit != lit_e; ++lit) { GameGraph::_GRAPH_ID gid = (*lit)->ai_location().game_vertex_id(); - Msg("[%d]", gid); + LogMsg("[{}]", gid); Fvector p = ai().game_graph().vertex(gid)->level_point(); - Msg("lch_name=%s pos=%f %f %f", - *ai().game_graph() + LogMsg("lch_name={0} pos={1} {2} {3}", + ai().game_graph() .header() .level(ai().game_graph().vertex(gid)->level_id()) .name(), @@ -432,7 +432,7 @@ void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp) { xr_vector::reverse_iterator it = map_point_path.rbegin(); xr_vector::reverse_iterator it_e = map_point_path.rend(); for (; (it != it_e) && (!bDone); ++it) { - if (*ai().game_graph() + if (ai().game_graph() .header() .level(ai().game_graph().vertex(*it)->level_id()) .name() == Level().name()) diff --git a/code/engine/xrGame/map_location.h b/code/engine/xrGame/map_location.h index b69f2cc50..09ecfe830 100644 --- a/code/engine/xrGame/map_location.h +++ b/code/engine/xrGame/map_location.h @@ -54,7 +54,7 @@ class CMapLocation : public IPureDestroyableObject { GameGraph::_GRAPH_ID m_graphID; Fvector2 m_Position; Fvector2 m_Direction; - shared_str m_LevelName; + std::string m_LevelName; bool m_Actuality; }; SCachedValues m_cached; @@ -95,7 +95,7 @@ class CMapLocation : public IPureDestroyableObject { void CalcPosition(); const Fvector2& CalcDirection(); - IC const shared_str& GetLevelName() { return m_cached.m_LevelName; } + const std::string& GetLevelName() { return m_cached.m_LevelName; } const Fvector2& GetPosition() { return m_cached.m_Position; } u16 ObjectID() { return m_objectID; } diff --git a/code/engine/xrGame/movement_manager_game.cpp b/code/engine/xrGame/movement_manager_game.cpp index d6386a3ba..2bdc5a6eb 100644 --- a/code/engine/xrGame/movement_manager_game.cpp +++ b/code/engine/xrGame/movement_manager_game.cpp @@ -24,25 +24,25 @@ #include "mt_config.h" void CMovementManager::show_game_path_info() { - Msg("! Cannot build GAME path! (object %s)", *object().cName()); - Msg("! CURRENT LEVEL : %s", *Level().name()); + LogMsg("! Cannot build GAME path! (object {})", *object().cName()); + LogMsg("! CURRENT LEVEL : {}", Level().name()); Fvector temp = ai().game_graph().vertex(object().ai_location().game_vertex_id())->level_point(); - Msg("! CURRENT game point position : [%f][%f][%f]", VPUSH(temp)); + LogMsg("! CURRENT game point position : [{0}][{1}][{2}]", VPUSH(temp)); const GameGraph::CVertex* vertex = ai().game_graph().vertex(game_dest_vertex_id()); - Msg("! TARGET LEVEL : %s", *ai().game_graph().header().level(vertex->level_id()).name()); + LogMsg("! TARGET LEVEL : {}", ai().game_graph().header().level(vertex->level_id()).name()); temp = vertex->level_point(); - Msg("! TARGET game point position : [%f][%f][%f]", VPUSH(temp)); + LogMsg("! TARGET game point position : [{0}][{1}][{2}]", VPUSH(temp)); const u8* target_vertex_type = ai().game_graph().vertex(game_dest_vertex_id())->vertex_type(); - Msg("! Target point mask [%d][%d][%d][%d]", target_vertex_type[0], target_vertex_type[1], + LogMsg("! Target point mask [{0}][{1}][{2}][{3}]", target_vertex_type[0], target_vertex_type[1], target_vertex_type[2], target_vertex_type[3]); - Msg("! Object masks (%d) :", m_location_manager->vertex_types().size()); + LogMsg("! Object masks ({}) :", m_location_manager->vertex_types().size()); typedef GameGraph::TERRAIN_VECTOR::const_iterator const_iterator; const_iterator I = m_location_manager->vertex_types().begin(); const_iterator E = m_location_manager->vertex_types().end(); for (; I != E; ++I) - Msg("! [%d][%d][%d][%d]", (*I).tMask[0], (*I).tMask[1], (*I).tMask[2], (*I).tMask[3]); + LogMsg("! [{0}][{1}][{2}][{3}]", (*I).tMask[0], (*I).tMask[1], (*I).tMask[2], (*I).tMask[3]); } void CMovementManager::process_game_path() { diff --git a/code/engine/xrGame/saved_game_wrapper.cpp b/code/engine/xrGame/saved_game_wrapper.cpp index 641af6e60..95248a776 100644 --- a/code/engine/xrGame/saved_game_wrapper.cpp +++ b/code/engine/xrGame/saved_game_wrapper.cpp @@ -150,7 +150,8 @@ CSavedGameWrapper::CSavedGameWrapper(LPCSTR saved_game_name) { { CGameGraph graph(*chunk); m_level_id = graph.vertex(object->m_tGraphID)->level_id(); - m_level_name = graph.header().level(m_level_id).name(); + // TODO: [imdex] remove shared_str + m_level_name = shared_str(graph.header().level(m_level_id).name().c_str()); } chunk->close(); diff --git a/code/engine/xrGame/ui/UIMap.cpp b/code/engine/xrGame/ui/UIMap.cpp index e04394fb8..6476ad3c2 100644 --- a/code/engine/xrGame/ui/UIMap.cpp +++ b/code/engine/xrGame/ui/UIMap.cpp @@ -18,24 +18,25 @@ CUICustomMap::CUICustomMap() { SetPointerDistance(0.0f); } -void CUICustomMap::Initialize(shared_str name, LPCSTR sh_name) { - CInifile* levelIni = NULL; +void CUICustomMap::Initialize(std::string name, LPCSTR sh_name) { + CInifile* levelIni = nullptr; if (name == g_pGameLevel->name()) levelIni = g_pGameLevel->pLevel; else { string_path map_cfg_fn; string_path fname; + // TODO: [imdex] use string_view strconcat(sizeof(fname), fname, name.c_str(), "\\level.ltx"); FS.update_path(map_cfg_fn, "$game_levels$", fname); levelIni = xr_new(map_cfg_fn); } if (levelIni->section_exist("level_map")) { - Init_internal(name, *levelIni, "level_map", sh_name); + Init_internal(std::move(name), *levelIni, "level_map", sh_name); } else { - Msg("! default LevelMap used for level[%s]", name.c_str()); + LogMsg("! default LevelMap used for level[{}]", name); Init_internal(name, *pGameIni, "def_map", sh_name); - m_name = name; + m_name = std::move(name); } if (levelIni != g_pGameLevel->pLevel) xr_delete(levelIni); @@ -57,9 +58,9 @@ void CUICustomMap::Draw() { UI().PopScissor(); } -void CUICustomMap::Init_internal(const shared_str& name, CInifile& pLtx, +void CUICustomMap::Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name) { - m_name = name; + m_name = std::move(name); Fvector4 tmp; m_texture = pLtx.r_string(sect_name, "texture"); @@ -262,11 +263,12 @@ void CUIGlobalMap::Initialize() { Init_internal("global_map", *pGameIni, "global_map", "hud\\default"); } -void CUIGlobalMap::Init_internal(const shared_str& name, CInifile& pLtx, +void CUIGlobalMap::Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name) { - inherited::Init_internal(name, pLtx, sect_name, sh_name); + inherited::Init_internal(std::move(name), pLtx, sect_name, sh_name); // Fvector2 size = CUIStatic::GetWndSize(); - SetMaxZoom(pLtx.r_float(m_name, "max_zoom")); + // TODO: [imdex] use_string_view + SetMaxZoom(pLtx.r_float(m_name.c_str(), "max_zoom")); } void CUIGlobalMap::Update() { @@ -389,10 +391,11 @@ void CUILevelMap::Draw() { inherited::Draw(); } -void CUILevelMap::Init_internal(const shared_str& name, CInifile& pLtx, const shared_str& sect_name, +void CUILevelMap::Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name) { - inherited::Init_internal(name, pLtx, sect_name, sh_name); - Fvector4 tmp = pGameIni->r_fvector4(MapName(), "global_rect"); + inherited::Init_internal(std::move(name), pLtx, sect_name, sh_name); + // TODO: [imdex] use string_view + Fvector4 tmp = pGameIni->r_fvector4(MapName().c_str(), "global_rect"); tmp.x *= UI().get_current_kx(); tmp.z *= UI().get_current_kx(); @@ -512,9 +515,9 @@ CUIMiniMap::CUIMiniMap() {} CUIMiniMap::~CUIMiniMap() {} -void CUIMiniMap::Init_internal(const shared_str& name, CInifile& pLtx, const shared_str& sect_name, +void CUIMiniMap::Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name) { - inherited::Init_internal(name, pLtx, sect_name, sh_name); + inherited::Init_internal(std::move(name), pLtx, sect_name, sh_name); CUIStatic::SetTextureColor(0x7fffffff); } diff --git a/code/engine/xrGame/ui/UIMap.h b/code/engine/xrGame/ui/UIMap.h index 9de1b9042..325717406 100644 --- a/code/engine/xrGame/ui/UIMap.h +++ b/code/engine/xrGame/ui/UIMap.h @@ -7,7 +7,7 @@ class CUIMapWnd; class CUICustomMap : public CUIStatic, public CUIWndCallback { protected: - shared_str m_name; + std::string m_name; Frect m_BoundRect_; // real map size (meters) Flags16 m_flags; @@ -28,7 +28,7 @@ class CUICustomMap : public CUIStatic, public CUIWndCallback { virtual void SetActivePoint(const Fvector& vNewPoint); - void Initialize(shared_str name, LPCSTR sh_name); + void Initialize(std::string name, LPCSTR sh_name); virtual Fvector2 ConvertRealToLocal(const Fvector2& src, bool for_drawing); // meters->pixels (relatively own left-top pos) @@ -50,8 +50,8 @@ class CUICustomMap : public CUIStatic, public CUIWndCallback { const Frect& BoundRect() const { return m_BoundRect_; } virtual void OptimalFit(const Frect& r); - const shared_str& MapName() { return m_name; } - virtual CUIGlobalMapSpot* GlobalMapSpot() { return NULL; } + const std::string& MapName() { return m_name; } + virtual CUIGlobalMapSpot* GlobalMapSpot() { return nullptr; } virtual void Draw(); virtual void Update(); @@ -64,7 +64,7 @@ class CUICustomMap : public CUIStatic, public CUIWndCallback { float GetPointerDistance() { return m_pointer_dist; }; protected: - virtual void Init_internal(const shared_str& name, CInifile& pLtx, const shared_str& sect_name, + virtual void Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name); virtual void UpdateSpots(){}; }; @@ -102,7 +102,7 @@ class CUIGlobalMap : public CUICustomMap { void Initialize(); protected: - virtual void Init_internal(const shared_str& name, CInifile& pLtx, const shared_str& sect_name, + virtual void Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name); }; @@ -132,7 +132,7 @@ class CUILevelMap : public CUICustomMap { protected: virtual void UpdateSpots(); - virtual void Init_internal(const shared_str& name, CInifile& pLtx, const shared_str& sect_name, + virtual void Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name); }; @@ -151,6 +151,6 @@ class CUIMiniMap : public CUICustomMap { protected: virtual void UpdateSpots(); - virtual void Init_internal(const shared_str& name, CInifile& pLtx, const shared_str& sect_name, + virtual void Init_internal(std::string name, CInifile& pLtx, const shared_str& sect_name, LPCSTR sh_name); }; diff --git a/code/engine/xrGame/ui/UIMapWnd.cpp b/code/engine/xrGame/ui/UIMapWnd.cpp index 31c448b4f..7d9894e87 100644 --- a/code/engine/xrGame/ui/UIMapWnd.cpp +++ b/code/engine/xrGame/ui/UIMapWnd.cpp @@ -42,20 +42,22 @@ CUIMapWnd::CUIMapWnd() { // UIMainMapHeader = NULL; m_scroll_mode = false; m_nav_timing = Device.dwTimeGlobal; - hint_wnd = NULL; + hint_wnd = nullptr; g_map_wnd = this; } CUIMapWnd::~CUIMapWnd() { delete_data(m_ActionPlanner); - delete_data(m_GameMaps); + for (auto& item : m_GameMaps) { + xr_delete(item.second); + } delete_data(m_map_location_hint); /* #ifdef DEBUG delete_data( m_dbg_text_hint ); delete_data( m_dbg_info ); #endif // DEBUG/**/ - g_map_wnd = NULL; + g_map_wnd = nullptr; } void CUIMapWnd::Init(LPCSTR xml_name, LPCSTR start_from) { @@ -144,7 +146,8 @@ void CUIMapWnd::Init(LPCSTR xml_name, LPCSTR start_from) { CInifile::Sect& S = pGameIni->r_section(sect_name.c_str()); auto it = S.Data.cbegin(), end = S.Data.cend(); for (; it != end; it++) { - shared_str map_name = it->first; + // TODO: [imdex] remove shared_str + std::string map_name(*it->first); xr_strlwr(map_name); R_ASSERT2(m_GameMaps.end() == m_GameMaps.find(map_name), "Duplicate level name not allowed"); @@ -152,7 +155,8 @@ void CUIMapWnd::Init(LPCSTR xml_name, LPCSTR start_from) { CUICustomMap*& l = m_GameMaps[map_name]; l = xr_new(this); - R_ASSERT2(pGameIni->section_exist(map_name), map_name.c_str()); + // TODO: [imdex] use string_view + R_ASSERT2(pGameIni->section_exist(map_name.c_str()), map_name.c_str()); l->Initialize(map_name, "hud\\default"); l->OptimalFit(m_UILevelFrame->GetWndRect()); @@ -171,9 +175,9 @@ void CUIMapWnd::Init(LPCSTR xml_name, LPCSTR start_from) { CUILevelMap* l2 = smart_cast(it2->second); VERIFY(l2); if (l->GlobalRect().intersected(l2->GlobalRect())) { - Msg(" --error-incorrect map definition global rect of map [%s] intersects with " - "[%s]", - *l->MapName(), *l2->MapName()); + LogMsg(" --error-incorrect map definition global rect of map [{0}] intersects with " + "[{1}]", + l->MapName(), l2->MapName()); } } if (FALSE == l->GlobalRect().intersected(GlobalMap()->BoundRect())) { @@ -243,7 +247,7 @@ void CUIMapWnd::RemoveMapToRender(CUICustomMap* m) { m_UILevelFrame->DetachChild(smart_cast(m)); } -void CUIMapWnd::SetTargetMap(const shared_str& name, const Fvector2& pos, bool bZoomIn) { +void CUIMapWnd::SetTargetMap(const std::string& name, const Fvector2& pos, bool bZoomIn) { u16 idx = GetIdxByName(name); if (idx != u16(-1)) { CUICustomMap* lm = GetMapByIdx(idx); @@ -251,7 +255,7 @@ void CUIMapWnd::SetTargetMap(const shared_str& name, const Fvector2& pos, bool b } } -void CUIMapWnd::SetTargetMap(const shared_str& name, bool bZoomIn) { +void CUIMapWnd::SetTargetMap(const std::string& name, bool bZoomIn) { u16 idx = GetIdxByName(name); if (idx != u16(-1)) { CUICustomMap* lm = GetMapByIdx(idx); @@ -450,10 +454,10 @@ CUICustomMap* CUIMapWnd::GetMapByIdx(u16 idx) { return it->second; } -u16 CUIMapWnd::GetIdxByName(const shared_str& map_name) { +u16 CUIMapWnd::GetIdxByName(const std::string& map_name) { auto it = m_GameMaps.find(map_name); if (it == m_GameMaps.end()) { - Msg("~ Level Map '%s' not registered", map_name.c_str()); + LogMsg("~ Level Map '{}' not registered", map_name); return u16(-1); } return (u16)std::distance(m_GameMaps.begin(), it); @@ -607,7 +611,7 @@ void CUIMapWnd::HideHint(CUIWindow* parent) { void CUIMapWnd::HideCurHint() { m_map_location_hint->SetOwner(NULL); } -void CUIMapWnd::Hint(const shared_str& text) { +void CUIMapWnd::Hint(const std::string_view text) { /* #ifdef DEBUG m_dbg_text_hint->SetTextST( *text ); diff --git a/code/engine/xrGame/ui/UIMapWnd.h b/code/engine/xrGame/ui/UIMapWnd.h index 44ea9544e..42997ffb2 100644 --- a/code/engine/xrGame/ui/UIMapWnd.h +++ b/code/engine/xrGame/ui/UIMapWnd.h @@ -20,7 +20,7 @@ class CGameTask; class CUIXml; class UIHint; -using GameMaps = xr_map; +using GameMaps = xr_map; class CUIMapWnd : public CUIWindow, public CUIWndCallback { typedef CUIWindow inherited; @@ -132,7 +132,7 @@ class CUIMapWnd : public CUIWindow, public CUIWndCallback { void HideHint(CUIWindow* parent); void HideCurHint(); - void Hint(const shared_str& text); + void Hint(const std::string_view text); virtual bool OnMouseAction(float x, float y, EUIMessages mouse_action); virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action); virtual bool OnKeyboardHold(int dik); @@ -141,8 +141,8 @@ class CUIMapWnd : public CUIWindow, public CUIWndCallback { void SetTargetMap(CUICustomMap* m, bool bZoomIn = false); void SetTargetMap(CUICustomMap* m, const Fvector2& pos, bool bZoomIn = false); - void SetTargetMap(const shared_str& name, const Fvector2& pos, bool bZoomIn = false); - void SetTargetMap(const shared_str& name, bool bZoomIn = false); + void SetTargetMap(const std::string& name, const Fvector2& pos, bool bZoomIn = false); + void SetTargetMap(const std::string& name, bool bZoomIn = false); void MapLocationRelcase(CMapLocation* ml); @@ -156,7 +156,7 @@ class CUIMapWnd : public CUIWindow, public CUIWndCallback { CUIGlobalMap* GlobalMap() { return m_GlobalMap; }; const GameMaps& GameMaps() { return m_GameMaps; }; CUICustomMap* GetMapByIdx(u16 idx); - u16 GetIdxByName(const shared_str& map_name); + u16 GetIdxByName(const std::string& map_name); void UpdateScroll(); shared_str cName() const { return "ui_map_wnd"; }; }; diff --git a/code/engine/xrGame/xrServer.cpp b/code/engine/xrGame/xrServer.cpp index 716f81a2c..535f1e991 100644 --- a/code/engine/xrGame/xrServer.cpp +++ b/code/engine/xrGame/xrServer.cpp @@ -767,8 +767,8 @@ void xrServer::verify_entity(const CSE_Abstract* entity) const { #endif // DEBUG -shared_str xrServer::level_name(const shared_str& server_options) const { - return (game->level_name(server_options)); +std::string xrServer::level_name(const shared_str& server_options) const { + return game->level_name(server_options); } shared_str xrServer::level_version(const shared_str& server_options) const { return (game_sv_GameState::parse_level_version(server_options)); diff --git a/code/engine/xrGame/xrServer.h b/code/engine/xrGame/xrServer.h index 3d0657d26..cbcd82244 100644 --- a/code/engine/xrGame/xrServer.h +++ b/code/engine/xrGame/xrServer.h @@ -210,7 +210,7 @@ class xrServer : public IPureServer { void SLS_Clear(); void SLS_Save(IWriter& fs); void SLS_Load(IReader& fs); - shared_str level_name(const shared_str& server_options) const; + std::string level_name(const shared_str& server_options) const; shared_str level_version(const shared_str& server_options) const; static LPCSTR get_map_download_url(LPCSTR level_name, LPCSTR level_version); diff --git a/code/engine/xrServerEntities/game_graph_space.h b/code/engine/xrServerEntities/game_graph_space.h index 39f62b499..38c0e9e7c 100644 --- a/code/engine/xrServerEntities/game_graph_space.h +++ b/code/engine/xrServerEntities/game_graph_space.h @@ -32,22 +32,23 @@ struct class #endif SLevel { - shared_str m_name; + std::string m_name; Fvector m_offset; _LEVEL_ID m_id; - shared_str m_section; + std::string m_section; xrGUID m_guid; public: - IC const shared_str& name() const { return (m_name); } + // TODO: [imdex] use string_view + const std::string& name() const { return m_name; } - IC const Fvector& offset() const { return (m_offset); } + Fvector offset() const { return m_offset; } - IC const _LEVEL_ID& id() const { return (m_id); } + const _LEVEL_ID& id() const { return m_id; } - IC const shared_str& section() const { return (m_section); } + std::string_view section() const { return m_section; } - IC const xrGUID& guid() const { return (m_guid); } + const xrGUID& guid() const { return m_guid; } IC void load(IReader* reader); IC void save(IWriter* writer); diff --git a/code/engine/xrServerEntities/object_destroyer.h b/code/engine/xrServerEntities/object_destroyer.h index 4109f06b8..80f990c0c 100644 --- a/code/engine/xrServerEntities/object_destroyer.h +++ b/code/engine/xrServerEntities/object_destroyer.h @@ -9,18 +9,18 @@ #pragma once struct CDestroyer { - IC static void delete_data(LPCSTR data) {} + static void delete_data(LPCSTR data) {} - IC static void delete_data(LPSTR data) { xr_free(data); } + static void delete_data(LPSTR data) { xr_free(data); } template - IC static void delete_data(std::pair& data) { + static void delete_data(std::pair& data) { delete_data(data.first); delete_data(data.second); } template - IC static void delete_data(svector& data) { + static void delete_data(svector& data) { svector::iterator I = data.begin(); svector::iterator E = data.end(); for (; I != E; ++I) @@ -29,7 +29,7 @@ struct CDestroyer { } template - IC static void delete_data(T (&array)[n]) { + static void delete_data(T (&array)[n]) { T* I = array; T* E = array + n; for (; I != E; ++I) @@ -37,14 +37,14 @@ struct CDestroyer { } template - IC static void delete_data(std::queue& data) { + static void delete_data(std::queue& data) { std::queue temp = data; for (; !temp.empty(); temp.pop()) delete_data(temp.front()); } template