- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r324 r325 2 2 using System.IO; 3 3 using UnityEngine; 4 using Object = UnityEngine.Object; 4 5 5 namespace AllocsFixes.FileCache 6 { 6 namespace AllocsFixes.FileCache { 7 7 // Special "cache" for map tile folder as both map rendering and webserver access files in there. 8 8 // Only map rendering tiles are cached. Writing is done by WriteThrough. 9 public class MapTileCache : AbstractCache 10 { 11 private struct CurrentZoomFile 12 { 13 public string filename; 14 public byte[] data; 15 } 16 9 public class MapTileCache : AbstractCache { 10 private readonly byte[] transparentTile; 17 11 private CurrentZoomFile[] cache; 18 12 19 private byte[] transparentTile; 20 21 public MapTileCache (int _tileSize) 22 { 13 public MapTileCache (int _tileSize) { 23 14 Texture2D tex = new Texture2D (_tileSize, _tileSize); 24 15 Color nullColor = new Color (0, 0, 0, 0); … … 28 19 } 29 20 } 21 30 22 transparentTile = tex.EncodeToPNG (); 31 UnityEngine.Object.Destroy (tex);23 Object.Destroy (tex); 32 24 } 33 25 34 public void SetZoomCount (int count) 35 { 26 public void SetZoomCount (int count) { 36 27 cache = new CurrentZoomFile[count]; 37 28 } 38 29 39 public byte[] LoadTile (int zoomlevel, string filename) 40 { 30 public byte[] LoadTile (int zoomlevel, string filename) { 41 31 try { 42 32 lock (cache) { … … 51 41 cache [zoomlevel].data = File.ReadAllBytes (filename); 52 42 } 43 53 44 return cache [zoomlevel].data; 54 45 } … … 56 47 Log.Out ("Error in MapTileCache.LoadTile: " + e); 57 48 } 49 58 50 return null; 59 51 } 60 52 61 public void SaveTile (int zoomlevel, byte[] content) 62 { 53 public void SaveTile (int zoomlevel, byte[] content) { 63 54 try { 64 55 lock (cache) { … … 73 64 } 74 65 75 public override byte[] GetFileContent (string filename) 76 { 66 public override byte[] GetFileContent (string filename) { 77 67 try { 78 68 lock (cache) { 79 69 foreach (CurrentZoomFile czf in cache) { 80 if (czf.filename != null && czf.filename.Equals (filename)) 70 if (czf.filename != null && czf.filename.Equals (filename)) { 81 71 return czf.data; 72 } 82 73 } 83 74 … … 85 76 return transparentTile; 86 77 } 78 87 79 return File.ReadAllBytes (filename); 88 80 } … … 90 82 Log.Out ("Error in MapTileCache.GetFileContent: " + e); 91 83 } 84 92 85 return null; 93 86 } 94 87 88 private struct CurrentZoomFile { 89 public string filename; 90 public byte[] data; 91 } 95 92 } 96 93 } 97
Note:
See TracChangeset
for help on using the changeset viewer.