-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
184 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
crates/beet_core/src/steer/steer_actions/score_steer_target.rs
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
crates/beet_core/src/steer/steer_actions/steer_target_score_provider.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::prelude::*; | ||
use beet_ecs::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
#[derive(Debug, Clone, PartialEq, Component, Action, Reflect)] | ||
#[reflect(Default, Component, ActionMeta)] | ||
#[category(ActionCategory::Behavior)] | ||
#[observers(provide_score)] | ||
/// Provides a [`ScoreValue`] based on distance to the [`SteerTarget`] | ||
pub struct SteerTargetScoreProvider { | ||
pub radius: f32, | ||
} | ||
|
||
impl Default for SteerTargetScoreProvider { | ||
fn default() -> Self { Self { radius: 0.5 } } | ||
} | ||
|
||
impl SteerTargetScoreProvider { | ||
pub fn new(radius: f32) -> Self { Self { radius } } | ||
} | ||
|
||
fn provide_score( | ||
trigger: Trigger<RequestScore>, | ||
mut commands: Commands, | ||
transforms: Query<&Transform>, | ||
agents: Query<(&Transform, &SteerTarget)>, | ||
query: Query<(&SteerTargetScoreProvider, &TargetAgent, &Parent)>, | ||
) { | ||
let (action, agent, parent) = query | ||
.get(trigger.entity()) | ||
.expect(expect_action::ACTION_QUERY_MISSING); | ||
|
||
let score = if let Ok((transform, target)) = agents.get(**agent) | ||
&& let Ok(target) = target.position(&transforms) | ||
&& Vec3::distance(transform.translation, target) <= action.radius | ||
{ | ||
1. | ||
} else { | ||
0. | ||
}; | ||
commands.trigger_targets( | ||
OnChildScore::new(trigger.entity(), score), | ||
parent.get(), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use bevy::prelude::*; | ||
|
||
|
||
|
||
#[derive(Component)] | ||
pub struct Foo; | ||
|
||
#[derive(Event)] | ||
pub struct Event1; | ||
|
||
#[derive(Event)] | ||
pub struct Event2; | ||
|
||
|
||
|
||
|
||
fn main() { | ||
let mut world = World::new(); | ||
world.observe(|_trigger: Trigger<Event2>, query: Query<&Foo>| { | ||
println!("Event2 triggered, num components: {}", query.iter().len()); | ||
}); | ||
world.observe(|_trigger: Trigger<Event1>, mut commands: Commands| { | ||
println!("Event1 triggered"); | ||
// must spawn Foo before trigger | ||
commands.spawn(Foo); | ||
commands.trigger(Event2); | ||
}); | ||
world.flush(); | ||
world.trigger(Event1); | ||
world.flush(); | ||
println!("Hello, world!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
pub mod score_flow; | ||
#[allow(unused_imports)] | ||
pub use self::score_flow::*; | ||
pub mod score_provider; | ||
#[allow(unused_imports)] | ||
pub use self::score_provider::*; | ||
pub mod sequence_flow; | ||
#[allow(unused_imports)] | ||
pub use self::sequence_flow::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
pub type ScoreValue = f32; | ||
|
||
/// A constant score provider. | ||
#[derive(Default, Deref, DerefMut, Component, Action, Reflect)] | ||
#[reflect(Default, Component)] | ||
#[category(ActionCategory::ChildBehaviors)] | ||
#[observers(provide_score)] | ||
pub struct ScoreProvider(pub ScoreValue); | ||
|
||
impl ScoreProvider { | ||
pub const FAIL: ScoreProvider = ScoreProvider(0.0); | ||
pub const PASS: ScoreProvider = ScoreProvider(1.0); | ||
pub const NEUTRAL: ScoreProvider = ScoreProvider(0.5); | ||
|
||
pub fn new(score: ScoreValue) -> Self { Self(score) } | ||
} | ||
|
||
fn provide_score( | ||
trigger: Trigger<RequestScore>, | ||
mut commands: Commands, | ||
query: Query<(&ScoreProvider, &Parent)>, | ||
) { | ||
let (score_provider, parent) = query | ||
.get(trigger.entity()) | ||
.expect(expect_action::ACTION_QUERY_MISSING); | ||
|
||
commands.trigger_targets( | ||
OnChildScore::new(trigger.entity(), **score_provider), | ||
parent.get(), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use bevy::prelude::*; | ||
|
||
#[derive(Debug, Clone, Copy, Event, Reflect)] | ||
pub struct OnChildValue<T> { | ||
child: Entity, | ||
value: T, | ||
} | ||
|
||
impl<T> OnChildValue<T> { | ||
pub fn new(child: Entity, value: T) -> Self { Self { child, value } } | ||
pub fn value(&self) -> &T { &self.value } | ||
pub fn child(&self) -> Entity { self.child } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters