using System; using System.Numerics; using MonoGameBlank2dStartKit.Core.Utils; using MoonTools.ECS; namespace MonoGameBlank2dStartKit.Core.Systems; public class RotationSystem : MoonTools.ECS.System { private readonly Filter _filter; public RotationSystem(World world) : base(world) { // Doesn't filter on Rotation, because it *should* blow up if RSpeed exists without Rotation. _filter = FilterBuilder.Include().Build(); } public override void Update(TimeSpan delta) { float deltaSec = delta.SecFloat(); foreach (var entity in _filter.Entities) { var currentRotation = World.Get(entity); var rotationSpeed = World.Get(entity); float change = rotationSpeed.Speed * deltaSec; World.Set(entity, currentRotation with { Value = currentRotation.Value + change }); float remainingRotation = rotationSpeed.Amount - change; float newSpeed = rotationSpeed.Speed - (rotationSpeed.Drag * deltaSec); if (Math.Sign(newSpeed) != Math.Sign(rotationSpeed.Speed) || remainingRotation <= 0) { World.Remove(entity); } else { World.Set(entity, rotationSpeed with { Speed = newSpeed, Amount = remainingRotation, }); } } } }