示例#1
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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }