|
|
@@ -56,12 +56,8 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
|
|
|
|
public bool SetSignal(uint signalID, float signal, bool input = true) |
|
|
|
{ |
|
|
|
ExclusiveGroup group = input ? NamedExclusiveGroup<InputPortsGroup>.Group : NamedExclusiveGroup<OutputPortsGroup>.Group; |
|
|
|
if (entitiesDB.Exists<PortEntityStruct>(signalID, group)) |
|
|
|
{ |
|
|
|
entitiesDB.QueryEntity<PortEntityStruct>(signalID, group).anyChannel.valueAsFloat = signal; |
|
|
|
return true; |
|
|
|
} |
|
|
|
var array = GetSignalStruct(signalID, out uint index, input); |
|
|
|
if (array != null) array[index].valueAsFloat = signal; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@@ -73,25 +69,27 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
|
|
|
|
public float AddSignal(uint signalID, float signal, bool clamp = true, bool input = true) |
|
|
|
{ |
|
|
|
ExclusiveGroup group = input ? NamedExclusiveGroup<InputPortsGroup>.Group : NamedExclusiveGroup<OutputPortsGroup>.Group; |
|
|
|
if (entitiesDB.Exists<PortEntityStruct>(signalID, group)) |
|
|
|
{ |
|
|
|
ref PortEntityStruct pes = ref entitiesDB.QueryEntity<PortEntityStruct>(signalID, group); |
|
|
|
pes.anyChannel.valueAsFloat += signal; |
|
|
|
if (clamp) |
|
|
|
{ |
|
|
|
if (pes.anyChannel.valueAsFloat > Signals.POSITIVE_HIGH) |
|
|
|
{ |
|
|
|
pes.anyChannel.valueAsFloat = Signals.POSITIVE_HIGH; |
|
|
|
} |
|
|
|
else if (pes.anyChannel.valueAsFloat < Signals.NEGATIVE_HIGH) |
|
|
|
{ |
|
|
|
pes.anyChannel.valueAsFloat = Signals.NEGATIVE_HIGH; |
|
|
|
} |
|
|
|
return pes.anyChannel.valueAsFloat; |
|
|
|
} |
|
|
|
} |
|
|
|
return signal; |
|
|
|
var array = GetSignalStruct(signalID, out uint index, input); |
|
|
|
if (array != null) |
|
|
|
{ |
|
|
|
ref var channelData = ref array[index]; |
|
|
|
channelData.valueAsFloat += signal; |
|
|
|
if (clamp) |
|
|
|
{ |
|
|
|
if (channelData.valueAsFloat > Signals.POSITIVE_HIGH) |
|
|
|
{ |
|
|
|
channelData.valueAsFloat = Signals.POSITIVE_HIGH; |
|
|
|
} |
|
|
|
else if (channelData.valueAsFloat < Signals.NEGATIVE_HIGH) |
|
|
|
{ |
|
|
|
channelData.valueAsFloat = Signals.NEGATIVE_HIGH; |
|
|
|
} |
|
|
|
|
|
|
|
return channelData.valueAsFloat; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return signal; |
|
|
|
} |
|
|
|
|
|
|
|
public float GetSignal(EGID blockID, out uint signalID, bool input = true) |
|
|
@@ -102,12 +100,8 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
|
|
|
|
public float GetSignal(uint signalID, bool input = true) |
|
|
|
{ |
|
|
|
ExclusiveGroup group = input ? NamedExclusiveGroup<InputPortsGroup>.Group : NamedExclusiveGroup<OutputPortsGroup>.Group; |
|
|
|
if (entitiesDB.Exists<PortEntityStruct>(signalID, group)) |
|
|
|
{ |
|
|
|
return entitiesDB.QueryEntity<PortEntityStruct>(signalID, group).anyChannel.valueAsFloat; |
|
|
|
} |
|
|
|
return 0f; |
|
|
|
var array = GetSignalStruct(signalID, out uint index, input); |
|
|
|
return array?[index].valueAsFloat ?? 0f; |
|
|
|
} |
|
|
|
|
|
|
|
public uint[] GetSignalIDs(EGID blockID, bool input = true) |
|
|
@@ -147,5 +141,23 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
} |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
private ChannelDataStruct[] GetSignalStruct(uint signalID, out uint index, bool input = true) |
|
|
|
{ |
|
|
|
ExclusiveGroup group = input |
|
|
|
? NamedExclusiveGroup<InputPortsGroup>.Group |
|
|
|
: NamedExclusiveGroup<OutputPortsGroup>.Group; |
|
|
|
if (entitiesDB.Exists<PortEntityStruct>(signalID, group)) |
|
|
|
{ |
|
|
|
index = entitiesDB.QueryEntity<PortEntityStruct>(signalID, group).anyChannelIndex; |
|
|
|
ChannelDataStruct[] channelData = entitiesDB |
|
|
|
.QueryEntities<ChannelDataStruct>(NamedExclusiveGroup<ChannelDataGroup>.Group) |
|
|
|
.ToFastAccess(out uint _); |
|
|
|
return channelData; |
|
|
|
} |
|
|
|
|
|
|
|
index = 0; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |