Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.12 support #86

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ homepage = "https://github.com/zkat/big-brain"
[workspace]

[dependencies]
bevy = { version = "0.11", default-features = false }
bevy = { version = "0.12.0", default-features = false }
big-brain-derive = { version = "=0.18.0", path = "./derive" }

[dev-dependencies]
bevy = { version = "0.11", default-features = true }
bevy = { version = "0.12.0", default-features = true }
rand = { version = "0.8.5", features = ["small_rng"] }

[features]
Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub mod prelude {
};
}

use bevy::{ecs::schedule::ScheduleLabel, prelude::*};
use bevy::{ecs::schedule::ScheduleLabel, prelude::*, utils::intern::Interned};

/// Core [`Plugin`] for Big Brain behavior. Required for any of the
/// [`Thinker`](thinker::Thinker)-related magic to work.
Expand All @@ -222,42 +222,42 @@ use bevy::{ecs::schedule::ScheduleLabel, prelude::*};
#[reflect(from_reflect = false)]
pub struct BigBrainPlugin {
#[reflect(ignore)]
schedule: Box<dyn ScheduleLabel>,
schedule: Interned<dyn ScheduleLabel>,
#[reflect(ignore)]
cleanup_schedule: Box<dyn ScheduleLabel>,
cleanup_schedule: Interned<dyn ScheduleLabel>,
}

impl BigBrainPlugin {
/// Create the BigBrain plugin which runs the scorers, thinker and actions in the specified
/// schedule
pub fn new(schedule: impl ScheduleLabel) -> Self {
Self {
schedule: Box::new(schedule),
cleanup_schedule: Box::new(Last),
schedule: schedule.intern(),
cleanup_schedule: Last.intern(),
}
}

/// Overwrite the Schedule that is used to run cleanup tasks. By default this happens in Last.
pub fn set_cleanup_schedule(mut self, cleanup_schedule: impl ScheduleLabel) -> Self {
self.cleanup_schedule = Box::new(cleanup_schedule);
self.cleanup_schedule = cleanup_schedule.intern();
self
}
}

impl Plugin for BigBrainPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
self.schedule.dyn_clone(),
self.schedule.intern(),
(
BigBrainSet::Scorers,
BigBrainSet::Thinkers,
BigBrainSet::Actions,
)
.chain(),
)
.configure_set(self.cleanup_schedule.dyn_clone(), BigBrainSet::Cleanup)
.configure_sets(self.cleanup_schedule.intern(), BigBrainSet::Cleanup)
.add_systems(
self.schedule.dyn_clone(),
self.schedule.intern(),
(
scorers::fixed_score_system,
scorers::measured_scorers_system,
Expand All @@ -270,15 +270,15 @@ impl Plugin for BigBrainPlugin {
.in_set(BigBrainSet::Scorers),
)
.add_systems(
self.schedule.dyn_clone(),
self.schedule.intern(),
thinker::thinker_system.in_set(BigBrainSet::Thinkers),
)
.add_systems(
self.schedule.dyn_clone(),
self.schedule.intern(),
(actions::steps_system, actions::concurrent_system).in_set(BigBrainSet::Actions),
)
.add_systems(
self.cleanup_schedule.dyn_clone(),
self.cleanup_schedule.intern(),
(
thinker::thinker_component_attach_system,
thinker::thinker_component_detach_system,
Expand Down
Loading