Core/Groups: Reuse group guids to stop endless growth

This commit is contained in:
leak
2011-02-22 23:47:32 +01:00
parent 44fc35bb07
commit b27735b590
3 changed files with 59 additions and 14 deletions

View File

@@ -285,7 +285,7 @@ ObjectMgr::~ObjectMgr()
delete[] playerInfo[race][class_].levelInfo;
// free group and guild objects
for (GroupSet::iterator itr = mGroupSet.begin(); itr != mGroupSet.end(); ++itr)
for (GroupMap::iterator itr = mGroupMap.begin(); itr != mGroupMap.end(); ++itr)
delete *itr;
for (GuildMap::iterator itr = mGuildMap.begin(); itr != mGuildMap.end(); ++itr)
@@ -303,10 +303,9 @@ ObjectMgr::~ObjectMgr()
Group * ObjectMgr::GetGroupByGUID(uint32 guid) const
{
for (GroupSet::const_iterator itr = mGroupSet.begin(); itr != mGroupSet.end(); ++itr)
if ((*itr)->GetLowGUID() == guid)
return *itr;
// Make sure given index exists in collection
if (guid < uint32(mGroupMap.size()))
return mGroupMap[guid];
return NULL;
}
@@ -3980,7 +3979,7 @@ void ObjectMgr::LoadGroups()
// 0 1 2 3 4 5 6 7 8 9
QueryResult result = CharacterDatabase.PQuery("SELECT leaderGuid, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6"
// 10 11 12 13 14 15
",icon7, icon8, groupType, difficulty, raiddifficulty, guid FROM groups");
",icon7, icon8, groupType, difficulty, raiddifficulty, guid FROM groups ORDER BY guid ASC");
if (!result)
{
sLog->outString(">> Loaded 0 group definitions. DB table `groups` is empty!");
@@ -3993,9 +3992,17 @@ void ObjectMgr::LoadGroups()
do
{
Field *fields = result->Fetch();
uint32 guid = fields[15].GetUInt32();
// Groups are pulled in ascending order from db and m_hiGroupGuid is initialized with 1,
// so if the group slot is used increment until we find the first free one for a potential new group
if (sObjectMgr->GetNextGroupGuid() == guid)
sObjectMgr->SetNextGroupGuid(guid + 1);
++count;
Group *group = new Group;
group->LoadGroupFromDB(fields[15].GetUInt32(), result, false);
group->LoadGroupFromDB(guid, result, false);
// group load will never be false (we have run consistency sql's before loading)
AddGroup(group);
}
@@ -6643,9 +6650,10 @@ void ObjectMgr::SetHighestGuids()
if (result)
m_guildId = (*result)[0].GetUInt32()+1;
// The next free guid is determined during group loading, here we just preallocate the group holder
result = CharacterDatabase.Query("SELECT MAX(guid) FROM groups");
if (result)
m_hiGroupGuid = (*result)[0].GetUInt32()+1;
mGroupMap.resize((*result)[0].GetUInt32()+1);
}
uint32 ObjectMgr::GenerateArenaTeamId()
@@ -6759,12 +6767,26 @@ uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh)
}
return m_hiDoGuid++;
case HIGHGUID_GROUP:
if (m_hiGroupGuid >= 0xFFFFFFFE)
{
uint32 newGuid = m_hiGroupGuid;
for (uint32 i = ++m_hiGroupGuid; i < 0xFFFFFFFF; ++i)
{
if (!GetGroupByGUID(i))
{
m_hiGroupGuid = i;
break;
}
}
// If newGuid doesn't differ from m_hiGroupGuid after the loop there is no free guid available
if (newGuid == m_hiGroupGuid)
{
sLog->outError("Group guid overflow!! Can't continue, shutting down server. ");
World::StopNow(ERROR_EXIT_CODE);
}
return m_hiGroupGuid++;
return newGuid;
}
case HIGHGUID_MO_TRANSPORT:
if (m_hiMoTransGuid >= 0xFFFFFFFE)
{
@@ -9424,3 +9446,18 @@ void ObjectMgr::LoadFactionChangeReputations()
sLog->outString(">> Loaded %u faction change reputation pairs in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
void ObjectMgr::AddGroup(Group* group)
{
uint32 groupGuid = group->GetLowGUID();
// Allocate space if necessary.
if (groupGuid >= uint32(mGroupMap.size()))
mGroupMap.resize(groupGuid + 1);
mGroupMap[groupGuid] = group;
}
void ObjectMgr::RemoveGroup(Group* group)
{
mGroupMap[group->GetLowGUID()] = NULL;
}

View File

@@ -591,7 +591,7 @@ class ObjectMgr
public:
typedef UNORDERED_MAP<uint32, Item*> ItemMap;
typedef std::set<Group *> GroupSet;
typedef std::vector<Group *> GroupMap;
typedef std::vector <Guild *> GuildMap;
@@ -626,8 +626,10 @@ class ObjectMgr
void AddGameobjectInfo(GameObjectInfo *goinfo);
Group * GetGroupByGUID(uint32 guid) const;
void AddGroup(Group* group) { mGroupSet.insert(group); }
void RemoveGroup(Group* group) { mGroupSet.erase(group); }
void AddGroup(Group* group);
void RemoveGroup(Group* group);
uint32 GetNextGroupGuid() { return m_hiGroupGuid; };
void SetNextGroupGuid(uint32 nextGuid) { m_hiGroupGuid = nextGuid; };
Guild* GetGuildByLeader(uint64 const&guid) const;
Guild* GetGuildById(uint32 guildId) const;
@@ -1269,7 +1271,7 @@ class ObjectMgr
typedef std::set<uint32> TavernAreaTriggerSet;
typedef std::set<uint32> GameObjectForQuestSet;
GroupSet mGroupSet;
GroupMap mGroupMap;
GuildMap mGuildMap;
ArenaTeamMap mArenaTeamMap;

View File

@@ -635,6 +635,12 @@ void Group::Disband(bool hideDestroy /* = false */)
CharacterDatabase.CommitTransaction(trans);
ResetInstances(INSTANCE_RESET_GROUP_DISBAND, false, NULL);
ResetInstances(INSTANCE_RESET_GROUP_DISBAND, true, NULL);
// If the deleted group guid is lower than the one we have stored for the next group creation,
// use this one instead.
if (lowguid < sObjectMgr->GetNextGroupGuid())
sObjectMgr->SetNextGroupGuid(lowguid);
}
sObjectMgr->RemoveGroup(this);