Esempio n. 1
0
        public void _PeerDisconnected(int peerId)
        {
            GD.Print(peerId, " disconnected!");
            if (!OnlinePlayers.TryGetValue(peerId, out var player))
            {
                return;
            }

            OnlinePlayers.Remove(peerId);
            Entities.DeReplicateEntity(player);
            player.Purge();
        }
Esempio n. 2
0
 /// <summary>
 /// Collects the current key's object and all objects that depend on the current key into an ever-growing HashSet.
 /// </summary>
 /// <param name="objKey">Fetch the node associated with this object.</param>
 /// <param name="objReturn">HashSet containing all keys that depend on <paramref name="objKey"/> in some way. It's a HashSet to prevent infinite loops in case of cycles</param>
 private void CollectDependents(T objKey, HashSet <T> objReturn)
 {
     if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <T> objLoopNode))
     {
         if (objReturn.Add(objLoopNode.MyObject))
         {
             foreach (DependencyGraphNode <T> objDependant in objLoopNode.UpStreamNodes.Where(x => x.DependencyCondition?.Invoke() != false).Select(x => x.Node))
             {
                 CollectDependents(objDependant.MyObject, objReturn);
             }
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Collects the current key's object and all objects that depend on the current key into an ever-growing HashSet.
 /// </summary>
 /// <param name="objParentInstance">Instance of the object whose dependencies are being processed, used for conditions.</param>
 /// <param name="objKey">Fetch the node associated with this object.</param>
 /// <param name="objReturn">Collection containing all keys that depend on <paramref name="objKey"/> in some way. It's a HashSet to prevent infinite loops in case of cycles</param>
 protected void CollectDependents(T2 objParentInstance, T objKey, ICollection <T> objReturn)
 {
     if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <T, T2> objLoopNode) && !objReturn.Contains(objLoopNode.MyObject))
     {
         objReturn.Add(objLoopNode.MyObject);
         foreach (DependencyGraphNodeWithCondition <T, T2> objNode in objLoopNode.UpStreamNodes)
         {
             if (objNode.DependencyCondition?.Invoke(objParentInstance) != false)
             {
                 CollectDependents(objParentInstance, objNode.Node.MyObject, objReturn);
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Returns an enumerable containing the current key's object and all objects that depend on the current key.
        /// Warning: DependencyGraphs with any cycles will cause this method to never terminate!
        /// </summary>
        /// <param name="objKey">Fetch the node associated with this object.</param>
        public IEnumerable <T> GetWithAllDependentsUnsafe(T objKey)
        {
            if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <T> objLoopNode))
            {
                yield return(objLoopNode.MyObject);

                foreach (DependencyGraphNode <T> objDependant in objLoopNode.UpStreamNodes.Where(x => x.DependencyCondition?.Invoke() != false).Select(x => x.Node))
                {
                    foreach (T objDependantObject in GetWithAllDependentsUnsafe(objDependant.MyObject))
                    {
                        yield return(objDependantObject);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns an enumerable containing the current key's object and all objects that depend on the current key.
        /// Warning: DependencyGraphs with any cycles will cause this method to never terminate!
        /// </summary>
        /// <param name="objParentInstance">Instance of the object whose dependencies are being processed, used for conditions.</param>
        /// <param name="objKey">Fetch the node associated with this object.</param>
        public IEnumerable <T> GetWithAllDependentsUnsafe(T2 objParentInstance, T objKey)
        {
            if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <T, T2> objLoopNode))
            {
                yield return(objLoopNode.MyObject);

                foreach (DependencyGraphNodeWithCondition <T, T2> objNode in objLoopNode.UpStreamNodes)
                {
                    if (objNode.DependencyCondition?.Invoke(objParentInstance) != false)
                    {
                        foreach (T objDependantObject in GetWithAllDependentsUnsafe(objParentInstance, objNode.Node.MyObject))
                        {
                            yield return(objDependantObject);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns a collection containing the current key's object and all objects that depend on the current key.
        /// Slower but idiot-proof compared to GetWithAllDependentsUnsafe().
        /// </summary>
        /// <param name="objKey">Fetch the node associated with this object.</param>
        public ICollection <T> GetWithAllDependents(T objKey)
        {
            HashSet <T> objReturn = new HashSet <T>();

            if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <T> objLoopNode))
            {
                if (objReturn.Add(objLoopNode.MyObject))
                {
                    foreach (DependencyGraphNode <T> objDependant in objLoopNode.UpStreamNodes.Where(x => x.DependencyCondition?.Invoke() != false).Select(x => x.Node))
                    {
                        CollectDependents(objDependant.MyObject, objReturn);
                    }
                }
            }
            else
            {
                objReturn.Add(objKey);
            }

            return(objReturn);
        }
Esempio n. 7
0
        /// <summary>
        /// Returns a collection containing the current key's object and all objects that depend on the current key.
        /// Slower but idiot-proof compared to GetWithAllDependentsUnsafe().
        /// </summary>
        /// <param name="objParentInstance">Instance of the object whose dependencies are being processed, used for conditions.</param>
        /// <param name="objKey">Fetch the node associated with this object.</param>
        public HashSet <T> GetWithAllDependents(T2 objParentInstance, T objKey)
        {
            HashSet <T> objReturn = new HashSet <T>();

            if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <T, T2> objLoopNode))
            {
                if (objReturn.Add(objLoopNode.MyObject))
                {
                    foreach (DependencyGraphNodeWithCondition <T, T2> objNode in objLoopNode.UpStreamNodes)
                    {
                        if (objNode.DependencyCondition?.Invoke(objParentInstance) != false)
                        {
                            CollectDependents(objParentInstance, objNode.Node.MyObject, objReturn);
                        }
                    }
                }
            }
            else
            {
                objReturn.Add(objKey);
            }

            return(objReturn);
        }
        /// <summary>
        /// Returns a collection containing the current key's object and all objects that depend on the current key.
        /// Slower but idiot-proof compared to GetWithAllDependentsUnsafe().
        /// </summary>
        /// <param name="objParentInstance">Instance of the object whose dependencies are being processed, used for conditions.</param>
        /// <param name="objKey">Fetch the node associated with this object.</param>
        /// <param name="blnUsePool">Whether to fetch the returned HashSet{string} from a pool or to just create a new one on the stack.</param>
        public HashSet <string> GetWithAllDependents(T objParentInstance, string objKey, bool blnUsePool)
        {
            HashSet <string> setReturn = blnUsePool ? Utils.StringHashSetPool.Get() : new HashSet <string>();

            if (NodeDictionary.TryGetValue(objKey, out DependencyGraphNode <string, T> objLoopNode))
            {
                if (setReturn.Add(objLoopNode.MyObject))
                {
                    foreach (DependencyGraphNodeWithCondition <string, T> objNode in objLoopNode.UpStreamNodes)
                    {
                        if (objNode.DependencyCondition?.Invoke(objParentInstance) != false)
                        {
                            CollectDependents(objParentInstance, objNode.Node.MyObject, setReturn);
                        }
                    }
                }
            }
            else
            {
                setReturn.Add(objKey);
            }

            return(setReturn);
        }
Esempio n. 9
0
 public bool TryGetNode(string id, out Node node)
 {
     return(NodeDictionary.TryGetValue(id, out node));
 }