Пример #1
0
        private static readonly int PLANET_SECTOR_IDLE_WORK_CYCLE = 50; // maximum number of cancelled sector requests to process


        /**
         * Find or create sector for scanning
         */
        private static bool GetOrCreateSector(MyPlanet me, ref MyPlanetSectorId id, ref Vector3D position, double minDistance, out Vector3D pos, out double distance, out MyPlanetEnvironmentSector sector)
        {
            if (!me.m_planetEnvironmentSectors.TryGetValue(id, out sector))
            {
                BoundingBoxD box;
                me.SectorIdToBoundingBox(ref id, out box);
                pos = box.Center;
                var posf = (Vector3)pos;

                pos = me.GetClosestSurfacePointLocal(ref posf);
                Vector3D.DistanceSquared(ref position, ref pos, out distance);

                if (distance > minDistance)
                {
                    return(false);
                }

                // Build allocator if necessary
                if (me.m_planetSectorsPool == null)
                {
                    me.m_planetSectorsPool = new MyDynamicObjectPool <MyPlanetEnvironmentSector>(SECTOR_POOL_SIZE);
                }

                // Try to get from cache if possible
                sector = me.m_planetSectorsPool.Allocate();
                sector.Init(ref id, me);

                me.m_planetEnvironmentSectors.Add(id, sector);
                me.SectorsCreated.Hit();
            }
            else
            {
                if (sector.IsClosed)
                {
                    sector.Init(ref id, me);
                }

                pos = sector.LocalSurfaceCenter;
                Vector3D.DistanceSquared(ref position, ref pos, out distance);
            }
            return(true);
        }
Пример #2
0
        public void SpawnFlora(Vector3D pos)
        {
            if (m_planetEnvironmentSectors == null)
            {
                m_planetEnvironmentSectors = new Dictionary <Vector3I, MyPlanetEnvironmentSector>(500);
            }

            Vector3D gravity       = GetWorldGravityNormalized(ref pos);
            Vector3D perpedincular = MyUtils.GetRandomPerpendicularVector(ref gravity);
            Vector3D third         = Vector3D.Cross(gravity, perpedincular);

            perpedincular += third;

            Vector3I min = new Vector3I(-ENVIROMENT_EXTEND);
            Vector3I max = new Vector3I(ENVIROMENT_EXTEND);

            Vector3 offset = new Vector3(-MyPlanetEnvironmentSector.SECTOR_SIZE_METERS);

            for (var it = new Vector3I.RangeIterator(ref min, ref max); it.IsValid(); it.MoveNext())
            {
                Vector3D currentPos = pos + it.Current * offset * perpedincular;
                currentPos = PlaceToOrbit(currentPos, ref gravity);

                if (false == ChekPosition(currentPos))
                {
                    Vector3I newSector = Vector3I.Floor(currentPos / MyPlanetEnvironmentSector.SECTOR_SIZE_METERS);
                    if (m_planetSectorsPool == null)
                    {
                        m_planetSectorsPool = new MyDynamicObjectPool <MyPlanetEnvironmentSector>(400);
                    }


                    MyPlanetEnvironmentSector sector = m_planetSectorsPool.Allocate();

                    sector.Init(ref newSector, this);
                    m_planetEnvironmentSectors[newSector] = sector;
                    sector.PlaceItems();
                }
            }

            Vector3I sectorCoords = Vector3I.Floor(PlaceToOrbit(pos, ref gravity) / MyPlanetEnvironmentSector.SECTOR_SIZE_METERS);

            Vector3I keepMin = sectorCoords + new Vector3I(-ENVIROMENT_EXTEND_KEEP);
            Vector3I keepMax = sectorCoords + new Vector3I(ENVIROMENT_EXTEND_KEEP);

            foreach (var enviromentSector in m_planetEnvironmentSectors)
            {
                if (enviromentSector.Key.IsInsideInclusive(keepMin, keepMax))
                {
                    m_sectorsToKeep.Add(enviromentSector.Key);
                }
            }
        }
Пример #3
0
        private static readonly int PLANET_SECTOR_IDLE_WORK_CYCLE = 50; // maximum number of cancelled sector requests to process


        /**
         * Find or create sector for scanning
         */
        private static bool GetOrCreateSector(MyPlanet me, ref MyPlanetSectorId id, ref Vector3D position, double minDistance, out Vector3D pos, out double distance, out MyPlanetEnvironmentSector sector)
        {
            if (!me.m_planetEnvironmentSectors.TryGetValue(id, out sector))
            {
                BoundingBoxD box;
                me.SectorIdToBoundingBox(ref id, out box);
                pos = box.Center;
                var posf = (Vector3)pos;

                pos = me.GetClosestSurfacePointLocal(ref posf);
                Vector3D.DistanceSquared(ref position, ref pos, out distance);

                if (distance > minDistance) return false;

                // Build allocator if necessary
                if (me.m_planetSectorsPool == null)
                    me.m_planetSectorsPool = new MyDynamicObjectPool<MyPlanetEnvironmentSector>(SECTOR_POOL_SIZE);

                // Try to get from cache if possible
                sector = me.m_planetSectorsPool.Allocate();
                sector.Init(ref id, me);

                me.m_planetEnvironmentSectors.Add(id, sector);
                me.SectorsCreated.Hit();
            }
            else
            {
                if (sector.IsClosed)
                    sector.Init(ref id, me);

                pos = sector.LocalSurfaceCenter;
                Vector3D.DistanceSquared(ref position, ref pos, out distance);
            }
            return true;
        }