Update README.md to include project description, developer documentation links, and license information.
CI / build-test (push) Successful in 1m6s

This commit is contained in:
Leonid Pershin
2026-06-11 04:03:07 +03:00
parent 31aba3aeee
commit ff2231a8ab
72 changed files with 4113 additions and 0 deletions
@@ -0,0 +1,53 @@
using MrGameEng.Core;
using Xunit;
namespace MrGameEng.Core.Tests;
public class GameClockTests
{
[Fact]
public void Advance_SingleFrame_UpdatesDeltaTotalAndFrameCount()
{
var clock = new GameClock();
clock.Advance(0.016f);
Assert.Equal(0.016f, clock.DeltaTime);
Assert.Equal(0.016f, clock.UnscaledDeltaTime);
Assert.Equal(0.016, clock.TotalTime, 3);
Assert.Equal(1, clock.FrameCount);
}
[Fact]
public void Advance_WithTimeScale_ScalesDeltaButNotUnscaled()
{
var clock = new GameClock { TimeScale = 0.5f };
clock.Advance(0.02f);
Assert.Equal(0.01f, clock.DeltaTime, 3);
Assert.Equal(0.02f, clock.UnscaledDeltaTime, 3);
Assert.Equal(0.01, clock.TotalTime, 3);
Assert.Equal(0.02, clock.UnscaledTotalTime, 3);
}
[Fact]
public void TimeScale_Zero_PausesScaledTime()
{
var clock = new GameClock { TimeScale = 0f };
clock.Advance(0.016f);
Assert.Equal(0f, clock.DeltaTime);
Assert.Equal(0.0, clock.TotalTime);
Assert.Equal(0.016, clock.UnscaledTotalTime, 3);
}
[Fact]
public void TimeScale_Negative_ClampsToZero()
{
var clock = new GameClock { TimeScale = -1f };
Assert.Equal(0f, clock.TimeScale);
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MrGameEng.Core\MrGameEng.Core.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,87 @@
using MrGameEng.Core;
using Xunit;
namespace MrGameEng.Core.Tests;
public class SceneManagerTests
{
private sealed class TrackingScene : Scene
{
public int LoadCount;
public int UnloadCount;
public int UpdateCount;
protected override void OnLoad() => LoadCount++;
protected override void OnUnload() => UnloadCount++;
public override void Update(GameClock clock)
{
UpdateCount++;
base.Update(clock);
}
}
[Fact]
public void Switch_IsDeferred_UntilNextUpdate()
{
var context = new EngineContext();
var scene = new TrackingScene();
context.Scenes.Switch(scene);
Assert.Null(context.Scenes.Current);
Assert.Equal(0, scene.LoadCount);
context.Scenes.Update(context.Clock);
Assert.Same(scene, context.Scenes.Current);
Assert.Equal(1, scene.LoadCount);
Assert.Equal(1, scene.UpdateCount);
Assert.True(scene.IsLoaded);
}
[Fact]
public void Switch_UnloadsPreviousScene_AndLoadsNext()
{
var context = new EngineContext();
var first = new TrackingScene();
var second = new TrackingScene();
context.Scenes.Switch(first);
context.Scenes.Update(context.Clock);
context.Scenes.Switch(second);
context.Scenes.Update(context.Clock);
Assert.Equal(1, first.UnloadCount);
Assert.False(first.IsLoaded);
Assert.Same(second, context.Scenes.Current);
Assert.Equal(1, second.LoadCount);
}
[Fact]
public void Switch_ToNull_UnloadsCurrentScene()
{
var context = new EngineContext();
var scene = new TrackingScene();
context.Scenes.Switch(scene);
context.Scenes.Update(context.Clock);
context.Scenes.Switch(null);
context.Scenes.Update(context.Clock);
Assert.Null(context.Scenes.Current);
Assert.Equal(1, scene.UnloadCount);
}
[Fact]
public void Update_WithoutScene_DoesNothing()
{
var context = new EngineContext();
context.Scenes.Update(context.Clock);
context.Scenes.Draw(context.Clock);
Assert.Null(context.Scenes.Current);
}
}
@@ -0,0 +1,73 @@
using Friflo.Engine.ECS;
using Friflo.Engine.ECS.Systems;
using MrGameEng.Core;
using Xunit;
namespace MrGameEng.Core.Tests;
public class SceneSystemsTests
{
private struct Velocity : IComponent
{
public float X;
}
private struct Translation : IComponent
{
public float X;
}
private sealed class MoveSystem : QuerySystem<Translation, Velocity>
{
protected override void OnUpdate()
{
foreach (var (translations, velocities, _) in Query.Chunks)
{
var t = translations.Span;
var v = velocities.Span;
for (var i = 0; i < t.Length; i++)
{
t[i].X += v[i].X * Tick.deltaTime;
}
}
}
}
private sealed class MovingScene : Scene
{
public Entity Mover;
protected override void OnLoad()
{
Mover = Store.CreateEntity(new Translation { X = 0f }, new Velocity { X = 10f });
UpdateSystems.Add(new MoveSystem());
}
}
[Fact]
public void Update_RunsRegisteredQuerySystem_WithClockDelta()
{
var context = new EngineContext();
var scene = new MovingScene();
context.Scenes.Switch(scene);
context.Clock.Advance(0.5f);
context.Scenes.Update(context.Clock);
Assert.Equal(5f, scene.Mover.GetComponent<Translation>().X, 3);
}
[Fact]
public void TimeScale_AffectsSystemDelta()
{
var context = new EngineContext();
var scene = new MovingScene();
context.Scenes.Switch(scene);
context.Clock.TimeScale = 0f;
context.Clock.Advance(0.5f);
context.Scenes.Update(context.Clock);
Assert.Equal(0f, scene.Mover.GetComponent<Translation>().X);
}
}