Skip to content

Commit

Permalink
feat(bevy): Update for bevy 0.13 (#93)
Browse files Browse the repository at this point in the history
Fixes: #92
  • Loading branch information
stargazing-dino committed Feb 19, 2024
1 parent 48b3ea4 commit 50415e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ homepage = "https://github.com/zkat/big-brain"
[workspace]

[dependencies]
bevy = { version = "0.12.1", default-features = false }
bevy = { version = "0.13.0", default-features = false }
big-brain-derive = { version = "=0.19.0", path = "./derive" }

[dev-dependencies]
bevy = { version = "0.12.1", default-features = true }
bevy = { version = "0.13.0", default-features = true }
rand = { version = "0.8.5", features = ["small_rng"] }
bevy-scene-hook = "9.0.0"
bevy-scene-hook = "10.0.0"

[features]
trace = []
46 changes: 18 additions & 28 deletions examples/farming_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,20 @@ pub fn sell_need_scorer_system(

// This is a component that will be attached to the actor entity when it is
// moving to a location. It's not an AI component, but a standard Bevy component
#[derive(Clone, Component, Debug)]
#[derive(Debug, Clone, Component, ActionBuilder)]
#[action_label = "MyGenericLabel"]
pub struct MoveToNearest<T: Component + std::fmt::Debug + Clone> {
// We use a PhantomData to store the type of the component we're moving to.
_marker: std::marker::PhantomData<T>,
speed: f32,
}

// We cannot use the derive macro here because we need to be generic over 'T'.
// Instead we manually implement the ActionBuilder trait.
impl<T> ActionBuilder for MoveToNearest<T>
where
T: Component + std::fmt::Debug + Clone,
{
// An action builder needs to implement this method. It's used to attach
// the Action component to the actor entity.
fn build(&self, cmd: &mut Commands, action: Entity, _actor: Entity) {
cmd.entity(action).insert(MoveToNearest::<T>::clone(self));
impl<T: Component + std::fmt::Debug + Clone> MoveToNearest<T> {
pub fn new(speed: f32) -> Self {
Self {
_marker: std::marker::PhantomData,
speed,
}
}
}

Expand Down Expand Up @@ -483,15 +481,15 @@ fn init_entities(

commands.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0,
brightness: 700.0,
});

commands.spawn((
Name::new("Light"),
SpotLightBundle {
spot_light: SpotLight {
shadows_enabled: true,
intensity: 5_000.0,
intensity: 500_000.0,
range: 100.0,
..default()
},
Expand Down Expand Up @@ -528,43 +526,34 @@ fn init_entities(

let move_and_sleep = Steps::build()
.label("MoveAndSleep")
.step(MoveToNearest::<House> {
speed: MOVEMENT_SPEED,
_marker: std::marker::PhantomData,
})
.step(MoveToNearest::<House>::new(MOVEMENT_SPEED))
.step(Sleep {
until: 10.0,
per_second: 15.0,
});

let move_and_farm = Steps::build()
.label("MoveAndFarm")
.step(MoveToNearest::<Field> {
speed: MOVEMENT_SPEED,
_marker: std::marker::PhantomData,
})
.step(MoveToNearest::<Field>::new(MOVEMENT_SPEED))
.step(Farm {
until: 10.0,
per_second: 10.0,
});

let move_and_sell = Steps::build()
.label("MoveAndSell")
.step(MoveToNearest::<Market> {
speed: MOVEMENT_SPEED,
_marker: std::marker::PhantomData,
})
.step(MoveToNearest::<Market>::new(MOVEMENT_SPEED))
.step(Sell);

commands.spawn((
Name::new("Farmer"),
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Capsule {
depth: 0.3,
mesh: meshes.add(Mesh::from(Capsule3d {
half_length: 0.15,
radius: 0.1,
..default()
})),
material: materials.add(DEFAULT_COLOR.into()),
material: materials.add(DEFAULT_COLOR),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
Expand Down Expand Up @@ -619,6 +608,7 @@ fn main() {
// Use `RUST_LOG=big_brain=trace,farming_sim=trace cargo run --example
// farming_sim --features=trace` to see extra tracing output.
filter: "big_brain=debug,farming_sim=debug".to_string(),
update_subscriber: None,
}))
.add_plugins(HookPlugin)
.add_plugins(BigBrainPlugin::new(PreUpdate))
Expand Down

0 comments on commit 50415e5

Please sign in to comment.