Split the platform out of Core: new Host library + HeadlessHost
CI / build-test (push) Successful in 1m24s

Core now depends only on Friflo.Engine.ECS — no MonoGame, no platform.
The windowed MonoGame host moves to the new MrGameEng.Host library:
GameHost, GameHostOptions, visual scene transitions (OverlayTransition,
Transitions.Fade/Wipe, TransitionRenderer) and the Input feature
(namespace MrGameEng.Input is unchanged). Transition timing stays in
Core (SceneManager exposes ActiveTransition/TransitionCoverage/
TransitionPhase; the host draws the overlay). EngineContext loses its
GraphicsDevice property: hosts publish the device as a service and
graphics code reads it via context.GetGraphicsDevice() in Graphics.

Core gains HeadlessHost: a fixed-timestep loop without a window or GPU
(Tick/RunTicks, Run with wall-clock pacing and lag resync) for dedicated
servers, batch simulation and tests. Graphics and Audio now carry their
own MonoGame.Framework.DesktopGL reference instead of inheriting it
from Core.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-06-12 23:04:34 +03:00
co-authored by Claude Fable 5
parent 79d406a9f4
commit 2ac074004a
33 changed files with 560 additions and 184 deletions
@@ -0,0 +1,106 @@
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));
}
}