Add MrGameEng.Tilemaps: code-built tile grids rendered through the batcher
CI / build-test (push) Failing after 1m4s

TileSet maps ids to texture regions with tints (0 = empty), TileGrid is a
bounds-checked dense ushort grid, and the Tilemap component places a grid
in the world per render layer. UseTilemaps() inserts TilemapRenderSystem
before the flush; it submits only the camera-visible cell range
(TilemapMath.VisibleCells), so frame cost scales with the screen, not the
grid. Demonstrated in the sample as a checkerboard floor; Tiled loading
stays on the roadmap on top of this API.
This commit is contained in:
Leonid Pershin
2026-06-11 10:24:47 +03:00
parent b318d1e795
commit b3415120c3
15 changed files with 548 additions and 6 deletions
@@ -12,6 +12,7 @@
<ProjectReference Include="..\..\src\MrGameEng.Audio\MrGameEng.Audio.csproj" />
<ProjectReference Include="..\..\src\MrGameEng.Assets\MrGameEng.Assets.csproj" />
<ProjectReference Include="..\..\src\MrGameEng.Atlases\MrGameEng.Atlases.csproj" />
<ProjectReference Include="..\..\src\MrGameEng.Tilemaps\MrGameEng.Tilemaps.csproj" />
<ProjectReference Include="..\..\src\MrGameEng.UI\MrGameEng.UI.csproj" />
<ProjectReference Include="..\..\src\MrGameEng.DevConsole\MrGameEng.DevConsole.csproj" />
<ProjectReference Include="..\..\src\MrGameEng.Assets.Generator\MrGameEng.Assets.Generator.csproj"
@@ -7,6 +7,7 @@ using MrGameEng.Core;
using MrGameEng.DevConsole;
using MrGameEng.Graphics;
using MrGameEng.Input;
using MrGameEng.Tilemaps;
using MrGameEng.UI;
using Myra.Graphics2D.UI;
@@ -32,6 +33,7 @@ public sealed class MainScene : Scene
var renderer = this.UseRenderer2D(new Renderer2DOptions { VirtualResolution = new Point(1280, 720) });
SampleLayers.EnsureRegistered(renderer);
this.UseTilemaps();
var playerTexture = assets.Load(GameAssets.Textures.Player);
var shapesTexture = assets.Load(GameAssets.Textures.Shapes);
@@ -50,6 +52,26 @@ public sealed class MainScene : Scene
new Texture2DRegion(shapesTexture, new Rectangle(32, 32, 32, 32)),
};
// Тайловая площадка под стартовой зоной: шахматный пол, строится кодом из TileSet/TileGrid.
// Видимые клетки сабмитятся каждый кадр; Depth -10 кладёт пол под декорации.
var floorTiles = new TileSet();
var floorA = floorTiles.Add(shapeRegions[0], new Color(70, 75, 95));
var floorB = floorTiles.Add(shapeRegions[2], new Color(55, 60, 78));
var floorGrid = new TileGrid(24, 14);
for (var y = 0; y < floorGrid.Height; y++)
{
for (var x = 0; x < floorGrid.Width; x++)
{
floorGrid[x, y] = (x + y) % 2 == 0 ? floorA : floorB;
}
}
Store.CreateEntity(new Tilemap(floorGrid, floorTiles, tileSize: 48f)
{
Origin = new Vector2(-24 * 24f, -14 * 24f),
Depth = -10f,
});
// Декорации по всему миру: уезжаешь камерой — попадают под culling (см. заголовок окна).
var random = new Random(42);
for (var i = 0; i < DecorCount; i++)