using System.Collections.Generic; using Content.Client.GameObjects.Components; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; namespace Content.Client.GameObjects.EntitySystems { [UsedImplicitly] public sealed class WindowSystem : EntitySystem { private readonly Queue _dirtyEntities = new Queue(); public override void Initialize() { base.Initialize(); SubscribeEvent(HandleDirtyEvent); } private void HandleDirtyEvent(object sender, WindowSmoothDirtyEvent ev) { if (sender is IEntity senderEnt && senderEnt.HasComponent()) { _dirtyEntities.Enqueue(senderEnt); } } public override void FrameUpdate(float frameTime) { base.FrameUpdate(frameTime); // Performance: This could be spread over multiple updates, or made parallel. while (_dirtyEntities.Count > 0) { var entity = _dirtyEntities.Dequeue(); if (entity.Deleted) { continue; } entity.GetComponent().UpdateSprite(); } } } /// /// Event raised by a when it needs to be recalculated. /// public sealed class WindowSmoothDirtyEvent : EntitySystemMessage { } }