diff --git a/Assets/_Scenes/MainManu.unity b/Assets/_Scenes/MainManu.unity index b6eab13..599faa9 100644 Binary files a/Assets/_Scenes/MainManu.unity and b/Assets/_Scenes/MainManu.unity differ diff --git a/Assets/_Scripts/Core/TerrainManager.cs b/Assets/_Scripts/Core/TerrainManager.cs index fe9a3ee..d82ea9b 100644 --- a/Assets/_Scripts/Core/TerrainManager.cs +++ b/Assets/_Scripts/Core/TerrainManager.cs @@ -39,52 +39,57 @@ void Start() void StartChunkUpdateThread() { - thread = new Thread(new ThreadStart(delegate + thread = new Thread(new ThreadStart(ChunkUpdateWork)); + thread.Priority = System.Threading.ThreadPriority.Lowest; + thread.Start(); + } + + void ChunkUpdateWork() + { + while (threadRunning) { - while (threadRunning) + Stopwatch.Reset(); + Stopwatch.Start(); + if (chunkQueue.TerrainCount != 0) { - Stopwatch.Reset(); - Stopwatch.Start(); - if (chunkQueue.TerrainCount != 0) + int count = chunkQueue.TerrainCount; + for (int i = 0; i < count; i++) { - int count = chunkQueue.TerrainCount; - for (int i = 0; i < count; i++) + int index = chunkQueue.PopTerrain(); + BlockTerrain.Chunk chunk = Terrain.GetChunk(index); + if (chunk == null) + continue; + lock (chunk) { - int index = chunkQueue.PopTerrain(); - BlockTerrain.Chunk chunk = Terrain.GetChunk(index); - lock (chunk) + switch (Terrain.chunkStats.Get(index).state) { - switch (Terrain.chunkStats.Get(index).state) - { - case 3: - terrainGenerator.MeshFromChunk(chunk, out chunk.mesh[0]); - terrainGenerator.MeshFromTransparent(chunk, out chunk.mesh[2]); - break; - case 1: - terrainGenerator.MeshFromChunk(chunk, out chunk.mesh[0]); - break; - case 2: - terrainGenerator.MeshFromTransparent(chunk, out chunk.mesh[2]); - break; - } + case 3: + terrainGenerator.MeshFromChunk(chunk, out chunk.mesh[0]); + terrainGenerator.MeshFromTransparent(chunk, out chunk.mesh[2]); + break; + case 1: + terrainGenerator.MeshFromChunk(chunk, out chunk.mesh[0]); + break; + case 2: + terrainGenerator.MeshFromTransparent(chunk, out chunk.mesh[2]); + break; } - chunkQueue.AddMain(index); } + chunkQueue.AddMain(index); } - if (needTerrainUpdate) - { - UpdateTerrain(centerChunk.X, centerChunk.Y); + } + if (needTerrainUpdate) + { + UpdateTerrain(centerChunk.X, centerChunk.Y); - needTerrainUpdate = false; - } - if (Stopwatch.ElapsedMilliseconds < updateMili) - { - Thread.Sleep(updateMili - (int)Stopwatch.ElapsedMilliseconds); - } + needTerrainUpdate = false; } - Debug.Log("chunk loading thread closed"); - })); - thread.Start(); + if (Stopwatch.ElapsedMilliseconds < updateMili) + { + Thread.Sleep(updateMili - (int)Stopwatch.ElapsedMilliseconds); + } + } + Debug.Log("chunk loading thread closed"); } void OnDisable() diff --git a/Assets/_Scripts/FPSDisplay.cs b/Assets/_Scripts/FPSDisplay.cs index 911a9bd..4fc3edd 100644 --- a/Assets/_Scripts/FPSDisplay.cs +++ b/Assets/_Scripts/FPSDisplay.cs @@ -9,7 +9,6 @@ public class FPSDisplay : MonoBehaviour void Update() { deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f; - } void OnGUI() @@ -24,7 +23,7 @@ void OnGUI() style.normal.textColor = new Color (1.0f, 1.0f, 1.0f, 1.0f); float msec = deltaTime * 1000.0f; float fps = 1.0f / deltaTime; - string text = string.Format("{0:0.0} ms ({1:0.} fps)\ncurrent chunk: {2}\n按ESC键暂停", msec, fps, TerrainManager.CurrentChunk ()); + string text = string.Format("{0:0.0} ms ({1:0.} fps)\ncurrent chunk: {2}\n按ESC键暂停\n按P键截图", msec, fps, TerrainManager.CurrentChunk ()); TerrainRaycast.RaycastResult? r = GetComponent ().LookingAt; if (r.HasValue) { //text += string.Format ("\nlooking at {0}", BlocksData.GetBlock(BlockTerrain.GetContent(r.Value.BlockValue)).Name); @@ -32,4 +31,4 @@ void OnGUI() } GUI.Label (rect, text, style); } -} \ No newline at end of file +} diff --git a/README.md b/README.md index dd8cb55..84498d7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Fancy SurvivalCraft Editor, inspired by [SCFE-Unity](https://github.com/khohryak * ~English support~ * ~Multi-thread chunk loading~ * ~Load Project.xml~ -* Setting panel +* ~Setting panel~ * Create a selection of blocks * Fill a selection with certain block * Save and Load selections diff --git a/README.zh-cn.md b/README.zh-cn.md index 6df87a0..e3d1ceb 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -6,7 +6,7 @@ Fancy SurvivalCraft Editor,可以翻译成“很棒的生存战争存档编辑 * ~英文版~ * ~多线程区块加载~ * ~加载Project.xml~ -* 设置界面 +* ~设置界面~ * 创建选区 * 填充选区 * 保存,导入选区