Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public bool isGridAttached(IMyCubeGrid grid)
 {
     if (myGrid == grid)
     {
         return(true);
     }
     if (needsRebuild || connectedChanged())
     {
         // might be rebuilding too frequently
         if (needsRebuild)
         {
             myLogger.debugLog("needsRebuild == true", "isGridAttached()");
         }
         else
         {
             myLogger.debugLog("connectedChanged() == true", "isGridAttached()");
         }
         rebuildAttached();
         needsRebuild = false;
     }
     return(isGridAttached(getFor(grid), ++searchAttached_ID));
 }
Exemplo n.º 3
0
        private CubeGridCache(IMyCubeGrid grid)
        {
            myLogger = new Logger("CubeGridCache", () => grid.DisplayName);
            CubeGrid = grid;
            List<IMySlimBlock> allSlims = new List<IMySlimBlock>();
            CubeGrid.GetBlocks_Safe(allSlims, slim => slim.FatBlock != null);

            foreach (IMySlimBlock slim in allSlims)
                CubeGrid_OnBlockAdded(slim);

            CubeGrid.OnBlockAdded += CubeGrid_OnBlockAdded;
            CubeGrid.OnBlockRemoved += CubeGrid_OnBlockRemoved;
            CubeGrid.OnClosing += CubeGrid_OnClosing;

            Registrar.Add(CubeGrid, this);
            myLogger.debugLog("built for: " + CubeGrid.DisplayName, Logger.severity.DEBUG);
        }
Exemplo n.º 4
0
        private GridCellCache(IMyCubeGrid grid)
        {
            m_logger = new Logger("GridCellCache", () => grid.DisplayName);
            m_grid = grid;

            List<IMySlimBlock> dummy = new List<IMySlimBlock>();
            MainLock.UsingShared(() => {
                using (lock_cellPositions.AcquireExclusiveUsing())
                    grid.GetBlocks(dummy, slim => {
                        Add(slim);
                        return false;
                    });

                grid.OnBlockAdded += grid_OnBlockAdded;
                grid.OnBlockRemoved += grid_OnBlockRemoved;
                grid.OnClosing += grid_OnClosing;
            });

            m_logger.debugLog("Initialized");
        }
Exemplo n.º 5
0
        private GridCellCache(IMyCubeGrid grid)
        {
            m_logger = new Logger(() => grid.DisplayName);
            m_grid   = grid;

            List <IMySlimBlock> dummy = new List <IMySlimBlock>();

            MainLock.UsingShared(() => {
                using (lock_cellPositions.AcquireExclusiveUsing())
                    grid.GetBlocks(dummy, slim => {
                        Add(slim);
                        return(false);
                    });

                grid.OnBlockAdded   += grid_OnBlockAdded;
                grid.OnBlockRemoved += grid_OnBlockRemoved;
                grid.OnClosing      += grid_OnClosing;
            });

            m_logger.debugLog("Initialized");
        }