CI / build-test (push) Failing after 1m7s
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>
90 lines
3.0 KiB
C#
90 lines
3.0 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using MrGameEng.Input;
|
|
using Xunit;
|
|
|
|
namespace MrGameEng.Input.Tests;
|
|
|
|
public class InputManagerTests
|
|
{
|
|
private static MouseState Mouse(int x = 0, int y = 0, int wheel = 0, ButtonState left = ButtonState.Released) =>
|
|
new(x, y, wheel, left, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
|
|
|
|
private static void Frame(InputManager input, KeyboardState keyboard = default, MouseState mouse = default) =>
|
|
input.Apply(keyboard, mouse, GamePadState.Default);
|
|
|
|
[Fact]
|
|
public void KeyPressed_OnlyOnTheFrameItGoesDown()
|
|
{
|
|
var input = new InputManager();
|
|
|
|
Frame(input, new KeyboardState(Keys.Space));
|
|
Assert.True(input.IsKeyPressed(Keys.Space));
|
|
Assert.True(input.IsKeyDown(Keys.Space));
|
|
|
|
Frame(input, new KeyboardState(Keys.Space));
|
|
Assert.False(input.IsKeyPressed(Keys.Space));
|
|
Assert.True(input.IsKeyDown(Keys.Space));
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyReleased_OnlyOnTheFrameItGoesUp()
|
|
{
|
|
var input = new InputManager();
|
|
|
|
Frame(input, new KeyboardState(Keys.A));
|
|
Frame(input);
|
|
|
|
Assert.True(input.IsKeyReleased(Keys.A));
|
|
Frame(input);
|
|
Assert.False(input.IsKeyReleased(Keys.A));
|
|
}
|
|
|
|
[Fact]
|
|
public void Capture_SuppressesInput_KeepsMousePositionAndWheel()
|
|
{
|
|
var capture = new MrGameEng.Core.InputCapture();
|
|
var input = new InputManager(capture);
|
|
|
|
Frame(input, new KeyboardState(Keys.W), Mouse(x: 10, y: 20, wheel: 120));
|
|
Assert.True(input.IsKeyDown(Keys.W));
|
|
|
|
capture.Captured = true;
|
|
input.Update(); // ввод захвачен оверлеем — устройства не опрашиваются
|
|
|
|
Assert.False(input.IsKeyDown(Keys.W));
|
|
Assert.True(input.IsKeyReleased(Keys.W)); // одно корректное событие отпускания
|
|
Assert.Equal(new Point(10, 20), input.MousePosition);
|
|
Assert.Equal(0, input.WheelDelta);
|
|
Assert.Equal(Point.Zero, input.MouseDelta);
|
|
|
|
input.Update();
|
|
Assert.False(input.IsKeyReleased(Keys.W)); // и больше никаких фантомных событий
|
|
}
|
|
|
|
[Fact]
|
|
public void MouseDeltaAndWheelDelta_ComputedBetweenFrames()
|
|
{
|
|
var input = new InputManager();
|
|
|
|
Frame(input, mouse: Mouse(x: 10, y: 10, wheel: 0));
|
|
Frame(input, mouse: Mouse(x: 25, y: 5, wheel: 120));
|
|
|
|
Assert.Equal(new Point(15, -5), input.MouseDelta);
|
|
Assert.Equal(120, input.WheelDelta);
|
|
Assert.Equal(new Point(25, 5), input.MousePosition);
|
|
}
|
|
|
|
[Fact]
|
|
public void MousePressed_DetectsLeftButtonEdge()
|
|
{
|
|
var input = new InputManager();
|
|
|
|
Frame(input, mouse: Mouse());
|
|
Frame(input, mouse: Mouse(left: ButtonState.Pressed));
|
|
|
|
Assert.True(input.IsMousePressed(MouseButton.Left));
|
|
Assert.False(input.IsMousePressed(MouseButton.Right));
|
|
}
|
|
}
|