示例#1
0
        private void AddGridToMap()
        {
            MyCubeGrid grid;

            while (NewGrids.TryDequeue(out grid))
            {
                var allFat = ConcurrentListPool.Get();

                var gridFat = grid.GetFatBlocks();
                for (int i = 0; i < gridFat.Count; i++)
                {
                    allFat.Add(gridFat[i]);
                }
                allFat.ApplyAdditions();

                var gridMap = GridMapPool.Get();

                if (grid.Components.TryGet(out gridMap.Targeting))
                {
                    gridMap.Targeting.AllowScanning = false;
                }
                gridMap.Trash = true;

                gridMap.MyCubeBocks = allFat;
                GridToInfoMap.TryAdd(grid, gridMap);
                grid.OnFatBlockAdded   += ToGridMap;
                grid.OnFatBlockRemoved += FromGridMap;
                grid.OnClose           += RemoveGridFromMap;
                DirtyGridInfos.Add(grid);
            }
        }
        private void ChangeReAdds()
        {
            for (int i = CompReAdds.Count - 1; i >= 0; i--)
            {
                var reAdd = CompReAdds[i];
                if (reAdd.Ai.Version != reAdd.AiVersion || Tick - reAdd.AddTick > 1200)
                {
                    CompReAdds.RemoveAtFast(i);
                    Log.Line($"ChangeReAdds reject: Age:{Tick - reAdd.AddTick} - Version:{reAdd.Ai.Version}({reAdd.AiVersion}) - Marked/Closed:{reAdd.Ai.MarkedForClose}({reAdd.Ai.Closed})");
                    continue;
                }

                if (!GridToInfoMap.ContainsKey(reAdd.Comp.MyCube.CubeGrid))
                {
                    continue;
                }

                if (reAdd.Comp.Ai != null && reAdd.Comp.Entity != null)
                {
                    reAdd.Comp.OnAddedToSceneTasks();
                }
                //else Log.Line($"ChangeReAdds nullSkip: Version:{reAdd.Ai.Version}({reAdd.AiVersion}) - Marked/Closed:{reAdd.Ai.MarkedForClose}({reAdd.Ai.Closed})");
                CompReAdds.RemoveAtFast(i);
            }
        }
示例#3
0
        private void StartComps()
        {
            for (int i = 0; i < CompsToStart.Count; i++)
            {
                var weaponComp = CompsToStart[i];
                if (weaponComp.MyCube.CubeGrid.IsPreview || CompRestricted(weaponComp))
                {
                    PlatFormPool.Return(weaponComp.Platform);
                    weaponComp.Platform = null;
                    CompsToStart.Remove(weaponComp);
                    continue;
                }

                if (weaponComp.MyCube.CubeGrid.Physics == null && !weaponComp.MyCube.CubeGrid.MarkedForClose && weaponComp.MyCube.BlockDefinition.HasPhysics)
                {
                    continue;
                }

                QuickDisableGunsCheck = true;
                if (weaponComp.Platform.State == MyWeaponPlatform.PlatformState.Fresh)
                {
                    if (weaponComp.MyCube.MarkedForClose)
                    {
                        CompsToStart.Remove(weaponComp);
                        continue;
                    }

                    if (!GridToInfoMap.ContainsKey(weaponComp.MyCube.CubeGrid))
                    {
                        continue;
                    }

                    if (ShieldApiLoaded)
                    {
                        SApi.AddAttacker(weaponComp.MyCube.EntityId);
                    }

                    IdToCompMap[weaponComp.MyCube.EntityId] = weaponComp;
                    weaponComp.MyCube.Components.Add(weaponComp);
                    CompsToStart.Remove(weaponComp);
                }
                else
                {
                    Log.Line($"comp didn't match CompsToStart condition, removing");
                    CompsToStart.Remove(weaponComp);
                }
            }
            CompsToStart.ApplyRemovals();
        }
示例#4
0
        private void RemoveGridFromMap(MyEntity myEntity)
        {
            var     grid = (MyCubeGrid)myEntity;
            GridMap gridMap;

            if (GridToInfoMap.TryRemove(grid, out gridMap))
            {
                ConcurrentListPool.Return(gridMap.MyCubeBocks);

                gridMap.Trash = true;
                GridMapPool.Return(gridMap);

                grid.OnFatBlockAdded   -= ToGridMap;
                grid.OnFatBlockRemoved -= FromGridMap;
                grid.OnClose           -= RemoveGridFromMap;
                grid.AddedToScene      -= GridAddedToScene;
                DirtyGridInfos.Add(grid);
            }
            else
            {
                Log.Line($"grid not removed and list not cleaned: marked:{grid.MarkedForClose}({grid.Closed}) - inScene:{grid.InScene}");
            }
        }
示例#5
0
        internal void PurgeAll()
        {
            PurgedAll = true;
            FutureEvents.Purge((int)Tick);


            foreach (var comp in CompsToStart)
            {
                if (comp?.Platform != null)
                {
                    CloseComps(comp.MyCube);
                }
            }

            foreach (var readd in CompReAdds)
            {
                if (!readd.Ai.Closed)
                {
                    readd.Ai.AiForceClose();
                }
                if (readd.Comp?.Platform != null)
                {
                    CloseComps(readd.Comp.MyCube);
                }
            }

            foreach (var comp in CompsDelayed)
            {
                if (comp?.Platform != null)
                {
                    CloseComps(comp.MyCube);
                }
            }

            foreach (var gridAi in DelayedAiClean)
            {
                if (!gridAi.Closed)
                {
                    gridAi.AiForceClose();
                }
            }

            PlatFormPool.Clean();
            CompsToStart.ClearImmediate();
            DelayedAiClean.ClearImmediate();

            CompsDelayed.Clear();
            CompReAdds.Clear();
            GridAiPool.Clean();


            PurgeTerminalSystem(this);
            HudUi.Purge();
            TerminalMon.Purge();
            foreach (var reports in Reporter.ReportData.Values)
            {
                foreach (var report in reports)
                {
                    report.Clean();
                    Reporter.ReportPool.Return(report);
                }
                reports.Clear();
            }
            Reporter.ReportData.Clear();
            Reporter.ReportPool.Clean();

            PacketsToClient.Clear();
            PacketsToServer.Clear();

            AcqManager.Clean();

            CleanSounds(true);

            foreach (var e in Emitters)
            {
                e.StopSound(true);
            }
            foreach (var e in Av.HitEmitters)
            {
                e.StopSound(true);
            }
            foreach (var e in Av.FireEmitters)
            {
                e.StopSound(true);
            }
            foreach (var e in Av.TravelEmitters)
            {
                e.StopSound(true);
            }

            Emitters.Clear();
            Av.HitEmitters.Clear();
            Av.FireEmitters.Clear();
            Av.TravelEmitters.Clear();

            foreach (var item in EffectedCubes)
            {
                var cubeid     = item.Key;
                var blockInfo  = item.Value;
                var functBlock = blockInfo.FunctBlock;

                if (functBlock == null || functBlock.MarkedForClose)
                {
                    _effectPurge.Enqueue(cubeid);
                    continue;
                }

                functBlock.EnabledChanged -= ForceDisable;
                functBlock.Enabled         = blockInfo.FirstState;
                functBlock.SetDamageEffect(false);
                if (HandlesInput)
                {
                    functBlock.AppendingCustomInfo -= blockInfo.AppendCustomInfo;
                }
                _effectPurge.Enqueue(cubeid);
            }

            while (_effectPurge.Count != 0)
            {
                EffectedCubes.Remove(_effectPurge.Dequeue());
            }

            Av.Glows.Clear();
            Av.AvShotPool.Clean();

            DeferedUpBlockTypeCleanUp(true);
            BlockTypeCleanUp.Clear();

            foreach (var map in GridToInfoMap.Keys)
            {
                RemoveGridFromMap(map);
            }

            GridToInfoMap.Clear();
            GridMapPool.Clean();

            DirtyGridsTmp.Clear();

            foreach (var structure in WeaponPlatforms.Values)
            {
                foreach (var system in structure.WeaponSystems)
                {
                    system.Value.PreFirePairs.Clear();
                    system.Value.FireWhenDonePairs.Clear();
                    system.Value.FirePerShotPairs.Clear();
                    system.Value.RotatePairs.Clear();
                    system.Value.ReloadPairs.Clear();
                    foreach (var ammo in system.Value.AmmoTypes)
                    {
                        ammo.AmmoDef.Const.PrimeEntityPool?.Clean();
                        ammo.AmmoDef.Const.HitDefaultSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitVoxelSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitShieldSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitFloatingSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitPlayerSoundPairs.Clear();
                        ammo.AmmoDef.Const.TravelSoundPairs.Clear();
                        ammo.AmmoDef.Const.CustomSoundPairs.Clear();
                    }
                }

                structure.WeaponSystems.Clear();
            }
            WeaponPlatforms.Clear();

            foreach (var gridToMap in GridToBlockTypeMap)
            {
                foreach (var map in gridToMap.Value)
                {
                    ConcurrentListPool.Return(map.Value);
                }
                gridToMap.Value.Clear();
                BlockTypePool.Return(gridToMap.Value);
            }
            GridToBlockTypeMap.Clear();

            foreach (var playerGrids in PlayerEntityIdInRange)
            {
                playerGrids.Value.Clear();
            }

            PlayerEntityIdInRange.Clear();
            DirtyGridInfos.Clear();

            DsUtil.Purge();
            DsUtil2.Purge();

            ShootingWeapons.Clear();
            WeaponToPullAmmo.Clear();
            AmmoToPullQueue.Clear();
            ChargingWeaponsIndexer.Clear();
            WeaponsToRemoveAmmoIndexer.Clear();
            ChargingWeapons.Clear();
            Hits.Clear();
            HomingWeapons.Clear();
            GridToMasterAi.Clear();
            Players.Clear();
            IdToCompMap.Clear();
            AllArmorBaseDefinitions.Clear();
            HeavyArmorBaseDefinitions.Clear();
            AllArmorBaseDefinitions.Clear();
            AcquireTargets.Clear();
            LargeBlockSphereDb.Clear();
            SmallBlockSphereDb.Clear();
            AnimationsToProcess.Clear();
            _subTypeIdToWeaponDefs.Clear();
            WeaponDefinitions.Clear();
            SlimsSortedList.Clear();
            _destroyedSlims.Clear();
            _destroyedSlimsClient.Clear();
            _slimHealthClient.Clear();
            _slimsSet.Clear();
            _turretDefinitions.Clear();
            _tmpNearByBlocks.Clear();

            foreach (var av in Av.AvShots)
            {
                av.GlowSteps.Clear();
                Av.AvShotPool.Return(av);
            }
            Av.AvShotPool.Clean();
            Av.AvBarrels1.Clear();
            Av.AvBarrels2.Clear();
            Av.AvShots.Clear();
            Av.HitSounds.Clear();

            foreach (var errorpkt in ClientSideErrorPkt)
            {
                errorpkt.Packet.CleanUp();
            }
            ClientSideErrorPkt.Clear();

            GridEffectPool.Clean();
            GridEffectsPool.Clean();
            BlockTypePool.Clean();
            ConcurrentListPool.Clean();

            TargetInfoPool.Clean();
            PacketObjPool.Clean();

            InventoryMoveRequestPool.Clean();
            WeaponCoreBlockDefs.Clear();
            VanillaIds.Clear();
            VanillaCoreIds.Clear();
            WeaponCoreFixedBlockDefs.Clear();
            WeaponCoreTurretBlockDefs.Clear();
            VoxelCaches.Clear();
            ArmorCubes.Clear();

            foreach (var p in Projectiles.ProjectilePool)
            {
                p.Info?.AvShot?.AmmoEffect?.Stop();
            }

            Projectiles.ShrapnelToSpawn.Clear();
            Projectiles.ShrapnelPool.Clean();
            Projectiles.FragmentPool.Clean();
            Projectiles.ActiveProjetiles.Clear();
            Projectiles.ProjectilePool.Clear();
            Projectiles.HitEntityPool.Clean();
            Projectiles.VirtInfoPool.Clean();

            DbsToUpdate.Clear();
            GridTargetingAIs.Clear();

            DsUtil          = null;
            DsUtil2         = null;
            SlimsSortedList = null;
            Settings        = null;
            StallReporter   = null;
            TerminalMon     = null;
            Physics         = null;
            Camera          = null;
            Projectiles     = null;
            TrackingAi      = null;
            UiInput         = null;
            TargetUi        = null;
            Placer          = null;
            TargetGps       = null;
            SApi.Unload();
            SApi                = null;
            Api                 = null;
            ApiServer           = null;
            Reporter            = null;
            WeaponDefinitions   = null;
            AnimationsToProcess = null;
            ProjectileTree.Clear();
            ProjectileTree     = null;
            Av                 = null;
            HudUi              = null;
            AllDefinitions     = null;
            SoundDefinitions   = null;
            ActiveCockPit      = null;
            ActiveControlBlock = null;
            ControlledEntity   = null;
            TmpStorage         = null;
        }
示例#6
0
        /*
         * IEnumerable<Vector3I> NearLine(Vector3I start, LineD line)
         * {
         *  MinHeap blocks;
         *  HashSet<Vector3I> seen = new HashSet<Vector3I> {start};
         *  blocks.Add(dist(line, start), start);
         *  while (!blocks.Empty)
         *  {
         *      var next = blocks.RemoveMin();
         *      yield return next;
         *      foreach (var neighbor in Neighbors(next))
         *      {
         *          if (seen.add(neighbor))
         *              blocks.Add(dist(line, neighbor), neighbor);
         *      }
         *  }
         * }
         */

        private void UpdateGrids()
        {
            DeferedUpBlockTypeCleanUp();

            DirtyGridsTmp.Clear();
            DirtyGridsTmp.AddRange(DirtyGridInfos);
            DirtyGridInfos.Clear();
            for (int i = 0; i < DirtyGridsTmp.Count; i++)
            {
                var grid       = DirtyGridsTmp[i];
                var newTypeMap = BlockTypePool.Get();
                newTypeMap[Offense]    = ConcurrentListPool.Get();
                newTypeMap[Utility]    = ConcurrentListPool.Get();
                newTypeMap[Thrust]     = ConcurrentListPool.Get();
                newTypeMap[Steering]   = ConcurrentListPool.Get();
                newTypeMap[Jumping]    = ConcurrentListPool.Get();
                newTypeMap[Power]      = ConcurrentListPool.Get();
                newTypeMap[Production] = ConcurrentListPool.Get();

                ConcurrentDictionary <WeaponDefinition.TargetingDef.BlockTypes, ConcurrentCachingList <MyCubeBlock> > noFatTypeMap;

                GridMap gridMap;
                if (GridToInfoMap.TryGetValue(grid, out gridMap))
                {
                    var allFat         = gridMap.MyCubeBocks;
                    var terminals      = 0;
                    var tStatus        = gridMap.Targeting == null || gridMap.Targeting.AllowScanning;
                    var thrusters      = 0;
                    var gyros          = 0;
                    var powerProducers = 0;
                    var warHead        = 0;
                    var working        = 0;
                    for (int j = 0; j < allFat.Count; j++)
                    {
                        var fat = allFat[j];
                        if (!(fat is IMyTerminalBlock))
                        {
                            continue;
                        }
                        terminals++;
                        using (fat.Pin()) {
                            if (fat.MarkedForClose)
                            {
                                continue;
                            }
                            if (fat.IsWorking && ++working == 1)
                            {
                                var oldCube = (gridMap.FakeController.SlimBlock as IMySlimBlock)?.FatBlock as MyCubeBlock;
                                if (oldCube == null || oldCube.MarkedForClose || oldCube.CubeGrid != grid)
                                {
                                    gridMap.FakeController.SlimBlock = fat.SlimBlock;
                                    GridDistributors[grid]           = gridMap;
                                }
                            }

                            var cockpit = fat as MyCockpit;
                            var decoy   = fat as IMyDecoy;
                            var bomb    = fat as IMyWarhead;

                            if (decoy != null)
                            {
                                WeaponDefinition.TargetingDef.BlockTypes type;
                                if (DecoyMap.TryGetValue(fat, out type))
                                {
                                    newTypeMap[type].Add(fat);
                                }
                                else
                                {
                                    newTypeMap[Utility].Add(fat);
                                    DecoyMap[fat] = Utility;
                                }
                                continue;
                            }

                            if (fat is IMyProductionBlock)
                            {
                                newTypeMap[Production].Add(fat);
                            }
                            else if (fat is IMyPowerProducer)
                            {
                                newTypeMap[Power].Add(fat);
                                powerProducers++;
                            }
                            else if (fat is IMyGunBaseUser || bomb != null || fat is MyConveyorSorter && WeaponPlatforms.ContainsKey(fat.BlockDefinition.Id))
                            {
                                if (bomb != null)
                                {
                                    warHead++;
                                }

                                if (!tStatus && fat is IMyGunBaseUser && !WeaponPlatforms.ContainsKey(fat.BlockDefinition.Id))
                                {
                                    tStatus = gridMap.Targeting.AllowScanning = true;
                                }

                                newTypeMap[Offense].Add(fat);
                            }
                            else if (fat is IMyUpgradeModule || fat is IMyRadioAntenna || cockpit != null && cockpit.EnableShipControl || fat is MyRemoteControl || fat is IMyShipGrinder || fat is IMyShipDrill)
                            {
                                newTypeMap[Utility].Add(fat);
                            }
                            else if (fat is MyThrust)
                            {
                                newTypeMap[Thrust].Add(fat);
                                thrusters++;
                            }
                            else if (fat is MyGyro)
                            {
                                newTypeMap[Steering].Add(fat);
                                gyros++;
                            }

                            else if (fat is MyJumpDrive)
                            {
                                newTypeMap[Jumping].Add(fat);
                            }
                        }
                    }

                    foreach (var type in newTypeMap)
                    {
                        type.Value.ApplyAdditions();
                    }

                    GridMap oldMap;
                    if (terminals == 0 && !gridMap.Trash && GridDistributors.TryRemove(grid, out oldMap))
                    {
                        oldMap.FakeController.SlimBlock = null;
                    }

                    gridMap.MyCubeBocks.ApplyAdditions();
                    gridMap.SuspectedDrone = warHead > 0 || powerProducers > 0 && thrusters > 0 && gyros > 0;
                    gridMap.Trash          = terminals == 0;
                    gridMap.Powered        = working > 0;
                    gridMap.PowerCheckTick = Tick;

                    var gridBlocks = grid.BlocksCount;

                    if (gridBlocks > gridMap.MostBlocks)
                    {
                        gridMap.MostBlocks = gridBlocks;
                    }

                    ConcurrentDictionary <WeaponDefinition.TargetingDef.BlockTypes, ConcurrentCachingList <MyCubeBlock> > oldTypeMap;
                    if (GridToBlockTypeMap.TryGetValue(grid, out oldTypeMap))
                    {
                        GridToBlockTypeMap[grid] = newTypeMap;
                        BlockTypeCleanUp.Enqueue(new DeferedTypeCleaning {
                            Collection = oldTypeMap, RequestTick = Tick
                        });
                    }
                    else
                    {
                        GridToBlockTypeMap[grid] = newTypeMap;
                    }
                }
                else if (GridToBlockTypeMap.TryRemove(grid, out noFatTypeMap))
                {
                    BlockTypeCleanUp.Enqueue(new DeferedTypeCleaning {
                        Collection = noFatTypeMap, RequestTick = Tick
                    });
                }
            }
            DirtyGridsTmp.Clear();
        }
示例#7
0
        private void UpdateGrids()
        {
            DeferedUpBlockTypeCleanUp();

            DirtyGridsTmp.Clear();
            DirtyGridsTmp.AddRange(DirtyGridInfos);
            DirtyGridInfos.Clear();
            for (int i = 0; i < DirtyGridsTmp.Count; i++)
            {
                var grid       = DirtyGridsTmp[i];
                var newTypeMap = BlockTypePool.Get();
                newTypeMap[Offense]    = ConcurrentListPool.Get();
                newTypeMap[Utility]    = ConcurrentListPool.Get();
                newTypeMap[Thrust]     = ConcurrentListPool.Get();
                newTypeMap[Steering]   = ConcurrentListPool.Get();
                newTypeMap[Jumping]    = ConcurrentListPool.Get();
                newTypeMap[Power]      = ConcurrentListPool.Get();
                newTypeMap[Production] = ConcurrentListPool.Get();

                ConcurrentDictionary <WeaponDefinition.TargetingDef.BlockTypes, ConcurrentCachingList <MyCubeBlock> > noFatTypeMap;

                GridMap gridMap;
                if (GridToInfoMap.TryGetValue(grid, out gridMap))
                {
                    var allFat    = gridMap.MyCubeBocks;
                    var terminals = 0;
                    var tStatus   = gridMap.Targeting == null || gridMap.Targeting.AllowScanning;
                    for (int j = 0; j < allFat.Count; j++)
                    {
                        var fat = allFat[j];
                        if (!(fat is IMyTerminalBlock))
                        {
                            continue;
                        }
                        terminals++;
                        using (fat.Pin()) {
                            if (fat.MarkedForClose)
                            {
                                continue;
                            }
                            var cockpit = fat as MyCockpit;

                            if (fat is IMyProductionBlock)
                            {
                                newTypeMap[Production].Add(fat);
                            }
                            else if (fat is IMyPowerProducer)
                            {
                                newTypeMap[Power].Add(fat);
                            }
                            else if (fat is IMyGunBaseUser || fat is IMyWarhead || fat is MyConveyorSorter && WeaponPlatforms.ContainsKey(fat.BlockDefinition.Id))
                            {
                                if (!tStatus && fat is IMyGunBaseUser && !WeaponPlatforms.ContainsKey(fat.BlockDefinition.Id))
                                {
                                    tStatus = gridMap.Targeting.AllowScanning = true;
                                }

                                newTypeMap[Offense].Add(fat);
                            }
                            else if (fat is IMyUpgradeModule || fat is IMyRadioAntenna || cockpit != null && cockpit.EnableShipControl || fat is MyRemoteControl || fat is IMyDecoy || fat is IMyShipGrinder || fat is IMyShipDrill)
                            {
                                newTypeMap[Utility].Add(fat);
                            }
                            else if (fat is MyThrust)
                            {
                                newTypeMap[Thrust].Add(fat);
                            }
                            else if (fat is MyGyro)
                            {
                                newTypeMap[Steering].Add(fat);
                            }
                            else if (fat is MyJumpDrive)
                            {
                                newTypeMap[Jumping].Add(fat);
                            }
                        }
                    }

                    foreach (var type in newTypeMap)
                    {
                        type.Value.ApplyAdditions();
                    }

                    gridMap.MyCubeBocks.ApplyAdditions();

                    gridMap.Trash = terminals == 0;
                    var gridBlocks = grid.BlocksCount;
                    if (gridBlocks > gridMap.MostBlocks)
                    {
                        gridMap.MostBlocks = gridBlocks;
                    }
                    ConcurrentDictionary <WeaponDefinition.TargetingDef.BlockTypes, ConcurrentCachingList <MyCubeBlock> > oldTypeMap;
                    if (GridToBlockTypeMap.TryGetValue(grid, out oldTypeMap))
                    {
                        GridToBlockTypeMap[grid] = newTypeMap;
                        BlockTypeCleanUp.Enqueue(new DeferedTypeCleaning {
                            Collection = oldTypeMap, RequestTick = Tick
                        });
                    }
                    else
                    {
                        GridToBlockTypeMap[grid] = newTypeMap;
                    }
                }
                else if (GridToBlockTypeMap.TryRemove(grid, out noFatTypeMap))
                {
                    BlockTypeCleanUp.Enqueue(new DeferedTypeCleaning {
                        Collection = noFatTypeMap, RequestTick = Tick
                    });
                }
            }
            DirtyGridsTmp.Clear();
        }