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) { foreach (var entity in _filter.Entities) { var currentRotation = World.Get(entity); var rotationSpeed = World.Get(entity); float change = rotationSpeed.Speed * delta.SecFloat(); World.Set(entity, currentRotation with { Value = currentRotation.Value + change }); var newSpeed = rotationSpeed.Speed - (rotationSpeed.Drag * delta.SecFloat()); if (Math.Sign(newSpeed) != Math.Sign(rotationSpeed.Speed)) { World.Remove(entity); } else { World.Set(entity, rotationSpeed with { Speed = newSpeed, Amount = rotationSpeed.Amount - change, }); } } } }