コード例 #1
0
        private bool PrepareGenerate()
        {
            if (!m_completedStates.Check(ChunkState.LoadData))
            {
                return(true);
            }

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

            if (Features.UseSerialization)
            {
                var task = Globals.MemPools.SMThreadPI.Pop();
                m_poolState      = m_poolState.Set(ChunkPoolItemState.ThreadPI);
                m_threadPoolItem = task;
                task.Set(chunk.ThreadID, actionOnPrepareGenerate, this);

                m_taskRunning = true;
                IOPoolManager.Add(m_threadPoolItem);

                return(true);
            }

            OnPrepareGenerateDone(this, false);
            return(false);
        }
コード例 #2
0
        private bool SaveData()
        {
            // We need to wait until chunk is generated
            if (!m_completedStates.Check(ChunkState.PrepareSaveData))
            {
                return(true);
            }

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

            if (Features.UseSerialization)
            {
                var task = Globals.MemPools.SMTaskPI.Pop();
                m_poolState      = m_poolState.Set(ChunkPoolItemState.TaskPI);
                m_threadPoolItem = task;
                task.Set(actionOnSaveData, this);

                m_taskRunning = true;
                IOPoolManager.Add(task);

                return(true);
            }

            OnSaveDataDone(this, false);
            return(false);
        }
コード例 #3
0
ファイル: ChunkManager.cs プロジェクト: gitter-badger/Voxe
        private void ProcessUpdateRequests()
        {
            Blocks = 0;

            // Process removal requests
            for (int i = 0; i < m_updateRequests.Count;)
            {
                Chunk chunk = m_updateRequests[i];

                OnProcessChunk(chunk);

                // Process chunk events
                chunk.UpdateChunk();

                Blocks += chunk.NonEmptyBlocks;

                // Automatically collect chunks which are ready to be removed form the world
                if (chunk.IsFinished())
                {
                    // Remove the chunk from our provider and unregister it from chunk storage
                    ChunkProvider.ReleaseChunk(chunk);
                    m_chunks.Remove(chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z);

                    // Unregister from updates
                    m_updateRequests.RemoveAt(i);
                    continue;
                }

                ++i;
            }

            // Commit collected work items
            WorkPoolManager.Commit();
            IOPoolManager.Commit();
        }
コード例 #4
0
        private bool SaveData()
        {
            // We need to wait until chunk is generated and data finalized
            if (!m_completedStates.Check(ChunkState.Generate) || !m_completedStates.Check(ChunkState.LoadData))
            {
                return(true);
            }

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

            m_taskRunning = true;
            IOPoolManager.Add(
                new TaskPoolItem(
                    arg =>
            {
                ChunkStateManagerClient stateManager = (ChunkStateManagerClient)arg;
                OnSaveData(stateManager);
            },
                    this)
                );

            return(true);
        }
コード例 #5
0
        public void CollectInfo()
        {
            m_text.Length = 0;
            m_lines       = 13;

            m_text.ConcatFormat("Currently allocated: {0}\n", m_allocMem.GetKiloString());
            m_text.ConcatFormat("Peak allocated: {0}\n", m_peakAlloc.GetKiloString());
            m_text.ConcatFormat("Last collected: {0}\n", m_collectAlloc.GetKiloString());
            m_text.ConcatFormat("Allocation rate: {0}\n", m_allocRate.GetKiloString());

            m_text.ConcatFormat("Collection freq: {0:0.00}s\n", m_delta);
            m_text.ConcatFormat("Last collect delta: {0:0.000}s ({1:0.0} FPS)\n", m_lastDeltaTime, 1f / m_lastDeltaTime);

            if (World != null)
            {
                ++m_lines;
                m_text.ConcatFormat("Chunks: {0}\n", World.Count);
            }

            // Tasks
            m_text.Append("-------------------------------------------------------\n");
            m_text.ConcatFormat("TP tasks: {0}\n", WorkPoolManager.ToString());
            m_text.ConcatFormat("IO tasks: {0}\n", IOPoolManager.ToString());

            // Individual object pools
            m_text.Append("-------------------------------------------------------\n");
            m_text.ConcatFormat("{0}\n", GameObjectProvider.Instance.ToString());
            m_text.ConcatFormat("Main pools: {0}\n", Globals.MemPools.ToString());   // the main thread pool
            m_text.ConcatFormat("IO pools: {0}\n", Globals.IOPool.Pools.ToString()); // io pool
            for (int i = 0; i < Globals.WorkPool.Size; i++)
            {
                ++m_lines;
                m_text.ConcatFormat("TP #{0} pools: {1}\n", i + 1, Globals.WorkPool.GetPool(i).ToString()); // thread pool
            }
        }
コード例 #6
0
        private bool LoadData()
        {
            /*Assert.IsTrue(
             *  m_completedStates.Check(ChunkState.Generate),
             *  string.Format(
             *      "[{0},{1},{2}] - LoadData set sooner than Generate completed. Pending:{3}, Completed:{4}", pos.x,
             *      pos.y, pos.z, m_pendingStates, m_completedStates)
             *  );*/
            if (!m_completedStates.Check(ChunkState.Generate))
            {
                return(true);
            }

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

            m_taskRunning = true;
            IOPoolManager.Add(
                new TaskPoolItem(
                    arg =>
            {
                ChunkStateManagerServer stateManager = (ChunkStateManagerServer)arg;
                OnLoadData(stateManager);
            },
                    this)
                );

            return(true);
        }
コード例 #7
0
ファイル: Chunk.cs プロジェクト: gitter-badger/Voxe
        private bool SerializeChunk()
        {
            // This state should only be set it streaming is enabled
            Assert.IsTrue(EngineSettings.WorldConfig.Streaming);

            // If chunk was generated...
            if (m_completedTasks.Check(ChunkState.Generate))
            {
                // ...  we need to wait until blueprints are generated and chunk is finalized
                if (!m_completedTasks.Check(
#if ENABLE_BLUEPRINTS
                        ChunkState.GenerateBlueprints |
#endif
                        ChunkState.FinalizeData
                        ))
                {
                    return(true);
                }
            }

            m_pendingTasks = m_pendingTasks.Reset(CurrStateSerializeChunk);

            // Nothing here for us to do if the chunk was not changed since the last serialization
            if (m_completedTasks.Check(CurrStateSerializeChunk) && !m_refreshTasks.Check(CurrStateSerializeChunk))
            {
                OnSerialzeChunkDone(this);
                return(false);
            }

            m_refreshTasks   = m_refreshTasks.Reset(CurrStateSerializeChunk);
            m_completedTasks = m_completedTasks.Reset(CurrStateSerializeChunk);

            ChunkProvider      provider = (ChunkProvider)Map.ChunkProvider;
            SSerializeWorkItem workItem = new SSerializeWorkItem(
                this,
                provider.GetFilePathFromIndex(Pos.X, Pos.Y, Pos.Z)
                );

            m_taskRunning = true;
            IOPoolManager.Add(new ThreadItem(
                                  arg =>
            {
                SSerializeWorkItem item = (SSerializeWorkItem)arg;
                OnSerializeChunk(item.Chunk, item.FilePath);
            },
                                  workItem)
                              );

            return(true);
        }
コード例 #8
0
ファイル: ChunkProvider.cs プロジェクト: JackTheRipper42/Voxe
        private static void RequestChunkFromDisk(Chunk chunk, string filePath)
        {
            IOPoolManager.Add(new TaskPoolItem(
                                  arg =>
            {
                if (LoadChunkFromDisk(chunk, filePath))
                {
                    chunk.StateManager.MarkAsGenerated();
                    return;
                }

                // File could not be read for some reason, delete it
                File.Delete(filePath);

                // Request new data from the internet
                chunk.StateManager.RequestState(ChunkState.Generate);
            },
                                  chunk));
        }
コード例 #9
0
        private void UpdateCache()
        {
#if DEBUG
            // Make it possible to see results in real-time
            m_clipmap.Init(ForceLOD, LODCoef);
#endif

            // Register new chunks in chunk manager
            foreach (var chunkPos in m_chunksToLoadByPos)
            {
                int xx = ViewerChunkPos.X + chunkPos.X;
                int yy = ViewerChunkPos.Y + chunkPos.Y;
                int zz = ViewerChunkPos.Z + chunkPos.Z;

                RegisterChunk(xx, yy, zz);
            }

            // Commit collected work items
            WorkPoolManager.Commit();
            IOPoolManager.Commit();
        }
コード例 #10
0
        private bool SaveData()
        {
            // This state should only be set it streaming is enabled
            Assert.IsTrue(EngineSettings.WorldConfig.Streaming);

            // If chunk was generated...
            if (m_completedStates.Check(ChunkState.Generate))
            {
                // ...  we need to wait until blueprints are generated and chunk is finalized
                if (!m_completedStates.Check(
                        ChunkState.FinalizeData
                        ))
                {
                    return(true);
                }
            }

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

            ChunkProvider      provider = (ChunkProvider)chunk.Map.ChunkProvider;
            SSerializeWorkItem workItem = new SSerializeWorkItem(
                this,
                provider.GetFilePathFromIndex(chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z)
                );

            m_taskRunning = true;
            IOPoolManager.Add(
                new TaskPoolItem(
                    arg =>
            {
                SSerializeWorkItem item = (SSerializeWorkItem)arg;
                OnSaveData(item.StateManager, item.FilePath);
            },
                    workItem)
                );

            return(true);
        }
コード例 #11
0
        private bool LoadData()
        {
            m_pendingStates       = m_pendingStates.Reset(CurrStateLoadData);
            m_completedStates     = m_completedStates.Reset(CurrStateLoadData);
            m_completedStatesSafe = m_completedStates;

            if (Features.UseSerialization)
            {
                var task = Globals.MemPools.SMTaskPI.Pop();
                m_poolState      = m_poolState.Set(ChunkPoolItemState.TaskPI);
                m_threadPoolItem = task;
                task.Set(actionOnLoadData, this);

                m_taskRunning = true;
                IOPoolManager.Add(m_threadPoolItem);

                return(true);
            }

            OnLoadDataDone(this, false);
            return(false);
        }
コード例 #12
0
        private bool LoadData()
        {
            if (!m_completedStates.Check(ChunkState.Generate))
            {
                return(true);
            }

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

            m_taskRunning = true;
            IOPoolManager.Add(
                new TaskPoolItem(
                    arg =>
            {
                ChunkStateManagerClient stateManager = (ChunkStateManagerClient)arg;
                OnLoadData(stateManager);
            },
                    this)
                );

            return(true);
        }
コード例 #13
0
ファイル: GlobalObjects.cs プロジェクト: TrueLoop/Voxelmetric
 void Update()
 {
     IOPoolManager.Commit();
     WorkPoolManager.Commit();
 }