Skip to content

remove unnecessary mut borrow and write access in chap 2 #194

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
remove unnecessary mut borrow and write access
  • Loading branch information
xysun committed Jul 31, 2022
commit 3496aad3889b276faea2a46d9b6412b6fe2be738
6 changes: 3 additions & 3 deletions chapter-02-helloecs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ struct State {

fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
let mut positions = ecs.write_storage::<Position>();
let mut players = ecs.write_storage::<Player>();
let players = ecs.read_storage::<Player>();

for (_player, pos) in (&mut players, &mut positions).join() {
for (_player, pos) in (&players, &mut positions).join() {
pos.x = min(79 , max(0, pos.x + delta_x));
pos.y = min(49, max(0, pos.y + delta_y));
}
}

fn player_input(gs: &mut State, ctx: &mut Rltk) {
fn player_input(gs: &mut State, ctx: &Rltk) {
// Player movement
match ctx.key {
None => {} // Nothing happened
Expand Down