-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Tilemaps #21756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Tilemaps #21756
Conversation
620817d to
f659c85
Compare
|
The generated |
b64736f to
e48a274
Compare
705b76e to
1790516
Compare
7ef1079 to
c8bb723
Compare
bevy_ecs_tilemap comes up in every conversation on the topic so some corrections: "simply porting it into bevy" was never an option. My original intention was to evolve the crate to fit upstream's needs but that was not a path upstream wanted to take. Previously raised issues like Transform propagation speed, etc were upstream performance issues and not issues in bevy_ecs_tilemap.
I still need to find time to do an actual review of the code here. |
I disagree that it's a superficial issue, I think it's a real usability issue especially when combined with the lack of autochunking. It turns every look up into a chunked map into the following:
and this is on top of whatever chunking solution the user is opting into or writing themselves. I think
Nested Queries look great, if this setup looks right, I'd definitely want to move the queries to nested queries. |
|
superficial here means it can be added by for example, writing a function, and isn't an architectural limitation. it does not mean that it isn't important. |
Objective
Non-Objectives
Existing Solutions
Currently Bevy has the TilemapChunkRender component to render single tilemap chunks, but no built in way to support auto chunking or actual tilemaps. Engines like Godot and Unity have native full tilemap support with no preset bounds and automatic chunking, this seems like a good feature for Bevy.
bevy_ecs_tilemap exists and supports entities as tiles as well as many tile shapes, it's also very popular. However, I don't think simply porting it into current bevy is the right approach for three reasons:
Solution
Tilemap and TileStorage
Tilemaps are a component that go on a top level entity and map chunk coordinates to chunk entities as well as the chunk size and tile size.
Chunks contain
TileStorage<T>components that store typed tile data as a vec, as well as aTileStoragescomponent that stores untyped information for adding and removing tiles to aTileStorage<T>(This is necessary for automatically removing all tile info for a given tile when it's removed from the map).If a user wants to spawn a tile entity, they simply need to spawn an entity with
(InMap(tilemap_entity_here), TileCoord::new(x, y). A component hook will then handle the following:TileCoord, if the chunk doesn't exist, spawn it.TileStorage<EntityTile>, if it doesn't exist, insert it into the chunk.TileStorage<EntityTile>by calculating the index fromTileCoord.If a user wants to query a tile entity, they can use
TilemapEntityQuery<D, F>:Testing
TODO
Showcase
examples/2d/tilemap.rstilemap.mp4
Uses non-entity tiles to spawn tiles on click.
examples/2d/tilemap_entites.rstilemap_entities.mp4
Spawns entity tiles randomly, rotating the tilemap to show transforms working.
examples/games/breakout.rsbreakout.mp4
Used tilemaps to add bomb tiles that take out surrounding tiles.
TODO
TODO