Exemple #1
0
 internal void UnmarkReplicable(MyProceduralLogicalSector sector)
 {
     Debug.Assert(sector.Replicable);
     m_sectorsForReplication.Remove(sector);
     QueueDestroyLogicalSector(sector);
     sector.Replicable = false;
 }
Exemple #2
0
 private void QueueRaiseLogicalSector(MyProceduralLogicalSector sector)
 {
     if (Sync.IsServer && Sync.MultiplayerActive)
     {
         Debug.Assert(MyMultiplayer.Static != null);
         m_sectorsToRaise.Enqueue(sector);
     }
 }
Exemple #3
0
        internal void MarkReplicable(MyProceduralLogicalSector sector)
        {
            Debug.Assert(!sector.Replicable);

            m_sectorsForReplication.Add(sector);
            QueueRaiseLogicalSector(sector);
            sector.Replicable = true;
        }
Exemple #4
0
 private void QueueDestroyLogicalSector(MyProceduralLogicalSector sector)
 {
     if (Sync.IsServer && Sync.MultiplayerActive)
     {
         Debug.Assert(MyMultiplayer.Static != null);
         m_sectorsToDestroy.Enqueue(sector);
     }
     else
     {
         sector.Close();
     }
 }
Exemple #5
0
        private void SaveLogicalSector(MyProceduralLogicalSector sector)
        {
            var sectorOb = sector.GetObjectBuilder();

            if (sectorOb == null)
            {
                m_savedSectors.Remove(sector.Id);
            }
            else
            {
                m_savedSectors[sector.Id] = (MyObjectBuilder_ProceduralEnvironmentSector)sectorOb;
            }
        }
Exemple #6
0
        internal void CloseSector(MyProceduralLogicalSector sector)
        {
            SaveLogicalSector(sector);
            m_sectors.Remove(sector.Id);

            if (sector.Replicable)
            {
                UnmarkReplicable(sector);
            }
            else
            {
                QueueDestroyLogicalSector(sector);
            }
        }
Exemple #7
0
        private MyProceduralLogicalSector GetLogicalSector(int x, int y, int localLod)
        {
            var key = MyPlanetSectorId.MakeSectorId(x, y, ProviderId, localLod);
            MyProceduralLogicalSector sector;

            if (!m_sectors.TryGetValue(key, out sector))
            {
                MyObjectBuilder_ProceduralEnvironmentSector sectorBuilder;
                m_savedSectors.TryGetValue(key, out sectorBuilder);
                sector    = new MyProceduralLogicalSector(this, x, y, localLod, sectorBuilder);
                sector.Id = key;

                m_sectors[key] = sector;
            }
            return(sector);
        }
Exemple #8
0
        public unsafe MyEnvironmentDataView GetItemView(int lod, ref Vector2I start, ref Vector2I end, ref Vector3D localOrigin)
        {
            var localLod   = lod / LodFactor;
            var logicalLod = lod % LodFactor;

            start >>= (localLod * LodFactor);
            end   >>= (localLod * LodFactor);

            MyProceduralDataView view = new MyProceduralDataView(this, lod, ref start, ref end);

            var lcount = (end - start + 1).Size();

            view.SectorOffsets      = new List <int>(lcount);
            view.LogicalSectors     = new List <MyLogicalEnvironmentSectorBase>(lcount);
            view.IntraSectorOffsets = new List <int>(lcount);

            // First round, calculate offsets and find any missing sectors.
            int offset = 0;

            for (int y = start.Y; y <= end.Y; y++)
            {
                for (int x = start.X; x <= end.X; x++)
                {
                    var sector = GetLogicalSector(x, y, localLod);

                    if (sector.MinimumScannedLod != logicalLod)
                    {
                        sector.ScanItems(logicalLod);
                    }

                    sector.Viewers.Add(view);
                    sector.UpdateMinLod();

                    view.SectorOffsets.Add(offset);
                    view.LogicalSectors.Add(sector);
                    offset += sector.ItemCountForLod[logicalLod];
                    view.IntraSectorOffsets.Add(0);
                }
            }

            // Allocate item list.
            view.Items = new List <ItemInfo>(offset);

            int offsetIndex = 0;

            for (int y = start.Y; y <= end.Y; y++)
            {
                for (int x = start.X; x <= end.X; x++)
                {
                    MyProceduralLogicalSector sector = m_sectors[MyPlanetSectorId.MakeSectorId(x, y, ProviderId, localLod)];

                    int itemCnt = sector.ItemCountForLod[logicalLod];

                    offset = view.SectorOffsets[offsetIndex++];

                    Vector3 centerOffset = sector.WorldPos - localOrigin;

                    fixed(ItemInfo *viewItems = view.Items.GetInternalArray())
                    fixed(ItemInfo * sectorItems = sector.Items.GetInternalArray())
                    for (int i = 0; i < itemCnt; ++i)
                    {
                        int vi = i + offset;     // view index

                        viewItems[vi].Position = sectorItems[i].Position + centerOffset;

                        // TODO: Memcpy?
                        viewItems[vi].DefinitionIndex = sectorItems[i].DefinitionIndex;
                        viewItems[vi].ModelIndex      = sectorItems[i].ModelIndex;
                        viewItems[vi].Rotation        = sectorItems[i].Rotation;
                    }
                }
            }

            view.Items.SetSize(view.Items.Capacity);

            if ((m_sectorsToRaise.Count > 0 || m_sectorsToRaise.Count > 0) && !m_sectorsQueued)
            {
                m_sectorsQueued = true;

                Parallel.ScheduleForThread(m_raiseCallback, null, MySandboxGame.Static.UpdateThread);
            }
            return(view);
        }