World

Namespace: Bang
Assembly: Bang.dll

public class World : IDisposable

This is the internal representation of a world within ECS. A world has the knowledge of all the entities and all the systems that exist within the game. This handles dispatching information and handling disposal of entities.

Implements: IDisposable

⭐ Constructors

public World(IList<T> systems)

Initialize the world!

Parameters
systems IList<T>

Exceptions
ArgumentException

⭐ Properties

_cachedRenderSystems

protected readonly SortedList<TKey, TValue> _cachedRenderSystems;

This must be called by engine implementations of Bang to handle with rendering.

Returns
SortedList<TKey, TValue>

_overallStopwatch

protected readonly Stopwatch _overallStopwatch;

This is the stopwatch used on all systems when monitoring performance. Only used if World.DIAGNOSTICS_MODE is set.

Returns
Stopwatch

_stopwatch

protected readonly Stopwatch _stopwatch;

This is the stopwatch used per systems when monitoring performance. Only used if World.DIAGNOSTICS_MODE is set.

Returns
Stopwatch

Contexts

protected readonly Dictionary<TKey, TValue> Contexts;

Maps all the context IDs with the context. We might add new ones if a system calls for a new context filter.

Returns
Dictionary<TKey, TValue>

DIAGNOSTICS_MODE

public static bool DIAGNOSTICS_MODE;

Use this to set whether diagnostics should be pulled from the world run.

Returns
bool

EntityCount

public int EntityCount { get; }

Total of entities in the world. This is useful for displaying debug information.

Returns
int

FixedUpdateCounters

public readonly Dictionary<TKey, TValue> FixedUpdateCounters;

This has the duration of each fixed update system (id) to its corresponding time (in ms). See World.IdToSystem on how to fetch the actual system.

Returns
Dictionary<TKey, TValue>

IdToSystem

public readonly ImmutableDictionary<TKey, TValue> IdToSystem;

Used when fetching systems based on its unique identifier. Maps: System order id -> System instance.

Returns
ImmutableDictionary<TKey, TValue>

IsExiting

public bool IsExiting { get; private set; }

Whether the world is currently being exited, e.g. World.Exit was called.

Returns
bool

IsPaused

public bool IsPaused { get; private set; }

Whether the world has been queried to be on pause or not. See World.Pause.

Returns
bool

ReactiveCounters

public readonly Dictionary<TKey, TValue> ReactiveCounters;

This has the duration of each reactive system (id) to its corresponding time (in ms). See World.IdToSystem on how to fetch the actual system.

Returns
Dictionary<TKey, TValue>

StartCounters

public readonly Dictionary<TKey, TValue> StartCounters;

This has the duration of each start system (id) to its corresponding time (in ms). See World.IdToSystem on how to fetch the actual system.

Returns
Dictionary<TKey, TValue>

UpdateCounters

public readonly Dictionary<TKey, TValue> UpdateCounters;

This has the duration of each update system (id) to its corresponding time (in ms). See World.IdToSystem on how to fetch the actual system.

Returns
Dictionary<TKey, TValue>

⭐ Methods

ClearDiagnosticsCountersForSystem(int)

protected virtual void ClearDiagnosticsCountersForSystem(int systemId)

Implemented by custom world in order to clear diagnostic information about the world.

Parameters
systemId int

InitializeDiagnosticsForSystem(int, ISystem)

protected virtual void InitializeDiagnosticsForSystem(int systemId, ISystem system)

Implemented by custom world in order to express diagnostic information about the world.

Parameters
systemId int
system ISystem

InitializeDiagnosticsCounters()

protected void InitializeDiagnosticsCounters()

Initialize the performance counters according to the systems present in the world.

ActivateSystem()

public bool ActivateSystem()

Activate a system within our world.

Returns
bool

ActivateSystem(Type)

public bool ActivateSystem(Type t)

Activate a system of type within our world.

Parameters
t Type

Returns
bool

DeactivateSystem(bool)

public bool DeactivateSystem(bool immediately)

Deactivate a system within our world.

Parameters
immediately bool

Returns
bool

DeactivateSystem(int, bool)

public bool DeactivateSystem(int id, bool immediately)

Deactivate a system within our world.

Parameters
id int
immediately bool

Returns
bool

DeactivateSystem(Type, bool)

public bool DeactivateSystem(Type t, bool immediately)

Deactivate a system within our world.

Parameters
t Type
immediately bool

Returns
bool

IsSystemActive(Type)

public bool IsSystemActive(Type t)

Whether a system is active within the world.

Parameters
t Type

Returns
bool

FindLookupImplementation()

public ComponentsLookup FindLookupImplementation()

Look for an implementation for the lookup table of components.

Returns
ComponentsLookup

AddEntity()

public Entity AddEntity()

Add a new empty entity to the world. This will map the instance to the world. Any components added after this entity has been created will be notified to any reactive systems.

Returns
Entity

AddEntity(IComponent[])

public Entity AddEntity(IComponent[] components)

Add a single entity to the world (e.g. collection of ). This will map the instance to the world.

Parameters
components IComponent[]

Returns
Entity

AddEntity(T?, IComponent[])

public Entity AddEntity(T? id, IComponent[] components)

Parameters
id T?
components IComponent[]

Returns
Entity

GetEntity(int)

public Entity GetEntity(int id)

Get an entity with the specific id.

Parameters
id int

Returns
Entity

GetUniqueEntity()

public Entity GetUniqueEntity()

Call [World.GetUniqueEntity``1(System.Int32)](../Bang/World.html#getuniqueentity(int) from a generator instead.

Returns
Entity

GetUniqueEntity(int)

public Entity GetUniqueEntity(int index)

Get an entity with the unique component .

Parameters
index int

Returns
Entity

TryGetEntity(int)

public Entity TryGetEntity(int id)

Tries to get an entity with the specific id. If the entity is no longer among us, return null.

Parameters
id int

Returns
Entity

TryGetUniqueEntity()

public Entity TryGetUniqueEntity()

Call [World.TryGetUniqueEntity``1(System.Int32)](../Bang/World.html#trygetuniqueentity(int) from a generator instead.

Returns
Entity

TryGetUniqueEntity(int)

public Entity TryGetUniqueEntity(int index)

Try to get a unique entity that owns .

Parameters
index int

Returns
Entity

GetActivatedAndDeactivatedEntitiesWith(Type[])

public ImmutableArray<T> GetActivatedAndDeactivatedEntitiesWith(Type[] components)

This is very slow. It should get both the activate an deactivate entities. Used when it is absolutely necessary to get both activate and deactivated entities on the filtering.

Parameters
components Type[]

Returns
ImmutableArray<T>

GetAllEntities()

public ImmutableArray<T> GetAllEntities()

This should be used very cautiously! I hope you know what you are doing. It fetches all the entities within the world and return them.

Returns
ImmutableArray<T>

GetEntitiesWith(ContextAccessorFilter, Type[])

public ImmutableArray<T> GetEntitiesWith(ContextAccessorFilter filter, Type[] components)

Retrieve a context for the specified filter and components.

Parameters
filter ContextAccessorFilter
components Type[]

Returns
ImmutableArray<T>

GetEntitiesWith(Type[])

public ImmutableArray<T> GetEntitiesWith(Type[] components)

Retrieve a context for the specified filter and components.

Parameters
components Type[]

Returns
ImmutableArray<T>

GetUnique()

public T GetUnique()

Call [World.GetUnique``1(System.Int32)](../Bang/World.html#getunique(int) from a generator instead.

Returns
T

GetUnique(int)

public T GetUnique(int index)

Get the unique component within an entity. The component has index of .

Parameters
index int

Returns
T

TryGetUnique()

public T? TryGetUnique()

Call [World.TryGetUnique``1(System.Int32)](../Bang/World.html#trygetunique(int) from a generator instead.

Returns
T?

TryGetUnique(int)

public T? TryGetUnique(int index)

Try to get a unique entity that owns . The component has index of .

Parameters
index int

Returns
T?

Dispose()

public virtual void Dispose()

This will first call all IExitSystem to cleanup each system. It will then call Dispose on each of the entities on the world and clear all the collections.

Pause()

public virtual void Pause()

Pause all the set of systems that qualify in World.IsPauseSystem(Bang.Systems.ISystem). A paused system will no longer be called on any World.Update calls.

Resume()

public virtual void Resume()

This will resume all paused systems.

ActivateAllSystems()

public void ActivateAllSystems()

Activate all systems across the world.

DeactivateAllSystems(Type[])

public void DeactivateAllSystems(Type[] skip)

Deactivate all systems across the world.

Parameters
skip Type[]

Exit()

public void Exit()

Call to end all systems. This is called right before shutting down or switching scenes.

FixedUpdate()

public void FixedUpdate()

Calls update on all IFixedUpdateSystem systems. This will be called on fixed intervals.

Start()

public void Start()

Call start on all systems. This is called before any updates and will notify any reactive systems by the end of it.

Update()

public void Update()

Calls update on all IUpdateSystem systems. At the end of update, it will notify all reactive systems of any changes made to entities they were watching. Finally, it destroys all pending entities and clear all messages.