[9571] Create and use ObjectGuidGenerator/IdGenerator template classes.

* This is let finally hide guid structure in ObjectGuid.h/.cpp code.
* Shared related code.

NOTE: while switch to use new clasess one more problem has been detected
with not-safe code in .pdump work for future per-map multi-threading.
It's need rewrited before will possible safe use in like case.
For current single world thread case it's safe.
This commit is contained in:
VladimirMangos 2010-03-11 15:50:45 +03:00
parent 873b2cab99
commit c4f3578226
8 changed files with 206 additions and 234 deletions

View file

@ -17,22 +17,25 @@
*/
#include "ObjectGuid.h"
#include "World.h"
#include <sstream>
char const* ObjectGuid::GetTypeName() const
char const* ObjectGuid::GetTypeName(HighGuid high)
{
switch(GetHigh())
switch(high)
{
case HIGHGUID_ITEM: return "item";
case HIGHGUID_PLAYER: return !IsEmpty() ? "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_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";
default:
return "<unknown>";
}
@ -48,6 +51,17 @@ std::string ObjectGuid::GetString() const
return str.str();
}
template<HighGuid high>
uint32 ObjectGuidGenerator<high>::Generate()
{
if (m_nextGuid >= ObjectGuid::GetMaxCounter(high)-1)
{
sLog.outError("%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());
@ -71,3 +85,13 @@ ByteBuffer &operator>>(ByteBuffer& buf, PackedGuidReader const& guid)
guid.m_guidPtr->Set(buf.readPackGUID());
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();