Ejemplo n.º 1
0
        private void InitializeOptimal(AILBlock[] Graph, AILBlock Root)
        {
            //This will go through all possible paths on the graph,
            //and store all inputs/outputs for each block. A register
            //that was previously written to already is not considered an input.
            //When a block can be reached by more than one path, then the
            //output from all paths needs to be set for this block, and
            //only outputs present in all of the parent blocks can be considered
            //when doing input elimination. Each block chain have a root, that's where
            //the code starts executing. They are present on the subroutine start point,
            //and on call return points too (address written to X30 by BL).
            HashSet <BlockIo> Visited = new HashSet <BlockIo>();

            Queue <BlockIo> Unvisited = new Queue <BlockIo>();

            void Enqueue(BlockIo Block)
            {
                if (!Visited.Contains(Block))
                {
                    Unvisited.Enqueue(Block);

                    Visited.Add(Block);
                }
            }

            Enqueue(new BlockIo()
            {
                Block = Root,
                Entry = Root
            });

            while (Unvisited.Count > 0)
            {
                BlockIo Current = Unvisited.Dequeue();

                Current.IntInputs  |= Current.Block.IntInputs & ~Current.IntOutputs;
                Current.VecInputs  |= Current.Block.VecInputs & ~Current.VecOutputs;
                Current.IntOutputs |= Current.Block.IntOutputs;
                Current.VecOutputs |= Current.Block.VecOutputs;

                //Check if this is a exit block
                //(a block that returns or calls another sub).
                if ((Current.Block.Next == null &&
                     Current.Block.Branch == null) || Current.Block.HasStateStore)
                {
                    if (!IntPaths.TryGetValue(Current.Block, out PathIo IntPath))
                    {
                        IntPaths.Add(Current.Block, IntPath = new PathIo());
                    }

                    if (!VecPaths.TryGetValue(Current.Block, out PathIo VecPath))
                    {
                        VecPaths.Add(Current.Block, VecPath = new PathIo());
                    }

                    IntPath.Set(Current.Entry, Current.IntInputs, Current.IntOutputs);
                    VecPath.Set(Current.Entry, Current.VecInputs, Current.VecOutputs);
                }

                void EnqueueFromCurrent(AILBlock Block, bool RetTarget)
                {
                    BlockIo BlkIO = new BlockIo()
                    {
                        Block = Block
                    };

                    if (RetTarget)
                    {
                        BlkIO.Entry = Block;
                    }
                    else
                    {
                        BlkIO.Entry      = Current.Entry;
                        BlkIO.IntInputs  = Current.IntInputs;
                        BlkIO.VecInputs  = Current.VecInputs;
                        BlkIO.IntOutputs = Current.IntOutputs;
                        BlkIO.VecOutputs = Current.VecOutputs;
                    }

                    Enqueue(BlkIO);
                }

                if (Current.Block.Next != null)
                {
                    EnqueueFromCurrent(Current.Block.Next, Current.Block.HasStateStore);
                }

                if (Current.Block.Branch != null)
                {
                    EnqueueFromCurrent(Current.Block.Branch, false);
                }
            }
        }
Ejemplo n.º 2
0
    public override IEnumerator MoveToPosition(IntPair pos, SuccessCallback callback = null)
    {
        if (callback == null)
        {
            callback = (s) => {}
        }
        ;

        if (animator != null)
        {
            animator.SetBool(AnimationStandards.IS_MOVING, true);
        }

        IntPair endPoint = pos;



        Game game = Game.current;

        if (game != null)
        {
            ShopGrid grid = game.shopGrid;

            if (grid != null)
            {
                bool done = false;


                while (!done)
                {
                    IntPath path = grid.FindPath(MyGrid, farCorner, endPoint);

                    if (path == null)
                    {
                        #region callback(false) and exit loop
                        if (animator != null)
                        {
                            animator.SetBool(AnimationStandards.IS_MOVING, false);
                        }
                        callback(false);
                        done = true;
                        #endregion
                    }
                    else
                    {
                        #region try to follow path; if path succeeds, callback(true) and exit
                        bool pathSucceeded = true;
                        for (int i = 0; i < path.Length; i++)
                        {
                            yield return(Glide(farCorner, path [i]));

                            farCorner = path [i];
                        }


                        if (pathSucceeded)
                        {
                            if (animator != null)
                            {
                                animator.SetBool(AnimationStandards.IS_MOVING, false);
                            }
                            callback(true);
                            done = true;
                        }
                        #endregion
                    }
                }
            }
        }
        else
        {
            callback(false);
        }
    }
Ejemplo n.º 3
0
 public CombinedPath(IntPath p1, IntPath p2)
 {
     path1 = p1;
     path2 = p2;
 }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadInt(32);
     Field1 = buffer.ReadInt(32);
     Field2 = buffer.ReadInt(32);
     Field3 = buffer.ReadInt(32);
     Field4 = buffer.ReadInt(32);
     Field5 = new InterpolationScalar();
     Field5.Parse(buffer);
     Field6 = new FloatPath();
     Field6.Parse(buffer);
     Field7 = new IntPath();
     Field7.Parse(buffer);
     Field8 = new FloatPath();
     Field8.Parse(buffer);
     Field9 = new TimePath();
     Field9.Parse(buffer);
     Field10 = new FloatPath();
     Field10.Parse(buffer);
     Field11 = new AnglePath();
     Field11.Parse(buffer);
     Field12 = new VelocityVectorPath();
     Field12.Parse(buffer);
     Field13 = new VelocityVectorPath();
     Field13.Parse(buffer);
     Field14 = new VelocityPath();
     Field14.Parse(buffer);
     Field15 = new VelocityPath();
     Field15.Parse(buffer);
     Field16 = new VelocityPath();
     Field16.Parse(buffer);
     Field17 = new VectorPath();
     Field17.Parse(buffer);
     Field18 = new VelocityPath();
     Field18.Parse(buffer);
     Field19 = buffer.ReadFloat32();
     Field20 = new UberMaterial();
     Field20.Parse(buffer);
     snoPhysics = buffer.ReadInt(32);
     Field22 = buffer.ReadFloat32();
     Field23 = buffer.ReadInt(32);
     Field24 = buffer.ReadFloat32();
     Field25 = buffer.ReadFloat32();
     Field26 = buffer.ReadFloat32();
     Field27 = buffer.ReadFloat32();
     Field28 = buffer.ReadFloat32();
     Field29 = buffer.ReadFloat32();
     Field30 = buffer.ReadFloat32();
     snoActor = buffer.ReadInt(32);
     Field32 = new EmitterParams();
     Field32.Parse(buffer);
     Field33 = new ColorPath();
     Field33.Parse(buffer);
     Field34 = new FloatPath();
     Field34.Parse(buffer);
     Field35 = new FloatPath();
     Field35.Parse(buffer);
     Field36 = new FloatPath();
     Field36.Parse(buffer);
     Field37 = new AnglePath();
     Field37.Parse(buffer);
     Field38 = new AngularVelocityPath();
     Field38.Parse(buffer);
     Field39 = new AngularVelocityPath();
     Field39.Parse(buffer);
     Field40 = new AnglePath();
     Field40.Parse(buffer);
     Field41 = new VectorPath();
     Field41.Parse(buffer);
     Field42 = new FloatPath();
     Field42.Parse(buffer);
     Field43 = new VelocityPath();
     Field43.Parse(buffer);
     Field44 = new AngularVelocityPath();
     Field44.Parse(buffer);
     Field45 = new FloatPath();
     Field45.Parse(buffer);
     Field46 = new VelocityPath();
     Field46.Parse(buffer);
     Field47 = new VectorPath();
     Field47.Parse(buffer);
     Field48 = new VelocityVectorPath();
     Field48.Parse(buffer);
     Field49 = new AccelVectorPath();
     Field49.Parse(buffer);
     Field50 = new VectorPath();
     Field50.Parse(buffer);
     Field51 = new VelocityVectorPath();
     Field51.Parse(buffer);
     Field52 = new AccelVectorPath();
     Field52.Parse(buffer);
     Field53 = new VelocityPath();
     Field53.Parse(buffer);
     Field54 = new FloatPath();
     Field54.Parse(buffer);
     Field55 = buffer.ReadInt(32);
     Field56 = buffer.ReadFloat32();
     Field57 = buffer.ReadFloat32();
     serMsgTriggeredEvents = new SerializeData();
     serMsgTriggeredEvents.Parse(buffer);
     Field59 = buffer.ReadInt(32);
     Field60 = new DT_VARIABLEARRAY();
     Field60.Parse(buffer);
 }
Ejemplo n.º 5
0
 public static IntPath AddPaths(IntPath p1, IntPath p2)
 {
     return(new CombinedPath(p1, p2));
 }