Skip to content

Commit

Permalink
fix compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-orr committed Dec 29, 2023
1 parent 2690a52 commit 642342d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 57 deletions.
1 change: 0 additions & 1 deletion crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern crate proc_macro;

mod component;
mod fetch;
mod state_matchers;
mod query_data;
mod query_filter;
Expand Down
9 changes: 1 addition & 8 deletions crates/bevy_ecs/src/schedule/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::mem;
use std::ops::Deref;

use crate as bevy_ecs;
use crate::change_detection::DetectChangesMut;
use crate::prelude::FromWorld;
#[cfg(feature = "bevy_reflect")]
use crate::reflect::ReflectResource;
Expand Down Expand Up @@ -208,7 +207,7 @@ impl<S: States> Deref for State<S> {
/// To queue a transition, just set the contained value to `Some(next_state)`.
/// Note that these transitions can be overridden by other systems:
/// only the actual value of this resource at the time of [`apply_state_transition`] matters.
#[derive(Resource, Debug)]
#[derive(Resource, Debug, Default)]
#[cfg_attr(
feature = "bevy_reflect",
derive(bevy_reflect::Reflect),
Expand Down Expand Up @@ -274,12 +273,6 @@ impl<S: States> Debug for NextState<S> {
}
}

impl<S: States> Default for NextState<S> {
fn default() -> Self {
Self(None)
}
}

impl<S: States> NextState<S> {
/// Tentatively set a planned state transition to `Some(state)`.
pub fn set(&mut self, state: S) {
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/schedule/state_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ impl<S: States, M: 'static, Sm: StateMatcher<S, M>> System for StateMatcherSyste
fn set_last_run(&mut self, last_run: crate::component::Tick) {
self.0.set_last_run(last_run);
}

fn has_deferred(&self) -> bool {
false
}
}

/// SAFETY: The boxed system is must be a read only system
Expand Down
26 changes: 13 additions & 13 deletions examples/ecs/black_box_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_systems(Update, toggle_pause)
.add_systems(Startup, setup)
.add_state::<AppState>()
.init_state::<AppState>()
// Because we can't really see the internals of `AppState`, we need to rely on matching functions exported from
// the `state` module. Fortunately, we can use these with the `entering`/`exiting`/`transitioning` functions!
// Here we are using the `in_menu` function, which uses a derive to match any state with `in_menu: true`
Expand Down Expand Up @@ -303,21 +303,21 @@ fn setup_game(
const SPEED: f32 = 100.0;
fn movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y += 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y -= 1.0;
}

Expand All @@ -329,21 +329,21 @@ fn movement(

fn inverted_movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y -= 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y += 1.0;
}

Expand All @@ -361,14 +361,14 @@ fn change_color(time: Res<Time>, mut query: Query<&mut Sprite>) {
}
}

fn toggle_pause(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn toggle_pause(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::Escape) {
// Like above, we can use the supported operations
next_state.setter(|state| state.toggle_pause());
}
}

fn invert_movement(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn invert_movement(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::ShiftLeft) {
next_state.setter(|s| s.invert_movement());
}
Expand Down
26 changes: 13 additions & 13 deletions examples/ecs/nested_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
.add_systems(Startup, setup)
// You need to register a state type for it to be usable in the app.
// This sets up all the necessary systems, schedules & resources in the background.
.add_state::<AppState>()
.init_state::<AppState>()
// This system runs when we enter `AppState::Menu`, during the `StateTransition` schedule.
// All systems from the exit schedule of the state we're leaving are run first,
// and then all systems from the enter schedule of the state we're entering are run second.
Expand Down Expand Up @@ -196,21 +196,21 @@ fn setup_game(
const SPEED: f32 = 100.0;
fn movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y += 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y -= 1.0;
}

Expand All @@ -222,21 +222,21 @@ fn movement(

fn inverted_movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y -= 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y += 1.0;
}

Expand All @@ -254,7 +254,7 @@ fn change_color(time: Res<Time>, mut query: Query<&mut Sprite>) {
}
}

fn toggle_pause(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn toggle_pause(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::Escape) {
// Alternatively, you provide next_state with a setter function, which will take the current state, and output the new state, allowing for some degree of update-in-place
next_state.setter(|state| match &state {
Expand All @@ -267,7 +267,7 @@ fn toggle_pause(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<App
}
}

fn invert_movement(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn invert_movement(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::ShiftLeft) {
next_state.set(AppState::InGame(GameState::Running { inverted: true }));
}
Expand Down
16 changes: 8 additions & 8 deletions examples/ecs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() {
)
// We can also have more than one state type set up in an app.
// In this case, we are adding a Struct as our state type, instead of an enum.
.add_state::<MovementState>()
.init_state::<MovementState>()
// And we can chain states just like any run condition, to check against multiple different states!
.add_systems(
Update,
Expand Down Expand Up @@ -212,21 +212,21 @@ fn movement(

fn inverted_movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y -= 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y += 1.0;
}

Expand All @@ -244,7 +244,7 @@ fn change_color(time: Res<Time>, mut query: Query<&mut Sprite>) {
}
}

fn toggle_pause(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn toggle_pause(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::Escape) {
// Alternatively, you provide next_state with a setter function, which will take the current state, and output the new state, allowing for some degree of update-in-place
next_state.setter(|state| match &state {
Expand All @@ -257,7 +257,7 @@ fn toggle_pause(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<App
}
}

fn invert_movement(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<MovementState>>) {
fn invert_movement(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<MovementState>>) {
if input.just_pressed(KeyCode::ShiftLeft) {
next_state.set(MovementState { inverted: true });
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/state_transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_state::<AppState>()
.init_state::<AppState>()
.add_systems(
Exiting,
cleanup_ui.run_if(state_matches!(AppState, every _)),
Expand Down
26 changes: 13 additions & 13 deletions examples/ecs/struct_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
.add_systems(Startup, setup)
// You need to register a state type for it to be usable in the app.
// This sets up all the necessary systems, schedules & resources in the background.
.add_state::<AppState>()
.init_state::<AppState>()
// Because our state is a complex object, it isn't worth using a value for OnEnter in this case.
// Instead, we will stick with pattern matching
.add_systems(
Expand Down Expand Up @@ -276,21 +276,21 @@ fn setup_game(
const SPEED: f32 = 100.0;
fn movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y += 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y -= 1.0;
}

Expand All @@ -302,21 +302,21 @@ fn movement(

fn inverted_movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
direction.x += 1.0;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
direction.x -= 1.0;
}
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
direction.y -= 1.0;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
direction.y += 1.0;
}

Expand All @@ -334,14 +334,14 @@ fn change_color(time: Res<Time>, mut query: Query<&mut Sprite>) {
}
}

fn toggle_pause(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn toggle_pause(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::Escape) {
// Like above, we can use the supported operations
next_state.setter(|state| state.toggle_pause());
}
}

fn invert_movement(input: Res<Input<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
fn invert_movement(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<AppState>>) {
if input.just_pressed(KeyCode::ShiftLeft) {
next_state.setter(|s| s.invert_movement());
}
Expand Down

0 comments on commit 642342d

Please sign in to comment.