Table of Contents

Class ComponentDependencies

Namespace
KeenEyes
Assembly
KeenEyes.Core.dll

Represents the component read/write dependencies of a system.

public sealed class ComponentDependencies
Inheritance
ComponentDependencies
Inherited Members

Examples

// A system that reads Position and writes Velocity
var deps = new ComponentDependencies(
    reads: [typeof(Position)],
    writes: [typeof(Velocity)]
);

// Check for conflicts with another system
if (deps.ConflictsWith(otherSystemDeps))
{
    // Cannot run in parallel
}

Remarks

Component dependencies are used by the parallel system scheduler to determine which systems can execute concurrently. Systems that don't have conflicting dependencies (no write-write or read-write conflicts on the same component) can run in parallel.

Dependencies can be inferred from registered queries or declared explicitly.

Constructors

ComponentDependencies(IEnumerable<Type>, IEnumerable<Type>)

Represents the component read/write dependencies of a system.

public ComponentDependencies(IEnumerable<Type> reads, IEnumerable<Type> writes)

Parameters

reads IEnumerable<Type>

Component types that are read.

writes IEnumerable<Type>

Component types that are written.

Examples

// A system that reads Position and writes Velocity
var deps = new ComponentDependencies(
    reads: [typeof(Position)],
    writes: [typeof(Velocity)]
);

// Check for conflicts with another system
if (deps.ConflictsWith(otherSystemDeps))
{
    // Cannot run in parallel
}

Remarks

Component dependencies are used by the parallel system scheduler to determine which systems can execute concurrently. Systems that don't have conflicting dependencies (no write-write or read-write conflicts on the same component) can run in parallel.

Dependencies can be inferred from registered queries or declared explicitly.

Fields

Empty

Empty dependencies - no component access.

public static readonly ComponentDependencies Empty

Field Value

ComponentDependencies

Properties

AllAccessed

Gets all component types accessed by this system (reads + writes).

public IReadOnlyCollection<Type> AllAccessed { get; }

Property Value

IReadOnlyCollection<Type>

Reads

Gets the component types that are read by this system.

public IReadOnlyCollection<Type> Reads { get; }

Property Value

IReadOnlyCollection<Type>

Writes

Gets the component types that are written by this system.

public IReadOnlyCollection<Type> Writes { get; }

Property Value

IReadOnlyCollection<Type>

Methods

ConflictsWith(ComponentDependencies)

Checks if this system has a conflict with another system's dependencies.

public bool ConflictsWith(ComponentDependencies other)

Parameters

other ComponentDependencies

The other system's dependencies.

Returns

bool

True if there is a conflict that prevents parallel execution.

Remarks

A conflict exists when: - Both systems write to the same component (write-write conflict) - One system writes and the other reads the same component (read-write conflict)

Two systems that only read the same components can run in parallel.

FromQueries(IEnumerable<QueryDescription>)

Creates dependencies from multiple query descriptions.

public static ComponentDependencies FromQueries(IEnumerable<QueryDescription> descriptions)

Parameters

descriptions IEnumerable<QueryDescription>

The query descriptions.

Returns

ComponentDependencies

Component dependencies merged from all queries.

FromQuery(QueryDescription)

Creates dependencies from a query description.

public static ComponentDependencies FromQuery(QueryDescription description)

Parameters

description QueryDescription

The query description.

Returns

ComponentDependencies

Component dependencies derived from the query.

GetConflictingComponents(ComponentDependencies)

Gets the conflicting component types with another system.

public IReadOnlyCollection<Type> GetConflictingComponents(ComponentDependencies other)

Parameters

other ComponentDependencies

The other system's dependencies.

Returns

IReadOnlyCollection<Type>

The set of component types that cause conflicts.

Merge(ComponentDependencies)

Merges this dependencies with another, returning a new combined instance.

public ComponentDependencies Merge(ComponentDependencies other)

Parameters

other ComponentDependencies

The other dependencies to merge.

Returns

ComponentDependencies

A new ComponentDependencies with all reads and writes from both.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.