Esempio n. 1
0
 public static IEnumerable <MyPlanet> AllPlanets()
 {
     using (lock_voxels.AcquireSharedUsing())
         foreach (MyPlanet planet in m_planets)
         {
             yield return(planet);
         }
 }
Esempio n. 2
0
        /// <summary>
        /// Rejection test for intersection with the profiled grid.
        /// </summary>
        /// <param name="grid">Grid whose cells will be rejected and compared to the profiled grid's rejections.</param>
        /// <returns>True iff there is a collision</returns>
        public bool rejectionIntersects(IMyCubeGrid grid, IMyCubeBlock ignore, out MyEntity entity, out Vector3?pointOfObstruction)
        {
            m_logger.debugLog("m_grid == null", Logger.severity.FATAL, condition: m_grid == null);

            //m_logger.debugLog("testing grid: " + grid.getBestName(), "rejectionIntersects()");

            GridCellCache gridCache = GridCellCache.GetCellCache(grid);
            MatrixD       toLocal   = m_grid.WorldMatrixNormalizedInv;
            Line          pathLine  = Path.get_Line();

            float minDist = m_grid.GridSize + grid.GridSize;
            //if (!m_landing)
            //	minDist += NotLandingBuffer;
            float pathRadius     = Path.Radius + minDist;
            float minDistSquared = minDist * minDist;

            MyEntity entity_in             = null;
            Vector3? pointOfObstruction_in = null;

            using (m_lock_rejcectionCells.AcquireSharedUsing())
                gridCache.ForEach(cell => {
                    Vector3 world = grid.GridIntegerToWorld(cell);
                    //m_logger.debugLog("checking position: " + world, "rejectionIntersects()");
                    if (pathLine.PointInCylinder(pathRadius, world))
                    {
                        //m_logger.debugLog("point in cylinder: " + world, "rejectionIntersects()");
                        Vector3 local = Vector3.Transform(world, toLocal);
                        if (rejectionIntersects(local, minDistSquared))
                        {
                            entity_in = grid.GetCubeBlock(cell).FatBlock as MyEntity ?? grid as MyEntity;
                            if (ignore != null && entity_in == ignore)
                            {
                                return(false);
                            }

                            pointOfObstruction_in = pathLine.ClosestPoint(world);
                            return(true);
                        }
                    }
                    return(false);
                });

            if (pointOfObstruction_in.HasValue)
            {
                entity             = entity_in;
                pointOfObstruction = pointOfObstruction_in;
                return(true);
            }

            entity             = null;
            pointOfObstruction = null;
            return(false);
        }
Esempio n. 3
0
        private void addKnownDefinition(string definition)
        {
            bool definitionIsKnown;

            using (lock_knownDefinitions.AcquireSharedUsing())
                definitionIsKnown = knownDefinitions.Contains(definition);
            if (!definitionIsKnown)
            {
                using (lock_knownDefinitions.AcquireExclusiveUsing())
                    knownDefinitions.Add(definition);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Acquire shared using lock on main thread.
        /// </summary>
        /// <returns>Shared using lock on main thread.</returns>
        public static IDisposable AcquireSharedUsing([CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
        {
            if (ThreadTracker.IsGameThread)
            {
                return(lock_dummy);
            }

            Profiler.StartProfileBlock("Waiting for shared lock. File: " + Path.GetFileName(callerFilePath) + " Member: " + callerMemberName);
            IDisposable result = Lock_MainThread.AcquireSharedUsing();

            Profiler.EndProfileBlock();
            return(result);
        }
Esempio n. 5
0
 public T this[int index]
 {
     get
     {
         using (lock_Queue.AcquireSharedUsing())
             return(Queue[index]);
     }
     set
     {
         using (lock_Queue.AcquireExclusiveUsing())
             Queue[index] = value;
     }
 }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns>an immutable read only list or null if there are no blocks of type T</returns>
 public ReadOnlyList <Ingame.IMyTerminalBlock> GetBlocksOfType(MyObjectBuilderType objBuildType)
 {
     //myLogger.debugLog("looking up type " + objBuildType, "GetBlocksOfType<T>()");
     using (lock_CubeBlocks.AcquireSharedUsing())
     {
         ListSnapshots <Ingame.IMyTerminalBlock> value;
         if (CubeBlocks_Type.TryGetValue(objBuildType, out value))
         {
             return(value.immutable());
             //value.IsClean = false;
             //return new ReadOnlyList<Ingame.IMyTerminalBlock>(value);
         }
         return(null);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// will return null if grid is closed, or CubeGridCache cannot be created
        /// </summary>
        public static CubeGridCache GetFor(IMyCubeGrid grid)
        {
            if (grid.Closed)
            {
                return(null);
            }

            CubeGridCache value;

            using (lock_registry.AcquireSharedUsing())
                if (registry.TryGetValue(grid, out value))
                {
                    return(value);
                }

            using (lock_registry.AcquireExclusiveUsing())
            {
                if (registry.TryGetValue(grid, out value))
                {
                    return(value);
                }
                try
                { return(new CubeGridCache(grid)); }
                catch (Exception e)
                {
                    (new Logger(null, "CubeGridCache")).log("Exception on creation: " + e, "GetFor()", Logger.severity.WARNING);
                    return(null);
                }
            }
        }
Esempio n. 8
0
        public void ForEach(Action <Vector3I> action)
        {
            using (lock_cellPositions.AcquireSharedUsing())
            {
                foreach (Vector3I cell in CellPositions)
                {
                    action(cell);
                }

                foreach (MyCubeBlock door in LargeDoors)
                {
                    if (door.Closed)
                    {
                        continue;
                    }

                    Dictionary <string, MyEntitySubpart> subparts = door.Subparts;
                    foreach (var part in subparts)
                    {
                        action(m_grid.WorldToGridInteger(part.Value.PositionComp.GetPosition()));
                    }
                }
            }
        }
Esempio n. 9
0
            public static void Add(long entityId, T script)
            {
                using (m_lock.AcquireExclusiveUsing())
                    m_dictionary.Add(entityId, script);

                if (m_afterScriptAdded != null)
                {
                    using (m_lock.AcquireSharedUsing())
                        if (m_afterScriptAdded != null)
                        {
                            foreach (Action <long, T> act in m_afterScriptAdded)
                            {
                                act.Invoke(entityId, script);
                            }
                        }
                }
            }
Esempio n. 10
0
        /// <summary>
        /// Count the number of blocks the cache contains that match BlockNamesContain.
        /// </summary>
        /// <param name="cache">Where to search for blocks.</param>
        /// <returns>An array of integers indicating how many blocks match each string in BlockNamesContain.</returns>
        public int[] Count(CubeGridCache cache)
        {
            if (m_sourceCount != CubeGridCache.DefinitionType.Count)
            {
                UpdateFromSource();
            }

            int[] results = new int[m_blocks.Length];

            using (m_lock.AcquireSharedUsing())
                for (int order = 0; order < m_blocks.Length; order++)
                {
                    MyDefinitionId[] array = m_blocks[order];
                    for (int index = 0; index < array.Length; index++)
                    {
                        results[order] += cache.CountByType(array[index]);
                    }
                }

            return(results);
        }
Esempio n. 11
0
 /// <summary>
 /// perform an Action while using a shared lock on main thread.
 /// </summary>
 /// <param name="safeAction">Action to perform</param>
 public static void UsingShared(Action safeAction)
 {
     using (Lock_MainThread.AcquireSharedUsing())
         safeAction.Invoke();
 }