- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/MapRendering/MapRendering.cs
r346 r351 5 5 using System.Text; 6 6 using System.Threading; 7 using System.Timers;8 7 using AllocsFixes.FileCache; 9 8 using AllocsFixes.JSON; … … 66 65 } 67 66 68 public static void RenderSingleChunk (Chunk chunk) {67 public static void RenderSingleChunk (Chunk _chunk) { 69 68 if (renderingEnabled) { 70 69 // TODO: Replace with regular thread and a blocking queue / set 71 ThreadPool.UnsafeQueueUserWorkItem ( o => {70 ThreadPool.UnsafeQueueUserWorkItem (_o => { 72 71 try { 73 72 if (!Instance.renderingFullMap) { 74 73 lock (lockObject) { 75 Chunk c = (Chunk) o;74 Chunk c = (Chunk) _o; 76 75 Vector3i cPos = c.GetWorldPos (); 77 76 Vector2i cPos2 = new Vector2i (cPos.x / Constants.MAP_CHUNK_SIZE, … … 95 94 Log.Out ("Exception in MapRendering.RenderSingleChunk(): " + e); 96 95 } 97 }, chunk);96 }, _chunk); 98 97 } 99 98 } … … 279 278 } 280 279 281 private void RenderZoomLevel (Vector2i innerBlock) {280 private void RenderZoomLevel (Vector2i _innerBlock) { 282 281 Profiler.BeginSample ("RenderZoomLevel"); 283 282 int level = Constants.ZOOMLEVELS - 1; 284 283 while (level > 0) { 285 284 Vector2i block, blockOffset; 286 getBlockNumber ( innerBlock, out block, out blockOffset, 2, Constants.MAP_BLOCK_SIZE / 2);285 getBlockNumber (_innerBlock, out block, out blockOffset, 2, Constants.MAP_BLOCK_SIZE / 2); 287 286 288 287 zoomLevelBuffers [level - 1].LoadBlock (block); … … 299 298 300 299 level--; 301 innerBlock = block;300 _innerBlock = block; 302 301 } 303 302 Profiler.EndSample (); 304 303 } 305 304 306 private void getBlockNumber (Vector2i innerPos, out Vector2i block, out Vector2i blockOffset, intscaleFactor,307 int offsetSize) {308 block = default (Vector2i);309 blockOffset = default (Vector2i);310 block.x = (innerPos.x + 16777216) / scaleFactor - 16777216 /scaleFactor;311 block.y = (innerPos.y + 16777216) / scaleFactor - 16777216 /scaleFactor;312 blockOffset.x = (innerPos.x + 16777216) % scaleFactor *offsetSize;313 blockOffset.y = (innerPos.y + 16777216) % scaleFactor *offsetSize;305 private void getBlockNumber (Vector2i _innerPos, out Vector2i _block, out Vector2i _blockOffset, int _scaleFactor, 306 int _offsetSize) { 307 _block = default (Vector2i); 308 _blockOffset = default (Vector2i); 309 _block.x = (_innerPos.x + 16777216) / _scaleFactor - 16777216 / _scaleFactor; 310 _block.y = (_innerPos.y + 16777216) / _scaleFactor - 16777216 / _scaleFactor; 311 _blockOffset.x = (_innerPos.x + 16777216) % _scaleFactor * _offsetSize; 312 _blockOffset.y = (_innerPos.y + 16777216) % _scaleFactor * _offsetSize; 314 313 } 315 314 … … 352 351 } 353 352 354 private void getWorldExtent (RegionFileManager rfm, out Vector2i minChunk, out Vector2imaxChunk,355 out Vector2i minPos, out Vector2imaxPos,356 out int widthChunks, out intheightChunks,357 out int widthPix, out intheightPix) {358 minChunk = default (Vector2i);359 maxChunk = default (Vector2i);360 minPos = default (Vector2i);361 maxPos = default (Vector2i);362 363 long[] keys = rfm.GetAllChunkKeys ();353 private void getWorldExtent (RegionFileManager _rfm, out Vector2i _minChunk, out Vector2i _maxChunk, 354 out Vector2i _minPos, out Vector2i _maxPos, 355 out int _widthChunks, out int _heightChunks, 356 out int _widthPix, out int _heightPix) { 357 _minChunk = default (Vector2i); 358 _maxChunk = default (Vector2i); 359 _minPos = default (Vector2i); 360 _maxPos = default (Vector2i); 361 362 long[] keys = _rfm.GetAllChunkKeys (); 364 363 int minX = int.MaxValue; 365 364 int minY = int.MaxValue; … … 387 386 } 388 387 389 minChunk.x = minX;390 minChunk.y = minY;391 392 maxChunk.x = maxX;393 maxChunk.y = maxY;394 395 minPos.x = minX * Constants.MAP_CHUNK_SIZE;396 minPos.y = minY * Constants.MAP_CHUNK_SIZE;397 398 maxPos.x = maxX * Constants.MAP_CHUNK_SIZE;399 maxPos.y = maxY * Constants.MAP_CHUNK_SIZE;400 401 widthChunks = maxX - minX + 1;402 heightChunks = maxY - minY + 1;403 404 widthPix =widthChunks * Constants.MAP_CHUNK_SIZE;405 heightPix =heightChunks * Constants.MAP_CHUNK_SIZE;406 } 407 408 private static Color32 shortColorToColor32 (ushort col) {409 byte r = (byte) (256 * (( col >> 10) & 31) / 32);410 byte g = (byte) (256 * (( col >> 5) & 31) / 32);411 byte b = (byte) (256 * ( col & 31) / 32);412 byte a = 255;388 _minChunk.x = minX; 389 _minChunk.y = minY; 390 391 _maxChunk.x = maxX; 392 _maxChunk.y = maxY; 393 394 _minPos.x = minX * Constants.MAP_CHUNK_SIZE; 395 _minPos.y = minY * Constants.MAP_CHUNK_SIZE; 396 397 _maxPos.x = maxX * Constants.MAP_CHUNK_SIZE; 398 _maxPos.y = maxY * Constants.MAP_CHUNK_SIZE; 399 400 _widthChunks = maxX - minX + 1; 401 _heightChunks = maxY - minY + 1; 402 403 _widthPix = _widthChunks * Constants.MAP_CHUNK_SIZE; 404 _heightPix = _heightChunks * Constants.MAP_CHUNK_SIZE; 405 } 406 407 private static Color32 shortColorToColor32 (ushort _col) { 408 byte r = (byte) (256 * ((_col >> 10) & 31) / 32); 409 byte g = (byte) (256 * ((_col >> 5) & 31) / 32); 410 byte b = (byte) (256 * (_col & 31) / 32); 411 const byte a = 255; 413 412 return new Color32 (r, g, b, a); 414 413 }
Note:
See TracChangeset
for help on using the changeset viewer.