feat(aswid): the Eclipse's dusk spends its time on the sunset

An even sweep from the afternoon to midnight looked still for three
seconds and then fell dark in half of one, because the sky hardly changes
between 0.25 and 0.75 and does its darkening around sunset. The dusk now
walks keyframes: half a second to late afternoon, three through the
sunset band, half a second to midnight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kanym 2026-09-26 19:24:23 +02:00
commit 52c26d9b52

View file

@ -863,8 +863,37 @@ namespace RacesOfValheim
StartCoroutine(EclipseRoutine());
}
/// <summary>How long the sky takes to run from the cast to midnight.</summary>
private const float EclipseDuskSeconds = 3.5f;
/// <summary>
/// The Eclipse's dusk as (seconds, day fraction) keys, walked linearly between them.
///
/// Not one even sweep, because the sky does not change evenly. EnvMan keeps it looking like
/// day from 0.25 to 0.75 and does all its darkening around sunset, so an even run from
/// the afternoon to midnight looked still for three seconds and then fell dark in half of
/// one. Here the afternoon goes by in half a second and the sunset band gets three.
/// The first key's fraction is replaced by the time of the cast, and any key earlier in
/// the day than that is lifted to it, so a cast near dusk does not run the clock backwards.
/// </summary>
private static readonly Vector2[] EclipseDuskKeys =
{
new Vector2(0f, 0f), // the time of the cast
new Vector2(0.5f, 0.70f), // late afternoon, just before the sky starts to change
new Vector2(3.5f, 0.95f), // through the sunset band, slowly
new Vector2(4f, 1f), // midnight
};
private static float EclipseDuskFraction(float from, float seconds)
{
float prevT = 0f, prevF = from;
for (int i = 1; i < EclipseDuskKeys.Length; i++)
{
float keyT = EclipseDuskKeys[i].x;
float keyF = Mathf.Max(EclipseDuskKeys[i].y, from);
if (seconds <= keyT) return Mathf.Lerp(prevF, keyF, Mathf.InverseLerp(prevT, keyT, seconds));
prevT = keyT;
prevF = keyF;
}
return 1f;
}
private System.Collections.IEnumerator EclipseRoutine()
{
@ -902,17 +931,18 @@ namespace RacesOfValheim
{
// Run the clock forward through dusk to midnight rather than cutting to it.
// While m_debugTimeOfDay is on, EnvMan copies m_debugTime straight onto the sky
// with no smoothing of its own, so the easing has to happen here. Forward means
// up to 1, which is midnight again; the Aswid's night buffs start at 0.75,
// partway through. The way back needs nothing: once the switch is off, EnvMan
// with no smoothing of its own, so the pacing has to happen here - see
// EclipseDuskKeys. Forward means up to 1, which is midnight again; the Aswid's
// night buffs start at 0.75, partway through. The way back needs nothing: once the switch is off, EnvMan
// eases towards the real time by itself.
float from = EnvMan.instance.GetDayFraction();
EnvMan.instance.m_debugTime = from;
EnvMan.instance.m_debugTimeOfDay = true;
for (float t = 0f; t < EclipseDuskSeconds && EnvMan.instance != null; t += Time.deltaTime)
float duskSeconds = EclipseDuskKeys[EclipseDuskKeys.Length - 1].x;
for (float t = 0f; t < duskSeconds && EnvMan.instance != null; t += Time.deltaTime)
{
EnvMan.instance.m_debugTime = Mathf.Lerp(from, 1f, Mathf.SmoothStep(0f, 1f, t / EclipseDuskSeconds));
EnvMan.instance.m_debugTime = EclipseDuskFraction(from, t);
yield return null;
}
if (EnvMan.instance != null) EnvMan.instance.m_debugTime = 1f;