- Timestamp:
- Aug 7, 2022, 3:02:24 PM (2 years ago)
- Location:
- binary-improvements2/MapRendering/src
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/src/MapRenderBlockBuffer.cs
r390 r391 6 6 using UnityEngine.Profiling; 7 7 8 namespace AllocsFixes.MapRendering {8 namespace MapRendering { 9 9 public class MapRenderBlockBuffer { 10 private readonly Texture2D blockMap = new Texture2D (Constants.M AP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE, Constants.DEFAULT_TEX_FORMAT, false);10 private readonly Texture2D blockMap = new Texture2D (Constants.MapBlockSize, Constants.MapBlockSize, Constants.DefaultTextureFormat, false); 11 11 private readonly MapTileCache cache; 12 12 private readonly NativeArray<int> emptyImageData; 13 private readonly Texture2D zoomBuffer = new Texture2D (Constants.M AP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE / 2, Constants.DEFAULT_TEX_FORMAT, false);13 private readonly Texture2D zoomBuffer = new Texture2D (Constants.MapBlockSize / 2, Constants.MapBlockSize / 2, Constants.DefaultTextureFormat, false); 14 14 private readonly int zoomLevel; 15 15 private readonly string folderBase; 16 16 17 private Vector2i currentBlockMapPos = new Vector2i ( Int32.MinValue, Int32.MinValue);17 private Vector2i currentBlockMapPos = new Vector2i (int.MinValue, int.MinValue); 18 18 private string currentBlockMapFolder = string.Empty; 19 19 … … 21 21 zoomLevel = _level; 22 22 cache = _cache; 23 folderBase = Constants.M AP_DIRECTORY+ "/" + zoomLevel + "/";23 folderBase = Constants.MapDirectory + "/" + zoomLevel + "/"; 24 24 25 25 { 26 26 // Initialize empty tile data 27 27 Color nullColor = new Color (0, 0, 0, 0); 28 for (int x = 0; x < Constants.M AP_BLOCK_SIZE; x++) {29 for (int y = 0; y < Constants.M AP_BLOCK_SIZE; y++) {28 for (int x = 0; x < Constants.MapBlockSize; x++) { 29 for (int y = 0; y < Constants.MapBlockSize; y++) { 30 30 blockMap.SetPixel (x, y, nullColor); 31 31 } … … 39 39 } 40 40 41 public TextureFormat FormatSelf { 42 get { return blockMap.format; } 43 } 41 public TextureFormat FormatSelf => blockMap.format; 44 42 45 43 public void ResetBlock () { 46 44 currentBlockMapFolder = string.Empty; 47 currentBlockMapPos = new Vector2i ( Int32.MinValue, Int32.MinValue);45 currentBlockMapPos = new Vector2i (int.MinValue, int.MinValue); 48 46 cache.ResetTile (zoomLevel); 49 47 } … … 94 92 95 93 public void SetPart (Vector2i _offset, int _partSize, Color32[] _pixels) { 96 if (_offset.x + _partSize > Constants.M AP_BLOCK_SIZE || _offset.y + _partSize > Constants.MAP_BLOCK_SIZE) {97 Log.Error ( string.Format ("MapBlockBuffer[{0}].SetPart ({1}, {2}, {3}) has blockMap.size ({4}/{5})",98 zoomLevel, _offset, _partSize, _pixels.Length, Constants.MAP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE));94 if (_offset.x + _partSize > Constants.MapBlockSize || _offset.y + _partSize > Constants.MapBlockSize) { 95 Log.Error ( 96 $"MapBlockBuffer[{zoomLevel}].SetPart ({_offset}, {_partSize}, {_pixels.Length}) has blockMap.size ({Constants.MapBlockSize}/{Constants.MapBlockSize})"); 99 97 return; 100 98 } … … 107 105 public Color32[] GetHalfScaled () { 108 106 Profiler.BeginSample ("HalfScaled.ResizeBuffer"); 109 zoomBuffer.Resize (Constants.M AP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE);107 zoomBuffer.Resize (Constants.MapBlockSize, Constants.MapBlockSize); 110 108 Profiler.EndSample (); 111 109 … … 125 123 126 124 Profiler.BeginSample ("HalfScaled.Scale"); 127 TextureScale.Point (zoomBuffer, Constants.M AP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE/ 2);125 TextureScale.Point (zoomBuffer, Constants.MapBlockSize / 2, Constants.MapBlockSize / 2); 128 126 Profiler.EndSample (); 129 127 … … 136 134 137 135 public void SetPartNative (Vector2i _offset, int _partSize, NativeArray<int> _pixels) { 138 if (_offset.x + _partSize > Constants.M AP_BLOCK_SIZE || _offset.y + _partSize > Constants.MAP_BLOCK_SIZE) {139 Log.Error ( string.Format ("MapBlockBuffer[{0}].SetPart ({1}, {2}, {3}) has blockMap.size ({4}/{5})",140 zoomLevel, _offset, _partSize, _pixels.Length, Constants.MAP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE));136 if (_offset.x + _partSize > Constants.MapBlockSize || _offset.y + _partSize > Constants.MapBlockSize) { 137 Log.Error ( 138 $"MapBlockBuffer[{zoomLevel}].SetPart ({_offset}, {_partSize}, {_pixels.Length}) has blockMap.size ({Constants.MapBlockSize}/{Constants.MapBlockSize})"); 141 139 return; 142 140 } … … 157 155 public NativeArray<int> GetHalfScaledNative () { 158 156 Profiler.BeginSample ("HalfScaledNative.ResizeBuffer"); 159 if (zoomBuffer.format != blockMap.format || zoomBuffer.height != Constants.M AP_BLOCK_SIZE / 2 || zoomBuffer.width != Constants.MAP_BLOCK_SIZE/ 2) {160 zoomBuffer.Resize (Constants.M AP_BLOCK_SIZE / 2, Constants.MAP_BLOCK_SIZE/ 2, blockMap.format, false);157 if (zoomBuffer.format != blockMap.format || zoomBuffer.height != Constants.MapBlockSize / 2 || zoomBuffer.width != Constants.MapBlockSize / 2) { 158 zoomBuffer.Resize (Constants.MapBlockSize / 2, Constants.MapBlockSize / 2, blockMap.format, false); 161 159 } 162 160 Profiler.EndSample (); … … 178 176 int newHeight = _targetTex.height; 179 177 180 float ratioX = ( (float) oldWidth)/ newWidth;181 float ratioY = ( (float) oldHeight)/ newHeight;182 183 for ( vary = 0; y < newHeight; y++) {184 varoldLineStart = (int) (ratioY * y) * oldWidth;185 varnewLineStart = y * newWidth;186 for ( varx = 0; x < newWidth; x++) {178 float ratioX = (float) oldWidth / newWidth; 179 float ratioY = (float) oldHeight / newHeight; 180 181 for (int y = 0; y < newHeight; y++) { 182 int oldLineStart = (int) (ratioY * y) * oldWidth; 183 int newLineStart = y * newWidth; 184 for (int x = 0; x < newWidth; x++) { 187 185 targetData [newLineStart + x] = srcData [(int) (oldLineStart + ratioX * x)]; 188 186 } … … 198 196 199 197 Profiler.BeginSample ("LoadImage"); 200 if (array != null && blockMap.LoadImage (array) && blockMap.height == Constants.M AP_BLOCK_SIZE&&201 blockMap.width == Constants.M AP_BLOCK_SIZE) {198 if (array != null && blockMap.LoadImage (array) && blockMap.height == Constants.MapBlockSize && 199 blockMap.width == Constants.MapBlockSize) { 202 200 Profiler.EndSample (); 203 201 … … 211 209 } 212 210 213 if (blockMap.format != Constants.D EFAULT_TEX_FORMAT || blockMap.height != Constants.MAP_BLOCK_SIZE||214 blockMap.width != Constants.M AP_BLOCK_SIZE) {215 blockMap.Resize (Constants.M AP_BLOCK_SIZE, Constants.MAP_BLOCK_SIZE, Constants.DEFAULT_TEX_FORMAT,211 if (blockMap.format != Constants.DefaultTextureFormat || blockMap.height != Constants.MapBlockSize || 212 blockMap.width != Constants.MapBlockSize) { 213 blockMap.Resize (Constants.MapBlockSize, Constants.MapBlockSize, Constants.DefaultTextureFormat, 216 214 false); 217 215 }
Note:
See TracChangeset
for help on using the changeset viewer.