-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run a system from a command #2234
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
95778ad
run a system from a command
mockersf cbf8e67
newline in example
mockersf fbdcc2c
use config
mockersf 36f5842
make the system actually pub
mockersf dd77f75
remove refcell
mockersf db16c7c
and remove the mutex
mockersf 0a48e64
example comment
mockersf ae3cb43
apply buffers from the one off system (commands)
mockersf f07d886
system yeet
mockersf c40f8cb
better doc
mockersf a10fc4d
update for AppBuilder removal
mockersf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use bevy::{prelude::*, utils::Duration}; | ||
|
||
/// This example triggers a system from a command | ||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_startup_system(spawn) | ||
.add_system(trigger_sync) | ||
.run(); | ||
} | ||
|
||
pub struct Player; | ||
|
||
/// Spawn some players to sync | ||
fn spawn(mut commands: Commands) { | ||
commands.spawn().insert(Player); | ||
commands.spawn().insert(Player); | ||
} | ||
|
||
fn trigger_sync(mut commands: Commands, mut last_sync: Local<f64>, time: Res<Time>) { | ||
if time.seconds_since_startup() - *last_sync > 5.0 { | ||
commands | ||
.run_system(sync_system.config(|config| config.1 = Some(time.time_since_startup()))); | ||
*last_sync = time.seconds_since_startup(); | ||
} | ||
} | ||
|
||
/// As this system is run through a command, it will run at the end of the current stage. | ||
fn sync_system(players: Query<&Player>, since_startup: Local<Duration>) { | ||
for _player in players.iter() { | ||
// do the sync | ||
} | ||
info!( | ||
"synced: {} players ({:?})", | ||
players.iter().len(), | ||
*since_startup | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this makes it seem like a copy paste error in my head haha 😅
Could we change this to be like
for _ in 0..5
or something similar?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a copy paste! from
bevy/examples/ecs/system_param.rs
Lines 33 to 35 in 653c103
But I removed one just to be different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still prefer the
for - in
syntax, but I guess I'm ok with how it is.