[9228] Speedup groups store and other code work.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
zhenya 2010-01-21 17:36:08 +03:00 committed by VladimirMangos
parent 4995a6d298
commit 4178d5bb6a
7 changed files with 74 additions and 91 deletions

View file

@ -404,8 +404,7 @@ void Creature::Update(uint32 diff)
}
else
{
Group* group = sObjectMgr.GetGroupByLeader(lootingGroupLeaderGUID);
if (group)
if (Group* group = sObjectMgr.GetGroupByLeaderLowGUID(GUID_LOPART(lootingGroupLeaderGUID)))
group->EndRoll();
m_groupLootTimer = 0;
lootingGroupLeaderGUID = 0;

View file

@ -1086,7 +1086,7 @@ void LoadLootTemplates_Creature()
{
if(uint32 lootid = cInfo->lootid)
{
if(!ids_set.count(lootid))
if (ids_set.find(lootid) == ids_set.end())
LootTemplates_Creature.ReportNotExistedId(lootid);
else
ids_setUsed.insert(lootid);
@ -1116,7 +1116,7 @@ void LoadLootTemplates_Disenchant()
{
if(uint32 lootid = proto->DisenchantID)
{
if(!ids_set.count(lootid))
if (ids_set.find(lootid) == ids_set.end())
LootTemplates_Disenchant.ReportNotExistedId(lootid);
else
ids_setUsed.insert(lootid);
@ -1138,7 +1138,7 @@ void LoadLootTemplates_Fishing()
for(uint32 i = 1; i < sAreaStore.GetNumRows(); ++i )
{
if(AreaTableEntry const* areaEntry = sAreaStore.LookupEntry(i))
if(ids_set.count(areaEntry->ID))
if (ids_set.find(areaEntry->ID) != ids_set.end())
ids_set.erase(areaEntry->ID);
}
@ -1158,7 +1158,7 @@ void LoadLootTemplates_Gameobject()
{
if(uint32 lootid = gInfo->GetLootId())
{
if(!ids_set.count(lootid))
if (ids_set.find(lootid) == ids_set.end())
LootTemplates_Gameobject.ReportNotExistedId(lootid);
else
ids_setUsed.insert(lootid);
@ -1180,7 +1180,7 @@ void LoadLootTemplates_Item()
// remove real entries and check existence loot
for(uint32 i = 1; i < sItemStorage.MaxEntry; ++i )
if(ItemPrototype const* proto = sItemStorage.LookupEntry<ItemPrototype>(i))
if(ids_set.count(proto->ItemId))
if (ids_set.find(proto->ItemId) != ids_set.end())
ids_set.erase(proto->ItemId);
// output error for any still listed (not referenced from appropriate table) ids
@ -1202,7 +1202,7 @@ void LoadLootTemplates_Milling()
if((proto->BagFamily & BAG_FAMILY_MASK_HERBS)==0)
continue;
if(ids_set.count(proto->ItemId))
if (ids_set.find(proto->ItemId) != ids_set.end())
ids_set.erase(proto->ItemId);
}
@ -1222,7 +1222,7 @@ void LoadLootTemplates_Pickpocketing()
{
if(uint32 lootid = cInfo->pickpocketLootId)
{
if(!ids_set.count(lootid))
if (ids_set.find(lootid) == ids_set.end())
LootTemplates_Pickpocketing.ReportNotExistedId(lootid);
else
ids_setUsed.insert(lootid);
@ -1251,7 +1251,7 @@ void LoadLootTemplates_Prospecting()
if((proto->BagFamily & BAG_FAMILY_MASK_MINING_SUPP)==0)
continue;
if(ids_set.count(proto->ItemId))
if (ids_set.find(proto->ItemId) != ids_set.end())
ids_set.erase(proto->ItemId);
}
@ -1267,7 +1267,7 @@ void LoadLootTemplates_Mail()
// remove real entries and check existence loot
for(uint32 i = 1; i < sMailTemplateStore.GetNumRows(); ++i )
if(sMailTemplateStore.LookupEntry(i))
if(ids_set.count(i))
if (ids_set.find(i) != ids_set.end())
ids_set.erase(i);
// output error for any still listed (not referenced from appropriate table) ids
@ -1286,7 +1286,7 @@ void LoadLootTemplates_Skinning()
{
if(uint32 lootid = cInfo->SkinLootId)
{
if(!ids_set.count(lootid))
if (ids_set.find(lootid) == ids_set.end())
LootTemplates_Skinning.ReportNotExistedId(lootid);
else
ids_setUsed.insert(lootid);
@ -1316,7 +1316,7 @@ void LoadLootTemplates_Spell()
if( !IsLootCraftingSpell(spellInfo))
continue;
if(!ids_set.count(spell_id))
if (ids_set.find(spell_id) == ids_set.end())
{
// not report about not trainable spells (optionally supported by DB)
// ignore 61756 (Northrend Inscription Research (FAST QA VERSION) for example

View file

@ -164,8 +164,8 @@ ObjectMgr::~ObjectMgr()
delete[] playerInfo[race][class_].levelInfo;
// free group and guild objects
for (GroupSet::iterator itr = mGroupSet.begin(); itr != mGroupSet.end(); ++itr)
delete (*itr);
for (GroupMap::iterator itr = mGroupMap.begin(); itr != mGroupMap.end(); ++itr)
delete itr->second;
for (GuildMap::iterator itr = mGuildMap.begin(); itr != mGuildMap.end(); ++itr)
delete itr->second;
@ -180,11 +180,11 @@ ObjectMgr::~ObjectMgr()
itr->second.Clear();
}
Group * ObjectMgr::GetGroupByLeader(const uint64 &guid) const
Group * ObjectMgr::GetGroupByLeaderLowGUID(uint32 guid) const
{
for(GroupSet::const_iterator itr = mGroupSet.begin(); itr != mGroupSet.end(); ++itr)
if ((*itr)->GetLeaderGUID() == guid)
return *itr;
GroupMap::const_iterator itr = mGroupMap.find(guid);
if (itr != mGroupMap.end())
return itr->second;
return NULL;
}
@ -225,16 +225,6 @@ Guild* ObjectMgr::GetGuildByLeader(const uint64 &guid) const
return NULL;
}
void ObjectMgr::AddGuild(Guild* guild)
{
mGuildMap[guild->GetId()] = guild;
}
void ObjectMgr::RemoveGuild(uint32 Id)
{
mGuildMap.erase(Id);
}
ArenaTeam* ObjectMgr::GetArenaTeamById(uint32 arenateamid) const
{
ArenaTeamMap::const_iterator itr = mArenaTeamMap.find(arenateamid);
@ -262,16 +252,6 @@ ArenaTeam* ObjectMgr::GetArenaTeamByCaptain(uint64 const& guid) const
return NULL;
}
void ObjectMgr::AddArenaTeam(ArenaTeam* arenaTeam)
{
mArenaTeamMap[arenaTeam->GetId()] = arenaTeam;
}
void ObjectMgr::RemoveArenaTeam(uint32 Id)
{
mArenaTeamMap.erase(Id);
}
CreatureInfo const* ObjectMgr::GetCreatureTemplate(uint32 id)
{
return sCreatureStorage.LookupEntry<CreatureInfo>(id);
@ -3128,8 +3108,6 @@ void ObjectMgr::LoadArenaTeams()
void ObjectMgr::LoadGroups()
{
// -- loading groups --
Group *group = NULL;
uint64 leaderGuid = 0;
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
QueryResult *result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups");
@ -3152,9 +3130,8 @@ void ObjectMgr::LoadGroups()
bar.step();
Field *fields = result->Fetch();
++count;
leaderGuid = MAKE_NEW_GUID(fields[16].GetUInt32(),0,HIGHGUID_PLAYER);
group = new Group;
uint64 leaderGuid = MAKE_NEW_GUID(fields[16].GetUInt32(),0,HIGHGUID_PLAYER);
Group *group = new Group;
if(!group->LoadGroupFromDB(leaderGuid, result, false))
{
group->Disband();
@ -3171,8 +3148,6 @@ void ObjectMgr::LoadGroups()
// -- loading members --
count = 0;
group = NULL;
leaderGuid = 0;
// 0 1 2 3
result = CharacterDatabase.Query("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid");
if(!result)
@ -3182,28 +3157,34 @@ void ObjectMgr::LoadGroups()
}
else
{
Group* group = NULL; // used as cached pointer for avoid relookup group for each member
barGoLink bar2( result->GetRowCount() );
do
{
bar2.step();
Field *fields = result->Fetch();
count++;
leaderGuid = MAKE_NEW_GUID(fields[3].GetUInt32(), 0, HIGHGUID_PLAYER);
if(!group || group->GetLeaderGUID() != leaderGuid)
uint32 memberGuidlow = fields[0].GetUInt32();
bool assistent = fields[1].GetBool();
uint8 subgroup = fields[2].GetUInt8();
uint32 leaderGuidLow = fields[3].GetUInt32();
if(!group || GUID_LOPART(group->GetLeaderGUID()) != leaderGuidLow)
{
group = GetGroupByLeader(leaderGuid);
group = GetGroupByLeaderLowGUID(leaderGuidLow);
if(!group)
{
sLog.outErrorDb("Incorrect entry in group_member table : no group with leader %d for member %d!", fields[3].GetUInt32(), fields[0].GetUInt32());
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields[0].GetUInt32());
sLog.outErrorDb("Incorrect entry in group_member table : no group with leader %d for member %d!", leaderGuidLow, memberGuidlow);
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", memberGuidlow);
continue;
}
}
if(!group->LoadMemberFromDB(fields[0].GetUInt32(), fields[2].GetUInt8(), fields[1].GetBool()))
if(!group->LoadMemberFromDB(memberGuidlow, subgroup, assistent))
{
sLog.outErrorDb("Incorrect entry in group_member table : member %d cannot be added to player %d's group!", fields[0].GetUInt32(), fields[3].GetUInt32());
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields[0].GetUInt32());
sLog.outErrorDb("Incorrect entry in group_member table : member %d cannot be added to player %d's group!", memberGuidlow, leaderGuidLow);
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", memberGuidlow);
}
}while( result->NextRow() );
delete result;
@ -3211,13 +3192,13 @@ void ObjectMgr::LoadGroups()
// clean groups
// TODO: maybe delete from the DB before loading in this case
for(GroupSet::iterator itr = mGroupSet.begin(); itr != mGroupSet.end();)
for (GroupMap::iterator itr = mGroupMap.begin(); itr != mGroupMap.end();)
{
if((*itr)->GetMembersCount() < 2)
if (itr->second->GetMembersCount() < 2)
{
(*itr)->Disband();
delete *itr;
mGroupSet.erase(itr++);
itr->second->Disband();
delete itr->second;
mGroupMap.erase(itr++);
}
else
++itr;
@ -3225,8 +3206,6 @@ void ObjectMgr::LoadGroups()
// -- loading instances --
count = 0;
group = NULL;
leaderGuid = 0;
result = CharacterDatabase.Query(
// 0 1 2 3 4 5
"SELECT leaderGuid, map, instance, permanent, difficulty, resettime, "
@ -3242,31 +3221,36 @@ void ObjectMgr::LoadGroups()
}
else
{
Group* group = NULL; // used as cached pointer for avoid relookup group for each member
barGoLink bar2( result->GetRowCount() );
do
{
bar2.step();
Field *fields = result->Fetch();
count++;
leaderGuid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
if(!group || group->GetLeaderGUID() != leaderGuid)
uint32 leaderGuidLow = fields[0].GetUInt32();
uint32 mapId = fields[1].GetUInt32();
uint32 diff = fields[4].GetUInt8();
if(!group || GUID_LOPART(group->GetLeaderGUID()) != leaderGuidLow)
{
group = GetGroupByLeader(leaderGuid);
group = GetGroupByLeaderLowGUID(leaderGuidLow);
if(!group)
{
sLog.outErrorDb("Incorrect entry in group_instance table : no group with leader %d", fields[0].GetUInt32());
sLog.outErrorDb("Incorrect entry in group_instance table : no group with leader %d", leaderGuidLow);
continue;
}
}
MapEntry const* mapEntry = sMapStore.LookupEntry(fields[1].GetUInt32());
MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
if(!mapEntry || !mapEntry->IsDungeon())
{
sLog.outErrorDb("Incorrect entry in group_instance table : no dungeon map %d", fields[1].GetUInt32());
sLog.outErrorDb("Incorrect entry in group_instance table : no dungeon map %d", mapId);
continue;
}
uint32 diff = fields[4].GetUInt8();
if(diff >= (mapEntry->IsRaid() ? MAX_RAID_DIFFICULTY : MAX_DUNGEON_DIFFICULTY))
{
sLog.outErrorDb("Wrong dungeon difficulty use in group_instance table: %d", diff + 1);
@ -7829,7 +7813,7 @@ void ObjectMgr::LoadTrainerSpell()
if(!(cInfo->npcflag & UNIT_NPC_FLAG_TRAINER))
{
if(skip_trainers.count(entry) == 0)
if (skip_trainers.find(entry) == skip_trainers.end())
{
sLog.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry);
skip_trainers.insert(entry);
@ -7852,7 +7836,7 @@ void ObjectMgr::LoadTrainerSpell()
if(GetTalentSpellCost(spell))
{
if(talentIds.count(spell)==0)
if (talentIds.find(spell) == talentIds.end())
{
sLog.outErrorDb("Table `npc_trainer` has talent as learning spell %u, ignore", spell);
talentIds.insert(spell);
@ -8380,7 +8364,7 @@ void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids)
if(!GetMangosStringLocale (itrM->second.dataint))
sLog.outErrorDb( "Table `db_script_string` is missing string id %u, used in database script id %u.", itrM->second.dataint, itrMM->first);
if(ids.count(itrM->second.dataint))
if (ids.find(itrM->second.dataint) != ids.end())
ids.erase(itrM->second.dataint);
}
}

View file

@ -33,6 +33,9 @@
#include "Database/DatabaseEnv.h"
#include "Mail.h"
#include "Map.h"
#include "Group.h"
#include "Guild.h"
#include "ArenaTeam.h"
#include "ObjectAccessor.h"
#include "ObjectDefines.h"
#include "Policies/Singleton.h"
@ -381,7 +384,7 @@ class ObjectMgr
typedef UNORDERED_MAP<uint32, Item*> ItemMap;
typedef std::set< Group * > GroupSet;
typedef UNORDERED_MAP<uint32, Group*> GroupMap;
typedef UNORDERED_MAP<uint32, Guild*> GuildMap;
@ -408,22 +411,22 @@ class ObjectMgr
void LoadGameobjectInfo();
void AddGameobjectInfo(GameObjectInfo *goinfo);
Group * GetGroupByLeader(const uint64 &guid) const;
void AddGroup(Group* group) { mGroupSet.insert( group ); }
void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
Group * GetGroupByLeaderLowGUID(uint32 lowguid) const;
void AddGroup(Group* group) { mGroupMap[GUID_LOPART(group->GetLeaderGUID())] = group ; }
void RemoveGroup(Group* group) { mGroupMap.erase(GUID_LOPART(group->GetLeaderGUID())); }
Guild* GetGuildByLeader(uint64 const&guid) const;
Guild* GetGuildById(uint32 GuildId) const;
Guild* GetGuildByName(const std::string& guildname) const;
std::string GetGuildNameById(uint32 GuildId) const;
void AddGuild(Guild* guild);
void RemoveGuild(uint32 Id);
void AddGuild(Guild* guild) { mGuildMap[guild->GetId()] = guild ; }
void RemoveGuild(uint32 Id) { mGuildMap.erase(Id); }
ArenaTeam* GetArenaTeamById(uint32 arenateamid) const;
ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
void AddArenaTeam(ArenaTeam* arenaTeam);
void RemoveArenaTeam(uint32 Id);
void AddArenaTeam(ArenaTeam* arenaTeam) { mArenaTeamMap[arenaTeam->GetId()] = arenaTeam; }
void RemoveArenaTeam(uint32 Id) { mArenaTeamMap.erase(Id); }
ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
@ -909,7 +912,7 @@ class ObjectMgr
typedef std::set<uint32> TavernAreaTriggerSet;
typedef std::set<uint32> GameObjectForQuestSet;
GroupSet mGroupSet;
GroupMap mGroupMap;
GuildMap mGuildMap;
ArenaTeamMap mArenaTeamMap;

View file

@ -3973,14 +3973,11 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
QueryResult *resultGroup = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid);
if(resultGroup)
{
uint64 leaderGuid = MAKE_NEW_GUID((*resultGroup)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
uint32 leaderGuidLow = (*resultGroup)[0].GetUInt32();
delete resultGroup;
Group* group = sObjectMgr.GetGroupByLeader(leaderGuid);
if(group)
{
if (Group* group = sObjectMgr.GetGroupByLeaderLowGUID(leaderGuidLow))
RemoveFromGroup(group, playerguid);
}
}
// remove signs from petitions (also remove petitions if owner);
RemovePetitionsAndSigns(playerguid, 10);
@ -15781,10 +15778,10 @@ void Player::_LoadGroup(QueryResult *result)
//QueryResult *result = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", GetGUIDLow());
if (result)
{
uint64 leaderGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
uint32 leaderGuidLow = (*result)[0].GetUInt32();
delete result;
if (Group* group = sObjectMgr.GetGroupByLeader(leaderGuid))
if (Group* group = sObjectMgr.GetGroupByLeaderLowGUID(leaderGuidLow))
{
uint8 subgroup = group->GetMemberGroup(GetGUID());
SetGroup(group, subgroup);

View file

@ -89,7 +89,7 @@ void LoadSkillDiscoveryTable()
SpellEntry const* reqSpellEntry = sSpellStore.LookupEntry(reqSkillOrSpell);
if (!reqSpellEntry)
{
if(reportedReqSpells.count(reqSkillOrSpell)==0)
if (reportedReqSpells.find(reqSkillOrSpell) == reportedReqSpells.end())
{
sLog.outErrorDb("Spell (ID: %u) have not existed spell (ID: %i) in `reqSpell` field in `skill_discovery_template` table",spellId,reqSkillOrSpell);
reportedReqSpells.insert(reqSkillOrSpell);
@ -102,7 +102,7 @@ void LoadSkillDiscoveryTable()
// explicit discovery ability
!IsExplicitDiscoverySpell(reqSpellEntry))
{
if (reportedReqSpells.count(reqSkillOrSpell)==0)
if (reportedReqSpells.find(reqSkillOrSpell) == reportedReqSpells.end())
{
sLog.outErrorDb("Spell (ID: %u) not have MECHANIC_DISCOVERY (28) value in Mechanic field in spell.dbc"
" and not 100%% chance random discovery ability but listed for spellId %u (and maybe more) in `skill_discovery_template` table",

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9227"
#define REVISION_NR "9228"
#endif // __REVISION_NR_H__