bevy_tilemap icon indicating copy to clipboard operation
bevy_tilemap copied to clipboard

Quality of Life Improvements for Procedural Tilemap Generation

Open huhlig opened this issue 3 years ago • 0 comments

What problem does this solve or what need does it fill?

The following list of features is designed to address some Quality of Life challenges the current implementation has for dealing with procedurally generated tilemaps of potentially enormous size.

  1. TilemapChunkEvent Spawn & Despawn currently only include the point which triggered a spawn/despawn and not the extents of the chunk or wether or not the chunk was loaded back into the tilemap from cache.
  2. Tilemap should optionally call a populate method on a trait object or call a function pointer with a provided user data reference such that when a new chunk not in cache is needed, the method can be called such that the chunk can be populated.

Describe the solution would you like?

  1. Adding some metadata to the TilemapChunkEvent.
pub enum TilemapChunkEvent {
    Spawned {
        point: Point2,
        extents: (Point2, Point2),
        cached: bool,
    },
    Modified {
        point: Point2,
        extents: (Point2, Point2),
    },
    Despawned {
        point: Point2,
        extents: (Point2, Point2),
    },
    AddLayer {
        layer_kind: LayerKind,
        sprite_layer: usize,
    },
    RemoveLayer {
        sprite_layer: usize,
    },
}```

2. Add an Option<TilemapPopulator> parameter to TilemapBuilder::auto_spawn() 

```rust
pub trait TilemapPopulator {
    fn populate(tilemap: &mut Tilemap, extents: (Point2, Point2))
}

pub fn auto_spawn(self, width: u32, height: u32, populator: TilemapPopulator) -> Self {/* ... */}

Describe the alternative(s) you've considered?

Using the existing event system with a is_none check for a point in the spawned chunk.

huhlig avatar Aug 08 '21 05:08 huhlig