acdream/tests/AcDream.Core.Tests/World/WorldTimeDebugTests.cs
Erik 1f25a60999 fix(diag): Campaign V slice V7 commit 2 - pin the world clock, because the route never did
THE ROUTE'S TIME PIN NEVER HELD, AND EVERY V7 NUMBER SO FAR WAS TAKEN THROUGH IT.

connected-backend-differential.route.txt opened by pressing
AcdreamCycleTimeOfDay three times, on the stated theory that the cycle walks
live -> 0.00 -> 0.25 -> 0.50 and lands on noon. The mechanism underneath is
WorldTimeService.SetDebugTime, and SyncFromServer clears it -- deliberately,
because that setter is the /time slash command and the command is meant to be a
look-at-dusk-for-a-moment affordance rather than a mode. There is even a test
pinning that behaviour: WorldTimeDebugTests.SyncFromServer_ClearsDebugOverride.
ACE sends TimeSync every few seconds. The clock was therefore un-pinned again
long before the route reached its first stop, on every run this campaign has
taken, including V6m's smoke pair.

The Dereth clock does not only move the sky. It moves the SUN, so it moves the
directional term of every lit surface in the scene.

MEASURED, rather than argued. A probe route captured each stop TWICE, 45 seconds
apart, in the same run on the same backend:

    GL,     Holtburg,      capture 1 vs capture 2:  205,772 px   22.33%
    Vulkan, Holtburg,      capture 1 vs capture 2:  218,732 px   23.73%
    GL,     Facility Hub,  capture 1 vs capture 2:  108,795 px   11.81%
    Vulkan, Facility Hub,  capture 1 vs capture 2:  130,206 px   14.13%

One backend, one stop, nothing moving, and a fifth of the frame changes while
you watch. No cross-backend number means anything against that noise floor, and
the cross-backend numbers taken during that probe run were duly absurd -- 56% at
Holtburg, where the two launches happened to be at different times of Dereth day.

THE FIX IS A PIN THAT OUTRANKS THE SERVER CLOCK AND SURVIVES SYNC.

WorldTimeService.PinnedDayFraction is a nullable day fraction that wins over both
Calendar.DayFraction(NowTicks) and SetDebugTime, and that SyncFromServer does not
touch. ACDREAM_WORLD_TIME -> RuntimeOptions.PinnedWorldDayFraction ->
WorldEnvironmentController, which writes it once: the Runtime environment owner
and its clock are session-scoped, so one write outlives every teleport and every
reveal generation. Values outside [0, 1) are REJECTED rather than clamped -- a
day fraction of 12.5 is a typo, and silently pinning the world at it would be
worse than ignoring it.

Unset is the default and every ordinary run. The calendar DATE still advances,
which is intentional: the date drives day-group selection, and ACDREAM_DAY_GROUP
already pins that. The differential gate forces the pin at 0.5 -- noon, which is
what the three presses were aiming at -- on both launches, and the route's
presses are deleted rather than left in as decoration.

This is instrument determinism on the footing of ACDREAM_DAY_GROUP and V7's
ACDREAM_SKY_PHASE_SECONDS, not a workaround: it is off by default, nothing in the
shipping client reads it, and the alternative was to keep measuring two backends
through a fifth of a frame of sunlight.

WHAT IT MOVED. The same three-stop route, same commit otherwise, before and after:

    holtburg_town           9.05%  ->  2.86%      (83,438 -> 26,330 px)
    facility_hub_interior  12.16%  ->  0.78%      (112,075 -> 7,176 px)
    aerlinthe_island       23.09%  ->  6.82%      (212,824 -> 62,892 px)

The interior stop is the headline. V6m recorded it as a route defect on the
theory that the indoor spring-arm camera settles to different distances in two
runs; that theory is now refuted. The camera was fine. The interior was lit
differently because the sun had moved, and with the sun held still the stop drops
by a factor of 15 to 0.78% -- close enough to the 0.001 threshold that its
remaining population is worth naming rather than guessing at. No route change was
needed and none was made.

WHAT REMAINS, per the difference maps, all of it now attributable by eye:
the animated portal beside the Holtburg stop; distant scenery foliage; wandering
NPCs and a chimney smoke plume, which are animation and emitter phase; the vitals
readouts, whose stamina and mana genuinely regenerate at different rates across
two logins minutes apart; and, at Aerlinthe, a dense low-magnitude speckle in a
scene whose mean luminance is 28/255 -- half of its differing pixels are exactly
delta 3, one step over a tolerance that is absolute rather than relative.

Gates. Release build green. App tests 4,134 passed / 3 skipped (one new: the
day-fraction range check); AcDream.Core.Tests WorldTimeDebugTests 6/6, including
the two new ones that assert the pin survives a sync and outranks the transient
override. GL offline pixel gate against the pre-slice tree: 2.66e-05, 15 pixels
of 563,200, inside the documented 9-31 band -- GL did not move.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 19:34:13 +02:00

120 lines
4.7 KiB
C#

using System;
using AcDream.Core.World;
using Xunit;
namespace AcDream.Core.Tests.World;
[Collection(DerethDateTimeCollection.Name)]
public sealed class WorldTimeDebugTests
{
[Fact]
public void SetDebugTime_OverridesDayFraction()
{
var service = new WorldTimeService(SkyStateProvider.Default());
service.SyncFromServer(0); // server tick 0 (= Morntide-and-Half)
service.SetDebugTime(0.5f); // force noon (Midsong-and-Half)
Assert.InRange(service.DayFraction, 0.499, 0.501);
}
[Fact]
public void ClearDebugTime_RestoresServerTime()
{
// Post tick-0-offset fix: DayFraction(tick) = ((tick + 7/16 * DayTicks) % DayTicks) / DayTicks.
// Pick a server tick whose real-world meaning is straightforward to verify.
// Sync to (0.25 - 7/16) * DayTicks negative means "3 slots before midnight
// past Morntide-and-Half", which in positive terms is 13/16 of the day
// past Morntide-and-Half, but simpler: sync to "1/16 past midnight" =
// ticks giving fraction 1/16. Required tick offset from 0 to land at
// fraction 1/16: solve (t + 7/16*D) mod D = 1/16*D
// → t = (1/16 - 7/16) * D mod D = -6/16 * D mod D = 10/16 * D.
double targetFraction = 1.0 / 16.0; // Darktide-and-Half
var service = new WorldTimeService(SkyStateProvider.Default());
double syncTick = targetFraction * DerethDateTime.DayTicks
- service.Calendar.OriginOffsetTicks;
while (syncTick < 0) syncTick += DerethDateTime.DayTicks;
service.SyncFromServer(syncTick);
service.SetDebugTime(0.5f);
service.ClearDebugTime();
Assert.InRange(service.DayFraction, targetFraction - 0.01, targetFraction + 0.01);
}
[Fact]
public void SyncFromServer_ClearsDebugOverride()
{
var service = new WorldTimeService(SkyStateProvider.Default());
service.SetDebugTime(0.75f);
service.SyncFromServer(0); // tick 0 = Morntide-and-Half → fraction 7/16
Assert.InRange(service.DayFraction, 7.0 / 16.0 - 0.01, 7.0 / 16.0 + 0.01);
}
/// <summary>
/// Campaign V slice V7. The transient override above is exactly what a
/// connected gate cannot use: <c>SyncFromServer_ClearsDebugOverride</c> is
/// the documented behaviour, and ACE sends TimeSync every few seconds, so a
/// route that pins the clock at startup is un-pinned before its first stop.
/// The pin has to outrank both the server clock and the slash command, and
/// survive every sync -- that is the whole property, so it is asserted
/// against a sync AND against a competing SetDebugTime.
/// </summary>
[Fact]
public void PinnedDayFraction_SurvivesServerSyncAndOutranksTheDebugOverride()
{
var service = new WorldTimeService(SkyStateProvider.Default())
{
PinnedDayFraction = 0.5f,
};
service.SyncFromServer(0); // tick 0 = fraction 7/16
Assert.InRange(service.DayFraction, 0.499, 0.501);
service.SetDebugTime(0.75f); // the /time command loses
Assert.InRange(service.DayFraction, 0.499, 0.501);
service.SyncFromServer(DerethDateTime.DayTicks / 4.0);
Assert.InRange(service.DayFraction, 0.499, 0.501);
}
/// <summary>
/// Unset is the default and must leave the clock completely alone, including
/// after the pin has been set and cleared again.
/// </summary>
[Fact]
public void PinnedDayFraction_UnsetLeavesTheServerClockAlone()
{
var service = new WorldTimeService(SkyStateProvider.Default());
service.SyncFromServer(0);
Assert.Null(service.PinnedDayFraction);
Assert.InRange(service.DayFraction, 7.0 / 16.0 - 0.01, 7.0 / 16.0 + 0.01);
service.PinnedDayFraction = 0.125f;
Assert.InRange(service.DayFraction, 0.124, 0.126);
service.PinnedDayFraction = null;
Assert.InRange(service.DayFraction, 7.0 / 16.0 - 0.01, 7.0 / 16.0 + 0.01);
}
[Fact]
public void SetProvider_AcceptsNewKeyframes()
{
var service = new WorldTimeService(SkyStateProvider.Default());
var custom = new SkyStateProvider(new[]
{
new SkyKeyframe(
Begin: 0f,
SunHeadingDeg: 0f,
SunPitchDeg: 90f,
DirColor: System.Numerics.Vector3.One,
DirBright: 1f,
AmbColor: System.Numerics.Vector3.One,
AmbBright: 1f,
FogColor: System.Numerics.Vector3.Zero,
FogDensity: 0f),
});
service.SetProvider(custom);
Assert.Equal(1, custom.KeyframeCount);
}
}