Files
mrgameeng/tests/MrGameEng.Core.Tests/SceneTransitionTests.cs
T
Leonid PershinandClaude Fable 5 501d81e19f
CI / build-test (push) Failing after 1m7s
Fix engine-wide code review findings
Collisions: init bucket heads to -1 (QueryAabb hung before the first
rebuild), reset query stamps on truncated QueryAabb (later queries
silently dropped entities), inside-origin raycasts hit at fraction 0 for
circles too, exactly-touching boxes now pair like touching circles.

Graphics: render into the letterbox viewport so the picture matches
ScreenToWorld/WorldToScreen instead of stretching; Y-sort by the
transform pivot rather than the quad center; lock-free snapshot
LayerRegistry (parallel submit read it unsynchronized); validate
InitialCapacity; warn when UseRenderer2D drops options of a later scene.

Core: scenes are explicitly single-use (re-loading threw silently
duplicated systems/entities before — now it throws), Scene.RegisterUnload
for per-scene resources, a switch requested during the reveal phase
covers again instead of hard-swapping, borderless fullscreen
(HardwareModeSwitch off), InputCapture service for input-suppressing
overlays, host disposes the transition renderer and IDisposable services
on shutdown.

Input: game input reads as released while InputCapture is held; mouse
position and wheel freeze so deltas stay zero.

DevConsole: holds InputCapture while open (typing no longer drives the
camera), Revision increments only under the lock, quoted command
arguments, history capped at 256.

UI: scene Desktop skips Myra input processing while the console is open
(clicks no longer fall through), is disposed on scene unload, and Myra
init no longer depends on a process-static flag.

Audio: validate channel count/sample rate before stopping the previous
track, empty looped oggs no longer hang FillBuffers, the instance stops
when a non-looping track drains (IsPlaying was stuck true).

Atlases: metadata v2 stores per-source size+mtime snapshots, so
timestamp-preserving copies and renames invalidate correctly; loader
checks the version and disposes pages on partial load failure; shared
pages never exceed a non-POT MaxPageSize; oversized items pack first
onto exact-size pages instead of splitting an open shared page; the CLI
validates numeric options.

Assets.Generator: file names are escaped in XML docs and string
literals, members no longer collide with the enclosing class (CS0542),
and the Assets root is resolved against build_property.projectdir so
nested "Assets" directories do not shift region paths.

Pathfinding: queries throw when the grid was resized after construction;
generation stamps survive int overflow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 21:18:08 +03:00

135 lines
4.5 KiB
C#

using MrGameEng.Core;
using Xunit;
namespace MrGameEng.Core.Tests;
public class SceneTransitionTests
{
private sealed class TrackingScene : Scene
{
public int LoadCount;
public int UnloadCount;
protected override void OnLoad() => LoadCount++;
protected override void OnUnload() => UnloadCount++;
}
private static void Tick(EngineContext context, float seconds)
{
context.Clock.Advance(seconds);
context.Scenes.Update(context.Clock);
}
[Fact]
public void TransitionSwitch_KeepsOldScene_UntilFullyCovered()
{
var context = new EngineContext();
var first = new TrackingScene();
var second = new TrackingScene();
context.Scenes.Switch(first);
Tick(context, 0.016f);
// Fade(1.0) → фаза закрытия 0.5 c, фаза открытия 0.5 c.
context.Scenes.Switch(second, Transition.Fade(1f));
Tick(context, 0.2f);
Assert.True(context.Scenes.IsTransitioning);
Assert.Same(first, context.Scenes.Current);
Assert.Equal(0, second.LoadCount);
Tick(context, 0.4f); // суммарно 0.6 > 0.5 — экран закрыт, своп произошёл
Assert.Same(second, context.Scenes.Current);
Assert.Equal(1, first.UnloadCount);
Assert.Equal(1, second.LoadCount);
Assert.True(context.Scenes.IsTransitioning); // идёт фаза открытия
Tick(context, 0.6f); // открытие завершено
Assert.False(context.Scenes.IsTransitioning);
Assert.Same(second, context.Scenes.Current);
}
[Fact]
public void Transition_UsesUnscaledTime_WorksWhilePaused()
{
var context = new EngineContext();
var first = new TrackingScene();
var second = new TrackingScene();
context.Scenes.Switch(first);
Tick(context, 0.016f);
context.Clock.TimeScale = 0f; // игра на паузе
context.Scenes.Switch(second, Transition.Fade(0.2f));
Tick(context, 0.15f);
Tick(context, 0.15f);
Assert.Same(second, context.Scenes.Current);
Assert.False(context.Scenes.IsTransitioning);
}
[Fact]
public void SwitchDuringTransition_ReplacesPendingTarget()
{
var context = new EngineContext();
var first = new TrackingScene();
var second = new TrackingScene();
var third = new TrackingScene();
context.Scenes.Switch(first);
Tick(context, 0.016f);
context.Scenes.Switch(second, Transition.Fade(1f));
Tick(context, 0.1f);
context.Scenes.Switch(third); // передумали, пока экран закрывается
Tick(context, 0.5f);
Assert.Same(third, context.Scenes.Current);
Assert.Equal(0, second.LoadCount);
}
[Fact]
public void SwitchDuringReveal_CoversAgain_InsteadOfHardSwap()
{
var context = new EngineContext();
var first = new TrackingScene();
var second = new TrackingScene();
var third = new TrackingScene();
context.Scenes.Switch(first);
Tick(context, 0.016f);
context.Scenes.Switch(second, Transition.Fade(1f)); // 0.5 c закрытие + 0.5 c открытие
Tick(context, 0.6f); // закрыто, своп на second, началось открытие
Assert.Same(second, context.Scenes.Current);
Tick(context, 0.25f); // открытие наполовину (coverage ~0.5)
context.Scenes.Switch(third, Transition.Fade(1f)); // передумали во время открытия
Tick(context, 0.05f); // экран снова закрывается — свопа ещё нет
Assert.Same(second, context.Scenes.Current);
Assert.True(context.Scenes.IsTransitioning);
Tick(context, 0.6f); // полностью закрыт — теперь своп на third
Assert.Same(third, context.Scenes.Current);
Assert.Equal(1, third.LoadCount);
}
[Fact]
public void ZeroDurationTransition_SwapsOnNextUpdates()
{
var context = new EngineContext();
var first = new TrackingScene();
var second = new TrackingScene();
context.Scenes.Switch(first);
Tick(context, 0.016f);
context.Scenes.Switch(second, Transition.Fade(0f));
Tick(context, 0.016f);
Tick(context, 0.016f);
Assert.Same(second, context.Scenes.Current);
Assert.False(context.Scenes.IsTransitioning);
}
}