crlib: switch to new hashmap

This commit is contained in:
jeefo 2023-04-15 04:10:09 +03:00
commit 2765eed7ac
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
8 changed files with 67 additions and 75 deletions

@ -1 +1 @@
Subproject commit 6d3c954a0ac8f03068e90825b7c3ed3eb0c921cc Subproject commit 998ce232be5558e856733d4b1ac165e43d1b9e92

View file

@ -252,7 +252,7 @@ public:
// get custom value // get custom value
StringRef fetchCustom (StringRef name) { StringRef fetchCustom (StringRef name) {
if (m_custom.has (name)) { if (m_custom.exists (name)) {
return m_custom[name]; return m_custom[name];
} }
SimpleLogger::instance ().error ("Trying to fetch unknown custom variable: %s", name); SimpleLogger::instance ().error ("Trying to fetch unknown custom variable: %s", name);

View file

@ -4847,51 +4847,51 @@ void Bot::showDebugOverlay () {
static float timeDebugUpdate = 0.0f; static float timeDebugUpdate = 0.0f;
static int index = kInvalidNodeIndex, goal = kInvalidNodeIndex, taskID = 0; static int index = kInvalidNodeIndex, goal = kInvalidNodeIndex, taskID = 0;
static HashMap <int32_t, String> tasks; static HashMap <int32_t, String> tasks {
static HashMap <int32_t, String> personalities; { Task::Normal, "Normal" },
static HashMap <int32_t, String> flags; { 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 <int32_t, String> personalities {
{ Personality::Rusher, "Rusher" },
{ Personality::Normal, "Normal" },
{ Personality::Careful, "Careful" }
};
static HashMap <int32_t, String> 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) { auto boolValue = [] (const bool test) {
return test ? "Yes" : "No"; 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 ()) { if (m_tasks.empty ()) {
return; return;
} }

View file

@ -793,7 +793,7 @@ const char *BotConfig::translate (StringRef input) {
} }
auto hash = hashLangString (input.chars ()); auto hash = hashLangString (input.chars ());
if (m_language.has (hash)) { if (m_language.exists (hash)) {
return m_language[hash].chars (); return m_language[hash].chars ();
} }
return input.chars (); // nothing found return input.chars (); // nothing found

View file

@ -132,7 +132,7 @@ int BotControl::cmdWeaponMode () {
auto mode = strValue (type); auto mode = strValue (type);
// check if selected mode exists // check if selected mode exists
if (!modes.has (mode)) { if (!modes.exists (mode)) {
return BotCommandResult::BadFormat; return BotCommandResult::BadFormat;
} }
bots.setWeaponMode (modes[mode]); bots.setWeaponMode (modes[mode]);
@ -352,7 +352,7 @@ int BotControl::cmdNode () {
addGraphCmd ("release_editor", "release_editor [noarguments]", "Releases graph editing rights.", &BotControl::cmdNodeReleaseEditor); 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)]; const auto &item = commands[strValue (cmd)];
// graph have only bad format return status // graph have only bad format return status
@ -365,7 +365,7 @@ int BotControl::cmdNode () {
} }
} }
else { 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)]; auto &item = commands[strValue (cmd2)];
msg ("Command: \"%s %s %s\"", m_args[root], m_args[alias], item.name); msg ("Command: \"%s %s %s\"", m_args[root], m_args[alias], item.name);

View file

@ -1041,7 +1041,7 @@ SharedLibrary::Func EntityLinkage::lookup (SharedLibrary::Handle module, const c
} }
#endif #endif
if (m_exports.has (function)) { if (m_exports.exists (function)) {
return m_exports[function]; return m_exports[function];
} }
auto botAddr = resolve (self); auto botAddr = resolve (self);

View file

@ -493,7 +493,7 @@ MessageDispatcher::MessageDispatcher () {
} }
int32_t MessageDispatcher::add (StringRef name, int32_t id) { int32_t MessageDispatcher::add (StringRef name, int32_t id) {
if (!m_wanted.has (name)) { if (!m_wanted.exists (name)) {
return id; return id;
} }
@ -511,7 +511,7 @@ void MessageDispatcher::start (edict_t *ent, int32_t type) {
} }
// search if we need to handle this message // search if we need to handle this message
if (m_reverseMap.has (type)) { if (m_reverseMap.exists (type)) {
auto msg = m_reverseMap[type]; auto msg = m_reverseMap[type];
m_current = m_handlers[msg] ? msg : NetMsg::None; m_current = m_handlers[msg] ? msg : NetMsg::None;
} }
@ -546,7 +546,7 @@ void MessageDispatcher::ensureMessages () {
// this function tries to associate appropriate message ids. // this function tries to associate appropriate message ids.
// check if we're have one // check if we're have one
if (m_maps.has (NetMsg::Money)) { if (m_maps.exists (NetMsg::Money)) {
return; return;
} }

View file

@ -539,28 +539,17 @@ String BotSupport::getCurrentDateTime () {
} }
String BotSupport::buildPath (int32_t file, bool isMemoryLoad) { String BotSupport::buildPath (int32_t file, bool isMemoryLoad) {
static HashMap <int32_t, StringArray> directories; using FilePath = Twin <String, String>;
static HashMap <int32_t, String> extensions;
// fill out directories paths, it's permanenet static HashMap <int32_t, FilePath> paths = {
if (directories.empty ()) { { BotFile::Vistable, FilePath ("train", "vis")},
directories[BotFile::Vistable] = { "data", "train" }; { BotFile::Practice, FilePath ("train", "prc")},
directories[BotFile::Practice] = { "data", "train" }; { BotFile::Pathmatrix, FilePath ("train", "pmx")},
directories[BotFile::Pathmatrix] = { "data", "train" }; { BotFile::LogFile, FilePath ("logs", "txt")},
directories[BotFile::LogFile] = { "data", "logs" }; { BotFile::Graph, FilePath ("graph", "graph")},
directories[BotFile::Graph] = { "data", "graph" }; { BotFile::PodbotPWF, FilePath ("pwf", "pwf")},
directories[BotFile::PodbotPWF] = { "data", "pwf" }; { BotFile::EbotEWP, FilePath ("ewp", "ewp")},
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 StringArray path; static StringArray path;
path.clear (); path.clear ();
@ -574,8 +563,11 @@ String BotSupport::buildPath (int32_t file, bool isMemoryLoad) {
path.emplace ("addons"); path.emplace ("addons");
path.emplace (product.folder); path.emplace (product.folder);
// the datadir
path.emplace ("data");
// append real filepath // append real filepath
path.extend (directories[file]); path.emplace (paths[file].first);
// if file is logfile use correct logfile name with date // if file is logfile use correct logfile name with date
if (file == BotFile::LogFile) { if (file == BotFile::LogFile) {
@ -586,11 +578,11 @@ String BotSupport::buildPath (int32_t file, bool isMemoryLoad) {
auto timebuf = strings.chars (); auto timebuf = strings.chars ();
strftime (timebuf, StringBuffer::StaticBufferSize, "L%d%m%Y", &timeinfo); 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 { else {
String mapName = game.getMapName (); 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 // 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 BotSupport::weaponIdToAlias (int32_t id) {
StringRef none = "none"; StringRef none = "none";
if (m_weaponAlias.has (id)) { if (m_weaponAlias.exists (id)) {
return m_weaponAlias[id]; return m_weaponAlias[id];
} }
return none; return none;