Exemplo n.º 1
0
        public void RemoveNodeCycle(ActionStateIndex stateIndex, NodeCycle cycle)
        {
            var index     = ToNodeIndex(stateIndex);
            var node      = _nodes[index];
            var chunk     = _chunks[stateIndex.ChunkIndex];
            var currCycle = node.Cycle;

            if (currCycle.Has(cycle))
            {
                currCycle = currCycle.Remove(cycle);
                switch (cycle)
                {
                case NodeCycle.Active: chunk.Active -= 1; break;

                case NodeCycle.Sleeping: chunk.Sleeping -= 1; break;

                case NodeCycle.Waking: chunk.Waking -= 1; break;
                }
            }

            node.Cycle    = currCycle;
            _nodes[index] = node;
            _chunks[stateIndex.ChunkIndex] = chunk;
        }
        private List <string> GetCycle(List <Node> nodeList)
        {
            List <NodeCycle> tempNode = new List <NodeCycle>();
            List <Node>      lista    = nodeList;

            for (int i = 0; i < lista.Count; i++)
            {
                NodeCycle nodzik = new NodeCycle(lista[i].node.ToString());
                tempNode.Add(nodzik);
            }
            int gf;

            for (int i = 0; i < tempNode.Count; i++)
            {
                gf = i;
                string thisName = tempNode[i].Id;
                var    tn       = lista.Find(a => a.node.ToString() == thisName);

                if (tn.nodesLinked.Count > 0)
                {
                    for (int x = 0; x < tn.nodesLinked.Count; x++)
                    {
                        if (tn.node == 0)
                        {
                            if (tn.nodesLinked[x] == 1)
                            {
                            }
                            else
                            {
                                string connectWith = tn.nodesLinked[x].ToString();

                                var z = tempNode.Find(a => a.Id == connectWith);
                                tempNode[i].Targets.Add(z);
                            }
                        }
                        else if (gf + 1 == tempNode.Count)
                        {
                            string connectWith = tn.nodesLinked[x].ToString();

                            var z = new NodeCycle("1");
                            tempNode[i].Targets.Add(z);
                        }
                        else
                        {
                            string connectWith = tn.nodesLinked[x].ToString();

                            var z = tempNode.Find(a => a.Id == connectWith);
                            tempNode[i].Targets.Add(z);
                        }
                    }
                }
            }
            StringBuilder cycles    = new StringBuilder();
            List <string> cycleList = new List <string>();

            foreach (var cycle in CyclePath.FindSimpleCycles(tempNode[0]))
            {
                Console.WriteLine(string.Join(",", cycle.Select(n => n.Id)));
                foreach (var node in cycle)
                {
                    cycles.Append(node.Id + " ");
                }
                var cyclesStringified = cycles.ToString();
                cycleList.Add(cyclesStringified.Trim());
                cycles.Clear();
            }
            return(cycleList);
        }
Exemplo n.º 3
0
        public void SetNodeCycle(ActionStateIndex stateIndex, NodeCycle cycle)
        {
            var index     = ToNodeIndex(stateIndex);
            var node      = _nodes[index];
            var chunk     = _chunks[stateIndex.ChunkIndex];
            var currCycle = node.Cycle;

            switch (cycle)
            {
            case NodeCycle.Active:
                if (!currCycle.Has(NodeCycle.Active))
                {
                    currCycle     = currCycle.Add(cycle);
                    chunk.Active += 1;
                }
                break;

            case NodeCycle.Sleeping:
                if (!currCycle.Has(NodeCycle.Sleeping))
                {
                    currCycle       = currCycle.Add(cycle);
                    chunk.Sleeping += 1;
                    if (currCycle.Has(NodeCycle.Waking))
                    {
                        currCycle     = currCycle.Remove(NodeCycle.Waking);
                        chunk.Waking -= 1;
                    }
                }
                break;

            case NodeCycle.Waking:
                if (!currCycle.Has(NodeCycle.Waking))
                {
                    currCycle     = currCycle.Add(cycle);
                    chunk.Waking += 1;
                    if (currCycle.Has(NodeCycle.Sleeping))
                    {
                        currCycle       = currCycle.Remove(NodeCycle.Sleeping);
                        chunk.Sleeping -= 1;
                    }
                }
                break;

            case NodeCycle.Inactive:
                if (currCycle.Has(NodeCycle.Active))
                {
                    chunk.Active -= 1;
                }
                if (currCycle.Has(NodeCycle.Waking))
                {
                    chunk.Waking -= 1;
                }
                if (currCycle.Has(NodeCycle.Sleeping))
                {
                    chunk.Sleeping -= 1;
                }
                currCycle = cycle;
                break;
            }
            node.Cycle    = currCycle;
            _nodes[index] = node;
            _chunks[stateIndex.ChunkIndex] = chunk;
        }
Exemplo n.º 4
0
 public static NodeCycle Remove(this NodeCycle self, NodeCycle cycle)
 {
     return(self & ~cycle);
 }
Exemplo n.º 5
0
 public static NodeCycle Add(this NodeCycle self, NodeCycle cycle)
 {
     return(self | cycle);
 }
Exemplo n.º 6
0
 public static bool Has(this NodeCycle self, NodeCycle cycle)
 {
     return((self & cycle) == cycle);
 }