General cleanup

Use c++ methods, remove unnecessary casts, unnecessary use of auto, etc..
This commit is contained in:
Kawe Mazidjatari 2022-08-09 15:19:12 +02:00
parent 0b4eb06dd2
commit e92b5d1300
18 changed files with 55 additions and 48 deletions

View File

@ -41,16 +41,16 @@ void MOD_GetAllInstalledMaps()
for (const fs::directory_entry& dEntry : fs::directory_iterator("vpk")) for (const fs::directory_entry& dEntry : fs::directory_iterator("vpk"))
{ {
std::string svFileName = dEntry.path().string(); std::string svFileName = dEntry.path().u8string();
std::regex_search(svFileName, smRegexMatches, rgArchiveRegex); std::regex_search(svFileName, smRegexMatches, rgArchiveRegex);
if (smRegexMatches.size() > 0) if (smRegexMatches.size() > 0)
{ {
if (strcmp(smRegexMatches[1].str().c_str(), "frontend") == 0) if (smRegexMatches[1].str().compare("frontend") == 0)
{ {
continue; continue;
} }
else if (strcmp(smRegexMatches[1].str().c_str(), "mp_common") == 0) else if (smRegexMatches[1].str().compare("mp_common") == 0)
{ {
if (std::find(g_vAllMaps.begin(), g_vAllMaps.end(), "mp_lobby") == g_vAllMaps.end()) if (std::find(g_vAllMaps.begin(), g_vAllMaps.end(), "mp_lobby") == g_vAllMaps.end())
g_vAllMaps.push_back("mp_lobby"); g_vAllMaps.push_back("mp_lobby");
@ -354,7 +354,7 @@ void MOD_PreloadPakFile(const string& svLevelName)
nlohmann::json jsIn; nlohmann::json jsIn;
try try
{ {
ifstream iPakLoadDefFile(fsPath.string().c_str(), std::ios::binary); // Load prerequisites file. ifstream iPakLoadDefFile(fsPath.u8string(), std::ios::binary); // Load prerequisites file.
jsIn = nlohmann::json::parse(iPakLoadDefFile); jsIn = nlohmann::json::parse(iPakLoadDefFile);
iPakLoadDefFile.close(); iPakLoadDefFile.close();

View File

@ -125,7 +125,7 @@ void NET_PrintFunc(const char* fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = '\0';
va_end(args); va_end(args);
DevMsg(eDLL_T::CLIENT, "%s", buf); DevMsg(eDLL_T::CLIENT, "%s", buf);

View File

@ -35,7 +35,7 @@ void HSys_Error(char* fmt, ...)
buf[sizeof(buf) -1] = 0; buf[sizeof(buf) -1] = 0;
va_end(args); va_end(args);
Error(eDLL_T::ENGINE, "%s\n", buf); Error(eDLL_T::ENGINE, "%s", buf);
return v_Sys_Error(buf); return v_Sys_Error(buf);
} }
@ -54,11 +54,11 @@ void* HSys_Warning(int level, char* fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = '\0';
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////
Warning(eDLL_T::COMMON, "Warning(%d):%s\n", level, buf); Warning(eDLL_T::COMMON, "Warning(%d):%s", level, buf);
return v_Sys_Warning(level, buf); return v_Sys_Warning(level, buf);
} }
@ -107,11 +107,12 @@ void HCon_NPrintf(int pos, const char* fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = '\0';
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////
snprintf((char*)g_pLogSystem.m_pszCon_NPrintf_Buf, 4096, buf); snprintf(g_pLogSystem.m_pszCon_NPrintf_Buf,
sizeof(g_pLogSystem.m_pszCon_NPrintf_Buf), buf);
} }
} }
#endif // !DEDICATED #endif // !DEDICATED

View File

@ -111,7 +111,7 @@ FileHandle_t CBaseFileSystem::VReadFromVPK(CBaseFileSystem* pFileSystem, FileHan
{ {
std::string svFilePath = ConvertToWinPath(pszFilePath); std::string svFilePath = ConvertToWinPath(pszFilePath);
if (strstr(svFilePath.c_str(), "\\\*\\")) if (svFilePath.find("\\\*\\") != string::npos)
{ {
// Erase '//*/'. // Erase '//*/'.
svFilePath.erase(0, 4); svFilePath.erase(0, 4);
@ -139,7 +139,7 @@ bool CBaseFileSystem::VReadFromCache(CBaseFileSystem* pFileSystem, char* pszFile
{ {
std::string svFilePath = ConvertToWinPath(pszFilePath); std::string svFilePath = ConvertToWinPath(pszFilePath);
if (strstr(svFilePath.c_str(), "\\\*\\")) if (svFilePath.find("\\\*\\") != string::npos)
{ {
// Erase '//*/'. // Erase '//*/'.
svFilePath.erase(0, 4); svFilePath.erase(0, 4);

View File

@ -31,7 +31,7 @@ void CAI_Network::DebugConnectMsg(int node1, int node2, const char* pszFormat, .
vsnprintf(buf, sizeof(buf), pszFormat, args); vsnprintf(buf, sizeof(buf), pszFormat, args);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = '\0';
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////

View File

@ -312,12 +312,12 @@ void CAI_NetworkManager::LoadNetworkGraph(CAI_NetworkManager* pAINetworkManager,
if (nAiNetVersion > AINET_VERSION_NUMBER) if (nAiNetVersion > AINET_VERSION_NUMBER)
{ {
Warning(eDLL_T::SERVER, "AI node graph '%s' deviates expectations (net version: '%d' expected: '%d')\n", Warning(eDLL_T::SERVER, "AI node graph '%s' deviates expectations (net version: '%d' expected: '%d')\n",
fsGraphPath.string().c_str(), nAiNetVersion, AINET_VERSION_NUMBER); fsGraphPath.relative_path().u8string().c_str(), nAiNetVersion, AINET_VERSION_NUMBER);
} }
else if (nAiMapVersion != g_ServerGlobalVariables->m_nMapVersion) else if (nAiMapVersion != g_ServerGlobalVariables->m_nMapVersion)
{ {
Warning(eDLL_T::SERVER, "AI node graph '%s' is out of date (map version: '%d' expected: '%d')\n", Warning(eDLL_T::SERVER, "AI node graph '%s' is out of date (map version: '%d' expected: '%d')\n",
fsGraphPath.string().c_str(), nAiMapVersion, g_ServerGlobalVariables->m_nMapVersion); fsGraphPath.relative_path().u8string().c_str(), nAiMapVersion, g_ServerGlobalVariables->m_nMapVersion);
} }
else else
{ {
@ -336,7 +336,7 @@ void CAI_NetworkManager::LoadNetworkGraph(CAI_NetworkManager* pAINetworkManager,
if (nNavMeshHash != nAiGraphHash) if (nNavMeshHash != nAiGraphHash)
{ {
Warning(eDLL_T::SERVER, "AI node graph '%s' is out of date (checksum: '0x%X' expected: '0x%X')\n", Warning(eDLL_T::SERVER, "AI node graph '%s' is out of date (checksum: '0x%X' expected: '0x%X')\n",
fsGraphPath.string().c_str(), nNavMeshHash, nAiGraphHash); fsGraphPath.relative_path().u8string().c_str(), nNavMeshHash, nAiGraphHash);
} }
iNavMesh.close(); iNavMesh.close();

View File

@ -535,7 +535,7 @@ void CConsole::ProcessCommand(const char* pszCommand)
t.detach(); // Detatch from render thread. t.detach(); // Detatch from render thread.
m_nHistoryPos = -1; m_nHistoryPos = -1;
for (ssize_t i = static_cast<ssize_t>(m_vHistory.size()) - 1; i >= 0; i--) for (size_t i = m_vHistory.size(); i-- > 0; )
{ {
if (m_vHistory[i].compare(pszCommand) == 0) if (m_vHistory[i].compare(pszCommand) == 0)
{ {

View File

@ -105,10 +105,10 @@ void buildLinkTable(dtNavMesh* mesh, LinkTableData& data)
{ {
dtMeshTile* tile = mesh->getTile(i); dtMeshTile* tile = mesh->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue; if (!tile || !tile->header || !tile->dataSize) continue;
auto pcount = tile->header->polyCount; int pcount = tile->header->polyCount;
for (int j = 0; j < pcount; j++) for (int j = 0; j < pcount; j++)
{ {
auto& poly = tile->polys[j]; dtPoly& poly = tile->polys[j];
poly.disjointSetId = -1; poly.disjointSetId = -1;
} }
} }
@ -118,14 +118,14 @@ void buildLinkTable(dtNavMesh* mesh, LinkTableData& data)
{ {
dtMeshTile* tile = mesh->getTile(i); dtMeshTile* tile = mesh->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue; if (!tile || !tile->header || !tile->dataSize) continue;
auto pcount = tile->header->polyCount; int pcount = tile->header->polyCount;
for (int j = 0; j < pcount; j++) for (int j = 0; j < pcount; j++)
{ {
auto& poly = tile->polys[j]; dtPoly& poly = tile->polys[j];
auto plink = poly.firstLink; unsigned int plink = poly.firstLink;
while (plink != DT_NULL_LINK) while (plink != DT_NULL_LINK)
{ {
auto l = tile->links[plink]; const dtLink l = tile->links[plink];
const dtMeshTile* t; const dtMeshTile* t;
const dtPoly* p; const dtPoly* p;
mesh->getTileAndPolyByRefUnsafe(l.ref, &t, &p); mesh->getTileAndPolyByRefUnsafe(l.ref, &t, &p);
@ -153,11 +153,11 @@ void buildLinkTable(dtNavMesh* mesh, LinkTableData& data)
{ {
dtMeshTile* tile = mesh->getTile(i); dtMeshTile* tile = mesh->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue; if (!tile || !tile->header || !tile->dataSize) continue;
auto pcount = tile->header->polyCount; int pcount = tile->header->polyCount;
for (int j = 0; j < pcount; j++) for (int j = 0; j < pcount; j++)
{ {
auto& poly = tile->polys[j]; dtPoly& poly = tile->polys[j];
auto id = data.find(poly.disjointSetId); int id = data.find(poly.disjointSetId);
poly.disjointSetId = id; poly.disjointSetId = id;
} }
} }

View File

@ -784,7 +784,7 @@ void Sample_TileMesh::removeAllTiles()
void Sample_TileMesh::buildAllHulls() void Sample_TileMesh::buildAllHulls()
{ {
for (auto& h : hulls) for (const hulldef& h : hulls)
{ {
m_agentRadius = h.radius; m_agentRadius = h.radius;
m_agentMaxClimb = h.climb_height; m_agentMaxClimb = h.climb_height;

View File

@ -550,18 +550,18 @@ void CUIBaseSurface::ParseMaps()
{ {
std::regex rgArchiveRegex{ R"([^_]*_(.*)(.bsp.pak000_dir).*)" }; std::regex rgArchiveRegex{ R"([^_]*_(.*)(.bsp.pak000_dir).*)" };
std::smatch smRegexMatches; std::smatch smRegexMatches;
for (const auto& dEntry : fs::directory_iterator("vpk")) for (const fs::directory_entry& dEntry : fs::directory_iterator("vpk"))
{ {
std::string svFileName = dEntry.path().string(); std::string svFileName = dEntry.path().string();
std::regex_search(svFileName, smRegexMatches, rgArchiveRegex); std::regex_search(svFileName, smRegexMatches, rgArchiveRegex);
if (smRegexMatches.size() > 0) if (smRegexMatches.size() > 0)
{ {
if (strcmp(smRegexMatches[1].str().c_str(), "frontend") == 0) if (smRegexMatches[1].str().compare("frontend") == 0)
{ {
continue; continue;
} }
else if (strcmp(smRegexMatches[1].str().c_str(), "mp_common") == 0) else if (smRegexMatches[1].str().compare("mp_common") == 0)
{ {
if (!this->m_MapCombo->Items.Contains("mp_lobby")) if (!this->m_MapCombo->Items.Contains("mp_lobby"))
{ {

View File

@ -91,7 +91,7 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = '\0';
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////

View File

@ -45,7 +45,7 @@ void Strtrim(char* s)
void ImGuiConfig::Load() void ImGuiConfig::Load()
{ {
fs::path fsPath = "platform\\imgui.json"; fs::path fsPath = "platform\\imgui.json";
DevMsg(eDLL_T::MS, "Loading ImGui config file '%s'\n", fsPath.relative_path().string().c_str()); DevMsg(eDLL_T::MS, "Loading ImGui config file '%s'\n", fsPath.relative_path().u8string().c_str());
if (fs::exists(fsPath)) if (fs::exists(fsPath))
{ {
@ -93,7 +93,7 @@ void ImGuiConfig::Save()
fs::path fsPath = "platform\\imgui.json"; fs::path fsPath = "platform\\imgui.json";
DevMsg(eDLL_T::MS, "Saving ImGui config file '%s'\n", fsPath.string().c_str()); DevMsg(eDLL_T::MS, "Saving ImGui config file '%s'\n", fsPath.relative_path().u8string().c_str());
std::ofstream outFile(fsPath, std::ios::out | std::ios::trunc); // Write config file. std::ofstream outFile(fsPath, std::ios::out | std::ios::trunc); // Write config file.
outFile << jsOut.dump(4); // Dump it into config file. outFile << jsOut.dump(4); // Dump it into config file.

View File

@ -62,12 +62,12 @@ void CNetAdr2::SetPort(const string& svInPort)
void CNetAdr2::SetIPAndPort(string svInAdr) void CNetAdr2::SetIPAndPort(string svInAdr)
{ {
SetType(netadrtype_t::NA_IP); SetType(netadrtype_t::NA_IP);
if (strstr(svInAdr.c_str(), "loopback") || strstr(svInAdr.c_str(), "::1")) if (svInAdr.find("loopback") != string::npos || svInAdr.find("::1") != string::npos)
{ {
SetType(netadrtype_t::NA_LOOPBACK); SetType(netadrtype_t::NA_LOOPBACK);
svInAdr = "[127.0.0.1]:" + GetPort(svInAdr); svInAdr = "[127.0.0.1]:" + GetPort(svInAdr);
} }
else if (strstr(svInAdr.c_str(), "localhost")) else if (svInAdr.find("localhost") != string::npos)
{ {
svInAdr = "[127.0.0.1]:" + GetPort(svInAdr); svInAdr = "[127.0.0.1]:" + GetPort(svInAdr);
} }
@ -102,7 +102,7 @@ void CNetAdr2::SetIPAndPort(string svInAdr, string svInPort)
svInAdr = "127.0.0.1"; svInAdr = "127.0.0.1";
} }
if (strstr(svInAdr.c_str(), "[") || strstr(svInAdr.c_str(), "]")) if (svInAdr.find("[") != string::npos || svInAdr.find("]") != string::npos)
{ {
svInAdr = GetBase(svInAdr); svInAdr = GetBase(svInAdr);
} }

View File

@ -135,7 +135,7 @@ void CLogSystem::DrawHostStats(void) const
nHeight = g_nWindowHeight - nHeight; nHeight = g_nWindowHeight - nHeight;
} }
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, v_Rui_GetFontFace(), m_nFontHeight, nWidth, nHeight, c.r(), c.g(), c.b(), c.a(), (char*)m_pszCon_NPrintf_Buf); CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, v_Rui_GetFontFace(), m_nFontHeight, nWidth, nHeight, c.r(), c.g(), c.b(), c.a(), m_pszCon_NPrintf_Buf);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -37,6 +37,12 @@ struct LogMsg_t
class CLogSystem class CLogSystem
{ {
public: public:
CLogSystem()
{
m_nFontHeight = 16;
memset(m_pszCon_NPrintf_Buf, '\0', sizeof(m_pszCon_NPrintf_Buf));
}
void Update(void); void Update(void);
void AddLog(LogType_t type, string svText); void AddLog(LogType_t type, string svText);
void DrawLog(void); void DrawLog(void);
@ -48,11 +54,11 @@ public:
private: private:
Color GetLogColorForType(LogType_t type) const; Color GetLogColorForType(LogType_t type) const;
vector<LogMsg_t> m_vLogs{}; vector<LogMsg_t> m_vLogs;
int m_nFontHeight = 16; int m_nFontHeight;
public: public:
char* m_pszCon_NPrintf_Buf[4096]{}; char m_pszCon_NPrintf_Buf[4096]{};
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -74,7 +74,7 @@ void CFactory::GetFactoriesFromRegister(void)
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
CMemory CFactory::GetFactoryPtr(const string& svFactoryName, bool bVersionLess) const CMemory CFactory::GetFactoryPtr(const string& svFactoryName, bool bVersionLess) const
{ {
for (auto& it : m_vFactories) // Loop through the whole vector. for (const FactoryInfo& it : m_vFactories) // Loop through the whole vector.
{ {
if (bVersionLess) if (bVersionLess)
{ {

View File

@ -23,7 +23,7 @@ int HQHull_PrintFunc(const char* fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = '\0';
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////

View File

@ -55,14 +55,14 @@ VPKDir_t CPackedStore::GetDirectoryFile(string svPackDirFile) const
for (size_t i = 0; i < DIR_LOCALE.size(); i++) for (size_t i = 0; i < DIR_LOCALE.size(); i++)
{ {
if (strstr(svPackDirFile.c_str(), DIR_CONTEXT[i].c_str())) if (svPackDirFile.find(DIR_CONTEXT[i]) != string::npos)
{ {
for (size_t j = 0; j < DIR_CONTEXT.size(); j++) for (size_t j = 0; j < DIR_CONTEXT.size(); j++)
{ {
if (strstr(svPackDirFile.c_str(), DIR_CONTEXT[j].c_str())) if (svPackDirFile.find(DIR_CONTEXT[j]) != string::npos)
{ {
string svPackDirPrefix = DIR_LOCALE[i] + DIR_LOCALE[i]; string svPackDirPrefix = DIR_LOCALE[i] + DIR_LOCALE[i];
StringReplace(svPackDirFile, DIR_LOCALE[i].c_str(), svPackDirPrefix.c_str()); StringReplace(svPackDirFile, DIR_LOCALE[i], svPackDirPrefix);
goto escape; goto escape;
} }
} }
@ -234,7 +234,7 @@ nlohmann::json CPackedStore::GetManifest(const string& svWorkSpace, const string
{ {
try try
{ {
ifstream iManifest(fsPath.string().c_str(), std::ios::binary); ifstream iManifest(fsPath.u8string(), std::ios::binary);
jsOut = nlohmann::json::parse(iManifest); jsOut = nlohmann::json::parse(iManifest);
return jsOut; return jsOut;
@ -306,9 +306,9 @@ string CPackedStore::StripLocalePrefix(const string& svDirectoryFile) const
for (size_t i = 0; i < DIR_LOCALE.size(); i++) for (size_t i = 0; i < DIR_LOCALE.size(); i++)
{ {
if (strstr(svFileName.c_str(), DIR_LOCALE[i].c_str())) if (svFileName.find(DIR_LOCALE[i]) != string::npos)
{ {
StringReplace(svFileName, DIR_LOCALE[i].c_str(), ""); StringReplace(svFileName, DIR_LOCALE[i], "");
break; break;
} }
} }