Exemplo 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();
        }
Exemplo n.º 3
0
        public SpraySoundEmitter(Func <Vector3D> positionGetter, Func <bool> realisticIsHoldingCondition)
        {
            if (positionGetter == null)
            {
                throw new ArgumentNullException("positionGetter");
            }

            if (realisticIsHoldingCondition == null)
            {
                throw new ArgumentNullException("realisticIsHoldingCondition");
            }

            SoundEmitter   = new MyEntity3DSoundEmitter(null);
            PositionGetter = positionGetter;

            // remove all 2D forcing conditions
            ConcurrentCachingList <Delegate> shouldPlay2D = SoundEmitter.EmitterMethods[(int)MyEntity3DSoundEmitter.MethodsEnum.ShouldPlay2D];

            shouldPlay2D.ClearImmediate();
            shouldPlay2D.Add(new Func <bool>(EmitterPlay2D)); // if no methods are declared, it defaults to always 2D

            if (MyAPIGateway.Session.SessionSettings.RealisticSound)
            {
                // remove some unnecessary conditions
                foreach (ConcurrentCachingList <Delegate> funcList in SoundEmitter.EmitterMethods.Values)
                {
                    foreach (Delegate func in funcList)
                    {
                        switch (func.Method.Name)
                        {
                        case "IsCurrentWeapon":
                        case "IsControlledEntity":
                        case "IsOnSameGrid":
                            funcList.Remove(func);
                            break;
                        }
                    }
                }

                // custom IsCurrentWeapon because Entity is not set for this emitter to detect on its own
                SoundEmitter.EmitterMethods[(int)MyEntity3DSoundEmitter.MethodsEnum.CanHear].Add(realisticIsHoldingCondition);

                //foreach(KeyValuePair<int, ConcurrentCachingList<Delegate>> kv in SoundEmitter.EmitterMethods)
                //{
                //    kv.Value.ApplyChanges();
                //    foreach(Delegate func in kv.Value)
                //    {
                //        Log.Info($"{((MyEntity3DSoundEmitter.MethodsEnum)kv.Key)} {func.Method.Name}");
                //    }
                //}
            }
        }
Exemplo n.º 4
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();
        }
            public void Add(MatrixD worldMatrix, BoundingBox box, Vector4I id, MyVoxelBase voxel)
            {
                if (m_list.Count > 1900)
                {
                    m_list.ClearList();
                }

                voxel = voxel.RootVoxel;
                box.Translate(-voxel.SizeInMetresHalf);
                //box.Translate(voxel.StorageMin);


                m_list.Add(new PredictionInfo
                {
                    Id     = id,
                    Bounds = MyOrientedBoundingBoxD.Create((BoundingBoxD)box, voxel.WorldMatrix),
                    Body   = voxel
                });
            }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
 public void Add(MyGyro gyro)
 {
     gyro.OnClose += Close;
     _gyros.Add(gyro);
     _gyros.ApplyAdditions();
 }
Exemplo n.º 8
0
 public void AddLine(DrawLine line)
 {
     _drawLines.Add(line);
     _drawLines.ApplyAdditions();
 }
        private void ProcessCell(MyStorageData cache, IMyStorage storage, Vector3I cell)
        {
            var min = cell << MyOreDetectorComponent.CELL_SIZE_IN_VOXELS_BITS;
            var max = min + (MyOreDetectorComponent.CELL_SIZE_IN_LOD_VOXELS - 1);

            storage.PinAndExecute(() =>
            {
                storage.ReadRange(cache, MyStorageDataTypeFlags.Content, MyOreDetectorComponent.QUERY_LOD, min, max);
                if (!cache.ContainsVoxelsAboveIsoLevel())
                {
                    return;
                }

                storage.ReadRange(cache, MyStorageDataTypeFlags.Material, MyOreDetectorComponent.QUERY_LOD, min, max);
            });

            var      materialData = MaterialData;
            Vector3I c;

            for (c.Z = 0; c.Z < MyOreDetectorComponent.CELL_SIZE_IN_LOD_VOXELS; ++c.Z)
            {
                for (c.Y = 0; c.Y < MyOreDetectorComponent.CELL_SIZE_IN_LOD_VOXELS; ++c.Y)
                {
                    for (c.X = 0; c.X < MyOreDetectorComponent.CELL_SIZE_IN_LOD_VOXELS; ++c.X)
                    {
                        int i = cache.ComputeLinear(ref c);
                        if (cache.Content(i) > MyVoxelDataConstants.IsoLevel)
                        {
                            const float VOXEL_SIZE      = MyVoxelConstants.VOXEL_SIZE_IN_METRES * (1 << MyOreDetectorComponent.QUERY_LOD);
                            const float VOXEL_SIZE_HALF = VOXEL_SIZE * 0.5f;
                            var         material        = cache.Material(i);

                            Vector3D localPos = (c + min) * VOXEL_SIZE + VOXEL_SIZE_HALF;
                            materialData[material].Sum   += localPos;
                            materialData[material].Count += 1;

                            var      pos = Vector3.Transform(localPos - VoxelMap.SizeInMetresHalf, Quaternion.CreateFromRotationMatrix(VoxelMap.WorldMatrix));
                            Vector3D worldpos;
                            MyVoxelCoordSystems.LocalPositionToWorldPosition((VoxelMap.PositionComp.GetPosition() - (Vector3D)VoxelMap.StorageMin), ref pos, out worldpos);

                            if (materialData[material].Positions == null)
                            {
                                materialData[material].Positions = new List <Vector3D>();
                            }
                            materialData[material].Positions.Add(worldpos);
                        }
                    }
                }
            }

            MyEntityOreDeposit result = null;

            for (int materialIdx = 0; materialIdx < materialData.Length; ++materialIdx)
            {
                if (materialData[materialIdx].Count == 0)
                {
                    continue;
                }

                var material = MyDefinitionManager.Static.GetVoxelMaterialDefinition((byte)materialIdx);
                if (material != null && material.IsRare)
                {
                    if (result == null)
                    {
                        result = new MyEntityOreDeposit(VoxelMap, cell);
                    }

                    result.Materials.Add(new MyEntityOreDeposit.Data()
                    {
                        Material             = material,
                        AverageLocalPosition = Vector3D.Transform((materialData[materialIdx].Sum / materialData[materialIdx].Count - VoxelMap.SizeInMetresHalf), Quaternion.CreateFromRotationMatrix(VoxelMap.WorldMatrix)),
                        Positions            = materialData[materialIdx].Positions,
                    });
                }
            }

            if (result != null)
            {
                m_result.Add(result);
            }
            else
            {
                m_emptyCells.Add(cell);
            }

            Array.Clear(materialData, 0, materialData.Length);

            return;
        }
Exemplo n.º 10
0
 public void Add(IMyLandingGear gear)
 {
     gear.OnClose += Close;
     _landingGears.Add(gear);
     _landingGears.ApplyAdditions();
 }