feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
parent
91081f4ad8
commit
f4c226423d
568 changed files with 10655 additions and 11019 deletions
100
src/server/game/Entities/Object/ObjectGuid.cpp
Normal file
100
src/server/game/Entities/Object/ObjectGuid.cpp
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2008-2021 TrinityCore <http://www.trinitycore.org/>
|
||||
*/
|
||||
|
||||
#include "ObjectGuid.h"
|
||||
#include "Log.h"
|
||||
#include "World.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') << _guid << std::dec;
|
||||
str << " Type: " << GetTypeName();
|
||||
if (HasEntry())
|
||||
str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " ";
|
||||
|
||||
str << " Low: " << GetCounter();
|
||||
return str.str();
|
||||
}
|
||||
|
||||
ObjectGuid ObjectGuid::Global(HighGuid type, LowType counter)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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._packedGuid);
|
||||
return buf;
|
||||
}
|
||||
|
||||
ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid)
|
||||
{
|
||||
buf.readPackGUID(reinterpret_cast<uint64&>(guid.Guid));
|
||||
return buf;
|
||||
}
|
||||
|
||||
void ObjectGuidGeneratorBase::HandleCounterOverflow(HighGuid high)
|
||||
{
|
||||
LOG_ERROR("server", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(high));
|
||||
World::StopNow(ERROR_EXIT_CODE);
|
||||
}
|
||||
|
||||
#define GUID_TRAIT_INSTANTIATE_GUID( HIGH_GUID ) \
|
||||
template class ObjectGuidGenerator< HIGH_GUID >;
|
||||
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Container)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Player)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::GameObject)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Transport)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Unit)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Pet)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Vehicle)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::DynamicObject)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Mo_Transport)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Instance)
|
||||
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Group)
|
||||
Loading…
Add table
Add a link
Reference in a new issue