From a24c1259a3317cf301a44296a5573d305b6fa30e Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Sat, 6 Jun 2026 11:11:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20-=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake-game/src/gameplay.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/snake-game/src/gameplay.rs b/snake-game/src/gameplay.rs index f8fba6b..a6c5998 100644 --- a/snake-game/src/gameplay.rs +++ b/snake-game/src/gameplay.rs @@ -11,6 +11,7 @@ pub fn head_rotation( query: Single<(&mut Transform, &Direction), With>, mut snake_path: ResMut, ) { + let _span = trace_span!("head_rotation").entered(); if input.just_pressed(KeyCode::ArrowLeft) { let (mut transform, direction) = query.into_inner(); let translation = transform.translation.clone(); @@ -19,15 +20,15 @@ pub fn head_rotation( let mut new_direction = direction.clone(); new_direction.rotate_left(); if !snake_path.push(dst_pos, new_direction) { - trace!("head_rotation - try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); + trace!("try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); dst_pos.shift(&direction); if !snake_path.push(dst_pos, new_direction) { - trace!("head_rotation - try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); + trace!("try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); return; } } transform.rotation = new_direction.orientation(); - trace!("head_rotation - running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}"); + trace!("running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}"); } else if input.just_pressed(KeyCode::ArrowRight) { let (mut transform, direction) = query.into_inner(); let translation = transform.translation.clone(); @@ -36,15 +37,15 @@ pub fn head_rotation( let mut new_direction = direction.clone(); new_direction.rotate_right(); if !snake_path.push(dst_pos, new_direction) { - trace!("head_rotation - try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); + trace!("try 1 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); dst_pos.shift(&direction); if !snake_path.push(dst_pos, new_direction) { - trace!("head_rotation - try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); + trace!("try 2 failed: cannot push [{dst_pos} => {new_direction}] into SnakePath"); return; } } transform.rotation = new_direction.orientation(); - trace!("head_rotation - running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}"); + trace!("running {direction} at {cur_pos} {translation}: go {new_direction} on {dst_pos}"); } } @@ -55,6 +56,7 @@ pub fn snake_moving( query: Query<(&mut Transform, &mut Direction, &Velocity, Entity, Has), Or<(With, With, With)>>, mut commands: Commands, ) { + let _span = trace_span!("snake_moving").entered(); for (mut transform, mut direction, Velocity(velocity), entity, has_end) in query.into_iter() { // первая часть движения - до границы сетки let delta = velocity * time.delta_secs(); @@ -70,7 +72,7 @@ pub fn snake_moving( let delta = second.1.abs(); let pos = Position::from(&*transform); if let Some(dir) = snake_path.peek(&pos) { - trace!("snake_moving - set new direction for {entity} in {pos} --> {dir}"); + trace!("set new direction for {entity} in {pos} --> {dir}"); *direction = dir.clone(); } let src = direction.get_coord(&*transform);