Skip to content

Commit

Permalink
Run systems in First after Time set
Browse files Browse the repository at this point in the history
If we accept that [(#4669) Res<Time> is jittery](bevyengine/bevy#4669) then

1. Time is updated in the [TimeSystem set](https://docs.rs/bevy/0.14.2/bevy/time/struct.TimeSystem.html)
2. No work should happen before the Time is updated in a frame

This doesn't fix the upstream jitter issue, but we can reduce bevy_ecs_tilemap's potential impact on the issue by making sure any work we do in `First` is done *after* time is updated.

\## Solution

1. Create a new `TilemapFirstSet` SystemSet
2. Add bevy_ecs_tilemap `First` systems to `TilemapFirstSet`
3. Order `TilemapFirstSet` systems after the `TimeSystem`.

\## Migration

This shouldn't require end-user migration, but if you want to run system in First after bevy_ecs_tilemap's work, then the new SystemSet should be used.
  • Loading branch information
ChristopherBiscardi committed Sep 15, 2024
1 parent ac311b0 commit f8d25c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
//! - Built in animation support – see [`animation` example](https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/examples/animation.rs).
//! - Texture array support.

use bevy::prelude::{
Bundle, Changed, Component, Deref, First, GlobalTransform, InheritedVisibility, Plugin, Query,
Reflect, ReflectComponent, Transform, ViewVisibility, Visibility,
use bevy::{
prelude::{
Bundle, Changed, Component, Deref, First, GlobalTransform, InheritedVisibility,
IntoSystemConfigs, IntoSystemSetConfigs, Plugin, Query, Reflect, ReflectComponent,
SystemSet, Transform, ViewVisibility, Visibility,
},
time::TimeSystem,
};

#[cfg(feature = "render")]
Expand Down Expand Up @@ -58,7 +62,7 @@ impl Plugin for TilemapPlugin {
#[cfg(feature = "render")]
app.add_plugins(render::TilemapRenderingPlugin);

app.add_systems(First, update_changed_tile_positions);
app.add_systems(First, update_changed_tile_positions.in_set(TilemapFirstSet));

#[cfg(all(not(feature = "atlas"), feature = "render"))]
{
Expand All @@ -83,10 +87,14 @@ impl Plugin for TilemapPlugin {
.register_type::<TileFlip>()
.register_type::<TileStorage>()
.register_type::<TilePosOld>()
.register_type::<AnimatedTile>();
.register_type::<AnimatedTile>()
.configure_sets(First, TilemapFirstSet.after(TimeSystem));
}
}

#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
pub struct TilemapFirstSet;

#[derive(Component, Reflect, Debug, Clone, Copy, Deref)]
#[reflect(Component)]
pub struct FrustumCulling(pub bool);
Expand Down
3 changes: 2 additions & 1 deletion src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use bevy::render::texture::GpuImage;
use crate::{
prelude::TilemapRenderSettings,
tiles::{TilePos, TileStorage},
TilemapFirstSet,
};
use crate::{
prelude::TilemapTexture,
Expand Down Expand Up @@ -113,7 +114,7 @@ impl Plugin for TilemapRenderingPlugin {
#[cfg(not(feature = "atlas"))]
app.add_systems(Update, set_texture_to_copy_src);

app.add_systems(First, clear_removed);
app.add_systems(First, clear_removed.in_set(TilemapFirstSet));
app.add_systems(PostUpdate, (removal_helper, removal_helper_tilemap));

app.add_plugins(MaterialTilemapPlugin::<StandardTilemapMaterial>::default());
Expand Down

0 comments on commit f8d25c6

Please sign in to comment.