コード例 #1
0
        private static void OnGenerateData(ChunkStateManagerClient stateManager)
        {
            Chunk chunk = stateManager.chunk;

            chunk.Map.ChunkGenerator.Generate(chunk);

            OnGenerateDataDone(stateManager);
        }
コード例 #2
0
        private static void OnSaveData(ChunkStateManagerClient stateManager, string filePath)
        {
            Chunk chunk = stateManager.chunk;

            // !TODO: Handle failure
            ChunkProvider.StoreChunkToDisk(chunk, filePath);

            OnSaveDataDone(stateManager);
        }
コード例 #3
0
 public SGenerateVerticesWorkItem(ChunkStateManagerClient stateManager, int minX, int maxX, int minY, int maxY, int minZ, int maxZ, int lod)
 {
     StateManager = stateManager;
     MinX         = minX;
     MaxX         = maxX;
     MinY         = minY;
     MaxY         = maxY;
     MinZ         = minZ;
     MaxZ         = maxZ;
     LOD          = lod;
 }
コード例 #4
0
        private void SubscribeTwoNeighbors(int cx, int cy, int cz, bool subscribe)
        {
            Chunk neighbor = chunk.Map.GetChunk(cx, cy, cz);

            if (neighbor != null)
            {
                ChunkStateManagerClient stateManager = neighbor.StateManager;
                // Subscribe with each other. Passing Idle as event - it is ignored in this case anyway
                stateManager.Subscribe(this, ChunkState.Idle, subscribe);
                Subscribe(stateManager, ChunkState.Idle, subscribe);
            }
        }
コード例 #5
0
        private static void OnGenerateVerices(ChunkStateManagerClient stateManager, int minX, int maxX, int minY, int maxY, int minZ, int maxZ, int lod)
        {
            Chunk chunk = stateManager.chunk;
            Map   map   = chunk.Map;

            int offsetX = (chunk.Pos.X << EngineSettings.ChunkConfig.LogSize) << map.VoxelLogScaleX;
            int offsetY = (chunk.Pos.Y << EngineSettings.ChunkConfig.LogSize) << map.VoxelLogScaleY;
            int offsetZ = (chunk.Pos.Z << EngineSettings.ChunkConfig.LogSize) << map.VoxelLogScaleZ;

            map.MeshBuilder.BuildMesh(map, chunk.RenderGeometryBatcher, offsetX, offsetY, offsetZ, minX, maxX, minY, maxY, minZ, maxZ, lod, chunk.Pools);

            OnGenerateVerticesDone(stateManager);
        }
コード例 #6
0
        private static void OnGenericWork(ref SGenericWorkItem item)
        {
            ChunkStateManagerClient chunk = item.Chunk;

            // Perform the action
            item.Action();

            int cnt = Interlocked.Decrement(ref chunk.m_genericWorkItemsLeftToProcess);

            if (cnt <= 0)
            {
                // Something is very wrong if we go below zero
                Assert.IsTrue(cnt == 0);

                // All generic work is done
                OnGenericWorkDone(chunk);
            }
        }
コード例 #7
0
        private static void OnFinalizeData(ChunkStateManagerClient stateManager)
        {
            Chunk chunk = stateManager.chunk;

            // Generate height limits
            chunk.CalculateProperties();
            // Compress chunk data
            //chunk.Blocks.IsCompressed = true;
            // Compress chunk data
            // Only do this when streaming is enabled for now
            if (EngineSettings.WorldConfig.Streaming)
            {
                chunk.Blocks.RLE.Reset();
                BlockData[] compressedData = chunk.Blocks.ToArray();
                chunk.Blocks.RLE.Compress(ref compressedData);
            }

            OnFinalizeDataDone(stateManager);
        }
コード例 #8
0
        private bool GenerateData()
        {
            m_pendingStates       = m_pendingStates.Reset(CurrStateGenerateData);
            m_completedStates     = m_completedStates.Reset(CurrStateGenerateData | CurrStateFinalizeData);
            m_completedStatesSafe = m_completedStates;

            m_taskRunning = true;

            // Let server generate chunk data
            WorkPoolManager.Add(
                new ThreadPoolItem(
                    chunk.ThreadID,
                    arg =>
            {
                ChunkStateManagerClient stateManager = (ChunkStateManagerClient)arg;
                OnGenerateData(stateManager);
            },
                    this)
                );

            return(true);
        }
コード例 #9
0
        private bool FinalizeData()
        {
            if (!m_completedStates.Check(ChunkState.Generate))
            {
                return(true);
            }

            m_pendingStates       = m_pendingStates.Reset(CurrStateFinalizeData);
            m_completedStatesSafe = m_completedStates = m_completedStates.Reset(CurrStateFinalizeData);

            m_taskRunning = true;
            WorkPoolManager.Add(new ThreadPoolItem(
                                    chunk.ThreadID,
                                    arg =>
            {
                ChunkStateManagerClient stateManager = (ChunkStateManagerClient)arg;
                OnFinalizeData(stateManager);
            },
                                    this)
                                );

            return(true);
        }
コード例 #10
0
 private static void OnGenerateVerticesDone(ChunkStateManagerClient stateManager)
 {
     stateManager.m_completedStates = stateManager.m_completedStates.Set(CurrStateGenerateVertices);
     stateManager.m_taskRunning     = false;
 }
コード例 #11
0
 private static void OnSaveDataDone(ChunkStateManagerClient stateManager)
 {
     stateManager.m_stateExternal   = ChunkStateExternal.Saved;
     stateManager.m_completedStates = stateManager.m_completedStates.Set(CurrStateSaveData);
     stateManager.m_taskRunning     = false;
 }
コード例 #12
0
 public SSerializeWorkItem(ChunkStateManagerClient stateManager, string filePath)
 {
     StateManager = stateManager;
     FilePath     = filePath;
 }
コード例 #13
0
 private static void OnFinalizeDataDone(ChunkStateManagerClient stateManager)
 {
     stateManager.m_completedStates = stateManager.m_completedStates.Set(CurrStateFinalizeData);
     stateManager.m_nextState       = NextStateFinalizeData;
     stateManager.m_taskRunning     = false;
 }
コード例 #14
0
 private static void OnGenericWorkDone(ChunkStateManagerClient chunk)
 {
     chunk.m_completedStates = chunk.m_completedStates.Set(CurrStateGenericWork);
     chunk.m_nextState       = NextStateGenericWork;
     chunk.m_taskRunning     = false;
 }
コード例 #15
0
 public SGenericWorkItem(ChunkStateManagerClient chunk, Action action)
 {
     Chunk  = chunk;
     Action = action;
 }