Skip to content

Commit

Permalink
remove: selectors & change-detction flow components
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Jul 12, 2024
1 parent c8990ad commit 37831d5
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 860 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tokio.workspace = true
### WORKSPACE ################################################################################################z###########################

[workspace.package]
version = "0.0.6"
version = "0.0.7"
edition = "2021"
description = "A very flexible AI behavior library for games and robotics."
documentation = "https://beetmash.com/docs/beet"
Expand Down Expand Up @@ -96,14 +96,14 @@ exclude = ["crates/beet_esp"]

[workspace.dependencies]
## internal
beet = { path = "./", version = "0.0.6" }
beet_core = { path = "crates/beet_core", version = "0.0.6", default-features = false }
beet_ecs = { path = "crates/beet_ecs", version = "0.0.6" }
beet_ecs_macros = { path = "crates/beet_ecs/macros", version = "0.0.6" }
beet_ml = { path = "crates/beet_ml", version = "0.0.6" }
beet_net = { path = "crates/beet_net", version = "0.0.6" }
beet_server = { path = "crates/beet_server", version = "0.0.6" }
beet_examples = { path = "crates/beet_examples", version = "0.0.6" }
beet = { path = "./", version = "0.0.7" }
beet_core = { path = "crates/beet_core", version = "0.0.7", default-features = false }
beet_ecs = { path = "crates/beet_ecs", version = "0.0.7" }
beet_ecs_macros = { path = "crates/beet_ecs/macros", version = "0.0.7" }
beet_ml = { path = "crates/beet_ml", version = "0.0.7" }
beet_net = { path = "crates/beet_net", version = "0.0.7" }
beet_server = { path = "crates/beet_server", version = "0.0.7" }
beet_examples = { path = "crates/beet_examples", version = "0.0.7" }

## local
# forky_core = { path = "../forky/crates/forky/forky_core" }
Expand Down
36 changes: 0 additions & 36 deletions crates/beet_core/src/robotics/avoid_obstacle_behavior.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/beet_core/src/robotics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
pub mod avoid_obstacle_behavior;
#[allow(unused_imports)]
pub use self::avoid_obstacle_behavior::*;
pub mod depth;
#[allow(unused_imports)]
pub use self::depth::*;
Expand Down
1 change: 0 additions & 1 deletion crates/beet_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub mod prelude {
pub use crate::lifecycle::components::*;
pub use crate::lifecycle::lifecycle_plugin::*;
pub use crate::lifecycle::lifecycle_systems_plugin::*;
pub use crate::lifecycle::selectors::*;
pub use crate::observers::*;
// pub use crate::lifecycle::*;
pub use crate::reflect::*;
Expand Down
72 changes: 0 additions & 72 deletions crates/beet_ecs/src/lifecycle/components/interrupt.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/beet_ecs/src/lifecycle/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
pub mod action_target;
#[allow(unused_imports)]
pub use self::action_target::*;
pub mod interrupt;
#[allow(unused_imports)]
pub use self::interrupt::*;
pub mod run_timer;
#[allow(unused_imports)]
pub use self::run_timer::*;
Expand Down
54 changes: 3 additions & 51 deletions crates/beet_ecs/src/lifecycle/components/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,12 @@ pub struct Running;

/// Indicate the result of an action.
/// As this is frequently added and removed, it is `SparseSet`.
#[derive(Default, Debug, Clone, Copy, Component, PartialEq, Reflect)]
#[component(storage = "SparseSet")]
#[reflect(Component, Default)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Reflect)]
#[reflect(Default)]
pub enum RunResult {
#[default]
/// The Action was successful.
Success,
/// The Action was unsuccessful.
Failure,
}


/// Syncs [`Running`] and [`RunResult`] components, by default added to [`PostNodeUpdateSet`].
pub fn sync_running(
mut commands: Commands,
// occurs immediately after `RunResult` is added
first_pass: Query<Entity, (Added<RunResult>, With<Running>)>,
// occurs one frame later
second_pass: Query<Entity, (With<RunResult>, Without<Running>)>,
) {
for entity in first_pass.iter() {
commands.entity(entity).remove::<Running>();
}
for entity in second_pass.iter() {
commands.entity(entity).remove::<RunResult>();
}
}


#[cfg(test)]
mod test {
use crate::prelude::*;
use anyhow::Result;
use bevy::prelude::*;
use sweet::*;

#[test]
pub fn works() -> Result<()> {
let mut app = App::new();
app.add_plugins(LifecyclePlugin);

let entity = app.world_mut().spawn((Running, RunResult::Success)).id();

expect(&app).to_have_component::<Running>(entity)?;
// add `RunResult`, remove `Running`
app.update();
expect(&app).not().to_have_component::<Running>(entity)?;
expect(&app).to_have_component::<RunResult>(entity)?;
// remove `Running`
app.update();
// remove `RunResult`
expect(&app).not().to_have_component::<Running>(entity)?;
expect(&app).not().to_have_component::<RunResult>(entity)?;

Ok(())
}
}
}
9 changes: 2 additions & 7 deletions crates/beet_ecs/src/lifecycle/lifecycle_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ impl Plugin for LifecyclePlugin {

app.add_plugins(ActionPlugin::<(
TriggerInDuration<OnRunResult>,
InsertOnRun<RunResult>,
RunTimer,
LogOnRun,
// CallOnRun,
SetOnSpawn<Score>,
// selectors
FallbackSelector,
ParallelSelector,
SequenceSelector,
ScoreSelector,
// utility
EmptyAction,
)>::default())
Expand All @@ -31,6 +25,8 @@ impl Plugin for LifecyclePlugin {
InsertOnTrigger<OnRun, Running>,
RemoveOnTrigger<OnRunResult, Running>,
SequenceFlow,
FallbackFlow,
ParallelFlow,
ScoreFlow,
ScoreProvider,
EndOnRun,
Expand All @@ -57,7 +53,6 @@ impl Plugin for LifecyclePlugin {
// running
world.init_component::<Running>();
world.init_component::<RunTimer>();
world.init_component::<RunResult>();
// graph
world.init_component::<Parent>();
world.init_component::<Children>();
Expand Down
6 changes: 1 addition & 5 deletions crates/beet_ecs/src/lifecycle/lifecycle_systems_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ impl Plugin for LifecycleSystemsPlugin {
.add_systems(schedule, apply_deferred.after(PreTickSet).before(TickSet))
.add_systems(schedule, apply_deferred.after(TickSet).before(TickSyncSet))
.add_systems(schedule, apply_deferred.after(TickSyncSet).before(PostTickSet))
.add_systems(
schedule,
(sync_interrupts, sync_running).chain().in_set(TickSyncSet),
)
.add_systems(
schedule,
set_root_as_target_agent.in_set(PreTickSet),
Expand All @@ -53,4 +49,4 @@ impl Plugin for LifecycleSystemsPlugin {
}
}

pub const NUM_GLOBAL_OBSERVERS: u32 = 3;
pub const NUM_GLOBAL_OBSERVERS: u32 = 3;
1 change: 0 additions & 1 deletion crates/beet_ecs/src/lifecycle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ pub use self::lifecycle_plugin::*;
pub mod lifecycle_systems_plugin;
#[allow(unused_imports)]
pub use self::lifecycle_systems_plugin::*;
pub mod selectors;
Loading

0 comments on commit 37831d5

Please sign in to comment.