Skip to content

feat!: Update to Bevy 0.16 #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ assets/scripts/tlconfig.lua
**.log
**build/
.html
.idea/

/assets/**/*.lad.json
/docs/src/ladfiles/*.lad.json
/docs/src/ladfiles/*.lad.json
22 changes: 10 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting"
version = "0.12.0"
version = "0.13.0"
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -76,37 +76,35 @@ profile_with_tracy = ["bevy/trace_tracy"]
[dependencies]
bevy = { workspace = true }
bevy_mod_scripting_core = { workspace = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.12.0", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.12.0", optional = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.13.0", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.13.0", optional = true }
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
bevy_mod_scripting_functions = { workspace = true }
bevy_mod_scripting_derive = { workspace = true }

[workspace.dependencies]
profiling = { version = "1.0" }
bevy = { version = "0.15.3", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.12.0" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.12.0", default-features = false }
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.12.0" }
bevy = { version = "0.16.0", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.13.0" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.13.0", default-features = false }
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.13.0" }

# test utilities
script_integration_test_harness = { path = "crates/testing_crates/script_integration_test_harness" }
test_utils = { path = "crates/testing_crates/test_utils" }

[dev-dependencies]
bevy = { workspace = true, default-features = true }
bevy = { workspace = true, default-features = true, features = ["std"] }
clap = { version = "4.1", features = ["derive"] }
rand = "0.8.5"
bevy_console = "0.13"
# rhai-rand = "0.1"
rand = "0.9.1"
criterion = { version = "0.5" }
ansi-parser = "0.9"
ladfile_builder = { path = "crates/ladfile_builder", version = "0.3.2" }
script_integration_test_harness = { workspace = true }
test_utils = { workspace = true }
libtest-mimic = "0.8"
tracing-tracy = "0.11"
regex = "1.11"
bevy_console = { git = "https://github.com/Katsutoshii/bevy-console", branch = "bevy-0.16.0"}

[workspace]
members = [
Expand Down
39 changes: 24 additions & 15 deletions assets/tests/add_system/added_systems_run_in_parallel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,30 @@ function on_test()

local expected_dot_graph = [[
digraph {
node_0 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
node_1 [label="on_test_post_update"];
node_2 [label="script_integration_test_harness::dummy_before_post_update_system"];
node_3 [label="script_integration_test_harness::dummy_post_update_system"];
node_4 [label="custom_system_a"];
node_5 [label="custom_system_b"];
node_6 [label="SystemSet GarbageCollection"];
node_7 [label="SystemSet ScriptSystem(custom_system_a)"];
node_8 [label="SystemSet ScriptSystem(custom_system_b)"];
node_0 -> node_6 [color=red, label="child of", arrowhead=diamond];
node_4 -> node_7 [color=red, label="child of", arrowhead=diamond];
node_5 -> node_8 [color=red, label="child of", arrowhead=diamond];
node_1 -> node_4 [color=blue, label="runs before", arrowhead=normal];
node_1 -> node_5 [color=blue, label="runs before", arrowhead=normal];
node_2 -> node_3 [color=blue, label="runs before", arrowhead=normal];
node_0 [label="bevy_asset::assets::Assets<bevy_asset::folder::LoadedFolder>::asset_events"];
node_1 [label="bevy_asset::assets::Assets<bevy_asset::assets::LoadedUntypedAsset>::asset_events"];
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_core::asset::ScriptAsset>::asset_events"];
node_4 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
node_5 [label="on_test_post_update"];
node_6 [label="script_integration_test_harness::dummy_before_post_update_system"];
node_7 [label="script_integration_test_harness::dummy_post_update_system"];
node_8 [label="custom_system_a"];
node_9 [label="custom_system_b"];
node_10 [label="SystemSet AssetEvents"];
node_11 [label="SystemSet GarbageCollection"];
node_12 [label="SystemSet ScriptSystem(custom_system_a)"];
node_13 [label="SystemSet ScriptSystem(custom_system_b)"];
node_0 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_1 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_2 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_3 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_4 -> node_11 [color=red, label="child of", arrowhead=diamond];
node_8 -> node_12 [color=red, label="child of", arrowhead=diamond];
node_9 -> node_13 [color=red, label="child of", arrowhead=diamond];
node_5 -> node_8 [color=blue, label="runs before", arrowhead=normal];
node_5 -> node_9 [color=blue, label="runs before", arrowhead=normal];
node_6 -> node_7 [color=blue, label="runs before", arrowhead=normal];
}
]]

Expand Down
39 changes: 24 additions & 15 deletions assets/tests/add_system/added_systems_run_in_parallel.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,30 @@ fn on_test() {

let expected_dot_graph = `
digraph {
node_0 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
node_1 [label="on_test_post_update"];
node_2 [label="script_integration_test_harness::dummy_before_post_update_system"];
node_3 [label="script_integration_test_harness::dummy_post_update_system"];
node_4 [label="custom_system_a"];
node_5 [label="custom_system_b"];
node_6 [label="SystemSet GarbageCollection"];
node_7 [label="SystemSet ScriptSystem(custom_system_a)"];
node_8 [label="SystemSet ScriptSystem(custom_system_b)"];
node_0 -> node_6 [color=red, label="child of", arrowhead=diamond];
node_4 -> node_7 [color=red, label="child of", arrowhead=diamond];
node_5 -> node_8 [color=red, label="child of", arrowhead=diamond];
node_1 -> node_4 [color=blue, label="runs before", arrowhead=normal];
node_1 -> node_5 [color=blue, label="runs before", arrowhead=normal];
node_2 -> node_3 [color=blue, label="runs before", arrowhead=normal];
node_0 [label="bevy_asset::assets::Assets<bevy_asset::folder::LoadedFolder>::asset_events"];
node_1 [label="bevy_asset::assets::Assets<bevy_asset::assets::LoadedUntypedAsset>::asset_events"];
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_core::asset::ScriptAsset>::asset_events"];
node_4 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
node_5 [label="on_test_post_update"];
node_6 [label="script_integration_test_harness::dummy_before_post_update_system"];
node_7 [label="script_integration_test_harness::dummy_post_update_system"];
node_8 [label="custom_system_a"];
node_9 [label="custom_system_b"];
node_10 [label="SystemSet AssetEvents"];
node_11 [label="SystemSet GarbageCollection"];
node_12 [label="SystemSet ScriptSystem(custom_system_a)"];
node_13 [label="SystemSet ScriptSystem(custom_system_b)"];
node_0 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_1 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_2 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_3 -> node_10 [color=red, label="child of", arrowhead=diamond];
node_4 -> node_11 [color=red, label="child of", arrowhead=diamond];
node_8 -> node_12 [color=red, label="child of", arrowhead=diamond];
node_9 -> node_13 [color=red, label="child of", arrowhead=diamond];
node_5 -> node_8 [color=blue, label="runs before", arrowhead=normal];
node_5 -> node_9 [color=blue, label="runs before", arrowhead=normal];
node_6 -> node_7 [color=blue, label="runs before", arrowhead=normal];
}`;

assert_str_eq.call(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph");
Expand Down
29 changes: 15 additions & 14 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
use bevy::log::tracing_subscriber::layer::SubscriberExt;
use bevy::log::{tracing_subscriber, Level};
use bevy::reflect::Reflect;
use bevy::utils::tracing;
use bevy::utils::tracing::span;
extern crate bevy_mod_scripting;
extern crate script_integration_test_harness;
extern crate test_utils;
use std::{collections::HashMap, path::PathBuf, sync::LazyLock, time::Duration};

use bevy::{
log::{
tracing, tracing::span, tracing_subscriber, tracing_subscriber::layer::SubscriberExt, Level,
},
reflect::Reflect,
};
use bevy_mod_scripting_core::bindings::{
FromScript, IntoScript, Mut, Ref, ReflectReference, ScriptValue, Val,
};
use criterion::{criterion_main, measurement::Measurement, BenchmarkGroup, Criterion};
use criterion::{BatchSize, BenchmarkFilter};
use criterion::{
criterion_main, measurement::Measurement, BatchSize, BenchmarkFilter, BenchmarkGroup, Criterion,
};
use regex::Regex;
use script_integration_test_harness::test_functions::rand::Rng;
use script_integration_test_harness::{
make_test_lua_plugin, make_test_rhai_plugin, perform_benchmark_with_generator,
run_lua_benchmark, run_plugin_script_load_benchmark, run_rhai_benchmark,
test_functions::rand::Rng,
};
use std::collections::HashMap;
use std::{path::PathBuf, sync::LazyLock, time::Duration};
use test_utils::{discover_all_tests, Test};

extern crate bevy_mod_scripting;
extern crate script_integration_test_harness;
extern crate test_utils;

static ENABLE_PROFILING: LazyLock<bool> =
LazyLock::new(|| std::env::var("ENABLE_PROFILING").is_ok());

Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_api_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ log = "0.4"
env_logger = "0.11"
rustc_plugin = "0.12.0-nightly-2024-12-15"
indexmap = "2"
tempdir = "0.3"
cargo_metadata = "0.18"
serde_json = "1"
serde = "1"
Expand All @@ -52,7 +51,6 @@ include_dir = "0.7"
prettyplease = "0.2"
convert_case = "0.6"
syn = { version = "2", features = ["parsing"], no-default-features = true }
clap-verbosity-flag = "2.2"
itertools = "0.12"
chrono = "0.4"

Expand Down
12 changes: 4 additions & 8 deletions crates/bevy_mod_scripting_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_core"
version = "0.12.0"
version = "0.13.0"
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -29,19 +29,15 @@ mlua = { version = "0.10", default-features = false, optional = true }
rhai = { version = "1.21", default-features = false, features = [
"sync",
], optional = true }
bevy = { workspace = true, default-features = false, features = ["bevy_asset"] }
thiserror = "1.0.31"
bevy = { workspace = true, default-features = false, features = ["bevy_asset", "std"] }
parking_lot = "0.12.1"
dashmap = "6"
smallvec = "1.11"
itertools = "0.13"
derivative = "2.2"
itertools = "0.14"
profiling = { workspace = true }
bevy_mod_scripting_derive = { workspace = true }
fixedbitset = "0.5"
petgraph = "0.6"
bevy_mod_debugdump = "0.12"
bevy_system_reflection = { path = "../bevy_system_reflection", version = "0.1.1" }
variadics_please = "1.1.0"

[dev-dependencies]
test_utils = { workspace = true }
Expand Down
32 changes: 16 additions & 16 deletions crates/bevy_mod_scripting_core/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//! Systems and resources for handling script assets and events

use crate::{
commands::{CreateOrUpdateScript, DeleteScript},
error::ScriptError,
script::ScriptId,
IntoScriptPluginParams, ScriptingSystemSet,
};
use std::borrow::Cow;

use bevy::{
app::{App, PreUpdate},
asset::{Asset, AssetEvent, AssetId, AssetLoader, AssetPath, Assets},
ecs::system::Resource,
log::{debug, info, trace, warn},
platform::collections::HashMap,
prelude::{
Commands, Event, EventReader, EventWriter, IntoSystemConfigs, IntoSystemSetConfigs, Res,
ResMut,
Commands, Event, EventReader, EventWriter, IntoScheduleConfigs, Res, ResMut, Resource,
},
reflect::TypePath,
utils::hashbrown::HashMap,
};
use std::borrow::Cow;

use crate::{
commands::{CreateOrUpdateScript, DeleteScript},
error::ScriptError,
script::ScriptId,
IntoScriptPluginParams, ScriptingSystemSet,
};

/// Represents a scripting language. Languages which compile into another language should use the target language as their language.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
Expand Down Expand Up @@ -231,7 +231,7 @@ pub(crate) fn dispatch_script_asset_events(
language,
};
debug!("Script loaded, populating metadata: {:?}:", metadata);
script_asset_events.send(ScriptAssetEvent::Added(metadata.clone()));
script_asset_events.write(ScriptAssetEvent::Added(metadata.clone()));
metadata_store.insert(*id, metadata);
} else {
warn!("A script was added but it's asset was not found, failed to compute metadata. This script will not be loaded. Did you forget to store `Handle<ScriptAsset>` somewhere?. {}", id);
Expand All @@ -241,15 +241,15 @@ pub(crate) fn dispatch_script_asset_events(
AssetEvent::Removed { id } => {
if let Some(metadata) = metadata_store.get(*id) {
debug!("Script removed: {:?}", metadata);
script_asset_events.send(ScriptAssetEvent::Removed(metadata.clone()));
script_asset_events.write(ScriptAssetEvent::Removed(metadata.clone()));
} else {
warn!("Script metadata not found for removed script asset: {}. Cannot properly clean up script", id);
}
}
AssetEvent::Modified { id } => {
if let Some(metadata) = metadata_store.get(*id) {
debug!("Script modified: {:?}", metadata);
script_asset_events.send(ScriptAssetEvent::Modified(metadata.clone()));
script_asset_events.write(ScriptAssetEvent::Modified(metadata.clone()));
} else {
warn!("Script metadata not found for modified script asset: {}. Cannot properly update script", id);
}
Expand Down Expand Up @@ -572,9 +572,9 @@ mod tests {
struct DummyPlugin;

impl IntoScriptPluginParams for DummyPlugin {
type R = ();
type C = ();
const LANGUAGE: Language = Language::Lua;
type C = ();
type R = ();

fn build_runtime() -> Self::R {}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/src/bindings/access_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::hash::{BuildHasherDefault, Hasher};

use bevy::{
ecs::{component::ComponentId, world::unsafe_world_cell::UnsafeWorldCell},
platform::collections::{HashMap, HashSet},
prelude::Resource,
utils::hashbrown::{HashMap, HashSet},
};
use parking_lot::Mutex;
use smallvec::SmallVec;
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_mod_scripting_core/src/bindings/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! An allocator used to control the lifetime of allocations

use bevy::prelude::Resource;
use bevy::{
app::{App, Plugin, PostUpdate},
diagnostic::{Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic},
ecs::system::{Res, Resource},
ecs::system::Res,
platform::collections::HashMap,
prelude::ResMut,
reflect::PartialReflect,
utils::hashbrown::HashMap,
};
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,4 @@ macro_rules! impl_from_script_tuple {
};
}

bevy::utils::all_tuples!(impl_from_script_tuple, 1, 14, T);
variadics_please::all_tuples!(impl_from_script_tuple, 1, 14, T);
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ macro_rules! impl_into_script_tuple {
}
}

bevy::utils::all_tuples!(impl_into_script_tuple, 1, 14, T);
variadics_please::all_tuples!(impl_into_script_tuple, 1, 14, T);
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
error::InteropError,
ScriptValue,
};
use bevy::platform::collections::HashMap;
use bevy::prelude::{Reflect, Resource};
use bevy::utils::hashbrown::HashMap;
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::borrow::Cow;
use std::collections::VecDeque;
Expand Down Expand Up @@ -622,13 +622,13 @@ macro_rules! impl_script_function {
};
}

bevy::utils::all_tuples!(impl_script_function, 0, 13, T);
variadics_please::all_tuples!(impl_script_function, 0, 13, T);

#[cfg(test)]
mod test {
use super::*;
use super::*;

fn with_local_world<F: Fn()>(f: F) {
fn with_local_world<F: Fn()>(f: F) {
let mut world = bevy::prelude::World::default();
WorldGuard::with_static_guard(&mut world, |world| {
ThreadWorldContainer.set_world(world).unwrap();
Expand Down
Loading