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 { 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().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().X); } }