Changeset 423 for binary-improvements2/MapRendering/src/MapRenderer.cs
- Timestamp:
- Mar 28, 2023, 8:08:01 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/src/MapRenderer.cs
r402 r423 43 43 } 44 44 45 public static bool HasInstance => instance != null; 46 45 47 public static MapRenderer Instance => instance ??= new MapRenderer (); 46 48 … … 50 52 51 53 public static void Shutdown () { 52 if ( Instance == null) {54 if (instance == null) { 53 55 return; 54 56 } 55 57 56 Instance.shutdown = true;58 instance.shutdown = true; 57 59 58 if (Instance.renderCoroutineRef != null) { 59 ThreadManager.StopCoroutine (Instance.renderCoroutineRef); 60 Instance.renderCoroutineRef = null; 61 } 60 if (instance.renderCoroutineRef != null) { 61 ThreadManager.StopCoroutine (instance.renderCoroutineRef); 62 instance.renderCoroutineRef = null; 63 } 64 65 instance = null; 62 66 } 63 67 64 68 public static void RenderSingleChunk (Chunk _chunk) { 65 if (renderingEnabled && Instance != null) { 66 // TODO: Replace with regular thread and a blocking queue / set 67 ThreadPool.UnsafeQueueUserWorkItem (_o => { 68 try { 69 if (Instance.renderingFullMap) { 69 if (!renderingEnabled || instance == null) { 70 return; 71 } 72 73 // TODO: Replace with regular thread and a blocking queue / set 74 ThreadPool.UnsafeQueueUserWorkItem (_o => { 75 try { 76 if (instance.renderingFullMap) { 77 return; 78 } 79 80 lock (lockObject) { 81 Chunk c = (Chunk) _o; 82 Vector3i cPos = c.GetWorldPos (); 83 Vector2i cPos2 = new Vector2i (cPos.x / Constants.MapChunkSize, 84 cPos.z / Constants.MapChunkSize); 85 86 ushort[] mapColors = c.GetMapColors (); 87 if (mapColors == null) { 70 88 return; 71 89 } 72 90 73 lock (lockObject) { 74 Chunk c = (Chunk) _o; 75 Vector3i cPos = c.GetWorldPos (); 76 Vector2i cPos2 = new Vector2i (cPos.x / Constants.MapChunkSize, 77 cPos.z / Constants.MapChunkSize); 78 79 ushort[] mapColors = c.GetMapColors (); 80 if (mapColors == null) { 81 return; 82 } 83 84 Color32[] realColors = 85 new Color32[Constants.MapChunkSize * Constants.MapChunkSize]; 86 for (int iColors = 0; iColors < mapColors.Length; iColors++) { 87 realColors [iColors] = shortColorToColor32 (mapColors [iColors]); 88 } 89 90 Instance.dirtyChunks [cPos2] = realColors; 91 92 //Log.Out ("Add Dirty: " + cPos2); 91 Color32[] realColors = 92 new Color32[Constants.MapChunkSize * Constants.MapChunkSize]; 93 for (int iColors = 0; iColors < mapColors.Length; iColors++) { 94 realColors [iColors] = shortColorToColor32 (mapColors [iColors]); 93 95 } 94 } catch (Exception e) { 95 Log.Out ($"Exception in MapRendering.RenderSingleChunk(): {e}"); 96 } 97 }, _chunk); 98 } 96 97 instance.dirtyChunks [cPos2] = realColors; 98 99 //Log.Out ("Add Dirty: " + cPos2); 100 } 101 } catch (Exception e) { 102 Log.Out ($"Exception in MapRendering.RenderSingleChunk(): {e}"); 103 } 104 }, _chunk); 99 105 } 100 106
Note:
See TracChangeset
for help on using the changeset viewer.