Skip to content

EntityManager Class

Manages a set of entities. Adds a render step and only renders the entities that are in the parent IScreenSurface visible area.

C#
[DataContract]
public class EntityManager : UpdateComponent, IComponent, IList<Entity>, ICollection<Entity>, IEnumerable<Entity>, IEnumerable, IDisposable

Inheritance objectUpdateComponent

Implements IComponent, IList<Entity>, ICollection<Entity>, IEnumerable<Entity>, IEnumerable, IDisposable

C#
public EntityManager()

Indicates that the entity renderer has been added to a parent object.

C#
protected bool IsAttached

The entities to process.

C#
[DataMember(Name = "Entities")]
protected List<Entity> _entities

The entities currently visible.

C#
protected List<Entity> _entitiesVisible

The parent screen hosting this component.

C#
protected IScreenSurface? _screen

Cached rectangle for rendering.

C#
protected Rectangle _offsetAreaPixels

A cached copy of the View of the hosting screen surface.

C#
protected Rectangle _screenCachedView

A cached copy of the Font of the hosting screen surface.

C#
protected IFont? _screenCachedFont

A cached copy of the FontSize of the hosting screen surface.

C#
protected Point _screenCachedFontSize

Internal use only

C#
public IRenderStep? RenderStep

The entities associated with this manager.

C#
public IReadOnlyList<Entity> Entities { get; }

The entities within the visible portion of the parent surface.

C#
public IReadOnlyList<Entity> EntitiesVisible { get; }

When true, indicates that this object needs to be redrawn; otherwise false.

C#
public bool IsDirty { get; set; }

When true, indicates this manager should call Update(TimeSpan) on each entity; otherwise false.

C#
public bool DoEntityUpdate { get; set; }

When true, the Add(Entity) and Remove(Entity) won’t check if the entity exists before doing its operation.

C#
public bool SkipExistsChecks { get; set; }

An alternative font to use when drawing the entities. If null, the hosting surface’s font is used.

C#
public IFont? AlternativeFont { get; set; }

The number of entities in the renderer.

C#
public int Count { get; }

Always returns false.

C#
public bool IsReadOnly { get; }

Gets an entity by index.

C#
public Entity this[int index] { get; set; }

Adds an entity to this manager.

C#
public void Add(Entity entity)

entity Entity
The entity to add.

Adds a collection of entities to this manager.

C#
public void AddRange(IEnumerable<Entity> entities)

entities IEnumerable<Entity>
The entities to add.

Adds an entity to the collection, subscribes to events, and calls OnEntityAdded(Entity) and OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>).

C#
protected void AddEntity(Entity entity, bool skipSort)

entity Entity
The entity to remove.

skipSort bool
When true, skips sorting when CalculateEntityVisibilityProtected(Entity, bool) is called inside this method.

Adds an entity to the collection, unsubscribes to events, and calls OnEntityRemoved(Entity).

C#
protected bool RemoveEntity(Entity entity)

entity Entity
The entity to remove.

bool

Removes an entity from this manager.

C#
public bool Remove(Entity entity)

entity Entity
The entity to remove.

bool

Removes all entities from this renderer.

C#
public void Clear()

Called when the component is added to a host.

C#
public override void OnAdded(IScreenObject host)

host IScreenObject
The host that added the component.

Called when the component is removed from the host.

C#
public override void OnRemoved(IScreenObject host)

host IScreenObject
The host that removed the component.

Called by a host on the update frame.

C#
public override void Update(IScreenObject host, TimeSpan delta)

host IScreenObject
The host calling the component.

delta TimeSpan
The time that has elapsed since this method was last called.

Gets a render rectangle for a position.

C#
public Rectangle GetRenderRectangle(Point position, bool isPixel)

position SadRogue.Primitives.Point
The position of the entity.

isPixel bool
Indicates the entity is pixel positioned.

SadRogue.Primitives.Rectangle

Sorts the EntitiesVisible collection according to the ZIndex value.

C#
public void SortVisibleEntities()

OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>)

Section titled “OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>)”

Called when an entity changes position.

C#
protected virtual void OnEntityChangedPosition(Entity entity, ValueChangedEventArgs<Point> e)

entity Entity
The entity that moved.

e SadRogue.Primitives.ValueChangedEventArgsSadRogue.Primitives.Point
The previous and new values of the position.

Called when an entity is added.

C#
protected virtual void OnEntityAdded(Entity entity)

entity Entity
The entity.

Called when an entity is removed.

C#
protected virtual void OnEntityRemoved(Entity entity)

entity Entity
The entity.

Updates the visibility state of an entity.

C#
public bool CalculateEntityVisibility(Entity entity)

entity Entity
The entity to check.

bool
Returns true when this entity is considered visible; otherwise false.

ArgumentException

CalculateEntityVisibilityProtected(Entity, bool)

Section titled “CalculateEntityVisibilityProtected(Entity, bool)”

Detects a visibility state change of an entity and changes its internal list position.

C#
protected bool CalculateEntityVisibilityProtected(Entity entity, bool skipSort)

entity Entity
The entity to check.

skipSort bool
If true, skips sorting the visible.

bool
true when the entity is visible; otherwise false.

Updates the cached view area based on the parent surface.

C#
protected void UpdateCachedVisibilityArea()
C#
public int IndexOf(Entity item)

item Entity

int

C#
public bool Contains(Entity item)

item Entity

bool

C#
public void CopyTo(Entity[] array, int arrayIndex)

array Entity[]

arrayIndex int

C#
public IEnumerator<Entity> GetEnumerator()

IEnumerator<Entity>

C#
protected virtual void Dispose(bool disposing)

disposing bool

C#
protected ~EntityManager()
C#
public void Dispose()