@@ -8,7 +8,7 @@ use std::{
8
8
9
9
use bevy:: {
10
10
app:: { Last , Plugin , PostUpdate , Startup , Update } ,
11
- asset:: { AssetServer , Handle } ,
11
+ asset:: { AssetServer , Handle , AssetPath , AssetId } ,
12
12
ecs:: {
13
13
component:: Component ,
14
14
event:: { Event , Events } ,
@@ -55,13 +55,15 @@ struct TestCallbackBuilder<P: IntoScriptPluginParams, L: IntoCallbackLabel> {
55
55
}
56
56
57
57
impl < L : IntoCallbackLabel , P : IntoScriptPluginParams > TestCallbackBuilder < P , L > {
58
- fn build ( script_id : impl Into < ScriptId > , expect_response : bool ) -> SystemConfigs {
59
- let script_id = script_id . into ( ) ;
58
+ fn build < ' a > ( script_path : impl Into < AssetPath < ' a > > , expect_response : bool ) -> SystemConfigs {
59
+ let script_path = script_path . into ( ) . into_owned ( ) ;
60
60
IntoSystem :: into_system (
61
61
move |world : & mut World ,
62
62
system_state : & mut SystemState < WithWorldGuard < HandlerContext < P > > > | {
63
+ let script_id = world. resource :: < AssetServer > ( ) . load ( script_path. clone ( ) ) . id ( ) ;
64
+
63
65
let with_guard = system_state. get_mut ( world) ;
64
- let _ = run_test_callback :: < P , L > ( & script_id. clone ( ) , with_guard, expect_response) ;
66
+ let _ = run_test_callback :: < P , L > ( & script_id, with_guard, expect_response) ;
65
67
66
68
system_state. apply ( world) ;
67
69
} ,
@@ -296,18 +298,18 @@ pub fn execute_integration_test<
296
298
}
297
299
298
300
fn run_test_callback < P : IntoScriptPluginParams , C : IntoCallbackLabel > (
299
- script_id : & str ,
301
+ script_id : & ScriptId ,
300
302
mut with_guard : WithWorldGuard < ' _ , ' _ , HandlerContext < ' _ , P > > ,
301
303
expect_response : bool ,
302
304
) -> Result < ScriptValue , ScriptError > {
303
305
let ( guard, handler_ctxt) = with_guard. get_mut ( ) ;
304
306
305
- if !handler_ctxt. is_script_fully_loaded ( script_id. to_string ( ) . into ( ) ) {
307
+ if !handler_ctxt. is_script_fully_loaded ( * script_id) {
306
308
return Ok ( ScriptValue :: Unit ) ;
307
309
}
308
310
309
311
let res = handler_ctxt. call :: < C > (
310
- & script_id. to_string ( ) . into ( ) ,
312
+ & script_id,
311
313
Entity :: from_raw ( 0 ) ,
312
314
vec ! [ ] ,
313
315
guard. clone ( ) ,
@@ -406,9 +408,9 @@ pub fn run_rhai_benchmark<M: criterion::measurement::Measurement>(
406
408
)
407
409
}
408
410
409
- pub fn run_plugin_benchmark < P , F , M : criterion:: measurement:: Measurement > (
411
+ pub fn run_plugin_benchmark < ' a , P , F , M : criterion:: measurement:: Measurement > (
410
412
plugin : P ,
411
- script_id : & str ,
413
+ script_path : impl Into < AssetPath < ' a > > ,
412
414
label : & str ,
413
415
criterion : & mut criterion:: BenchmarkGroup < M > ,
414
416
bench_fn : F ,
@@ -425,14 +427,22 @@ where
425
427
426
428
install_test_plugin ( & mut app, plugin, true ) ;
427
429
428
- let script_id = script_id. to_owned ( ) ;
429
- let script_id_clone = script_id. clone ( ) ;
430
- app. add_systems (
431
- Startup ,
432
- move |server : Res < AssetServer > , mut handle : Local < Handle < ScriptAsset > > | {
433
- * handle = server. load ( script_id_clone. to_owned ( ) ) ;
434
- } ,
435
- ) ;
430
+ // let script_id = script_id.to_owned();
431
+ // let script_id_clone = script_id.clone();
432
+
433
+
434
+ let script_path = script_path. into ( ) ;
435
+ let script_handle = app. world ( ) . resource :: < AssetServer > ( ) . load ( script_path) ;
436
+ let script_id = script_handle. id ( ) ;
437
+
438
+
439
+ // app.add_systems(
440
+ // Startup,
441
+ // move |server: Res<AssetServer>, mut handle: Local<Handle<ScriptAsset>>| {
442
+ // *handle = server.load(script_id_clone.to_owned());
443
+ // handle.id()
444
+ // },
445
+ // );
436
446
437
447
// finalize
438
448
app. cleanup ( ) ;
@@ -482,7 +492,7 @@ pub fn run_plugin_script_load_benchmark<
482
492
benchmark_id : & str ,
483
493
content : & str ,
484
494
criterion : & mut criterion:: BenchmarkGroup < M > ,
485
- script_id_generator : impl Fn ( u64 ) -> String ,
495
+ script_id_generator : impl Fn ( u64 ) -> AssetId < ScriptAsset > ,
486
496
reload_probability : f32 ,
487
497
) {
488
498
let mut app = setup_integration_test ( |_, _| { } ) ;
@@ -502,7 +512,7 @@ pub fn run_plugin_script_load_benchmark<
502
512
let content = content. to_string ( ) . into_boxed_str ( ) ;
503
513
(
504
514
CreateOrUpdateScript :: < P > :: new (
505
- random_script_id. into ( ) ,
515
+ random_script_id,
506
516
content. clone ( ) . into ( ) ,
507
517
None ,
508
518
) ,
0 commit comments