Skip to content

Commit

Permalink
feat: build observer scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Jul 28, 2024
1 parent deabdf6 commit 9341c5a
Show file tree
Hide file tree
Showing 28 changed files with 30,738 additions and 170 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ opt-level = 1
opt-level = 3

[workspace.package]
version = "0.0.4-rc.1"
version = "0.0.4-rc.2"
edition = "2021"
description = "A very flexible AI behavior library for games and robotics."
documentation = "https://beetmash.com/docs/beet"
Expand Down Expand Up @@ -38,12 +38,12 @@ members = [

[workspace.dependencies]
## internal
beet = { path = "./", version = "0.0.4-rc.1" }
beet_spatial = { path = "crates/beet_spatial", version = "0.0.4-rc.1", default-features = false }
beet_flow = { path = "crates/beet_flow", version = "0.0.4-rc.1" }
beet_flow_macros = { path = "crates/beet_flow/macros", version = "0.0.4-rc.1" }
beet_ml = { path = "crates/beet_ml", version = "0.0.4-rc.1" }
beet_examples = { path = "crates/beet_examples", version = "0.0.4-rc.1" }
beet = { path = "./", version = "0.0.4-rc.2" }
beet_spatial = { path = "crates/beet_spatial", version = "0.0.4-rc.2", default-features = false }
beet_flow = { path = "crates/beet_flow", version = "0.0.4-rc.2" }
beet_flow_macros = { path = "crates/beet_flow/macros", version = "0.0.4-rc.2" }
beet_ml = { path = "crates/beet_ml", version = "0.0.4-rc.2" }
beet_examples = { path = "crates/beet_examples", version = "0.0.4-rc.2" }

## local
beetmash = { version = "0.0.6-rc.1", path = "../beetmash" }
Expand Down
60 changes: 54 additions & 6 deletions crates/beet_examples/src/plugins/beet_example_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
use crate::prelude::*;
use beet_flow::prelude::*;
use beet_ml::prelude::*;
use beet_spatial::prelude::*;
use beetmash::prelude::*;
use bevy::prelude::*;

pub struct BeetExamplePlugin;
pub fn running_beet_example_plugin(app: &mut App) {
app.add_plugins((
BeetmashDefaultPlugins::with_beetmash_assets(),
beet_example_plugin,
));
}

pub fn beet_example_plugin(app: &mut App) {
app.add_plugins((
// BeetmashDefaultPlugins::with_beetmash_assets(),
DefaultPlaceholderPlugin,
UiTerminalPlugin,
LifecyclePlugin::default(),
BeetSpatialPlugins,
BeetDebugPlugin,
DefaultReplicatePlugin,
))
.add_plugins((plugin_spatial, plugin_2d, plugin_3d))
.register_type::<Collectable>();
}


/// For apps and scenes that use beet_spatial
pub fn plugin_spatial(app: &mut App) {
app
.add_plugins(ActionPlugin::<(
RemoveOnTrigger<OnRunResult, SteerTarget>,
RemoveOnTrigger<OnRunResult, Velocity>,
InsertOnTrigger<OnRun, Velocity>,
RemoveOnTrigger<OnRun, Velocity>,
)>::default())
/*-*/;
}

impl Plugin for BeetExamplePlugin {
fn build(&self, app: &mut App) {
app.add_plugins((plugin_2d, plugin_3d))
.register_type::<Collectable>();
}

pub fn plugin_ml(app: &mut App) {
app.add_plugins((
FrozenLakePlugin,
// sentence selector
BertPlugin::default(),
AssetPlaceholderPlugin::<Bert>::default(),
ReadyOnAssetLoadPlugin::<Bert>::default(),
// qtables (frozen lake)
AssetPlaceholderPlugin::<QTable<GridPos, GridDirection>>::default(),
ReadyOnAssetLoadPlugin::<QTable<GridPos, GridDirection>>::default(),
))
// fetch
.add_plugins(ActionPlugin::<(
InsertSentenceSteerTarget<Collectable>,
RemoveOnTrigger<OnRunResult, Sentence>,
)>::default())
/*-*/;
}

fn plugin_2d(app: &mut App) {
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions crates/beet_examples/src/scenes/spatial/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
pub mod avoid_obstacles;
#[allow(unused_imports)]
pub use self::avoid_obstacles::*;
pub mod beet_spatial_scene_plugin;
#[allow(unused_imports)]
pub use self::beet_spatial_scene_plugin::*;
pub mod flock;
#[allow(unused_imports)]
pub use self::flock::*;
Expand Down
3 changes: 1 addition & 2 deletions crates/beet_flow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ categories.workspace = true


[features]
default = ["net"]
default = ["net", "reflect"]
# beetmash = ["dep:beetmash"]
net = ["dep:beetmash", "beetmash/net"]
# default = ["reflect"]
reflect = []
test = ["dep:sweet"]

Expand Down
1 change: 1 addition & 0 deletions crates/beet_flow/src/lifecycle/beet_debug_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Default for BeetDebugConfig {
/// A plugin that logs lifecycle events for behaviors with a [`Name`].
/// It triggers [OnLogMessage] events, and also adds a listener that
/// will print to stdout if [`BeetDebugConfig::log_to_stdout`] is true.
#[derive(Clone)]
pub struct BeetDebugPlugin;
impl Plugin for BeetDebugPlugin {
fn build(&self, app: &mut App) {
Expand Down
24 changes: 0 additions & 24 deletions crates/beet_ml/src/plugins/ml_plugin.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/beet_ml/src/plugins/mod.rs

This file was deleted.

8 changes: 3 additions & 5 deletions crates/beet_spatial/src/app/beet_plugins.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::prelude::*;
use beet_flow::prelude::*;
use bevy::app::PluginGroupBuilder;
use bevy::prelude::*;

/// Plugins used for most beet apps.
#[derive(Default)]
pub struct BeetPlugins;
#[derive(Default, Clone)]
pub struct BeetSpatialPlugins;

impl PluginGroup for BeetPlugins {
impl PluginGroup for BeetSpatialPlugins {
fn build(self) -> PluginGroupBuilder {
#[allow(unused_mut)]
let mut builder = PluginGroupBuilder::start::<Self>()
.add(LifecyclePlugin::default())
.add(MovementPlugin::default())
.add(SteerPlugin::default());

Expand Down
16 changes: 2 additions & 14 deletions examples/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,5 @@
use beet_examples::prelude::*;
use bevy::prelude::*;

fn main() {
App::new()
.add_plugins((
BeetmashDefaultPlugins::with_beetmash_assets(),
BeetPlugins,
BeetDebugPlugin,
ExamplePluginTy1pesBasic,
DefaultReplicatePlugin,
CliSceneLoadPlugin,
DefaultPlaceholderPlugin,
UiTerminalPlugin,
))
.run();
}

fn main() { App::new().add_plugins(running_beet_example_plugin).run(); }
102 changes: 56 additions & 46 deletions examples/build_scenes.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
use anyhow::Result;
use beet_examples::prelude::*;
use beetmash::prelude::*;
use bevy::ecs::observer::ObserverState;
use bevy::prelude::*;

const DIR: &str = "scenes";

fn plugin(app: &mut App) {
app.add_plugins((MostDefaultPlugins, beet_example_plugin));
}

const CHECKS: DynamicSceneChecks = DynamicSceneChecks {
asset_checks: false,
entity_checks: true,
component_checks: true,
};

fn main() -> Result<()> {
SceneExporter::new((
MostDefaultPlugins,
DefaultPlaceholderPlugin,
UiTerminalPlugin,
))
.with_checks(DynamicSceneChecks {
asset_checks: false,
entity_checks: true,
component_checks: true,
})
.with_dir(DIR)
.with_query::<(Without<ObserverState>, Without<Observer<OnLogMessage, ()>>)>(
)
.add_scene("beet-debug", beet_examples::scenes::flow::beet_debug)
.add_scene("hello-world", beet_examples::scenes::flow::hello_world)
.build()?;
SceneExporter::new(plugin)
.with_checks(CHECKS)
.with_dir(DIR)
.with_query::<(Without<ObserverState>, Without<Observer<OnLogMessage, ()>>)>(
)
.add_scene("beet-debug", beet_examples::scenes::flow::beet_debug)
.add_scene("hello-world", beet_examples::scenes::flow::hello_world)
.build()?;

// BeetmashSceneBuilder::new((
// MostDefaultPlugins,
// DefaultPlaceholderPlugin,
// UiTerminalPlugin,
// beet::spatial::scenes::beet_spatial_scene_plugin,
// ))
// .with_dir(DIR)
// .with_query::<(Without<ObserverState>, Without<Observer<OnLogMessage, ()>>)>(
// )
// .add_scene("seek", beet::spatial::scenes::seek)
// .add_scene("flock", beet::spatial::scenes::flock)
// .add_scene("seek-3d", beet::spatial::scenes::seek_3d)
// .add_scene("hello-animation", beet::spatial::scenes::hello_animation)
// .build()?;
SceneExporter::new(plugin)
.with_checks(CHECKS)
.with_dir(DIR)
.with_query::<(Without<ObserverState>, Without<Observer<OnLogMessage, ()>>)>(
)
.without_clear_target()
.add_scene("seek", beet_examples::scenes::spatial::seek)
.add_scene("flock", beet_examples::scenes::spatial::flock)
.add_scene("seek-3d", beet_examples::scenes::spatial::seek_3d)
.add_scene(
"hello-animation",
beet_examples::scenes::spatial::hello_animation,
)
.build()?;


// BeetmashSceneBuilder::new((
// MostDefaultPlugins,
// DefaultPlaceholderPlugin,
// UiTerminalPlugin,
// ))
// .with_dir(DIR)
// .with_query::<(Without<ObserverState>, Without<Observer<OnLogMessage, ()>>)>(
// )
// .add_scene("fetch-scene", beet::ml::scenes::fetch_scene)
// .add_scene("fetch-npc", beet::ml::scenes::fetch_npc)
// .add_scene("sentence-selector", beet::ml::scenes::hello_ml)
// // frozen-lake
// .add_scene("frozen-lake-scene", beet::ml::scenes::frozen_lake_scene)
// .add_scene("frozen-lake-train", beet::ml::scenes::frozen_lake_train)
// .add_scene("frozen-lake-run", beet::ml::scenes::frozen_lake_run)
// .build()?;
SceneExporter::new((plugin, plugin_ml))
.with_checks(CHECKS)
.with_dir(DIR)
.without_clear_target()
.with_query::<(Without<ObserverState>, Without<Observer<OnLogMessage, ()>>)>(
)
.add_scene("fetch-scene", beet_examples::scenes::ml::fetch_scene)
.add_scene("fetch-npc", beet_examples::scenes::ml::fetch_npc)
.add_scene("sentence-selector", beet_examples::scenes::ml::hello_ml)
// frozen-lake
.add_scene(
"frozen-lake-scene",
beet_examples::scenes::ml::frozen_lake_scene,
)
.add_scene(
"frozen-lake-train",
beet_examples::scenes::ml::frozen_lake_train,
)
.add_scene(
"frozen-lake-run",
beet_examples::scenes::ml::frozen_lake_run,
)
.build()?;
Ok(())
}
Loading

0 comments on commit 9341c5a

Please sign in to comment.