示例#1
0
        public List <int> Diagnose(
            ISimulationGrid grid,
            Bone[] bones,
            int maxiteration = 6)
        {
            var ret = new List <int>();

            if (Crashed)
            {
                return(ret);
            }
            Debug.Assert(maxiteration != 0, "Momentum tick can't die but attempted diagnose");

            SimulationPoint[] body = Body.Step();
            int        bodylen     = Body.Length;
            bool       dead        = Crashed;
            int        rState      = remountState;
            RectLRTB   phys        = new RectLRTB(ref body[0]);
            List <int> breaks      = new List <int>();

            using (grid.Sync.AcquireRead())
            {
                for (int i = 0; i < maxiteration; i++)
                {
                    ProcessBones(bones, body, ref dead, ref rState, breaks);
                    if (dead)
                    {
                        return(breaks);
                    }
                    ProcessLines(grid, body, ref phys);
                }
            }
            if (maxiteration == 6)
            {
                var nose = body[RiderConstants.SledTR].Location - body[RiderConstants.SledTL].Location;
                var tail = body[RiderConstants.SledBL].Location - body[RiderConstants.SledTL].Location;
                var head = body[RiderConstants.BodyShoulder].Location - body[RiderConstants.BodyButt].Location;
                if ((nose.X * tail.Y) - (nose.Y * tail.X) < 0) // tail fakie

                {
                    dead = true;
                    ret.Add(-1);
                }
                if ((nose.X * head.Y) - (nose.Y * head.X) > 0)// head fakie
                {
                    dead = true;
                    ret.Add(-2);
                }
            }

            return(ret);
        }
示例#2
0
        public Rider Simulate(
            ISimulationGrid grid,
            Bone[] bones,
            ref int activetriggers,
            LinkedList <int> collisions,
            int maxiteration = 6,
            bool stepscarf   = true,
            int frameid      = 0)
        {
            SimulationPoint[] body = Body.Step();
            int      bodylen       = Body.Length;
            bool     dead          = Crashed;
            bool     sledbroken    = SledBroken;
            RectLRTB phys          = new RectLRTB(ref body[0]);

            using (grid.Sync.AcquireRead())
            {
                for (int i = 0; i < maxiteration; i++)
                {
                    ProcessBones(bones, body, ref dead);
                    ProcessLines(grid, body, ref phys, ref activetriggers, collisions);
                }
            }
            if (maxiteration == 6)
            {
                var nose = body[RiderConstants.SledTR].Location - body[RiderConstants.SledTL].Location;
                var tail = body[RiderConstants.SledBL].Location - body[RiderConstants.SledTL].Location;
                var head = body[RiderConstants.BodyShoulder].Location - body[RiderConstants.BodyButt].Location;
                if ((nose.X * tail.Y) - (nose.Y * tail.X) < 0 || // tail fakie
                    (nose.X * head.Y) - (nose.Y * head.X) > 0)   // head fakie
                {
                    dead       = true;
                    sledbroken = true;
                }
            }
            SimulationPoint[] scarf;
            if (stepscarf)
            {
                scarf    = Scarf.Step(friction: true);
                scarf[0] = body[RiderConstants.BodyShoulder];
                FlutterScarf(scarf, frameid, Utility.LengthFast(scarf[0].Momentum));
                ProcessScarfBones(RiderConstants.ScarfBones, scarf);
            }
            else
            {
                scarf = new SimulationPoint[Scarf.Length];
            }
            return(new Rider(body, scarf, phys, dead, sledbroken));
        }
示例#3
0
        private unsafe static void ProcessLines(
            ISimulationGrid grid,
            SimulationPoint[] body,
            ref RectLRTB physinfo,
            ref int activetriggers,
            LinkedList <int> collisions = null)
        {
            int bodylen = body.Length;

            for (int i = 0; i < bodylen; i++)
            {
                var startpos = body[i].Location;
                var cellx    = (int)Math.Floor(startpos.X / 14);
                var celly    = (int)Math.Floor(startpos.Y / 14);

                //every itreration is at least 3x3, so asjust the info for that
                physinfo.left   = Math.Min(cellx - 1, physinfo.left);
                physinfo.top    = Math.Min(celly - 1, physinfo.top);
                physinfo.right  = Math.Max(cellx + 1, physinfo.right);
                physinfo.bottom = Math.Max(celly + 1, physinfo.bottom);
                for (var x = -1; x <= 1; x++)
                {
                    for (var y = -1; y <= 1; y++)
                    {
                        var cell = grid.GetCell(cellx + x, celly + y);
                        if (cell == null)
                        {
                            continue;
                        }
                        foreach (var line in cell)
                        {
                            if (line.Interact(ref body[i]))
                            {
                                collisions?.AddLast(line.ID);
                                if (line.Trigger != null)
                                {
                                    if (activetriggers != line.ID)
                                    {
                                        activetriggers = line.ID;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        public Rider Simulate(
            ISimulationGrid grid,
            Bone[] bones,
            LinkedList <int> collisions,
            int maxiteration = 6,
            bool stepscarf   = true,
            int frameid      = 0)
        {
            SimulationPoint[] body = Body.Step();
            int      bodylen       = Body.Length;
            bool     dead          = Crashed;
            bool     sledbroken    = SledBroken;
            int      rState        = remountState;
            int      rTimer        = remountTimer;
            RectLRTB phys          = new RectLRTB(ref body[0]);

            using (grid.Sync.AcquireRead())
            {
                for (int i = 0; i < maxiteration; i++)
                {
                    ProcessBones(bones, body, ref dead, ref rState);
                    ProcessLines(grid, body, ref phys, collisions);
                }
            }
            if (maxiteration == 6)
            {
                var nose = body[RiderConstants.SledTR].Location - body[RiderConstants.SledTL].Location;
                var tail = body[RiderConstants.SledBL].Location - body[RiderConstants.SledTL].Location;
                var head = body[RiderConstants.BodyShoulder].Location - body[RiderConstants.BodyButt].Location;
                if (!dead && ((nose.X * tail.Y) - (nose.Y * tail.X) < 0 || // tail fakie
                              (nose.X * head.Y) - (nose.Y * head.X) > 0))  // head fakie
                {
                    dead       = true;
                    sledbroken = true;
                }
            }

            if (UseRemount)
            {
                ProcessRemount(bones, body, ref dead, ref sledbroken, ref rState, ref rTimer);
            }

            SimulationPoint[] scarf;
            if (stepscarf)
            {
                scarf = Scarf.Step(friction: true);

                if (Settings.multiScarfAmount * Settings.multiScarfSegments > RiderConstants.ScarfBones.Length)
                {
                    Settings.multiScarfAmount = 1;
                }                                  //if too big set to zero

                if (Settings.multiScarfAmount > 1) //If using dual scarf
                {
                    List <SimulationPoint>[] scarves    = new List <SimulationPoint> [Settings.multiScarfAmount];
                    List <SimulationPoint>   finalScarf = new List <SimulationPoint>();

                    for (int i = 0; i < Settings.multiScarfAmount; i++)
                    {
                        scarf[i * Settings.multiScarfSegments] = body[RiderConstants.BodyShoulder];
                        scarves[i] = new List <SimulationPoint>();

                        if (i != Settings.multiScarfAmount - 1)
                        {
                            for (int k = 0; k < Settings.multiScarfSegments; k++)
                            {
                                scarves[i].Add(scarf[k + (i * Settings.multiScarfSegments)]);
                            }
                        }
                        else
                        {
                            for (int k = 0; k < scarf.Length - (i * Settings.multiScarfSegments); k++)
                            {
                                scarves[i].Add(scarf[k + (i * Settings.multiScarfSegments)]);
                            }
                        }

                        SimulationPoint[] scarfArr = scarves[i].ToArray();

                        FlutterScarf(scarfArr, frameid, Utility.LengthFast(scarf[i * Settings.multiScarfSegments].Momentum) + (i * 5));
                        ProcessScarfBones(RiderConstants.ScarfBones, scarfArr);

                        for (int j = 0; j < scarfArr.Length; j++)
                        {
                            finalScarf.Add(scarfArr[j]);
                        }
                    }

                    scarf = finalScarf.ToArray();
                }
                else
                {
                    scarf[0] = body[RiderConstants.BodyShoulder];
                    FlutterScarf(scarf, frameid, Utility.LengthFast(scarf[0].Momentum));
                    ProcessScarfBones(RiderConstants.ScarfBones, scarf);
                }
            }
            else
            {
                scarf = new SimulationPoint[Scarf.Length];
            }
            return(new Rider(body, scarf, phys, dead, sledbroken, UseRemount, rState, rTimer));
        }