예제 #1
0
        public override void UpdateBeforeSimulation100()
        {
            if (DockCore.instance?.TextAPI == null)
            {
                return;
            }
            if (DockCore.instance.isDedicated)
            {
                return;
            }
            //not init
            if (connector == null || connector.MarkedForClose || connector.Closed)
            {
                return;
            }
            if (dirtyblock == null || dirtyblock.MarkedForClose || dirtyblock.Closed)
            {
                isdirty = false;
            }
            if (MyAPIGateway.Session?.Player?.Controller?.ControlledEntity == null)
            {
                return;
            }
            if (!alive)
            {
                return;
            }
            if (updating)
            {
                DockCore.OnDraw -= Draw;
                updating         = false;
            }
            if (MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent() == connector.GetTopMostParent())
            {
                index = DockCore.instance.indexer.Add((connector));
            }
            if (!connector.IsWorking)
            {
                return;
            }
            //add to cache
            string   debug      = "";
            Vector3D Coordinate = connector.WorldMatrix.Translation / scale;

            if (Coordinate.AbsMax() >= Vector3I.MaxValue.AbsMax())
            {
                scale      = (Coordinate.AbsMax() * 2) / Vector3I.MaxValue.AbsMax();
                isdirty    = true;
                dirtyblock = connector;
                BlockCache.Clear();                 //BOOM
                //return;
            }
            debug += scale.ToString() + '\n';
            EntityCache Cache;

            BlockCache.TryGetValue(lastpos, out Cache);
            if (Cache != null)
            {
                Cache.Remove(connector);
            }

            lastpos = new Vector3I(Coordinate);
            EntityCache Search = new EntityCache();

            BlockCache.TryGetValue(lastpos, out Cache);
            if (Cache != null)
            {
                Search.Copy(Cache);
                Cache.Add(connector);
            }
            else
            {
                Cache = new EntityCache();
                Cache.Add(connector);
                BlockCache.Add(lastpos, Cache);
            }
            IMyFunctionalBlock Closest;

            if (TryGetClosestMergeblock(connector, ref Search, out Closest))
            {
                debug += Closest.EntityId.ToString() + '\n';
                if (MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent() == connector.GetTopMostParent())
                {
                    DockCore.instance.CanDraw = true;
                    if (DockCore.instance.idx % DockCore.instance.indexer.Count() == index)
                    {
                        target           = Closest;
                        DockCore.OnDraw += Draw;
                        updating         = true;
                    }
                }
            }
            debug += Search.Count().ToString();
        }