From 2dc2938b2e0ba19fa2b0ffa2617ce3a3f7157073 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 12 Oct 2026 21:45:55 +0200 Subject: [PATCH] fix(render): camera clamp keeps the far edge on the map; drop unused pan Co-Authored-By: Claude Fable 5.1 --- crates/cyberpunk/src/render/viewport.rs | 10 +++------- crates/cyberpunk/src/screens/explore.rs | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/cyberpunk/src/render/viewport.rs b/crates/cyberpunk/src/render/viewport.rs index 0578824..ee7dbaa 100644 --- a/crates/cyberpunk/src/render/viewport.rs +++ b/crates/cyberpunk/src/render/viewport.rs @@ -32,11 +32,6 @@ impl Camera { self.ty = p.y; } - pub fn pan(&mut self, dx: i32, dy: i32) { - self.tx += dx; - self.ty += dy; - } - /// Moves the target only when `p` leaves the middle third of the view. pub fn follow(&mut self, p: Pos, view_w: u16, view_h: u16) { let zx = (view_w as i32 / 6).max(1); @@ -71,13 +66,14 @@ impl Camera { let half_h = view_h as i32 / 2; let w = size.w as i32; let h = size.h as i32; + // The view spans origin..origin+view, so the far bound is the view's other half. self.tx = if w > view_w as i32 { - self.tx.clamp(half_w, w - half_w) + self.tx.clamp(half_w, w - (view_w as i32 - half_w)) } else { w / 2 }; self.ty = if h > view_h as i32 { - self.ty.clamp(half_h, h - half_h) + self.ty.clamp(half_h, h - (view_h as i32 - half_h)) } else { h / 2 }; diff --git a/crates/cyberpunk/src/screens/explore.rs b/crates/cyberpunk/src/screens/explore.rs index 4b22555..d3f5f16 100644 --- a/crates/cyberpunk/src/screens/explore.rs +++ b/crates/cyberpunk/src/screens/explore.rs @@ -554,6 +554,7 @@ mod tests { let mut s = MapScreen::explore(0); let mut t = Terminal::new(TestBackend::new(120, 40)).unwrap(); t.draw(|f| s.draw(&st, f)).unwrap(); + s.update(&mut st, &[]); let before = s.cursor; s.update(&mut st, &[key(KeyCode::Right), key(KeyCode::Down)]); assert_eq!(s.cursor, Pos::new(before.x + 1, before.y + 1));