diff --git a/.github/workflows/pr-titles.yml b/.github/workflows/pr-titles.yml index d5e92a5a6c..5a2c6a2ff6 100644 --- a/.github/workflows/pr-titles.yml +++ b/.github/workflows/pr-titles.yml @@ -28,6 +28,7 @@ jobs: docs refactor perf + changed scopes: | ladfile 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 1b4e4e1509..f1a5b3bbf0 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/script_system.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/script_system.rs @@ -15,7 +15,7 @@ use crate::{ error::{InteropError, ScriptError}, event::CallbackLabel, extractors::get_all_access_ids, - handler::CallbackSettings, + handler::ScriptingHandler, runtime::RuntimeContainer, script::{ScriptAttachment, ScriptContext}, IntoScriptPluginParams, @@ -200,7 +200,6 @@ impl ScriptSystemBuilder { struct DynamicHandlerContext<'w, P: IntoScriptPluginParams> { script_context: &'w ScriptContext
, - callback_settings: &'w CallbackSettings
, context_loading_settings: &'w ContextLoadingSettings
, runtime_container: &'w RuntimeContainer
,
}
@@ -215,9 +214,6 @@ impl<'w, P: IntoScriptPluginParams> DynamicHandlerContext<'w, P> {
let mut access = FilteredAccess:: >();
- let callback_settings_res_id = world
- .resource_id:: ::call(
- handler,
+ P::handle(
payload,
context_key,
label,
diff --git a/crates/bevy_mod_scripting_core/src/extractors.rs b/crates/bevy_mod_scripting_core/src/extractors.rs
index e72ea9172e..ca4abd3417 100644
--- a/crates/bevy_mod_scripting_core/src/extractors.rs
+++ b/crates/bevy_mod_scripting_core/src/extractors.rs
@@ -3,6 +3,7 @@
//! These are designed to be used to pipe inputs into other systems which require them, while handling any configuration erorrs nicely.
#![allow(deprecated)]
use crate::bindings::pretty_print::DisplayWithWorld;
+use crate::handler::ScriptingHandler;
use crate::{
bindings::{
access_map::ReflectAccessId, script_value::ScriptValue, WorldAccessGuard, WorldGuard,
@@ -10,7 +11,6 @@ use crate::{
context::ContextLoadingSettings,
error::{InteropError, ScriptError},
event::{CallbackLabel, IntoCallbackLabel},
- handler::CallbackSettings,
runtime::RuntimeContainer,
script::{ScriptAttachment, ScriptContext, StaticScripts},
IntoScriptPluginParams,
@@ -122,8 +122,6 @@ unsafe impl ,
/// Settings for loading contexts
pub(crate) context_loading_settings: ContextLoadingSettings ,
/// The runtime container
@@ -139,7 +137,6 @@ impl {
/// Every call to this function must be paired with a call to [`Self::release`].
pub fn yoink(world: &mut World) -> Self {
Self {
- callback_settings: world.remove_resource().unwrap_or_default(),
context_loading_settings: world.remove_resource().unwrap_or_default(),
runtime_container: world.remove_resource().unwrap_or_default(),
static_scripts: world.remove_resource().unwrap_or_default(),
@@ -151,7 +148,6 @@ impl {
/// Only call this if you have previously yoinked the handler context from the world.
pub fn release(self, world: &mut World) {
// insert the handler context back into the world
- world.insert_resource(self.callback_settings);
world.insert_resource(self.context_loading_settings);
world.insert_resource(self.runtime_container);
world.insert_resource(self.static_scripts);
@@ -165,24 +161,17 @@ impl {
pub fn destructure(
&mut self,
) -> (
- &mut CallbackSettings ,
&mut ContextLoadingSettings ,
&mut RuntimeContainer ,
&mut StaticScripts,
) {
(
- &mut self.callback_settings,
&mut self.context_loading_settings,
&mut self.runtime_container,
&mut self.static_scripts,
)
}
- /// Get the callback settings
- pub fn callback_settings(&mut self) -> &mut CallbackSettings {
- &mut self.callback_settings
- }
-
/// Get the context loading settings
pub fn context_loading_settings(&mut self) -> &mut ContextLoadingSettings {
&mut self.context_loading_settings
@@ -226,7 +215,6 @@ impl {
};
// call the script
- let handler = self.callback_settings.callback_handler;
let pre_handling_initializers = &self
.context_loading_settings
.context_pre_handling_initializers;
@@ -234,8 +222,7 @@ impl {
let mut context = context.lock();
- CallbackSettings:: ::call(
- handler,
+ P::handle(
payload,
context_key,
label,
diff --git a/crates/bevy_mod_scripting_core/src/handler.rs b/crates/bevy_mod_scripting_core/src/handler.rs
index f6be314c6e..6408a508b9 100644
--- a/crates/bevy_mod_scripting_core/src/handler.rs
+++ b/crates/bevy_mod_scripting_core/src/handler.rs
@@ -17,7 +17,6 @@ use crate::{
use bevy::{
ecs::{
event::EventCursor,
- resource::Resource,
system::{Local, SystemState},
world::{Mut, World},
},
@@ -35,39 +34,26 @@ pub type HandlerFn = fn(
runtime: & ::R,
) -> Result ,
-}
-
-impl {
- fn default() -> Self {
- Self {
- callback_handler: |_, _, _, _, _, _| Ok(ScriptValue::Unit),
- }
- }
-}
-
-impl {
- fn clone(&self) -> Self {
- Self {
- callback_handler: self.callback_handler,
- }
- }
+/// A utility trait, implemented for all types implementing `IntoScriptPluginParams`.
+///
+/// Calls the underlying handler function with the provided arguments and context.
+/// Implementations will handle the necessary thread local context emplacement and retrieval.
+pub trait ScriptingHandler ],
+ runtime: &P::R,
+ world: WorldGuard,
+ ) -> Result {
- /// Creates a new callback settings resource with the given handler function
- pub fn new(callback_handler: HandlerFn ) -> Self {
- Self { callback_handler }
- }
-
+impl for P {
/// Calls the handler function while providing the necessary thread local context
- pub fn call(
- handler: HandlerFn ,
+ fn handle(
args: Vec {
) -> Result ,
- /// The handler used for executing callbacks in scripts
- pub callback_handler: HandlerFn ,
+
/// The context builder for loading contexts
pub context_builder: ContextBuilder ,
@@ -103,7 +105,6 @@ where
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ScriptingPlugin")
- .field("callback_handler", &self.callback_handler)
.field("context_policy", &self.context_policy)
.field("language", &self.language)
.field("context_initializers", &self.context_initializers)
@@ -120,7 +121,6 @@ impl {
fn default() -> Self {
Self {
runtime_settings: Default::default(),
- callback_handler: CallbackSettings:: ::default().callback_handler,
context_builder: Default::default(),
context_policy: ContextPolicy::default(),
language: Default::default(),
@@ -138,9 +138,6 @@ impl {
.insert_resource::