Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "big-brain"
version = "0.22.0"
version = "0.23.0"
authors = ["Kat Marchán <[email protected]>"]
edition = "2021"
description = "Rusty Utility AI library"
Expand All @@ -15,11 +15,11 @@ homepage = "https://github.com/zkat/big-brain"
[workspace]

[dependencies]
bevy = { version = "0.15.0", default-features = false }
big-brain-derive = { version = "=0.22.0", path = "./derive" }
bevy = { version = "0.16.0", default-features = false, features = ["bevy_log"] }
big-brain-derive = { version = "=0.23.0", path = "./derive" }

[dev-dependencies]
bevy = { version = "0.15.0", default-features = true }
bevy = { version = "0.16.0", default-features = true }
rand = { version = "0.8.5", features = ["small_rng"] }

[features]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn main() {

#### bevy version and MSRV

The current version of `big-brain` is compatible with `bevy` 0.15.0.
The current version of `big-brain` is compatible with `bevy` 0.16.0.

The Minimum Supported Rust Version for `big-brain` should be considered to
be the same as `bevy`'s, which as of the time of this writing was "the
Expand Down
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "big-brain-derive"
version = "0.22.0"
version = "0.23.0"
authors = ["Kat Marchán <[email protected]>"]
description = "Procedural macros to simplify implementation of Big Brain traits"
documentation = "https://docs.rs/big-brain-derive"
Expand Down
1 change: 0 additions & 1 deletion examples/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy::utils::tracing::debug;
use big_brain::prelude::*;
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_measure.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! This example demonstrates how to build a custom measure and use that
//! in a Thinker.

use bevy::ecs::component::Mutable;
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy::utils::tracing::debug;
use big_brain::prelude::*;
use big_brain::scorers::MeasuredScorer;

Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct EatWaffles;

fn eat_thing_action<
TActionMarker: std::fmt::Debug + Component,
TActorMarker: Component + EatFood,
TActorMarker: Component<Mutability = Mutable> + EatFood,
>(
time: Res<Time>,
mut items: Query<&mut TActorMarker>,
Expand Down
1 change: 1 addition & 0 deletions examples/farming_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ fn init_entities(
commands.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 700.0,
..default()
});

commands.spawn((
Expand Down
1 change: 0 additions & 1 deletion examples/one_off.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy::utils::tracing::{debug, trace};
use big_brain::prelude::*;

#[derive(Clone, Component, Debug, ActionBuilder)]
Expand Down
1 change: 0 additions & 1 deletion examples/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy::utils::tracing::{debug, trace};
use big_brain::prelude::*;

/// First, we make a simple Position component.
Expand Down
1 change: 0 additions & 1 deletion examples/thirst.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy::utils::tracing::{debug, trace};
use big_brain::prelude::*;

// First, we define a "Thirst" component and associated system. This is NOT
Expand Down
14 changes: 6 additions & 8 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
use std::sync::Arc;

use bevy::prelude::*;
#[cfg(feature = "trace")]
use bevy::utils::tracing::trace;

use crate::thinker::{Action, ActionSpan, Actor};

Expand Down Expand Up @@ -287,8 +285,8 @@ pub fn steps_system(
let step_state = step_state.clone();
let mut seq_state = states.get_mut(seq_ent).expect("idk");
*seq_state = step_state;
if let Some(ent) = cmd.get_entity(steps_action.active_ent.entity()) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(steps_action.active_ent.entity()) {
ent.despawn();
}
}
Success if steps_action.active_step == steps_action.steps.len() - 1 => {
Expand All @@ -298,16 +296,16 @@ pub fn steps_system(
let step_state = step_state.clone();
let mut seq_state = states.get_mut(seq_ent).expect("idk");
*seq_state = step_state;
if let Some(ent) = cmd.get_entity(steps_action.active_ent.entity()) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(steps_action.active_ent.entity()) {
ent.despawn();
}
}
Success => {
#[cfg(feature = "trace")]
trace!("Step succeeded, but there's more steps. Spawning next action.");
// Deactivate current step and go to the next step
if let Some(ent) = cmd.get_entity(steps_action.active_ent.entity()) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(steps_action.active_ent.entity()) {
ent.despawn();
}

steps_action.active_step += 1;
Expand Down
2 changes: 0 additions & 2 deletions src/scorers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use std::{cmp::Ordering, sync::Arc};

use bevy::prelude::*;
#[cfg(feature = "trace")]
use bevy::utils::tracing::trace;

use crate::{
evaluators::Evaluator,
Expand Down
37 changes: 19 additions & 18 deletions src/thinker.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
//! Thinkers are the "brain" of an entity. You attach Scorers to it, and the
//! Thinker picks the right Action to run based on the resulting Scores.

use std::{collections::VecDeque, sync::Arc};
use std::{
collections::VecDeque,
sync::Arc,
time::{Duration, Instant},
};

use bevy::{
prelude::*,
utils::{
tracing::{debug, field, span, Level, Span},
Duration, Instant,
log::{
tracing::{field, span, Span},
Level,
},
prelude::*,
};

#[cfg(feature = "trace")]
use bevy::utils::tracing::trace;

use crate::{
actions::{self, ActionBuilder, ActionBuilderWrapper, ActionState},
choices::{Choice, ChoiceBuilder},
Expand Down Expand Up @@ -263,8 +264,8 @@ pub fn thinker_component_detach_system(
q: Query<(Entity, &HasThinker), Without<ThinkerBuilder>>,
) {
for (actor, HasThinker(thinker)) in q.iter() {
if let Some(ent) = cmd.get_entity(*thinker) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(*thinker) {
ent.despawn();
}
cmd.entity(actor).remove::<HasThinker>();
}
Expand All @@ -278,8 +279,8 @@ pub fn actor_gone_cleanup(
for (child, Actor(actor)) in q.iter() {
if actors.get(*actor).is_err() {
// Actor is gone. Let's clean up.
if let Some(ent) = cmd.get_entity(child) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(child) {
ent.despawn();
}
}
}
Expand Down Expand Up @@ -354,8 +355,8 @@ pub fn thinker_system(
match state {
ActionState::Success | ActionState::Failure => {
debug!("Action already wrapped up on its own. Cleaning up action in Thinker.");
if let Some(ent) = cmd.get_entity(current.0 .0) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(current.0 .0) {
ent.despawn();
}
thinker.current_action = None;
}
Expand Down Expand Up @@ -436,8 +437,8 @@ pub fn thinker_system(
"Action completed and nothing was picked. Despawning action entity.",
);
// Despawn the action itself.
if let Some(ent) = cmd.get_entity(action_ent.0) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(action_ent.0) {
ent.despawn();
}
thinker.current_action = None;
} else if *curr_action_state == ActionState::Init {
Expand Down Expand Up @@ -544,8 +545,8 @@ fn exec_picked_action(
ActionState::Init | ActionState::Success | ActionState::Failure => {
debug!("Previous action already completed. Despawning action entity.",);
// Despawn the action itself.
if let Some(ent) = cmd.get_entity(action_ent.0) {
ent.despawn_recursive();
if let Ok(mut ent) = cmd.get_entity(action_ent.0) {
ent.despawn();
}
if let Some((Scorer(ent), score)) = scorer_info {
let scorer_span = scorer_spans.get(*ent).expect("Where is it?");
Expand Down
2 changes: 1 addition & 1 deletion tests/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn exit_action(
*state = ActionState::Executing;
}
if *state == ActionState::Executing {
app_exit_events.send(AppExit::Success);
app_exit_events.write(AppExit::Success);
}
}
}
Expand Down