Exemple #1
0
    public bool RemoveNamedNodeFromGraph(MemoryGraphNode memNode)
    {
        if (memNode.MemoryType != MemoryType.Cue)
        {
            //First we check the cues that this memory belongs to.
            //If the cue is only pointing to this memory, we will remove the cue too.
            for (int i = 0; i < memNode.RelatedCues.Length; i++)
            {
                MemoryGraphNode cueNode;
                if (Contains(memNode.RelatedCues[i]) == false)
                    cueNode = AddNamedNodeToGraph(new MemoryNode(memNode.RelatedCues[i], MemoryType.Cue));
                else
                    cueNode = GetNamedNodeFromGraph(memNode.RelatedCues[i]);

                if (cueNode.Neighbours.Count == 0)
                    RemoveNamedNodeFromGraph(cueNode);
            }

            //Next we must check any neighbours which are pointing to it, and remove those.
            for (int i = 0; i < memNode.Neighbours.Count; i++)
            {
                int index = memNode.Neighbours.IndexOf(memNode);
                if (index != -1)
                {
                    memNode.RemoveNeighbour(index);
                }
            }
        }

        //Finally, we can remove the node itself from our overall list as well as the hash table.
        bool retVal = true;

        retVal &= MemoryNodes.Remove(memNode);
        retVal &= MemoryHash.Remove(memNode.UID);

        return retVal;  //We return a value which will be true if successfully removed from both, or false otherwise.
    }
Exemple #2
0
    public void RemoveEdge(MemoryGraphNode fromNode, MemoryGraphNode toNode)
    {
        //Debug.Log("Removing an edge: " + fromNode.UID + " to " + toNode.UID);
        for (int i = 0; i < fromNode.Neighbours.Count; i++)
        {
            if (fromNode.Neighbours[i] == toNode)
            {
                fromNode.RemoveNeighbour(i);
                break;
            }
        }

        for (int i = 0; i < toNode.Neighbours.Count; i++)
        {
            if (toNode.Neighbours[i] == fromNode)
            {
                toNode.RemoveNeighbour(i);
                break;
            }
        }

        //This will need to be watched, to see if any loose memories leak into this system.
        //As is, I don't believe it is possible. We only need to outright remove a node if the cue reference breaks down.
        if(fromNode.MemoryType == MemoryType.Cue)
        {
            //Debug.Log("Removing the entire node: " + toNode.UID);
            deadNodes.Add(toNode.UID);  //We can't remove a node in the middle of the update, so we store it until the end of the frame.
        }
    }