Closed PudgeKim closed 5 months ago
As you noticed, you have to hook into something shipyard understands, which is going to be either run_if
or skip_if
.
I'm pretty sure you can't impl sys2
, you could in theory make it generic but then you wouldn't be able to specify is_excluded
for each system so it would be useless.
If you plan on having a macro then one of the easiest way is to wrap the system with skip_if
.
fn some_test() { ... }
#[exclude(some_test)]
fn sys2(c1: View<Component1>, c2: UniqueView<Component2>, ...) { .. }
would expend to:
fn some_test() { ... }
fn sys2() -> WorkloadSystem {
fn sys2(c1: View<Component1>, c2: UniqueView<Component2>, ...) { .. }
sys2.skip_if(some_test)
}
I just pushed a commit to make fn sys2() -> WorkloadSystem
work like a "system generator".
Before the commit you'd have to use sys2()
to add it to a workload, now you can use sys2
.
hmm.. I don't understand sys2.skip_if(some_test)
.
skip_if
method needs IntoRunIf
trait as a parameter.
#[track_caller]
fn skip_if<RunB, Run: IntoRunIf<RunB>>(self, run_if: Run) -> WorkloadSystem {
let mut run_if = run_if.into_workload_run_if().unwrap();
run_if.system_fn = Box::new(move |world| (run_if.system_fn)(world).map(Not::not));
SystemModificator::<($($type,)+), R>::run_if(self, run_if)
}
skip_if
accepts any system that returns bool
.
Wait a second.
I'll write this macro which implements WorkloadExclusion trait to true in test_environment
If you want to run a system only during tests then why not:
fn workload() -> Workload {
(
sys1,
#[cfg(test)]
sys2,
sys3,
)
}
// OR
#[cfg(test)]
fn sys2(c1: View<Component1>, c2: UniqueView<Component2>, ...) { .. }
#[cfg(not(test))]
fn sys2() {}
oh IntoRunIf
implements for 'static + Send + Sync + Fn() -> bool
.
Actually, using #[cfg]
and #[cfg(not(..)]
was my first plan. (I think I'll do my first plan)
I wondered there's some shipyard way. anyway thank you!
I want to impl the trait above to all System trait.
In my case, I don't need
Data
andReturn
but I don't know how to treatBorrow
. My goal is some systems which implementWorkloadExclusion
'sis_excluded
to true should be excluded when the code below runs.There are some macros in shipyard code so I don't know where to fix it exactly.
--- edited ---
It seems WorkloadExclusion trait also should be implemented to WorkloadSystem struct. My final goal is like
---- edited2 ----
I found
SystemModificator
/WorkloadModificator
trait. and there'srun_if
method. Can I use this to reach my goal? (It seems I can't use IntoRunIf trait ..? even it's pub trait. what should I import to use it?)