Class Circuit
Represents a collection of partition sets that are connected into a single circuit.
Use the pooling mechanism (Get(int) and Free(Circuit)) to obtain and free instances.
A tree structure is used for merging circuits. When one circuit is merged into another, all of its children and the circuit itself are added as children to the other circuit. All children of a root circuit dispatch operations to their root.
Inheritance
Namespace: AS2.Sim
Assembly: .dll
Syntax
public class Circuit
Constructors
| Edit this page View SourceCircuit(int)
Declaration
private Circuit(int id)
Parameters
Type | Name | Description |
---|---|---|
int | id |
Fields
| Edit this page View Sourcechildren
The circuits merged into this one.
Declaration
private List<Circuit> children
Field Value
Type | Description |
---|---|
List<Circuit> |
color
The color in which this circuit should be displayed.
Declaration
private Color color
Field Value
Type | Description |
---|---|
Color |
colorOverride
Indicates whether the circuit color has been set by a partition set.
Declaration
private bool colorOverride
Field Value
Type | Description |
---|---|
bool |
hasBeep
Indicates whether a beep is sent on this circuit in this round.
Declaration
private bool hasBeep
Field Value
Type | Description |
---|---|
bool |
id
The ID given to this circuit while computing circuits in a particle system. Used to easily identify and refer to circuits while merging.
Declaration
public int id
Field Value
Type | Description |
---|---|
int |
message
The message that is sent via this circuit in this round.
null
if no message is sent.
Declaration
private Message message
Field Value
Type | Description |
---|---|
Message |
numPartitionSets
The number of partition sets added directly to this circuit. Since this circuit might be merged into a larger one, this number is not always up to date.
Declaration
private int numPartitionSets
Field Value
Type | Description |
---|---|
int |
pool
A stack that contains the currently unused circuits.
Declaration
private static Stack<Circuit> pool
Field Value
Type | Description |
---|---|
Stack<Circuit> |
rootParent
Reference to the root circuit that contains this one.
null
if this circuit is the root.
Declaration
private Circuit rootParent
Field Value
Type | Description |
---|---|
Circuit |
Properties
| Edit this page View SourceNumPartitionSets
The number of partition sets belonging to this circuit.
Declaration
public int NumPartitionSets { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceAddPartitionSet(SysPartitionSet)
Adds the given partition set to this circuit.
If the partition set has a planned beep or message or has defined a display color, this information will be stored in the circuit.
Declaration
public void AddPartitionSet(SysPartitionSet ps)
Parameters
Type | Name | Description |
---|---|---|
SysPartitionSet | ps | The partition set to be added. |
AddPartitionSetRoot(SysPartitionSet)
Counterpart to AddPartitionSet(SysPartitionSet) to be called on the root only.
Declaration
private void AddPartitionSetRoot(SysPartitionSet ps)
Parameters
Type | Name | Description |
---|---|---|
SysPartitionSet | ps | The partition set to be added. |
Free(Circuit)
Returns the given circuit instance to the pool.
Declaration
public static void Free(Circuit c)
Parameters
Type | Name | Description |
---|---|---|
Circuit | c | The circuit to be returned to the pool. |
Get(int)
Returns a new circuit instance with the given ID.
Use Free(Circuit) on the instance when it is not needed anymore so that it can be reused later.
Declaration
public static Circuit Get(int id)
Parameters
Type | Name | Description |
---|---|---|
int | id | The ID for the new circuit. |
Returns
Type | Description |
---|---|
Circuit | A new circuit instance obtained from the pool or newly created. |
GetColor()
Returns the color in which the circuit should be displayed. This may be one of the default colors or a color defined by a partition set.
Declaration
public Color GetColor()
Returns
Type | Description |
---|---|
Color | The desired display color of the circuit. |
GetMessage()
Gets the message sent on this circuit in this round.
Declaration
public Message GetMessage()
Returns
Type | Description |
---|---|
Message | The message sent on this circuit in this round,
or |
GetRoot()
Returns the root circuit in this circuit's tree.
Declaration
private Circuit GetRoot()
Returns
Type | Description |
---|---|
Circuit | The root of the circuit tree to which this circuit belongs. |
HasBeep()
Checks whether a beep has been sent on this circuit.
Declaration
public bool HasBeep()
Returns
Type | Description |
---|---|
bool |
|
HasColorOverride()
Checks whether the color of this circuit was changed by a partition set.
Declaration
public bool HasColorOverride()
Returns
Type | Description |
---|---|
bool |
|
IsRoot()
Checks whether this circuit is currently a root.
Declaration
public bool IsRoot()
Returns
Type | Description |
---|---|
bool |
|
MergeOther(Circuit)
Merges the given other circuit into this one. If one of the circuits has a color override, that color is used. If both circuits have a color override, the color of this circuit is used.
Declaration
private void MergeOther(Circuit other)
Parameters
Type | Name | Description |
---|---|---|
Circuit | other | The circuit to be merged into this one. It will be set to inactive after the merge. |
MergeWith(Circuit)
Merges this circuit with the given other circuit.
Nothing happens if the other circuit is the same as this one. Otherwise, the smaller circuit is merged into the bigger one and the smaller one is set to be inactive. If one of the circuits has a planned beep, the resulting circuit will also have a planned beep. If any of the two circuits has a message, the message with the higher priority is sent on the resulting circuit. The color is determined by override if only one has a color set or by the larger one if both have a color override.
Declaration
public void MergeWith(Circuit other)
Parameters
Type | Name | Description |
---|---|---|
Circuit | other | The circuit to merge this one with. |
MergeWithRoot(Circuit)
Counterpart to MergeWith(Circuit) to be called on the root only.
Declaration
private void MergeWithRoot(Circuit other)
Parameters
Type | Name | Description |
---|---|---|
Circuit | other | The other circuit to merge with this root. |
Reset(int)
Completely reinitializes the circuit with a new ID.
Declaration
private void Reset(int id)
Parameters
Type | Name | Description |
---|---|---|
int | id | The new ID. |
SameCircuitAs(Circuit)
Checks whether this circuit is part of the same tree as the given circuit.
Declaration
public bool SameCircuitAs(Circuit other)
Parameters
Type | Name | Description |
---|---|---|
Circuit | other | The other circuit to be checked. |
Returns
Type | Description |
---|---|
bool |
|
SetColor(Color)
Sets the display color of this circuit.
Declaration
public void SetColor(Color c)
Parameters
Type | Name | Description |
---|---|---|
Color | c | The new color in which the circuit should be displayed. |