Пример #1
0
        void CheckObjectInVoxel()
        {
            if (m_checkObjectInsideVoxel >= m_synchronizedFloatingObjects.Count)
            {
                m_checkObjectInsideVoxel = 0;
            }

            if (m_synchronizedFloatingObjects.Count > 0)
            {
                var floatingObjectToCheck = m_synchronizedFloatingObjects[m_checkObjectInsideVoxel];

                BoundingBoxD aabb = floatingObjectToCheck.PositionComp.WorldAABB;

                using (m_tmpResultList.GetClearToken())
                {
                    MyGamePruningStructure.GetAllEntitiesInBox(ref aabb, m_tmpResultList);
                    MyVoxelMap voxelMap = m_tmpResultList.Find(m_isVoxelMapPredicate) as MyVoxelMap;
                    if (voxelMap != null && !voxelMap.MarkedForClose)
                    {
                        float unused;
                        var   penetrationAmountNormalized = voxelMap.GetVoxelContentInBoundingBox(aabb, out unused);
                        var   penetrationVolume           = penetrationAmountNormalized * MyVoxelConstants.VOXEL_VOLUME_IN_METERS;
                        var   penetrationRatio            = penetrationVolume / aabb.Volume;
                        if (penetrationRatio >= 1.0f)
                        {
                            floatingObjectToCheck.NumberOfFramesInsideVoxel++;

                            if (floatingObjectToCheck.NumberOfFramesInsideVoxel > MyFloatingObject.NUMBER_OF_FRAMES_INSIDE_VOXEL_TO_REMOVE)
                            {
                                //MyLog.Default.WriteLine("Floating object " + (floatingObjectToCheck.DisplayName != null ? floatingObjectToCheck.DisplayName : floatingObjectToCheck.ToString()) + " was removed because it was inside voxel.");
                                if (Sync.IsServer)
                                {
                                    RemoveFloatingObject(floatingObjectToCheck);
                                }
                            }
                        }
                        else
                        {
                            floatingObjectToCheck.NumberOfFramesInsideVoxel = 0;
                        }
                    }
                }
            }

            m_checkObjectInsideVoxel++;
        }
Пример #2
0
        private bool TestPlacement()
        {
            if (MySession.ControlledEntity != null &&
                (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator))
            {
                for (int i = 0; i < m_previewVoxelMaps.Count; ++i)
                {
                    var aabb = m_previewVoxelMaps[i].PositionComp.WorldAABB;

                    using (m_tmpResultList.GetClearToken())
                    {
                        MyGamePruningStructure.GetAllEntitiesInBox(ref aabb, m_tmpResultList);

                        foreach (var entity in m_tmpResultList)
                        {
                            m_tmpResultHashset.Add(entity.GetTopMostParent());
                        }

                        foreach (var entity in m_tmpResultHashset)
                        {
                            //ignore asteroids
                            if (entity is MyVoxelBase)
                            {
                                continue;
                            }

                            //ignore stations
                            if (entity is MyCubeGrid)
                            {
                                var grid = entity as MyCubeGrid;
                                if (grid.IsStatic)
                                {
                                    continue;
                                }
                            }

                            switch (m_previewVoxelMaps[i].GetVoxelRangeTypeInBoundingBox(entity.PositionComp.WorldAABB))
                            {
                            case MyVoxelRangeType.EMPTY:
                                break;

                            case MyVoxelRangeType.MIXED:
                            {
                                m_tmpResultList.Clear();
                                m_tmpResultHashset.Clear();
                                return(false);
                            }
                            break;

                            case MyVoxelRangeType.FULL:
                            {
                                m_tmpResultList.Clear();
                                m_tmpResultHashset.Clear();
                                return(false);
                            }
                            break;

                            default:
                                throw new InvalidBranchException();
                                break;
                            }
                        }
                        m_tmpResultHashset.Clear();
                    }
                }
            }
            return(true);
        }