Changeset 329 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 5, 2018, 11:16:04 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r326 r329 2 2 using System.IO; 3 3 using UnityEngine; 4 using UnityEngine.Profiling; 4 5 using Object = UnityEngine.Object; 5 6 … … 26 27 public void SetZoomCount (int count) { 27 28 cache = new CurrentZoomFile[count]; 29 for (int i = 0; i < cache.Length; i++) { 30 cache [i] = new CurrentZoomFile (); 31 } 28 32 } 29 33 … … 31 35 try { 32 36 lock (cache) { 33 if (cache [zoomlevel].filename == null || !cache [zoomlevel].filename.Equals (filename)) { 34 cache [zoomlevel].filename = filename; 37 CurrentZoomFile cacheEntry = cache [zoomlevel]; 38 39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals (filename)) { 40 cacheEntry.filename = filename; 35 41 36 42 if (!File.Exists (filename)) { 37 cache [zoomlevel].data = null;43 cacheEntry.pngData = null; 38 44 return null; 39 45 } 40 46 41 cache [zoomlevel].data = File.ReadAllBytes (filename); 47 Profiler.BeginSample ("ReadPng"); 48 cacheEntry.pngData = File.ReadAllBytes (filename); 49 Profiler.EndSample (); 42 50 } 43 51 44 return cache [zoomlevel].data;52 return cacheEntry.pngData; 45 53 } 46 54 } catch (Exception e) { 47 Log. Out("Error in MapTileCache.LoadTile: " + e);55 Log.Warning ("Error in MapTileCache.LoadTile: " + e); 48 56 } 49 57 … … 51 59 } 52 60 53 public void SaveTile (int zoomlevel, byte[] content ) {61 public void SaveTile (int zoomlevel, byte[] contentPng) { 54 62 try { 55 63 lock (cache) { 56 if (cache [zoomlevel].filename == null) { 64 CurrentZoomFile cacheEntry = cache [zoomlevel]; 65 66 if (string.IsNullOrEmpty (cacheEntry.filename)) { 57 67 return; 58 68 } 69 70 cacheEntry.pngData = contentPng; 59 71 60 cache [zoomlevel].data = content; 61 File.WriteAllBytes (cache [zoomlevel].filename, content); 72 Profiler.BeginSample ("WritePng"); 73 File.WriteAllBytes (cacheEntry.filename, contentPng); 74 Profiler.EndSample (); 62 75 } 63 76 } catch (Exception e) { 64 Log. Out("Error in MapTileCache.SaveTile: " + e);77 Log.Warning ("Error in MapTileCache.SaveTile: " + e); 65 78 } 66 79 } … … 71 84 foreach (CurrentZoomFile czf in cache) { 72 85 if (czf.filename != null && czf.filename.Equals (filename)) { 73 return czf. data;86 return czf.pngData; 74 87 } 75 88 } … … 82 95 } 83 96 } catch (Exception e) { 84 Log. Out("Error in MapTileCache.GetFileContent: " + e);97 Log.Warning ("Error in MapTileCache.GetFileContent: " + e); 85 98 } 86 99 … … 88 101 } 89 102 90 private structCurrentZoomFile {103 private class CurrentZoomFile { 91 104 public string filename; 92 public byte[] data;105 public byte[] pngData; 93 106 } 94 107 }
Note:
See TracChangeset
for help on using the changeset viewer.