Map local guids 6.x -> 4.3.4
Ported the following commits: https://github.com/TrinityCore/TrinityCore/commit/ca83e14f8b141fab0a13e08f48fca6c1ace0c4c7 https://github.com/TrinityCore/TrinityCore/commit/ee1c1b97be4492ecabe8b15ea6323fc37e4eaa8c https://github.com/TrinityCore/TrinityCore/commit/18e4ab6911468b829b0fc768e532a770263c3717 https://github.com/TrinityCore/TrinityCore/commit/bf37446b3c2ed73b4d3aa9e227d3eff5c53b378b https://github.com/TrinityCore/TrinityCore/commit/cb854a2b7bb7bd96cf9c4d1daf3789f797bf4db8
This commit is contained in:
1 parent
694c89d76d
commit
b3ea9fbbe5
163 files changed
+2448
-2328
No files matched your search
@@ -90,14 +90,12 @@ Object::~Object()
|
||||
if (isType(TYPEMASK_ITEM))
|
||||
TC_LOG_FATAL("misc", "Item slot %u", ((Item*)this)->GetSlot());
|
||||
ASSERT(false);
|
||||
RemoveFromWorld();
|
||||
}
|
||||
|
||||
if (m_objectUpdated)
|
||||
{
|
||||
TC_LOG_FATAL("misc", "Object::~Object %s deleted but still in update list!!", GetGUID().ToString().c_str());
|
||||
ASSERT(false);
|
||||
sObjectAccessor->RemoveUpdateObject(this);
|
||||
}
|
||||
|
||||
delete [] m_uint32Values;
|
||||
@@ -142,7 +140,8 @@ void Object::AddToWorld()
|
||||
m_inWorld = true;
|
||||
|
||||
// synchronize values mirror with values array (changes will send in updatecreate opcode any way
|
||||
ClearUpdateMask(true);
|
||||
ASSERT(!m_objectUpdated);
|
||||
ClearUpdateMask(false);
|
||||
}
|
||||
|
||||
void Object::RemoveFromWorld()
|
||||
@@ -168,17 +167,17 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c
|
||||
if (target == this) // building packet for yourself
|
||||
flags |= UPDATEFLAG_SELF;
|
||||
|
||||
switch (GetGUIDHigh())
|
||||
switch (GetGUID().GetHigh())
|
||||
{
|
||||
case HIGHGUID_PLAYER:
|
||||
case HIGHGUID_PET:
|
||||
case HIGHGUID_CORPSE:
|
||||
case HIGHGUID_DYNAMICOBJECT:
|
||||
case HIGHGUID_AREATRIGGER:
|
||||
case HighGuid::Player:
|
||||
case HighGuid::Pet:
|
||||
case HighGuid::Corpse:
|
||||
case HighGuid::DynamicObject:
|
||||
case HighGuid::AreaTrigger:
|
||||
updateType = UPDATETYPE_CREATE_OBJECT2;
|
||||
break;
|
||||
case HIGHGUID_UNIT:
|
||||
case HIGHGUID_VEHICLE:
|
||||
case HighGuid::Unit:
|
||||
case HighGuid::Vehicle:
|
||||
{
|
||||
if (TempSummon const* summon = ToUnit()->ToTempSummon())
|
||||
if (summon->GetSummonerGUID().IsPlayer())
|
||||
@@ -186,7 +185,7 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c
|
||||
|
||||
break;
|
||||
}
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
case HighGuid::GameObject:
|
||||
{
|
||||
if (ToGameObject()->GetOwnerGUID().IsPlayer())
|
||||
updateType = UPDATETYPE_CREATE_OBJECT2;
|
||||
@@ -692,6 +691,15 @@ void Object::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* targe
|
||||
data->append(fieldBuffer);
|
||||
}
|
||||
|
||||
void Object::AddToObjectUpdateIfNeeded()
|
||||
{
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
AddToObjectUpdate();
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Object::ClearUpdateMask(bool remove)
|
||||
{
|
||||
_changesMask.Clear();
|
||||
@@ -699,7 +707,7 @@ void Object::ClearUpdateMask(bool remove)
|
||||
if (m_objectUpdated)
|
||||
{
|
||||
if (remove)
|
||||
sObjectAccessor->RemoveUpdateObject(this);
|
||||
RemoveFromObjectUpdate();
|
||||
m_objectUpdated = false;
|
||||
}
|
||||
}
|
||||
@@ -800,11 +808,7 @@ void Object::SetInt32Value(uint16 index, int32 value)
|
||||
m_int32Values[index] = value;
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,11 +821,7 @@ void Object::SetUInt32Value(uint16 index, uint32 value)
|
||||
m_uint32Values[index] = value;
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -843,11 +843,7 @@ void Object::SetUInt64Value(uint16 index, uint64 value)
|
||||
_changesMask.SetBit(index);
|
||||
_changesMask.SetBit(index + 1);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -860,11 +856,7 @@ bool Object::AddGuidValue(uint16 index, ObjectGuid value)
|
||||
_changesMask.SetBit(index);
|
||||
_changesMask.SetBit(index + 1);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -882,11 +874,7 @@ bool Object::RemoveGuidValue(uint16 index, ObjectGuid value)
|
||||
_changesMask.SetBit(index);
|
||||
_changesMask.SetBit(index + 1);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -903,11 +891,7 @@ void Object::SetFloatValue(uint16 index, float value)
|
||||
m_floatValues[index] = value;
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,11 +911,7 @@ void Object::SetByteValue(uint16 index, uint8 offset, uint8 value)
|
||||
m_uint32Values[index] |= uint32(uint32(value) << (offset * 8));
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -951,11 +931,7 @@ void Object::SetUInt16Value(uint16 index, uint8 offset, uint16 value)
|
||||
m_uint32Values[index] |= uint32(uint32(value) << (offset * 16));
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -968,11 +944,7 @@ void Object::SetGuidValue(uint16 index, ObjectGuid value)
|
||||
_changesMask.SetBit(index);
|
||||
_changesMask.SetBit(index + 1);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1042,11 +1014,7 @@ void Object::SetFlag(uint16 index, uint32 newFlag)
|
||||
m_uint32Values[index] = newval;
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,11 +1031,7 @@ void Object::RemoveFlag(uint16 index, uint32 oldFlag)
|
||||
m_uint32Values[index] = newval;
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1107,11 +1071,7 @@ void Object::SetByteFlag(uint16 index, uint8 offset, uint8 newFlag)
|
||||
m_uint32Values[index] |= uint32(uint32(newFlag) << (offset * 8));
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1130,11 +1090,7 @@ void Object::RemoveByteFlag(uint16 index, uint8 offset, uint8 oldFlag)
|
||||
m_uint32Values[index] &= ~uint32(uint32(oldFlag) << (offset * 8));
|
||||
_changesMask.SetBit(index);
|
||||
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1349,7 +1305,7 @@ bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool
|
||||
float sizefactor = GetObjectSize() + obj->GetObjectSize();
|
||||
float maxdist = dist2compare + sizefactor;
|
||||
|
||||
if (GetTransport() && obj->GetTransport() && obj->GetTransport()->GetGUIDLow() == GetTransport()->GetGUIDLow())
|
||||
if (GetTransport() && obj->GetTransport() && obj->GetTransport()->GetGUID().GetCounter() == GetTransport()->GetGUID().GetCounter())
|
||||
{
|
||||
float dtx = m_movementInfo.transport.pos.m_positionX - obj->m_movementInfo.transport.pos.m_positionX;
|
||||
float dty = m_movementInfo.transport.pos.m_positionY - obj->m_movementInfo.transport.pos.m_positionY;
|
||||
@@ -1931,11 +1887,7 @@ bool WorldObject::CanDetectStealthOf(WorldObject const* obj, bool checkAlert) co
|
||||
void Object::ForceValuesUpdateAtIndex(uint32 i)
|
||||
{
|
||||
_changesMask.SetBit(i);
|
||||
if (m_inWorld && !m_objectUpdated)
|
||||
{
|
||||
sObjectAccessor->AddUpdateObject(this);
|
||||
m_objectUpdated = true;
|
||||
}
|
||||
AddToObjectUpdateIfNeeded();
|
||||
}
|
||||
|
||||
void WorldObject::SendMessageToSet(WorldPacket* data, bool self)
|
||||
@@ -2006,7 +1958,7 @@ void WorldObject::AddObjectToRemoveList()
|
||||
Map* map = FindMap();
|
||||
if (!map)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "Object (TypeId: %u Entry: %u GUID: %u) at attempt add to move list not have valid map (Id: %u).", GetTypeId(), GetEntry(), GetGUIDLow(), GetMapId());
|
||||
TC_LOG_ERROR("misc", "Object (TypeId: %u Entry: %u GUID: %u) at attempt add to move list not have valid map (Id: %u).", GetTypeId(), GetEntry(), GetGUID().GetCounter(), GetMapId());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2083,7 +2035,7 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
|
||||
break;
|
||||
}
|
||||
|
||||
if (!summon->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), this, 0, entry, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), nullptr, vehId))
|
||||
if (!summon->Create(GenerateLowGuid<HighGuid::Unit>(), this, 0, entry, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), nullptr, vehId))
|
||||
{
|
||||
delete summon;
|
||||
return NULL;
|
||||
@@ -2140,6 +2092,11 @@ void WorldObject::SetZoneScript()
|
||||
}
|
||||
}
|
||||
|
||||
void WorldObject::ClearZoneScript()
|
||||
{
|
||||
m_zoneScript = nullptr;
|
||||
}
|
||||
|
||||
TempSummon* WorldObject::SummonCreature(uint32 entry, const Position &pos, TempSummonType spwtype, uint32 duration, uint32 /*vehId*/) const
|
||||
{
|
||||
if (Map* map = FindMap())
|
||||
@@ -2180,7 +2137,7 @@ GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float
|
||||
|
||||
Map* map = GetMap();
|
||||
GameObject* go = new GameObject();
|
||||
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), entry, map, GetPhaseMask(), x, y, z, ang, rotation0, rotation1, rotation2, rotation3, 100, GO_STATE_READY))
|
||||
if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, GetPhaseMask(), x, y, z, ang, rotation0, rotation1, rotation2, rotation3, 100, GO_STATE_READY))
|
||||
{
|
||||
delete go;
|
||||
return NULL;
|
||||
@@ -2466,7 +2423,7 @@ void WorldObject::MovePosition(Position &pos, float dist, float angle)
|
||||
if (!Trinity::IsValidMapCoord(destx, desty, pos.m_positionZ))
|
||||
{
|
||||
TC_LOG_FATAL("misc", "WorldObject::MovePosition: Object (TypeId: %u Entry: %u GUID: %u) has invalid coordinates X: %f and Y: %f were passed!",
|
||||
GetTypeId(), GetEntry(), GetGUIDLow(), destx, desty);
|
||||
GetTypeId(), GetEntry(), GetGUID().GetCounter(), destx, desty);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2889,6 +2846,16 @@ void WorldObject::BuildUpdate(UpdateDataMapType& data_map)
|
||||
ClearUpdateMask(false);
|
||||
}
|
||||
|
||||
void WorldObject::AddToObjectUpdate()
|
||||
{
|
||||
GetMap()->AddUpdateObject(this);
|
||||
}
|
||||
|
||||
void WorldObject::RemoveFromObjectUpdate()
|
||||
{
|
||||
GetMap()->RemoveUpdateObject(this);
|
||||
}
|
||||
|
||||
ObjectGuid WorldObject::GetTransGUID() const
|
||||
{
|
||||
if (GetTransport())
|
||||
|
||||
@@ -103,9 +103,6 @@ class Object
|
||||
virtual void RemoveFromWorld();
|
||||
|
||||
ObjectGuid GetGUID() const { return GetGuidValue(OBJECT_FIELD_GUID); }
|
||||
uint32 GetGUIDLow() const { return GetGuidValue(OBJECT_FIELD_GUID).GetCounter(); }
|
||||
uint32 GetGUIDMid() const { return GetGuidValue(OBJECT_FIELD_GUID).GetEntry(); }
|
||||
uint32 GetGUIDHigh() const { return GetGuidValue(OBJECT_FIELD_GUID).GetHigh(); }
|
||||
PackedGuid const& GetPackGUID() const { return m_PackGUID; }
|
||||
uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); }
|
||||
void SetEntry(uint32 entry) { SetUInt32Value(OBJECT_FIELD_ENTRY, entry); }
|
||||
@@ -222,6 +219,10 @@ class Object
|
||||
|
||||
uint16 m_objectType;
|
||||
|
||||
virtual void AddToObjectUpdate() = 0;
|
||||
virtual void RemoveFromObjectUpdate() = 0;
|
||||
void AddToObjectUpdateIfNeeded();
|
||||
|
||||
TypeID m_objectTypeId;
|
||||
uint16 m_updateFlag;
|
||||
|
||||
@@ -569,6 +570,7 @@ class WorldObject : public Object, public WorldLocation
|
||||
Map const* GetBaseMap() const;
|
||||
|
||||
void SetZoneScript();
|
||||
void ClearZoneScript();
|
||||
ZoneScript* GetZoneScript() const { return m_zoneScript; }
|
||||
|
||||
TempSummon* SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const;
|
||||
@@ -589,6 +591,9 @@ class WorldObject : public Object, public WorldLocation
|
||||
virtual void UpdateObjectVisibility(bool forced = true);
|
||||
void BuildUpdate(UpdateDataMapType&) override;
|
||||
|
||||
void AddToObjectUpdate() override;
|
||||
void RemoveFromObjectUpdate() override;
|
||||
|
||||
//relocation and visibility system functions
|
||||
void AddToNotify(uint16 f) { m_notifyflags |= f;}
|
||||
bool isNeedNotify(uint16 f) const { return (m_notifyflags & f) != 0; }
|
||||
|
||||
@@ -28,21 +28,21 @@ char const* ObjectGuid::GetTypeName(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HIGHGUID_ITEM: return "Item";
|
||||
case HIGHGUID_PLAYER: return "Player";
|
||||
case HIGHGUID_GAMEOBJECT: return "Gameobject";
|
||||
case HIGHGUID_TRANSPORT: return "Transport";
|
||||
case HIGHGUID_UNIT: return "Creature";
|
||||
case HIGHGUID_PET: return "Pet";
|
||||
case HIGHGUID_VEHICLE: return "Vehicle";
|
||||
case HIGHGUID_DYNAMICOBJECT: return "DynObject";
|
||||
case HIGHGUID_CORPSE: return "Corpse";
|
||||
case HIGHGUID_AREATRIGGER: return "AreaTrigger";
|
||||
case HIGHGUID_BATTLEGROUND: return "Battleground";
|
||||
case HIGHGUID_MO_TRANSPORT: return "MoTransport";
|
||||
case HIGHGUID_INSTANCE: return "InstanceID";
|
||||
case HIGHGUID_GROUP: return "Group";
|
||||
case HIGHGUID_GUILD: return "Guild";
|
||||
case HighGuid::Item: return "Item";
|
||||
case HighGuid::Player: return "Player";
|
||||
case HighGuid::GameObject: return "Gameobject";
|
||||
case HighGuid::Transport: return "Transport";
|
||||
case HighGuid::Unit: return "Creature";
|
||||
case HighGuid::Pet: return "Pet";
|
||||
case HighGuid::Vehicle: return "Vehicle";
|
||||
case HighGuid::DynamicObject: return "DynObject";
|
||||
case HighGuid::Corpse: return "Corpse";
|
||||
case HighGuid::AreaTrigger: return "AreaTrigger";
|
||||
case HighGuid::BattleGround: return "Battleground";
|
||||
case HighGuid::Mo_Transport: return "MoTransport";
|
||||
case HighGuid::Instance: return "InstanceID";
|
||||
case HighGuid::Group: return "Group";
|
||||
case HighGuid::Guild: return "Guild";
|
||||
default:
|
||||
return "<unknown>";
|
||||
}
|
||||
@@ -60,15 +60,14 @@ std::string ObjectGuid::ToString() const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
template<HighGuid high>
|
||||
uint32 ObjectGuidGenerator<high>::Generate()
|
||||
ObjectGuid ObjectGuid::Global(HighGuid type, LowType counter)
|
||||
{
|
||||
if (_nextGuid >= ObjectGuid::GetMaxCounter(high) - 1)
|
||||
{
|
||||
TC_LOG_ERROR("", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(high));
|
||||
World::StopNow(ERROR_EXIT_CODE);
|
||||
}
|
||||
return _nextGuid++;
|
||||
return ObjectGuid(type, counter);
|
||||
}
|
||||
|
||||
ObjectGuid ObjectGuid::MapSpecific(HighGuid type, uint32 entry, LowType counter)
|
||||
{
|
||||
return ObjectGuid(type, entry, counter);
|
||||
}
|
||||
|
||||
ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid)
|
||||
@@ -95,17 +94,8 @@ ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid)
|
||||
return buf;
|
||||
}
|
||||
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_ITEM>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_PLAYER>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_GAMEOBJECT>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_TRANSPORT>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_UNIT>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_PET>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_VEHICLE>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_DYNAMICOBJECT>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_CORPSE>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_AREATRIGGER>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_BATTLEGROUND>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_INSTANCE>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_GROUP>::Generate();
|
||||
template uint32 ObjectGuidGenerator<HIGHGUID_GUILD>::Generate();
|
||||
void ObjectGuidGeneratorBase::HandleCounterOverflow(HighGuid high)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(high));
|
||||
World::StopNow(ERROR_EXIT_CODE);
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Common.h"
|
||||
#include "ByteBuffer.h"
|
||||
|
||||
#include <type_traits>
|
||||
#include <functional>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -54,26 +55,67 @@ enum TypeMask
|
||||
TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT
|
||||
};
|
||||
|
||||
enum HighGuid
|
||||
enum class HighGuid
|
||||
{
|
||||
HIGHGUID_ITEM = 0x400, // blizz 4000
|
||||
HIGHGUID_CONTAINER = 0x400, // blizz 4000
|
||||
HIGHGUID_PLAYER = 0x000, // blizz 0000
|
||||
HIGHGUID_GAMEOBJECT = 0xF11, // blizz F110
|
||||
HIGHGUID_TRANSPORT = 0xF12, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT)
|
||||
HIGHGUID_UNIT = 0xF13, // blizz F130
|
||||
HIGHGUID_PET = 0xF14, // blizz F140
|
||||
HIGHGUID_VEHICLE = 0xF15, // blizz F550
|
||||
HIGHGUID_DYNAMICOBJECT = 0xF10, // blizz F100
|
||||
HIGHGUID_CORPSE = 0xF101, // blizz F100
|
||||
HIGHGUID_AREATRIGGER = 0xF102,
|
||||
HIGHGUID_BATTLEGROUND = 0x1F1,
|
||||
HIGHGUID_MO_TRANSPORT = 0x1FC, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT)
|
||||
HIGHGUID_INSTANCE = 0x1F4, // blizz 1F40
|
||||
HIGHGUID_GROUP = 0x1F5,
|
||||
HIGHGUID_GUILD = 0x1FF
|
||||
Item = 0x400, // blizz 4000
|
||||
Container = 0x400, // blizz 4000
|
||||
Player = 0x000, // blizz 0000
|
||||
GameObject = 0xF11, // blizz F110
|
||||
Transport = 0xF12, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT)
|
||||
Unit = 0xF13, // blizz F130
|
||||
Pet = 0xF14, // blizz F140
|
||||
Vehicle = 0xF15, // blizz F550
|
||||
DynamicObject = 0xF10, // blizz F100
|
||||
Corpse = 0xF101, // blizz F100
|
||||
AreaTrigger = 0xF102,
|
||||
BattleGround = 0x1F1,
|
||||
Mo_Transport = 0x1FC, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT)
|
||||
Instance = 0x1F4, // blizz 1F40
|
||||
Group = 0x1F5,
|
||||
Guild = 0x1FF
|
||||
};
|
||||
|
||||
template<HighGuid guid>
|
||||
struct ObjectGuidTraits
|
||||
{
|
||||
static bool const Global = false;
|
||||
static bool const MapSpecific = false;
|
||||
};
|
||||
|
||||
#define GUID_TRAIT_GLOBAL(highguid) \
|
||||
template<> struct ObjectGuidTraits<highguid> \
|
||||
{ \
|
||||
static bool const Global = true; \
|
||||
static bool const MapSpecific = false; \
|
||||
}
|
||||
|
||||
#define GUID_TRAIT_MAP_SPECIFIC(highguid) \
|
||||
template<> struct ObjectGuidTraits<highguid> \
|
||||
{ \
|
||||
static bool const Global = false; \
|
||||
static bool const MapSpecific = true; \
|
||||
}
|
||||
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Mo_Transport);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Group);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Instance);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::BattleGround);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Player);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Item);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Transport);
|
||||
GUID_TRAIT_GLOBAL(HighGuid::Guild);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::Unit);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::Vehicle);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::Pet);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::GameObject);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::DynamicObject);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::Corpse);
|
||||
GUID_TRAIT_MAP_SPECIFIC(HighGuid::AreaTrigger);
|
||||
|
||||
#undef GUID_TRAIT_GLOBAL
|
||||
#undef GUID_TRAIT_REALM_SPECIFIC
|
||||
#undef GUID_TRAIT_MAP_SPECIFIC
|
||||
|
||||
class ObjectGuid;
|
||||
class PackedGuid;
|
||||
|
||||
@@ -90,10 +132,16 @@ class ObjectGuid
|
||||
|
||||
typedef uint32 LowType;
|
||||
|
||||
template<HighGuid type>
|
||||
static typename std::enable_if<ObjectGuidTraits<type>::Global, ObjectGuid>::type Create(LowType counter) { return Global(type, counter); }
|
||||
|
||||
template<HighGuid type>
|
||||
static typename std::enable_if<ObjectGuidTraits<type>::MapSpecific, ObjectGuid>::type Create(uint32 entry, LowType counter) { return MapSpecific(type, entry, counter); }
|
||||
|
||||
ObjectGuid() { _data._guid = UI64LIT(0); }
|
||||
explicit ObjectGuid(uint64 guid) { _data._guid = guid; }
|
||||
ObjectGuid(HighGuid hi, uint32 entry, uint32 counter) { _data._guid = counter ? uint64(counter) | (uint64(entry) << 32) | (uint64(hi) << ((hi == HIGHGUID_CORPSE || hi == HIGHGUID_AREATRIGGER) ? 48 : 52)) : 0; }
|
||||
ObjectGuid(HighGuid hi, uint32 counter) { _data._guid = counter ? uint64(counter) | (uint64(hi) << ((hi == HIGHGUID_CORPSE || hi == HIGHGUID_AREATRIGGER) ? 48 : 52)) : 0; }
|
||||
ObjectGuid(HighGuid hi, uint32 entry, uint32 counter) { _data._guid = counter ? uint64(counter) | (uint64(entry) << 32) | (uint64(hi) << ((hi == HighGuid::Corpse || hi == HighGuid::AreaTrigger) ? 48 : 52)) : 0; }
|
||||
ObjectGuid(HighGuid hi, uint32 counter) { _data._guid = counter ? uint64(counter) | (uint64(hi) << ((hi == HighGuid::Corpse || hi == HighGuid::AreaTrigger) ? 48 : 52)) : 0; }
|
||||
ObjectGuid(ObjectGuid const& r) : _data(r._data) { }
|
||||
ObjectGuid(ObjectGuid&& r) : _data(r._data) { }
|
||||
|
||||
@@ -111,8 +159,8 @@ class ObjectGuid
|
||||
uint64 GetRawValue() const { return _data._guid; }
|
||||
HighGuid GetHigh() const
|
||||
{
|
||||
uint32 temp = ((uint64(_data._guid) >> 48) & 0x0000FFFF);
|
||||
return HighGuid((temp == HIGHGUID_CORPSE || temp == HIGHGUID_AREATRIGGER) ? temp : ((temp >> 4) & 0x00000FFF));
|
||||
HighGuid temp = static_cast<HighGuid>((uint64(_data._guid) >> 48) & 0x0000FFFF);
|
||||
return HighGuid((temp == HighGuid::Corpse || temp == HighGuid::AreaTrigger) ? temp : HighGuid(((uint32)temp >> 4) & 0x00000FFF));
|
||||
}
|
||||
uint32 GetEntry() const { return HasEntry() ? uint32((_data._guid >> 32) & UI64LIT(0x00000000000FFFFF)) : 0; }
|
||||
uint32 GetCounter() const
|
||||
@@ -140,48 +188,48 @@ class ObjectGuid
|
||||
}
|
||||
|
||||
bool IsEmpty() const { return _data._guid == 0; }
|
||||
bool IsCreature() const { return GetHigh() == HIGHGUID_UNIT; }
|
||||
bool IsPet() const { return GetHigh() == HIGHGUID_PET; }
|
||||
bool IsVehicle() const { return GetHigh() == HIGHGUID_VEHICLE; }
|
||||
bool IsCreature() const { return GetHigh() == HighGuid::Unit; }
|
||||
bool IsPet() const { return GetHigh() == HighGuid::Pet; }
|
||||
bool IsVehicle() const { return GetHigh() == HighGuid::Vehicle; }
|
||||
bool IsCreatureOrPet() const { return IsCreature() || IsPet(); }
|
||||
bool IsCreatureOrVehicle() const { return IsCreature() || IsVehicle(); }
|
||||
bool IsAnyTypeCreature() const { return IsCreature() || IsPet() || IsVehicle(); }
|
||||
bool IsPlayer() const { return !IsEmpty() && GetHigh() == HIGHGUID_PLAYER; }
|
||||
bool IsPlayer() const { return !IsEmpty() && GetHigh() == HighGuid::Player; }
|
||||
bool IsUnit() const { return IsAnyTypeCreature() || IsPlayer(); }
|
||||
bool IsItem() const { return GetHigh() == HIGHGUID_ITEM; }
|
||||
bool IsGameObject() const { return GetHigh() == HIGHGUID_GAMEOBJECT; }
|
||||
bool IsDynamicObject() const { return GetHigh() == HIGHGUID_DYNAMICOBJECT; }
|
||||
bool IsCorpse() const { return GetHigh() == HIGHGUID_CORPSE; }
|
||||
bool IsAreaTrigger() const { return GetHigh() == HIGHGUID_AREATRIGGER; }
|
||||
bool IsBattleground() const { return GetHigh() == HIGHGUID_BATTLEGROUND; }
|
||||
bool IsTransport() const { return GetHigh() == HIGHGUID_TRANSPORT; }
|
||||
bool IsMOTransport() const { return GetHigh() == HIGHGUID_MO_TRANSPORT; }
|
||||
bool IsItem() const { return GetHigh() == HighGuid::Item; }
|
||||
bool IsGameObject() const { return GetHigh() == HighGuid::GameObject; }
|
||||
bool IsDynamicObject() const { return GetHigh() == HighGuid::DynamicObject; }
|
||||
bool IsCorpse() const { return GetHigh() == HighGuid::Corpse; }
|
||||
bool IsAreaTrigger() const { return GetHigh() == HighGuid::AreaTrigger; }
|
||||
bool IsBattleground() const { return GetHigh() == HighGuid::BattleGround; }
|
||||
bool IsTransport() const { return GetHigh() == HighGuid::Transport; }
|
||||
bool IsMOTransport() const { return GetHigh() == HighGuid::Mo_Transport; }
|
||||
bool IsAnyTypeGameObject() const { return IsGameObject() || IsTransport() || IsMOTransport(); }
|
||||
bool IsInstance() const { return GetHigh() == HIGHGUID_INSTANCE; }
|
||||
bool IsGroup() const { return GetHigh() == HIGHGUID_GROUP; }
|
||||
bool IsGuild() const { return GetHigh() == HIGHGUID_GUILD; }
|
||||
bool IsInstance() const { return GetHigh() == HighGuid::Instance; }
|
||||
bool IsGroup() const { return GetHigh() == HighGuid::Group; }
|
||||
bool IsGuild() const { return GetHigh() == HighGuid::Guild; }
|
||||
|
||||
static TypeID GetTypeId(HighGuid high)
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HIGHGUID_ITEM: return TYPEID_ITEM;
|
||||
//case HIGHGUID_CONTAINER: return TYPEID_CONTAINER; HIGHGUID_CONTAINER==HIGHGUID_ITEM currently
|
||||
case HIGHGUID_UNIT: return TYPEID_UNIT;
|
||||
case HIGHGUID_PET: return TYPEID_UNIT;
|
||||
case HIGHGUID_PLAYER: return TYPEID_PLAYER;
|
||||
case HIGHGUID_GAMEOBJECT: return TYPEID_GAMEOBJECT;
|
||||
case HIGHGUID_DYNAMICOBJECT: return TYPEID_DYNAMICOBJECT;
|
||||
case HIGHGUID_CORPSE: return TYPEID_CORPSE;
|
||||
case HIGHGUID_AREATRIGGER: return TYPEID_AREATRIGGER;
|
||||
case HIGHGUID_MO_TRANSPORT: return TYPEID_GAMEOBJECT;
|
||||
case HIGHGUID_VEHICLE: return TYPEID_UNIT;
|
||||
case HighGuid::Item: return TYPEID_ITEM;
|
||||
//case HighGuid::Container: return TYPEID_CONTAINER; HighGuid::Container==HighGuid::Item currently
|
||||
case HighGuid::Unit: return TYPEID_UNIT;
|
||||
case HighGuid::Pet: return TYPEID_UNIT;
|
||||
case HighGuid::Player: return TYPEID_PLAYER;
|
||||
case HighGuid::GameObject: return TYPEID_GAMEOBJECT;
|
||||
case HighGuid::DynamicObject: return TYPEID_DYNAMICOBJECT;
|
||||
case HighGuid::Corpse: return TYPEID_CORPSE;
|
||||
case HighGuid::AreaTrigger: return TYPEID_AREATRIGGER;
|
||||
case HighGuid::Mo_Transport: return TYPEID_GAMEOBJECT;
|
||||
case HighGuid::Vehicle: return TYPEID_UNIT;
|
||||
// unknown
|
||||
case HIGHGUID_INSTANCE:
|
||||
case HIGHGUID_BATTLEGROUND:
|
||||
case HIGHGUID_GROUP:
|
||||
case HIGHGUID_GUILD:
|
||||
default: return TYPEID_OBJECT;
|
||||
case HighGuid::Instance:
|
||||
case HighGuid::BattleGround:
|
||||
case HighGuid::Group:
|
||||
case HighGuid::Guild:
|
||||
default: return TYPEID_OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,19 +249,19 @@ class ObjectGuid
|
||||
{
|
||||
switch (high)
|
||||
{
|
||||
case HIGHGUID_ITEM:
|
||||
case HIGHGUID_PLAYER:
|
||||
case HIGHGUID_DYNAMICOBJECT:
|
||||
case HIGHGUID_CORPSE:
|
||||
case HIGHGUID_MO_TRANSPORT:
|
||||
case HIGHGUID_INSTANCE:
|
||||
case HIGHGUID_GROUP:
|
||||
case HighGuid::Item:
|
||||
case HighGuid::Player:
|
||||
case HighGuid::DynamicObject:
|
||||
case HighGuid::Corpse:
|
||||
case HighGuid::Mo_Transport:
|
||||
case HighGuid::Instance:
|
||||
case HighGuid::Group:
|
||||
return false;
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
case HIGHGUID_TRANSPORT:
|
||||
case HIGHGUID_UNIT:
|
||||
case HIGHGUID_PET:
|
||||
case HIGHGUID_VEHICLE:
|
||||
case HighGuid::GameObject:
|
||||
case HighGuid::Transport:
|
||||
case HighGuid::Unit:
|
||||
case HighGuid::Pet:
|
||||
case HighGuid::Vehicle:
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@@ -221,6 +269,9 @@ class ObjectGuid
|
||||
|
||||
bool HasEntry() const { return HasEntry(GetHigh()); }
|
||||
|
||||
static ObjectGuid Global(HighGuid type, LowType counter);
|
||||
static ObjectGuid MapSpecific(HighGuid type, uint32 entry, LowType counter);
|
||||
|
||||
explicit ObjectGuid(uint32 const&) = delete; // no implementation, used to catch wrong type assignment
|
||||
ObjectGuid(HighGuid, uint32, uint64 counter) = delete; // no implementation, used to catch wrong type assignment
|
||||
ObjectGuid(HighGuid, uint64 counter) = delete; // no implementation, used to catch wrong type assignment
|
||||
@@ -260,18 +311,32 @@ class PackedGuid
|
||||
ByteBuffer _packedGuid;
|
||||
};
|
||||
|
||||
template<HighGuid high>
|
||||
class ObjectGuidGenerator
|
||||
class ObjectGuidGeneratorBase
|
||||
{
|
||||
public:
|
||||
explicit ObjectGuidGenerator(uint32 start = 1) : _nextGuid(start) { }
|
||||
ObjectGuidGeneratorBase(ObjectGuid::LowType start = 1) : _nextGuid(start) { }
|
||||
|
||||
void Set(uint32 val) { _nextGuid = val; }
|
||||
uint32 Generate();
|
||||
uint32 GetNextAfterMaxUsed() const { return _nextGuid; }
|
||||
virtual void Set(ObjectGuid::LowType val) { _nextGuid = val; }
|
||||
virtual ObjectGuid::LowType Generate() = 0;
|
||||
ObjectGuid::LowType GetNextAfterMaxUsed() const { return _nextGuid; }
|
||||
|
||||
private:
|
||||
uint32 _nextGuid;
|
||||
protected:
|
||||
static void HandleCounterOverflow(HighGuid high);
|
||||
ObjectGuid::LowType _nextGuid;
|
||||
};
|
||||
|
||||
template<HighGuid high>
|
||||
class ObjectGuidGenerator : public ObjectGuidGeneratorBase
|
||||
{
|
||||
public:
|
||||
explicit ObjectGuidGenerator(ObjectGuid::LowType start = 1) : ObjectGuidGeneratorBase(start) { }
|
||||
|
||||
ObjectGuid::LowType Generate() override
|
||||
{
|
||||
if (_nextGuid >= ObjectGuid::GetMaxCounter(high) - 1)
|
||||
HandleCounterOverflow(high);
|
||||
return _nextGuid++;
|
||||
}
|
||||
};
|
||||
|
||||
ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid);
|
||||
|
||||
Reference in new issue
Block a user