bevy_entitiles 0.2.2

A tilemap library for bevy. With many algorithms built in.
# Bevy EntiTiles 🗺️


A tilemap library for bevy. With many algorithms built in.

This repo is under maintenance as long as this message exists. ( Hope this message can bring you peace of mind. Yeah, that's childish :p )

Notice that the following progress may **not up to date**. Check the `README.md` in `dev` brach to get the latest progress!

## Currently Working On


- Tilemap Serializing

## Future Goals


- Wave Function Collapse ( Optimization; Collapse map patterns )
- ~~Pathfinding~~
- Tilemap-Link
- Runtime Mesh & Texture Baking
- Tilemap Serializing
- Chunk Unloading
- Wang Tilling
- Tilemap Mask
- Frustum Culling ( Optimization )
- ~~Physics~~
- Tilemap Editor

## Delayed


- SSAO ( Personal capability )
- Volumetric Clouds / Fog ( Personal capability )
- Lighting ( Personal capability )
- Realtime Shadow ( Personal capability )

## Known Issues


- The success probability of the wfc algorithm significantly decreased after switching to `LookupHeap`. ( And that's why I didn't switch to `LookupHeap` )
- Program panics when load a tilemap twice.

## Features


| Flag             | Funtionality                                                                                                            |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `algorithm`      | Implementation of algorithms                                                                                            |
| `debug`          | Show some debug info including aabbs for chunks and tilemaps, path finding results etc.                                 |
| `debug-verbose`  | Show verbose process of functions. This feature is only useful when debug algorithms. But it's useless for most of you. |
| `physics_rapier` | Physics support for [`bevy_rapier`]https://github.com/dimforge/bevy_rapier                                            |
| `physics_xpbd`   | Physics support for [`bevy_xpbd`]https://github.com/Jondolf/bevy_xpbd, like setting colliders etc.                    |
| `serializing`    | Save and load the tilemap from files. Also contains tools for upgrading files.                                          |

## Performance


Platform: 10600KF

### Frustum Culling


<div>
	<img src="./docs/imgs/without_frustum_culling.png" width="300px"/>
	<img src="./docs/imgs/with_frustum_culling.png" width="300px"/>
</div>

> *Bevy 0.11.3, crate 0.1.1, 1000x1000 tiles*

### Pathfinding


The pathfinding algorithm is very fast.

Notice this tests are done with **synchronized pathfinding**. Which means whole algorithm will figure the path out in one frame. But since `0.2.1`, we support the asynchronized one. The algorithm can complete a part of the pathfinding and continue it in the next frame. This will make it even smoother.

<div>
	<img src="./docs/imgs/pathfinding.png" width="500px">
</div>

| Size      | Time(avg of 3 tests) ms |
| --------- | ----------------------- |
| 100x100   | 12.00                   |
| 500x500   | 295.67                  |
| 1000x1000 | 1384.33                 |

> *Bevy 0.12, crate 0.2.1, using `pathfinding` example*

### Wave Function Collapse


In the following case, each tile has at least one corresponding color gap with its neighboring tiles.

Video at `docs/vids/wfc.mp4`

<div>
	<img src="./docs/imgs/wfc.png" width="500px">
</div>

| Size    | Time(avg of 3 tests) ms | Time(avg of 3 tests) ms |
| ------- | ----------------------- | ----------------------- |
| 10x10   | 33.312                  | 16.264 (3)              |
| 20x20   | 490.950                 | 96.009 (3)              |
| 30x30   | 2,280.121               | 335.697 (6)             |
| 50x50   | 18,838.542              | 2,095.428 (8)           |
| 100x100 | (Not measurable)        | 32,309.045 (16)         |

> *Column 1: Bevy 0.11.3, crate 0.2.0, NoneWeighted; Column 2: Bevy 0.12, crate 0.2.1, NoneWeighted, `max_retrace_factor` = number in parentheses*

## Special Thanks


- SSAO & Volumetric Clouds / Fog inspired by [this video]https://www.bilibili.com/video/BV1KG411U7uk/.

- [`bevy_ecs_tilemap`]https://github.com/StarArawn/bevy_ecs_tilemap. I took this crate as the reference and learnt the basis of bevy rendering.

## Versions


| Bevy ver | EntiTiles ver |
| -------- | ------------- |
| 0.12.x   | 0.2.x         |
| 0.11.x   | 0.1.x         |