Esempio n. 1
0
        private void RegisterNewGrid(MyCubeGrid grid)
        {
            // Logic for picking proper grids goes here
            IMyShipController mainControl = null;

            foreach (IMyShipController controller in grid.GetFatBlocks <MyShipController>())
            {
                if (!controller.CustomData.Contains("DemoSetup"))
                {
                    continue;
                }
                mainControl = controller;
            }
            if (mainControl == null)
            {
                return;
            }
            WriteToLog("RegisterNewGrid", $"Registering new grid: {mainControl.CubeGrid.DisplayName}", LogType.General);
            ControllableGrid controllableGrid = new ControllableGrid(grid, mainControl);

            controllableGrid.OnWriteToLog += WriteToLog;
            controllableGrid.OnClose      += OnGridClose;
            controllableGrid.SetupGrid();
            _grids.Add(controllableGrid);
            _grids.ApplyAdditions();
        }
        /// <summary>
        /// Parallel thread - listener.
        /// </summary>
        private void ServerListenerProc()
        {
            Thread.CurrentThread.Name = "External Debugging Listener";
            ProfilerShort.Autocommit  = false;

            m_listener = new TcpListener(IPAddress.Any, GameDebugPort)
            {
                ExclusiveAddressUse = false
            };
            try
            {
                m_listener.Start();
            }
            catch (SocketException e)
            {
                MyLog.Default.WriteLine("Cannot start debug listener.");
                MyLog.Default.WriteLine(e);
                m_listener = null;
                m_active   = false;
                return;
            }
            MyLog.Default.WriteLine("External debugger: listening...");
            while (true)
            {
                try
                {
                    var client = m_listener.AcceptTcpClient();
                    client.Client.Blocking = true;
                    MyLog.Default.WriteLine("External debugger: accepted client.");
                    m_clients.Add(new MyDebugClientInfo()
                    {
                        TcpClient  = client,
                        LastHeader = MyExternalDebugStructures.CommonMsgHeader.Create("UNKNOWN")
                    });
                    m_clients.ApplyAdditions();
                }
                catch (SocketException e)
                {
                    if (e.SocketErrorCode == SocketError.Interrupted)
                    {
                        m_listener.Stop();
                        m_listener = null;
                        MyLog.Default.WriteLine("External debugger: interrupted.");
                        ProfilerShort.Commit();
                        ProfilerShort.DestroyThread();
                        return;
                    }
                    else
                    {
                        MyLog.Default.WriteLine(e);
                        break;
                    }
                }
            }
            m_listener.Stop();
            m_listener = null;
            ProfilerShort.Commit();
            ProfilerShort.DestroyThread();
        }
Esempio n. 3
0
        public static void GetBlocksInsideSphereFast(MyCubeGrid grid, ref BoundingSphereD sphere, bool checkDestroyed, ConcurrentCachingList <CubeAccel> blocks)
        {
            var radius = sphere.Radius;

            radius *= grid.GridSizeR;
            var      center = grid.WorldToGridInteger(sphere.Center);
            var      gridMin = grid.Min;
            var      gridMax = grid.Max;
            double   radiusSq = radius * radius;
            int      radiusCeil = (int)Math.Ceiling(radius);
            int      i, j, k;
            Vector3I max2 = Vector3I.Min(Vector3I.One * radiusCeil, gridMax - center);
            Vector3I min2 = Vector3I.Max(Vector3I.One * -radiusCeil, gridMin - center);

            for (i = min2.X; i <= max2.X; ++i)
            {
                for (j = min2.Y; j <= max2.Y; ++j)
                {
                    for (k = min2.Z; k <= max2.Z; ++k)
                    {
                        if (i * i + j * j + k * k < radiusSq)
                        {
                            MyCube cube;
                            var    vector3I = center + new Vector3I(i, j, k);

                            if (grid.TryGetCube(vector3I, out cube))
                            {
                                var slim = (IMySlimBlock)cube.CubeBlock;
                                if (slim.Position == vector3I)
                                {
                                    if (checkDestroyed && slim.IsDestroyed)
                                    {
                                        continue;
                                    }

                                    blocks.Add(new CubeAccel {
                                        Block = slim, CubeExists = slim.FatBlock != null, Grid = (MyCubeGrid)slim.CubeGrid
                                    });
                                }
                            }
                        }
                    }
                }
            }
            blocks.ApplyAdditions();
        }
Esempio n. 4
0
        private void CheckHits()
        {
            for (int x = ActiveProjetiles.Count - 1; x >= 0; x--)
            {
                var p = ActiveProjetiles[x];

                if ((int)p.State > 3)
                {
                    continue;
                }

                if (p.Info.Ai.ProInMinCacheRange > 99999 && !p.Info.Ai.AccelChecked)
                {
                    p.Info.Ai.ComputeAccelSphere();
                }

                p.UseEntityCache = p.Info.Ai.AccelChecked && p.Info.DistanceTraveled <= p.Info.Ai.NearByEntitySphere.Radius && !p.Info.Ai.MarkedForClose;
                var triggerRange  = p.Info.ConsumableDef.Const.EwarTriggerRange > 0 && !p.Info.EwarAreaPulse ? p.Info.ConsumableDef.Const.EwarTriggerRange : 0;
                var useEwarSphere = (triggerRange > 0 || p.Info.EwarActive) && p.Info.ConsumableDef.Const.Pulse;
                p.Beam = useEwarSphere ? new LineD(p.Position + (-p.Info.Direction * p.Info.ConsumableDef.Const.EwarTriggerRange), p.Position + (p.Info.Direction * p.Info.ConsumableDef.Const.EwarTriggerRange)) : new LineD(p.LastPosition, p.Position);

                if ((p.FieldTime <= 0 && p.State != ProjectileState.OneAndDone && p.Info.DistanceTraveled * p.Info.DistanceTraveled >= p.DistanceToTravelSqr))
                {
                    p.PruneSphere.Center = p.Position;
                    p.PruneSphere.Radius = p.Info.ConsumableDef.Const.DetonationRadius;

                    var dInfo = p.Info.ConsumableDef.AreaEffect.Detonation;
                    if (p.MoveToAndActivate || dInfo.DetonateOnEnd && p.Info.Age >= dInfo.MinArmingTime && (!dInfo.ArmOnlyOnHit || p.Info.ObjectsHit > 0))
                    {
                        if (!p.UseEntityCache)
                        {
                            MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref p.PruneSphere, p.MyEntityList, p.PruneQuery);
                        }

                        if (p.Info.System.TrackProjectile)
                        {
                            foreach (var lp in p.Info.Ai.LiveProjectile)
                            {
                                if (p.PruneSphere.Contains(lp.Position) != ContainmentType.Disjoint && lp != p.Info.Target.Projectile)
                                {
                                    ProjectileHit(p, lp, p.Info.ConsumableDef.Const.CollisionIsLine, ref p.Beam);
                                }
                            }
                        }

                        p.State = ProjectileState.Detonate;

                        if (p.EnableAv)
                        {
                            p.Info.AvShot.ForceHitParticle = true;
                        }
                    }
                    else
                    {
                        p.State = ProjectileState.Detonate;
                    }

                    p.EarlyEnd            = true;
                    p.Info.Hit.SurfaceHit = p.Position;
                    p.Info.Hit.LastHit    = p.Position;
                }

                p.SphereCheck = false;
                p.LineCheck   = false;

                if (p.MineSeeking && !p.MineTriggered)
                {
                    p.SeekEnemy();
                }
                else if (useEwarSphere)
                {
                    if (p.Info.EwarActive)
                    {
                        p.PruneSphere = new BoundingSphereD(p.Position, 0).Include(new BoundingSphereD(p.LastPosition, 0));
                        var currentRadius = p.Info.TriggerGrowthSteps < p.Info.ConsumableDef.Const.AreaEffectSize ? p.Info.TriggerMatrix.Scale.AbsMax() : p.Info.ConsumableDef.Const.AreaEffectSize;
                        if (p.PruneSphere.Radius < currentRadius)
                        {
                            p.PruneSphere.Center = p.Position;
                            p.PruneSphere.Radius = currentRadius;
                        }
                    }
                    else
                    {
                        p.PruneSphere = new BoundingSphereD(p.Position, triggerRange);
                    }

                    if (p.PruneSphere.Contains(p.DeadSphere) == ContainmentType.Disjoint)
                    {
                        p.SphereCheck = true;
                    }
                }
                else if (p.Info.ConsumableDef.Const.CollisionIsLine)
                {
                    p.PruneSphere.Center = p.Position;
                    p.PruneSphere.Radius = p.Info.ConsumableDef.Const.CollisionSize;
                    if (p.Info.ConsumableDef.Const.IsBeamWeapon || p.PruneSphere.Contains(p.DeadSphere) == ContainmentType.Disjoint)
                    {
                        p.LineCheck = true;
                    }
                }
                else
                {
                    p.SphereCheck = true;
                    p.PruneSphere = new BoundingSphereD(p.Position, 0).Include(new BoundingSphereD(p.LastPosition, 0));
                    if (p.PruneSphere.Radius < p.Info.ConsumableDef.Const.CollisionSize)
                    {
                        p.PruneSphere.Center = p.Position;
                        p.PruneSphere.Radius = p.Info.ConsumableDef.Const.CollisionSize;
                    }
                }
            }

            var apCount  = ActiveProjetiles.Count;
            var minCount = Session.Settings.Enforcement.ServerOptimizations ? 96 : 99999;
            var stride   = apCount < minCount ? 100000 : 48;

            MyAPIGateway.Parallel.For(0, apCount, i =>
            {
                var p = ActiveProjetiles[i];
                if (p.SphereCheck)
                {
                    if (p.DynamicGuidance && p.PruneQuery == MyEntityQueryType.Dynamic && p.Info.System.Session.Tick60)
                    {
                        p.CheckForNearVoxel(60);
                    }

                    if (!p.UseEntityCache)
                    {
                        MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref p.PruneSphere, p.MyEntityList, p.PruneQuery);
                    }
                }
                else if (p.LineCheck)
                {
                    if (p.DynamicGuidance && p.PruneQuery == MyEntityQueryType.Dynamic && p.Info.System.Session.Tick60)
                    {
                        p.CheckForNearVoxel(60);
                    }

                    if (!p.UseEntityCache)
                    {
                        MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref p.Beam, p.MySegmentList, p.PruneQuery);
                    }
                }

                p.CheckType = p.UseEntityCache && p.SphereCheck ? CheckTypes.CachedSphere : p.UseEntityCache ? CheckTypes.CachedRay : p.SphereCheck ? CheckTypes.Sphere : CheckTypes.Ray;

                if (p.Info.Target.IsProjectile || p.UseEntityCache && p.Info.Ai.NearByEntityCache.Count > 0 || p.CheckType == CheckTypes.Ray && p.MySegmentList.Count > 0 || p.CheckType == CheckTypes.Sphere && p.MyEntityList.Count > 0)
                {
                    ValidateHits.Add(p);
                }
            }, stride);
            ValidateHits.ApplyAdditions();
        }
Esempio n. 5
0
 public void Add(MyGyro gyro)
 {
     gyro.OnClose += Close;
     _gyros.Add(gyro);
     _gyros.ApplyAdditions();
 }
Esempio n. 6
0
 public void AddLine(DrawLine line)
 {
     _drawLines.Add(line);
     _drawLines.ApplyAdditions();
 }
 public void Add(IMyLandingGear gear)
 {
     gear.OnClose += Close;
     _landingGears.Add(gear);
     _landingGears.ApplyAdditions();
 }