コード例 #1
0
        public MyProceduralLogicalSector TryGetLogicalSector(int lod, int logicalx, int logicaly)
        {
            MyProceduralLogicalSector sector;

            m_sectors.TryGetValue(MyPlanetSectorId.MakeSectorId(logicalx, logicaly, ProviderId, lod), out sector);

            return(sector);
        }
コード例 #2
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);
        }
コード例 #3
0
        public void CloseView(MyProceduralDataView view)
        {
            var lod = view.Lod / LodFactor;

            for (int y = view.Start.Y; y <= view.End.Y; y++)
            {
                for (int x = view.Start.X; x <= view.End.X; x++)
                {
                    var key = MyPlanetSectorId.MakeSectorId(x, y, ProviderId, lod);

                    var sector = m_sectors[key];
                    sector.Viewers.Remove(view);
                    sector.UpdateMinLod();

                    if (sector.Viewers.Count == 0 && !sector.ServerOwned)
                    {
                        CloseSector(sector);
                    }
                }
            }
        }
コード例 #4
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);
        }