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
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);

View file

@ -4847,51 +4847,51 @@ void Bot::showDebugOverlay () {
static float timeDebugUpdate = 0.0f;
static int index = kInvalidNodeIndex, goal = kInvalidNodeIndex, taskID = 0;
static HashMap <int32_t, String> tasks;
static HashMap <int32_t, String> personalities;
static HashMap <int32_t, String> flags;
static HashMap <int32_t, String> 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 <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) {
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;
}

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

@ -539,28 +539,17 @@ String BotSupport::getCurrentDateTime () {
}
String BotSupport::buildPath (int32_t file, bool isMemoryLoad) {
static HashMap <int32_t, StringArray> directories;
static HashMap <int32_t, String> extensions;
using FilePath = Twin <String, String>;
// 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 <int32_t, FilePath> 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;