Index: binary-improvements2/MapRendering/src/MapRenderer.cs
===================================================================
--- binary-improvements2/MapRendering/MapRendering/MapRendering.cs	(revision 383)
+++ binary-improvements2/MapRendering/src/MapRenderer.cs	(revision 391)
@@ -11,11 +11,11 @@
 using Object = UnityEngine.Object;
 
-namespace AllocsFixes.MapRendering {
-	public class MapRendering {
-		private static MapRendering instance;
+namespace MapRendering {
+	public class MapRenderer {
+		private static MapRenderer instance;
 
 		private static readonly object lockObject = new object ();
 		public static bool renderingEnabled = true;
-		private readonly MapTileCache cache = new MapTileCache (Constants.MAP_BLOCK_SIZE);
+		private readonly MapTileCache cache = new MapTileCache (Constants.MapBlockSize);
 		private readonly Dictionary<Vector2i, Color32[]> dirtyChunks = new Dictionary<Vector2i, Color32[]> ();
 		private readonly MicroStopwatch msw = new MicroStopwatch ();
@@ -26,6 +26,6 @@
 		private bool shutdown;
 
-		private MapRendering () {
-			Constants.MAP_DIRECTORY = GameIO.GetSaveGameDir () + "/map";
+		private MapRenderer () {
+			Constants.MapDirectory = GameIO.GetSaveGameDir () + "/map";
 
 			lock (lockObject) {
@@ -35,8 +35,8 @@
 			}
 
-			cache.SetZoomCount (Constants.ZOOMLEVELS);
-
-			zoomLevelBuffers = new MapRenderBlockBuffer[Constants.ZOOMLEVELS];
-			for (int i = 0; i < Constants.ZOOMLEVELS; i++) {
+			cache.SetZoomCount (Constants.Zoomlevels);
+
+			zoomLevelBuffers = new MapRenderBlockBuffer[Constants.Zoomlevels];
+			for (int i = 0; i < Constants.Zoomlevels; i++) {
 				zoomLevelBuffers [i] = new MapRenderBlockBuffer (i, cache);
 			}
@@ -45,13 +45,5 @@
 		}
 
-		public static MapRendering Instance {
-			get {
-				if (instance == null) {
-					instance = new MapRendering ();
-				}
-
-				return instance;
-			}
-		}
+		public static MapRenderer Instance => instance ??= new MapRenderer ();
 
 		public static MapTileCache GetTileCache () {
@@ -77,24 +69,28 @@
 				ThreadPool.UnsafeQueueUserWorkItem (_o => {
 					try {
-						if (!Instance.renderingFullMap) {
-							lock (lockObject) {
-								Chunk c = (Chunk) _o;
-								Vector3i cPos = c.GetWorldPos ();
-								Vector2i cPos2 = new Vector2i (cPos.x / Constants.MAP_CHUNK_SIZE,
-									cPos.z / Constants.MAP_CHUNK_SIZE);
-
-								ushort[] mapColors = c.GetMapColors ();
-								if (mapColors != null) {
-									Color32[] realColors =
-										new Color32[Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE];
-									for (int i_colors = 0; i_colors < mapColors.Length; i_colors++) {
-										realColors [i_colors] = shortColorToColor32 (mapColors [i_colors]);
-									}
-
-									Instance.dirtyChunks [cPos2] = realColors;
-
-									//Log.Out ("Add Dirty: " + cPos2);
-								}
+						if (Instance.renderingFullMap) {
+							return;
+						}
+
+						lock (lockObject) {
+							Chunk c = (Chunk) _o;
+							Vector3i cPos = c.GetWorldPos ();
+							Vector2i cPos2 = new Vector2i (cPos.x / Constants.MapChunkSize,
+								cPos.z / Constants.MapChunkSize);
+
+							ushort[] mapColors = c.GetMapColors ();
+							if (mapColors == null) {
+								return;
 							}
+
+							Color32[] realColors =
+								new Color32[Constants.MapChunkSize * Constants.MapChunkSize];
+							for (int iColors = 0; iColors < mapColors.Length; iColors++) {
+								realColors [iColors] = shortColorToColor32 (mapColors [iColors]);
+							}
+
+							Instance.dirtyChunks [cPos2] = realColors;
+
+							//Log.Out ("Add Dirty: " + cPos2);
 						}
 					} catch (Exception e) {
@@ -112,25 +108,18 @@
 			Texture2D fullMapTexture = null;
 
-			Vector2i minChunk, maxChunk;
-			Vector2i minPos, maxPos;
-			int widthChunks, heightChunks, widthPix, heightPix;
-			getWorldExtent (rfm, out minChunk, out maxChunk, out minPos, out maxPos, out widthChunks, out heightChunks,
-				out widthPix, out heightPix);
-
-			Log.Out (string.Format (
-				"RenderMap: min: {0}, max: {1}, minPos: {2}, maxPos: {3}, w/h: {4}/{5}, wP/hP: {6}/{7}",
-				minChunk.ToString (), maxChunk.ToString (),
-				minPos.ToString (), maxPos.ToString (),
-				widthChunks, heightChunks,
-				widthPix, heightPix)
+			getWorldExtent (rfm, out Vector2i minChunk, out Vector2i maxChunk, out Vector2i minPos, out Vector2i maxPos, out int widthChunks, out int heightChunks,
+				out int widthPix, out int heightPix);
+
+			Log.Out (
+				$"RenderMap: min: {minChunk.ToString ()}, max: {maxChunk.ToString ()}, minPos: {minPos.ToString ()}, maxPos: {maxPos.ToString ()}, w/h: {widthChunks}/{heightChunks}, wP/hP: {widthPix}/{heightPix}"
 			);
 
 			lock (lockObject) {
-				for (int i = 0; i < Constants.ZOOMLEVELS; i++) {
+				for (int i = 0; i < Constants.Zoomlevels; i++) {
 					zoomLevelBuffers [i].ResetBlock ();
 				}
 
-				if (Directory.Exists (Constants.MAP_DIRECTORY)) {
-					Directory.Delete (Constants.MAP_DIRECTORY, true);
+				if (Directory.Exists (Constants.MapDirectory)) {
+					Directory.Delete (Constants.MapDirectory, true);
 				}
 
@@ -143,12 +132,12 @@
 				}
 
-				Vector2i curFullMapPos = default (Vector2i);
-				Vector2i curChunkPos = default (Vector2i);
-				for (curFullMapPos.x = 0; curFullMapPos.x < widthPix; curFullMapPos.x += Constants.MAP_CHUNK_SIZE) {
+				Vector2i curFullMapPos = default;
+				Vector2i curChunkPos = default;
+				for (curFullMapPos.x = 0; curFullMapPos.x < widthPix; curFullMapPos.x += Constants.MapChunkSize) {
 					for (curFullMapPos.y = 0;
 						curFullMapPos.y < heightPix;
-						curFullMapPos.y += Constants.MAP_CHUNK_SIZE) {
-						curChunkPos.x = curFullMapPos.x / Constants.MAP_CHUNK_SIZE + minChunk.x;
-						curChunkPos.y = curFullMapPos.y / Constants.MAP_CHUNK_SIZE + minChunk.y;
+						curFullMapPos.y += Constants.MapChunkSize) {
+						curChunkPos.x = curFullMapPos.x / Constants.MapChunkSize + minChunk.x;
+						curChunkPos.y = curFullMapPos.y / Constants.MapChunkSize + minChunk.y;
 
 						try {
@@ -159,7 +148,7 @@
 								if (mapColors != null) {
 									Color32[] realColors =
-										new Color32[Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE];
-									for (int i_colors = 0; i_colors < mapColors.Length; i_colors++) {
-										realColors [i_colors] = shortColorToColor32 (mapColors [i_colors]);
+										new Color32[Constants.MapChunkSize * Constants.MapChunkSize];
+									for (int iColors = 0; iColors < mapColors.Length; iColors++) {
+										realColors [iColors] = shortColorToColor32 (mapColors [iColors]);
 									}
 
@@ -167,5 +156,5 @@
 									if (fullMapTexture != null) {
 										fullMapTexture.SetPixels32 (curFullMapPos.x, curFullMapPos.y,
-											Constants.MAP_CHUNK_SIZE, Constants.MAP_CHUNK_SIZE, realColors);
+											Constants.MapChunkSize, Constants.MapChunkSize, realColors);
 									}
 								}
@@ -180,6 +169,5 @@
 					}
 
-					Log.Out (string.Format ("RenderMap: {0}/{1} ({2}%)", curFullMapPos.x, widthPix,
-						(int) ((float) curFullMapPos.x / widthPix * 100)));
+					Log.Out ($"RenderMap: {curFullMapPos.x}/{widthPix} ({(int)((float)curFullMapPos.x / widthPix * 100)}%)");
 				}
 			}
@@ -189,5 +177,5 @@
 			if (fullMapTexture != null) {
 				byte[] array = fullMapTexture.EncodeToPNG ();
-				File.WriteAllBytes (Constants.MAP_DIRECTORY + "/map.png", array);
+				File.WriteAllBytes (Constants.MapDirectory + "/map.png", array);
 				Object.Destroy (fullMapTexture);
 			}
@@ -200,5 +188,5 @@
 
 		private void SaveAllBlockMaps () {
-			for (int i = 0; i < Constants.ZOOMLEVELS; i++) {
+			for (int i = 0; i < Constants.Zoomlevels; i++) {
 				zoomLevelBuffers [i].SaveBlock ();
 			}
@@ -246,26 +234,27 @@
 			//Log.Out ("Start Dirty: " + chunkPos);
 
-			getBlockNumber (chunkPos, out Vector2i block, out _, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MAP_CHUNK_SIZE);
-
-			zoomLevelBuffers [Constants.ZOOMLEVELS - 1].LoadBlock (block);
+			getBlockNumber (chunkPos, out Vector2i block, out _, Constants.MAP_BLOCK_TO_CHUNK_DIV, Constants.MapChunkSize);
+
+			zoomLevelBuffers [Constants.Zoomlevels - 1].LoadBlock (block);
 			Profiler.EndSample ();
 
 			Profiler.BeginSample ("RenderDirtyChunks.Work");
 			// Write all chunks that are in the same image tile of the highest zoom level 
-			Vector2i v_block, v_blockOffset;
 			foreach (Vector2i v in chunksToRender) {
-				getBlockNumber (v, out v_block, out v_blockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV,
-					Constants.MAP_CHUNK_SIZE);
-				if (v_block.Equals (block)) {
-					//Log.Out ("Dirty: " + v + " render: true");
-					chunksRendered.Add (v);
-					if (dirtyChunks [v].Length != Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE) {
-						Log.Error (string.Format ("Rendering chunk has incorrect data size of {0} instead of {1}",
-							dirtyChunks [v].Length, Constants.MAP_CHUNK_SIZE * Constants.MAP_CHUNK_SIZE));
-					}
-
-					zoomLevelBuffers [Constants.ZOOMLEVELS - 1]
-						.SetPart (v_blockOffset, Constants.MAP_CHUNK_SIZE, dirtyChunks [v]);
-				}
+				getBlockNumber (v, out Vector2i vBlock, out Vector2i vBlockOffset, Constants.MAP_BLOCK_TO_CHUNK_DIV,
+					Constants.MapChunkSize);
+				if (!vBlock.Equals (block)) {
+					continue;
+				}
+
+				//Log.Out ("Dirty: " + v + " render: true");
+				chunksRendered.Add (v);
+				if (dirtyChunks [v].Length != Constants.MapChunkSize * Constants.MapChunkSize) {
+					Log.Error (
+						$"Rendering chunk has incorrect data size of {dirtyChunks [v].Length} instead of {Constants.MapChunkSize * Constants.MapChunkSize}");
+				}
+
+				zoomLevelBuffers [Constants.Zoomlevels - 1]
+					.SetPart (vBlockOffset, Constants.MapChunkSize, dirtyChunks [v]);
 			}
 			Profiler.EndSample ();
@@ -285,8 +274,7 @@
 		private void RenderZoomLevel (Vector2i _innerBlock) {
 			Profiler.BeginSample ("RenderZoomLevel");
-			int level = Constants.ZOOMLEVELS - 1;
+			int level = Constants.Zoomlevels - 1;
 			while (level > 0) {
-				Vector2i block, blockOffset;
-				getBlockNumber (_innerBlock, out block, out blockOffset, 2, Constants.MAP_BLOCK_SIZE / 2);
+				getBlockNumber (_innerBlock, out Vector2i block, out Vector2i blockOffset, 2, Constants.MapBlockSize / 2);
 
 				zoomLevelBuffers [level - 1].LoadBlock (block);
@@ -296,7 +284,7 @@
 				     zoomLevelBuffers [level].FormatSelf == TextureFormat.RGBA32) &&
 				    zoomLevelBuffers [level].FormatSelf == zoomLevelBuffers [level - 1].FormatSelf) {
-					zoomLevelBuffers [level - 1].SetPartNative (blockOffset, Constants.MAP_BLOCK_SIZE / 2, zoomLevelBuffers [level].GetHalfScaledNative ());
+					zoomLevelBuffers [level - 1].SetPartNative (blockOffset, Constants.MapBlockSize / 2, zoomLevelBuffers [level].GetHalfScaledNative ());
 				} else {
-					zoomLevelBuffers [level - 1].SetPart (blockOffset, Constants.MAP_BLOCK_SIZE / 2, zoomLevelBuffers [level].GetHalfScaled ());
+					zoomLevelBuffers [level - 1].SetPart (blockOffset, Constants.MapBlockSize / 2, zoomLevelBuffers [level].GetHalfScaled ());
 				}
 				Profiler.EndSample ();
@@ -310,6 +298,6 @@
 		private void getBlockNumber (Vector2i _innerPos, out Vector2i _block, out Vector2i _blockOffset, int _scaleFactor,
 			int _offsetSize) {
-			_block = default (Vector2i);
-			_blockOffset = default (Vector2i);
+			_block = default;
+			_blockOffset = default;
 			_block.x = (_innerPos.x + 16777216) / _scaleFactor - 16777216 / _scaleFactor;
 			_block.y = (_innerPos.y + 16777216) / _scaleFactor - 16777216 / _scaleFactor;
@@ -319,33 +307,32 @@
 
 		private void WriteMapInfo () {
-			JSONObject mapInfo = new JSONObject ();
-			mapInfo.Add ("blockSize", new JSONNumber (Constants.MAP_BLOCK_SIZE));
-			mapInfo.Add ("maxZoom", new JSONNumber (Constants.ZOOMLEVELS - 1));
-
-			Directory.CreateDirectory (Constants.MAP_DIRECTORY);
-			File.WriteAllText (Constants.MAP_DIRECTORY + "/mapinfo.json", mapInfo.ToString (), Encoding.UTF8);
+			JsonObject mapInfo = new JsonObject ();
+			mapInfo.Add ("blockSize", new JsonNumber (Constants.MapBlockSize));
+			mapInfo.Add ("maxZoom", new JsonNumber (Constants.Zoomlevels - 1));
+
+			Directory.CreateDirectory (Constants.MapDirectory);
+			File.WriteAllText (Constants.MapDirectory + "/mapinfo.json", mapInfo.ToString (), Encoding.UTF8);
 		}
 
 		private bool LoadMapInfo () {
-			if (!File.Exists (Constants.MAP_DIRECTORY + "/mapinfo.json")) {
+			if (!File.Exists (Constants.MapDirectory + "/mapinfo.json")) {
 				return false;
 			}
 
-			string json = File.ReadAllText (Constants.MAP_DIRECTORY + "/mapinfo.json", Encoding.UTF8);
+			string json = File.ReadAllText (Constants.MapDirectory + "/mapinfo.json", Encoding.UTF8);
 			try {
-				JSONNode node = Parser.Parse (json);
-				if (node is JSONObject) {
-					JSONObject jo = (JSONObject) node;
+				JsonNode node = Parser.Parse (json);
+				if (node is JsonObject jo) {
 					if (jo.ContainsKey ("blockSize")) {
-						Constants.MAP_BLOCK_SIZE = ((JSONNumber) jo ["blockSize"]).GetInt ();
+						Constants.MapBlockSize = ((JsonNumber) jo ["blockSize"]).GetInt ();
 					}
 
 					if (jo.ContainsKey ("maxZoom")) {
-						Constants.ZOOMLEVELS = ((JSONNumber) jo ["maxZoom"]).GetInt () + 1;
+						Constants.Zoomlevels = ((JsonNumber) jo ["maxZoom"]).GetInt () + 1;
 					}
 
 					return true;
 				}
-			} catch (MalformedJSONException e) {
+			} catch (MalformedJsonException e) {
 				Log.Out ("Exception in LoadMapInfo: " + e);
 			} catch (InvalidCastException e) {
@@ -360,8 +347,8 @@
 			out int _widthChunks, out int _heightChunks,
 			out int _widthPix, out int _heightPix) {
-			_minChunk = default (Vector2i);
-			_maxChunk = default (Vector2i);
-			_minPos = default (Vector2i);
-			_maxPos = default (Vector2i);
+			_minChunk = default;
+			_maxChunk = default;
+			_minPos = default;
+			_maxPos = default;
 
 			long[] keys = _rfm.GetAllChunkKeys ();
@@ -397,15 +384,15 @@
 			_maxChunk.y = maxY;
 
-			_minPos.x = minX * Constants.MAP_CHUNK_SIZE;
-			_minPos.y = minY * Constants.MAP_CHUNK_SIZE;
-
-			_maxPos.x = maxX * Constants.MAP_CHUNK_SIZE;
-			_maxPos.y = maxY * Constants.MAP_CHUNK_SIZE;
+			_minPos.x = minX * Constants.MapChunkSize;
+			_minPos.y = minY * Constants.MapChunkSize;
+
+			_maxPos.x = maxX * Constants.MapChunkSize;
+			_maxPos.y = maxY * Constants.MapChunkSize;
 
 			_widthChunks = maxX - minX + 1;
 			_heightChunks = maxY - minY + 1;
 
-			_widthPix = _widthChunks * Constants.MAP_CHUNK_SIZE;
-			_heightPix = _heightChunks * Constants.MAP_CHUNK_SIZE;
+			_widthPix = _widthChunks * Constants.MapChunkSize;
+			_heightPix = _heightChunks * Constants.MapChunkSize;
 		}
 
