Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: std::map to btree_map and std::set to btree_set #1376

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target, bool aggre
const Creature* targetMaster = target->getMaster();

if ((!targetMaster || !targetMaster->getPlayer()) && attacker->getFaction() == FACTION_DEFAULT) {

if (!attackerMaster || !attackerMaster->getPlayer()) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
Expand Down Expand Up @@ -915,8 +914,8 @@ void Combat::doChainEffect(const Position &origin, const Position &dest, uint8_t

bool Combat::doCombatChain(Creature* caster, Creature* target, bool aggressive) const {
auto targets = std::vector<Creature*>();
auto targetSet = std::set<uint32_t>();
auto visitedChain = std::set<uint32_t>();
auto targetSet = phmap::btree_set<uint32_t>();
auto visitedChain = phmap::btree_set<uint32_t>();
if (target != nullptr) {
targets.push_back(target);
targetSet.insert(target->getID());
Expand Down Expand Up @@ -1378,7 +1377,7 @@ void Combat::setRuneSpellName(const std::string &value) {
runeSpellName = value;
}

void Combat::pickChainTargets(Creature* caster, std::vector<Creature*> &targets, std::set<uint32_t> &targetSet, std::set<uint32_t> &visited, const CombatParams &params, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive) {
void Combat::pickChainTargets(Creature* caster, std::vector<Creature*> &targets, phmap::btree_set<uint32_t> &targetSet, phmap::btree_set<uint32_t> &visited, const CombatParams &params, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive) {
if (maxTargets == 0 || targets.size() > maxTargets) {
return;
}
Expand Down Expand Up @@ -1556,7 +1555,6 @@ void ValueCallback::getMinMaxValues(Player* player, CombatDamage &damage, bool u
int32_t physDmg = std::round(defaultDmg * (1.0 - factor));
damage.primary.value = physDmg;
damage.secondary.value = elementDamage;

} else {
damage.primary.value = defaultDmg;
damage.secondary.type = COMBAT_NONE;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/combat/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class AreaCombat {
return it->second;
}

std::map<Direction, MatrixArea*> areas;
phmap::btree_map<Direction, MatrixArea*> areas;
bool hasExtArea = false;
};

Expand Down Expand Up @@ -324,7 +324,7 @@ class Combat {

private:
static void doChainEffect(const Position &origin, const Position &pos, uint8_t effect);
static void pickChainTargets(Creature* caster, std::vector<Creature*> &targets, std::set<uint32_t> &targetSet, std::set<uint32_t> &visited, const CombatParams &params, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive);
static void pickChainTargets(Creature* caster, std::vector<Creature*> &targets, phmap::btree_set<uint32_t> &targetSet, phmap::btree_set<uint32_t> &visited, const CombatParams &params, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive);

static void doCombatDefault(Creature* caster, Creature* target, const CombatParams &params);

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool Spells::registerRuneLuaEvent(RuneSpell* event) {
std::list<uint16_t> Spells::getSpellsByVocation(uint16_t vocationId) {
std::list<uint16_t> spellsList;
VocSpellMap vocSpells;
std::map<uint16_t, bool>::const_iterator vocSpellsIt;
phmap::btree_map<uint16_t, bool>::const_iterator vocSpellsIt;

for (const auto &it : instants) {
vocSpells = it.second.getVocMap();
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InstantSpell;
class RuneSpell;
class Spell;

using VocSpellMap = std::map<uint16_t, bool>;
using VocSpellMap = phmap::btree_map<uint16_t, bool>;
using InstantSpell_ptr = std::unique_ptr<InstantSpell>;
using RuneSpell_ptr = std::unique_ptr<RuneSpell>;

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void Creature::onDeath() {
const int64_t timeNow = OTSYS_TIME();
const uint32_t inFightTicks = g_configManager().getNumber(PZ_LOCKED);
int32_t mostDamage = 0;
std::map<Creature*, uint64_t> experienceMap;
phmap::btree_map<Creature*, uint64_t> experienceMap;
for (const auto &it : damageMap) {
if (Creature* attacker = g_game().getCreatureByID(it.first)) {
CountBlock_t cb = it.second;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class Creature : virtual public Thing {
int32_t total;
int64_t ticks;
};
using CountMap = std::map<uint32_t, CountBlock_t>;
using CountMap = phmap::btree_map<uint32_t, CountBlock_t>;
CountMap getDamageMap() const {
return damageMap;
}
Expand Down
8 changes: 4 additions & 4 deletions src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,9 +1451,9 @@ struct HistoryMarketOffer {

using MarketOfferList = std::list<MarketOffer>;
using HistoryMarketOfferList = std::list<HistoryMarketOffer>;
using StashItemList = std::map<uint16_t, uint32_t>;
using StashItemList = phmap::btree_map<uint16_t, uint32_t>;

using ItemsTierCountList = std::map<uint16_t, std::map<uint8_t, uint32_t>>;
using ItemsTierCountList = phmap::btree_map<uint16_t, phmap::btree_map<uint8_t, uint32_t>>;
/*
> ItemsTierCountList structure:
|- [itemID]
Expand Down Expand Up @@ -1639,8 +1639,8 @@ struct PartyAnalyzer {
uint64_t lootPrice = 0;
uint64_t supplyPrice = 0;

std::map<uint16_t, uint64_t> lootMap; // [itemID] = amount
std::map<uint16_t, uint64_t> supplyMap; // [itemID] = amount
phmap::btree_map<uint16_t, uint64_t> lootMap; // [itemID] = amount
phmap::btree_map<uint16_t, uint64_t> supplyMap; // [itemID] = amount
};

#endif // SRC_CREATURES_CREATURES_DEFINITIONS_HPP_
12 changes: 6 additions & 6 deletions src/creatures/interactions/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class Party;
class Player;

using UsersMap = std::map<uint32_t, Player*>;
using InvitedMap = std::map<uint32_t, const Player*>;
using UsersMap = phmap::btree_map<uint32_t, Player*>;
using InvitedMap = phmap::btree_map<uint32_t, const Player*>;

class ChatChannel {
public:
Expand Down Expand Up @@ -147,10 +147,10 @@ class Chat {
}

private:
std::map<uint16_t, ChatChannel> normalChannels;
std::map<uint16_t, PrivateChatChannel> privateChannels;
std::map<Party*, ChatChannel> partyChannels;
std::map<uint32_t, ChatChannel> guildChannels;
phmap::btree_map<uint16_t, ChatChannel> normalChannels;
phmap::btree_map<uint16_t, PrivateChatChannel> privateChannels;
phmap::btree_map<Party*, ChatChannel> partyChannels;
phmap::btree_map<uint32_t, ChatChannel> guildChannels;

LuaScriptInterface scriptInterface;

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ MonsterType* Monsters::getMonsterType(const std::string &name) {
}

MonsterType* Monsters::getMonsterTypeByRaceId(uint16_t thisrace) {
std::map<uint16_t, std::string> raceid_list = g_game().getBestiaryList();
phmap::btree_map<uint16_t, std::string> raceid_list = g_game().getBestiaryList();
auto it = raceid_list.find(thisrace);
if (it == raceid_list.end()) {
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/creatures/monsters/monsters.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class MonsterType {
struct MonsterInfo {
LuaScriptInterface* scriptInterface;

std::map<CombatType_t, int32_t> elementMap;
std::map<CombatType_t, int32_t> reflectMap;
std::map<CombatType_t, int32_t> healingMap;
phmap::btree_map<CombatType_t, int32_t> elementMap;
phmap::btree_map<CombatType_t, int32_t> reflectMap;
phmap::btree_map<CombatType_t, int32_t> healingMap;

std::vector<voiceBlock_t> voiceVector;

Expand Down Expand Up @@ -269,7 +269,7 @@ class Monsters {
bool deserializeSpell(MonsterSpell* spell, spellBlock_t &sb, const std::string &description = "");

std::unique_ptr<LuaScriptInterface> scriptInterface;
std::map<std::string, MonsterType*> monsters;
phmap::btree_map<std::string, MonsterType*> monsters;

private:
ConditionDamage* getDamageCondition(ConditionType_t conditionType, int32_t maxDamage, int32_t minDamage, int32_t startDamage, uint32_t tickInterval);
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/spawns/spawn_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SpawnMonster {
SpawnedMap spawnedMonsterMap;

// map of creatures in the spawn
std::map<uint32_t, spawnBlock_t> spawnMonsterMap;
phmap::btree_map<uint32_t, spawnBlock_t> spawnMonsterMap;

Position centerPos;
int32_t radius;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/npcs/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class Npc final : public Creature {

std::string strDescription;

std::map<uint32_t, uint16_t> playerInteractions;
phmap::btree_map<uint32_t, uint16_t> playerInteractions;

std::set<Player*> shopPlayerSet;
phmap::btree_set<Player*> shopPlayerSet;

NpcType* npcType;
SpawnNpc* spawnNpc = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/npcs/npcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Npcs {

private:
std::unique_ptr<LuaScriptInterface> scriptInterface;
std::map<std::string, NpcType*> npcs;
phmap::btree_map<std::string, NpcType*> npcs;
};

constexpr auto g_npcs = &Npcs::getInstance;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/npcs/spawns/spawn_npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SpawnNpc {
SpawnedNpcMap spawnedNpcMap;

// map of npcs in the spawn
std::map<uint32_t, spawnBlockNpc_t> spawnNpcMap;
phmap::btree_map<uint32_t, spawnBlockNpc_t> spawnNpcMap;

Position centerPos;
int32_t radius;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/grouping/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void Party::addPlayerLoot(const Player* player, const Item* item) {
if (priceType == LEADER_PRICE) {
playerAnalyzer->lootPrice += leader->getItemCustomPrice(item->getID()) * count;
} else {
std::map<uint16_t, uint64_t> itemMap { { item->getID(), count } };
phmap::btree_map<uint16_t, uint64_t> itemMap { { item->getID(), count } };
playerAnalyzer->lootPrice += g_game().getItemMarketPrice(itemMap, false);
}
updateTrackerAnalyzer();
Expand All @@ -632,7 +632,7 @@ void Party::addPlayerSupply(const Player* player, const Item* item) {
if (priceType == LEADER_PRICE) {
playerAnalyzer->supplyPrice += leader->getItemCustomPrice(item->getID(), true);
} else {
std::map<uint16_t, uint64_t> itemMap { { item->getID(), 1 } };
phmap::btree_map<uint16_t, uint64_t> itemMap { { item->getID(), 1 } };
playerAnalyzer->supplyPrice += g_game().getItemMarketPrice(itemMap, true);
}
updateTrackerAnalyzer();
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/grouping/party.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Party {
const char* getSharedExpReturnMessage(SharedExpStatus_t value);
SharedExpStatus_t getSharedExperienceStatus();

std::map<uint32_t, int64_t> ticksMap;
phmap::btree_map<uint32_t, int64_t> ticksMap;

PlayerVector memberList;
PlayerVector inviteList;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/grouping/team_finder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class TeamFinder {
public:
TeamFinder() = default;
TeamFinder(uint16_t initMinLevel, uint16_t initMaxLevel, uint8_t initVocationIDs, uint16_t initTeamSlots, uint16_t initFreeSlots, bool initPartyBool, uint32_t initTimestamp, uint8_t initTeamType, uint16_t initBossID, uint16_t initHunt_type, uint16_t initHunt_area, uint16_t initQuestID, uint32_t initLeaderGuid, std::map<uint32_t, uint8_t> initMembersMap) :
TeamFinder(uint16_t initMinLevel, uint16_t initMaxLevel, uint8_t initVocationIDs, uint16_t initTeamSlots, uint16_t initFreeSlots, bool initPartyBool, uint32_t initTimestamp, uint8_t initTeamType, uint16_t initBossID, uint16_t initHunt_type, uint16_t initHunt_area, uint16_t initQuestID, uint32_t initLeaderGuid, phmap::btree_map<uint32_t, uint8_t> initMembersMap) :
minLevel(initMinLevel),
maxLevel(initMaxLevel),
vocationIDs(initVocationIDs),
Expand Down Expand Up @@ -50,7 +50,7 @@ class TeamFinder {
uint32_t leaderGuid = 0;

// list: player:getGuid(), player status
std::map<uint32_t, uint8_t> membersMap = {};
phmap::btree_map<uint32_t, uint8_t> membersMap = {};
};

#endif // SRC_CREATURES_PLAYERS_GROUPING_TEAM_FINDER_HPP_
2 changes: 1 addition & 1 deletion src/creatures/players/management/ban.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ConnectBlock {
uint32_t count;
};

using IpConnectMap = std::map<uint32_t, ConnectBlock>;
using IpConnectMap = phmap::btree_map<uint32_t, ConnectBlock>;

class Ban {
public:
Expand Down
18 changes: 9 additions & 9 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ bool Player::openShopWindow(Npc* npc) {
npc->addShopPlayer(this);

sendShop(npc);
std::map<uint16_t, uint16_t> inventoryMap;
phmap::btree_map<uint16_t, uint16_t> inventoryMap;
sendSaleItemList(getAllSaleItemIdAndCount(inventoryMap));
return true;
}
Expand Down Expand Up @@ -3895,14 +3895,14 @@ std::vector<Item*> Player::getEquippedItems() const {
return valid_items;
}

std::map<uint32_t, uint32_t> &Player::getAllItemTypeCount(std::map<uint32_t, uint32_t> &countMap) const {
phmap::btree_map<uint32_t, uint32_t> &Player::getAllItemTypeCount(phmap::btree_map<uint32_t, uint32_t> &countMap) const {
for (const auto item : getAllInventoryItems()) {
countMap[static_cast<uint32_t>(item->getID())] += Item::countByType(item, -1);
}
return countMap;
}

std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t, uint16_t> &countMap) const {
phmap::btree_map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(phmap::btree_map<uint16_t, uint16_t> &countMap) const {
for (const auto item : getAllInventoryItems(false, true)) {
if (!item->hasImbuements()) {
countMap[item->getID()] += item->getItemCount();
Expand All @@ -3912,7 +3912,7 @@ std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t
return countMap;
}

void Player::getAllItemTypeCountAndSubtype(std::map<uint32_t, uint32_t> &countMap) const {
void Player::getAllItemTypeCountAndSubtype(phmap::btree_map<uint32_t, uint32_t> &countMap) const {
for (const auto item : getAllInventoryItems()) {
uint16_t itemId = item->getID();
if (Item::items[itemId].isFluidContainer()) {
Expand Down Expand Up @@ -6059,7 +6059,7 @@ uint64_t Player::getItemCustomPrice(uint16_t itemId, bool buyPrice /* = false*/)
return it->second;
}

std::map<uint16_t, uint64_t> itemMap { { itemId, 1 } };
phmap::btree_map<uint16_t, uint64_t> itemMap { { itemId, 1 } };
return g_game().getItemMarketPrice(itemMap, buyPrice);
}

Expand Down Expand Up @@ -6447,7 +6447,7 @@ void Player::requestDepotItems() {

uint8_t itemTier = Item::items[(*it)->getID()].upgradeClassification > 0 ? (*it)->getTier() + 1 : 0;
if (itemMap_it == itemMap.end()) {
std::map<uint8_t, uint32_t> itemTierMap;
phmap::btree_map<uint8_t, uint32_t> itemTierMap;
itemTierMap[itemTier] = Item::countByType((*it), -1);
itemMap[(*it)->getID()] = itemTierMap;
count++;
Expand All @@ -6469,7 +6469,7 @@ void Player::requestDepotItems() {
}

if (itemMap_it == itemMap.end()) {
std::map<uint8_t, uint32_t> itemTierMap;
phmap::btree_map<uint8_t, uint32_t> itemTierMap;
itemTierMap[0] = itemCount;
itemMap[itemId] = itemTierMap;
count++;
Expand Down Expand Up @@ -6631,13 +6631,13 @@ Item* Player::getItemFromDepotSearch(uint16_t itemId, const Position &pos) {
return nullptr;
}

std::pair<std::vector<Item*>, std::map<uint16_t, std::map<uint8_t, uint32_t>>> Player::requestLockerItems(DepotLocker* depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const {
std::pair<std::vector<Item*>, phmap::btree_map<uint16_t, phmap::btree_map<uint8_t, uint32_t>>> Player::requestLockerItems(DepotLocker* depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const {
if (depotLocker == nullptr) {
SPDLOG_ERROR("{} - Depot locker is nullptr", __FUNCTION__);
return {};
}

std::map<uint16_t, std::map<uint8_t, uint32_t>> lockerItems;
phmap::btree_map<uint16_t, phmap::btree_map<uint8_t, uint32_t>> lockerItems;
std::vector<Item*> itemVector;
std::vector<Container*> containers { depotLocker };

Expand Down
Loading