private void GetChunk(ref Vector3I coord, out VoxelChunk chunk, MyStorageDataTypeFlags required)
        {
            using (m_cacheLock.AcquireExclusiveUsing())
            {
                if (!m_cachedChunks.TryGetValue(coord, out chunk))
                {
                    chunk = new VoxelChunk(coord);

                    var rangeStart = coord << VoxelChunk.SizeBits;
                    var rangeEnd   = ((coord + 1) << VoxelChunk.SizeBits) - 1;

                    if (required != 0)
                    {
                        using (m_storageLock.AcquireSharedUsing())
                            ReadDatForChunk(chunk, required);
                    }

                    m_chunksbyAge.Enqueue(coord);
                    m_cachedChunks.Add(coord, chunk);

                    var bb = new BoundingBox(rangeStart, rangeEnd);

                    chunk.TreeProxy = m_cacheMap.AddProxy(ref bb, chunk, 0);
                }
                else if ((chunk.Cached & required) != required)
                {
                    using (m_storageLock.AcquireSharedUsing())
                        ReadDatForChunk(chunk, required & ~chunk.Cached);
                }
            }
        }
Ejemplo n.º 2
0
        private void storage_RangeChangedPlanet(Vector3I minChanged, Vector3I maxChanged, MyStorageDataTypeFlags dataChanged)
        {
            ProfilerShort.Begin("MyVoxelMap::storage_RangeChanged");
            Vector3I minSector = minChanged / PHYSICS_SECTOR_SIZE_METERS;
            Vector3I maxSector = maxChanged / PHYSICS_SECTOR_SIZE_METERS;

            MyVoxelPhysics voxelMap;

            if (m_physicsShapes != null)
            {
                for (var it = new Vector3I_RangeIterator(ref minSector, ref maxSector);
                     it.IsValid(); it.MoveNext())
                {
                    if (m_physicsShapes.TryGetValue(it.Current, out voxelMap))
                    {
                        if (voxelMap != null)
                        {
                            voxelMap.OnStorageChanged(minChanged, maxChanged, dataChanged);
                        }
                    }
                }
            }

            if (Render is MyRenderComponentVoxelMap)
            {
                (Render as MyRenderComponentVoxelMap).InvalidateRange(minChanged, maxChanged);
            }

            OnRangeChanged(minChanged, maxChanged, dataChanged);
            ProfilerShort.End();
        }
Ejemplo n.º 3
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.º 4
0
        private static void EnqueueHistory(MyVoxelDataRequest request)
        {
            using (m_historyLock.AcquireExclusiveUsing())
            {
                if (UnculledRequestHistory.Count >= MAX_UNCULLED_HISTORY)
                {
                    UnculledRequestHistory.Dequeue();
                }

                request.Target = null;
                UnculledRequestHistory.Enqueue(request);
            }

            MyConcurrentHashSet <Vector3I> sizes;

            if (!KnownLodSizes.TryGetValue(request.Lod, out sizes))
            {
                sizes = new MyConcurrentHashSet <Vector3I>();
                if (!KnownLodSizes.TryAdd(request.Lod, sizes))
                {
                    sizes = KnownLodSizes[request.Lod];
                }
            }

            sizes.Add(request.maxInLod - request.minInLod + Vector3I.One);
        }
Ejemplo n.º 5
0
        public static bool TryGetEntity(long entityId, out IMyEntity entity)
        {
            bool result = m_entityList.TryGetValue(entityId, out entity);

            Debug.Assert(!result || !entity.DebugAsyncLoading, "Getting entity which is being asynchronously loaded!");
            return(result);
        }
Ejemplo n.º 6
0
        //  Lazy-loading and then returning reference to model
        //  Doesn't load vertex/index shader and doesn't touch GPU. Use it when you need model data - vertex, triangles, octre...
        public static MyModel GetModelOnlyData(string modelAsset)
        {
            if (string.IsNullOrEmpty(modelAsset))
            {
                return(null);
            }

            MyModel model;

            if (!m_models.TryGetValue(modelAsset, out model))
            {
                model = new MyModel(modelAsset);
                m_models[modelAsset] = model;
            }

            model.LoadData();
            return(model);
        }
Ejemplo n.º 7
0
        public void AddTrigger(MyEntity entity, int triggerSize)
        {
            if (entity == null)
            {
                return;
            }
            MyUpdateTriggerComponent t;

            if (m_triggers.TryGetValue(entity, out t))
            {
                t.Size = triggerSize;
            }
            else
            {
                t = new MyUpdateTriggerComponent(triggerSize);
                entity.Components.Add(t);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Refreshes replicable, updates it's child status and parent.
        /// Returns true if replicable is root.
        /// </summary>
        bool Refresh(IMyReplicable replicable)
        {
            IMyReplicable parent;

            if (replicable.HasToBeChild && TryGetParent(replicable, out parent)) // Replicable is child
            {
                IMyReplicable oldParent;
                if (m_childToParent.TryGetValue(replicable, out oldParent)) // Replicable was child
                {
                    if (oldParent != parent)                                // Replicable was child with different parent
                    {
                        RemoveChild(replicable, oldParent);
                        AddChild(replicable, parent);
                    }
                }
                else // Replicable was root
                {
                    RemoveRoot(replicable);
                    AddChild(replicable, parent);
                }
                return(false);
            }
            else
            {
                IMyReplicable oldParent;
                if (m_childToParent.TryGetValue(replicable, out oldParent)) // Replicable was child
                {
                    RemoveChild(replicable, oldParent);
                    AddRoot(replicable);
                    return(true);
                }
                else if (ContainsRoot(replicable)) // Replicable was root
                {
                    Debug.Assert(!replicable.HasToBeChild, "Cannot have child in roots");

                    // Nothing to do, was root and is root
                    return(true);
                }
                else
                {
                    return(false); // Replicable was removed meanwhile
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Refreshes replicable, updates it's child status and parent.
        /// Returns true if replicable is root.
        /// </summary>
        public bool Refresh(IMyReplicable replicable)
        {
            IMyReplicable parent;

            if (replicable.IsChild && TryGetDependency(replicable, out parent)) // Replicable is child
            {
                IMyReplicable oldParent;
                if (m_childToParent.TryGetValue(replicable, out oldParent)) // Replicable was child
                {
                    if (oldParent != parent)                                // Replicable was child with different parent
                    {
                        RemoveChild(replicable, oldParent);
                        AddChild(replicable, parent);
                    }
                }
                else // Replicable was root
                {
                    m_roots.Remove(replicable);
                    AddChild(replicable, parent);
                }
                return(false);
            }
            else
            {
                IMyReplicable oldParent;
                if (m_childToParent.TryGetValue(replicable, out oldParent)) // Replicable was child
                {
                    RemoveChild(replicable, oldParent);
                    m_roots.Add(replicable);
                    return(true);
                }
                else if (m_roots.Contains(replicable)) // Replicable was root
                {
                    // Nothing to do, was root and is root
                    return(true);
                }
                else
                {
                    return(false); // Replicable was removed meanwhile
                }
            }
        }
Ejemplo n.º 10
0
        protected void AddChild(IMyReplicable replicable, IMyReplicable parent)
        {
            HashSet <IMyReplicable> children;

            if (!m_parentToChildren.TryGetValue(parent, out children))
            {
                children = Obtain();
                m_parentToChildren[parent] = children;
            }
            children.Add(replicable);
            m_childToParent[replicable] = parent;
        }
Ejemplo n.º 11
0
        public static MyCubeBlockDefinition GetDefinition(MyObjectBuilder_CubeBlock block)
        {
            if (DefCache.TryGetValue(block.SubtypeId, out var def))
            {
                return(def);
            }

            var blockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(block);

            DefCache[block.SubtypeId] = blockDefinition;
            return(blockDefinition);
        }
Ejemplo n.º 12
0
        // Don't call remove reference on this, this shape is pooled
        public HkShape GetDebrisShape(MyModel model, HkShapeType shapeType)
        {
            MyModelShapeInfo info = new MyModelShapeInfo();

            info.Model     = model;
            info.ShapeType = shapeType;

            HkShape shape;

            if (!m_shapes.TryGetValue(info, out shape))
            {
                shape = CreateShape(model, shapeType);
                m_shapes.TryAdd(info, shape);
            }
            return(shape);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets an instance from the pool.
        /// </summary>
        /// <returns>An instance of <typeparamref name="T"/>.</returns>
        public T Get(Thread thread)
        {
            MyConcurrentQueue <T> queue;

            if (!m_instances.TryGetValue(thread, out queue))
            {
                queue = new MyConcurrentQueue <T>();
                m_instances.Add(thread, queue);
            }

            T instance;

            if (!queue.TryDequeue(out instance))
            {
                instance = new T();
            }

            return(instance);
        }
Ejemplo n.º 14
0
        public Type FindTypeFor(object obj)
        {
            Type originalType = obj.GetType();

            if (originalType.IsValueType)
            {
                throw new InvalidOperationException("obj cannot be value type");
            }

            Type resultType = null;
            Type lookupType = originalType;

            while (lookupType != typeof(Object) && !m_objTypeToExternalReplicableType.TryGetValue(lookupType, out resultType))
            {
                lookupType = lookupType.BaseType;
            }
            if (originalType != lookupType)
            {
                m_objTypeToExternalReplicableType.TryAdd(originalType, resultType); // Faster lookup next time
            }
            return(resultType);
        }