/// <summary> /// This method is used when loading existing entity IDs to track the last generated ID /// </summary> public static void MarkIdUsed(long id) { long num = GetIdUniqueNumber(id); ID_OBJECT_TYPE type = GetIdObjectType(id); MyUtils.InterlockedMax(ref m_lastGeneratedIds[(byte)type], num); }
/** * Construct an ID using the hash from a string. */ public static long ConstructIdFromString(ID_OBJECT_TYPE type, string uniqueString) { Debug.Assert(!string.IsNullOrEmpty(uniqueString), "Unique string was incorrect!"); long eid = uniqueString.GetHashCode64(); eid = (eid >> 8) + eid + (eid << 13); return((eid & 0x00FFFFFFFFFFFFFF) | ((long)type << 56)); }
/// <summary> /// This method is used when loading existing entity IDs to track the last generated ID /// </summary> public static void MarkIdUsed(long id) { long num = GetIdUniqueNumber(id); ID_OBJECT_TYPE type = GetIdObjectType(id); if (m_lastGeneratedIds[(byte)type] < num) { m_lastGeneratedIds[(byte)type] = num; } }
/// <summary> /// Allocated new entity ID (won't add to list) /// Entity with this ID should be added immediatelly /// </summary> public static long AllocateId(ID_OBJECT_TYPE objectType = ID_OBJECT_TYPE.ENTITY, ID_ALLOCATION_METHOD generationMethod = ID_ALLOCATION_METHOD.RANDOM) { Debug.Assert(objectType != ID_OBJECT_TYPE.NPC, "NPC identity IDs are obsolete!"); Debug.Assert(objectType != ID_OBJECT_TYPE.SPAWN_GROUP, "SPAWN_GROUP identity IDs are obsolete!"); long generatedNumber; if (generationMethod == ID_ALLOCATION_METHOD.RANDOM) { // We can use the MyRandom RNG, because its instance is per-thread generatedNumber = MyRandom.Instance.NextLong() & 0x00FFFFFFFFFFFFFF; } else { Debug.Assert(generationMethod == ID_ALLOCATION_METHOD.SERIAL_START_WITH_1, "Unknown entity ID generation method!"); generatedNumber = Interlocked.Increment(ref m_lastGeneratedIds[(byte)objectType]); } return(ConstructId(objectType, generatedNumber)); }
public static long ConstructId(ID_OBJECT_TYPE type, long uniqueNumber) { Debug.Assert(((ulong)uniqueNumber & 0xFF00000000000000) == 0, "Unique number was incorrect!"); return((uniqueNumber & 0x00FFFFFFFFFFFFFF) | ((long)type << 56)); }
/// <summary> /// Allocated new entity ID (won't add to list) /// Entity with this ID should be added immediatelly /// </summary> public static long AllocateId(ID_OBJECT_TYPE objectType = ID_OBJECT_TYPE.ENTITY) { // We can use the MyRandom RNG, because its instance is per-thread return(MyRandom.Instance.NextLong() & 0x0000FFFFFFFFFFFF | ((long)objectType << 56)); }
public static bool IsIdentityObjectType(ID_OBJECT_TYPE identityType) { return(identityType == ID_OBJECT_TYPE.PLAYER || identityType == ID_OBJECT_TYPE.NPC || identityType == ID_OBJECT_TYPE.SPAWN_GROUP); }