feat(Core): GUID recycler (#1820)
Automatically recycle GUIDs, thus avoiding crashes when reaching the limit of data type "int" in MySQL.
This commit is contained in:
@@ -6198,7 +6198,12 @@ void ObjectMgr::SetHighestGuids()
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM creature");
|
||||
if (result)
|
||||
{
|
||||
_hiCreatureGuid = (*result)[0].GetUInt32()+1;
|
||||
_hiCreatureRecycledGuid = _hiCreatureGuid;
|
||||
_hiCreatureRecycledGuidMax = _hiCreatureRecycledGuid + 10000;
|
||||
_hiCreatureGuid = _hiCreatureRecycledGuidMax + 1;
|
||||
}
|
||||
|
||||
result = CharacterDatabase.Query("SELECT MAX(guid) FROM item_instance");
|
||||
if (result)
|
||||
@@ -6212,7 +6217,12 @@ void ObjectMgr::SetHighestGuids()
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject");
|
||||
if (result)
|
||||
{
|
||||
_hiGoGuid = (*result)[0].GetUInt32()+1;
|
||||
_hiGoRecycledGuid = _hiGoGuid;
|
||||
_hiGoRecycledGuidMax = _hiGoRecycledGuid + 1;
|
||||
_hiGoGuid = _hiGoRecycledGuidMax + 1;
|
||||
}
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM transports");
|
||||
if (result)
|
||||
@@ -6341,6 +6351,31 @@ uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh)
|
||||
}
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::GenerateRecycledLowGuid(HighGuid guidHigh)
|
||||
{
|
||||
switch (guidHigh)
|
||||
{
|
||||
case HIGHGUID_UNIT:
|
||||
{
|
||||
ASSERT(_hiCreatureRecycledGuid < 0x00FFFFFE && "Creature recycled guid overflow!");
|
||||
if (_hiCreatureRecycledGuid < _hiCreatureRecycledGuidMax)
|
||||
return _hiCreatureRecycledGuid++;
|
||||
break;
|
||||
}
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
{
|
||||
ASSERT(_hiGoRecycledGuid < 0x00FFFFFE && "Gameobject recycled guid overflow!");
|
||||
if (_hiGoRecycledGuid < _hiGoRecycledGuidMax)
|
||||
return _hiGoRecycledGuid++;
|
||||
break;
|
||||
}
|
||||
default: // Default case is not handled by the recycler
|
||||
break;
|
||||
}
|
||||
|
||||
return GenerateLowGuid(guidHigh);
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadGameObjectLocales()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
@@ -1057,6 +1057,7 @@ class ObjectMgr
|
||||
|
||||
void SetHighestGuids();
|
||||
uint32 GenerateLowGuid(HighGuid guidhigh);
|
||||
uint32 GenerateRecycledLowGuid(HighGuid guidHigh);
|
||||
uint32 GenerateAuctionID();
|
||||
uint64 GenerateEquipmentSetGuid();
|
||||
uint32 GenerateMailID();
|
||||
@@ -1354,6 +1355,11 @@ class ObjectMgr
|
||||
uint32 _hiCorpseGuid; ACE_Thread_Mutex _hiCorpseGuidMutex;
|
||||
uint32 _hiMoTransGuid; ACE_Thread_Mutex _hiMoTransGuidMutex;
|
||||
|
||||
uint32 _hiCreatureRecycledGuidMax;
|
||||
uint32 _hiCreatureRecycledGuid;
|
||||
uint32 _hiGoRecycledGuidMax;
|
||||
uint32 _hiGoRecycledGuid;
|
||||
|
||||
QuestMap _questTemplates;
|
||||
std::vector<Quest*> _questTemplatesFast; // pussywizard
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
Map* map = player->GetMap();
|
||||
|
||||
GameObject* object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject();
|
||||
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
|
||||
uint32 guidLow = sObjectMgr->GenerateRecycledLowGuid(HIGHGUID_GAMEOBJECT);
|
||||
|
||||
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, G3D::Quat(), 0, GO_STATE_READY))
|
||||
{
|
||||
|
||||
@@ -212,7 +212,7 @@ public:
|
||||
if (Transport* tt = chr->GetTransport())
|
||||
if (MotionTransport* trans = tt->ToMotionTransport())
|
||||
{
|
||||
uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT);
|
||||
uint32 guid = sObjectMgr->GenerateRecycledLowGuid(HIGHGUID_UNIT);
|
||||
CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
|
||||
data.id = id;
|
||||
data.phaseMask = chr->GetPhaseMaskForSpawn();
|
||||
@@ -230,7 +230,7 @@ public:
|
||||
}
|
||||
|
||||
Creature* creature = new Creature();
|
||||
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
|
||||
if (!creature->Create(sObjectMgr->GenerateRecycledLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
|
||||
{
|
||||
delete creature;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user