diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 841716792df..aa6aa6e86a3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -308,6 +308,7 @@ if (MSVC) ${Boost_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR} ${CURL_INCLUDE_DIRS} + ${PARALLEL_HASHMAP_INCLUDE_DIRS} ${Protobuf_INCLUDE_DIRS} ${SPDLOG_INCLUDE_DIR} ${GMP_INCLUDE_DIR} @@ -335,6 +336,7 @@ else() PRIVATE ${CMAKE_SOURCE_DIR}/src ${LUAJIT_INCLUDE_DIRS} + ${PARALLEL_HASHMAP_INCLUDE_DIRS} ${Protobuf_INCLUDE_DIRS} ${GMP_INCLUDE_DIRS} ) diff --git a/src/creatures/monsters/monster.h b/src/creatures/monsters/monster.h index e85bac478e1..839d4486f23 100644 --- a/src/creatures/monsters/monster.h +++ b/src/creatures/monsters/monster.h @@ -28,7 +28,7 @@ class Creature; class Game; class Spawn; -using CreatureHashSet = std::unordered_set; +using CreatureHashSet = phmap::flat_hash_set; using CreatureList = std::list; class Monster final : public Creature diff --git a/src/creatures/monsters/monsters.h b/src/creatures/monsters/monsters.h index c2ad25581c4..bbffffc8883 100644 --- a/src/creatures/monsters/monsters.h +++ b/src/creatures/monsters/monsters.h @@ -131,7 +131,7 @@ class MonsterType bool targetPreferMaster = false; Faction_t faction = FACTION_DEFAULT; - std::unordered_set enemyFactions; + phmap::flat_hash_set enemyFactions; bool canPushItems = false; bool canPushCreatures = false; diff --git a/src/creatures/players/grouping/groups.cpp b/src/creatures/players/grouping/groups.cpp index 7d2ac315aed..ec37e924914 100644 --- a/src/creatures/players/grouping/groups.cpp +++ b/src/creatures/players/grouping/groups.cpp @@ -24,7 +24,7 @@ #include "utils/pugicast.h" #include "utils/tools.h" -const std::unordered_map ParsePlayerFlagMap = { +const phmap::flat_hash_map ParsePlayerFlagMap = { {"cannotusecombat", PlayerFlag_CannotUseCombat}, {"cannotattackplayer", PlayerFlag_CannotAttackPlayer}, {"cannotattackmonster", PlayerFlag_CannotAttackMonster}, @@ -65,9 +65,9 @@ const std::unordered_map ParsePlayerFlagMap = { {"isalwayspremium", PlayerFlag_IsAlwaysPremium} }; -const std::unordered_map ParsePlayerCustomFlagMap = { - {"canmapclickteleport", PlayerCustomFlag_CanMapClickTeleport}, - {"ignoredbynpcs", PlayerCustomFlag_IgnoredByNpcs} +const phmap::flat_hash_map ParsePlayerCustomFlagMap = { + {"canmapclickteleport", PlayerCustomFlag_CanMapClickTeleport}, + {"ignoredbynpcs", PlayerCustomFlag_IgnoredByNpcs} }; bool Groups::load() diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 6d745c59972..c923be4b414 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -5456,7 +5456,7 @@ uint16_t Player::getHelpers() const uint16_t helpers; if (guild && party) { - std::unordered_set helperSet; + phmap::flat_hash_set helperSet; const auto& guildMembers = guild->getMembersOnline(); helperSet.insert(guildMembers.begin(), guildMembers.end()); diff --git a/src/creatures/players/player.h b/src/creatures/players/player.h index 6865efaa39f..a8847a3c85d 100644 --- a/src/creatures/players/player.h +++ b/src/creatures/players/player.h @@ -2154,9 +2154,9 @@ class Player final : public Creature, public Cylinder void internalAddThing(Thing* thing) override; void internalAddThing(uint32_t index, Thing* thing) override; - std::unordered_set attackedSet; + phmap::flat_hash_set attackedSet; - std::unordered_set VIPList; + phmap::flat_hash_set VIPList; std::map openContainers; std::map depotLockerMap; diff --git a/src/game/game.h b/src/game/game.h index 47647a50ee7..ff4aba18490 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -471,7 +471,7 @@ class Game void sendOfflineTrainingDialog(Player* player); const std::map& getItemsPrice() const { return itemsPriceMap; } - const std::unordered_map& getPlayers() const { return players; } + const phmap::flat_hash_map& getPlayers() const { return players; } const std::map& getNpcs() const { return npcs; } const std::vector& getItemsClassifications() const { return itemsClassifications; } @@ -490,7 +490,7 @@ class Game void removeGuild(uint32_t guildId); void decreaseBrowseFieldRef(const Position& pos); - std::unordered_map browseFields; + phmap::flat_hash_map browseFields; void internalRemoveItems(std::vector itemList, uint32_t amount, bool stackable); @@ -514,7 +514,7 @@ class Game GameStore gameStore; Canary::protobuf::appearances::Appearances appearances; - std::unordered_set getTilesToClean() const { + phmap::flat_hash_set getTilesToClean() const { return tilesToClean; } void addTileToClean(Tile* tile) { @@ -586,11 +586,11 @@ class Game bool playerSpeakTo(Player* player, SpeakClasses type, const std::string& receiver, const std::string& text); void playerSpeakToNpc(Player* player, const std::string& text); - std::unordered_map players; - std::unordered_map playersActiveImbuements; - std::unordered_map mappedPlayerNames; - std::unordered_map guilds; - std::unordered_map uniqueItems; + phmap::flat_hash_map players; + phmap::flat_hash_map playersActiveImbuements; + phmap::flat_hash_map mappedPlayerNames; + phmap::flat_hash_map guilds; + phmap::flat_hash_map uniqueItems; std::map stages; /* Items stored from the lua scripts positions @@ -626,7 +626,7 @@ class Game std::map bedSleepersMap; - std::unordered_set tilesToClean; + phmap::flat_hash_set tilesToClean; ModalWindow offlineTrainingWindow { std::numeric_limits::max(), "Choose a Skill", "Please choose a skill:" }; diff --git a/src/game/scheduling/scheduler.h b/src/game/scheduling/scheduler.h index 52b7774d4b9..d570937508f 100644 --- a/src/game/scheduling/scheduler.h +++ b/src/game/scheduling/scheduler.h @@ -87,7 +87,7 @@ class Scheduler : public ThreadHolder uint32_t lastEventId {0}; std::priority_queue, TaskComparator> eventList; - std::unordered_set eventIds; + phmap::flat_hash_set eventIds; }; constexpr auto g_scheduler = &Scheduler::getInstance; diff --git a/src/items/functions/item_parse.hpp b/src/items/functions/item_parse.hpp index 7ce7163040e..f45e94339ff 100644 --- a/src/items/functions/item_parse.hpp +++ b/src/items/functions/item_parse.hpp @@ -28,7 +28,7 @@ class ConditionDamage; -const std::unordered_map ItemParseAttributesMap = { +const phmap::flat_hash_map ItemParseAttributesMap = { {"type", ITEM_PARSE_TYPE}, {"description", ITEM_PARSE_DESCRIPTION}, {"runespellname", ITEM_PARSE_RUNESPELLNAME}, @@ -149,7 +149,7 @@ const std::unordered_map ItemParseAttributes {"imbuementslot", ITEM_PARSE_IMBUEMENT}, }; -const std::unordered_map ItemTypesMap = { +const phmap::flat_hash_map ItemTypesMap = { {"key", ITEM_TYPE_KEY}, {"magicfield", ITEM_TYPE_MAGICFIELD}, {"container", ITEM_TYPE_CONTAINER}, @@ -169,7 +169,7 @@ const std::unordered_map ItemTypesMap = { {"potion", ITEM_TYPE_POTION}, }; -const std::unordered_map TileStatesMap = { +const phmap::flat_hash_map TileStatesMap = { {"down", TILESTATE_FLOORCHANGE_DOWN}, {"north", TILESTATE_FLOORCHANGE_NORTH}, {"south", TILESTATE_FLOORCHANGE_SOUTH}, @@ -179,7 +179,7 @@ const std::unordered_map TileStatesMap = { {"eastalt", TILESTATE_FLOORCHANGE_EAST_ALT}, }; -const std::unordered_map FluidTypesMap = { +const phmap::flat_hash_map FluidTypesMap = { {"water", FLUID_WATER }, {"blood", FLUID_BLOOD}, {"beer", FLUID_BEER}, @@ -200,7 +200,7 @@ const std::unordered_map FluidTypesMap = { {"ink", FLUID_INK }, }; -const std::unordered_map WeaponTypesMap = { +const phmap::flat_hash_map WeaponTypesMap = { {"sword", WEAPON_SWORD}, {"club", WEAPON_CLUB}, {"axe", WEAPON_AXE}, @@ -210,7 +210,7 @@ const std::unordered_map WeaponTypesMap = { {"ammunition", WEAPON_AMMO} }; -const std::unordered_map ImbuementsTypeMap = { +const phmap::flat_hash_map ImbuementsTypeMap = { {"elemental damage", IMBUEMENT_ELEMENTAL_DAMAGE}, {"life leech", IMBUEMENT_LIFE_LEECH}, {"mana leech", IMBUEMENT_MANA_LEECH}, diff --git a/src/items/item.h b/src/items/item.h index 77b053e1c02..568e710e7c5 100644 --- a/src/items/item.h +++ b/src/items/item.h @@ -319,7 +319,7 @@ class ItemAttributes static double emptyDouble; static bool emptyBool; - typedef std::unordered_map CustomAttributeMap; + typedef phmap::flat_hash_map CustomAttributeMap; struct Attribute { union { diff --git a/src/items/items.cpp b/src/items/items.cpp index 6b170d06b8d..9675700493e 100644 --- a/src/items/items.cpp +++ b/src/items/items.cpp @@ -43,7 +43,7 @@ void Items::clear() nameToItems.clear(); } -using LootTypeNames = std::unordered_map; +using LootTypeNames = phmap::flat_hash_map; LootTypeNames lootTypeNames = { {"armor", ITEM_TYPE_ARMOR}, diff --git a/src/items/tile.h b/src/items/tile.h index 63a9b2e0849..065e5930e03 100644 --- a/src/items/tile.h +++ b/src/items/tile.h @@ -37,7 +37,7 @@ class BedItem; using CreatureVector = std::vector; using ItemVector = std::vector; -using SpectatorHashSet = std::unordered_set; +using SpectatorHashSet = phmap::flat_hash_set; class TileItemVector : private ItemVector { diff --git a/src/lua/scripts/lua_environment.hpp b/src/lua/scripts/lua_environment.hpp index 75e636747f5..e4607fb90e2 100644 --- a/src/lua/scripts/lua_environment.hpp +++ b/src/lua/scripts/lua_environment.hpp @@ -59,16 +59,16 @@ class LuaEnvironment: public LuaScriptInterface { private: void executeTimerEvent(uint32_t eventIndex); - std::unordered_map < uint32_t, + phmap::flat_hash_map < uint32_t, LuaTimerEventDesc > timerEvents; - std::unordered_map < uint32_t, + phmap::flat_hash_map < uint32_t, Combat * > combatMap; - std::unordered_map < uint32_t, + phmap::flat_hash_map < uint32_t, AreaCombat * > areaMap; - std::unordered_map < LuaScriptInterface * , + phmap::flat_hash_map < LuaScriptInterface * , std::vector < uint32_t >> combatIdMap; - std::unordered_map < LuaScriptInterface * , + phmap::flat_hash_map < LuaScriptInterface * , std::vector < uint32_t >> areaIdMap; LuaScriptInterface * testInterface = nullptr; diff --git a/src/lua/scripts/script_environment.hpp b/src/lua/scripts/script_environment.hpp index 1ee98c1697a..128e109227b 100644 --- a/src/lua/scripts/script_environment.hpp +++ b/src/lua/scripts/script_environment.hpp @@ -98,7 +98,7 @@ class ScriptEnvironment { static std::multimap < ScriptEnvironment * , Item * > tempItems; // local item map - std::unordered_map < uint32_t, Item * > localMap; + phmap::flat_hash_map < uint32_t, Item * > localMap; uint32_t lastUID = std::numeric_limits < uint16_t > ::max(); // script file id diff --git a/src/map/house/house.h b/src/map/house/house.h index 6bced1d230e..a9b435e0928 100644 --- a/src/map/house/house.h +++ b/src/map/house/house.h @@ -46,8 +46,8 @@ class AccessList private: std::string list; - std::unordered_set playerList; - std::unordered_set guildRankList; + phmap::flat_hash_set playerList; + phmap::flat_hash_set guildRankList; bool allowEveryone = false; }; diff --git a/src/map/map.h b/src/map/map.h index b6d29a09217..9365fa12352 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -70,7 +70,7 @@ class AStarNodes private: AStarNode nodes[MAX_NODES]; bool openNodes[MAX_NODES]; - std::unordered_map nodeTable; + phmap::flat_hash_map nodeTable; size_t curNode; int_fast32_t closedNodes; }; diff --git a/src/otpch.h b/src/otpch.h index 3346d2a879f..6980096a922 100644 --- a/src/otpch.h +++ b/src/otpch.h @@ -46,5 +46,6 @@ #include #include "spdlog/spdlog.h" +#include "parallel_hashmap/phmap.h" #endif // SRC_OTPCH_H_ diff --git a/src/server/network/connection/connection.h b/src/server/network/connection/connection.h index 7bb49150fd8..fe6cdf83acd 100644 --- a/src/server/network/connection/connection.h +++ b/src/server/network/connection/connection.h @@ -59,7 +59,7 @@ class ConnectionManager private: ConnectionManager() = default; - std::unordered_set connections; + phmap::flat_hash_set connections; std::mutex connectionManagerLock; }; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index a96e6859164..82f56c4e9dd 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -6712,7 +6712,7 @@ void ProtocolGame::openImbuementWindow(Item *item) } std::vector imbuements = g_imbuements().getImbuements(player, item); - std::unordered_map needItems; + phmap::flat_hash_map needItems; msg.add(imbuements.size()); for (const Imbuement *imbuement : imbuements) @@ -7173,7 +7173,7 @@ void ProtocolGame::reloadCreature(const Creature *creature) NetworkMessage msg; - std::unordered_set::iterator it = std::find(knownCreatureSet.begin(), knownCreatureSet.end(), creature->getID()); + phmap::flat_hash_set::iterator it = std::find(knownCreatureSet.begin(), knownCreatureSet.end(), creature->getID()); if (it != knownCreatureSet.end()) { msg.addByte(0x6B); diff --git a/src/server/network/protocol/protocolgame.h b/src/server/network/protocol/protocolgame.h index e038b75e24c..25a546019a0 100644 --- a/src/server/network/protocol/protocolgame.h +++ b/src/server/network/protocol/protocolgame.h @@ -474,7 +474,7 @@ class ProtocolGame final : public Protocol friend class Player; - std::unordered_set knownCreatureSet; + phmap::flat_hash_set knownCreatureSet; Player *player = nullptr; uint32_t eventConnect = 0; diff --git a/src/server/server.h b/src/server/server.h index a3b60fa53ac..5d5de16dd3b 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -116,7 +116,7 @@ class ServiceManager private: void die(); - std::unordered_map acceptors; + phmap::flat_hash_map acceptors; boost::asio::io_service io_service; Signals signals{io_service}; diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index 8837eb1c201..29d804c6f01 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -503,19 +503,19 @@ Direction getDirectionTo(const Position& from, const Position& to) return dir; } -using MagicEffectNames = std::unordered_map; -using ShootTypeNames = std::unordered_map; -using CombatTypeNames = std::unordered_map>; -using AmmoTypeNames = std::unordered_map; -using WeaponActionNames = std::unordered_map; -using SkullNames = std::unordered_map; -using ImbuementTypeNames = std::unordered_map; +using MagicEffectNames = phmap::flat_hash_map; +using ShootTypeNames = phmap::flat_hash_map; +using CombatTypeNames = phmap::flat_hash_map>; +using AmmoTypeNames = phmap::flat_hash_map; +using WeaponActionNames = phmap::flat_hash_map; +using SkullNames = phmap::flat_hash_map; +using ImbuementTypeNames = phmap::flat_hash_map; /** * @Deprecated * It will be dropped with monsters. Use RespawnPeriod_t instead. */ -using SpawnTypeNames = std::unordered_map; +using SpawnTypeNames = phmap::flat_hash_map; MagicEffectNames magicEffectNames = { {"assassin", CONST_ME_ASSASSIN}, diff --git a/src/utils/utils_definitions.hpp b/src/utils/utils_definitions.hpp index 9edc424aeeb..bc93a4bedd7 100644 --- a/src/utils/utils_definitions.hpp +++ b/src/utils/utils_definitions.hpp @@ -683,7 +683,7 @@ enum item_t : uint16_t { }; // A map which contains items that, when on creating, should be transformed to the default type. -const std::unordered_map ItemTransformationMap = { +const phmap::flat_hash_map ItemTransformationMap = { {ITEM_SWORD_RING_ACTIVATED, ITEM_SWORD_RING}, {ITEM_CLUB_RING_ACTIVATED, ITEM_CLUB_RING}, {ITEM_DWARVEN_RING_ACTIVATED, ITEM_DWARVEN_RING}, @@ -753,7 +753,7 @@ enum Blessings_t : uint8_t { HEARTH_OF_THE_MOUNTAIN = 8, }; -const std::unordered_map BlessingNames = { +const phmap::flat_hash_map BlessingNames = { {TWIST_OF_FATE, "Twist of Fate"}, {WISDOM_OF_SOLITUDE, "The Wisdom of Solitude"}, {SPARK_OF_THE_PHOENIX, "The Spark of the Phoenix"}, diff --git a/vcpkg.json b/vcpkg.json index 56e1730af44..5101167b7d4 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -13,6 +13,7 @@ "curl", "jsoncpp", "protobuf", + "parallel-hashmap", { "name": "luajit", "platform": "!arm"