Exemple #1
0
        public static ProvideTask FillChunk(Chunk chunk, int[] rawdata, Block[, ,] blocks, ChunkInfo info, Action onSkip, Action onGeneration)
        {
            ProvideTask rt = new ProvideTask()
            {
                Chunk                = chunk,
                Blocks               = blocks,
                RawData              = rawdata,
                Info                 = info,
                OnSkipCallback       = onSkip,
                OnGenerationCallback = onGeneration
            };

            m_Tasks.Add(rt);
            return(rt);
        }
Exemple #2
0
        private static void ProvideBlocksToChunk(ProvideTask task)
        {
            if (m_ResultLayer == null)
            {
                throw new InvalidOperationException("No 3D store result layer was found in the world configuration.");
            }
            if (task == null)
            {
                return;
            }
            DateTime start = DateTime.Now;

            FilteredConsole.WriteLine(FilterCategory.OptimizationTiming, "Started with 0ms.");

            if (m_CurrentProvideState == null)
            {
                ProvideState ps = new ProvideState();
                ps.Blocks  = task.Blocks;
                ps.RawData = task.RawData;
                ps.Info    = task.Info;
                //ps.Z = task.Chunk.GlobalZ;
                ps.ProvideTask          = task;
                ps.OnSkipCallback       = task.OnSkipCallback;
                ps.OnGenerationCallback = task.OnGenerationCallback;
                m_CurrentProvideState   = ps;
            }

            // Generate or load data.
            int[] data = null;
            int   computations;

            if (m_CurrentProvideState.ProvideTask.Info.LevelDisk == null || !m_CurrentProvideState.ProvideTask.Info.LevelDisk.HasRegion(
                    m_CurrentProvideState.Info.Bounds.X,
                    m_CurrentProvideState.Info.Bounds.Y,
                    m_CurrentProvideState.Info.Bounds.Z,
                    m_CurrentProvideState.Info.Bounds.Width,
                    m_CurrentProvideState.Info.Bounds.Height,
                    m_CurrentProvideState.Info.Bounds.Depth))
            {
                data = m_ResultLayer.GenerateData(
                    m_CurrentProvideState.Info.Bounds.X,
                    m_CurrentProvideState.Info.Bounds.Y,
                    m_CurrentProvideState.Info.Bounds.Z,
                    (int)m_CurrentProvideState.Info.Bounds.Width,
                    (int)m_CurrentProvideState.Info.Bounds.Height,
                    (int)m_CurrentProvideState.Info.Bounds.Depth,
                    out computations);
            }
            else
            {
                data = m_CurrentProvideState.ProvideTask.Info.LevelDisk.ProvideRegion(
                    m_CurrentProvideState.Info.Bounds.X,
                    m_CurrentProvideState.Info.Bounds.Y,
                    m_CurrentProvideState.Info.Bounds.Z,
                    m_CurrentProvideState.Info.Bounds.Width,
                    m_CurrentProvideState.Info.Bounds.Height,
                    m_CurrentProvideState.Info.Bounds.Depth);
            }

            // Set up block mappings.
            for (int i = 0; i < m_CurrentProvideState.Info.Bounds.Width; i++)
            {
                for (int j = 0; j < m_CurrentProvideState.Info.Bounds.Height; j++)
                {
                    for (int k = 0; k < m_CurrentProvideState.Info.Bounds.Depth; k++)
                    {
                        int id = data[i + j * m_CurrentProvideState.Info.Bounds.Width + k * m_CurrentProvideState.Info.Bounds.Width * m_CurrentProvideState.Info.Bounds.Height];
                        m_CurrentProvideState.RawData[i + j * m_CurrentProvideState.Info.Bounds.Width + k * m_CurrentProvideState.Info.Bounds.Width * m_CurrentProvideState.Info.Bounds.Height] = id;
                        if (id == -1)
                        {
                            m_CurrentProvideState.Blocks[i, j, k] = null;
                        }
                        else
                        {
                            try
                            {
                                m_CurrentProvideState.Blocks[i, j, k] = Block.BlockIDMapping[data[i + j * m_CurrentProvideState.Info.Bounds.Width + k * m_CurrentProvideState.Info.Bounds.Width * m_CurrentProvideState.Info.Bounds.Height]];
                            }
                            catch (KeyNotFoundException)
                            {
                                m_CurrentProvideState.Blocks[i, j, k] = null;
                            }
                        }
                    }
                }
            }

            FilteredConsole.WriteLine(FilterCategory.OptimizationTiming, "Provided " + /*zcount +*/ " levels to chunk in " + (DateTime.Now - start).TotalMilliseconds + "ms.");

            // Signal finish.
            m_CurrentProvideState.OnGenerationCallback();
            m_CurrentProvideState = null;
        }