A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Pan the map by a one-update flick's travel beyond the tap slop (#1929)
Eyal Golandfb2e8a5f429
diff --git a/changelog.d/1661-flick-pan.md b/changelog.d/1661-flick-pan.mdnew file mode 100644index 000000000..1ddeed6ba--- /dev/null+++ b/changelog.d/1661-flick-pan.md@@ -0,0 +1 @@+- A fast one finger swipe now pans the map once by its travel past the tap threshold, even if it ends before the next frame. Ella's tap fix already keeps the swipe from selecting anything. A swipe that goes out past the threshold and back before the next frame is a pan too, and selects nothing.diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.csindex c32f975e6..99a06aa4f 100644--- a/unity/Assets/Scripts/Map/CameraController.cs+++ b/unity/Assets/Scripts/Map/CameraController.cs@@ -108,6 +108,7 @@ namespace Statecraft.Game.MapInputAction? pan, dragPan, zoom, zoomKeys, orbit;InputAction? mousePress, mousePosition, touchPress, touchPosition;+ InputAction? fingerPress;void Awake() => rig = GetComponent<CameraRig>();@@ -121,10 +122,30 @@ namespace Statecraft.Game.MapmousePosition = new InputAction("camera-drag-position", InputActionType.PassThrough, "<Mouse>/position");mousePosition.performed += ctx => mouseDrag.Move(ctx.ReadValue<Vector2>());touchPress = new InputAction("camera-touch-press", InputActionType.Button, "<Touchscreen>/primaryTouch/press");- touchPress.performed += ctx => touchDrag.Begin(((Touchscreen)ctx.control.device).primaryTouch.position.ReadValue(), IsOverUi);- touchPress.canceled += _ => touchDrag.End();+ touchPress.performed += ctx =>+ {+ var ts = (Touchscreen)ctx.control.device;+ touchDrag.Begin(ts.primaryTouch.position.ReadValue(), IsOverUi);+ ClassifyTouch(ts);+ };+ touchPress.canceled += ctx =>+ {+ var ts = (Touchscreen)ctx.control.device;+ touchDrag.Move(ts.primaryTouch.position.ReadValue());+ ClassifyTouch(ts);+ if (HoldsTouchDrag != null) touchDrag.Lift(); else touchDrag.End();+ };touchPosition = new InputAction("camera-touch-position", InputActionType.PassThrough, "<Touchscreen>/primaryTouch/position");- touchPosition.performed += ctx => touchDrag.Move(ctx.ReadValue<Vector2>());+ touchPosition.performed += ctx =>+ {+ touchDrag.Move(ctx.ReadValue<Vector2>());+ // Drop pair motion after recording its position; later one-finger movement stays live.+ ClassifyTouch((Touchscreen)ctx.control.device);+ };+ // Observe secondary fingers even when the primary position never changes during their lifetime.+ fingerPress = new InputAction("camera-finger-press", InputActionType.PassThrough, "<Touchscreen>/touch*/press");+ fingerPress.performed += ctx => ClassifyTouch((Touchscreen)ctx.control.device);+ fingerPress.Enable();mousePress.Enable(); mousePosition.Enable(); touchPress.Enable(); touchPosition.Enable();DrainWheel(); // events from while the camera was off (a menu) are not a zoomTrackpadMagnification(); // nor is a pinch from then@@ -141,13 +162,20 @@ namespace Statecraft.Game.MapInputSystem.actions?.FindActionMap("Camera")?.Disable();mousePress?.Dispose(); mousePress = null; mousePosition?.Dispose(); mousePosition = null;touchPress?.Dispose(); touchPress = null; touchPosition?.Dispose(); touchPosition = null;+ fingerPress?.Dispose(); fingerPress = null;mouseDrag.End(); touchDrag.End();+ touchDrag.TakeLifted(); // disabling discards completed motion as well as the current pressdragFromUi = dragWasDown = false;}bool dragFromUi, dragWasDown;readonly PressDrag mouseDrag = new PressDrag(), touchDrag = new PressDrag();+ void ClassifyTouch(Touchscreen ts)+ {+ if (FingersDown(ts, out _, out _) == 2) touchDrag.Discard();+ }+void Update() => Tick(Time.unscaledDeltaTime);/// <summary>One frame from the live actions, <paramref name="dt"/> seconds long. Test seam (internal; the tests see it@@ -199,24 +227,38 @@ namespace Statecraft.Game.Mapvar modifier = ModifierHeld(Keyboard.current);var input = Gather(pan.ReadValue<Vector2>(), drag, zoomRaw, orbit.ReadValue<float>(), down, pointer, zoomKeys.ReadValue<float>(), modifier);if (down) input.DragFromUi = fromUi; // latched at the actual press, even between camera frames+ // Classify and filter the current gesture before draining earlier, already-approved motion.+ // A new UI press owns only its own drag; OverUi must still block its wheel/magnify zoom.+ input.DragPan = (input.DragFromUi ? Vector2.zero : input.DragPan) + touchDrag.TakeLifted();+ input.DragFromUi = false;Step(rig, input, ClampDt(dt), Bounds, Ground, GroundTop, FixedNorth);}/// <summary>Position history scoped to one press. Begin resets even if release/repress happens between/// camera ticks. Event positions, rather than Mouse/delta, exclude pre-press movement and retain multiple- /// input updates. Released gestures are not replayed here (Ella owns ruling 3).</summary>+ /// input updates. Completed touch travel is kept separately from the next press (ruling 3's camera half).</summary>internal sealed class PressDrag{- Vector2 origin, previous, pending;- bool down, panning;+ Vector2 origin, previous, pending, lifted;+ bool down, panning, replayBlocked;internal bool FromUi { get; private set; }internal void Begin(Vector2 at, Func<Vector2, bool>? overUi = null){origin = previous = at; pending = Vector2.zero;- down = true; panning = false; FromUi = overUi?.Invoke(at) == true;+ down = true; panning = replayBlocked = false; FromUi = overUi?.Invoke(at) == true;}internal void End() { down = panning = false; pending = Vector2.zero; }- internal void Discard() { pending = Vector2.zero; }+ internal void Lift()+ {+ if (down && !replayBlocked && !FromUi) lifted += pending;+ End();+ }+ internal Vector2 TakeLifted()+ {+ var result = lifted; lifted = Vector2.zero; return result;+ }+ // A pinch rejects completed replay, not the remaining finger's live movement.+ internal void Discard() { pending = Vector2.zero; replayBlocked = true; }internal void Move(Vector2 at){if (!down) return;@@ -251,9 +293,9 @@ namespace Statecraft.Game.Mapt.press.isPressed || t.press.wasPressedThisFrame;/// <summary>The first two touches down <em>now</em> (2 stands for two or more), or fewer. Level state on- /// purpose: a finger that has already lifted contributes no ongoing drag, so counting it here would turn a- /// one-update flick into a pan. Whether a finger merely touched during the update is a separate question,- /// asked by <see cref="DownThisUpdate"/> at the call site (#1792).</summary>+ /// purpose: ended fingers contribute no live drag or pinch. Approved completed one-finger travel is replayed+ /// separately by PressDrag.TakeLifted; <see cref="DownThisUpdate"/> detects a finger that merely touched during+ /// this update (#1792).</summary>static int FingersDown(Touchscreen ts, out UnityEngine.InputSystem.Controls.TouchControl a,out UnityEngine.InputSystem.Controls.TouchControl b){diff --git a/unity/Assets/Scripts/Map/MapPointer.cs b/unity/Assets/Scripts/Map/MapPointer.csindex e853b82e1..228e119ba 100644--- a/unity/Assets/Scripts/Map/MapPointer.cs+++ b/unity/Assets/Scripts/Map/MapPointer.cs@@ -32,14 +32,19 @@ namespace Statecraft.Game.Map/// one input update, and then <c>position</c> and <c>start</c> are the same sample: the distance test below/// sees nothing moved however far it went. The frame's own travel does see it. Callers with no travel to/// report (the mouse's right button, which is stepped from its action callbacks) pass none, so their rule is- /// unchanged.</para></summary>- public Vector2? Step(bool pressed, bool released, Vector2 position, bool otherFingerDown, Vector2 travel = default)+ /// unchanged.</para>+ /// <para><paramref name="strayed"/> is true when the press left the slop at one of its own input events, even+ /// if it came back before the frame sampled it (#1929 review): a path out past the slop and back inside one+ /// update has no net travel, yet the camera pans by it, so it must not also be a tap.</para></summary>+ public Vector2? Step(bool pressed, bool released, Vector2 position, bool otherFingerDown, Vector2 travel = default,+ bool strayed = false){if (pressed) { start = position; down = true; moved = false; pinched = false; }if (!down) return null;if (otherFingerDown) pinched = true; // a pinch is never a tap, even a still thumbif ((position - start).sqrMagnitude > SlopPixels * SlopPixels) moved = true; // latched: coming back helps notif (travel.sqrMagnitude > SlopPixels * SlopPixels) moved = true; // a whole flick inside one frame+ if (strayed) moved = true; // out and back inside one frameif (!released) return null;down = false;return moved || pinched ? (Vector2?)null : start;@@ -82,9 +87,14 @@ namespace Statecraft.Game.Map// Right clicks, as presses are: the right button's press, every pointer move while it is held and its release are// each stepped at their own event's position, so a drag out and back inside one slow frame is still a drag.readonly Queue<Vector2> rightClicks = new Queue<Vector2>();- InputAction? press, leftMove, rightPress, rightMove;+ InputAction? press, leftMove, rightPress, rightMove, touchPress, touchMove;TapPress tap, rightTap, leftTap;+ // The primary finger's slop at its own events (#1929 review), as CameraController.PressDrag records it: same+ // controls, same origin (the press event's position) and the same strict test, so the tap and the camera's+ // lifted pan agree on a path that leaves the slop and comes back inside one input update.+ Vector2 touchFrom;+ bool touchDown, touchStrayed;/// <summary>True while the right button's press could still end as a right click (TapPress.TapCandidate): the/// camera holds its right-drag pan until it is false.</summary>@@ -111,6 +121,13 @@ namespace Statecraft.Game.MaprightMove = new InputAction("map-right-move", InputActionType.PassThrough, "<Mouse>/position");rightMove.performed += OnRightMoved;rightMove.Enable();+ touchPress = new InputAction("map-touch-press", InputActionType.Button, "<Touchscreen>/primaryTouch/press");+ touchPress.performed += OnTouchPressed;+ touchPress.canceled += OnTouchReleased;+ touchPress.Enable();+ touchMove = new InputAction("map-touch-move", InputActionType.PassThrough, "<Touchscreen>/primaryTouch/position");+ touchMove.performed += OnTouchMoved;+ touchMove.Enable();}void OnDisable()@@ -119,8 +136,30 @@ namespace Statecraft.Game.Mapif (leftMove != null) { leftMove.performed -= OnLeftMoved; leftMove.Dispose(); leftMove = null; }if (rightPress != null) { rightPress.performed -= OnRightPressed; rightPress.canceled -= OnRightReleased; rightPress.Dispose(); rightPress = null; }if (rightMove != null) { rightMove.performed -= OnRightMoved; rightMove.Dispose(); rightMove = null; }+ if (touchPress != null) { touchPress.performed -= OnTouchPressed; touchPress.canceled -= OnTouchReleased; touchPress.Dispose(); touchPress = null; }+ if (touchMove != null) { touchMove.performed -= OnTouchMoved; touchMove.Dispose(); touchMove = null; }presses.Clear(); rightClicks.Clear();rightTap = default; leftTap = default;+ touchDown = touchStrayed = false;+ }++ void OnTouchPressed(InputAction.CallbackContext ctx)+ {+ if (ctx.control.device is not Touchscreen ts) return;+ touchFrom = ts.primaryTouch.position.ReadValue(); touchDown = true; touchStrayed = false;+ }++ void OnTouchMoved(InputAction.CallbackContext ctx) => TouchMoved(ctx.ReadValue<Vector2>());++ void OnTouchReleased(InputAction.CallbackContext ctx)+ {+ if (ctx.control.device is Touchscreen ts) TouchMoved(ts.primaryTouch.position.ReadValue());+ touchDown = false;+ }++ void TouchMoved(Vector2 at)+ {+ if (touchDown && (at - touchFrom).sqrMagnitude > TapPress.SlopPixels * TapPress.SlopPixels) touchStrayed = true;}void OnRightPressed(InputAction.CallbackContext ctx)@@ -183,7 +222,8 @@ namespace Statecraft.Game.Mapif (CameraController.DownThisUpdate(touch)) pressed++; // counts a finger that already lifted this update (#1792)// any other finger down cancels the tap (TapPress): a releasing pinch's thumb is inside the slop, yet must not selectvar tapAt = tap.Step(t.press.wasPressedThisFrame, t.press.wasReleasedThisFrame,- t.position.ReadValue(), pressed > (CameraController.DownThisUpdate(t) ? 1 : 0), t.delta.ReadValue());+ t.position.ReadValue(), pressed > (CameraController.DownThisUpdate(t) ? 1 : 0), t.delta.ReadValue(),+ touchStrayed);if (tapAt.HasValue) OnPress(tapAt.Value); // a tap selects where the finger landed, like a click}diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.csindex 13b957c12..95692428d 100644--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs@@ -823,6 +823,235 @@ public class PressOriginCameraInputTests : SharedCameraActionsFixturepublic void Dispose() { Send(Pointer, "OnDisable"); Send(Camera, "OnDisable"); Object.DestroyImmediate(Go); Game.Dispose(); }}+ void Flick(int id, Vector2 from, Vector2 travel)+ {+ BeginTouch(id, from, queueEventOnly: true);+ MoveTouch(id, from + travel, queueEventOnly: true);+ EndTouch(id, from + travel);+ }++ static void PanIs(Rig rig, float pixels)+ {+ TestContext.WriteLine(string.Format(System.Globalization.CultureInfo.InvariantCulture,+ "pan trace: excess={0} px; expected x={1}; actual x={2}; z={3}; distance={4}",+ pixels, 500000 - pixels * 120, rig.View.LookAt.x, rig.View.LookAt.z, rig.View.Distance));+ Assert.That(rig.View.LookAt.x, Is.EqualTo(500000 - pixels * 120).Within(0.1f));+ Assert.That(rig.View.LookAt.z, Is.EqualTo(500000).Within(0.1f));+ }++ [TestCase(0)]+ [TestCase(20)]+ [TestCase(30)]+ [TestCase(31)]+ [TestCase(200)]+ public void ACompletedFlickPansOnlyItsExcessOnce(int travel)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig();+ rig.Frame(); // Ella's warming frame is required to see the press edge.+ var clicks = 0;+ rig.Pointer.HexClicked += (_, __, ___) => clicks++;+ Flick(1, new Vector2(600, 400), new Vector2(travel, 0));+ rig.Frame(); PanIs(rig, Mathf.Max(0, travel - 30));+ rig.Frame(); PanIs(rig, Mathf.Max(0, travel - 30));+ Assert.AreEqual(travel <= 30 ? 1 : 0, rig.Orders.Count, "short presses keep their tap semantics");+ Assert.AreEqual(travel <= 30 ? 1 : 0, clicks, "a touch tap selects; it does not issue a right-click order");+ Assert.IsEmpty(rig.Game.Bridge.Session.Committed);+ }++ [Test]+ public void LiftKeepsOnlyTravelNotAlreadyConsumedByADragFrame()+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ BeginTouch(1, new Vector2(600, 400)); rig.Frame();+ MoveTouch(1, new Vector2(700, 400)); rig.Frame(); PanIs(rig, 70);+ MoveTouch(1, new Vector2(800, 400), queueEventOnly: true);+ EndTouch(1, new Vector2(800, 400));+ rig.Frame(); PanIs(rig, 170);+ rig.Frame(); PanIs(rig, 170);+ Assert.IsEmpty(rig.Orders);+ }++ [TestCase(false)]+ [TestCase(true)]+ public void ANewShortPressCannotEraseThePreviousFlick(bool overUi)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ rig.Camera.IsOverUi = p => overUi && p.x < 500;+ rig.Pointer.IsOverUi = p => overUi && p.x < 500;+ var clicks = 0;+ rig.Pointer.HexClicked += (_, __, ___) => clicks++;+ Flick(1, new Vector2(600, 400), new Vector2(200, 0));+ BeginTouch(2, new Vector2(400, 400), queueEventOnly: true);+ MoveTouch(2, new Vector2(410, 400));+ rig.Frame(); PanIs(rig, 170);+ EndTouch(2, new Vector2(410, 400));+ rig.Frame(); rig.Frame(); PanIs(rig, 170);+ Assert.AreEqual(overUi ? 0 : 1, clicks);+ Assert.IsEmpty(rig.Game.Bridge.Session.Committed);+ }++ [TestCase(200, 340)]+ [TestCase(-100, 100)]+ public void TwoCompletedFlicksEachPayTheirOwnSlop(int secondTravel, int total)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ Flick(1, new Vector2(600, 400), new Vector2(200, 0));+ Flick(2, new Vector2(600, 400), new Vector2(secondTravel, 0));+ rig.Frame(); PanIs(rig, total);+ rig.Frame(); PanIs(rig, total);+ Assert.IsEmpty(rig.Orders); Assert.IsEmpty(rig.Game.Bridge.Session.Committed);+ }++ [Test]+ public void AUiOriginFlickCannotLeakIntoTheNextMapPress()+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ rig.Camera.IsOverUi = p => p.x < 500;+ Flick(1, new Vector2(400, 400), new Vector2(200, 0));+ rig.Frame(); PanIs(rig, 0);+ BeginTouch(2, new Vector2(600, 400)); rig.Frame(); PanIs(rig, 0);+ }++ [TestCase(false)]+ [TestCase(true)]+ public void DisablingOrUngatedTouchDoesNotReplayACompletedFlick(bool ungated)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ if (ungated) rig.Camera.HoldsTouchDrag = null;+ Flick(1, new Vector2(600, 400), new Vector2(200, 0));+ if (!ungated) { Send(rig.Camera, "OnDisable"); Send(rig.Camera, "OnEnable"); }+ rig.Frame(); rig.Frame(); PanIs(rig, 0);+ }++ [Test]+ public void RemovingTheTouchscreenDoesNotLoseOrRepeatAnApprovedFlick()+ {+ var screen = InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ Flick(1, new Vector2(600, 400), new Vector2(200, 0));+ InputSystem.RemoveDevice(screen);+ rig.Frame(); PanIs(rig, 170);+ rig.Frame(); PanIs(rig, 170);+ }++ void EndedPinch(bool oneUpdate, int movementStage, bool primaryFirst)+ {+ BeginTouch(1, new Vector2(600, 400), queueEventOnly: oneUpdate);+ if (movementStage == 0) MoveTouch(1, new Vector2(800, 400), queueEventOnly: oneUpdate);+ BeginTouch(2, new Vector2(900, 400), queueEventOnly: oneUpdate);+ if (movementStage == 1) MoveTouch(1, new Vector2(800, 400), queueEventOnly: oneUpdate);+ if (primaryFirst) EndTouch(1, new Vector2(800, 400), queueEventOnly: oneUpdate);+ EndTouch(2, new Vector2(900, 400), queueEventOnly: oneUpdate);+ if (!primaryFirst)+ {+ if (movementStage == 2) MoveTouch(1, new Vector2(800, 400), queueEventOnly: oneUpdate);+ EndTouch(1, new Vector2(800, 400), queueEventOnly: oneUpdate);+ }+ if (oneUpdate) InputSystem.Update();+ }++ [TestCase(true, 0, false)]+ [TestCase(true, 1, false)]+ [TestCase(true, 2, false)]+ [TestCase(false, 0, false)]+ [TestCase(false, 1, false)]+ [TestCase(false, 2, false)]+ [TestCase(true, 1, true)]+ [TestCase(false, 1, true)]+ public void AnEndedPinchNeverBecomesALiftedPan(bool oneUpdate, int movementStage, bool primaryFirst)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ EndedPinch(oneUpdate, movementStage, primaryFirst);+ rig.Frame(); PanIs(rig, 0);+ rig.Frame(); PanIs(rig, 0);+ Assert.AreEqual(100000, rig.View.Distance, "an ended pair invents no pinch zoom");+ Assert.IsEmpty(rig.Orders); Assert.IsEmpty(rig.Game.Bridge.Session.Committed);+ }++ [TestCase(false)]+ [TestCase(true)]+ public void APinchCannotDeleteAnUnrelatedValidFlick(bool pinchFirst)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ if (pinchFirst) EndedPinch(false, 2, false);+ Flick(3, new Vector2(600, 400), new Vector2(200, 0));+ if (!pinchFirst) EndedPinch(false, 2, false);+ rig.Frame(); PanIs(rig, 170);+ rig.Frame(); PanIs(rig, 170);+ Assert.IsEmpty(rig.Game.Bridge.Session.Committed);+ }++ [TestCase(0.05f)]+ [TestCase(-0.05f)]+ public void ATrackpadMagnifyStillZoomsWithALiftedFlick(float magnification)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ Flick(1, new Vector2(600, 400), new Vector2(200, 0));+ var pending = magnification;+ rig.Camera.TrackpadMagnification = () => { var value = pending; pending = 0; return value; };+ rig.Frame();+ Assert.AreEqual(100000 / (1 + magnification), rig.View.Distance, 1f);+ Assert.That(rig.View.LookAt.x, Is.EqualTo(500000 - 170 * 0.0012f * rig.View.Distance).Within(0.1f));+ var at = rig.View.LookAt;+ rig.Frame(); Assert.AreEqual(at, rig.View.LookAt);+ Assert.AreEqual(100000 / (1 + magnification), rig.View.Distance, 1f);+ }++ [Test]+ public void ASampledPinchKeepsTheRemainingFingersLivePan()+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ BeginTouch(1, new Vector2(600, 400)); rig.Frame();+ MoveTouch(1, new Vector2(700, 400)); rig.Frame(); PanIs(rig, 70);+ BeginTouch(2, new Vector2(900, 400)); rig.Frame(); PanIs(rig, 70);+ EndTouch(2, new Vector2(900, 400)); rig.Frame(); PanIs(rig, 70);+ MoveTouch(1, new Vector2(750, 400)); rig.Frame(); PanIs(rig, 120);+ rig.Frame(); PanIs(rig, 120);+ EndTouch(1, new Vector2(800, 400)); // a pinched press must not save even its final movement+ rig.Frame(); rig.Frame(); PanIs(rig, 120);+ Assert.AreEqual(100000, rig.View.Distance);+ Assert.IsEmpty(rig.Orders); Assert.IsEmpty(rig.Game.Bridge.Session.Committed);+ }++ [Test]+ public void ALiveTouchscreenPinchStillZoomsWithoutPanning()+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ BeginTouch(1, new Vector2(600, 400));+ BeginTouch(2, new Vector2(900, 400)); rig.Frame();+ MoveTouch(2, new Vector2(1000, 400)); rig.Frame();+ PanIs(rig, 0);+ Assert.AreEqual(90000, rig.View.Distance, 1f, "one hundred pixels of live pinch is one notch");+ }++ [Test]+ public void EnableDrainsMagnifyAndANewUiPressStillBlocksZoom()+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig(); rig.Frame();+ Send(rig.Camera, "OnDisable");+ var pending = 0.05f;+ rig.Camera.TrackpadMagnification = () => { var value = pending; pending = 0; return value; };+ Send(rig.Camera, "OnEnable"); rig.Frame();+ Assert.AreEqual(100000, rig.View.Distance);+ Flick(1, new Vector2(600, 400), new Vector2(200, 0));+ rig.Camera.IsOverUi = p => p.x < 500;+ BeginTouch(2, new Vector2(400, 400)); pending = 0.05f;+ rig.Frame(); PanIs(rig, 170);+ Assert.AreEqual(100000, rig.View.Distance, "the retained pan exception must not clear OverUi");+ }+[TestCase(10)][TestCase(31)]public void AReleaseAndNewPressBeforeTheCameraFrameStartsANewGesture(int travel)diff --git a/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs b/unity/Assets/Tests/EditMode/FixedNorthCameraTests.csindex 85524cfab..43d6c3297 100644--- a/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs+++ b/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs@@ -56,6 +56,8 @@ public class FixedNorthCameraTests : SharedCameraActionsFixture{Assert.AreEqual(0f, rig.Yaw, "entering gameplay resets an inherited heading immediately");Press(clockwise ? keyboard.eKey : keyboard.qKey);+ Assert.AreEqual(clockwise ? 1f : -1f, actions.FindAction("Camera/Orbit", true).ReadValue<float>(),+ "the key reaches the shipped orbit binding, so a north yaw below is the policy, not a lost key");for (int i = 0; i < 10; i++) controller.Tick(0.1f);Assert.AreEqual(0f, rig.Yaw);}@@ -124,6 +126,37 @@ public class FixedNorthCameraTests : SharedCameraActionsFixturefinally { Close(); }}+ /// <summary>#1661 ruling 3 under the fixed-north policy: a gated one-update flick (press, 200 px and release before+ /// the camera's frame) pans once by its 170 px beyond the slop. Under gdd-0.3 a yaw disturbed before the frame is+ /// repaired first, so the pan runs due west; the older rulesets keep their yaw and the pan turns with it.</summary>+ [TestCase(true)]+ [TestCase(false)]+ public void AGatedFlickPansOnceAlongTheRulesetsHeading(bool gdd03)+ {+ InputSystem.AddDevice<Touchscreen>();+ Open(gdd03 ? SaveGame.Gdd03Ruleset : SaveGame.LegacyRuleset);+ try+ {+ controller.HoldsTouchDrag = () => false; // gated, and no tap candidate holds the drag+ controller.Tick(0.016f);+ var from = new Vector2(400, 400);+ BeginTouch(1, from, queueEventOnly: true);+ MoveTouch(1, from + new Vector2(200, 0), queueEventOnly: true);+ EndTouch(1, from + new Vector2(200, 0));+ if (gdd03) rig.Yaw = 77f; // a heading set outside the camera's input+ var yaw = gdd03 ? 0f : 37f;+ var expected = new Vector3(500000, 0, 500000) + Quaternion.Euler(0, yaw, 0) * new Vector3(-170 * 120f, 0, 0);+ controller.Tick(0.016f);+ Assert.AreEqual(yaw, rig.Yaw, 0.001f);+ Assert.AreEqual(expected.x, rig.LookAt.x, 0.1f, "the flick pans by its travel beyond the 30 px slop");+ Assert.AreEqual(expected.z, rig.LookAt.z, 0.1f);+ controller.Tick(0.016f);+ Assert.AreEqual(expected.x, rig.LookAt.x, 0.1f, "the lift pans once");+ Assert.AreEqual(expected.z, rig.LookAt.z, 0.1f);+ }+ finally { Close(); }+ }+[Test]public void Gdd03WheelKeysAndTrackpadPinchKeepTheirExistingRates(){diff --git a/unity/Assets/Tests/EditMode/MapPointerTickTests.cs b/unity/Assets/Tests/EditMode/MapPointerTickTests.csindex 45c351431..eaaf82d34 100644--- a/unity/Assets/Tests/EditMode/MapPointerTickTests.cs+++ b/unity/Assets/Tests/EditMode/MapPointerTickTests.cs@@ -120,10 +120,13 @@ public class MapPointerTickTests : SharedCameraActionsFixturerig.Frame();rig.SettleFrame();Assert.IsEmpty(rig.Asked, "a fast swipe selects nothing: the travel is inside the frame, and the slop sees it");- // The pan is not asserted here, and deliberately. In this extreme the finger is already up when the frame- // runs, so CameraController's FingersDown sees none and never reads its delta; panning it would mean changing- // the camera, which is ruling 2's file. A swipe the camera sees a finger during is the next test.- Assert.AreEqual(start, rig.View.LookAt, "today it also does not pan, because the finger is gone by the frame");+ // Deliberately inverted for ruling 3's camera half ("the map pans by the swipe", #1661). This assertion used to+ // pin that the map stayed put, because the finger is up before the camera's frame. The camera now keeps the+ // travel beyond the 30 px slop and pans by it once. Ella's no-selection assertion and warming frame are unchanged.+ Assert.That(rig.View.LookAt.x, Is.EqualTo(start.x - 170 * 120).Within(0.1f));+ Assert.AreEqual(start.z, rig.View.LookAt.z);+ rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(start.x - 170 * 120).Within(0.1f), "the lift pans once");}/// <summary>The same ruling for a swipe the camera can actually see: fast, but with the finger down across a@@ -166,6 +169,43 @@ public class MapPointerTickTests : SharedCameraActionsFixtureAssert.AreEqual(start, rig.View.LookAt, "and a tap never pans");}+ /// <summary>#1929 review: a finger that goes out past the slop and comes back, then lifts, all inside one input+ /// update, is a click or a pan, never both. The frame sees no net travel (the release is where the press was), so+ /// before the fix the pointer queued a tap while the camera's lifted replay kept the excursion and panned. The+ /// pointer now latches the slop at each touch event, as the camera does and as the mouse's left and right+ /// buttons already did (MapPressTests' out-and-back cases): coming back helps not, so it is a pan and nothing is+ /// selected. The pan is the camera's rule, the travel beyond the slop: 10 px out, then 40 px back, so 30 px back.+ /// <para>Run with merging on and with the game's setting (InputConfig, merging off), and with the press already+ /// down before the update. The still-press control is the test above.</para></summary>+ [TestCase(false, false)]+ [TestCase(true, false)]+ [TestCase(true, true)]+ public void AnOutAndBackInsideOneInputUpdateIsAPanNotAlsoATap(bool gameMerging, bool pressedEarlier)+ {+ var old = InputSystem.settings.disableRedundantEventsMerging;+ try+ {+ if (gameMerging) Statecraft.Game.Boot.InputConfig.Apply();+ using var rig = new Rig();+ var start = rig.View.LookAt;+ var from = new Vector2(600, 400);+ rig.Frame(); // warms press.wasPressedThisFrame, as in the flick test above+ if (pressedEarlier) { BeginTouch(1, from); rig.Frame(); }+ else BeginTouch(1, from, queueEventOnly: true);+ MoveTouch(1, from + new Vector2(40, 0), queueEventOnly: true); // 10 px past the 30 px slop+ MoveTouch(1, from, queueEventOnly: true);+ EndTouch(1, from);+ rig.Frame();+ rig.SettleFrame();+ Assert.IsEmpty(rig.Asked, "the excursion past the slop makes it a drag: no tap");+ Assert.That(rig.View.LookAt.x, Is.EqualTo(start.x + 30 * 120).Within(0.1f), "and the drag pans by its travel beyond the slop");+ Assert.AreEqual(start.z, rig.View.LookAt.z);+ rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(start.x + 30 * 120).Within(0.1f), "the lift pans once");+ }+ finally { InputSystem.settings.disableRedundantEventsMerging = old; }+ }+// --- item 5: the order, now declared ------------------------------------------------------------------------/// <summary>Item 5's fix, pinned at its cause: the pointer's frame must run before the camera's, because the camera