Replies: 2 comments 1 reply
-
In this case you want to use a It might end up looking like the following: pub fn try_move_player(ecs: &mut World, delta_x: i32, delta_y: i32) -> RunState {
// Construct a `SystemState` struct, passing in a tuple of `SystemParam`
// as if you were writing an ordinary system.
let mut system_state: SystemState<(
ResMut<Map>,
ResMut<GameLog>,
Query<(Entity, &mut Position, &mut Viewshed), With<Player>>,
Query<&CombatStats>,
)> = SystemState::new(&mut ecs);
let (
mut map,
mut log,
mut query,
combat_stats,
) = system_state.get_mut(&mut ecs);
if let Ok((entity, mut pos, mut viewshed)) = query.get_single_mut() {
// Blahblah, code you already wrote
} else {
RunState::AwaitingInput
}
} As you correctly intuited, the problem is that rust doesn't know you are borrowing different bits of |
Beta Was this translation helpful? Give feedback.
1 reply
-
I ended up using @nicopap 's direct answer to come up with a somewhat different approach using one-shot systems: pub fn try_move_player_system(
In(dx_dy): In<(i32, i32)>,
mut commands: Commands,
mut log: ResMut<GameLog>,
mut map: ResMut<Map>,
mut query: Query<(Entity, &mut Position, &mut Viewshed), With<Player>>, // need mutable?
combat_stats: Query<&CombatStats>,
) -> RunState {
let (delta_x, delta_y) = dx_dy;
// ...
}
pub fn try_move_player(ecs: &mut World, delta_x: i32, delta_y: i32) -> RunState {
ecs.run_system_once_with((delta_x, delta_y), try_move_player_system)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been porting some specs ECS code to bevy's ecs, and currently i'm looking at rewriting this function:
However, I'm getting many errors related to mutably borrowing ecs multiple times, which has me feeling that I'm going against the grain. How would it be best to structure this in bevy?
Beta Was this translation helpful? Give feedback.
All reactions