#Update system_set stage thing to 0.10

79 messages Β· Page 1 of 1 (latest)

ruby depot
#
use bevy::prelude::*;
use bevy_ecs_tilemap::TilemapStage;

#[derive(Debug, Clone, PartialEq, Eq, Hash, StageLabel)]
pub struct TilesetMapStage;

#[derive(SystemLabel, Clone, Debug, Hash, Eq, PartialEq)]
pub enum TilesetMapLabel {
    /// Labels the system that handles auto tile updates
    UpdateAutoTiles,
    /// Labels the system that handles auto tile removals
    RemoveAutoTiles,
}

/// Plugin for setting up tilesets
#[derive(Default)]
pub struct TilesetMapPlugin;

impl Plugin for TilesetMapPlugin {
    fn build(&self, app: &mut App) {
        app.add_stage_before(TilemapStage, TilesetMapStage, SystemStage::parallel());

        #[cfg(feature = "auto-tile")]
        app.add_event::<crate::auto::RemoveAutoTileEvent>()
            .add_system_set_to_stage(
                TilesetMapStage,
                SystemSet::new().with_system(
                    crate::auto::on_remove_auto_tile.label(TilesetMapLabel::RemoveAutoTiles),
                ),
            )
            .add_system_to_stage(
                TilemapStage,
                crate::auto::on_change_auto_tile
                    .label(TilesetMapLabel::UpdateAutoTiles)
                    .before(bevy_ecs_tilemap::TilemapLabel::UpdateChunkVisibility),
            );
    }
}``` I don't know how to update this, I've tried reading migration/updating it, brain hurty
molten sonnet
#

Why is it currently in its own stage?

ruby depot
#

I wish I could tell you

#

for bevy 0.10

molten sonnet
#

Ping @maiden ginkgo then :p

maiden ginkgo
#

Hm, I believe I added the stage so that changes to the tilemap would be applied before the tilemap stage runs. But it's been a while πŸ˜…

#

Also ping @barren aspen who was also working on updating this crate

barren aspen
#

I’ve since stopped working on it at least for now. I hop projects so much and lifes been hectic lmao

maiden ginkgo
#

Haha no worries, just thought I'd get your insight if you had any

#

I think the main thing would be to ensure we apply_system_buffers before the tilemap stuff runs so we avoid visual flicker

barren aspen
maiden ginkgo
#

Yeah

#

Then again bevy_ecs_tilemap has changed so much I'm not sure how much still applies

molten sonnet
#

Right, so just stick it in the same set as the tile set plugin, see if anything breaks, and then add an apply_system_buffers in between them if needed

barren aspen
#

Was it due to autotiling?

#

Like so you don’t see the tiles before they update to the proper auto tiled ones

#

But yeah just try it in the same set as Alice said

maiden ginkgo
#

Oh right! It's due to auto-tiling

#

Since basically we need to:

  1. Get the placed tile
  2. Calculate if neighbors need to be updated
  3. Update the map
#

And we want that all to happen before the next render

#

Otherwise, you render the placed tile, one frame of delay, and then the updated neighbors

barren aspen
#

Yeah that makes sense

ruby depot
#

I have like only like 5 errors now

ruby depot
#

at least what I've encountered

#

most errors right now are talking about how it can't find Tile but I hope that's easy to fix

ruby depot
maiden ginkgo
#

Nice! Thanks for doing this. Both you and Vixeliz are real life savers!

#

I was dreading updating, especially this crate due to the bevy_ecs_tilemap changes

ruby depot
#

they also removed a trait alias but I just added that back in for ease of use

#

so, so far it's been pretty easy

#

I just don't know how the new bevy system stages work to convert them

ruby depot
#

very easy

maiden ginkgo
ruby depot
#

did something happen in 0.7 that just caused a wipeout of all of bevy_ecs_tilemap stuff

#

because a lot of things are just gone and I would have to rewrite the code to fix

molten sonnet
#

Prompted by changes to Bevy's rendering + accumulated tech debt

vapid crane
#

Rewrite addressed a lot of things to make the API more ergonomic. πŸ™‚ Feel free to ping me if you have any questions.

ruby depot
#

Is there a replacement for MapTileError? I am just using bevy's asset Error rn which works (so far)

#

or maybe that's the intended solution

#

also MapQuery is gone is there a similar replacement for it?

#

I don't wish to rewrite all of the code if there is

#

same with LayerBuilder

ruby depot
vapid crane
#

MapQuery doesn't exist

#

It is somewhat replaced by TileStorage

#

I might add in a tilemap layer struct in the future but it's pretty basic just:

const GROUND_LAYER: u32 = 0;
const TREE_LAYER: u32 = 1;

pub struct TilemapLayers {
  layers: HashMap<u32, Entity>, // u32 is the layer id, Entity is the tilemap entity.
}
#

You can make that a bevy resource or a component and stick it on an entity.

ruby depot
#

Layers don't seem that hard I just didn't want to create new code for existing feature

ruby depot
vapid crane
ruby depot
#

getting tiles, mapping errors, despawning is what I've seen so far

vapid crane
#

I did actually create a layer builder in my own game code. I don't mind sharing it here too.

ruby depot
#

notifying chunks

vapid crane
vapid crane
# ruby depot

look at the accessing_tiles example, everything is much simpler with the TileStorage struct.

ruby depot
#

alright

#

I'll swap MapQuery for that

#

and convert all the code, and make my own layer struct

#

thank you

vapid crane
ruby depot
vapid crane
ruby depot
#
#[derive(SystemParam)]
pub struct TilePlacer<'w, 's> {
    map_query: TileStorage,
    tilesets: Tilesets<'w, 's>,
    commands: Commands<'w, 's>,
    /// Query used to get info about a tile
    #[cfg(not(feature = "auto-tile"))]
    #[allow(dead_code)]
    query: Query<'w, 's, (&'static TileTextureIndex, Option<&'static AnimatedTile>)>,
    /// Query used to get info about a tile
    #[cfg(feature = "auto-tile")]
    #[allow(dead_code)]
    query: Query<
        'w,
        's,
        (
            &'static TileTextureIndex,
            Option<&'static AnimatedTile>,
            Option<&'static bevy_tileset::auto::AutoTileId>,
        ),
    >,
    /// Query used to get and send data for the [`RemoveAutoTileEvent`] event
    #[cfg(feature = "auto-tile")]
    #[allow(dead_code)]
    auto_query: Query<
        'w,
        's,
        (
            &'static TilePos,
            &'static TileParent,
            &'static bevy_tileset::auto::AutoTileId,
        ),
        With<Tile>,
    >,
    #[cfg(feature = "auto-tile")]
    #[allow(dead_code)]
    event_writer: EventWriter<'w, 's, crate::auto::RemoveAutoTileEvent>,
}
#

that's the code

vapid crane
#

TileStorage is a component on the tilemap entity. πŸ™‚ map_query: Query<'w, 's, &'static TileStorage>,

ruby depot
#

alright thank you that worked, time to convert all of the code

vapid crane
ruby depot
#

it is a pain

#

but it will be worth it I hope

vapid crane
#

When I upgraded my game I cheated and started over fresh :p