Tactical view fixes: clamp SimClock.Rate (refuse NaN), one far-clip writer, pin blend curve, thresholds and clamps
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0df1642d66
commit
012f33e6ac
5 changed files with 82 additions and 7 deletions
|
|
@ -1246,7 +1246,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
private TacticalFade _tacticalFade;
|
||||
private PostProcessVolume _tacticalVolume;
|
||||
private Camera _schematicCamera;
|
||||
private float _authoredFarClip;
|
||||
|
||||
// Flying: a ship under the player's hand, not docked. Everything tactical reads 0 otherwise.
|
||||
private bool Flying => RunLive && CurrentEntity != null && DockedEntity == null;
|
||||
|
|
@ -1263,16 +1262,15 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
private float BaseFollowDistance(Entity entity) => Settings.FollowCameraDistancePerReach * Contacts.Radius(entity);
|
||||
|
||||
// The one writer of the follow camera's distance and far clip: the hull's framed distance times the tactical zoom,
|
||||
// far enough to see the whole zone from there.
|
||||
// The one writer of the follow camera's distance: the hull's framed distance times the tactical zoom. It asks
|
||||
// ZoneRenderer, the one writer of the far clip, to see the whole zone from there.
|
||||
private void ApplyFraming(Entity entity)
|
||||
{
|
||||
if (_framingTransposer == null)
|
||||
_framingTransposer = FollowCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
|
||||
if (_authoredFarClip == 0) _authoredFarClip = FollowCamera.m_Lens.FarClipPlane;
|
||||
var distance = _tactical.Distance(BaseFollowDistance(entity));
|
||||
_framingTransposer.m_CameraDistance = distance;
|
||||
FollowCamera.m_Lens.FarClipPlane = Mathf.Max(_authoredFarClip, distance + 2 * entity.Zone.Pack.Radius);
|
||||
ZoneRenderer.FarClipNeeded = distance + 2 * entity.Zone.Pack.Radius;
|
||||
}
|
||||
|
||||
// Everything the tactical view shows is read off the camera distance: the fade, the schematic, the map icons' size
|
||||
|
|
|
|||
|
|
@ -61,7 +61,13 @@ public sealed class SimClock
|
|||
public float Rate
|
||||
{
|
||||
get => _rate;
|
||||
set => _rate = Math.Min(Math.Max(value, float.Epsilon), 1f);
|
||||
set
|
||||
{
|
||||
// NaN is no rate: it would poison the accumulator for good (only Reset clears it), so it is refused and the
|
||||
// last rate stands. Anything else is clamped into (0, 1]: the sim never runs faster than real time or backward.
|
||||
if (float.IsNaN(value)) return;
|
||||
_rate = Math.Min(Math.Max(value, float.Epsilon), 1f);
|
||||
}
|
||||
}
|
||||
|
||||
// Feeds real seconds (negative counts as none, one frame counts at most MaxFrameSeconds) and runs the whole
|
||||
|
|
|
|||
|
|
@ -144,10 +144,26 @@ public class ZoneRenderer : MonoBehaviour
|
|||
_viewDistance = value;
|
||||
foreach (var camera in FogCameras)
|
||||
camera.orthographicSize = value;
|
||||
SceneCamera.m_Lens.FarClipPlane = value * FarPlaneDistanceMultiplier;
|
||||
ApplyFarClip();
|
||||
}
|
||||
}
|
||||
|
||||
// How far the camera must see to take in the whole zone from where the follow camera sits (the tactical view's
|
||||
// reach). The view distance sets the floor; ApplyFarClip is the one writer of the scene camera's far clip.
|
||||
public float FarClipNeeded
|
||||
{
|
||||
set
|
||||
{
|
||||
_farClipNeeded = value;
|
||||
ApplyFarClip();
|
||||
}
|
||||
}
|
||||
|
||||
private float _farClipNeeded;
|
||||
|
||||
private void ApplyFarClip() =>
|
||||
SceneCamera.m_Lens.FarClipPlane = Mathf.Max(_viewDistance * FarPlaneDistanceMultiplier, _farClipNeeded);
|
||||
|
||||
public float MinimapDistance
|
||||
{
|
||||
set
|
||||
|
|
|
|||
|
|
@ -413,6 +413,36 @@ public sealed partial class RunStartTests
|
|||
|
||||
// Rate dilates the real seconds fed, never the step: sixteen frames of one period's real time at Rate 1/16 (all exact in
|
||||
// binary) buy exactly one step, and that step is the same Step.
|
||||
[Fact]
|
||||
public void RateIsHeldInsideZeroExclusiveToOneAndRefusesNaN()
|
||||
{
|
||||
var clock = new SimClock(1f / 60, 60);
|
||||
Assert.Equal(1f, clock.Rate);
|
||||
clock.Rate = .25f;
|
||||
Assert.Equal(.25f, clock.Rate);
|
||||
clock.Rate = float.NaN;
|
||||
Assert.Equal(.25f, clock.Rate); // refused, the last rate stands
|
||||
clock.Rate = 2f;
|
||||
Assert.Equal(1f, clock.Rate);
|
||||
clock.Rate = float.PositiveInfinity;
|
||||
Assert.Equal(1f, clock.Rate);
|
||||
clock.Rate = 0f;
|
||||
Assert.Equal(float.Epsilon, clock.Rate);
|
||||
clock.Rate = -3f;
|
||||
Assert.Equal(float.Epsilon, clock.Rate);
|
||||
clock.Rate = float.NegativeInfinity;
|
||||
Assert.Equal(float.Epsilon, clock.Rate);
|
||||
|
||||
// A refused NaN leaves the clock stepping: none of the accumulator is poisoned.
|
||||
clock.Rate = .5f;
|
||||
clock.Rate = float.NaN;
|
||||
Assert.True(clock.Advance(1f, _ => { }) > 0);
|
||||
clock.Rate = 1f;
|
||||
var before = clock.Steps;
|
||||
clock.Advance(.1f, _ => { });
|
||||
Assert.True(clock.Steps > before);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RateDilatesRealTimeWithoutChangingStep()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
// TacticalView owns the flight camera's zoom; blend and time rate are derived from the distance, never stored.
|
||||
|
|
@ -55,6 +56,30 @@ public sealed class TacticalViewTests
|
|||
Assert.InRange(view.Blend(End / 1.01f), .95f, 1f);
|
||||
}
|
||||
|
||||
// The band is smoothstep over the logarithm of distance: a quarter, half and three quarters of the way up in ln
|
||||
// are 250 x 4^t m, and the thresholds themselves are the 250 m and 1000 m the operator tunes by eye (GameSettings).
|
||||
[Fact]
|
||||
public void BlendIsSmoothstepOverLogDistanceBetweenTheThresholds()
|
||||
{
|
||||
var view = Make();
|
||||
Assert.Equal(.15625f, view.Blend(250f * MathF.Pow(4, .25f)), 3);
|
||||
Assert.Equal(.5f, view.Blend(500f), 3);
|
||||
Assert.Equal(.84375f, view.Blend(250f * MathF.Pow(4, .75f)), 3);
|
||||
Assert.Equal(0f, view.Blend(249f));
|
||||
Assert.Equal(1f, view.Blend(1001f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeRateIsTheScaleToTheBlendPowerNotLinear()
|
||||
{
|
||||
var view = Make();
|
||||
Assert.Equal(.1f, view.TimeRate(.5f), 5);
|
||||
Assert.Equal(MathF.Pow(.01f, .25f), view.TimeRate(.25f), 5);
|
||||
Assert.Equal(MathF.Pow(.01f, .75f), view.TimeRate(.75f), 5);
|
||||
Assert.Equal(1f, view.TimeRate(-1));
|
||||
Assert.Equal(Scale, view.TimeRate(2), 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeRateIsOneInFlightAndTheScaleInTactical()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue