Allow Commands to register systems#11019
Conversation
…create new SystemId
… push a system into an already created entity
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
…bevy into register_system_with_commands
|
While at it, is it a good Idea to add tests for testing Commands::run_system and Commands::register_system in system_registry.rs? |
|
I will never say no to more tests :D I think in this case we should probably split them out into a seperate PR if we can: I suspect they'll be much faster to merge that way. |
|
Regarding the matter about verifying if the System was already registred before, found out something fn do_something() {}
fn do_another_something() {}
// If we cast the function into an pointer, we can found out the actual address of the function, which can be very useful
assert_ne!(do_something as usize, do_another_something as usize);
// That same thing is possible with closure, with a little problem though
let closure_one = || {};
let closure_two = || {};
assert_ne!(closure_one as fn() as usize, closure_two as fn() as usize);
// Closures must be casted first as a function, then into an address for this to work
// Last, with the same problem, closures created from a function can't be casted into an Address
// But if you pass the function into a var first, it can later be casted into an address from inside the function
// This works
fn get_closure_address() -> usize {
let closure = || {};
closure as fn() as usize
}
// This doesn't
fn get_closure_address() -> impl Fn() {
|| {}
}
let closure = get_closure_address();
closure as fn() as usize // Can't be castedMaybe that can be useful |
|
It would be cool if you added |
|
Made an doc-test, but not sure if that is the best doc-test In this situation. Must I assert that the function is indeed an System or maybe assert that the run will make the Counter value change? |
I think the latter is more robust. |
You mean that's too much for this doc Test or more robust like "better"? |
|
Better :) Less likely to pass while the functionality is broken. |
|
Done it, now the doc verify both: If the function is a system and if the run affect the counter, asserting that the system is registered |
jdm
left a comment
There was a problem hiding this comment.
Nice usability improvement, and I found the example very helpful!
|
I'll solve conflicts today :) |
# Objective - `SystemId`'s `Debug` implementation includes its `entity` field twice. - This was likely an oversight in #11019, since before that PR the second field was the `PhantomData` one. ## Solution - Only include it once Alternatively, this could be changed to match the struct representation of `SystemId`, thus instructing the formatter to print a named struct and including the `PhantomData` field.
Objective
Commands::register_one_shot_systemSolution
RegisterSystemfor Commands use.Changelog
Added
RegisterSystemCommands::register_one_shot_systemApp::register_one_shot_systemChanged
Migration Guide
If you want to access the entity field, you should use
SystemId::entityinstead ofSystemId::0Showcase