コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /**
         * 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));
        }
コード例 #3
0
        /// <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;
            }
        }
コード例 #4
0
        /// <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));
        }
コード例 #5
0
 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));
 }
コード例 #6
0
 /// <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));
 }
コード例 #7
0
 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);
 }