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); }
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); }
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(); }
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); }
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 } }
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); }
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); }
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)); }
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(); }
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); }
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); }
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); }
void Update() { IOPoolManager.Commit(); WorkPoolManager.Commit(); }