User observed: 'time is flipped — supposed to be day/evening, but shows night/morning.' That's a ~half-day offset. Root cause in ACE DerethDateTime.cs line 23: private const double dayZeroTicks = 0; // Morningthaw 1, 10 P.Y. - Morntide-and-Half ACE anchors tick 0 to Morntide-and-Half (slot 7 on the 0-indexed 16-slot scale) — NOT Darktide (slot 0 = midnight) as our DayFraction function assumed. Confirmed by DerethDateTime.cs:145: private int hour = (int)Hours.Morntide_and_Half; Fix: shift DayFraction by +7/16 * DayTicks (3333.75) so tick 0 maps to its real calendar slot. Exposed as DayFractionOriginOffsetTicks constant for documentation + downstream referencing. Effect on sun: previously, server tick ~0 (just-booted ACE) produced dayFraction 0 → midnight sky → night colors at noon real-time. Now dayFraction 7/16 = 0.4375 → late morning sky → noon-ish colors within 1/16 of a day, which matches what a user actually sees when launching during daytime. Tests updated for the corrected convention: - DerethDateTime.DayFraction(0) = 7/16 (not 0). - CurrentHour(0) = MorntideAndHalf (not Darktide). - IsDaytime(0) = true. - Midnight (Darktide, slot 0) is 9/16 of a day past tick 0. - SkyState + WorldTimeDebug tests retargeted to the new frame. Build green, 711 tests pass. Ref: references/ACE/Source/ACE.Common/DerethDateTime.cs:23-25 + :145. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.6 KiB
C#
69 lines
2.6 KiB
C#
using System;
|
|
using AcDream.Core.World;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.World;
|
|
|
|
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
|
|
double syncTick = (targetFraction - (7.0 / 16.0) + 1.0) * DerethDateTime.DayTicks;
|
|
|
|
var service = new WorldTimeService(SkyStateProvider.Default());
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetProvider_AcceptsNewKeyframes()
|
|
{
|
|
var service = new WorldTimeService(SkyStateProvider.Default());
|
|
var custom = new SkyStateProvider(new[]
|
|
{
|
|
new SkyKeyframe(
|
|
Begin: 0f,
|
|
SunHeadingDeg: 0f,
|
|
SunPitchDeg: 90f,
|
|
SunColor: System.Numerics.Vector3.One,
|
|
AmbientColor: System.Numerics.Vector3.One,
|
|
FogColor: System.Numerics.Vector3.Zero,
|
|
FogDensity: 0f),
|
|
});
|
|
service.SetProvider(custom);
|
|
Assert.Equal(1, custom.KeyframeCount);
|
|
}
|
|
}
|