@@ -267,24 +267,41 @@ pub fn machine_ticker<P: IntoScriptPluginParams>(world: &mut World) {
267
267
}
268
268
/// A command which triggers the script processing pipeline to run once,
269
269
/// causing outstanding attachment events to be processed
270
- pub struct RunProcessingPipelineOnce < P > ( PhantomData < fn ( P ) > ) ;
270
+ pub struct RunProcessingPipelineOnce < P > {
271
+ override_budget : Option < Duration > ,
272
+ _ph : PhantomData < fn ( P ) > ,
273
+ }
271
274
272
275
impl < P > RunProcessingPipelineOnce < P > {
273
- /// Creates a new [`RunProcessingPipelineOnce`] command for the given plugin
274
- pub fn new ( ) -> Self {
275
- Self ( Default :: default ( ) )
276
+ /// Creates a new [`RunProcessingPipelineOnce`] command for the given plugin.
277
+ /// The budget override can be used to make sure all scripts in the pipeline get fully processed in one go
278
+ pub fn new ( override_budget : Option < Duration > ) -> Self {
279
+ Self {
280
+ override_budget,
281
+ _ph : PhantomData ,
282
+ }
276
283
}
277
284
}
278
285
279
286
impl < P > Default for RunProcessingPipelineOnce < P > {
280
287
fn default ( ) -> Self {
281
- Self :: new ( )
288
+ Self :: new ( None )
282
289
}
283
290
}
284
291
285
292
impl < P : IntoScriptPluginParams > Command for RunProcessingPipelineOnce < P > {
286
293
fn apply ( self , world : & mut World ) {
294
+ let mut last_setting = None ;
295
+ if let Some ( override_budget) = self . override_budget {
296
+ let mut machines = world. get_resource_or_init :: < ActiveMachines < P > > ( ) ;
297
+ last_setting = Some ( machines. budget ) ;
298
+ machines. budget = Some ( override_budget)
299
+ }
287
300
world. run_schedule ( ScriptProcessingSchedule :: < P > :: default ( ) ) ;
301
+ if let Some ( last_setting) = last_setting {
302
+ let mut machines = world. get_resource_or_init :: < ActiveMachines < P > > ( ) ;
303
+ machines. budget = last_setting;
304
+ }
288
305
}
289
306
}
290
307
@@ -326,7 +343,7 @@ pub fn automatic_pipeline_runner<P: IntoScriptPluginParams>(world: &mut World) {
326
343
. get_resource :: < ActiveMachines < P > > ( )
327
344
. is_some_and ( |machines| machines. active_machines ( ) > 0 )
328
345
{
329
- RunProcessingPipelineOnce :: < P > :: new ( ) . apply ( world) ;
346
+ RunProcessingPipelineOnce :: < P > :: new ( None ) . apply ( world) ;
330
347
}
331
348
}
332
349
@@ -353,8 +370,12 @@ impl PipelineRun for App {
353
370
#[ cfg( test) ]
354
371
mod test {
355
372
use bevy_asset:: { AssetApp , AssetId , AssetPlugin } ;
356
- use bevy_ecs:: { system:: SystemState , world:: FromWorld } ;
373
+ use bevy_ecs:: { entity :: Entity , system:: SystemState , world:: FromWorld } ;
357
374
use bevy_mod_scripting_asset:: Language ;
375
+ use bevy_mod_scripting_bindings:: ScriptValue ;
376
+ use test_utils:: make_test_plugin;
377
+
378
+ use crate :: config:: { GetPluginThreadConfig , ScriptingPluginConfiguration } ;
358
379
359
380
use super :: * ;
360
381
#[ test]
@@ -404,4 +425,25 @@ mod test {
404
425
assert ! ( loaded. is_empty( ) )
405
426
}
406
427
}
428
+
429
+ make_test_plugin ! ( crate ) ;
430
+
431
+ #[ test]
432
+ fn test_run_override_is_undid ( ) {
433
+ let mut app = App :: default ( ) ;
434
+ app. add_event :: < ScriptAttachedEvent > ( ) ;
435
+
436
+ app. add_plugins ( ( AssetPlugin :: default ( ) , TestPlugin :: default ( ) ) ) ;
437
+ app. init_asset :: < ScriptAsset > ( ) ;
438
+ let mut machines = ActiveMachines :: < TestPlugin > :: default ( ) ;
439
+ machines. budget = None ;
440
+ app. insert_resource ( machines) ;
441
+ app. finish ( ) ;
442
+
443
+ let world = app. world_mut ( ) ;
444
+ RunProcessingPipelineOnce :: < TestPlugin > :: new ( Some ( Duration :: from_secs ( 1 ) ) ) . apply ( world) ;
445
+
446
+ let machines = world. get_resource :: < ActiveMachines < TestPlugin > > ( ) . unwrap ( ) ;
447
+ assert_eq ! ( machines. budget, None ) ;
448
+ }
407
449
}
0 commit comments