Ejemplo n.º 1
0
        private static bool OnAttach(MyMechanicalConnectionBlockBase __instance, MyAttachableTopBlockBase top)
        {
            if (!BlockLimiterConfig.Instance.MergerBlocking || !BlockLimiterConfig.Instance.EnableLimits || !MySession.Static.Ready)
            {
                return(true);
            }
            var topGrid  = top.CubeGrid;
            var baseGrid = __instance.CubeGrid;

            var      remoteUserId = MyEventContext.Current.Sender.Value;
            DateTime topDateTime  = default;

            if (_lastChecked.TryGetValue(__instance.EntityId, out var inDateTime) || _lastChecked.TryGetValue(top.EntityId, out topDateTime))
            {
                if (Math.Abs((DateTime.Now - inDateTime).Seconds) > 10)
                {
                    _lastChecked.Remove(__instance.EntityId);
                }
                if (Math.Abs((DateTime.Now - topDateTime).Seconds) > 10)
                {
                    _lastChecked.Remove(top.EntityId);
                }

                if (remoteUserId <= 0)
                {
                    return(false);
                }
                Utilities.SendFailSound(remoteUserId);
                Utilities.ValidationFailed(remoteUserId);
                return(false);
            }
            var result = Grid.CanMerge(topGrid, baseGrid, out var blocks, out var count, out var limitName);

            if (result)
            {
                return(true);
            }

            _lastChecked[__instance.EntityId] = DateTime.Now;
            _lastChecked[top.EntityId]        = DateTime.Now;

            BlockLimiter.Instance.Log.Info($"Blocked attachement between {baseGrid.DisplayName} and {topGrid.DisplayName}");

            if (remoteUserId <= 0)
            {
                return(false);
            }
            Utilities.SendFailSound(remoteUserId);
            Utilities.ValidationFailed(remoteUserId);
            var msg = Utilities.GetMessage(BlockLimiterConfig.Instance.DenyMessage, blocks, limitName, count);

            BlockLimiter.Instance.Torch.CurrentSession.Managers.GetManager <ChatManagerServer>()?
            .SendMessageAsOther(BlockLimiterConfig.Instance.ServerName, msg, Color.Red, remoteUserId);
            topGrid.RemoveBlock(top.SlimBlock);
            baseGrid.RemoveBlock(__instance.SlimBlock);
            return(false);
        }
Ejemplo n.º 2
0
        private void CalculateBoxesContaining()
        {
            foreach (ShipyardItem item in ProcessLocalYards.LocalYards)
            {
                foreach (IMyCubeGrid grid in item.ContainsGrids)
                {
                    if (item.YardType != ShipyardType.Disabled || grid.Closed || !ShipyardSettings.Instance.GetYardSettings(item.EntityId).GuideEnabled)
                    {
                        BoxDict.Remove(grid.EntityId);
                        continue;
                    }
                    //if (BoxDict.ContainsKey(grid.EntityId) && Vector3D.DistanceSquared(BoxDict[grid.EntityId].LastPos, grid.GetPosition()) < 0.01)
                    //    continue;

                    uint color;

                    if (grid.Physics != null)
                    {
                        color = Color.Green.PackedValue;
                    }
                    else
                    {
                        var proj = grid.Projector();

                        if (proj == null) //ghost grid like Digi's helmet
                        {
                            continue;
                        }

                        if (proj.RemainingBlocks == 0) //projection is complete
                        {
                            continue;
                        }

                        color = Color.Cyan.PackedValue;
                    }

                    BoxDict[grid.EntityId] = new BoxItem
                    {
                        Lines  = MathUtility.CalculateObbLines(MathUtility.CreateOrientedBoundingBox(grid)),
                        GridId = grid.EntityId,
                        //PackedColor = grid.Physics == null ? Color.Cyan.PackedValue : Color.Green.PackedValue,
                        PackedColor = color,
                        LastPos     = grid.GetPosition()
                    };
                }
            }
        }
Ejemplo n.º 3
0
        public void RemoveTrigger(MyEntity entity)
        {
            MyUpdateTriggerComponent t;

            if (m_triggers.TryGetValue(entity, out t))
            {
                m_triggers.Remove(entity);
            }
        }
Ejemplo n.º 4
0
        protected void RemoveChild(IMyReplicable replicable, IMyReplicable parent)
        {
            m_childToParent.Remove(replicable);
            var children = m_parentToChildren[parent];

            children.Remove(replicable);
            if (children.Count == 0)
            {
                m_parentToChildren.Remove(parent);
                m_hashSetPool.Push(children);
            }
        }
Ejemplo n.º 5
0
        protected virtual void RaiseDestroyed()
        {
            var handler = Destroyed;

            if (handler != null)
            {
                handler(this);
            }

            // Probably happens when replicable is not fully initialized, but it's being destroyed (world unload)
            var inst = GetInstance();

            if (inst != null)
            {
                m_objectExternalReplicables.Remove(inst);
            }
        }
        public bool CleanCachedChunks()
        {
            int count     = m_chunksbyAge.Count;
            int discarded = 0;

            // This procedure is thread safe enough because even if a chunk
            // is discarded when in use the data is still valid.
            for (int i = 0; i < count && discarded < MaxChunksToDiscard; ++i)
            {
                var coord = m_chunksbyAge.Dequeue();

                var ck = m_cachedChunks[coord];

                // this allows us to skip locking on most chunks
                if (ck.Dirty == 0 && ck.HitCount <= MaximumHitsForDiscard)
                {
                    using (ck.Lock.AcquireSharedUsing())
                    {
                        if (ck.Dirty == 0 && ck.HitCount <= MaximumHitsForDiscard)
                        {
                            using (m_cacheLock.AcquireExclusiveUsing())
                            {
                                m_cachedChunks.Remove(coord);
                                m_cacheMap.RemoveProxy(ck.TreeProxy);
                            }
                        }
                        else
                        {
                            // not removed, requeue, refresh age
                            m_chunksbyAge.Enqueue(coord);
                            ck.HitCount = 0; // reset hit count for next time.
                        }
                    }
                }
                else
                {
                    m_chunksbyAge.Enqueue(coord);
                    ck.HitCount = 0; // reset hit count for next time.
                }
            }

            return(m_cachedChunks.Count == 0);
        }
Ejemplo n.º 7
0
        public override void UpdateAfterSimulation100()
        {
            //Debug.Assert(MyExternalReplicable.FindByObject(this) != null, "Planet replicable not found, but it should be there");
            base.UpdateAfterSimulation100();

            if (m_physicsShapes != null)
            {
                ProfilerShort.Begin("Study shapes to remove");
                foreach (var physicsShape in m_physicsShapes)
                {
                    BoundingBoxD box;
                    if (physicsShape.Value != null)
                    {
                        box      = physicsShape.Value.PositionComp.WorldAABB;
                        box.Min -= box.HalfExtents;
                        box.Max += box.HalfExtents;
                    }
                    else
                    {
                        Vector3 min = (Vector3)physicsShape.Key * PHYSICS_SECTOR_SIZE_METERS + PositionLeftBottomCorner;
                        box = new BoundingBoxD(min, min + PHYSICS_SECTOR_SIZE_METERS);
                    }

                    m_entities.Clear();

                    MyGamePruningStructure.GetTopMostEntitiesInBox(ref box, m_entities);

                    bool keep = false;
                    foreach (var entity in m_entities)
                    {
                        if (entity.Physics != null)
                        {
                            if (entity.Physics.IsStatic)
                            {
                                MyCubeGrid grid = entity as MyCubeGrid;
                                //welded grids to voxels are static but planet physics sector needs to be kept for them
                                if (grid != null && grid.IsStatic == false)
                                {
                                    keep = true;
                                }
                            }
                            else
                            {
                                keep = true;
                            }
                        }
                    }

                    if (!keep)
                    {
                        m_sectorsPhysicsToRemove.Add(physicsShape.Key);
                    }
                }

                foreach (var shapeToRemove in m_sectorsPhysicsToRemove)
                {
                    MyVoxelPhysics physics;
                    if (m_physicsShapes.TryGetValue(shapeToRemove, out physics))
                    {
                        if (physics != null)
                        {
                            physics.Close();
                        }
                    }
                    m_physicsShapes.Remove(shapeToRemove);
                }
                m_sectorsPhysicsToRemove.Clear();
                ProfilerShort.End();
            }
        }
Ejemplo n.º 8
0
 public static void RemoveEntity(long entityId)
 {
     //    Debug.Assert(m_entityList.ContainsKey(entityId), "Attempting to remove already removed entity. This shouldn't happen.");
     m_entityList.Remove(entityId);
 }