Wormhole warp: centre follows the wormhole the ship is at in each half

The presenter stored the entered wormhole's position once, so the exit half
pulled toward a point in the old zone. The ship already holds the wormhole
position for the current half; expose it as Ship.WormholePosition and read it
each frame, dropping the presenter's copy.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-25 23:29:12 +01:00
commit bff39805cf
4 changed files with 32 additions and 5 deletions

View file

@ -701,7 +701,7 @@ public class ActionGameManager : MonoBehaviour
{
if (!(CurrentEntity is Ship ship) || ship.WormholeAnimationInProgress) return;
ship.EnterWormhole(wormhole.Position);
WormholeWarpPresenter.Begin(ship, wormhole.Position, DeathPost.gameObject.layer,
WormholeWarpPresenter.Begin(ship, DeathPost.gameObject.layer,
Mathf.Max(DeathPost.priority, HeatstrokePost.priority, HypothermiaPost.priority,
SevereHeatstrokePost.priority, SevereHypothermiaPost.priority) + 1);
ship.OnEnteredWormhole += () =>

View file

@ -54,6 +54,10 @@ public class Ship : Entity
: _exitingWormhole ? 1 - _wormholeAnimationProgress
: 0;
// The wormhole the ship is at in the current half: the one it dives into, then the one it emerges from. Presenters
// read it (the screen warp centres on it); it is the sim's own position, so it needs no copy elsewhere.
public float2 WormholePosition => _wormholePosition;
public event Action OnExitedWormhole;
public event Action OnEnteredWormhole;

View file

@ -51,16 +51,14 @@ internal sealed class WormholeWarpRenderer : PostProcessEffectRenderer<WormholeW
public sealed class WormholeWarpPresenter : MonoBehaviour
{
private Ship _ship;
private Vector3 _wormhole;
private PostProcessVolume _volume;
private WormholeWarp _settings;
private bool _seenAnimation;
public static void Begin(Ship ship, CultMath.float2 wormholePosition, int layer, float priority)
public static void Begin(Ship ship, int layer, float priority)
{
var presenter = new GameObject("Wormhole Warp").AddComponent<WormholeWarpPresenter>();
presenter._ship = ship;
presenter._wormhole = new Vector3(wormholePosition.x, 0, wormholePosition.y);
presenter._settings = ScriptableObject.CreateInstance<WormholeWarp>();
presenter._settings.enabled.Override(true);
presenter._volume = PostProcessManager.instance.QuickVolume(layer, priority, presenter._settings);
@ -76,7 +74,9 @@ public sealed class WormholeWarpPresenter : MonoBehaviour
_seenAnimation = true;
var camera = Camera.main;
if (camera == null) return;
var viewport = camera.WorldToViewportPoint(_wormhole);
// The wormhole the ship is at in this half, read from the ship each frame.
var wormhole = _ship.WormholePosition;
var viewport = camera.WorldToViewportPoint(new Vector3(wormhole.x, 0, wormhole.y));
_settings.Center.value = new Vector2(viewport.x, viewport.y);
_settings.Strength.value = _ship.WormholeWarp;
}

View file

@ -322,6 +322,29 @@ public sealed partial class RunStartTests
Assert.Equal(0f, player.WormholeWarp);
}
// The warp centres on the wormhole the ship is at in each half: the one it dives into, then the one it emerges from,
// which is a different place in the new zone.
[Fact]
public void ShipWormholePositionFollowsTheHalf()
{
var (arena, player) = LaunchDuel();
var entered = player.Position.xz + float2(50, 0);
var emerging = player.Position.xz + float2(-300, 120);
var exiting = false;
var arrived = false;
player.OnEnteredWormhole += () => { player.ExitWormhole(emerging, float2(0, 40)); exiting = true; };
player.OnExitedWormhole += () => arrived = true;
player.EnterWormhole(entered);
Assert.Equal(entered, player.WormholePosition);
for (var step = 0; step < 2000 && !arrived; step++)
{
arena.Update(ClockFrame);
if (arrived) break;
Assert.Equal(exiting ? emerging : entered, player.WormholePosition);
}
Assert.True(arrived && exiting, "the ship dives and emerges");
}
// The turn a presenter draws ahead is the turn the next step makes: a ship held in a steady turn, drawn one whole
// step ahead of the pose it was last given, is where the sim puts that pose next.
[Fact]