Show / Hide Table of Contents

Class EntityManager

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

Inheritance
object
UpdateComponent
EntityManager
EntityManagerZoned
Implements
IComponent
IList<Entity>
ICollection<Entity>
IEnumerable<Entity>
IEnumerable
IDisposable
Inherited Members
UpdateComponent.SortOrder
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole.Entities
Assembly: SadConsole.dll
Syntax
[DataContract]
public class EntityManager : UpdateComponent, IComponent, IList<Entity>, ICollection<Entity>, IEnumerable<Entity>, IEnumerable, IDisposable

Constructors

EntityManager()

Declaration
public EntityManager()

Fields

IsAttached

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

Declaration
protected bool IsAttached
Field Value
Type Description
bool

RenderStep

Internal use only

Declaration
public IRenderStep? RenderStep
Field Value
Type Description
IRenderStep

_entities

The entities to process.

Declaration
[DataMember(Name = "Entities")]
protected List<Entity> _entities
Field Value
Type Description
List<Entity>

_entitiesVisible

The entities currently visible.

Declaration
protected List<Entity> _entitiesVisible
Field Value
Type Description
List<Entity>

_offsetAreaPixels

Cached rectangle for rendering.

Declaration
protected Rectangle _offsetAreaPixels
Field Value
Type Description
Rectangle

_screen

The parent screen hosting this component.

Declaration
protected IScreenSurface? _screen
Field Value
Type Description
IScreenSurface

_screenCachedFont

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

Declaration
protected IFont? _screenCachedFont
Field Value
Type Description
IFont

_screenCachedFontSize

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

Declaration
protected Point _screenCachedFontSize
Field Value
Type Description
Point

_screenCachedView

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

Declaration
protected Rectangle _screenCachedView
Field Value
Type Description
Rectangle

Properties

AlternativeFont

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

Declaration
public IFont? AlternativeFont { get; set; }
Property Value
Type Description
IFont

Count

The number of entities in the renderer.

Declaration
public int Count { get; }
Property Value
Type Description
int

DoEntityUpdate

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

Declaration
public bool DoEntityUpdate { get; set; }
Property Value
Type Description
bool

Entities

The entities associated with this manager.

Declaration
public IReadOnlyList<Entity> Entities { get; }
Property Value
Type Description
IReadOnlyList<Entity>

EntitiesVisible

The entities within the visible portion of the parent surface.

Declaration
public IReadOnlyList<Entity> EntitiesVisible { get; }
Property Value
Type Description
IReadOnlyList<Entity>

IsDirty

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

Declaration
public bool IsDirty { get; set; }
Property Value
Type Description
bool

IsReadOnly

Always returns false.

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
bool

this[int]

Gets an entity by index.

Declaration
public Entity this[int index] { get; set; }
Parameters
Type Name Description
int index
Property Value
Type Description
Entity

The entity.

Exceptions
Type Condition
NotSupportedException

SkipExistsChecks

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

Declaration
public bool SkipExistsChecks { get; set; }
Property Value
Type Description
bool

Methods

Add(Entity)

Adds an entity to this manager.

Declaration
public void Add(Entity entity)
Parameters
Type Name Description
Entity entity

The entity to add.

AddEntity(Entity, bool)

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

Declaration
protected void AddEntity(Entity entity, bool skipSort)
Parameters
Type Name Description
Entity entity

The entity to remove.

bool skipSort

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

AddRange(IEnumerable<Entity>)

Adds a collection of entities to this manager.

Declaration
public void AddRange(IEnumerable<Entity> entities)
Parameters
Type Name Description
IEnumerable<Entity> entities

The entities to add.

CalculateEntityVisibility(Entity)

Updates the visibility state of an entity.

Declaration
public bool CalculateEntityVisibility(Entity entity)
Parameters
Type Name Description
Entity entity

The entity to check.

Returns
Type Description
bool

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

Exceptions
Type Condition
ArgumentException

CalculateEntityVisibilityProtected(Entity, bool)

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

Declaration
protected bool CalculateEntityVisibilityProtected(Entity entity, bool skipSort)
Parameters
Type Name Description
Entity entity

The entity to check.

bool skipSort

If true, skips sorting the visible.

Returns
Type Description
bool

true when the entity is visible; otherwise false.

Clear()

Removes all entities from this renderer.

Declaration
public void Clear()

Contains(Entity)

Declaration
public bool Contains(Entity item)
Parameters
Type Name Description
Entity item
Returns
Type Description
bool

CopyTo(Entity[], int)

Declaration
public void CopyTo(Entity[] array, int arrayIndex)
Parameters
Type Name Description
Entity[] array
int arrayIndex

Dispose()

Declaration
public void Dispose()

Dispose(bool)

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

~EntityManager()

Declaration
protected ~EntityManager()

GetEnumerator()

Declaration
public IEnumerator<Entity> GetEnumerator()
Returns
Type Description
IEnumerator<Entity>

GetRenderRectangle(Point, bool)

Gets a render rectangle for a position.

Declaration
public Rectangle GetRenderRectangle(Point position, bool isPixel)
Parameters
Type Name Description
Point position

The position of the entity.

bool isPixel

Indicates the entity is pixel positioned.

Returns
Type Description
Rectangle

IndexOf(Entity)

Declaration
public int IndexOf(Entity item)
Parameters
Type Name Description
Entity item
Returns
Type Description
int

OnAdded(IScreenObject)

Called when the component is added to a host.

Declaration
public override void OnAdded(IScreenObject host)
Parameters
Type Name Description
IScreenObject host

The host that added the component.

Overrides
UpdateComponent.OnAdded(IScreenObject)

OnEntityAdded(Entity)

Called when an entity is added.

Declaration
protected virtual void OnEntityAdded(Entity entity)
Parameters
Type Name Description
Entity entity

The entity.

OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>)

Called when an entity changes position.

Declaration
protected virtual void OnEntityChangedPosition(Entity entity, ValueChangedEventArgs<Point> e)
Parameters
Type Name Description
Entity entity

The entity that moved.

ValueChangedEventArgs<Point> e

The previous and new values of the position.

OnEntityRemoved(Entity)

Called when an entity is removed.

Declaration
protected virtual void OnEntityRemoved(Entity entity)
Parameters
Type Name Description
Entity entity

The entity.

OnRemoved(IScreenObject)

Called when the component is removed from the host.

Declaration
public override void OnRemoved(IScreenObject host)
Parameters
Type Name Description
IScreenObject host

The host that removed the component.

Overrides
UpdateComponent.OnRemoved(IScreenObject)

Remove(Entity)

Removes an entity from this manager.

Declaration
public bool Remove(Entity entity)
Parameters
Type Name Description
Entity entity

The entity to remove.

Returns
Type Description
bool

RemoveEntity(Entity)

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

Declaration
protected bool RemoveEntity(Entity entity)
Parameters
Type Name Description
Entity entity

The entity to remove.

Returns
Type Description
bool

SortVisibleEntities()

Sorts the EntitiesVisible collection according to the ZIndex value.

Declaration
public void SortVisibleEntities()

Update(IScreenObject, TimeSpan)

Called by a host on the update frame.

Declaration
public override void Update(IScreenObject host, TimeSpan delta)
Parameters
Type Name Description
IScreenObject host

The host calling the component.

TimeSpan delta

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

Overrides
UpdateComponent.Update(IScreenObject, TimeSpan)

UpdateCachedVisibilityArea()

Updates the cached view area based on the parent surface.

Declaration
protected void UpdateCachedVisibilityArea()

Implements

IComponent
IList<T>
ICollection<T>
IEnumerable<T>
IEnumerable
IDisposable

Extension Methods

ExtensionsSystem.GetDebuggerDisplayValue(object)
In this article

Back to top

Back to top Generated by DocFX