예제 #1
0
 public static GridCellCache GetCellCache(IMyCubeGrid grid)
 {
     GridCellCache cache;
     using (lock_cellCache.AcquireExclusiveUsing())
         if (!CellCache.TryGetValue(grid, out cache))
         {
             cache = new GridCellCache(grid);
             CellCache.Add(grid, cache);
         }
     return cache;
 }
예제 #2
0
        public static GridCellCache GetCellCache(IMyCubeGrid grid)
        {
            GridCellCache cache;

            using (lock_cellCache.AcquireExclusiveUsing())
                if (!CellCache.TryGetValue(grid, out cache))
                {
                    cache = new GridCellCache(grid);
                    CellCache.Add(grid, cache);
                }
            return(cache);
        }
예제 #3
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);
        }
예제 #4
0
        public void Init(IMyCubeGrid grid, RelativePosition3F destination, Vector3 navBlockLocalPosition, bool landing)
        {
            if (grid != m_grid)
            {
                this.m_grid      = grid;
                this.m_logger    = new Logger(() => m_grid.DisplayName);
                this.m_cellCache = GridCellCache.GetCellCache(grid);
            }

            m_directNorm = Vector3.Normalize(destination.ToLocal() - navBlockLocalPosition);
            m_landing    = landing;
            Vector3 centreDestination = destination.ToLocal() + Centre - navBlockLocalPosition;

            rejectAll();
            createCapsule(centreDestination, navBlockLocalPosition);
        }
예제 #5
0
        public void Init(IMyCubeGrid grid, RelativePosition3F destination, Vector3 navBlockLocalPosition, bool landing)
        {
            if (grid != m_grid)
            {
                this.m_grid = grid;
                this.m_logger = new Logger("GridShapeProfiler", () => m_grid.DisplayName);
                this.m_cellCache = GridCellCache.GetCellCache(grid);
            }

            m_directNorm = Vector3.Normalize(destination.ToLocal() - navBlockLocalPosition);
            m_landing = landing;
            Vector3 centreDestination = destination.ToLocal() + Centre - navBlockLocalPosition;
            rejectAll();
            createCapsule(centreDestination, navBlockLocalPosition);
        }