Changeset 423 for binary-improvements2/MapRendering
- Timestamp:
- Mar 28, 2023, 8:08:01 PM (20 months ago)
- Location:
- binary-improvements2/MapRendering
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/ModInfo.xml
r422 r423 5 5 <Description value="Render the game map to image map tiles as it is uncovered" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.0.2 46.0" />7 <Version value="21.0.250.0" /> 8 8 <Website value="" /> 9 9 </xml> -
binary-improvements2/MapRendering/src/Commands/RenderMap.cs
r405 r423 14 14 15 15 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 16 if (!MapRenderer.HasInstance) { 17 SdtdConsole.Instance.Output ("Renderer not enabled"); 18 return; 19 } 20 16 21 MapRenderer.Instance.RenderFullMap (); 17 22 -
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 -
binary-improvements2/MapRendering/src/ModApi.cs
r406 r423 7 7 public class ModApi : IModApi { 8 8 public void InitMod (Mod _modInstance) { 9 if (ConnectionManager.Instance.IsServer) { 10 ModEvents.GameShutdown.RegisterHandler (GameShutdown); 11 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone); 12 } 13 9 ModEvents.GameStartDone.RegisterHandler (GameStartDone); 10 14 11 Web.ServerInitialized += _web => { 12 if (!GamePrefs.GetBool (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.EnableMapRendering)))) { 13 return; 14 } 15 15 16 _web.RegisterPathHandler ("/map/", new StaticHandler ( 16 17 $"{GameIO.GetSaveGameDir ()}/map", … … 20 21 ); 21 22 }; 23 } 24 25 private void GameStartDone () { 26 if (!ConnectionManager.Instance.IsServer) { 27 return; 28 } 29 30 if (!GamePrefs.GetBool (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.EnableMapRendering)))) { 31 return; 32 } 33 34 ModEvents.GameShutdown.RegisterHandler (GameShutdown); 35 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone); 22 36 } 23 37
Note:
See TracChangeset
for help on using the changeset viewer.