Conversation
0bb5ad2 to
0cbf1b2
Compare
0cbf1b2 to
7272759
Compare
[Editor] - We were iterating over the same 9 maps (3x3 grid) 6 separate times for different layers/attributes. This fix consolidates the whole thing into a single pass. - Add DrawAllMapAttributes() to consolidate 3 attribute draw calls - Cached property lookups in DrawGridOverlay, DrawTransparentBorders, and DrawMapBorders to avoid repeated access - Cache textures and property lookups in hot paths - Move DrawMapGrid lines outside nested loop, reduction in draw calls - Reduce DrawMapBorders from 8 to 4 calls, pre-calculates values - Optimized DrawTransparentBorders with texture caching and IsDisposed check - Add view culling to skip off-screen rendering - Removes unused imports and variables. Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com>
7272759 to
48a99eb
Compare
| MapInstance map = null; | ||
| try | ||
| { | ||
| map = MapInstance.Get(Globals.MapGrid.Grid[x, y].MapId); | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| Intersect.Core.ApplicationContext.Context.Value?.Logger.LogError( | ||
| exception, | ||
| $"{Globals.MapGrid.Grid.GetLength(0)}x{Globals.MapGrid.Grid.GetLength(1)} -- {x},{y}" | ||
| ); | ||
| } |
There was a problem hiding this comment.
Why get rid of exception handling
| // Draw vertical lines | ||
| for (var x = 0; x <= mapWidth; x++) | ||
| { | ||
| DrawTexture(sWhiteTex, new RectangleF(0, 0, 1, 1), new RectangleF(leftPos + x * tileWidth, topPos, 1, totalHeight), null); |
There was a problem hiding this comment.
The original code also sucked, but this should be made to be 1 parameter per line for DrawTexture and the second nested RectangleF (the first RectangleF(0, 0, 1, 1) can be on a line by itself because it's so simple).
| Options.Instance.Map.MapWidth * Options.Instance.Map.TileWidth, 1 | ||
| ), null | ||
| ); | ||
| DrawTexture(sWhiteTex, new RectangleF(0, 0, 1, 1), new RectangleF(leftPos, topPos + y * tileHeight, totalWidth, 1), null); |
There was a problem hiding this comment.
The original code also sucked, but this should be made to be 1 parameter per line for DrawTexture and the second nested RectangleF (the first RectangleF(0, 0, 1, 1) can be on a line by itself because it's so simple).
| { | ||
| var transTex = GameContentManager.GetTexture(GameContentManager.TextureType.Misc, "transtile.png"); | ||
| if (transTex == null) | ||
| if (_transparentGridTexture == null || _transparentGridTexture.IsDisposed) |
There was a problem hiding this comment.
_transparentGridTexture?.IsDisposed != false?
| Options.Instance.Map.TileHeight | ||
| ), System.Drawing.Color.White, null | ||
| ); | ||
| DrawTexture(_transparentGridTexture, texRect, new RectangleF(xoffset + x * tileWidth, yoffset + y * tileHeight, tileWidth, tileHeight), System.Drawing.Color.White, null); |
| grid.ContentRect.Y + y * grid.TileHeight, grid.TileWidth, grid.TileHeight | ||
| ), System.Drawing.Color.FromArgb(45, 45, 48), sMapGridChain | ||
| ); | ||
| DrawTexture(whiteTex, new RectangleF(0, 0, 1, 1), destRect, emptySlotColor, sMapGridChain); |
There was a problem hiding this comment.
One parameter per line for DrawTexture (not RF)
| ), System.Drawing.Color.Gray, sMapGridChain | ||
| ); | ||
| } | ||
| DrawTexture(tile.Tex, new RectangleF(0, 0, tile.Tex.Width, tile.Tex.Height), destRect, Color.White, sMapGridChain); |
There was a problem hiding this comment.
One parameter per line for DrawTexture (not RF)
| for (var x = 0; x <= grid.GridWidth + 2; x++) | ||
| { | ||
| float lineX = grid.ContentRect.X + x * grid.TileWidth; | ||
| DrawTexture(whiteTex, srcRect, new RectangleF(lineX, grid.ContentRect.Y, 1, (grid.GridHeight + 2) * grid.TileHeight), gridLineColor, sMapGridChain); |
| for (var y = 0; y <= grid.GridHeight + 2; y++) | ||
| { | ||
| float lineY = grid.ContentRect.Y + y * grid.TileHeight; | ||
| DrawTexture(whiteTex, srcRect, new RectangleF(grid.ContentRect.X, lineY, (grid.GridWidth + 2) * grid.TileWidth, 1), gridLineColor, sMapGridChain); |
| new RectangleF(0, CurrentView.Y + Options.Instance.Map.TileHeight * Options.Instance.Map.MapHeight - 1, CurrentView.Width, 3), | ||
| System.Drawing.Color.DimGray | ||
| ); | ||
|
|
[Editor]
Before:
2026-01-31.21-04-47.mp4
After:
2026-02-07.20-51-48.1.mp4