Beispiel #1
0
        /// <summary>
        /// Removes an object after it has expired from the destruction queue, or it has been destroyed
        /// </summary>
        public void RemoveObject(PhysicsObj obj, bool inverse = true)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (obj == null)
                {
                    return;
                }

                RemoveKnownObject(obj, inverse);
                RemoveVisibleObject(obj, inverse);
                DestructionQueue.Remove(obj, out _);

                if (obj.IsPlayer)
                {
                    RemoveKnownPlayer(obj);
                }

                RemoveVisibleTarget(obj);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Clears all of the ObjMaint tables for an object
 /// </summary>
 private void RemoveAllObjects()
 {
     KnownObjects.Clear();
     VisibleObjects.Clear();
     DestructionQueue.Clear();
     KnownPlayers.Clear();
     VisibleTargets.Clear();
 }
Beispiel #3
0
        /// <summary>
        /// Removes an object from the destruction queue
        /// if it has been invisible for less than 25s
        /// this is only used for players
        /// </summary>
        public bool RemoveObjectToBeDestroyed(PhysicsObj obj)
        {
            double time = -1;

            DestructionQueue.TryGetValue(obj, out time);
            if (time != -1 && time > PhysicsTimer.CurrentTime)
            {
                DestructionQueue.Remove(obj);
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Removes any objects that have been in the destruction queue
        /// for more than 25s
        /// this is only used for players
        /// </summary>
        public List <PhysicsObj> DestroyObjects()
        {
            // find the list of objects that have been in the destruction queue > 25s
            var expiredObjs = DestructionQueue.Where(kvp => kvp.Value <= PhysicsTimer.CurrentTime).ToDictionary(kvp => kvp.Key, kvp => kvp.Value).Keys.ToList();

            // remove expired objects from all lists
            foreach (var expiredObj in expiredObjs)
            {
                RemoveObject(expiredObj);
            }

            return(expiredObjs);
        }
Beispiel #5
0
        /// <summary>
        /// Adds an object to the destruction queue
        /// Called when an object exits the PVS range
        /// only maintained for players
        /// </summary>
        public bool AddObjectToBeDestroyed(PhysicsObj obj)
        {
            RemoveVisibleObject(obj);

            if (DestructionQueue.ContainsKey(obj))
            {
                return(false);
            }

            DestructionQueue.Add(obj, PhysicsTimer.CurrentTime + DestructionTime);

            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Removes an object after it has expired from the destruction queue,
        /// or it has been destroyed
        /// </summary>
        public void RemoveObject(PhysicsObj obj, bool inverse = true)
        {
            if (obj == null)
            {
                return;
            }

            RemoveKnownObject(obj, inverse);
            RemoveVisibleObject(obj, inverse);
            DestructionQueue.Remove(obj);

            RemoveKnownPlayer(obj);
            RemoveVisibleTarget(obj);
        }
Beispiel #7
0
        /// <summary>
        /// Removes an object from the destruction queue if it has been invisible for less than 25s
        /// this is only used for players
        /// </summary>
        public bool RemoveObjectToBeDestroyed(PhysicsObj obj)
        {
            rwLock.EnterWriteLock();
            try
            {
                double time = -1;
                DestructionQueue.TryGetValue(obj, out time);
                if (time != -1 && time > PhysicsTimer.CurrentTime)
                {
                    DestructionQueue.Remove(obj, out _);
                    return(true);
                }

                return(false);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Adds an object to the destruction queue
        /// Called when an object exits the PVS range
        /// only maintained for players
        /// </summary>
        public bool AddObjectToBeDestroyed(PhysicsObj obj)
        {
            rwLock.EnterWriteLock();
            try
            {
                RemoveVisibleObject(obj);

                if (DestructionQueue.ContainsKey(obj))
                {
                    return(false);
                }

                DestructionQueue.TryAdd(obj, PhysicsTimer.CurrentTime + DestructionTime);

                return(true);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Removes any objects that have been in the destruction queue for more than 25s
        /// this is only used for players
        /// </summary>
        public List <PhysicsObj> DestroyObjects()
        {
            rwLock.EnterWriteLock();
            try
            {
                // find the list of objects that have been in the destruction queue > 25s
                var expiredObjs = DestructionQueue.Where(kvp => kvp.Value <= PhysicsTimer.CurrentTime)
                                  .Select(kvp => kvp.Key).ToList();

                // remove expired objects from all lists
                foreach (var expiredObj in expiredObjs)
                {
                    RemoveObject(expiredObj);
                }

                return(expiredObjs);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }