From 7fdfe377fa6b7445994805863e16e4549e243175 Mon Sep 17 00:00:00 2001 From: opfromthestart Date: Thu, 15 Dec 2022 23:29:46 -0500 Subject: [PATCH 01/11] Update to 0.9.1 --- Cargo.toml | 6 +- api_gen_config.toml | 4 - bevy_event_priority/Cargo.toml | 2 +- bevy_event_priority/src/lib.rs | 2 +- bevy_mod_scripting_core/Cargo.toml | 2 +- bevy_mod_scripting_core/src/hosts.rs | 2 + bevy_mod_scripting_core/src/lib.rs | 14 +- bevy_mod_scripting_core/src/systems.rs | 13 +- bevy_script_api/Cargo.toml | 2 +- bevy_script_api/src/generated.rs | 137 +++++-------------- bevy_script_api/src/lua/bevy/mod.rs | 16 ++- bevy_script_api/src/lua/mod.rs | 22 ++- bevy_script_api/src/lua/std.rs | 2 +- bevy_script_api/src/lua/util.rs | 16 +++ bevy_script_api/src/sub_reflect.rs | 2 +- examples/lua/bevy_api.rs | 9 +- examples/lua/complex_game_loop.rs | 2 +- examples/lua/coroutines.rs | 4 +- examples/lua/event_recipients.rs | 2 +- examples/lua/game_of_life.rs | 8 +- examples/rhai/bevy_api.rs | 5 +- examples/wrappers.rs | 14 +- languages/bevy_mod_scripting_lua/Cargo.toml | 4 +- languages/bevy_mod_scripting_lua/src/lib.rs | 1 + languages/bevy_mod_scripting_rhai/Cargo.toml | 2 +- languages/bevy_mod_scripting_rhai/src/lib.rs | 1 + makefile | 36 ++--- readme.md | 4 +- 28 files changed, 151 insertions(+), 183 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0dcaa0b8..df9f9e96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ bevy_mod_scripting_rhai = { path = "languages/bevy_mod_scripting_rhai", version bevy_script_api = { path = "bevy_script_api", version = "0.1.1", optional = true } [dev-dependencies] -bevy = { version = "0.8.0"} +bevy = { version = "0.9.1"} rand = "0.8.5" @@ -62,7 +62,7 @@ rand = "0.8.5" # bevy_mod_scripting_lua = {path="languages/bevy_mod_scripting_lua", version="0.1.1", features=["lua54"]} # bevy_mod_scripting_lua_derive = {path="languages/bevy_mod_scripting_lua_derive", version="0.1.1"} -# bevy = { version = "0.8.0"} +# bevy = { version = "0.9.1"} # serde = "1.0.137" # criterion = "0.3" @@ -89,7 +89,7 @@ opt-level = 1 opt-level = 3 -# needs bevy 0.8 support from console +# needs bevy 0.9 support from console # [[example]] # name = "console_integration_lua" # path = "examples/console_integration_lua.rs" diff --git a/api_gen_config.toml b/api_gen_config.toml index d3e622a7..debaf539 100644 --- a/api_gen_config.toml +++ b/api_gen_config.toml @@ -486,10 +486,6 @@ traits=[ {name="CameraProjection", import_path="bevy::render::camera::CameraProjection"} ] -[[types]] -type="DepthCalculation" -source="bevy_render" - [[types]] type="CameraRenderGraph" source="bevy_render" diff --git a/bevy_event_priority/Cargo.toml b/bevy_event_priority/Cargo.toml index 7743be45..e1a2d531 100644 --- a/bevy_event_priority/Cargo.toml +++ b/bevy_event_priority/Cargo.toml @@ -16,5 +16,5 @@ name = "bevy_event_priority" path = "src/lib.rs" [dependencies] -bevy = { version = "0.8.0", default-features = false} +bevy = { version = "0.9.1", default-features = false} diff --git a/bevy_event_priority/src/lib.rs b/bevy_event_priority/src/lib.rs index 37d6829d..98e7546e 100644 --- a/bevy_event_priority/src/lib.rs +++ b/bevy_event_priority/src/lib.rs @@ -63,7 +63,7 @@ impl Clone for EventInstance { /// This implementation does NOT provide double buffering. /// Writers and readers are expected to remove events as soon as they are read, /// this implies a one to one mapping between events and event handlers. -#[derive(Debug)] +#[derive(Debug, Resource)] pub struct PriorityEvents { events: BinaryHeap>, } diff --git a/bevy_mod_scripting_core/Cargo.toml b/bevy_mod_scripting_core/Cargo.toml index 6cf7c912..962b9fcb 100644 --- a/bevy_mod_scripting_core/Cargo.toml +++ b/bevy_mod_scripting_core/Cargo.toml @@ -28,7 +28,7 @@ doc_always = [] [dependencies] -bevy = { version = "0.8.0", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite","filesystem_watcher"]} +bevy = { version = "0.9.1", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite","filesystem_watcher"]} bevy_event_priority = {path = "../bevy_event_priority", version = "0.1.1"} thiserror = "1.0.31" paste = "1.0.7" diff --git a/bevy_mod_scripting_core/src/hosts.rs b/bevy_mod_scripting_core/src/hosts.rs index 2241f50e..7a946742 100644 --- a/bevy_mod_scripting_core/src/hosts.rs +++ b/bevy_mod_scripting_core/src/hosts.rs @@ -177,6 +177,7 @@ pub trait APIProvider: 'static + Send + Sync { fn register_with_app(&self, _app: &mut App) {} } +#[derive(Resource)] /// Stores many API providers pub struct APIProviders { pub providers: Vec< @@ -256,6 +257,7 @@ impl APIProviders { /// /// We keep this public for now since there is no API for communicating with scripts /// outside of events. Later this might change. +#[derive(Resource)] pub struct ScriptContexts { /// holds script contexts for all scripts given their instance ids. /// This also stores contexts which are not fully loaded hence the Option diff --git a/bevy_mod_scripting_core/src/lib.rs b/bevy_mod_scripting_core/src/lib.rs index d6303346..02cb150e 100644 --- a/bevy_mod_scripting_core/src/lib.rs +++ b/bevy_mod_scripting_core/src/lib.rs @@ -75,11 +75,11 @@ pub trait AddScriptHost { /// the given stage will contain systems handling script loading,re-loading, removal etc. /// This stage will also send events related to the script lifecycle. /// Any systems which need to run the same frame a script is loaded must run after this stage. - fn add_script_host(&mut self, stage: S) -> &mut Self; + fn add_script_host(&mut self, stage: S) -> &mut Self; } impl AddScriptHost for App { - fn add_script_host(&mut self, stage: S) -> &mut Self { + fn add_script_host(&mut self, stage: S) -> &mut Self where T: ScriptHost + Resource, S: StageLabel { T::register_with_app(self, stage); self.init_resource::(); self.add_event::(); @@ -143,14 +143,14 @@ pub trait AddScriptHostHandler { /// /// The *frequency* of running these events, is controlled by your systems, if the event is not emitted, it cannot not handled. /// Of course there is nothing stopping your from emitting a single event type at varying priorities. - fn add_script_handler_stage( + fn add_script_handler_stage( &mut self, stage: S, ) -> &mut Self; /// Like `add_script_handler_stage` but with additional run criteria fn add_script_handler_stage_with_criteria< - T: ScriptHost, + T: ScriptHost + Resource, S: StageLabel, M, C: IntoRunCriteria, @@ -164,14 +164,13 @@ pub trait AddScriptHostHandler { } impl AddScriptHostHandler for App { - fn add_script_handler_stage( + fn add_script_handler_stage( &mut self, stage: S, ) -> &mut Self { self.add_system_to_stage( stage, script_event_handler:: - .exclusive_system() .label(ScriptSystemLabel::EventHandling) .at_end(), ); @@ -179,7 +178,7 @@ impl AddScriptHostHandler for App { } fn add_script_handler_stage_with_criteria< - T: ScriptHost, + T: ScriptHost + Resource, S: StageLabel, M, C: IntoRunCriteria, @@ -193,7 +192,6 @@ impl AddScriptHostHandler for App { self.add_system_to_stage( stage, script_event_handler:: - .exclusive_system() .label(ScriptSystemLabel::EventHandling) .at_end() .with_run_criteria(criteria), diff --git a/bevy_mod_scripting_core/src/systems.rs b/bevy_mod_scripting_core/src/systems.rs index aebfd5cd..c5e9c525 100644 --- a/bevy_mod_scripting_core/src/systems.rs +++ b/bevy_mod_scripting_core/src/systems.rs @@ -4,7 +4,7 @@ use bevy::{ ecs::system::SystemState, prelude::{ debug, AssetEvent, Assets, ChangeTrackers, Changed, Entity, EventReader, EventWriter, - FromWorld, Query, RemovedComponents, Res, ResMut, SystemLabel, World, + FromWorld, Query, RemovedComponents, Res, ResMut, SystemLabel, World, Resource, }, }; use bevy_event_priority::PriorityEventReader; @@ -25,7 +25,7 @@ pub enum ScriptSystemLabel { /// Handles creating contexts for new/modified scripts /// Scripts are likely not loaded instantly at this point, so most of the time /// this system simply inserts an empty context -pub fn script_add_synchronizer( +pub fn script_add_synchronizer( query: Query< ( Entity, @@ -104,12 +104,12 @@ pub fn script_remove_synchronizer( query.iter().for_each(|v| { // we know that this entity used to have a script component // ergo a script context must exist in ctxts, remove all scripts on the entity - contexts.remove_context(v.id()); + contexts.remove_context(v.index()); }) } /// Reloads hot-reloaded scripts, or loads missing contexts for scripts which were added but not loaded -pub fn script_hot_reload_handler( +pub fn script_hot_reload_handler( mut events: EventReader>, mut host: ResMut, scripts: Query<&ScriptCollection>, @@ -150,7 +150,7 @@ pub fn script_hot_reload_handler( } /// Lets the script host handle all script events -pub fn script_event_handler(world: &mut World) { +pub fn script_event_handler(world: &mut World) { // we need to collect the events to drop the borrow of the world let mut state: CachedScriptState = world.remove_resource().unwrap(); @@ -205,8 +205,9 @@ pub fn script_event_handler(world world.insert_resource(providers); } +#[derive(Resource)] /// system state for exclusive systems dealing with script events -pub struct CachedScriptState<'w, 's, H: ScriptHost> { +pub struct CachedScriptState<'w : 'static, 's : 'static, H: ScriptHost> { pub event_state: SystemState<( PriorityEventReader<'w, 's, H::ScriptEvent>, EventWriter<'w, 's, ScriptErrorEvent>, diff --git a/bevy_script_api/Cargo.toml b/bevy_script_api/Cargo.toml index 3bcaf308..fec65eea 100644 --- a/bevy_script_api/Cargo.toml +++ b/bevy_script_api/Cargo.toml @@ -16,7 +16,7 @@ lua = ["bevy_mod_scripting_lua","bevy_mod_scripting_lua_derive"] rhai = ["bevy_mod_scripting_rhai"] [dependencies] -bevy = { version = "0.8.0", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite","filesystem_watcher"]} +bevy = { version = "0.9.1", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite","filesystem_watcher"]} bevy_mod_scripting_derive = { path="../bevy_mod_scripting_derive", version = "0.1.1"} bevy_mod_scripting_core = { path="../bevy_mod_scripting_core", version = "0.1.1"} parking_lot="0.12.1" diff --git a/bevy_script_api/src/generated.rs b/bevy_script_api/src/generated.rs index edf1c683..1b5a944c 100644 --- a/bevy_script_api/src/generated.rs +++ b/bevy_script_api/src/generated.rs @@ -53,6 +53,7 @@ use bevy::math::u32::UVec2; use bevy::math::u32::UVec3; use bevy::math::u32::UVec4; use bevy::math::EulerRot; +use bevy::math::Rect; use bevy::pbr::wireframe::Wireframe; use bevy::pbr::wireframe::WireframeConfig; use bevy::pbr::AlphaMode; @@ -68,7 +69,6 @@ use bevy::prelude::App; use bevy::render::camera::Camera; use bevy::render::camera::CameraProjection; use bevy::render::camera::CameraRenderGraph; -use bevy::render::camera::DepthCalculation; use bevy::render::camera::OrthographicProjection; use bevy::render::camera::PerspectiveProjection; use bevy::render::camera::Projection; @@ -88,7 +88,6 @@ use bevy::render::view::visibility::VisibleEntities; use bevy::render::view::Msaa; use bevy::sprite::Anchor; use bevy::sprite::Mesh2dHandle; -use bevy::sprite::Rect; use bevy::sprite::Sprite; use bevy::sprite::TextureAtlasSprite; use bevy::text::HorizontalAlign; @@ -101,6 +100,7 @@ use bevy::text::TextStyle; use bevy::text::VerticalAlign; use bevy::time::Stopwatch; use bevy::time::Timer; +use bevy::time::TimerMode; use bevy::transform::components::GlobalTransform; use bevy::transform::components::Transform; use bevy::ui::widget::Button; @@ -121,7 +121,6 @@ use bevy::ui::Node; use bevy::ui::Overflow; use bevy::ui::PositionType; use bevy::ui::Style; -use bevy::ui::UiColor; use bevy::ui::UiImage; use bevy::ui::Val; use bevy_mod_scripting_core::prelude::*; @@ -407,7 +406,6 @@ impl_script_newtype! { ) + BinOps ( - self Add Raw(f32) -> Wrapped(Val), ) + UnaryOps ( @@ -560,29 +558,6 @@ impl_script_newtype! { { } } -impl_script_newtype! { - #[languages(on_feature(lua))] - ///The color of the node - bevy_ui::UiColor : - Clone + - Debug + - Methods - ( - ) - + Fields - ( - 0: Wrapped(Color), - ) - + BinOps - ( - ) - + UnaryOps - ( - ) - lua impl - { - } -} impl_script_newtype! { #[languages(on_feature(lua))] ///The image of the node @@ -1131,6 +1106,27 @@ impl_script_newtype! { { } } +impl_script_newtype! { + #[languages(on_feature(lua))] + bevy_time::timer::TimerMode : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + lua impl + { + } +} impl_script_newtype! { #[languages(on_feature(lua))] ///Tracks elapsed time. Enters the finished state once `duration` is reached. @@ -1152,7 +1148,7 @@ impl_script_newtype! { ///# use bevy_time::*; ///let mut timer = Timer::from_seconds(1.0, false); ///``` - from_seconds(Raw(f32),Raw(bool)) -> self, + from_seconds(Raw(f32),Wrapped(TimerMode)) -> self, ///Returns `true` if the timer has reached its duration. /// @@ -1186,26 +1182,26 @@ impl_script_newtype! { ///See also [`Timer::elapsed`](Timer::elapsed). elapsed_secs(&self:) -> Raw(f32), - ///Returns `true` if the timer is repeating. + ///Returns the mode the timer is using /// ///# Examples ///``` ///# use bevy_time::*; - ///let mut timer = Timer::from_seconds(1.0, true); - ///assert!(timer.repeating()); + ///let mut timer = Timer::from_seconds(1.0, TimerMode::Repeating); + ///asserteq!(timer.mode(), TimerMode::Repeating); ///``` - repeating(&self:) -> Raw(bool), + mode(&self:) -> Wrapped(TimerMode), ///Sets whether the timer is repeating or not. /// ///# Examples ///``` ///# use bevy_time::*; - ///let mut timer = Timer::from_seconds(1.0, true); - ///timer.set_repeating(false); - ///assert!(!timer.repeating()); + ///let mut timer = Timer::from_seconds(1.0, TimerMode::Repeating); + ///timer.set_mode(TimerMode::Once); + ///asserteq!(timer.mode(), TimerMode::Once); ///``` - set_repeating(&mut self:Raw(bool)), + set_mode(&mut self:Wrapped(TimerMode)), ///Pauses the Timer. Disables the ticking of the timer. /// @@ -1455,7 +1451,7 @@ impl_script_newtype! { ///No two simultaneously-live entities share the same ID, but dead entities' IDs may collide ///with both live and dead entities. Useful for compactly representing entities within a ///specific snapshot of the world, such as when serializing. - id(self:) -> Raw(u32), + index(self:) -> Raw(u32), ///Returns the generation of this Entity's id. The generation is incremented each time an ///entity with a given id is despawned. This serves as a "count" of the number of times a @@ -1511,7 +1507,7 @@ impl_script_newtype! { ///Creates a new identity [`Transform`], with no translation, rotation, and a scale of 1 on ///all axes. - identity() -> self, + default() -> self, ///Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine ///transformation matrix. @@ -1638,13 +1634,6 @@ impl_script_newtype! { ///resulting [`Transform`] mul_transform(&self:Wrapped(Transform)) -> self, - ///Returns a [`Vec3`] of this [`Transform`] applied to `value`. - mul_vec3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), - - ///Changes the `scale` of this [`Transform`], multiplying the current `scale` by - ///`scale_factor`. - apply_non_uniform_scale(&mut self:Wrapped(Vec3)), - ) + Fields ( @@ -1707,7 +1696,7 @@ impl_script_newtype! { compute_transform(&self:) -> Wrapped(Transform), ///Creates a new identity [`GlobalTransform`], that maps all points in space to themselves. - identity() -> self, + default() -> self, ///Return the local right vector (X). right(&self:) -> Wrapped(Vec3), @@ -1736,9 +1725,6 @@ impl_script_newtype! { ///Get an upper bound of the radius from the given `extents`. radius_vec3a(&self:Wrapped(Vec3A)) -> Raw(f32), - ///Returns a [`Vec3`] of this [`Transform`] applied to `value`. - mul_vec3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), - ///Multiplies `self` with `transform` component by component, returning the ///resulting [`GlobalTransform`] mul_transform(&self:Wrapped(Transform)) -> self, @@ -2293,7 +2279,7 @@ impl_script_newtype! { #[languages(on_feature(lua))] ///A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere ///(top-left, bottom-left, etc) - bevy_sprite::Rect : + bevy::math::Rect : Clone + Debug + Methods @@ -2381,7 +2367,7 @@ impl_script_newtype! { Methods ( ///Creates a new [`Visibility`], set as visible - visible() -> self, + default() -> self, ) + Fields @@ -2447,7 +2433,7 @@ impl_script_newtype! { Methods ( ///Creates a new [`ComputedVisibility`], set as not visible - not_visible() -> self, + default() -> self, ///Whether this entity is visible to something this frame. This is true if and only if [`Self::is_visible_in_hierarchy`] and [`Self::is_visible_in_view`] ///are true. This is the canonical method to call to determine if an entity should be drawn. @@ -2774,8 +2760,6 @@ impl_script_newtype! { /// If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this /// camera will not be rendered. is_active: Raw(bool), - /// The method used to calculate this camera's depth. This will be used for projections and visibility. - depth_calculation: Wrapped(DepthCalculation), /// The "target" that this camera will render to. target: Wrapped(RenderTarget), ) @@ -2858,8 +2842,6 @@ impl_script_newtype! { update(&mut self:Raw(f32),Raw(f32)), - depth_calculation(&self:) -> Wrapped(DepthCalculation), - far(&self:) -> Raw(f32), ) @@ -2887,8 +2869,6 @@ impl_script_newtype! { update(&mut self:Raw(f32),Raw(f32)), - depth_calculation(&self:) -> Wrapped(DepthCalculation), - far(&self:) -> Raw(f32), ) @@ -2904,8 +2884,6 @@ impl_script_newtype! { window_origin: Wrapped(WindowOrigin), scaling_mode: Wrapped(ScalingMode), scale: Raw(f32), - #[rename("_depth_calculation")] - depth_calculation: Wrapped(DepthCalculation), ) + BinOps ( @@ -2928,8 +2906,6 @@ impl_script_newtype! { update(&mut self:Raw(f32),Raw(f32)), - depth_calculation(&self:) -> Wrapped(DepthCalculation), - far(&self:) -> Raw(f32), ) @@ -2951,27 +2927,6 @@ impl_script_newtype! { { } } -impl_script_newtype! { - #[languages(on_feature(lua))] - bevy_render::camera::DepthCalculation : - Clone + - Debug + - Methods - ( - ) - + Fields - ( - ) - + BinOps - ( - ) - + UnaryOps - ( - ) - lua impl - { - } -} impl_script_newtype! { #[languages(on_feature(lua))] ///Configures the [`RenderGraph`](crate::render_graph::RenderGraph) name assigned to be run for a given [`Camera`] entity. @@ -8366,11 +8321,8 @@ impl_script_newtype! { ) + BinOps ( - self Add self -> Wrapped(Affine2), - self Sub self -> Wrapped(Affine2), self Mul Wrapped(Affine2) -> Wrapped(Affine2), self Mul Wrapped(Affine2) -> Wrapped(Affine2), - self Mul Raw(f32) -> Wrapped(Affine2), self Mul Wrapped(Mat3) -> Wrapped(Mat3), self Mul Wrapped(Mat3A) -> Wrapped(Mat3A), ) @@ -8515,11 +8467,8 @@ impl_script_newtype! { ) + BinOps ( - self Add self -> Wrapped(Affine3A), - self Sub self -> Wrapped(Affine3A), self Mul Wrapped(Affine3A) -> Wrapped(Affine3A), self Mul Wrapped(Affine3A) -> Wrapped(Affine3A), - self Mul Raw(f32) -> Wrapped(Affine3A), self Mul Wrapped(Mat4) -> Wrapped(Mat4), ) + UnaryOps @@ -8618,11 +8567,8 @@ impl_script_newtype! { ) + BinOps ( - self Add self -> Wrapped(DAffine2), - self Sub self -> Wrapped(DAffine2), self Mul Wrapped(DAffine2) -> Wrapped(DAffine2), self Mul Wrapped(DAffine2) -> Wrapped(DAffine2), - self Mul Raw(f64) -> Wrapped(DAffine2), self Mul Wrapped(DMat3) -> Wrapped(DMat3), ) + UnaryOps @@ -8757,11 +8703,8 @@ impl_script_newtype! { ) + BinOps ( - self Add self -> Wrapped(DAffine3), - self Sub self -> Wrapped(DAffine3), self Mul Wrapped(DAffine3) -> Wrapped(DAffine3), self Mul Wrapped(DAffine3) -> Wrapped(DAffine3), - self Mul Raw(f64) -> Wrapped(DAffine3), self Mul Wrapped(DMat4) -> Wrapped(DMat4), ) + UnaryOps @@ -9578,7 +9521,6 @@ impl APIProvider for LuaBevyAPIProvider { .process_type::() .process_type::() .process_type::() - .process_type::() .process_type::() .process_type::() .process_type::() @@ -9656,7 +9598,6 @@ impl APIProvider for LuaBevyAPIProvider { .process_type::() .process_type::() .process_type::() - .process_type::() .process_type::() .process_type::>() .process_type::() @@ -9785,7 +9726,6 @@ impl APIProvider for LuaBevyAPIProvider { app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::