diff --git a/.gitignore b/.gitignore index f8a150654c..b8efa21749 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ assets/scripts/tlconfig.lua **.log **build/ .html +.idea/ /assets/**/*.lad.json -/docs/src/ladfiles/*.lad.json \ No newline at end of file +/docs/src/ladfiles/*.lad.json diff --git a/Cargo.toml b/Cargo.toml index b5a0fe4c7d..97cba286e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting" -version = "0.12.0" +version = "0.13.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT OR Apache-2.0" @@ -76,37 +76,38 @@ 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_math = { version = "0.16.0", default-features = false } +bevy_reflect = { version = "0.16.0", default-features = false } +bevy_input = { version = "0.16.0", default-features = false } +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/RichoDemus/bevy-console" } [workspace] members = [ diff --git a/assets/tests/add_system/added_systems_run_in_parallel.lua b/assets/tests/add_system/added_systems_run_in_parallel.lua index 2adf8104d0..bd7951c729 100644 --- a/assets/tests/add_system/added_systems_run_in_parallel.lua +++ b/assets/tests/add_system/added_systems_run_in_parallel.lua @@ -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::asset_events"]; + node_1 [label="bevy_asset::assets::Assets::asset_events"]; + node_2 [label="bevy_asset::assets::Assets<()>::asset_events"]; + node_3 [label="bevy_asset::assets::Assets::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]; } ]] diff --git a/assets/tests/add_system/added_systems_run_in_parallel.rhai b/assets/tests/add_system/added_systems_run_in_parallel.rhai index 4ab2ddc17a..b49d41b9b3 100644 --- a/assets/tests/add_system/added_systems_run_in_parallel.rhai +++ b/assets/tests/add_system/added_systems_run_in_parallel.rhai @@ -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::asset_events"]; + node_1 [label="bevy_asset::assets::Assets::asset_events"]; + node_2 [label="bevy_asset::assets::Assets<()>::asset_events"]; + node_3 [label="bevy_asset::assets::Assets::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"); diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index c69109c5e5..2a7c599756 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -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 = LazyLock::new(|| std::env::var("ENABLE_PROFILING").is_ok()); diff --git a/crates/bevy_api_gen/Cargo.toml b/crates/bevy_api_gen/Cargo.toml index 5773d66271..e84c96e17d 100644 --- a/crates/bevy_api_gen/Cargo.toml +++ b/crates/bevy_api_gen/Cargo.toml @@ -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" @@ -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" diff --git a/crates/bevy_mod_scripting_core/Cargo.toml b/crates/bevy_mod_scripting_core/Cargo.toml index b94c1a88a3..5ce556108b 100644 --- a/crates/bevy_mod_scripting_core/Cargo.toml +++ b/crates/bevy_mod_scripting_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_core" -version = "0.12.0" +version = "0.13.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT OR Apache-2.0" @@ -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 } diff --git a/crates/bevy_mod_scripting_core/src/asset.rs b/crates/bevy_mod_scripting_core/src/asset.rs index c077ce82e6..226ec7331a 100644 --- a/crates/bevy_mod_scripting_core/src/asset.rs +++ b/crates/bevy_mod_scripting_core/src/asset.rs @@ -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)] @@ -239,7 +239,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` somewhere?. {}", id); @@ -249,7 +249,7 @@ 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); } @@ -257,7 +257,7 @@ pub(crate) fn dispatch_script_asset_events( 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); } @@ -580,9 +580,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 {} } diff --git a/crates/bevy_mod_scripting_core/src/bindings/access_map.rs b/crates/bevy_mod_scripting_core/src/bindings/access_map.rs index cf91e5bced..d4a290fab0 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/access_map.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/access_map.rs @@ -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; diff --git a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs index c37acdb943..9feb3c2454 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs @@ -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::{ diff --git a/crates/bevy_mod_scripting_core/src/bindings/function/from.rs b/crates/bevy_mod_scripting_core/src/bindings/function/from.rs index 0852840708..c07b25921c 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/function/from.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/function/from.rs @@ -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); diff --git a/crates/bevy_mod_scripting_core/src/bindings/function/into.rs b/crates/bevy_mod_scripting_core/src/bindings/function/into.rs index fd1fb88e9b..fd48053c1e 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/function/into.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/function/into.rs @@ -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); diff --git a/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs b/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs index 0b255995dd..2ac70799f0 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs @@ -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; @@ -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: F) { + fn with_local_world(f: F) { let mut world = bevy::prelude::World::default(); WorldGuard::with_static_guard(&mut world, |world| { ThreadWorldContainer.set_world(world).unwrap(); diff --git a/crates/bevy_mod_scripting_core/src/bindings/function/type_dependencies.rs b/crates/bevy_mod_scripting_core/src/bindings/function/type_dependencies.rs index 0bc1bf0a3f..e02dc601af 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/function/type_dependencies.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/function/type_dependencies.rs @@ -1,11 +1,11 @@ //! This module contains the [`GetTypeDependencies`] trait and its implementations for various types. use super::{ - from::{Mut, Ref, Union, Val}, - script_function::FunctionCallContext, DynamicScriptFunction, DynamicScriptFunctionMut, + from::{Mut, Ref, Union, Val}, + script_function::FunctionCallContext, DynamicScriptFunction, DynamicScriptFunctionMut, }; use crate::{ - bindings::{ReflectReference, ScriptValue}, error::InteropError} + bindings::{ReflectReference, ScriptValue}, error::InteropError} ; use bevy::reflect::{FromReflect, GetTypeRegistration, TypeRegistry, Typed}; use bevy_mod_scripting_derive::impl_get_type_dependencies; @@ -156,7 +156,7 @@ macro_rules! register_tuple_dependencies { } -bevy::utils::all_tuples!(register_tuple_dependencies, 1, 14, T); +variadics_please::all_tuples!(register_tuple_dependencies, 1, 14, T); /// A trait collecting type dependency information for a whole function. Used to register everything used by a function with the type registry pub trait GetFunctionTypeDependencies { @@ -184,4 +184,4 @@ macro_rules! impl_script_function_type_dependencies{ }; } -bevy::utils::all_tuples!(impl_script_function_type_dependencies, 0, 13, T); +variadics_please::all_tuples!(impl_script_function_type_dependencies, 0, 13, T); diff --git a/crates/bevy_mod_scripting_core/src/bindings/globals/mod.rs b/crates/bevy_mod_scripting_core/src/bindings/globals/mod.rs index 42f4d2de80..49e329e5ba 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/globals/mod.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/globals/mod.rs @@ -1,15 +1,15 @@ //! Contains abstractions for exposing "globals" to scripts, in a language-agnostic way. use super::{ - function::arg_meta::{ScriptReturn, TypedScriptReturn}, - script_value::ScriptValue, - WorldGuard, + function::arg_meta::{ScriptReturn, TypedScriptReturn}, + script_value::ScriptValue, + WorldGuard, }; use crate::{ - docgen::{into_through_type_info, typed_through::ThroughTypeInfo}, - error::InteropError, + docgen::{into_through_type_info, typed_through::ThroughTypeInfo}, + error::InteropError, }; -use bevy::{ecs::system::Resource, reflect::Typed, utils::hashbrown::HashMap}; +use bevy::{platform::collections::HashMap, prelude::Resource, reflect::Typed}; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::{any::TypeId, borrow::Cow, sync::Arc}; @@ -235,11 +235,11 @@ impl ScriptGlobalsRegistry { #[cfg(test)] mod test { - use bevy::ecs::world::World; + use bevy::ecs::world::World; - use super::*; + use super::*; - #[test] + #[test] fn test_script_globals_registry() { let mut registry = ScriptGlobalsRegistry::default(); diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index 9df1e2fbdc..d573154d7b 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -6,19 +6,19 @@ //! we need wrapper types which have owned and ref variants. use super::{access_map::ReflectAccessId, WorldGuard}; use crate::{ - bindings::{with_access_read, with_access_write, ReflectAllocationId}, - error::InteropError, - reflection_extensions::{PartialReflectExt, TypeIdExtensions}, - ReflectAllocator, + bindings::{with_access_read, with_access_write, ReflectAllocationId}, + error::InteropError, + reflection_extensions::{PartialReflectExt, TypeIdExtensions}, + ReflectAllocator, }; use bevy::{ - ecs::{ - change_detection::MutUntyped, component::ComponentId, entity::Entity, - world::unsafe_world_cell::UnsafeWorldCell, - }, - prelude::{Component, ReflectDefault, Resource}, - ptr::Ptr, - reflect::{ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath}, + ecs::{ + change_detection::MutUntyped, component::ComponentId, entity::Entity, + world::unsafe_world_cell::UnsafeWorldCell, + }, + prelude::{Component, ReflectDefault, Resource}, + ptr::Ptr, + reflect::{ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath}, }; use std::{any::TypeId, fmt::Debug}; @@ -214,7 +214,7 @@ impl ReflectReference { self.with_reflect(world.clone(), |r| { ::from_reflect_or_clone(r, world.clone()) - }) + })? } /// The way to access the value of the reference, that is the pointed-to value. @@ -503,7 +503,11 @@ impl ReflectBase { match self { ReflectBase::Component(entity, component_id) => { // Safety: the caller ensures invariants hold - world.get_entity(entity)?.get_by_id(component_id) + if let Ok(entity) = world.get_entity(entity) { + entity.get_by_id(component_id) + } else { + None + } } ReflectBase::Resource(component_id) => { // Safety: the caller ensures invariants hold @@ -522,7 +526,11 @@ impl ReflectBase { match self { ReflectBase::Component(entity, component_id) => { // Safety: the caller ensures invariants hold - world.get_entity(entity)?.get_mut_by_id(component_id) + if let Ok(entity) = world.get_entity(entity) { + entity.get_mut_by_id(component_id).ok() + } else { + None + } } ReflectBase::Resource(component_id) => { // Safety: the caller ensures invariants hold @@ -638,15 +646,15 @@ impl Iterator for ReflectRefIter { #[cfg(test)] mod test { - use bevy::prelude::{AppTypeRegistry, World}; + use bevy::prelude::{AppTypeRegistry, World}; - use crate::bindings::{ - function::script_function::AppScriptFunctionRegistry, AppReflectAllocator, - }; + use crate::bindings::{ + function::script_function::AppScriptFunctionRegistry, AppReflectAllocator, + }; - use super::*; + use super::*; - #[derive(Reflect, Component, Debug, Clone, PartialEq)] + #[derive(Reflect, Component, Debug, Clone, PartialEq)] struct Component(Vec); #[derive(Reflect, Resource, Debug, Clone, PartialEq)] diff --git a/crates/bevy_mod_scripting_core/src/bindings/schedule.rs b/crates/bevy_mod_scripting_core/src/bindings/schedule.rs index 4e04dbdc78..25d66e2405 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/schedule.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/schedule.rs @@ -3,15 +3,15 @@ use super::{script_system::ScriptSystemBuilder, WorldAccessGuard}; use crate::{error::InteropError, IntoScriptPluginParams}; use bevy::{ - app::{ - First, FixedFirst, FixedLast, FixedMain, FixedPostUpdate, FixedPreUpdate, FixedUpdate, - Last, PostStartup, PostUpdate, PreStartup, PreUpdate, RunFixedMainLoop, Startup, Update, - }, - ecs::{ - schedule::{Schedule, ScheduleLabel, Schedules}, - system::Resource, - world::World, - }, + app::{ + First, FixedFirst, FixedLast, FixedMain, FixedPostUpdate, FixedPreUpdate, FixedUpdate, + Last, PostStartup, PostUpdate, PreStartup, PreUpdate, RunFixedMainLoop, Startup, Update, + }, + ecs::{ + schedule::{Schedule, ScheduleLabel, Schedules}, + world::World, + }, + prelude::Resource, }; use bevy_system_reflection::{ReflectSchedule, ReflectSystem}; use parking_lot::RwLock; @@ -191,19 +191,18 @@ impl WorldAccessGuard<'_> { reason = "tests are there but not working currently" )] mod tests { - - use bevy::{ - app::{App, Update}, - ecs::{ - schedule::{NodeId, Schedules}, - system::IntoSystem, - }, - }; - use test_utils::make_test_plugin; - - use super::*; - - #[test] + use bevy::{ + app::Update, + ecs::{ + schedule::{NodeId, Schedules}, + system::IntoSystem, + }, + }; + use test_utils::make_test_plugin; + + use super::*; + + #[test] fn test_schedule_registry() { let mut registry = ScheduleRegistry::default(); registry.register(Update); @@ -342,7 +341,7 @@ mod tests { // Collect all edges as (from, to) name pairs. let mut found_edges = Vec::new(); - for (from, to, _) in graph.dependency().graph().all_edges() { + for (from, to) in graph.dependency().graph().all_edges() { let name_from = resolve_name(from); let name_to = resolve_name(to); found_edges.push((name_from, name_to)); diff --git a/crates/bevy_mod_scripting_core/src/bindings/script_component.rs b/crates/bevy_mod_scripting_core/src/bindings/script_component.rs index 74243b29a3..b1a0c650f0 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/script_component.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/script_component.rs @@ -3,13 +3,11 @@ use super::{ScriptComponentRegistration, ScriptTypeRegistration, ScriptValue, WorldAccessGuard}; use crate::error::InteropError; use bevy::{ - app::{App, Plugin}, - ecs::{ - component::{Component, ComponentDescriptor, StorageType}, - system::Resource, - }, - reflect::{prelude::ReflectDefault, GetTypeRegistration, Reflect}, - utils::HashMap, + app::{App, Plugin}, + ecs::component::{Component, ComponentDescriptor, StorageType, ComponentCloneBehavior, Mutable}, + platform::collections::HashMap, + prelude::Resource, + reflect::{prelude::ReflectDefault, GetTypeRegistration, Reflect}, }; use parking_lot::RwLock; use std::{alloc::Layout, mem::needs_drop, sync::Arc}; @@ -31,6 +29,7 @@ pub struct DynamicComponentInfo { impl Component for DynamicComponent { const STORAGE_TYPE: StorageType = StorageType::Table; + type Mutability = Mutable; } /// A registry of dynamically registered script components @@ -96,6 +95,8 @@ impl WorldAccessGuard<'_> { DynamicComponent::STORAGE_TYPE, Layout::new::(), needs_drop::().then_some(|x| x.drop_as::()), + true, + ComponentCloneBehavior::Default, ) }; w.register_component_with_descriptor(descriptor) @@ -135,10 +136,10 @@ impl Plugin for DynamicScriptComponentPlugin { #[cfg(test)] mod test { - use super::*; - use bevy::ecs::world::World; + use super::*; + use bevy::ecs::world::World; - #[test] + #[test] fn test_script_component() { let mut world = World::new(); let registration = { diff --git a/crates/bevy_mod_scripting_core/src/bindings/script_system.rs b/crates/bevy_mod_scripting_core/src/bindings/script_system.rs index ab840e9593..5ccc3c0a56 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/script_system.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/script_system.rs @@ -27,15 +27,19 @@ use bevy::{ entity::Entity, query::{Access, FilteredAccess, FilteredAccessSet, QueryState}, reflect::AppTypeRegistry, - schedule::{IntoSystemConfigs, SystemSet}, - system::{IntoSystem, System}, + schedule::{ + SystemSet, Infallible + }, + system::{IntoSystem, System, SystemParamValidationError}, world::{unsafe_world_cell::UnsafeWorldCell, World}, }, + platform::collections::HashSet, + prelude::{BevyError, IntoScheduleConfigs}, reflect::{OffsetAccess, ParsedPath, Reflect}, - utils::hashbrown::HashSet, }; use bevy_system_reflection::{ReflectSchedule, ReflectSystem}; use std::{any::TypeId, borrow::Cow, hash::Hash, marker::PhantomData, ops::Deref}; + #[derive(Clone, Hash, PartialEq, Eq)] /// a system set for script systems. pub struct ScriptSystemSet(Cow<'static, str>); @@ -160,7 +164,7 @@ impl ScriptSystemBuilder { // this is quite important, by default systems are placed in a set defined by their TYPE, i.e. in this case // all script systems would be the same // let set = ScriptSystemSet::next(); - let mut system_config = IntoSystemConfigs::>::into_configs(self); // apply ordering + let mut system_config = > + 'static)>, (Infallible, IsDynamicScriptSystem

)>>::into_configs(self); // apply ordering for (other, is_before) in before_systems .into_iter() .map(|b| (b, true)) @@ -170,7 +174,8 @@ impl ScriptSystemBuilder { if is_before { bevy::log::info!("before {default_set:?}"); system_config = system_config.before(*default_set); - } else { bevy::log::info!("before {default_set:?}"); + } else { + bevy::log::info!("before {default_set:?}"); bevy::log::info!("after {default_set:?}"); system_config = system_config.after(*default_set); } @@ -642,9 +647,9 @@ impl System for DynamicScriptSystem

{ unsafe fn validate_param_unsafe( &mut self, - _world: bevy::ecs::world::unsafe_world_cell::UnsafeWorldCell, - ) -> bool { - true + _world: UnsafeWorldCell, + ) -> Result<(), SystemParamValidationError> { + Ok(()) } fn default_system_sets(&self) -> Vec { @@ -655,7 +660,7 @@ impl System for DynamicScriptSystem

{ TypeId::of::() } - fn validate_param(&mut self, world: &World) -> bool { + fn validate_param(&mut self, world: &World) -> Result<(), SystemParamValidationError> { let world_cell = world.as_unsafe_world_cell_readonly(); self.update_archetype_component_access(world_cell); // SAFETY: diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index c88dc84f61..7c061d2d19 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -29,16 +29,18 @@ use crate::{ error::InteropError, reflection_extensions::PartialReflectExt, }; +use bevy::ecs::component::Mutable; +use bevy::prelude::{ChildOf, Children}; use bevy::{ app::AppExit, ecs::{ component::{Component, ComponentId}, entity::Entity, + prelude::Resource, reflect::{AppTypeRegistry, ReflectFromWorld, ReflectResource}, - system::{Commands, Resource}, + system::Commands, world::{unsafe_world_cell::UnsafeWorldCell, CommandQueue, Mut, World}, }, - hierarchy::{BuildChildren, Children, DespawnRecursiveExt, Parent}, reflect::{ std_traits::ReflectDefault, DynamicEnum, DynamicStruct, DynamicTuple, DynamicTupleStruct, DynamicVariant, ParsedPath, PartialReflect, TypeRegistryArc, @@ -446,7 +448,7 @@ impl<'w> WorldAccessGuard<'w> { format!("Could not access component: {}", std::any::type_name::()), { // Safety: we have acquired access for the duration of the closure - f(unsafe { cell.get_entity(entity).and_then(|e| e.get::()) }) + f(unsafe { cell.get_entity(entity).map(|e| e.get::()) }.ok().unwrap_or(None)) } ) } @@ -454,7 +456,7 @@ impl<'w> WorldAccessGuard<'w> { /// Safely accesses the component by claiming and releasing access to it. pub fn with_component_mut(&self, entity: Entity, f: F) -> Result where - T: Component, + T: Component, F: FnOnce(Option>) -> O, { let cell = self.as_unsafe_world_cell()?; @@ -466,7 +468,7 @@ impl<'w> WorldAccessGuard<'w> { format!("Could not access component: {}", std::any::type_name::()), { // Safety: we have acquired access for the duration of the closure - f(unsafe { cell.get_entity(entity).and_then(|e| e.get_mut::()) }) + f(unsafe { cell.get_entity(entity).map(|e| e.get_mut::()) }.ok().unwrap_or(None)) } ) } @@ -478,7 +480,7 @@ impl<'w> WorldAccessGuard<'w> { f: F, ) -> Result where - T: Component + Default, + T: Component + Default, F: FnOnce(&mut T) -> O, { self.with_global_access(|world| match world.get_mut::(entity) { @@ -536,7 +538,7 @@ impl<'w> WorldAccessGuard<'w> { /// checks if a given entity exists and is valid pub fn is_valid_entity(&self, entity: Entity) -> Result { let cell = self.as_unsafe_world_cell()?; - Ok(cell.get_entity(entity).is_some() && entity.index() != 0) + Ok(cell.get_entity(entity).is_ok() && entity.index() != 0) } /// Tries to call a fitting overload of the function with the given name and in the type id's namespace based on the arguments provided. @@ -816,10 +818,10 @@ impl WorldAccessGuard<'_> { // try to construct type from reflect // TODO: it would be nice to have a ::from_reflect_with_fallback equivalent, that does exactly that // only using this as it's already there and convenient, the clone variant hitting will be confusing to end users - Ok(::from_reflect_or_clone( + ::from_reflect_or_clone( dynamic.as_ref(), self.clone(), - )) + ) } /// Spawns a new entity in the world @@ -989,7 +991,7 @@ impl WorldAccessGuard<'_> { let cell = self.as_unsafe_world_cell()?; let entity = cell .get_entity(entity) - .ok_or_else(|| InteropError::missing_entity(entity))?; + .map_err(|_| InteropError::missing_entity(entity))?; if entity.contains_id(component_registration.component_id) { Ok(Some(ReflectReference { @@ -1016,7 +1018,7 @@ impl WorldAccessGuard<'_> { let cell = self.as_unsafe_world_cell()?; let entity = cell .get_entity(entity) - .ok_or_else(|| InteropError::missing_entity(entity))?; + .map_err(|_| InteropError::missing_entity(entity))?; Ok(entity.contains_id(component_id)) } @@ -1111,7 +1113,7 @@ impl WorldAccessGuard<'_> { return Err(InteropError::missing_entity(entity)); } - self.with_component(entity, |c: Option<&Parent>| c.map(|c| c.get())) + self.with_component(entity, |c: Option<&ChildOf>| c.map(|c| c.parent())) } /// insert children into the given entity @@ -1185,7 +1187,7 @@ impl WorldAccessGuard<'_> { self.with_global_access(|world| { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); - commands.entity(parent).despawn_recursive(); + commands.entity(parent).despawn(); queue.apply(world); }) } @@ -1199,7 +1201,7 @@ impl WorldAccessGuard<'_> { self.with_global_access(|world| { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); - commands.entity(entity).despawn(); + commands.entity(entity).remove::().despawn(); queue.apply(world); }) } @@ -1213,7 +1215,7 @@ impl WorldAccessGuard<'_> { self.with_global_access(|world| { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); - commands.entity(parent).despawn_descendants(); + commands.entity(parent).despawn_related::(); queue.apply(world); }) } diff --git a/crates/bevy_mod_scripting_core/src/context.rs b/crates/bevy_mod_scripting_core/src/context.rs index dec993f7be..6d8fe65f6f 100644 --- a/crates/bevy_mod_scripting_core/src/context.rs +++ b/crates/bevy_mod_scripting_core/src/context.rs @@ -6,7 +6,10 @@ use crate::{ script::ScriptId, IntoScriptPluginParams, }; -use bevy::ecs::{entity::Entity, system::Resource}; +use bevy::{ + ecs::entity::Entity, + prelude::Resource +}; /// A trait that all script contexts must implement. /// diff --git a/crates/bevy_mod_scripting_core/src/docgen/info.rs b/crates/bevy_mod_scripting_core/src/docgen/info.rs index b6a9ce5ae1..949286c0d3 100644 --- a/crates/bevy_mod_scripting_core/src/docgen/info.rs +++ b/crates/bevy_mod_scripting_core/src/docgen/info.rs @@ -191,18 +191,18 @@ macro_rules! impl_documentable { }; } -bevy::utils::all_tuples!(impl_documentable, 0, 13, T); +variadics_please::all_tuples!(impl_documentable, 0, 13, T); #[cfg(test)] mod test { - use crate::{ - bindings::function::from::{Mut, Ref, Val}, - docgen::typed_through::UntypedWrapperKind, - }; + use crate::{ + bindings::function::from::{Mut, Ref, Val}, + docgen::typed_through::UntypedWrapperKind, + }; - use super::*; + use super::*; - #[test] + #[test] fn test_get_function_info() { fn test_fn(a: i32, b: f32) -> f64 { (a as f64) + (b as f64) diff --git a/crates/bevy_mod_scripting_core/src/docgen/typed_through.rs b/crates/bevy_mod_scripting_core/src/docgen/typed_through.rs index 7e467b6180..694711af35 100644 --- a/crates/bevy_mod_scripting_core/src/docgen/typed_through.rs +++ b/crates/bevy_mod_scripting_core/src/docgen/typed_through.rs @@ -6,18 +6,18 @@ use std::{ffi::OsString, path::PathBuf}; use bevy::reflect::{TypeInfo, Typed}; use crate::{ - bindings::{ - function::{ - from::{Mut, Ref, Union, Val}, - script_function::{ - DynamicScriptFunction, DynamicScriptFunctionMut, FunctionCallContext, - }, - }, - script_value::ScriptValue, - ReflectReference, - }, - error::InteropError, - reflection_extensions::TypeInfoExtensions, + bindings::{ + function::{ + from::{Mut, Ref, Union, Val}, + script_function::{ + DynamicScriptFunction, DynamicScriptFunctionMut, FunctionCallContext, + }, + }, + script_value::ScriptValue, + ReflectReference, + }, + error::InteropError, + reflection_extensions::TypeInfoExtensions, }; /// All Through types follow one rule: @@ -265,13 +265,13 @@ macro_rules! impl_through_typed_tuple { }; } -bevy::utils::all_tuples!(impl_through_typed_tuple, 0, 13, T); +variadics_please::all_tuples!(impl_through_typed_tuple, 0, 13, T); #[cfg(test)] mod test { - use super::*; + use super::*; - fn assert_type_info_is_through() { + fn assert_type_info_is_through() { let type_info = T::type_info(); let through_type_info = T::through_type_info(); diff --git a/crates/bevy_mod_scripting_core/src/extractors.rs b/crates/bevy_mod_scripting_core/src/extractors.rs index d105cca7b5..5b1f0c9d12 100644 --- a/crates/bevy_mod_scripting_core/src/extractors.rs +++ b/crates/bevy_mod_scripting_core/src/extractors.rs @@ -4,14 +4,17 @@ #![allow(deprecated)] use std::ops::{Deref, DerefMut}; -use bevy::ecs::{ - component::ComponentId, - entity::Entity, - event::{Event, EventCursor, EventIterator, Events}, - query::{Access, AccessConflicts}, - storage::SparseSetIndex, - system::{Local, Resource, SystemParam, SystemState}, - world::World, +use bevy::{ + ecs::{ + component::ComponentId, + entity::Entity, + event::{Event, EventCursor, EventIterator, Events}, + query::{Access, AccessConflicts}, + storage::SparseSetIndex, + system::{Local, SystemParam, SystemState, SystemParamValidationError}, + world::World, + }, + prelude::Resource }; use fixedbitset::FixedBitSet; @@ -365,7 +368,7 @@ unsafe impl SystemParam for WithWorldGuard<'_, '_, T> { state: &Self::State, system_meta: &bevy::ecs::system::SystemMeta, world: bevy::ecs::world::unsafe_world_cell::UnsafeWorldCell, - ) -> bool { + ) -> Result<(), SystemParamValidationError> { T::validate_param(&state.0, system_meta, world) } } @@ -417,9 +420,10 @@ mod test { ecs::{ component::Component, event::{Event, EventReader}, - system::{Query, ResMut, Resource}, + system::{Query, ResMut}, world::FromWorld, }, + prelude::Resource, }; use test_utils::make_test_plugin; diff --git a/crates/bevy_mod_scripting_core/src/handler.rs b/crates/bevy_mod_scripting_core/src/handler.rs index 34f259c4c7..f3ff397c66 100644 --- a/crates/bevy_mod_scripting_core/src/handler.rs +++ b/crates/bevy_mod_scripting_core/src/handler.rs @@ -18,11 +18,11 @@ use bevy::{ ecs::{ entity::Entity, query::QueryState, - system::{Local, Resource, SystemState}, + system::{Local, SystemState}, world::{Mut, World}, }, log::trace_once, - prelude::{Events, Ref}, + prelude::{Events, Ref, Resource}, }; /// A function that handles a callback event diff --git a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs index e923c33b3f..1ff32fb425 100644 --- a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs +++ b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs @@ -4,11 +4,14 @@ use crate::{ bindings::{ReflectReference, WorldGuard}, error::InteropError, }; -use bevy::reflect::{PartialReflect, Reflect, ReflectFromReflect, ReflectMut, TypeInfo}; +use bevy::reflect::{ + PartialReflect, Reflect, ReflectFromReflect, ReflectMut, TypeInfo, +}; use std::{ any::{Any, TypeId}, cmp::max, }; + /// Extension trait for [`PartialReflect`] providing additional functionality for working with specific types. pub trait PartialReflectExt { /// Try to get a reference to the given key in an underyling map, if the type is a map. @@ -30,7 +33,7 @@ pub trait PartialReflectExt { fn from_reflect_or_clone( reflect: &dyn PartialReflect, world: WorldGuard, - ) -> Box; + ) -> Result, InteropError>; /// Allocate a new boxed reflect reference from a boxed reflect. fn allocate(boxed: Box, world: WorldGuard) -> ReflectReference; @@ -424,11 +427,19 @@ impl PartialReflectExt for T { fn from_reflect_or_clone( reflect: &dyn PartialReflect, world: WorldGuard, - ) -> Box { + ) -> Result, InteropError> { // try from reflect match ::from_reflect(reflect, world.clone()) { - Ok(v) => v.into_partial_reflect(), - Err(_) => reflect.clone_value(), + Ok(v) => Ok(v.into_partial_reflect()), + Err(_) => reflect + .reflect_clone() + .map(|v| v.into_partial_reflect()) + .map_err(|e| { + InteropError::failed_from_reflect( + reflect.get_represented_type_info().map(|ti| ti.type_id()), + e.to_string(), + ) + }), } } @@ -667,7 +678,7 @@ mod test { let mut map = std::collections::HashMap::>::default(); let value = DynamicMap::from_iter(vec![(1, 2), (2, 3), (3, 4)]); - let value_ref: Box = Box::new(value.clone_dynamic()); + let value_ref: Box = Box::new(value.to_dynamic_map()); map.insert(1, std::collections::HashMap::::default()); map.insert(2, std::collections::HashMap::::default()); map.insert(3, std::collections::HashMap::::default()); diff --git a/crates/bevy_mod_scripting_core/src/runtime.rs b/crates/bevy_mod_scripting_core/src/runtime.rs index 359a7a0c97..0f69158fed 100644 --- a/crates/bevy_mod_scripting_core/src/runtime.rs +++ b/crates/bevy_mod_scripting_core/src/runtime.rs @@ -3,8 +3,8 @@ use crate::{error::ScriptError, IntoScriptPluginParams}; use bevy::{ - ecs::system::{ResMut, Resource}, - prelude::Res, + ecs::system::{ResMut}, + prelude::{Res, Resource}, }; /// A trait that all script runtimes must implement. diff --git a/crates/bevy_mod_scripting_core/src/script.rs b/crates/bevy_mod_scripting_core/src/script.rs index d5b0fe46ae..dd29fdc22a 100644 --- a/crates/bevy_mod_scripting_core/src/script.rs +++ b/crates/bevy_mod_scripting_core/src/script.rs @@ -1,11 +1,17 @@ //! Script related types, functions and components -use crate::{asset::ScriptAsset, IntoScriptPluginParams}; -use bevy::prelude::ReflectComponent; -use bevy::{asset::Handle, ecs::system::Resource, reflect::Reflect, utils::HashSet}; -use parking_lot::Mutex; use std::{borrow::Cow, collections::HashMap, ops::Deref, sync::Arc}; +use bevy::{ + asset::Handle, + platform::collections::HashSet, + prelude::{ReflectComponent, Resource}, + reflect::Reflect, +}; +use parking_lot::Mutex; + +use crate::{asset::ScriptAsset, IntoScriptPluginParams}; + /// A unique identifier for a script, by default corresponds to the path of the asset excluding the asset source. /// /// I.e. an asset with the path `path/to/asset.ext` will have the script id `path/to/asset.ext` diff --git a/crates/bevy_mod_scripting_derive/Cargo.toml b/crates/bevy_mod_scripting_derive/Cargo.toml index 0f867cbf67..cd77066a16 100644 --- a/crates/bevy_mod_scripting_derive/Cargo.toml +++ b/crates/bevy_mod_scripting_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_derive" -version = "0.12.0" +version = "0.13.0" edition = "2021" authors = ["Maksymilian Mozolewski "] license = "MIT OR Apache-2.0" diff --git a/crates/bevy_mod_scripting_derive/src/derive/mod.rs b/crates/bevy_mod_scripting_derive/src/derive/mod.rs index b0363a2455..b2b1171376 100644 --- a/crates/bevy_mod_scripting_derive/src/derive/mod.rs +++ b/crates/bevy_mod_scripting_derive/src/derive/mod.rs @@ -9,8 +9,8 @@ use quote::{quote_spanned, ToTokens}; use syn::{Ident, ImplItemFn, ItemImpl}; pub use self::{ - get_type_dependencies::get_type_dependencies, into_script::into_script, - script_bindings::script_bindings, script_globals::script_globals, typed_through::typed_through, + get_type_dependencies::get_type_dependencies, into_script::into_script, + script_bindings::script_bindings, script_globals::script_globals, typed_through::typed_through, }; pub(crate) fn impl_fn_to_namespace_builder_registration(fun: &ImplItemFn) -> TokenStream { diff --git a/crates/bevy_mod_scripting_functions/Cargo.toml b/crates/bevy_mod_scripting_functions/Cargo.toml index e2ad1971a3..18433d6297 100644 --- a/crates/bevy_mod_scripting_functions/Cargo.toml +++ b/crates/bevy_mod_scripting_functions/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_functions" -version = "0.12.0" +version = "0.13.0" edition = "2021" authors = ["Maksymilian Mozolewski "] license = "MIT OR Apache-2.0" @@ -28,13 +28,16 @@ rhai_bindings = ["bevy_mod_scripting_rhai"] [dependencies] bevy = { workspace = true } +bevy_math = { workspace = true, features = ["curve"]} +bevy_reflect = { workspace = true, features = ["smol_str"]} +bevy_input = { workspace = true, features = ["smol_str"]} profiling = { workspace = true } uuid = "1.11" smol_str = "0.2.2" bevy_mod_scripting_core = { workspace = true } bevy_mod_scripting_derive = { workspace = true } -bevy_mod_scripting_lua = { path = "../languages/bevy_mod_scripting_lua", optional = true, version = "0.12.0" } -bevy_mod_scripting_rhai = { path = "../languages/bevy_mod_scripting_rhai", optional = true, version = "0.12.0" } +bevy_mod_scripting_lua = { path = "../languages/bevy_mod_scripting_lua", optional = true, version = "0.13.0" } +bevy_mod_scripting_rhai = { path = "../languages/bevy_mod_scripting_rhai", optional = true, version = "0.13.0" } bevy_system_reflection = { path = "../bevy_system_reflection", version = "0.1.1" } [lints] diff --git a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_core.rs b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_core.rs index 2d2e6ee754..f6466929c0 100644 --- a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_core.rs +++ b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_core.rs @@ -2,15 +2,8 @@ #![allow(clippy::all)] #![allow(unused, deprecated, dead_code)] #![cfg_attr(rustfmt, rustfmt_skip)] -use bevy_mod_scripting_core::bindings::{ - ReflectReference, - function::{ - from::{Ref, Mut, Val}, - namespace::NamespaceBuilder, - }, -}; +use bevy_mod_scripting_core::bindings::function::from::{Ref, Val}; use bevy_mod_scripting_derive::script_bindings; -use crate::*; pub struct BevyCoreScriptingPlugin; #[script_bindings( remote, @@ -18,20 +11,20 @@ pub struct BevyCoreScriptingPlugin; bms_core_path = "bevy_mod_scripting_core", generated )] -impl bevy::core::prelude::Name { - fn clone(_self: Ref) -> Val { - let output: Val = ::clone( +impl bevy::prelude::Name { + fn clone(_self: Ref) -> Val { + let output: Val = ::clone( &_self, ) .into(); output } fn eq( - _self: Ref, - other: Ref, + _self: Ref, + other: Ref, ) -> bool { - let output: bool = >::eq(&_self, &other) .into(); output diff --git a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_hierarchy.rs b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_hierarchy.rs index 529c8c7f5d..373bff58bc 100644 --- a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_hierarchy.rs +++ b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_hierarchy.rs @@ -18,14 +18,14 @@ pub struct BevyHierarchyScriptingPlugin; bms_core_path = "bevy_mod_scripting_core", generated )] -impl bevy::hierarchy::prelude::Children { +impl bevy::prelude::Children { /// Swaps the child at `a_index` with the child at `b_index`. fn swap( - mut _self: Mut, + mut _self: Mut, a_index: usize, b_index: usize, ) -> () { - let output: () = bevy::hierarchy::prelude::Children::swap( + let output: () = bevy::prelude::Children::swap( &mut _self, a_index, b_index, @@ -40,74 +40,39 @@ impl bevy::hierarchy::prelude::Children { bms_core_path = "bevy_mod_scripting_core", generated )] -impl bevy::hierarchy::prelude::Parent { - fn assert_receiver_is_total_eq(_self: Ref) -> () { - let output: () = ::assert_receiver_is_total_eq( +impl bevy::prelude::ChildOf { + fn assert_receiver_is_total_eq(_self: Ref) -> () { + let output: () = ::assert_receiver_is_total_eq( &_self, ) .into(); output } fn eq( - _self: Ref, - other: Ref, + _self: Ref, + other: Ref, ) -> bool { - let output: bool = >::eq(&_self, &other) .into(); output } /// Gets the [`Entity`] ID of the parent. fn get( - _self: Ref, + _self: Ref, ) -> Val { - let output: Val = bevy::hierarchy::prelude::Parent::get( + let output: Val = bevy::prelude::ChildOf::get( &_self, ) .into(); output } } -#[script_bindings( - remote, - name = "hierarchy_event_functions", - bms_core_path = "bevy_mod_scripting_core", - generated -)] -impl bevy::hierarchy::HierarchyEvent { - fn assert_receiver_is_total_eq(_self: Ref) -> () { - let output: () = ::assert_receiver_is_total_eq( - &_self, - ) - .into(); - output - } - fn clone( - _self: Ref, - ) -> Val { - let output: Val = ::clone( - &_self, - ) - .into(); - output - } - fn eq( - _self: Ref, - other: Ref, - ) -> bool { - let output: bool = >::eq(&_self, &other) - .into(); - output - } -} impl ::bevy::app::Plugin for BevyHierarchyScriptingPlugin { fn build(&self, app: &mut ::bevy::prelude::App) { let mut world = app.world_mut(); register_children_functions(&mut world); register_parent_functions(&mut world); - register_hierarchy_event_functions(&mut world); } } diff --git a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_input.rs b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_input.rs index 712fa729dc..592fd54354 100644 --- a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_input.rs +++ b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_input.rs @@ -1191,22 +1191,6 @@ impl bevy::input::gamepad::AxisSettings { .into(); output } - /// Filters the `new_value` based on the `old_value`, according to the [`AxisSettings`]. - /// Returns the clamped `new_value` if the change exceeds the settings threshold, - /// and `None` otherwise. - fn filter( - _self: Ref, - new_value: f32, - old_value: std::option::Option, - ) -> std::option::Option { - let output: std::option::Option = bevy::input::gamepad::AxisSettings::filter( - &_self, - new_value, - old_value, - ) - .into(); - output - } /// Get the value below which negative inputs will be rounded down to -1.0. fn livezone_lowerbound(_self: Ref) -> f32 { let output: f32 = bevy::input::gamepad::AxisSettings::livezone_lowerbound(&_self) @@ -1315,22 +1299,6 @@ impl bevy::input::gamepad::ButtonAxisSettings { .into(); output } - /// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`]. - /// Returns the clamped `new_value`, according to the [`ButtonAxisSettings`], if the change - /// exceeds the settings threshold, and `None` otherwise. - fn filter( - _self: Ref, - new_value: f32, - old_value: std::option::Option, - ) -> std::option::Option { - let output: std::option::Option = bevy::input::gamepad::ButtonAxisSettings::filter( - &_self, - new_value, - old_value, - ) - .into(); - output - } } #[script_bindings( remote, diff --git a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_math.rs b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_math.rs index 6a65dc0527..5d0a60944c 100644 --- a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_math.rs +++ b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_math.rs @@ -501,15 +501,6 @@ impl bevy::math::Ray3d { generated )] impl bevy::math::Rot2 { - /// Returns the angle in radians needed to make `self` and `other` coincide. - fn angle_between(_self: Val, other: Val) -> f32 { - let output: f32 = bevy::math::Rot2::angle_between( - _self.into_inner(), - other.into_inner(), - ) - .into(); - output - } /// Returns the angle in radians needed to make `self` and `other` coincide. fn angle_to(_self: Val, other: Val) -> f32 { let output: f32 = bevy::math::Rot2::angle_to( @@ -3390,11 +3381,11 @@ impl bevy::math::primitives::Segment2d { output } /// Create a new `Segment2d` from a direction and full length of the segment - fn new( + fn from_direction_and_length( direction: Val, length: f32, ) -> Val { - let output: Val = bevy::math::primitives::Segment2d::new( + let output: Val = bevy::math::primitives::Segment2d::from_direction_and_length( direction.into_inner(), length, ) @@ -4039,11 +4030,11 @@ impl bevy::math::primitives::Segment3d { output } /// Create a new `Segment3d` from a direction and full length of the segment - fn new( + fn from_direction_and_length( direction: Val, length: f32, ) -> Val { - let output: Val = bevy::math::primitives::Segment3d::new( + let output: Val = bevy::math::primitives::Segment3d::from_direction_and_length( direction.into_inner(), length, ) @@ -4569,7 +4560,7 @@ impl bevy::math::bounding::BoundingSphereCast { bms_core_path = "bevy_mod_scripting_core", generated )] -impl bevy::math::curve::interval::Interval { +impl bevy::math::curve::Interval { /// Clamp the given `value` to lie within this interval. fn clamp(_self: Val, value: f32) -> f32 { let output: f32 = bevy::math::curve::interval::Interval::clamp( diff --git a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_reflect.rs b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_reflect.rs index 303da037a7..b981719c12 100644 --- a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_reflect.rs +++ b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_reflect.rs @@ -408,7 +408,7 @@ impl std::sync::atomic::AtomicUsize { bms_core_path = "bevy_mod_scripting_core", generated )] -impl bevy::utils::Duration { +impl std::time::Duration { /// Computes the absolute difference between `self` and `other`. /// # Examples /// ``` @@ -417,10 +417,10 @@ impl bevy::utils::Duration { /// assert_eq!(Duration::new(100, 400_000_000).abs_diff(Duration::new(110, 0)), Duration::new(9, 600_000_000)); /// ``` fn abs_diff( - _self: Val, - other: Val, - ) -> Val { - let output: Val = bevy::utils::Duration::abs_diff( + _self: Val, + other: Val, + ) -> Val { + let output: Val = std::time::Duration::abs_diff( _self.into_inner(), other.into_inner(), ) @@ -428,11 +428,11 @@ impl bevy::utils::Duration { output } fn add( - _self: Val, - rhs: Val, - ) -> Val { - let output: Val = , + rhs: Val, + ) -> Val { + let output: Val = >::add(_self.into_inner(), rhs.into_inner()) .into(); output @@ -444,8 +444,8 @@ impl bevy::utils::Duration { /// let duration = Duration::new(5, 730_023_852); /// assert_eq!(duration.as_micros(), 5_730_023); /// ``` - fn as_micros(_self: Ref) -> u128 { - let output: u128 = bevy::utils::Duration::as_micros(&_self).into(); + fn as_micros(_self: Ref) -> u128 { + let output: u128 = std::time::Duration::as_micros(&_self).into(); output } /// Returns the total number of whole milliseconds contained by this `Duration`. @@ -455,8 +455,8 @@ impl bevy::utils::Duration { /// let duration = Duration::new(5, 730_023_852); /// assert_eq!(duration.as_millis(), 5_730); /// ``` - fn as_millis(_self: Ref) -> u128 { - let output: u128 = bevy::utils::Duration::as_millis(&_self).into(); + fn as_millis(_self: Ref) -> u128 { + let output: u128 = std::time::Duration::as_millis(&_self).into(); output } /// Returns the total number of nanoseconds contained by this `Duration`. @@ -466,8 +466,8 @@ impl bevy::utils::Duration { /// let duration = Duration::new(5, 730_023_852); /// assert_eq!(duration.as_nanos(), 5_730_023_852); /// ``` - fn as_nanos(_self: Ref) -> u128 { - let output: u128 = bevy::utils::Duration::as_nanos(&_self).into(); + fn as_nanos(_self: Ref) -> u128 { + let output: u128 = std::time::Duration::as_nanos(&_self).into(); output } /// Returns the number of _whole_ seconds contained by this `Duration`. @@ -484,8 +484,8 @@ impl bevy::utils::Duration { /// [`as_secs_f64`]: Duration::as_secs_f64 /// [`as_secs_f32`]: Duration::as_secs_f32 /// [`subsec_nanos`]: Duration::subsec_nanos - fn as_secs(_self: Ref) -> u64 { - let output: u64 = bevy::utils::Duration::as_secs(&_self).into(); + fn as_secs(_self: Ref) -> u64 { + let output: u64 = std::time::Duration::as_secs(&_self).into(); output } /// Returns the number of seconds contained by this `Duration` as `f32`. @@ -496,8 +496,8 @@ impl bevy::utils::Duration { /// let dur = Duration::new(2, 700_000_000); /// assert_eq!(dur.as_secs_f32(), 2.7); /// ``` - fn as_secs_f32(_self: Ref) -> f32 { - let output: f32 = bevy::utils::Duration::as_secs_f32(&_self).into(); + fn as_secs_f32(_self: Ref) -> f32 { + let output: f32 = std::time::Duration::as_secs_f32(&_self).into(); output } /// Returns the number of seconds contained by this `Duration` as `f64`. @@ -508,26 +508,26 @@ impl bevy::utils::Duration { /// let dur = Duration::new(2, 700_000_000); /// assert_eq!(dur.as_secs_f64(), 2.7); /// ``` - fn as_secs_f64(_self: Ref) -> f64 { - let output: f64 = bevy::utils::Duration::as_secs_f64(&_self).into(); + fn as_secs_f64(_self: Ref) -> f64 { + let output: f64 = std::time::Duration::as_secs_f64(&_self).into(); output } - fn assert_receiver_is_total_eq(_self: Ref) -> () { - let output: () = ::assert_receiver_is_total_eq( + fn assert_receiver_is_total_eq(_self: Ref) -> () { + let output: () = ::assert_receiver_is_total_eq( &_self, ) .into(); output } - fn clone(_self: Ref) -> Val { - let output: Val = ::clone( + fn clone(_self: Ref) -> Val { + let output: Val = ::clone( &_self, ) .into(); output } - fn div(_self: Val, rhs: u32) -> Val { - let output: Val = , rhs: u32) -> Val { + let output: Val = >::div(_self.into_inner(), rhs) .into(); @@ -542,10 +542,10 @@ impl bevy::utils::Duration { /// assert_eq!(dur1.div_duration_f32(dur2), 0.5); /// ``` fn div_duration_f32( - _self: Val, - rhs: Val, + _self: Val, + rhs: Val, ) -> f32 { - let output: f32 = bevy::utils::Duration::div_duration_f32( + let output: f32 = std::time::Duration::div_duration_f32( _self.into_inner(), rhs.into_inner(), ) @@ -561,10 +561,10 @@ impl bevy::utils::Duration { /// assert_eq!(dur1.div_duration_f64(dur2), 0.5); /// ``` fn div_duration_f64( - _self: Val, - rhs: Val, + _self: Val, + rhs: Val, ) -> f64 { - let output: f64 = bevy::utils::Duration::div_duration_f64( + let output: f64 = std::time::Duration::div_duration_f64( _self.into_inner(), rhs.into_inner(), ) @@ -584,10 +584,10 @@ impl bevy::utils::Duration { /// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_599)); /// ``` fn div_f32( - _self: Val, + _self: Val, rhs: f32, - ) -> Val { - let output: Val = bevy::utils::Duration::div_f32( + ) -> Val { + let output: Val = std::time::Duration::div_f32( _self.into_inner(), rhs, ) @@ -605,19 +605,19 @@ impl bevy::utils::Duration { /// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_599)); /// ``` fn div_f64( - _self: Val, + _self: Val, rhs: f64, - ) -> Val { - let output: Val = bevy::utils::Duration::div_f64( + ) -> Val { + let output: Val = std::time::Duration::div_f64( _self.into_inner(), rhs, ) .into(); output } - fn eq(_self: Ref, other: Ref) -> bool { - let output: bool = , other: Ref) -> bool { + let output: bool = >::eq(&_self, &other) .into(); output @@ -630,8 +630,8 @@ impl bevy::utils::Duration { /// assert_eq!(1, duration.as_secs()); /// assert_eq!(2_000, duration.subsec_nanos()); /// ``` - fn from_micros(micros: u64) -> Val { - let output: Val = bevy::utils::Duration::from_micros( + fn from_micros(micros: u64) -> Val { + let output: Val = std::time::Duration::from_micros( micros, ) .into(); @@ -645,8 +645,8 @@ impl bevy::utils::Duration { /// assert_eq!(2, duration.as_secs()); /// assert_eq!(569_000_000, duration.subsec_nanos()); /// ``` - fn from_millis(millis: u64) -> Val { - let output: Val = bevy::utils::Duration::from_millis( + fn from_millis(millis: u64) -> Val { + let output: Val = std::time::Duration::from_millis( millis, ) .into(); @@ -664,8 +664,8 @@ impl bevy::utils::Duration { /// assert_eq!(1, duration.as_secs()); /// assert_eq!(123, duration.subsec_nanos()); /// ``` - fn from_nanos(nanos: u64) -> Val { - let output: Val = bevy::utils::Duration::from_nanos(nanos) + fn from_nanos(nanos: u64) -> Val { + let output: Val = std::time::Duration::from_nanos(nanos) .into(); output } @@ -677,8 +677,8 @@ impl bevy::utils::Duration { /// assert_eq!(5, duration.as_secs()); /// assert_eq!(0, duration.subsec_nanos()); /// ``` - fn from_secs(secs: u64) -> Val { - let output: Val = bevy::utils::Duration::from_secs(secs) + fn from_secs(secs: u64) -> Val { + let output: Val = std::time::Duration::from_secs(secs) .into(); output } @@ -706,8 +706,8 @@ impl bevy::utils::Duration { /// let res = Duration::from_secs_f32(0.999e-9); /// assert_eq!(res, Duration::new(0, 1)); /// ``` - fn from_secs_f32(secs: f32) -> Val { - let output: Val = bevy::utils::Duration::from_secs_f32( + fn from_secs_f32(secs: f32) -> Val { + let output: Val = std::time::Duration::from_secs_f32( secs, ) .into(); @@ -737,8 +737,8 @@ impl bevy::utils::Duration { /// let res = Duration::from_secs_f64(0.999e-9); /// assert_eq!(res, Duration::new(0, 1)); /// ``` - fn from_secs_f64(secs: f64) -> Val { - let output: Val = bevy::utils::Duration::from_secs_f64( + fn from_secs_f64(secs: f64) -> Val { + let output: Val = std::time::Duration::from_secs_f64( secs, ) .into(); @@ -756,12 +756,12 @@ impl bevy::utils::Duration { /// assert!(!Duration::from_nanos(1).is_zero()); /// assert!(!Duration::from_secs(1).is_zero()); /// ``` - fn is_zero(_self: Ref) -> bool { - let output: bool = bevy::utils::Duration::is_zero(&_self).into(); + fn is_zero(_self: Ref) -> bool { + let output: bool = std::time::Duration::is_zero(&_self).into(); output } - fn mul(_self: Val, rhs: u32) -> Val { - let output: Val = , rhs: u32) -> Val { + let output: Val = >::mul(_self.into_inner(), rhs) .into(); @@ -778,10 +778,10 @@ impl bevy::utils::Duration { /// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847_800, 0)); /// ``` fn mul_f32( - _self: Val, + _self: Val, rhs: f32, - ) -> Val { - let output: Val = bevy::utils::Duration::mul_f32( + ) -> Val { + let output: Val = std::time::Duration::mul_f32( _self.into_inner(), rhs, ) @@ -799,10 +799,10 @@ impl bevy::utils::Duration { /// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0)); /// ``` fn mul_f64( - _self: Val, + _self: Val, rhs: f64, - ) -> Val { - let output: Val = bevy::utils::Duration::mul_f64( + ) -> Val { + let output: Val = std::time::Duration::mul_f64( _self.into_inner(), rhs, ) @@ -821,8 +821,8 @@ impl bevy::utils::Duration { /// use std::time::Duration; /// let five_seconds = Duration::new(5, 0); /// ``` - fn new(secs: u64, nanos: u32) -> Val { - let output: Val = bevy::utils::Duration::new(secs, nanos) + fn new(secs: u64, nanos: u32) -> Val { + let output: Val = std::time::Duration::new(secs, nanos) .into(); output } @@ -836,10 +836,10 @@ impl bevy::utils::Duration { /// assert_eq!(Duration::new(1, 0).saturating_add(Duration::new(u64::MAX, 0)), Duration::MAX); /// ``` fn saturating_add( - _self: Val, - rhs: Val, - ) -> Val { - let output: Val = bevy::utils::Duration::saturating_add( + _self: Val, + rhs: Val, + ) -> Val { + let output: Val = std::time::Duration::saturating_add( _self.into_inner(), rhs.into_inner(), ) @@ -856,10 +856,10 @@ impl bevy::utils::Duration { /// assert_eq!(Duration::new(u64::MAX - 1, 0).saturating_mul(2), Duration::MAX); /// ``` fn saturating_mul( - _self: Val, + _self: Val, rhs: u32, - ) -> Val { - let output: Val = bevy::utils::Duration::saturating_mul( + ) -> Val { + let output: Val = std::time::Duration::saturating_mul( _self.into_inner(), rhs, ) @@ -875,10 +875,10 @@ impl bevy::utils::Duration { /// assert_eq!(Duration::new(0, 0).saturating_sub(Duration::new(0, 1)), Duration::ZERO); /// ``` fn saturating_sub( - _self: Val, - rhs: Val, - ) -> Val { - let output: Val = bevy::utils::Duration::saturating_sub( + _self: Val, + rhs: Val, + ) -> Val { + let output: Val = std::time::Duration::saturating_sub( _self.into_inner(), rhs.into_inner(), ) @@ -886,11 +886,11 @@ impl bevy::utils::Duration { output } fn sub( - _self: Val, - rhs: Val, - ) -> Val { - let output: Val = , + rhs: Val, + ) -> Val { + let output: Val = >::sub(_self.into_inner(), rhs.into_inner()) .into(); output @@ -906,8 +906,8 @@ impl bevy::utils::Duration { /// assert_eq!(duration.as_secs(), 1); /// assert_eq!(duration.subsec_micros(), 234_567); /// ``` - fn subsec_micros(_self: Ref) -> u32 { - let output: u32 = bevy::utils::Duration::subsec_micros(&_self).into(); + fn subsec_micros(_self: Ref) -> u32 { + let output: u32 = std::time::Duration::subsec_micros(&_self).into(); output } /// Returns the fractional part of this `Duration`, in whole milliseconds. @@ -921,8 +921,8 @@ impl bevy::utils::Duration { /// assert_eq!(duration.as_secs(), 5); /// assert_eq!(duration.subsec_millis(), 432); /// ``` - fn subsec_millis(_self: Ref) -> u32 { - let output: u32 = bevy::utils::Duration::subsec_millis(&_self).into(); + fn subsec_millis(_self: Ref) -> u32 { + let output: u32 = std::time::Duration::subsec_millis(&_self).into(); output } /// Returns the fractional part of this `Duration`, in nanoseconds. @@ -936,8 +936,8 @@ impl bevy::utils::Duration { /// assert_eq!(duration.as_secs(), 5); /// assert_eq!(duration.subsec_nanos(), 10_000_000); /// ``` - fn subsec_nanos(_self: Ref) -> u32 { - let output: u32 = bevy::utils::Duration::subsec_nanos(&_self).into(); + fn subsec_nanos(_self: Ref) -> u32 { + let output: u32 = std::time::Duration::subsec_nanos(&_self).into(); output } } @@ -947,29 +947,29 @@ impl bevy::utils::Duration { bms_core_path = "bevy_mod_scripting_core", generated )] -impl bevy::utils::Instant { +impl bevy::platform::time::Instant { /// # Panics /// This function may panic if the resulting point in time cannot be represented by the /// underlying data structure. See [`Instant::checked_add`] for a version without panic. fn add( - _self: Val, - other: Val, - ) -> Val { - let output: Val = , + other: Val, + ) -> Val { + let output: Val = >::add(_self.into_inner(), other.into_inner()) .into(); output } - fn assert_receiver_is_total_eq(_self: Ref) -> () { - let output: () = ::assert_receiver_is_total_eq( + fn assert_receiver_is_total_eq(_self: Ref) -> () { + let output: () = ::assert_receiver_is_total_eq( &_self, ) .into(); output } - fn clone(_self: Ref) -> Val { - let output: Val = ::clone( + fn clone(_self: Ref) -> Val { + let output: Val = ::clone( &_self, ) .into(); @@ -993,10 +993,10 @@ impl bevy::utils::Instant { /// println!("{:?}", now.duration_since(new_now)); // 0ns /// ``` fn duration_since( - _self: Ref, - earlier: Val, - ) -> Val { - let output: Val = bevy::utils::Instant::duration_since( + _self: Ref, + earlier: Val, + ) -> Val { + let output: Val = bevy::platform::time::Instant::duration_since( &_self, earlier.into_inner(), ) @@ -1018,14 +1018,14 @@ impl bevy::utils::Instant { /// sleep(three_secs); /// assert!(instant.elapsed() >= three_secs); /// ``` - fn elapsed(_self: Ref) -> Val { - let output: Val = bevy::utils::Instant::elapsed(&_self) + fn elapsed(_self: Ref) -> Val { + let output: Val = bevy::platform::time::Instant::elapsed(&_self) .into(); output } - fn eq(_self: Ref, other: Ref) -> bool { - let output: bool = , other: Ref) -> bool { + let output: bool = >::eq(&_self, &other) .into(); output @@ -1036,8 +1036,8 @@ impl bevy::utils::Instant { /// use std::time::Instant; /// let now = Instant::now(); /// ``` - fn now() -> Val { - let output: Val = bevy::utils::Instant::now().into(); + fn now() -> Val { + let output: Val = bevy::platform::time::Instant::now().into(); output } /// Returns the amount of time elapsed from another instant to this one, @@ -1053,10 +1053,10 @@ impl bevy::utils::Instant { /// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns /// ``` fn saturating_duration_since( - _self: Ref, - earlier: Val, - ) -> Val { - let output: Val = bevy::utils::Instant::saturating_duration_since( + _self: Ref, + earlier: Val, + ) -> Val { + let output: Val = bevy::platform::time::Instant::saturating_duration_since( &_self, earlier.into_inner(), ) @@ -1064,11 +1064,11 @@ impl bevy::utils::Instant { output } fn sub( - _self: Val, - other: Val, - ) -> Val { - let output: Val = , + other: Val, + ) -> Val { + let output: Val = >::sub(_self.into_inner(), other.into_inner()) .into(); output @@ -1081,11 +1081,11 @@ impl bevy::utils::Instant { /// See [Monotonicity]. /// [Monotonicity]: Instant#monotonicity fn sub( - _self: Val, - other: Val, - ) -> Val { - let output: Val = , + other: Val, + ) -> Val { + let output: Val = >::sub(_self.into_inner(), other.into_inner()) .into(); output diff --git a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_time.rs b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_time.rs index 4802139580..2e7a937b67 100644 --- a/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_time.rs +++ b/crates/bevy_mod_scripting_functions/src/bevy_bindings/bevy_time.rs @@ -71,8 +71,8 @@ impl bevy::time::prelude::Timer { /// let timer = Timer::new(Duration::from_secs(1), TimerMode::Once); /// assert_eq!(timer.duration(), Duration::from_secs(1)); /// ``` - fn duration(_self: Ref) -> Val { - let output: Val = bevy::time::prelude::Timer::duration( + fn duration(_self: Ref) -> Val { + let output: Val = bevy::time::prelude::Timer::duration( &_self, ) .into(); @@ -89,8 +89,8 @@ impl bevy::time::prelude::Timer { /// timer.tick(Duration::from_secs_f32(0.5)); /// assert_eq!(timer.elapsed(), Duration::from_secs_f32(0.5)); /// ``` - fn elapsed(_self: Ref) -> Val { - let output: Val = bevy::time::prelude::Timer::elapsed( + fn elapsed(_self: Ref) -> Val { + let output: Val = bevy::time::prelude::Timer::elapsed( &_self, ) .into(); @@ -218,7 +218,7 @@ impl bevy::time::prelude::Timer { /// Creates a new timer with a given duration. /// See also [`Timer::from_seconds`](Timer::from_seconds). fn new( - duration: Val, + duration: Val, mode: Val, ) -> Val { let output: Val = bevy::time::prelude::Timer::new( @@ -268,8 +268,8 @@ impl bevy::time::prelude::Timer { /// timer.tick(Duration::from_secs_f32(0.5)); /// assert_eq!(timer.remaining(), Duration::from_secs_f32(1.5)); /// ``` - fn remaining(_self: Ref) -> Val { - let output: Val = bevy::time::prelude::Timer::remaining( + fn remaining(_self: Ref) -> Val { + let output: Val = bevy::time::prelude::Timer::remaining( &_self, ) .into(); @@ -318,7 +318,7 @@ impl bevy::time::prelude::Timer { /// ``` fn set_duration( mut _self: Mut, - duration: Val, + duration: Val, ) -> () { let output: () = bevy::time::prelude::Timer::set_duration( &mut _self, @@ -341,7 +341,7 @@ impl bevy::time::prelude::Timer { /// ``` fn set_elapsed( mut _self: Mut, - time: Val, + time: Val, ) -> () { let output: () = bevy::time::prelude::Timer::set_elapsed( &mut _self, @@ -493,8 +493,8 @@ impl bevy::time::Stopwatch { /// # See Also /// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` value is desirable instead. /// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. - fn elapsed(_self: Ref) -> Val { - let output: Val = bevy::time::Stopwatch::elapsed(&_self) + fn elapsed(_self: Ref) -> Val { + let output: Val = bevy::time::Stopwatch::elapsed(&_self) .into(); output } @@ -599,7 +599,7 @@ impl bevy::time::Stopwatch { /// ``` fn set_elapsed( mut _self: Mut, - time: Val, + time: Val, ) -> () { let output: () = bevy::time::Stopwatch::set_elapsed( &mut _self, diff --git a/crates/bevy_mod_scripting_functions/src/core.rs b/crates/bevy_mod_scripting_functions/src/core.rs index 08963a02d3..82da20e1ad 100644 --- a/crates/bevy_mod_scripting_functions/src/core.rs +++ b/crates/bevy_mod_scripting_functions/src/core.rs @@ -4,28 +4,28 @@ use std::{collections::HashMap, ops::Deref}; use bevy::prelude::*; use bevy_mod_scripting_core::{ - bindings::{ - function::{ - from::Union, namespace::GlobalNamespace, script_function::DynamicScriptFunctionMut, - }, - script_system::ScriptSystemBuilder, - }, - docgen::info::FunctionInfo, - *, + bindings::{ + function::{ + from::Union, namespace::GlobalNamespace, script_function::DynamicScriptFunctionMut, + }, + script_system::ScriptSystemBuilder, + }, + docgen::info::FunctionInfo, + *, }; use bevy_mod_scripting_derive::script_bindings; use bevy_system_reflection::{ReflectSchedule, ReflectSystem}; use bindings::{ - function::{ - from::{Ref, Val}, - from_ref::FromScriptRef, - into_ref::IntoScriptRef, - script_function::{FunctionCallContext, ScriptFunctionMut}, - }, - pretty_print::DisplayWithWorld, - script_value::ScriptValue, - ReflectReference, ScriptComponentRegistration, ScriptQueryBuilder, ScriptQueryResult, - ScriptResourceRegistration, ScriptTypeRegistration, ThreadWorldContainer, WorldContainer, + function::{ + from::{Ref, Val}, + from_ref::FromScriptRef, + into_ref::IntoScriptRef, + script_function::{FunctionCallContext, ScriptFunctionMut}, + }, + pretty_print::DisplayWithWorld, + script_value::ScriptValue, + ReflectReference, ScriptComponentRegistration, ScriptQueryBuilder, ScriptQueryResult, + ScriptResourceRegistration, ScriptTypeRegistration, ThreadWorldContainer, WorldContainer, }; use error::InteropError; use reflection_extensions::{PartialReflectExt, TypeIdExtensions}; diff --git a/crates/bevy_mod_scripting_functions/src/lib.rs b/crates/bevy_mod_scripting_functions/src/lib.rs index 5f998f4cb4..5d48dc58a6 100644 --- a/crates/bevy_mod_scripting_functions/src/lib.rs +++ b/crates/bevy_mod_scripting_functions/src/lib.rs @@ -15,7 +15,7 @@ impl Plugin for ScriptFunctionsPlugin { register_core_functions(app); // TODO: if bevy ever does this itself we should remove this - app.world_mut().register_component::(); + app.world_mut().register_component::(); app.world_mut().register_component::(); } } diff --git a/crates/bevy_system_reflection/Cargo.toml b/crates/bevy_system_reflection/Cargo.toml index 95921576f8..675d8929f3 100644 --- a/crates/bevy_system_reflection/Cargo.toml +++ b/crates/bevy_system_reflection/Cargo.toml @@ -12,9 +12,8 @@ categories = ["game-development"] readme = "readme.md" [dependencies] -bevy = { workspace = true, default-features = false } +bevy = { workspace = true, default-features = false, features = ["bevy_log"]} dot-writer = "0.1.4" -petgraph = "0.6" [dev-dependencies] diff --git a/crates/bevy_system_reflection/src/lib.rs b/crates/bevy_system_reflection/src/lib.rs index bf7cf158db..e8829d411e 100644 --- a/crates/bevy_system_reflection/src/lib.rs +++ b/crates/bevy_system_reflection/src/lib.rs @@ -1,13 +1,16 @@ //! A visualiser for bevy system schedules, as well as utilities for querying them via reflection -use std::ops::Deref; -use std::{any::TypeId, borrow::Cow}; - -use bevy::ecs::schedule::{ - InternedScheduleLabel, InternedSystemSet, NodeId, Schedule, ScheduleLabel, SystemSet, +use std::{any::TypeId, borrow::Cow, ops::Deref}; + +use bevy::{ + ecs::{ + schedule::{ + InternedScheduleLabel, InternedSystemSet, NodeId, Schedule, ScheduleLabel, SystemSet, + }, + system::{System, SystemInput}, + }, + platform::collections::{HashMap, HashSet}, + reflect::Reflect, }; -use bevy::ecs::system::{System, SystemInput}; -use bevy::reflect::Reflect; -use bevy::utils::hashbrown::{HashMap, HashSet}; use dot_writer::{Attributes, DotWriter}; #[derive(Reflect, Debug, Clone)] @@ -283,7 +286,7 @@ pub fn schedule_to_reflect_graph(schedule: &Schedule) -> ReflectSystemGraph { let dependencies = dependency .all_edges() - .map(|(from, to, _)| Edge { + .map(|(from, to)| Edge { from: ReflectNodeId(from), to: ReflectNodeId(to), }) @@ -291,7 +294,7 @@ pub fn schedule_to_reflect_graph(schedule: &Schedule) -> ReflectSystemGraph { let hierarchy = hierarchy .all_edges() - .map(|(from, to, _)| Edge { + .map(|(from, to)| Edge { from: ReflectNodeId(from), to: ReflectNodeId(to), }) @@ -466,17 +469,11 @@ pub struct Edge { #[cfg(test)] mod test { - use bevy::{ - app::Update, - ecs::{ - schedule::{IntoSystemConfigs, IntoSystemSetConfigs}, - world::World, - }, - }; + use bevy::{app::Update, ecs::world::World, prelude::IntoScheduleConfigs}; - use super::*; + use super::*; - fn system_a() {} + fn system_a() {} fn system_b() {} diff --git a/crates/ladfile_builder/Cargo.toml b/crates/ladfile_builder/Cargo.toml index 6b78ed7b8d..adcc25e745 100644 --- a/crates/ladfile_builder/Cargo.toml +++ b/crates/ladfile_builder/Cargo.toml @@ -16,7 +16,7 @@ readme = "readme.md" bevy_mod_scripting_core = { workspace = true } # I don't think bevy has a top level feature for this :C bevy = { workspace = true } -bevy_reflect = { version = "0.15.3", features = ["documentation"] } +bevy_reflect = { version = "0.16.0", features = ["documentation"] } ladfile = { version = "0.5.0", path = "../ladfile" } regex = "1.11" diff --git a/crates/ladfile_builder/src/lib.rs b/crates/ladfile_builder/src/lib.rs index 9fa1150d6b..3c146b7a9f 100644 --- a/crates/ladfile_builder/src/lib.rs +++ b/crates/ladfile_builder/src/lib.rs @@ -1,34 +1,35 @@ //! Parsing definitions for the LAD (Language Agnostic Decleration) file format. pub mod plugin; -use bevy::{ecs::world::World, utils::HashSet}; +use std::{ + any::TypeId, + borrow::Cow, + cmp::{max, min}, + collections::HashMap, + ffi::OsString, + path::PathBuf, +}; + +use bevy::{ecs::world::World, platform::collections::HashSet}; use bevy_mod_scripting_core::{ - bindings::{ - function::{ - namespace::Namespace, - script_function::{ - DynamicScriptFunction, DynamicScriptFunctionMut, FunctionCallContext, - }, - }, - ReflectReference, - }, - docgen::{ - info::FunctionInfo, - typed_through::{ThroughTypeInfo, TypedWrapperKind, UntypedWrapperKind}, - TypedThrough, - }, - match_by_type, + bindings::{ + function::{ + namespace::Namespace, + script_function::{ + DynamicScriptFunction, DynamicScriptFunctionMut, FunctionCallContext, + }, + }, + ReflectReference, + }, + docgen::{ + info::FunctionInfo, + typed_through::{ThroughTypeInfo, TypedWrapperKind, UntypedWrapperKind}, + TypedThrough, + }, + match_by_type, }; use bevy_reflect::{NamedField, TypeInfo, TypeRegistry, Typed, UnnamedField}; use ladfile::*; -use std::{ - any::TypeId, - borrow::Cow, - cmp::{max, min}, - collections::HashMap, - ffi::OsString, - path::PathBuf, -}; /// We can assume that the types here will be either primitives /// or reflect types, as the rest will be covered by typed wrappers @@ -787,21 +788,21 @@ impl<'t> LadFileBuilder<'t> { #[cfg(test)] mod test { - use bevy_mod_scripting_core::{ - bindings::{ - function::{ - from::Ref, - namespace::{GlobalNamespace, IntoNamespace}, - }, - Union, Val, - }, - docgen::info::GetFunctionInfo, - }; - use bevy_reflect::Reflect; - - use super::*; - - /// normalize line endings etc.. + use bevy_mod_scripting_core::{ + bindings::{ + function::{ + from::Ref, + namespace::{GlobalNamespace, IntoNamespace}, + }, + Union, Val, + }, + docgen::info::GetFunctionInfo, + }; + use bevy_reflect::Reflect; + + use super::*; + + /// normalize line endings etc.. fn normalize_file(file: &mut String) { *file = file.replace("\r\n", "\n"); } diff --git a/crates/ladfile_builder/src/plugin.rs b/crates/ladfile_builder/src/plugin.rs index ef6a3a6773..89942ae47a 100644 --- a/crates/ladfile_builder/src/plugin.rs +++ b/crates/ladfile_builder/src/plugin.rs @@ -3,17 +3,13 @@ use std::path::PathBuf; use bevy::{ - app::{App, Plugin, Startup}, - ecs::{ - reflect::AppTypeRegistry, - system::{Res, Resource}, - world::World, - }, + app::{App, Plugin, Startup}, + ecs::{prelude::Resource, reflect::AppTypeRegistry, system::Res, world::World}, }; use bevy_mod_scripting_core::bindings::{ - function::{namespace::Namespace, script_function::AppScriptFunctionRegistry}, - globals::AppScriptGlobalsRegistry, - IntoNamespace, MarkAsCore, MarkAsGenerated, MarkAsSignificant, + function::{namespace::Namespace, script_function::AppScriptFunctionRegistry}, + globals::AppScriptGlobalsRegistry, + IntoNamespace, MarkAsCore, MarkAsGenerated, MarkAsSignificant, }; use ladfile::{default_importance, LadTypeKind}; diff --git a/crates/languages/bevy_mod_scripting_lua/Cargo.toml b/crates/languages/bevy_mod_scripting_lua/Cargo.toml index 9ca8352a0a..45aa8aee47 100644 --- a/crates/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_lua/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_lua" -version = "0.12.0" +version = "0.13.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT OR Apache-2.0" @@ -40,10 +40,6 @@ path = "src/lib.rs" bevy = { workspace = true, default-features = false } bevy_mod_scripting_core = { workspace = true, features = ["mlua_impls"] } mlua = { version = "0.10", features = ["vendored", "send", "macros"] } -parking_lot = "0.12.1" -uuid = "1.1" -smol_str = "0.2.2" -smallvec = "1.13" profiling = { workspace = true } [lints] diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index 473c98d24c..33df2015d0 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -72,7 +72,7 @@ impl Default for LuaScriptingPlugin { Ok(()) }, - |_script_id, context: &mut Lua| { + |_script_id, context| { // set static globals let world = ThreadWorldContainer.try_get_world()?; let globals_registry = diff --git a/crates/languages/bevy_mod_scripting_rhai/Cargo.toml b/crates/languages/bevy_mod_scripting_rhai/Cargo.toml index 2c2789922d..64e10ee089 100644 --- a/crates/languages/bevy_mod_scripting_rhai/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_rhai/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_rhai" -version = "0.12.0" +version = "0.13.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT OR Apache-2.0" diff --git a/crates/languages/bevy_mod_scripting_rhai/src/lib.rs b/crates/languages/bevy_mod_scripting_rhai/src/lib.rs index a1a477cf5e..c72d6ca7a8 100644 --- a/crates/languages/bevy_mod_scripting_rhai/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_rhai/src/lib.rs @@ -3,31 +3,30 @@ use std::ops::Deref; use bevy::{ - app::Plugin, - ecs::{entity::Entity, world::World}, + app::Plugin, + ecs::{entity::Entity, world::World}, }; use bevy_mod_scripting_core::{ - asset::Language, - bindings::{ - function::namespace::Namespace, globals::AppScriptGlobalsRegistry, - script_value::ScriptValue, ThreadWorldContainer, WorldContainer, - }, - context::{ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, - error::ScriptError, - event::CallbackLabel, - reflection_extensions::PartialReflectExt, - runtime::RuntimeSettings, - script::ScriptId, - IntoScriptPluginParams, ScriptingPlugin, + asset::Language, + bindings::{ + function::namespace::Namespace, globals::AppScriptGlobalsRegistry, + script_value::ScriptValue, ThreadWorldContainer, WorldContainer, + }, + context::{ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, + error::ScriptError, + event::CallbackLabel, + reflection_extensions::PartialReflectExt, + runtime::RuntimeSettings, + script::ScriptId, + IntoScriptPluginParams, ScriptingPlugin, }; use bindings::{ - reference::{ReservedKeyword, RhaiReflectReference, RhaiStaticReflectReference}, - script_value::{FromDynamic, IntoDynamic}, + reference::{ReservedKeyword, RhaiReflectReference, RhaiStaticReflectReference}, + script_value::{FromDynamic, IntoDynamic}, }; use parking_lot::RwLock; -use rhai::{CallFnOptions, Dynamic, Engine, EvalAltResult, Scope, AST}; - pub use rhai; +use rhai::{CallFnOptions, Dynamic, Engine, EvalAltResult, Scope, AST}; /// Bindings for rhai. pub mod bindings; @@ -71,7 +70,7 @@ impl Default for RhaiScriptingPlugin { scripting_plugin: ScriptingPlugin { context_assignment_strategy: Default::default(), runtime_settings: RuntimeSettings { - initializers: vec![|runtime: &RhaiRuntime| { + initializers: vec![|runtime| { let mut engine = runtime.write(); engine.set_max_expr_depths(999, 999); engine.build_type::(); @@ -86,14 +85,14 @@ impl Default for RhaiScriptingPlugin { reload: rhai_context_reload, }, context_initializers: vec![ - |_, context: &mut RhaiScriptContext| { + |_, context| { context.scope.set_or_push( "world", RhaiStaticReflectReference(std::any::TypeId::of::()), ); Ok(()) }, - |_, context: &mut RhaiScriptContext| { + |_, context| { // initialize global functions let world = ThreadWorldContainer.try_get_world()?; let globals_registry = @@ -301,9 +300,9 @@ pub fn rhai_callback_handler( #[cfg(test)] mod test { - use super::*; + use super::*; - #[test] + #[test] fn test_reload_doesnt_overwrite_old_context() { let runtime = RhaiRuntime::new(Engine::new()); let script_id = ScriptId::from("asd.rhai"); diff --git a/crates/testing_crates/script_integration_test_harness/src/lib.rs b/crates/testing_crates/script_integration_test_harness/src/lib.rs index fa039361e7..ae69ed2082 100644 --- a/crates/testing_crates/script_integration_test_harness/src/lib.rs +++ b/crates/testing_crates/script_integration_test_harness/src/lib.rs @@ -1,40 +1,40 @@ pub mod test_functions; use std::{ - marker::PhantomData, - path::PathBuf, - time::{Duration, Instant}, + marker::PhantomData, + path::PathBuf, + time::{Duration, Instant}, }; use bevy::{ - app::{Last, Plugin, PostUpdate, Startup, Update}, - asset::{AssetServer, Handle}, - ecs::{ - component::Component, - event::{Event, Events}, - schedule::{IntoSystemConfigs, SystemConfigs}, - system::{IntoSystem, Local, Res, Resource, SystemState}, - world::{Command, FromWorld, Mut}, - }, - log::Level, - prelude::{Entity, World}, - reflect::{Reflect, TypeRegistry}, - utils::tracing, + app::{Last, Plugin, PostUpdate, Startup, Update}, + asset::{AssetServer, Handle}, + ecs::{ + component::Component, + event::{Event, Events}, + prelude::{Command, Resource}, + schedule::ScheduleConfigs, + system::{BoxedSystem, InfallibleSystemWrapper, IntoSystem, Local, Res, SystemState}, + world::{FromWorld, Mut}, + }, + log::{tracing, tracing::event, Level}, + prelude::{BevyError, Entity, IntoScheduleConfigs, World}, + reflect::{Reflect, TypeRegistry}, }; use bevy_mod_scripting_core::{ - asset::ScriptAsset, - bindings::{ - pretty_print::DisplayWithWorld, script_value::ScriptValue, CoreScriptGlobalsPlugin, - ReflectAccessId, WorldAccessGuard, WorldGuard, - }, - callback_labels, - commands::CreateOrUpdateScript, - error::{InteropError, ScriptError}, - event::{IntoCallbackLabel, ScriptErrorEvent}, - extractors::{HandlerContext, WithWorldGuard}, - handler::handle_script_errors, - script::ScriptId, - BMSScriptingInfrastructurePlugin, IntoScriptPluginParams, ScriptingPlugin, + asset::ScriptAsset, + bindings::{ + pretty_print::DisplayWithWorld, script_value::ScriptValue, CoreScriptGlobalsPlugin, + ReflectAccessId, WorldAccessGuard, WorldGuard, + }, + callback_labels, + commands::CreateOrUpdateScript, + error::{InteropError, ScriptError}, + event::{IntoCallbackLabel, ScriptErrorEvent}, + extractors::{HandlerContext, WithWorldGuard}, + handler::handle_script_errors, + script::ScriptId, + BMSScriptingInfrastructurePlugin, IntoScriptPluginParams, ScriptingPlugin, }; use bevy_mod_scripting_functions::ScriptFunctionsPlugin; use criterion::{measurement::Measurement, BatchSize}; @@ -55,9 +55,12 @@ struct TestCallbackBuilder { } impl TestCallbackBuilder { - fn build(script_id: impl Into, expect_response: bool) -> SystemConfigs { + fn build( + script_id: impl Into, + expect_response: bool, + ) -> ScheduleConfigs>> { let script_id = script_id.into(); - IntoSystem::into_system( + let system = Box::new(InfallibleSystemWrapper::new(IntoSystem::into_system( move |world: &mut World, system_state: &mut SystemState>>| { let with_guard = system_state.get_mut(world); @@ -65,9 +68,9 @@ impl TestCallbackBuilder system_state.apply(world); }, - ) - .with_name(L::into_callback_label().to_string()) - .into_configs() + ).with_name(L::into_callback_label().to_string()))); + + system.into_configs() } } @@ -130,12 +133,12 @@ pub fn make_test_lua_plugin() -> bevy_mod_scripting_lua::LuaScriptingPlugin { #[cfg(feature = "rhai")] pub fn make_test_rhai_plugin() -> bevy_mod_scripting_rhai::RhaiScriptingPlugin { use bevy_mod_scripting_core::{ - bindings::{ThreadWorldContainer, WorldContainer}, - ConfigureScriptPlugin, + bindings::{ThreadWorldContainer, WorldContainer}, + ConfigureScriptPlugin, }; use bevy_mod_scripting_rhai::{ - rhai::{Dynamic, EvalAltResult, FnPtr, NativeCallContext}, - RhaiScriptingPlugin, + rhai::{Dynamic, EvalAltResult, FnPtr, NativeCallContext}, + RhaiScriptingPlugin, }; RhaiScriptingPlugin::default().add_runtime_initializer(|runtime| { @@ -341,7 +344,7 @@ pub fn run_lua_benchmark( label: &str, criterion: &mut criterion::BenchmarkGroup, ) -> Result<(), String> { - use bevy::{log::Level, utils::tracing}; + use bevy::log::Level; use bevy_mod_scripting_lua::mlua::Function; let plugin = make_test_lua_plugin(); @@ -373,7 +376,7 @@ pub fn run_rhai_benchmark( label: &str, criterion: &mut criterion::BenchmarkGroup, ) -> Result<(), String> { - use bevy::{log::Level, utils::tracing}; + use bevy::log::Level; use bevy_mod_scripting_rhai::rhai::Dynamic; let plugin = make_test_rhai_plugin(); @@ -418,7 +421,7 @@ where F: Fn(&mut P::C, &P::R, &str, &mut criterion::BenchmarkGroup) -> Result<(), String>, { use bevy_mod_scripting_core::bindings::{ - ThreadWorldContainer, WorldAccessGuard, WorldContainer, + ThreadWorldContainer, WorldAccessGuard, WorldContainer, }; let mut app = setup_integration_test(|_, _| {}); @@ -587,7 +590,7 @@ pub fn perform_benchmark_with_generator< ) }, |(i, w)| { - bevy::utils::tracing::event!(bevy::log::Level::TRACE, "profiling_iter {}", label); + event!(bevy::log::Level::TRACE, "profiling_iter {}", label); bench_fn(w, i) }, batch_size, diff --git a/crates/testing_crates/test_utils/src/test_data.rs b/crates/testing_crates/test_utils/src/test_data.rs index 030f7dc020..6bc5d1eaba 100644 --- a/crates/testing_crates/test_utils/src/test_data.rs +++ b/crates/testing_crates/test_utils/src/test_data.rs @@ -1,12 +1,13 @@ -use std::alloc::Layout; -use std::collections::HashMap; +use std::{alloc::Layout, collections::HashMap}; -use bevy::asset::AssetPlugin; -use bevy::diagnostic::DiagnosticsPlugin; -use bevy::ecs::{component::*, world::World}; -use bevy::log::LogPlugin; -use bevy::prelude::*; -use bevy::reflect::*; +use bevy::{ + asset::AssetPlugin, + diagnostic::DiagnosticsPlugin, + ecs::{component::*, world::World}, + log::LogPlugin, + prelude::*, + reflect::*, +}; /// Test component with Reflect and ReflectComponent registered #[derive(Component, Reflect, PartialEq, Eq, Debug)] @@ -312,6 +313,8 @@ fn init_world(world: &mut World, init: StorageType::Table, Layout::new::(), None, + true, + ComponentCloneBehavior::Default, )) }; } @@ -346,7 +349,6 @@ pub fn setup_integration_test(init: F) app.add_plugins(( MinimalPlugins, AssetPlugin::default(), - HierarchyPlugin, DiagnosticsPlugin, LogPlugin { filter: log_level, @@ -358,9 +360,9 @@ pub fn setup_integration_test(init: F) #[cfg(test)] mod test { - use super::*; + use super::*; - #[test] + #[test] fn setup_works() { setup_world(|_, _| {}); } diff --git a/examples/game_of_life.rs b/examples/game_of_life.rs index 325b4a4db9..a65b907596 100644 --- a/examples/game_of_life.rs +++ b/examples/game_of_life.rs @@ -280,7 +280,7 @@ pub fn update_rendered_state( let old_rendered_state = assets .get_mut(&old_rendered_state.image) .expect("World is not setup correctly"); - old_rendered_state.data = new_state.cells.clone(); + old_rendered_state.data = Some(new_state.cells.clone()); } } @@ -301,7 +301,7 @@ pub fn send_on_click( ) { if buttons.just_pressed(MouseButton::Left) { let window = q_windows.single(); - let pos = window.cursor_position().unwrap_or_default(); + let pos = window.unwrap().cursor_position().unwrap_or_default(); let x = pos.x as u32; let y = pos.y as u32; events.send(ScriptCallbackEvent::new_for_all( diff --git a/src/lib.rs b/src/lib.rs index a880540a76..5860ae083c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,17 @@ #![doc=include_str!("../readme.md")] pub mod core { - pub use bevy_mod_scripting_core::*; + pub use bevy_mod_scripting_core::*; } #[cfg(feature = "lua")] pub mod lua { - pub use bevy_mod_scripting_lua::*; + pub use bevy_mod_scripting_lua::*; } #[cfg(feature = "rhai")] pub mod rhai { - pub use bevy_mod_scripting_rhai::*; + pub use bevy_mod_scripting_rhai::*; } // #[cfg(feature = "rune")] @@ -21,7 +21,7 @@ pub mod rhai { use bevy::app::plugin_group; use bevy_mod_scripting_core::{ - bindings::CoreScriptGlobalsPlugin, BMSScriptingInfrastructurePlugin, + bindings::CoreScriptGlobalsPlugin, BMSScriptingInfrastructurePlugin, }; pub use bevy_mod_scripting_derive::*; pub use bevy_mod_scripting_functions::*;