public bool TryGetSector(long id, out MyEnvironmentSector environmentSector)
 {
     if (!PhysicsSectors.TryGetValue(id, out environmentSector))
     {
         return(HeldSectors.TryGetValue(id, out environmentSector));
     }
     return(false);
 }
        public void Init(MyEnvironmentSector sector, List<int> items)
        {
            m_sector = sector;
            m_items = items;
            m_spawnQueue = new Queue<int>();

            foreach (var item in m_items)
                m_spawnQueue.Enqueue(item);
        }
        public void Init(MyEnvironmentSector sector, List<int> items)
        {
            m_sector = sector;
            MyEntityComponentBase comp = (MyEntityComponentBase)m_sector.Owner;
            m_planet = comp.Entity as MyPlanet;
            m_items = items;

            LoadVoxelMapsInfo();
        }
        public void Init(MyEnvironmentSector sector, List <int> items)
        {
            m_sector = sector;

            if (Sync.IsServer)
            {
                m_sector.OnContactPoint += SectorOnContactPoint;
            }
        }
 internal bool CheckOnGraphicsClose(MyEnvironmentSector sector)
 {
     if (sector.HasPhysics == sector.IsPendingPhysicsToggle && !sector.IsPinned)
     {
         EnqueueClosing(sector);
         return(true);
     }
     return(false);
 }
        public void Init(IMy2DClipmapManager parent, int x, int y, int lod, ref BoundingBox2D bounds)
        {
            m_manager = (MyPlanetEnvironmentComponent)parent;

            var bounds3D = new BoundingBoxD(new Vector3D(bounds.Min, 0), new Vector3D(bounds.Max, 0));

            Lod = lod;

            Face = m_manager.ActiveFace;

            var matrix = m_manager.ActiveClipmap.WorldMatrix;

            bounds3D = bounds3D.Transform(matrix);

            Coords = new Vector2I(x, y);

            Id = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod);

            m_manager.RegisterProxy(this);

            MyEnvironmentSectorParameters sectorParams;

            matrix.Translation = Vector3D.Zero;

            sectorParams.SurfaceBasisX = Vector3.Transform(new Vector3(bounds.Width / 2, 0, 0), matrix);
            sectorParams.SurfaceBasisY = Vector3.Transform(new Vector3(0, bounds.Height / 2, 0), matrix);
            sectorParams.Center        = bounds3D.Center;

            if (lod > m_manager.MaxLod)
            {
                return;
            }

            if (!m_manager.TryGetSector(Id, out EnvironmentSector))
            {
                sectorParams.SectorId = Id;
                sectorParams.EntityId = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod);

                sectorParams.Bounds = m_manager.GetBoundingShape(ref sectorParams.Center, ref sectorParams.SurfaceBasisX, ref sectorParams.SurfaceBasisY);;

                sectorParams.Environment = m_manager.EnvironmentDefinition;

                sectorParams.DataRange = new BoundingBox2I(Coords << lod, ((Coords + 1) << lod) - 1);

                sectorParams.Provider = m_manager.Providers[m_manager.ActiveFace];

                EnvironmentSector = m_manager.EnvironmentDefinition.CreateSector();
                EnvironmentSector.Init(m_manager, ref sectorParams);

                m_manager.Planet.AddChildEntity((MyEntity)EnvironmentSector);
            }

            m_manager.EnqueueOperation(this, lod);
            LodSet = lod;

            EnvironmentSector.OnLodCommit += sector_OnMyLodCommit;
        }
Ejemplo n.º 7
0
        public void OnWorldPosChanged(ref MatrixD newTransform)
        {
            MatrixD worldPos = newTransform;

            m_caster.OnWorldPositionChanged(ref worldPos);

            var      entitiesInRange = this.m_caster.EntitiesInRange;
            float    closestDistance = float.MaxValue;
            MyEntity closestEntity   = null;
            int      itemId          = 0;

            if (!m_isPointOfRefSet)
            {
                m_pointOfReference = worldPos.Translation;
            }

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
                // int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    float distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_pointOfReference);

                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            closestEntity          = entity.Entity;
                            itemId                 = entity.ItemId;
                            this.m_distanceToHitSq = distanceSq;
                            this.m_hitPosition     = entity.DetectionPoint;

                            closestDistance = distanceSq;
                        }
                    }
                    //   ++i;
                }
            }

            this.m_hitCubeGrid          = closestEntity as MyCubeGrid;
            this.m_hitBlock             = null;
            this.m_hitDestroaybleObj    = closestEntity as IMyDestroyableObject;
            this.m_hitFloatingObject    = closestEntity as MyFloatingObject;
            this.m_hitCharacter         = closestEntity as MyCharacter;
            this.m_hitEnvironmentSector = closestEntity as MyEnvironmentSector;
            this.m_environmentItem      = itemId;

            if (m_hitCubeGrid != null)
            {
                var      invWorld     = m_hitCubeGrid.PositionComp.WorldMatrixNormalizedInv;
                var      gridLocalPos = Vector3D.Transform(this.m_hitPosition, invWorld);
                Vector3I blockPos;
                m_hitCubeGrid.FixTargetCube(out blockPos, gridLocalPos / m_hitCubeGrid.GridSize);
                m_hitBlock = m_hitCubeGrid.GetCubeBlock(blockPos);
            }
        }
Ejemplo n.º 8
0
        public void Init(MyEnvironmentSector sector, List <int> items)
        {
            m_sector = sector;
            MyEntityComponentBase comp = (MyEntityComponentBase)m_sector.Owner;

            m_planet = comp.Entity as MyPlanet;
            m_items  = items;

            LoadVoxelMapsInfo();
        }
 public void ScheduleWork(MyEnvironmentSector sector, bool parallel)
 {
     if (parallel)
     {
         m_sectorsToWorkParallel.Enqueue(sector);
     }
     else
     {
         m_sectorsToWorkSerial.Enqueue(sector);
     }
 }
Ejemplo n.º 10
0
        public void Init(MyEnvironmentSector sector, List <int> items)
        {
            m_sector     = sector;
            m_items      = items;
            m_spawnQueue = new Queue <int>();

            foreach (var item in m_items)
            {
                m_spawnQueue.Enqueue(item);
            }
        }
        public void Init(IMy2DClipmapManager parent, int x, int y, int lod, ref BoundingBox2D bounds)
        {
            m_manager = (MyPlanetEnvironmentComponent)parent;

            var bounds3D = new BoundingBoxD(new Vector3D(bounds.Min, 0), new Vector3D(bounds.Max, 0));
            Lod = lod;

            Face = m_manager.ActiveFace;

            var matrix = m_manager.ActiveClipmap.WorldMatrix;

            bounds3D = bounds3D.Transform(matrix);

            Coords = new Vector2I(x, y);

            Id = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod);

            m_manager.RegisterProxy(this);

            MyEnvironmentSectorParameters sectorParams;

            matrix.Translation = Vector3D.Zero;

            sectorParams.SurfaceBasisX = Vector3.Transform(new Vector3(bounds.Width / 2, 0, 0), matrix);
            sectorParams.SurfaceBasisY = Vector3.Transform(new Vector3(0, bounds.Height / 2, 0), matrix);
            sectorParams.Center = bounds3D.Center;

            if (lod > m_manager.MaxLod) return;

            if (!m_manager.TryGetSector(Id, out EnvironmentSector))
            {
                sectorParams.SectorId = Id;
                sectorParams.EntityId = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod);

                sectorParams.Bounds = m_manager.GetBoundingShape(ref sectorParams.Center, ref sectorParams.SurfaceBasisX, ref sectorParams.SurfaceBasisY); ;

                sectorParams.Environment = m_manager.EnvironmentDefinition;

                sectorParams.DataRange = new BoundingBox2I(Coords << lod, ((Coords + 1) << lod) - 1);

                sectorParams.Provider = m_manager.Providers[m_manager.ActiveFace];

                EnvironmentSector = m_manager.EnvironmentDefinition.CreateSector();
                EnvironmentSector.Init(m_manager, ref sectorParams);

                m_manager.Planet.AddChildEntity((MyEntity)EnvironmentSector);
            }

            m_manager.EnqueueOperation(this, lod);
            LodSet = lod;

            EnvironmentSector.OnLodCommit += sector_OnMyLodCommit;
        }
 public void SetSectorPinned(MyEnvironmentSector sector, bool pinned)
 {
     if (pinned != sector.IsPinned)
     {
         if (pinned)
         {
             sector.IsPinned = true;
             HeldSectors.Add(sector.SectorId, sector);
         }
         else
         {
             sector.IsPinned = false;
             HeldSectors.Remove(sector.SectorId);
         }
     }
 }
        private void sector_OnMyLodCommit(MyEnvironmentSector sector, int lod)
        {
            Debug.Assert(sector == EnvironmentSector);
            Debug.Assert((m_closed == (lod == -1)) || m_dependencies.Count > 0, "Lod set does not match expected lod.");

            if (lod == LodSet)
            {
                m_stateCommited = true;

                if (m_dependencies.Count == 0)
                {
                    if (lod == -1 && m_closed)
                        CloseCommit(false);
                    else
                        NotifyDependants(false);
                }
            } // if dependants then we actually commited a different lod, in that case we just ignore this
        }
Ejemplo n.º 14
0
        private static bool IsVoxelItem(MyEnvironmentSector sector, short definitionIndex)
        {
            var modules = sector.Owner.EnvironmentDefinition.Items[definitionIndex].Type.ProxyModules;

            if (modules == null)
            {
                return(false);
            }

            for (int i = 0; i < modules.Length; ++i)
            {
                if (modules[i].Type.IsSubclassOf(typeof(MyVoxelMapEnvironmentProxy)) || modules[i].Type == typeof(MyVoxelMapEnvironmentProxy))
                {
                    return(true);
                }
            }

            return(false);
        }
 public void ScheduleWork(MyEnvironmentSector sector, bool parallel)
 {
     if (parallel)
         m_sectorsToWorkParallel.Enqueue(sector);
     else
         m_sectorsToWorkSerial.Enqueue(sector);
 }
 public void SetSectorPinned(MyEnvironmentSector sector, bool pinned)
 {
     if (pinned != sector.IsPinned)
     {
         if (pinned)
         {
             sector.IsPinned = true;
             HeldSectors.Add(sector.SectorId, sector);
         }
         else
         {
             sector.IsPinned = false;
             HeldSectors.Remove(sector.SectorId);
         }
     }
 }
 internal bool CheckOnGraphicsClose(MyEnvironmentSector sector)
 {
     if (sector.HasPhysics == sector.IsPendingPhysicsToggle && !sector.IsPinned)
     {
         EnqueueClosing(sector);
         return true;
     }
     return false;
 }
 internal void EnqueueClosing(MyEnvironmentSector sector)
 {
     Debug.Assert(sector.LodLevel == -1 || sector.IsPendingLodSwitch);
     m_sectorsClosing.Add(sector);
 }
 public bool TryGetSector(long id, out MyEnvironmentSector environmentSector)
 {
     if (!PhysicsSectors.TryGetValue(id, out environmentSector))
         return HeldSectors.TryGetValue(id, out environmentSector);
     return false;
 }
        private static bool IsVoxelItem(MyEnvironmentSector sector, short definitionIndex)
        {
            var modules = sector.Owner.EnvironmentDefinition.Items[definitionIndex].Type.ProxyModules;

            if (modules == null)
                return false;

            for (int i = 0; i < modules.Length; ++i)
            {
                if (modules[i].Type.IsSubclassOf(typeof(MyVoxelMapEnvironmentProxy)) || modules[i].Type == typeof(MyVoxelMapEnvironmentProxy))
                    return true;
            }

            return false;
        }
Ejemplo n.º 21
0
 public void DetachEnvironment(MyEnvironmentSector myEnvironmentSector)
 {
     Close();
 }
        private void sector_OnMyLodCommit(MyEnvironmentSector sector, int lod)
        {
            Debug.Assert(sector == EnvironmentSector);
            Debug.Assert((m_closed == (lod == -1)) || m_dependencies.Count > 0, "Lod set does not match expected lod.");

            if (lod == LodSet)
            {
                m_stateCommited = true;

                if (m_dependencies.Count == 0)
                {
                    if (lod == -1 && m_closed)
                        CloseCommit(false);
                    else
                        NotifyDependants(false);
                }
            } // if dependants then we actually commited a different lod, in that case we just ignore this
        }
Ejemplo n.º 23
0
        public void OnWorldPosChanged(ref MatrixD newTransform)
        {

            MatrixD worldPos = newTransform;
            m_caster.OnWorldPositionChanged(ref worldPos);

            var entitiesInRange = this.m_caster.EntitiesInRange;
            float closestDistance = float.MaxValue;
            MyEntity closestEntity = null;
            int itemId = 0;

            if (!m_isPointOfRefSet)
                m_pointOfReference = worldPos.Translation;

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
               // int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    float distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_pointOfReference);

                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            closestEntity = entity.Entity;
                            itemId = entity.ItemId;
                            this.m_distanceToHitSq = distanceSq;
                            this.m_hitPosition = entity.DetectionPoint;

                            closestDistance = distanceSq;
                        }
                    }
                 //   ++i;
                }
            }

            this.m_hitCubeGrid = closestEntity as MyCubeGrid;
            this.m_hitBlock = null;
            this.m_hitDestroaybleObj = closestEntity as IMyDestroyableObject;
            this.m_hitFloatingObject = closestEntity as MyFloatingObject;
            this.m_hitCharacter = closestEntity as MyCharacter;
            this.m_hitEnvironmentSector = closestEntity as MyEnvironmentSector;
            this.m_environmentItem = itemId;

            if (m_hitCubeGrid != null)
            {
                var invWorld = m_hitCubeGrid.PositionComp.WorldMatrixNormalizedInv;
                var gridLocalPos = Vector3D.Transform(this.m_hitPosition, invWorld);
                Vector3I blockPos;
                m_hitCubeGrid.FixTargetCube(out blockPos, gridLocalPos / m_hitCubeGrid.GridSize);
                m_hitBlock = m_hitCubeGrid.GetCubeBlock(blockPos);

            }

            
        }
 internal void EnqueueClosing(MyEnvironmentSector sector)
 {
     Debug.Assert(sector.LodLevel == -1 || sector.IsPendingLodSwitch);
     m_sectorsClosing.Add(sector);
 }