diff options
| author | Shauren <shauren.trinity@gmail.com> | 2014-09-16 21:50:01 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2014-09-16 21:50:01 +0200 |
| commit | 7d1d55124c1e289748d2afefae896c97f710e57b (patch) | |
| tree | dcae6831f97fa1d353233fa7367800af1c4caa98 /src/server/game/Entities/Object | |
| parent | 6810a4469ebe6600be2f8649e917110a17ce27f3 (diff) | |
| parent | 9b933b4a291e377d4ae124eb8e3d2ba74b37f34f (diff) | |
Merge branch 'ObjectGuid' of https://github.com/TrinityCore/TrinityCore
Conflicts:
src/server/game/Entities/Player/Player.cpp
src/server/game/Entities/Player/Player.h
src/server/game/Scripting/MapScripts.cpp
src/server/scripts/Northrend/Naxxramas/instance_naxxramas.cpp
src/server/scripts/Northrend/Nexus/EyeOfEternity/instance_eye_of_eternity.cpp
src/server/scripts/Northrend/Nexus/Nexus/boss_anomalus.cpp
src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp
src/server/scripts/Northrend/Nexus/Oculus/boss_varos.cpp
src/server/scripts/Northrend/Ulduar/HallsOfStone/halls_of_stone.cpp
src/server/scripts/Northrend/Ulduar/Ulduar/boss_auriaya.cpp
src/server/scripts/Northrend/Ulduar/Ulduar/boss_freya.cpp
src/server/scripts/Northrend/Ulduar/Ulduar/boss_hodir.cpp
src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp
src/server/scripts/Northrend/Ulduar/Ulduar/boss_razorscale.cpp
src/server/scripts/Northrend/UtgardeKeep/UtgardePinnacle/boss_skadi.cpp
src/server/scripts/Northrend/UtgardeKeep/UtgardePinnacle/boss_svala.cpp
src/server/scripts/Northrend/UtgardeKeep/UtgardePinnacle/boss_ymiron.cpp
Diffstat (limited to 'src/server/game/Entities/Object')
| -rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 81 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/Object.h | 57 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/ObjectDefines.h | 186 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/ObjectGuid.cpp | 105 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/ObjectGuid.h | 262 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/Updates/UpdateData.cpp | 14 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/Updates/UpdateData.h | 9 |
7 files changed, 445 insertions, 269 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index e402836f4c2..71ab2abeba8 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -82,8 +82,6 @@ Object::Object() : m_PackGUID(sizeof(uint64)+1) m_inWorld = false; m_objectUpdated = false; - - m_PackGUID.appendPackGUID(0); } WorldObject::~WorldObject() @@ -93,8 +91,8 @@ WorldObject::~WorldObject() { if (GetTypeId() == TYPEID_CORPSE) { - TC_LOG_FATAL("misc", "Object::~Object Corpse guid=" UI64FMTD ", type=%d, entry=%u deleted but still in map!!", - GetGUID(), ((Corpse*)this)->GetType(), GetEntry()); + TC_LOG_FATAL("misc", "Object::~Object Corpse type=%d deleted but still in map!!", + GetGUID().ToString().c_str(), ((Corpse*)this)->GetType()); ASSERT(false); } ResetMap(); @@ -105,7 +103,7 @@ Object::~Object() { if (IsInWorld()) { - TC_LOG_FATAL("misc", "Object::~Object - guid=" UI64FMTD ", typeid=%d, entry=%u deleted but still in world!!", GetGUID(), GetTypeId(), GetEntry()); + TC_LOG_FATAL("misc", "Object::~Object %s but still in world!!", GetGUID().ToString().c_str()); if (isType(TYPEMASK_ITEM)) TC_LOG_FATAL("misc", "Item slot %u", ((Item*)this)->GetSlot()); ASSERT(false); @@ -114,7 +112,7 @@ Object::~Object() if (m_objectUpdated) { - TC_LOG_FATAL("misc", "Object::~Object - guid=" UI64FMTD ", typeid=%d, entry=%u deleted but still in update list!!", GetGUID(), GetTypeId(), GetEntry()); + TC_LOG_FATAL("misc", "Object::~Object %s deleted but still in update list!!", GetGUID().ToString().c_str()); ASSERT(false); sObjectAccessor->RemoveUpdateObject(this); } @@ -137,11 +135,10 @@ void Object::_Create(uint32 guidlow, uint32 entry, HighGuid guidhigh) { if (!m_uint32Values) _InitValues(); - uint64 guid = MAKE_NEW_GUID(guidlow, entry, guidhigh); - SetUInt64Value(OBJECT_FIELD_GUID, guid); + ObjectGuid guid(guidhigh, entry, guidlow); + SetGuidValue(OBJECT_FIELD_GUID, guid); SetUInt32Value(OBJECT_FIELD_TYPE, m_objectType); - m_PackGUID.wpos(0); - m_PackGUID.appendPackGUID(GetGUID()); + m_PackGUID.Set(guid); } std::string Object::_ConcatFields(uint16 startIndex, uint16 size) const @@ -181,7 +178,7 @@ void Object::BuildMovementUpdateBlock(UpdateData* data, uint32 flags) const ByteBuffer buf(500); buf << uint8(UPDATETYPE_MOVEMENT); - buf.append(GetPackGUID()); + buf << GetPackGUID(); BuildMovementUpdate(&buf, flags); @@ -237,7 +234,7 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c ByteBuffer buf(500); buf << uint8(updateType); - buf.append(GetPackGUID()); + buf << GetPackGUID(); buf << uint8(m_objectTypeId); BuildMovementUpdate(&buf, flags); @@ -261,7 +258,7 @@ void Object::BuildValuesUpdateBlockForPlayer(UpdateData* data, Player* target) c ByteBuffer buf(500); buf << uint8(UPDATETYPE_VALUES); - buf.append(GetPackGUID()); + buf << GetPackGUID(); BuildValuesUpdate(UPDATETYPE_VALUES, &buf, target); @@ -336,6 +333,12 @@ uint16 Object::GetUInt16Value(uint16 index, uint8 offset) const return *(((uint16*)&m_uint32Values[index])+offset); } +ObjectGuid Object::GetGuidValue(uint16 index) const +{ + ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, false)); + return *((ObjectGuid*)&(m_uint32Values[index])); +} + void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const { Unit const* unit = NULL; @@ -376,7 +379,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const Transport* transport = object->GetTransport(); if (transport) - data->append(transport->GetPackGUID()); + *data << transport->GetPackGUID(); else *data << uint8(0); @@ -465,7 +468,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const { ASSERT(unit); if (Unit* victim = unit->GetVictim()) - data->append(victim->GetPackGUID()); + *data << victim->GetPackGUID(); else *data << uint8(0); } @@ -687,13 +690,12 @@ void Object::SetUInt64Value(uint16 index, uint64 value) } } -bool Object::AddUInt64Value(uint16 index, uint64 value) +bool Object::AddGuidValue(uint16 index, ObjectGuid value) { ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, true)); - if (value && !*((uint64*)&(m_uint32Values[index]))) + if (value && !*((ObjectGuid*)&(m_uint32Values[index]))) { - m_uint32Values[index] = PAIR64_LOPART(value); - m_uint32Values[index + 1] = PAIR64_HIPART(value); + *((ObjectGuid*)&(m_uint32Values[index])) = value; _changesMask.SetBit(index); _changesMask.SetBit(index + 1); @@ -709,10 +711,10 @@ bool Object::AddUInt64Value(uint16 index, uint64 value) return false; } -bool Object::RemoveUInt64Value(uint16 index, uint64 value) +bool Object::RemoveGuidValue(uint16 index, ObjectGuid value) { ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, true)); - if (value && *((uint64*)&(m_uint32Values[index])) == value) + if (value && *((ObjectGuid*)&(m_uint32Values[index])) == value) { m_uint32Values[index] = 0; m_uint32Values[index + 1] = 0; @@ -796,6 +798,23 @@ void Object::SetUInt16Value(uint16 index, uint8 offset, uint16 value) } } +void Object::SetGuidValue(uint16 index, ObjectGuid value) +{ + ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, true)); + if (*((ObjectGuid*)&(m_uint32Values[index])) != value) + { + *((ObjectGuid*)&(m_uint32Values[index])) = value; + _changesMask.SetBit(index); + _changesMask.SetBit(index + 1); + + if (m_inWorld && !m_objectUpdated) + { + sObjectAccessor->AddUpdateObject(this); + m_objectUpdated = true; + } + } +} + void Object::SetStatFloatValue(uint16 index, float value) { if (value < 0) @@ -1072,7 +1091,7 @@ ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYZOStreamer const& st void MovementInfo::OutDebug() { TC_LOG_INFO("misc", "MOVEMENT INFO"); - TC_LOG_INFO("misc", "guid " UI64FMTD, guid); + TC_LOG_INFO("misc", "guid %s", guid.ToString().c_str()); TC_LOG_INFO("misc", "flags %u", flags); TC_LOG_INFO("misc", "flags2 %u", flags2); TC_LOG_INFO("misc", "time %u current time " UI64FMTD "", flags2, uint64(::time(NULL))); @@ -1080,7 +1099,7 @@ void MovementInfo::OutDebug() if (flags & MOVEMENTFLAG_ONTRANSPORT) { TC_LOG_INFO("misc", "TRANSPORT:"); - TC_LOG_INFO("misc", "guid: " UI64FMTD, transport.guid); + TC_LOG_INFO("misc", "guid: %s", transport.guid.ToString().c_str()); TC_LOG_INFO("misc", "position: `%s`", transport.pos.ToString().c_str()); TC_LOG_INFO("misc", "seat: %i", transport.seat); TC_LOG_INFO("misc", "time: %u", transport.time); @@ -1892,7 +1911,7 @@ void Object::ForceValuesUpdateAtIndex(uint32 i) void Unit::BuildHeartBeatMsg(WorldPacket* data) const { data->Initialize(MSG_MOVE_HEARTBEAT, 32); - data->append(GetPackGUID()); + *data << GetPackGUID(); BuildMovementPacket(data); } @@ -1914,7 +1933,7 @@ void WorldObject::SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr VisitNearbyWorldObject(GetVisibilityRange(), notifier); } -void WorldObject::SendObjectDeSpawnAnim(uint64 guid) +void WorldObject::SendObjectDeSpawnAnim(ObjectGuid guid) { WorldPacket data(SMSG_GAMEOBJECT_DESPAWN_ANIM, 8); data << uint64(guid); @@ -2611,7 +2630,7 @@ struct WorldObjectChangeAccumulator { UpdateDataMapType& i_updateDatas; WorldObject& i_object; - std::set<uint64> plr_list; + GuidSet plr_list; WorldObjectChangeAccumulator(WorldObject &obj, UpdateDataMapType &d) : i_updateDatas(d), i_object(obj) { } void Visit(PlayerMapType &m) { @@ -2652,13 +2671,13 @@ struct WorldObjectChangeAccumulator for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter) { source = iter->GetSource(); - uint64 guid = source->GetCasterGUID(); + ObjectGuid guid = source->GetCasterGUID(); - if (IS_PLAYER_GUID(guid)) + if (guid.IsPlayer()) { //Caster may be NULL if DynObj is in removelist if (Player* caster = ObjectAccessor::FindPlayer(guid)) - if (caster->GetUInt64Value(PLAYER_FARSIGHT) == source->GetGUID()) + if (caster->GetGuidValue(PLAYER_FARSIGHT) == source->GetGUID()) BuildPacket(caster); } } @@ -2691,9 +2710,9 @@ void WorldObject::BuildUpdate(UpdateDataMapType& data_map) ClearUpdateMask(false); } -uint64 WorldObject::GetTransGUID() const +ObjectGuid WorldObject::GetTransGUID() const { if (GetTransport()) return GetTransport()->GetGUID(); - return 0; + return ObjectGuid::Empty; } diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 652a4d4b71f..fcbb89408d0 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -46,33 +46,6 @@ #define NOMINAL_MELEE_RANGE 5.0f #define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players -enum TypeMask -{ - TYPEMASK_OBJECT = 0x0001, - TYPEMASK_ITEM = 0x0002, - TYPEMASK_CONTAINER = 0x0006, // TYPEMASK_ITEM | 0x0004 - TYPEMASK_UNIT = 0x0008, // creature - TYPEMASK_PLAYER = 0x0010, - TYPEMASK_GAMEOBJECT = 0x0020, - TYPEMASK_DYNAMICOBJECT = 0x0040, - TYPEMASK_CORPSE = 0x0080, - TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT -}; - -enum TypeID -{ - TYPEID_OBJECT = 0, - TYPEID_ITEM = 1, - TYPEID_CONTAINER = 2, - TYPEID_UNIT = 3, - TYPEID_PLAYER = 4, - TYPEID_GAMEOBJECT = 5, - TYPEID_DYNAMICOBJECT = 6, - TYPEID_CORPSE = 7 -}; - -#define NUM_CLIENT_OBJECT_TYPES 8 - uint32 GuidHigh2TypeId(uint32 guid_hi); enum TempSummonType @@ -128,11 +101,11 @@ class Object virtual void AddToWorld(); virtual void RemoveFromWorld(); - uint64 GetGUID() const { return GetUInt64Value(0); } - uint32 GetGUIDLow() const { return GUID_LOPART(GetUInt64Value(0)); } - uint32 GetGUIDMid() const { return GUID_ENPART(GetUInt64Value(0)); } - uint32 GetGUIDHigh() const { return GUID_HIPART(GetUInt64Value(0)); } - const ByteBuffer& GetPackGUID() const { return m_PackGUID; } + 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); } @@ -157,6 +130,7 @@ class Object float GetFloatValue(uint16 index) const; uint8 GetByteValue(uint16 index, uint8 offset) const; uint16 GetUInt16Value(uint16 index, uint8 offset) const; + ObjectGuid GetGuidValue(uint16 index) const; void SetInt32Value(uint16 index, int32 value); void SetUInt32Value(uint16 index, uint32 value); @@ -166,11 +140,12 @@ class Object void SetByteValue(uint16 index, uint8 offset, uint8 value); void SetUInt16Value(uint16 index, uint8 offset, uint16 value); void SetInt16Value(uint16 index, uint8 offset, int16 value) { SetUInt16Value(index, offset, (uint16)value); } + void SetGuidValue(uint16 index, ObjectGuid value); void SetStatFloatValue(uint16 index, float value); void SetStatInt32Value(uint16 index, int32 value); - bool AddUInt64Value(uint16 index, uint64 value); - bool RemoveUInt64Value(uint16 index, uint64 value); + bool AddGuidValue(uint16 index, ObjectGuid value); + bool RemoveGuidValue(uint16 index, ObjectGuid value); void ApplyModUInt32Value(uint16 index, int32 val, bool apply); void ApplyModInt32Value(uint16 index, int32 val, bool apply); @@ -265,7 +240,7 @@ class Object private: bool m_inWorld; - ByteBuffer m_PackGUID; + PackedGuid m_PackGUID; // for output helpfull error messages from asserts bool PrintIndexError(uint32 index, bool set) const; @@ -410,7 +385,7 @@ ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYZOStreamer const& st struct MovementInfo { // common - uint64 guid; + ObjectGuid guid; uint32 flags; uint16 flags2; Position pos; @@ -421,14 +396,14 @@ struct MovementInfo { void Reset() { - guid = 0; + guid.Clear(); pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f); seat = -1; time = 0; time2 = 0; } - uint64 guid; + ObjectGuid guid; Position pos; int8 seat; uint32 time; @@ -457,7 +432,7 @@ struct MovementInfo float splineElevation; MovementInfo() : - guid(0), flags(0), flags2(0), time(0), pitch(0.0f), fallTime(0), splineElevation(0.0f) + guid(), flags(0), flags2(0), time(0), pitch(0.0f), fallTime(0), splineElevation(0.0f) { pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f); transport.Reset(); @@ -655,7 +630,7 @@ class WorldObject : public Object, public WorldLocation void PlayDistanceSound(uint32 sound_id, Player* target = NULL); void PlayDirectSound(uint32 sound_id, Player* target = NULL); - void SendObjectDeSpawnAnim(uint64 guid); + void SendObjectDeSpawnAnim(ObjectGuid guid); virtual void SaveRespawnTime() { } void AddObjectToRemoveList(); @@ -739,7 +714,7 @@ class WorldObject : public Object, public WorldLocation float GetTransOffsetO() const { return m_movementInfo.transport.pos.GetOrientation(); } uint32 GetTransTime() const { return m_movementInfo.transport.time; } int8 GetTransSeat() const { return m_movementInfo.transport.seat; } - virtual uint64 GetTransGUID() const; + virtual ObjectGuid GetTransGUID() const; void SetTransport(Transport* t) { m_transport = t; } MovementInfo m_movementInfo; diff --git a/src/server/game/Entities/Object/ObjectDefines.h b/src/server/game/Entities/Object/ObjectDefines.h index 236f77caf5a..3b7709bc1f1 100644 --- a/src/server/game/Entities/Object/ObjectDefines.h +++ b/src/server/game/Entities/Object/ObjectDefines.h @@ -20,22 +20,7 @@ #define TRINITY_OBJECTDEFINES_H #include "Define.h" - -enum HighGuid -{ - HIGHGUID_ITEM = 0x4000, // blizz 4000 - HIGHGUID_CONTAINER = 0x4000, // blizz 4000 - HIGHGUID_PLAYER = 0x0000, // blizz 0000 - HIGHGUID_GAMEOBJECT = 0xF110, // blizz F110 - HIGHGUID_TRANSPORT = 0xF120, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT) - HIGHGUID_UNIT = 0xF130, // blizz F130 - HIGHGUID_PET = 0xF140, // blizz F140 - HIGHGUID_VEHICLE = 0xF150, // blizz F550 - HIGHGUID_DYNAMICOBJECT = 0xF100, // blizz F100 - HIGHGUID_CORPSE = 0xF101, // blizz F100 - HIGHGUID_MO_TRANSPORT = 0x1FC0, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT) - HIGHGUID_GROUP = 0x1F50 -}; +#include "ObjectGuid.h" // used for creating values for respawn for example inline uint64 MAKE_PAIR64(uint32 l, uint32 h); @@ -46,35 +31,6 @@ inline uint32 MAKE_PAIR32(uint16 l, uint16 h); inline uint16 PAIR32_HIPART(uint32 x); inline uint16 PAIR32_LOPART(uint32 x); -inline bool IS_EMPTY_GUID(uint64 guid); -inline bool IS_CREATURE_GUID(uint64 guid); -inline bool IS_PET_GUID(uint64 guid); -inline bool IS_VEHICLE_GUID(uint64 guid); -inline bool IS_CRE_OR_VEH_GUID(uint64 guid); -inline bool IS_CRE_OR_VEH_OR_PET_GUID(uint64 guid); -inline bool IS_PLAYER_GUID(uint64 guid); -inline bool IS_UNIT_GUID(uint64 guid); -inline bool IS_ITEM_GUID(uint64 guid); -inline bool IS_GAMEOBJECT_GUID(uint64 guid); -inline bool IS_DYNAMICOBJECT_GUID(uint64 guid); -inline bool IS_CORPSE_GUID(uint64 guid); -inline bool IS_TRANSPORT_GUID(uint64 guid); -inline bool IS_MO_TRANSPORT_GUID(uint64 guid); -inline bool IS_GROUP_GUID(uint64 guid); - -// l - OBJECT_FIELD_GUID -// e - OBJECT_FIELD_ENTRY for GO (except GAMEOBJECT_TYPE_MO_TRANSPORT) and creatures or UNIT_FIELD_PETNUMBER for pets -// h - OBJECT_FIELD_GUID + 1 -inline uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h); - -//#define GUID_HIPART(x) (uint32)((uint64(x) >> 52)) & 0x0000FFFF) -inline uint32 GUID_HIPART(uint64 guid); -inline uint32 GUID_ENPART(uint64 x); -inline uint32 GUID_LOPART(uint64 x); - -inline bool IsGuidHaveEnPart(uint64 guid); -inline char const* GetLogNameForGuid(uint64 guid); - uint64 MAKE_PAIR64(uint32 l, uint32 h) { return uint64(l | (uint64(h) << 32)); @@ -110,144 +66,4 @@ uint16 PAIR32_LOPART(uint32 x) return (uint16)(x & 0x0000FFFF); } -bool IS_EMPTY_GUID(uint64 guid) -{ - return guid == 0; -} - -bool IS_CREATURE_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_UNIT; -} - -bool IS_PET_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_PET; -} - -bool IS_VEHICLE_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_VEHICLE; -} - -bool IS_CRE_OR_VEH_GUID(uint64 guid) -{ - return IS_CREATURE_GUID(guid) || IS_VEHICLE_GUID(guid); -} - -bool IS_CRE_OR_VEH_OR_PET_GUID(uint64 guid) -{ - return IS_CRE_OR_VEH_GUID(guid) || IS_PET_GUID(guid); -} - -bool IS_PLAYER_GUID(uint64 guid) -{ - return guid != 0 && GUID_HIPART(guid) == HIGHGUID_PLAYER; -} - -bool IS_UNIT_GUID(uint64 guid) -{ - return IS_CRE_OR_VEH_OR_PET_GUID(guid) || IS_PLAYER_GUID(guid); -} - -bool IS_ITEM_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_ITEM; -} - -bool IS_GAMEOBJECT_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_GAMEOBJECT; -} - -bool IS_DYNAMICOBJECT_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_DYNAMICOBJECT; -} - -bool IS_CORPSE_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_CORPSE; -} - -bool IS_TRANSPORT_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_TRANSPORT; -} - -bool IS_MO_TRANSPORT_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_MO_TRANSPORT; -} - -bool IS_GROUP_GUID(uint64 guid) -{ - return GUID_HIPART(guid) == HIGHGUID_GROUP; -} - -uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h) -{ - return uint64(uint64(l) | (uint64(e) << 24) | (uint64(h) << 48)); -} - -uint32 GUID_HIPART(uint64 guid) -{ - return (uint32)((uint64(guid) >> 48) & 0x0000FFFF); -} - -uint32 GUID_ENPART(uint64 x) -{ - return IsGuidHaveEnPart(x) - ? (uint32)((x >> 24) & UI64LIT(0x0000000000FFFFFF)) - : 0; -} - -uint32 GUID_LOPART(uint64 x) -{ - return IsGuidHaveEnPart(x) - ? (uint32)(x & UI64LIT(0x0000000000FFFFFF)) - : (uint32)(x & UI64LIT(0x00000000FFFFFFFF)); -} - -bool IsGuidHaveEnPart(uint64 guid) -{ - switch (GUID_HIPART(guid)) - { - case HIGHGUID_ITEM: - case HIGHGUID_PLAYER: - case HIGHGUID_DYNAMICOBJECT: - case HIGHGUID_CORPSE: - case HIGHGUID_GROUP: - return false; - case HIGHGUID_GAMEOBJECT: - case HIGHGUID_TRANSPORT: - case HIGHGUID_UNIT: - case HIGHGUID_PET: - case HIGHGUID_VEHICLE: - case HIGHGUID_MO_TRANSPORT: - default: - return true; - } -} - -char const* GetLogNameForGuid(uint64 guid) -{ - switch (GUID_HIPART(guid)) - { - case HIGHGUID_ITEM: return "item"; - case HIGHGUID_PLAYER: return guid ? "player" : "none"; - 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_MO_TRANSPORT: return "mo_transport"; - case HIGHGUID_GROUP: return "group"; - default: - return "<unknown>"; - } -} - #endif diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp new file mode 100644 index 00000000000..cf40e248808 --- /dev/null +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "ObjectGuid.h" +#include "World.h" +#include "ObjectMgr.h" +#include <sstream> +#include <iomanip> + +ObjectGuid const ObjectGuid::Empty = ObjectGuid(); + +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_MO_TRANSPORT: return "MoTransport"; + case HIGHGUID_INSTANCE: return "InstanceID"; + case HIGHGUID_GROUP: return "Group"; + default: + return "<unknown>"; + } +} + +std::string ObjectGuid::ToString() const +{ + std::ostringstream str; + str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << m_guid << std::dec; + str << " Type: " << GetTypeName(); + if (HasEntry()) + str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " "; + + str << " Low: " << GetCounter(); + return str.str(); +} + +template<HighGuid high> +uint32 ObjectGuidGenerator<high>::Generate() +{ + if (m_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 m_nextGuid++; +} + +ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid) +{ + buf << uint64(guid.GetRawValue()); + return buf; +} + +ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid) +{ + guid.Set(buf.read<uint64>()); + return buf; +} + +ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid) +{ + buf.append(guid.m_packedGuid); + return buf; +} + +ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid) +{ + buf.readPackGUID(*reinterpret_cast<uint64*>(guid.m_guidPtr)); + 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_INSTANCE>::Generate(); +template uint32 ObjectGuidGenerator<HIGHGUID_GROUP>::Generate(); diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h new file mode 100644 index 00000000000..30b7b1e0293 --- /dev/null +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ObjectGuid_h__ +#define ObjectGuid_h__ + +#include "Common.h" +#include "ByteBuffer.h" + +#include <functional> + +enum TypeID +{ + TYPEID_OBJECT = 0, + TYPEID_ITEM = 1, + TYPEID_CONTAINER = 2, + TYPEID_UNIT = 3, + TYPEID_PLAYER = 4, + TYPEID_GAMEOBJECT = 5, + TYPEID_DYNAMICOBJECT = 6, + TYPEID_CORPSE = 7 +}; + +#define NUM_CLIENT_OBJECT_TYPES 8 + +enum TypeMask +{ + TYPEMASK_OBJECT = 0x0001, + TYPEMASK_ITEM = 0x0002, + TYPEMASK_CONTAINER = 0x0006, // TYPEMASK_ITEM | 0x0004 + TYPEMASK_UNIT = 0x0008, // creature + TYPEMASK_PLAYER = 0x0010, + TYPEMASK_GAMEOBJECT = 0x0020, + TYPEMASK_DYNAMICOBJECT = 0x0040, + TYPEMASK_CORPSE = 0x0080, + TYPEMASK_SEER = TYPEMASK_PLAYER | TYPEMASK_UNIT | TYPEMASK_DYNAMICOBJECT +}; + +enum HighGuid +{ + HIGHGUID_ITEM = 0x4000, // blizz 4000 + HIGHGUID_CONTAINER = 0x4000, // blizz 4000 + HIGHGUID_PLAYER = 0x0000, // blizz 0000 + HIGHGUID_GAMEOBJECT = 0xF110, // blizz F110 + HIGHGUID_TRANSPORT = 0xF120, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT) + HIGHGUID_UNIT = 0xF130, // blizz F130 + HIGHGUID_PET = 0xF140, // blizz F140 + HIGHGUID_VEHICLE = 0xF150, // blizz F550 + HIGHGUID_DYNAMICOBJECT = 0xF100, // blizz F100 + HIGHGUID_CORPSE = 0xF101, // blizz F100 + HIGHGUID_MO_TRANSPORT = 0x1FC0, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT) + HIGHGUID_INSTANCE = 0x1F40, // blizz 1F40 + HIGHGUID_GROUP = 0x1F50 +}; + +class ObjectGuid; +class PackedGuid; + +struct PackedGuidReader +{ + explicit PackedGuidReader(ObjectGuid& guid) : m_guidPtr(&guid) {} + ObjectGuid* m_guidPtr; +}; + +class ObjectGuid +{ + public: + static ObjectGuid const Empty; + + ObjectGuid() : m_guid(0) {} + explicit ObjectGuid(uint64 guid) : m_guid(guid) {} + ObjectGuid(HighGuid hi, uint32 entry, uint32 counter) : m_guid(counter ? uint64(counter) | (uint64(entry) << 24) | (uint64(hi) << 48) : 0) {} + ObjectGuid(HighGuid hi, uint32 counter) : m_guid(counter ? uint64(counter) | (uint64(hi) << 48) : 0) {} + + operator uint64() const { return m_guid; } + PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); } + + void Set(uint64 guid) { m_guid = guid; } + void Clear() { m_guid = 0; } + + PackedGuid WriteAsPacked() const; + + uint64 GetRawValue() const { return m_guid; } + HighGuid GetHigh() const { return HighGuid((m_guid >> 48) & 0x0000FFFF); } + uint32 GetEntry() const { return HasEntry() ? uint32((m_guid >> 24) & UI64LIT(0x0000000000FFFFFF)) : 0; } + uint32 GetCounter() const + { + return HasEntry() + ? uint32(m_guid & UI64LIT(0x0000000000FFFFFF)) + : uint32(m_guid & UI64LIT(0x00000000FFFFFFFF)); + } + + static uint32 GetMaxCounter(HighGuid high) + { + return HasEntry(high) + ? uint32(0x00FFFFFF) + : uint32(0xFFFFFFFF); + } + + uint32 GetMaxCounter() const { return GetMaxCounter(GetHigh()); } + + bool IsEmpty() const { return m_guid == 0; } + 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 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 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; } + + 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_MO_TRANSPORT: return TYPEID_GAMEOBJECT; + case HIGHGUID_VEHICLE: return TYPEID_UNIT; + // unknown + case HIGHGUID_INSTANCE: + case HIGHGUID_GROUP: + default: return TYPEID_OBJECT; + } + } + + TypeID GetTypeId() const { return GetTypeId(GetHigh()); } + + bool operator!() const { return IsEmpty(); } + bool operator== (ObjectGuid const& guid) const { return GetRawValue() == guid.GetRawValue(); } + bool operator!= (ObjectGuid const& guid) const { return GetRawValue() != guid.GetRawValue(); } + bool operator< (ObjectGuid const& guid) const { return GetRawValue() < guid.GetRawValue(); } + + static char const* GetTypeName(HighGuid high); + char const* GetTypeName() const { return !IsEmpty() ? GetTypeName(GetHigh()) : "None"; } + std::string ToString() const; + + private: + static bool HasEntry(HighGuid high) + { + switch (high) + { + 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: + default: + return true; + } + } + + bool HasEntry() const { return HasEntry(GetHigh()); } + + 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 + + uint64 m_guid; +}; + +// Some Shared defines +typedef std::set<ObjectGuid> GuidSet; +typedef std::list<ObjectGuid> GuidList; +typedef std::deque<ObjectGuid> GuidDeque; +typedef std::vector<ObjectGuid> GuidVector; + +// minimum buffer size for packed guid is 9 bytes +#define PACKED_GUID_MIN_BUFFER_SIZE 9 + +class PackedGuid +{ + friend ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid); + + public: // constructors + explicit PackedGuid() : m_packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { m_packedGuid.appendPackGUID(0); } + explicit PackedGuid(uint64 guid) : m_packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { m_packedGuid.appendPackGUID(guid); } + explicit PackedGuid(ObjectGuid guid) : m_packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { m_packedGuid.appendPackGUID(guid.GetRawValue()); } + + void Set(uint64 guid) { m_packedGuid.wpos(0); m_packedGuid.appendPackGUID(guid); } + void Set(ObjectGuid guid) { m_packedGuid.wpos(0); m_packedGuid.appendPackGUID(guid.GetRawValue()); } + + size_t size() const { return m_packedGuid.size(); } + + private: // fields + ByteBuffer m_packedGuid; +}; + +template<HighGuid high> +class ObjectGuidGenerator +{ + public: // constructors + explicit ObjectGuidGenerator(uint32 start = 1) : m_nextGuid(start) {} + + void Set(uint32 val) { m_nextGuid = val; } + uint32 Generate(); + uint32 GetNextAfterMaxUsed() const { return m_nextGuid; } + + private: // fields + uint32 m_nextGuid; +}; + +ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid); +ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid); + +ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid); +ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid); + +inline PackedGuid ObjectGuid::WriteAsPacked() const { return PackedGuid(*this); } + +namespace std +{ + template<> + class hash<ObjectGuid> + { + public: + size_t operator()(ObjectGuid const& key) const + { + return hash<uint64>()(key.GetRawValue()); + } + }; +} + +#endif // ObjectGuid_h__ diff --git a/src/server/game/Entities/Object/Updates/UpdateData.cpp b/src/server/game/Entities/Object/Updates/UpdateData.cpp index f6ac0bc67cc..98eaa3184e4 100644 --- a/src/server/game/Entities/Object/Updates/UpdateData.cpp +++ b/src/server/game/Entities/Object/Updates/UpdateData.cpp @@ -27,12 +27,12 @@ UpdateData::UpdateData() : m_blockCount(0) { } -void UpdateData::AddOutOfRangeGUID(std::set<uint64>& guids) +void UpdateData::AddOutOfRangeGUID(GuidSet& guids) { m_outOfRangeGUIDs.insert(guids.begin(), guids.end()); } -void UpdateData::AddOutOfRangeGUID(uint64 guid) +void UpdateData::AddOutOfRangeGUID(ObjectGuid guid) { m_outOfRangeGUIDs.insert(guid); } @@ -109,13 +109,11 @@ bool UpdateData::BuildPacket(WorldPacket* packet) if (!m_outOfRangeGUIDs.empty()) { - buf << (uint8) UPDATETYPE_OUT_OF_RANGE_OBJECTS; - buf << (uint32) m_outOfRangeGUIDs.size(); + buf << uint8(UPDATETYPE_OUT_OF_RANGE_OBJECTS); + buf << uint32(m_outOfRangeGUIDs.size()); - for (std::set<uint64>::const_iterator i = m_outOfRangeGUIDs.begin(); i != m_outOfRangeGUIDs.end(); ++i) - { - buf.appendPackGUID(*i); - } + for (GuidSet::const_iterator i = m_outOfRangeGUIDs.begin(); i != m_outOfRangeGUIDs.end(); ++i) + buf << i->WriteAsPacked(); } buf.append(m_data); diff --git a/src/server/game/Entities/Object/Updates/UpdateData.h b/src/server/game/Entities/Object/Updates/UpdateData.h index 1ec86192fab..d1305deabd8 100644 --- a/src/server/game/Entities/Object/Updates/UpdateData.h +++ b/src/server/game/Entities/Object/Updates/UpdateData.h @@ -20,6 +20,7 @@ #define __UPDATEDATA_H #include "ByteBuffer.h" +#include "ObjectGuid.h" #include <set> class WorldPacket; @@ -59,18 +60,18 @@ class UpdateData { } - void AddOutOfRangeGUID(std::set<uint64>& guids); - void AddOutOfRangeGUID(uint64 guid); + void AddOutOfRangeGUID(GuidSet& guids); + void AddOutOfRangeGUID(ObjectGuid guid); void AddUpdateBlock(const ByteBuffer &block); bool BuildPacket(WorldPacket* packet); bool HasData() const { return m_blockCount > 0 || !m_outOfRangeGUIDs.empty(); } void Clear(); - std::set<uint64> const& GetOutOfRangeGUIDs() const { return m_outOfRangeGUIDs; } + GuidSet const& GetOutOfRangeGUIDs() const { return m_outOfRangeGUIDs; } protected: uint32 m_blockCount; - std::set<uint64> m_outOfRangeGUIDs; + GuidSet m_outOfRangeGUIDs; ByteBuffer m_data; void Compress(void* dst, uint32 *dst_size, void* src, int src_size); |
