Skip to content

Commit

Permalink
feat: screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Jul 7, 2024
1 parent 6fb053c commit 9da7e68
Show file tree
Hide file tree
Showing 18 changed files with 337 additions and 121 deletions.
32 changes: 23 additions & 9 deletions Cargo.lock

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

38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ tokio = ["beet_net/tokio", "beet_examples/tokio"]
# dynamic_linking = ["bevy/dynamic_linking"]

[dependencies]
beet_core.workspace = true
beet_ecs.workspace = true
beet_core.workspace = true
beet_ml = { workspace = true, optional = true }
beet_net = { workspace = true, optional = true }

Expand All @@ -59,7 +59,7 @@ tokio.workspace = true
### WORKSPACE ################################################################################################z###########################

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

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

## local
forky_core = { path = "../forky/crates/forky/forky_core" }
forky_bevy = { path = "../forky/crates/forky/forky_bevy" }
forky_web = { path = "../forky/crates/forky/forky_web", default-features = false }
sweet = { path = "../forky/crates/sweet", features = ["bevy"] }

# forky_core = "0.1.49"
# forky_bevy = "0.1.49"
# forky_web = "0.1.49"
# sweet = { version = "0.1.49", features = ["bevy"] }
# forky_core = { path = "../forky/crates/forky/forky_core" }
# forky_bevy = { path = "../forky/crates/forky/forky_bevy" }
# forky_web = { path = "../forky/crates/forky/forky_web", default-features = false }
# sweet = { path = "../forky/crates/sweet", features = ["bevy"] }

forky_core = "0.1.50"
forky_bevy = "0.1.50"
forky_web = "0.1.50"
sweet = { version = "0.1.50", features = ["bevy"] }

## logging
log = "0.4"
Expand Down
11 changes: 8 additions & 3 deletions crates/beet_examples/examples/build_replication_registry.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
//! This example is for exporting the example replication registry.
//! Import it into other apps for consistent reg_ids.
use anyhow::Result;
use beet::prelude::*;
use beet_examples::prelude::*;
use bevy::prelude::*;
use std::fs;


fn main() {
fn main() -> Result<()> {
let mut app = App::new();
app.add_plugins(ExampleReplicatePlugin);
let registry = app.world().resource::<ReplicateRegistry>();
println!("Replicate Registry:\n{}", registry.types_to_json());
let json = registry.types_to_json();
let path = "target/replication_registry.json";
fs::write(path, json)?;
println!("Wrote Replication registry:\nPath: {path}\nDetails:\n{}", registry.types_to_json());
Ok(())
}
51 changes: 30 additions & 21 deletions crates/beet_examples/src/components/camera_distance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy::window::WindowResized;

/// Moves camera distance to keep the width in view on window resize
Expand All @@ -25,32 +26,40 @@ impl CameraDistance {

pub fn camera_distance(
mut resize: EventReader<WindowResized>,
main_window: Query<&Window, With<PrimaryWindow>>,
camera_added: Query<
(),
(
With<CameraDistance>,
Or<(Added<Camera>, Added<CameraDistance>)>,
),
>,
mut query: Query<(&mut Transform, &Projection, &CameraDistance)>,
) {
for e in resize.read() {
// e.width;
let aspect_ratio = e.width as f32 / e.height as f32;


for (mut transform, projection, camera_distance) in query.iter_mut() {
let Projection::Perspective(perspective) = projection else {
continue;
};
let fov = perspective.fov * 0.5;

let hfov = 2. * f32::atan(f32::tan(fov) * aspect_ratio);
let z = camera_distance.width / f32::tan(hfov * 0.5);
if camera_added.iter().count() == 0 && resize.read().count() == 0 {
return;
}
let Ok(window) = main_window.get_single() else {
return;
};

// log::info!("z: {}", z);
let aspect_ratio = window.width() as f32 / window.height() as f32;

// let z = camera_distance.x / fov.tan();
for (mut transform, projection, camera_distance) in query.iter_mut() {
let Projection::Perspective(perspective) = projection else {
continue;
};
let fov = perspective.fov * 0.5;

let hfov = 2. * f32::atan(f32::tan(fov) * aspect_ratio);
let z = camera_distance.width / f32::tan(hfov * 0.5);

// let fwd = transform.forward();
let fwd = camera_distance.offset.normalize();
let pos = camera_distance.offset + fwd * z;
transform.translation = pos;
transform.look_at(Vec3::ZERO, Vec3::Y);
}
// log::info!("z: {}", z);
// let z = camera_distance.x / fov.tan();
// let fwd = transform.forward();
let fwd = camera_distance.offset.normalize();
let pos = camera_distance.offset + fwd * z;
transform.translation = pos;
transform.look_at(Vec3::ZERO, Vec3::Y);
}
}
24 changes: 19 additions & 5 deletions crates/beet_examples/src/components/ui_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Plugin for UiTerminalPlugin {
))
.add_systems(
PostUpdate,
(init_output,handle_resize_event,remove_excessive_lines)
(init_output,resize_output_container,remove_excessive_lines)
.before(UiSystem::Layout),
)
.add_systems(
Expand Down Expand Up @@ -109,10 +109,13 @@ fn get_top_pos(node: &Node, parent: &Node) -> f32 {

fn scroll_to_bottom_on_resize(
mut resize_reader: EventReader<WindowResized>,
containers_added: Query<(), Added<UiTerminal>>,
parents: Query<&Node>,
mut list: Query<(&mut Style, &Node, &Parent), With<UiTerminal>>,
) {
for _ev in resize_reader.read() {
let should_update =
resize_reader.read().count() > 0 || containers_added.iter().count() > 0;
if should_update {
for (mut style, node, parent) in list.iter_mut() {
if let Ok(parent) = parents.get(**parent) {
style.top = Val::Px(get_top_pos(node, parent));
Expand Down Expand Up @@ -155,13 +158,20 @@ fn show_new_sections(mut query: Query<&mut Text, Added<OutputItem>>) {

const INPUT_HEIGHT_PX: f32 = 50.;

fn handle_resize_event(
fn resize_output_container(
mut resize_reader: EventReader<WindowResized>,
window: Query<&Window>,
containers_added: Query<(), Added<OutputContainer>>,
mut containers: Query<&mut Style, With<OutputContainer>>,
) {
for ev in resize_reader.read() {
let should_update =
resize_reader.read().count() > 0 || containers_added.iter().count() > 0;
if should_update {
let Ok(window) = window.get_single() else {
return;
};
for mut style in containers.iter_mut() {
style.height = Val::Px(ev.height as f32 - INPUT_HEIGHT_PX);
style.height = Val::Px(window.height() - INPUT_HEIGHT_PX);
}
}
}
Expand Down Expand Up @@ -262,9 +272,13 @@ pub fn spawn_ui_terminal(mut commands: Commands, user_input: bool) {

fn parse_text_input(
mut evr_char: EventReader<KeyboardInput>,
keys: Res<ButtonInput<KeyCode>>,
mut on_submit: EventWriter<OnUserMessage>,
mut query: Query<&mut Text, With<InputContainer>>,
) {
if keys.any_pressed([KeyCode::ControlRight, KeyCode::ControlLeft]) {
return;
}
for ev in evr_char.read() {
if let ButtonState::Released = ev.state {
continue;
Expand Down
18 changes: 10 additions & 8 deletions crates/beet_examples/src/plugins/example_plugin_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ impl Plugin for ExampleMlPlugin {
// qtables (frozen lake)
AssetPlaceholderPlugin::<QTable<GridPos, GridDirection>>::default(),
ReadyOnAssetLoadPlugin::<QTable<GridPos, GridDirection>>::default(),
));
))
// fetch
.add_plugins(ActionPlugin::<(
InsertOnAssetEvent<RunResult, Bert>,
FindSentenceSteerTarget<Collectable>,
RemoveAgentOnRun<Sentence>,
RemoveAgentOnRun<SteerTarget>,
)>::default())
/*-*/;
}
}
pub struct ExampleBasePlugin;
Expand Down Expand Up @@ -133,12 +141,6 @@ impl Plugin for Example3dPlugin {
)
.register_type::<FollowCursor3d>()
.register_type::<CameraDistance>()
//fetch stuff
.add_plugins(ActionPlugin::<(
InsertOnAssetEvent<RunResult, Bert>,
FindSentenceSteerTarget<Collectable>,
RemoveAgentOnRun<Sentence>,
RemoveAgentOnRun<SteerTarget>,
)>::default());
/*-*/;
}
}
1 change: 0 additions & 1 deletion crates/beet_examples/src/scenes/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn fetch_npc(mut commands: Commands) {
parent
.spawn((
Name::new("Idle Or Fetch"),
TriggerOnRun(AppReady),
TargetAgent(agent),
ScoreSelector::default(),
// ScoreSelector::consuming(),
Expand Down
Loading

0 comments on commit 9da7e68

Please sign in to comment.