EntityManager Class
Definition
Section titled “Definition”Manages a set of entities. Adds a render step and only renders the entities that are in the parent IScreenSurface visible area.
[DataContract]public class EntityManager : UpdateComponent, IComponent, IList<Entity>, ICollection<Entity>, IEnumerable<Entity>, IEnumerable, IDisposableInheritance object → UpdateComponent
Implements IComponent, IList<Entity>, ICollection<Entity>, IEnumerable<Entity>, IEnumerable, IDisposable
Constructors
Section titled “Constructors”EntityManager()
Section titled “EntityManager()”public EntityManager()Fields
Section titled “Fields”IsAttached
Section titled “IsAttached”Indicates that the entity renderer has been added to a parent object.
protected bool IsAttached_entities
Section titled “_entities”The entities to process.
[DataMember(Name = "Entities")]protected List<Entity> _entities_entitiesVisible
Section titled “_entitiesVisible”The entities currently visible.
protected List<Entity> _entitiesVisible_screen
Section titled “_screen”The parent screen hosting this component.
protected IScreenSurface? _screen_offsetAreaPixels
Section titled “_offsetAreaPixels”Cached rectangle for rendering.
protected Rectangle _offsetAreaPixels_screenCachedView
Section titled “_screenCachedView”A cached copy of the View of the hosting screen surface.
protected Rectangle _screenCachedView_screenCachedFont
Section titled “_screenCachedFont”A cached copy of the Font of the hosting screen surface.
protected IFont? _screenCachedFont_screenCachedFontSize
Section titled “_screenCachedFontSize”A cached copy of the FontSize of the hosting screen surface.
protected Point _screenCachedFontSizeRenderStep
Section titled “RenderStep”Internal use only
public IRenderStep? RenderStepProperties
Section titled “Properties”Entities
Section titled “Entities”The entities associated with this manager.
public IReadOnlyList<Entity> Entities { get; }EntitiesVisible
Section titled “EntitiesVisible”The entities within the visible portion of the parent surface.
public IReadOnlyList<Entity> EntitiesVisible { get; }IsDirty
Section titled “IsDirty”When true, indicates that this object needs to be redrawn; otherwise false.
public bool IsDirty { get; set; }DoEntityUpdate
Section titled “DoEntityUpdate”When true, indicates this manager should call Update(TimeSpan) on each entity; otherwise false.
public bool DoEntityUpdate { get; set; }SkipExistsChecks
Section titled “SkipExistsChecks”When true, the Add(Entity) and Remove(Entity) won’t check if the entity exists before doing its operation.
public bool SkipExistsChecks { get; set; }AlternativeFont
Section titled “AlternativeFont”An alternative font to use when drawing the entities. If null, the hosting surface’s font is used.
public IFont? AlternativeFont { get; set; }The number of entities in the renderer.
public int Count { get; }IsReadOnly
Section titled “IsReadOnly”Always returns false.
public bool IsReadOnly { get; }this[int]
Section titled “this[int]”Gets an entity by index.
public Entity this[int index] { get; set; }Methods
Section titled “Methods”Add(Entity)
Section titled “Add(Entity)”Adds an entity to this manager.
public void Add(Entity entity)Parameters
Section titled “Parameters”entity Entity
The entity to add.
AddRange(IEnumerable<Entity>)
Section titled “AddRange(IEnumerable<Entity>)”Adds a collection of entities to this manager.
public void AddRange(IEnumerable<Entity> entities)Parameters
Section titled “Parameters”entities IEnumerable<Entity>
The entities to add.
AddEntity(Entity, bool)
Section titled “AddEntity(Entity, bool)”Adds an entity to the collection, subscribes to events, and calls OnEntityAdded(Entity) and OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>).
protected void AddEntity(Entity entity, bool skipSort)Parameters
Section titled “Parameters”entity Entity
The entity to remove.
skipSort bool
When true, skips sorting when CalculateEntityVisibilityProtected(Entity, bool) is called inside this method.
RemoveEntity(Entity)
Section titled “RemoveEntity(Entity)”Adds an entity to the collection, unsubscribes to events, and calls OnEntityRemoved(Entity).
protected bool RemoveEntity(Entity entity)Parameters
Section titled “Parameters”entity Entity
The entity to remove.
Returns
Section titled “Returns”Remove(Entity)
Section titled “Remove(Entity)”Removes an entity from this manager.
public bool Remove(Entity entity)Parameters
Section titled “Parameters”entity Entity
The entity to remove.
Returns
Section titled “Returns”Clear()
Section titled “Clear()”Removes all entities from this renderer.
public void Clear()OnAdded(IScreenObject)
Section titled “OnAdded(IScreenObject)”Called when the component is added to a host.
public override void OnAdded(IScreenObject host)Parameters
Section titled “Parameters”host IScreenObject
The host that added the component.
OnRemoved(IScreenObject)
Section titled “OnRemoved(IScreenObject)”Called when the component is removed from the host.
public override void OnRemoved(IScreenObject host)Parameters
Section titled “Parameters”host IScreenObject
The host that removed the component.
Update(IScreenObject, TimeSpan)
Section titled “Update(IScreenObject, TimeSpan)”Called by a host on the update frame.
public override void Update(IScreenObject host, TimeSpan delta)Parameters
Section titled “Parameters”host IScreenObject
The host calling the component.
delta TimeSpan
The time that has elapsed since this method was last called.
GetRenderRectangle(Point, bool)
Section titled “GetRenderRectangle(Point, bool)”Gets a render rectangle for a position.
public Rectangle GetRenderRectangle(Point position, bool isPixel)Parameters
Section titled “Parameters”position SadRogue.Primitives.Point
The position of the entity.
isPixel bool
Indicates the entity is pixel positioned.
Returns
Section titled “Returns”SadRogue.Primitives.Rectangle
SortVisibleEntities()
Section titled “SortVisibleEntities()”Sorts the EntitiesVisible collection according to the ZIndex value.
public void SortVisibleEntities()OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>)
Section titled “OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>)”Called when an entity changes position.
protected virtual void OnEntityChangedPosition(Entity entity, ValueChangedEventArgs<Point> e)Parameters
Section titled “Parameters”entity Entity
The entity that moved.
e SadRogue.Primitives.ValueChangedEventArgsSadRogue.Primitives.Point
The previous and new values of the position.
OnEntityAdded(Entity)
Section titled “OnEntityAdded(Entity)”Called when an entity is added.
protected virtual void OnEntityAdded(Entity entity)Parameters
Section titled “Parameters”entity Entity
The entity.
OnEntityRemoved(Entity)
Section titled “OnEntityRemoved(Entity)”Called when an entity is removed.
protected virtual void OnEntityRemoved(Entity entity)Parameters
Section titled “Parameters”entity Entity
The entity.
CalculateEntityVisibility(Entity)
Section titled “CalculateEntityVisibility(Entity)”Updates the visibility state of an entity.
public bool CalculateEntityVisibility(Entity entity)Parameters
Section titled “Parameters”entity Entity
The entity to check.
Returns
Section titled “Returns”bool
Returns true when this entity is considered visible; otherwise false.
Exceptions
Section titled “Exceptions”CalculateEntityVisibilityProtected(Entity, bool)
Section titled “CalculateEntityVisibilityProtected(Entity, bool)”Detects a visibility state change of an entity and changes its internal list position.
protected bool CalculateEntityVisibilityProtected(Entity entity, bool skipSort)Parameters
Section titled “Parameters”entity Entity
The entity to check.
skipSort bool
If true, skips sorting the visible.
Returns
Section titled “Returns”bool
true when the entity is visible; otherwise false.
UpdateCachedVisibilityArea()
Section titled “UpdateCachedVisibilityArea()”Updates the cached view area based on the parent surface.
protected void UpdateCachedVisibilityArea()IndexOf(Entity)
Section titled “IndexOf(Entity)”public int IndexOf(Entity item)Parameters
Section titled “Parameters”item Entity
Returns
Section titled “Returns”Contains(Entity)
Section titled “Contains(Entity)”public bool Contains(Entity item)Parameters
Section titled “Parameters”item Entity
Returns
Section titled “Returns”CopyTo(Entity[], int)
Section titled “CopyTo(Entity[], int)”public void CopyTo(Entity[] array, int arrayIndex)Parameters
Section titled “Parameters”array Entity[]
arrayIndex int
GetEnumerator()
Section titled “GetEnumerator()”public IEnumerator<Entity> GetEnumerator()Returns
Section titled “Returns”Dispose(bool)
Section titled “Dispose(bool)”protected virtual void Dispose(bool disposing)Parameters
Section titled “Parameters”disposing bool
~EntityManager()
Section titled “~EntityManager()”protected ~EntityManager()Dispose()
Section titled “Dispose()”public void Dispose()