From 2765eed7ac8db06256c9f655bf4a95c175c48823 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 15 Apr 2023 04:10:09 +0300 Subject: [PATCH] crlib: switch to new hashmap --- ext/crlib | 2 +- inc/config.h | 2 +- src/botlib.cpp | 80 ++++++++++++++++++++++++------------------------- src/config.cpp | 2 +- src/control.cpp | 6 ++-- src/linkage.cpp | 2 +- src/message.cpp | 6 ++-- src/support.cpp | 42 +++++++++++--------------- 8 files changed, 67 insertions(+), 75 deletions(-) diff --git a/ext/crlib b/ext/crlib index 6d3c954..998ce23 160000 --- a/ext/crlib +++ b/ext/crlib @@ -1 +1 @@ -Subproject commit 6d3c954a0ac8f03068e90825b7c3ed3eb0c921cc +Subproject commit 998ce232be5558e856733d4b1ac165e43d1b9e92 diff --git a/inc/config.h b/inc/config.h index b31e003..75aed42 100644 --- a/inc/config.h +++ b/inc/config.h @@ -252,7 +252,7 @@ public: // get custom value StringRef fetchCustom (StringRef name) { - if (m_custom.has (name)) { + if (m_custom.exists (name)) { return m_custom[name]; } SimpleLogger::instance ().error ("Trying to fetch unknown custom variable: %s", name); diff --git a/src/botlib.cpp b/src/botlib.cpp index e00cf3d..19e4651 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -4847,51 +4847,51 @@ void Bot::showDebugOverlay () { static float timeDebugUpdate = 0.0f; static int index = kInvalidNodeIndex, goal = kInvalidNodeIndex, taskID = 0; - static HashMap tasks; - static HashMap personalities; - static HashMap flags; + static HashMap tasks { + { Task::Normal, "Normal" }, + { Task::Pause, "Pause" }, + { Task::MoveToPosition, "Move" }, + { Task::FollowUser, "Follow" }, + { Task::PickupItem, "Pickup" }, + { Task::Camp, "Camp" }, + { Task::PlantBomb, "PlantBomb" }, + { Task::DefuseBomb, "DefuseBomb" }, + { Task::Attack, "Attack" }, + { Task::Hunt, "Hunt" }, + { Task::SeekCover, "SeekCover" }, + { Task::ThrowExplosive, "ThrowHE" }, + { Task::ThrowFlashbang, "ThrowFL" }, + { Task::ThrowSmoke, "ThrowSG" }, + { Task::DoubleJump, "DoubleJump" }, + { Task::EscapeFromBomb, "EscapeFromBomb" }, + { Task::ShootBreakable, "DestroyBreakable" }, + { Task::Hide, "Hide" }, + { Task::Blind, "Blind" }, + { Task::Spraypaint, "Spray" } + }; + + static HashMap personalities { + { Personality::Rusher, "Rusher" }, + { Personality::Normal, "Normal" }, + { Personality::Careful, "Careful" } + }; + + static HashMap flags { + { AimFlags::Nav, "Nav" }, + { AimFlags::Camp, "Camp" }, + { AimFlags::PredictPath, "Predict" }, + { AimFlags::LastEnemy, "LastEnemy" }, + { AimFlags::Entity, "Entity" }, + { AimFlags::Enemy, "Enemy" }, + { AimFlags::Grenade, "Grenade" }, + { AimFlags::Override, "Override" }, + { AimFlags::Danger, "Danger" }, + }; auto boolValue = [] (const bool test) { return test ? "Yes" : "No"; }; - if (tasks.empty ()) { - tasks[Task::Normal] = "Normal"; - tasks[Task::Pause] = "Pause"; - tasks[Task::MoveToPosition] = "Move"; - tasks[Task::FollowUser] = "Follow"; - tasks[Task::PickupItem] = "Pickup"; - tasks[Task::Camp] = "Camp"; - tasks[Task::PlantBomb] = "PlantBomb"; - tasks[Task::DefuseBomb] = "DefuseBomb"; - tasks[Task::Attack] = "Attack"; - tasks[Task::Hunt] = "Hunt"; - tasks[Task::SeekCover] = "SeekCover"; - tasks[Task::ThrowExplosive] = "ThrowHE"; - tasks[Task::ThrowFlashbang] = "ThrowFL"; - tasks[Task::ThrowSmoke] = "ThrowSG"; - tasks[Task::DoubleJump] = "DoubleJump"; - tasks[Task::EscapeFromBomb] = "EscapeFromBomb"; - tasks[Task::ShootBreakable] = "DestroyBreakable"; - tasks[Task::Hide] = "Hide"; - tasks[Task::Blind] = "Blind"; - tasks[Task::Spraypaint] = "Spray"; - - personalities[Personality::Rusher] = "Rusher"; - personalities[Personality::Normal] = "Normal"; - personalities[Personality::Careful] = "Careful"; - - flags[AimFlags::Nav] = "Nav"; - flags[AimFlags::Camp] = "Camp"; - flags[AimFlags::PredictPath] = "Predict"; - flags[AimFlags::LastEnemy] = "LastEnemy"; - flags[AimFlags::Entity] = "Entity"; - flags[AimFlags::Enemy] = "Enemy"; - flags[AimFlags::Grenade] = "Grenade"; - flags[AimFlags::Override] = "Override"; - flags[AimFlags::Danger] = "Danger"; - } - if (m_tasks.empty ()) { return; } diff --git a/src/config.cpp b/src/config.cpp index bbdb285..5cae639 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -793,7 +793,7 @@ const char *BotConfig::translate (StringRef input) { } auto hash = hashLangString (input.chars ()); - if (m_language.has (hash)) { + if (m_language.exists (hash)) { return m_language[hash].chars (); } return input.chars (); // nothing found diff --git a/src/control.cpp b/src/control.cpp index 30724ce..8d1ac3f 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -132,7 +132,7 @@ int BotControl::cmdWeaponMode () { auto mode = strValue (type); // check if selected mode exists - if (!modes.has (mode)) { + if (!modes.exists (mode)) { return BotCommandResult::BadFormat; } bots.setWeaponMode (modes[mode]); @@ -352,7 +352,7 @@ int BotControl::cmdNode () { addGraphCmd ("release_editor", "release_editor [noarguments]", "Releases graph editing rights.", &BotControl::cmdNodeReleaseEditor); } } - if (commands.has (strValue (cmd))) { + if (commands.exists (strValue (cmd))) { const auto &item = commands[strValue (cmd)]; // graph have only bad format return status @@ -365,7 +365,7 @@ int BotControl::cmdNode () { } } else { - if (strValue (cmd) == "help" && hasArg (cmd2) && commands.has (strValue (cmd2))) { + if (strValue (cmd) == "help" && hasArg (cmd2) && commands.exists (strValue (cmd2))) { auto &item = commands[strValue (cmd2)]; msg ("Command: \"%s %s %s\"", m_args[root], m_args[alias], item.name); diff --git a/src/linkage.cpp b/src/linkage.cpp index 91e090d..1ee0d50 100644 --- a/src/linkage.cpp +++ b/src/linkage.cpp @@ -1041,7 +1041,7 @@ SharedLibrary::Func EntityLinkage::lookup (SharedLibrary::Handle module, const c } #endif - if (m_exports.has (function)) { + if (m_exports.exists (function)) { return m_exports[function]; } auto botAddr = resolve (self); diff --git a/src/message.cpp b/src/message.cpp index 15dc982..f00b375 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -493,7 +493,7 @@ MessageDispatcher::MessageDispatcher () { } int32_t MessageDispatcher::add (StringRef name, int32_t id) { - if (!m_wanted.has (name)) { + if (!m_wanted.exists (name)) { return id; } @@ -511,7 +511,7 @@ void MessageDispatcher::start (edict_t *ent, int32_t type) { } // search if we need to handle this message - if (m_reverseMap.has (type)) { + if (m_reverseMap.exists (type)) { auto msg = m_reverseMap[type]; m_current = m_handlers[msg] ? msg : NetMsg::None; } @@ -546,7 +546,7 @@ void MessageDispatcher::ensureMessages () { // this function tries to associate appropriate message ids. // check if we're have one - if (m_maps.has (NetMsg::Money)) { + if (m_maps.exists (NetMsg::Money)) { return; } diff --git a/src/support.cpp b/src/support.cpp index 338581c..bbd1215 100644 --- a/src/support.cpp +++ b/src/support.cpp @@ -539,28 +539,17 @@ String BotSupport::getCurrentDateTime () { } String BotSupport::buildPath (int32_t file, bool isMemoryLoad) { - static HashMap directories; - static HashMap extensions; + using FilePath = Twin ; - // fill out directories paths, it's permanenet - if (directories.empty ()) { - directories[BotFile::Vistable] = { "data", "train" }; - directories[BotFile::Practice] = { "data", "train" }; - directories[BotFile::Pathmatrix] = { "data", "train" }; - directories[BotFile::LogFile] = { "data", "logs" }; - directories[BotFile::Graph] = { "data", "graph" }; - directories[BotFile::PodbotPWF] = { "data", "pwf" }; - directories[BotFile::EbotEWP] = { "data", "ewp" }; - - // fill out extensions fo needed types - extensions[BotFile::Vistable] = "vis"; - extensions[BotFile::Practice] = "prc"; - extensions[BotFile::Pathmatrix] = "pmx"; - extensions[BotFile::LogFile] = "txt"; - extensions[BotFile::Graph] = "graph"; - extensions[BotFile::PodbotPWF] = "pwf"; - extensions[BotFile::EbotEWP] = "ewp"; - } + static HashMap paths = { + { BotFile::Vistable, FilePath ("train", "vis")}, + { BotFile::Practice, FilePath ("train", "prc")}, + { BotFile::Pathmatrix, FilePath ("train", "pmx")}, + { BotFile::LogFile, FilePath ("logs", "txt")}, + { BotFile::Graph, FilePath ("graph", "graph")}, + { BotFile::PodbotPWF, FilePath ("pwf", "pwf")}, + { BotFile::EbotEWP, FilePath ("ewp", "ewp")}, + }; static StringArray path; path.clear (); @@ -574,8 +563,11 @@ String BotSupport::buildPath (int32_t file, bool isMemoryLoad) { path.emplace ("addons"); path.emplace (product.folder); + // the datadir + path.emplace ("data"); + // append real filepath - path.extend (directories[file]); + path.emplace (paths[file].first); // if file is logfile use correct logfile name with date if (file == BotFile::LogFile) { @@ -586,11 +578,11 @@ String BotSupport::buildPath (int32_t file, bool isMemoryLoad) { auto timebuf = strings.chars (); strftime (timebuf, StringBuffer::StaticBufferSize, "L%d%m%Y", &timeinfo); - path.emplace (strings.format ("%s_%s.%s", product.folder, timebuf, extensions[file])); + path.emplace (strings.format ("%s_%s.%s", product.folder, timebuf, paths[file].second)); } else { String mapName = game.getMapName (); - path.emplace (strings.format ("%s.%s", mapName.lowercase (), extensions[file])); + path.emplace (strings.format ("%s.%s", mapName.lowercase (), paths[file].second)); } // finally use correct path separarators for us @@ -670,7 +662,7 @@ int32_t BotSupport::sendTo (int socket, const void *message, size_t length, int StringRef BotSupport::weaponIdToAlias (int32_t id) { StringRef none = "none"; - if (m_weaponAlias.has (id)) { + if (m_weaponAlias.exists (id)) { return m_weaponAlias[id]; } return none;