- Timestamp:
- Sep 10, 2014, 8:09:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs
r168 r187 1 using AllocsFixes.JSON; 1 2 using System; 2 3 using System.Collections.Generic; 3 4 using System.IO; 5 using System.Text; 4 6 using System.Threading; 5 7 using UnityEngine; … … 20 22 } 21 23 22 private MapRenderBlockBuffer[] zoomLevelBuffers = new MapRenderBlockBuffer[Constants.ZOOMLEVELS];24 private MapRenderBlockBuffer[] zoomLevelBuffers; 23 25 private Dictionary<Vector2i, Color[]> dirtyChunks = new Dictionary<Vector2i, Color[]> (); 24 26 private System.Timers.Timer chunkSaveTimer = new System.Timers.Timer (500); … … 31 33 Constants.MAP_DIRECTORY = StaticDirectories.GetSaveGameDir () + "/map"; 32 34 35 if (File.Exists (Constants.MAP_DIRECTORY + "/mapinfo.json")) { 36 LoadMapInfo (); 37 } else { 38 WriteMapInfo (); 39 } 40 41 zoomLevelBuffers = new MapRenderBlockBuffer[Constants.ZOOMLEVELS]; 33 42 for (int i = 0; i < Constants.ZOOMLEVELS; i++) { 34 43 zoomLevelBuffers [i] = new MapRenderBlockBuffer (i); … … 100 109 } 101 110 102 if (Directory.Exists (Constants.MAP_DIRECTORY)) 111 if (Directory.Exists (Constants.MAP_DIRECTORY)) { 103 112 Directory.Delete (Constants.MAP_DIRECTORY, true); 113 } 114 WriteMapInfo (); 104 115 105 116 renderingFullMap = true; … … 239 250 } 240 251 252 private void WriteMapInfo () 253 { 254 JSONObject mapInfo = new JSONObject (); 255 mapInfo.Add ("blockSize", new JSONNumber (Constants.MAP_BLOCK_SIZE)); 256 mapInfo.Add ("maxZoom", new JSONNumber (Constants.ZOOMLEVELS - 1)); 257 258 Directory.CreateDirectory (Constants.MAP_DIRECTORY); 259 File.WriteAllText (Constants.MAP_DIRECTORY + "/mapinfo.json", mapInfo.ToString (), Encoding.UTF8); 260 } 261 262 private void LoadMapInfo () 263 { 264 if (File.Exists (Constants.MAP_DIRECTORY + "/mapinfo.json")) { 265 string json = File.ReadAllText (Constants.MAP_DIRECTORY + "/mapinfo.json", Encoding.UTF8); 266 JSONNode node = Parser.Parse (json); 267 if (node is JSONObject) { 268 JSONObject jo = (JSONObject)node; 269 if (jo.ContainsKey ("blockSize")) 270 Constants.MAP_BLOCK_SIZE = ((JSONNumber)jo ["blockSize"]).GetInt (); 271 if (jo.ContainsKey ("maxZoom")) 272 Constants.ZOOMLEVELS = ((JSONNumber)jo ["maxZoom"]).GetInt () + 1; 273 } 274 } 275 } 276 241 277 private void getWorldExtent (RegionFileManager rfm, out Vector2i minChunk, out Vector2i maxChunk, 242 278 out Vector2i minPos, out Vector2i maxPos,
Note:
See TracChangeset
for help on using the changeset viewer.