Skip to content

Commit

Permalink
perf(default): Updated visuals, added thumbnail, corrected bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
richardspence committed Nov 23, 2021
1 parent c319eb5 commit 15e14d0
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 49 deletions.
54 changes: 50 additions & 4 deletions AutomationPlus/Alu8Gate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override int GetInputValue1()
var val1 = base.GetInputValue1();
var val2 = this.ports?.GetInputValue(Alu8Gate.INPUT_PORT_ID1B) ?? 0;

return (val1 << 3) | val2;
return (val1 << 4) | val2;

}

Expand All @@ -33,7 +33,7 @@ public override int GetInputValue2()
var val1 = base.GetInputValue2();
var val2 = this.ports?.GetInputValue(Alu8Gate.INPUT_PORT_ID2B) ?? 0;

return (val1 << 3) | val2;
return (val1 << 4) | val2;

}

Expand All @@ -45,8 +45,8 @@ protected override bool ShouldRecalcValue(LogicValueChanged logicValueChanged)

protected override void UpdateValue()
{
var val1 = this.currentValue >> 3;
var val2 = this.currentValue | 0xf;
var val1 = this.currentValue >> 4;
var val2 = this.currentValue & 0xf;
this.GetComponent<LogicPorts>().SendSignal(AluGate.OUTPUT_PORT_ID, val1);
this.GetComponent<LogicPorts>().SendSignal(Alu8Gate.OUTPUT_PORT_IDB, val2);
}
Expand All @@ -58,5 +58,51 @@ protected override bool HasPort(HashedString portId)
|| portId == Alu8Gate.INPUT_PORT_ID2B
|| portId == Alu8Gate.OUTPUT_PORT_IDB;
}

protected override void ToggleBlooms()
{
var nw1 = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.INPUT_PORT_ID1));
var nw1b = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.INPUT_PORT_ID1B));
var nw2 = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.INPUT_PORT_ID2));
var nw2b = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.INPUT_PORT_ID2B));
var nwOp = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.OP_PORT_ID));
var nwOut = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.OUTPUT_PORT_ID));
var nwOutb = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(Alu8Gate.OUTPUT_PORT_IDB));
ShowSymbolConditionally(nwOp, () => nwOp.OutputValue > 0, $"light{24}_bloom_green", $"light{24}_bloom_red");


//16-19 outb
ShowSymbolConditionally(nwOutb, () => LogicCircuitNetwork.IsBitActive(3, nwOutb.OutputValue), $"light{19}_bloom_green", $"light{19}_bloom_red");
ShowSymbolConditionally(nwOutb, () => LogicCircuitNetwork.IsBitActive(2, nwOutb.OutputValue), $"light{18}_bloom_green", $"light{18}_bloom_red");
ShowSymbolConditionally(nwOutb, () => LogicCircuitNetwork.IsBitActive(1, nwOutb.OutputValue), $"light{17}_bloom_green", $"light{17}_bloom_red");
ShowSymbolConditionally(nwOutb, () => LogicCircuitNetwork.IsBitActive(0, nwOutb.OutputValue), $"light{16}_bloom_green", $"light{16}_bloom_red");
// 20-23 out
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(3, nwOut.OutputValue), $"light{23}_bloom_green", $"light{23}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(2, nwOut.OutputValue), $"light{22}_bloom_green", $"light{22}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(1, nwOut.OutputValue), $"light{21}_bloom_green", $"light{21}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(0, nwOut.OutputValue), $"light{20}_bloom_green", $"light{20}_bloom_red");

//in1b 0-3
ShowSymbolConditionally(nw1b, () => LogicCircuitNetwork.IsBitActive(3, nw1b.OutputValue), $"light{3}_bloom_green", $"light{3}_bloom_red");
ShowSymbolConditionally(nw1b, () => LogicCircuitNetwork.IsBitActive(2, nw1b.OutputValue), $"light{2}_bloom_green", $"light{2}_bloom_red");
ShowSymbolConditionally(nw1b, () => LogicCircuitNetwork.IsBitActive(1, nw1b.OutputValue), $"light{1}_bloom_green", $"light{1}_bloom_red");
ShowSymbolConditionally(nw1b, () => LogicCircuitNetwork.IsBitActive(0, nw1b.OutputValue), $"light{0}_bloom_green", $"light{0}_bloom_red");
//in1 4-7
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(3, nw1.OutputValue), $"light{7}_bloom_green", $"light{7}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(2, nw1.OutputValue), $"light{6}_bloom_green", $"light{6}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(1, nw1.OutputValue), $"light{5}_bloom_green", $"light{5}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(0, nw1.OutputValue), $"light{4}_bloom_green", $"light{4}_bloom_red");

//in2b 8-11
ShowSymbolConditionally(nw2b, () => LogicCircuitNetwork.IsBitActive(3, nw2b.OutputValue), $"light{11}_bloom_green", $"light{11}_bloom_red");
ShowSymbolConditionally(nw2b, () => LogicCircuitNetwork.IsBitActive(2, nw2b.OutputValue), $"light{10}_bloom_green", $"light{10}_bloom_red");
ShowSymbolConditionally(nw2b, () => LogicCircuitNetwork.IsBitActive(1, nw2b.OutputValue), $"light{9}_bloom_green", $"light{9}_bloom_red");
ShowSymbolConditionally(nw2b, () => LogicCircuitNetwork.IsBitActive(0, nw2b.OutputValue), $"light{8}_bloom_green", $"light{8}_bloom_red");
//in2 12-15
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(3, nw2.OutputValue), $"light{15}_bloom_green", $"light{15}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(2, nw2.OutputValue), $"light{14}_bloom_green", $"light{14}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(1, nw2.OutputValue), $"light{13}_bloom_green", $"light{13}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(0, nw2.OutputValue), $"light{12}_bloom_green", $"light{12}_bloom_red");
}
}
}
2 changes: 1 addition & 1 deletion AutomationPlus/Alu8GateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override BuildingDef CreateBuildingDef()
LogicPorts.Port.RibbonInputPort(AluGate.INPUT_PORT_ID1, new CellOffset(0, 2), (string) Alu8GateStrings.INPUT_PORT1, (string) Alu8GateStrings.INPUT_PORT_ACTIVE, (string) Alu8GateStrings.INPUT_PORT_INACTIVE , true, true),
LogicPorts.Port.RibbonInputPort(Alu8Gate.INPUT_PORT_ID2B, new CellOffset(0, 1), (string) Alu8GateStrings.INPUT_PORT2B, (string) Alu8GateStrings.INPUT_PORT_ACTIVE, (string) Alu8GateStrings.INPUT_PORT_INACTIVE , true, true),
LogicPorts.Port.RibbonInputPort(AluGate.INPUT_PORT_ID2, new CellOffset(0, 0), (string) Alu8GateStrings.INPUT_PORT2, (string) Alu8GateStrings.INPUT_PORT_ACTIVE, (string) Alu8GateStrings.INPUT_PORT_INACTIVE , true, true),
new LogicPorts.Port(AluGate.OP_PORT_ID, new CellOffset(1, 0), Alu8GateStrings.OP_PORT_DESCRIPTION, Alu8GateStrings.OP_CODE_ACTIVE, Alu8GateStrings.OP_CODE_INACTIVE, true, LogicPortSpriteType.ControlInput, true),
new LogicPorts.Port(AluGate.OP_PORT_ID, new CellOffset(1, 0), Alu8GateStrings.OP_PORT_DESCRIPTION, Alu8GateStrings.OP_CODE_ACTIVE, Alu8GateStrings.OP_CODE_INACTIVE, false, LogicPortSpriteType.ControlInput, true),
};
buildingDef.LogicOutputPorts = new List<LogicPorts.Port>() {
LogicPorts.Port.RibbonOutputPort(Alu8Gate.OUTPUT_PORT_IDB, new CellOffset(1, 3), Alu8GateStrings.OUTPUT_NAMEB, Alu8GateStrings.OUTPUT_ACTIVE, Alu8GateStrings.OUTPUT_INACTIVE, true, true),
Expand Down
109 changes: 83 additions & 26 deletions AutomationPlus/AluGate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,37 @@

namespace AutomationPlus
{
//enum AluGateOperators
//{
// none = 0x0,
// add = 0x1,
// subtract = 0x2,
// multiply = 0x4,
// modulus = 0x5,
// exp = 0x6,
// divide = 0x8,
// logicalBitRight = 0xD,
// logicalBitLeft = 0xE, //(6) (==, !=, <=, >= , <, >)
//}

enum AluGateOperators
{
none = 0x0,
add = 0x1,
subtract = 0x2,
multiply = 0x4,
modulus = 0x5,
exp = 0x6,
divide = 0x8,
logicalBitRight = 0xD,
logicalBitLeft = 0xE, //(6) (==, !=, <=, >= , <, >)
multiply = 0x3,
modulus = 0x4,
exp = 0x5,
divide = 0x6,
logicalBitRight = 0x7,
logicalBitLeft = 0x8,
equal = 0x9,
notEqual = 0xA,
lessThan = 0xB,
greaterThan = 0xC,
lessThanOrEqual = 0xD,
greaterThanOrEqual = 0xE,
plusPlus = 0xF,
}

class BinaryFormatter : IFormatProvider, ICustomFormatter
Expand Down Expand Up @@ -166,9 +186,9 @@ class AluGate : KMonoBehaviour
private KBatchedAnimController kbac;

[Serialize]
private int lhs;
protected int lhs;
[Serialize]
private int rhs;
protected int rhs;
[Serialize]
private AluGateOperators _inputOpCode;

Expand Down Expand Up @@ -346,7 +366,6 @@ public void OnLogicValueChanged(object data)
{
return;
}
this.ports.inputPortInfo[2].requiresConnection = false;
var nw1 = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.INPUT_PORT_ID1));
var nw2 = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.INPUT_PORT_ID2));
var nwOut = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.OP_PORT_ID));
Expand Down Expand Up @@ -402,22 +421,7 @@ private void RefreshAnimations()
{
this.kbac.Play("on_0");

ShowSymbolConditionally(nwOp, () => nwOp.OutputValue > 0, $"light{8}_bloom_green", $"light{8}_bloom_red");

ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(3, currentValue), $"light{12}_bloom_green", $"light{12}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(2, currentValue), $"light{11}_bloom_green", $"light{11}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(1, currentValue), $"light{10}_bloom_green", $"light{10}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(0, currentValue), $"light{9}_bloom_green", $"light{9}_bloom_red");

ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(3, rhs), $"light{7}_bloom_green", $"light{7}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(2, rhs), $"light{6}_bloom_green", $"light{6}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(1, rhs), $"light{5}_bloom_green", $"light{5}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(0, rhs), $"light{4}_bloom_green", $"light{4}_bloom_red");

ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(3, lhs), $"light{3}_bloom_green", $"light{3}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(2, lhs), $"light{2}_bloom_green", $"light{2}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(1, lhs), $"light{1}_bloom_green", $"light{1}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(0, lhs), $"light{0}_bloom_green", $"light{0}_bloom_red");
ToggleBlooms();

DisplayOperator();

Expand All @@ -431,6 +435,30 @@ private void RefreshAnimations()

}

protected virtual void ToggleBlooms()
{
var nw1 = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.INPUT_PORT_ID1));
var nw2 = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.INPUT_PORT_ID2));
var nwOp = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.OP_PORT_ID));
var nwOut = Game.Instance.logicCircuitManager.GetNetworkForCell(this.ports.GetPortCell(AluGate.OUTPUT_PORT_ID));
ShowSymbolConditionally(nwOp, () => nwOp.OutputValue > 0, $"light{8}_bloom_green", $"light{8}_bloom_red");

ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(3, currentValue), $"light{12}_bloom_green", $"light{12}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(2, currentValue), $"light{11}_bloom_green", $"light{11}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(1, currentValue), $"light{10}_bloom_green", $"light{10}_bloom_red");
ShowSymbolConditionally(nwOut, () => LogicCircuitNetwork.IsBitActive(0, currentValue), $"light{9}_bloom_green", $"light{9}_bloom_red");

ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(3, rhs), $"light{7}_bloom_green", $"light{7}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(2, rhs), $"light{6}_bloom_green", $"light{6}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(1, rhs), $"light{5}_bloom_green", $"light{5}_bloom_red");
ShowSymbolConditionally(nw2, () => LogicCircuitNetwork.IsBitActive(0, rhs), $"light{4}_bloom_green", $"light{4}_bloom_red");

ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(3, lhs), $"light{3}_bloom_green", $"light{3}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(2, lhs), $"light{2}_bloom_green", $"light{2}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(1, lhs), $"light{1}_bloom_green", $"light{1}_bloom_red");
ShowSymbolConditionally(nw1, () => LogicCircuitNetwork.IsBitActive(0, lhs), $"light{0}_bloom_green", $"light{0}_bloom_red");
}

private void DisplayOperator()
{
ToggleOperator(_inputOpCode == AluGateOperators.add, "op_add");
Expand All @@ -441,6 +469,14 @@ private void DisplayOperator()
ToggleOperator(_inputOpCode == AluGateOperators.modulus, "op_mod");
ToggleOperator(_inputOpCode == AluGateOperators.multiply, "op_mul");
ToggleOperator(_inputOpCode == AluGateOperators.subtract, "op_minus");
ToggleOperator(_inputOpCode == AluGateOperators.lessThan, "op_less");
ToggleOperator(_inputOpCode == AluGateOperators.lessThanOrEqual, "op_lessThanOrEqual");
ToggleOperator(_inputOpCode == AluGateOperators.greaterThan, "op_more");
ToggleOperator(_inputOpCode == AluGateOperators.greaterThanOrEqual, "op_moreThanOrEqual");
ToggleOperator(_inputOpCode == AluGateOperators.plusPlus, "op_addadd");
ToggleOperator(_inputOpCode == AluGateOperators.equal, "op_equality");
ToggleOperator(_inputOpCode == AluGateOperators.notEqual, "op_not_equality");

}

private void ToggleOperator(
Expand Down Expand Up @@ -505,6 +541,27 @@ private void RecalcValues()
case AluGateOperators.logicalBitLeft:
currentValue = lhs << rhs;
break;
case AluGateOperators.equal:
currentValue = lhs == rhs ? 1 : 0;
break;
case AluGateOperators.notEqual:
currentValue = lhs != rhs ? 1 : 0;
break;
case AluGateOperators.lessThan:
currentValue = lhs < rhs ? 1 : 0;
break;
case AluGateOperators.lessThanOrEqual:
currentValue = lhs <= rhs ? 1 : 0;
break;
case AluGateOperators.greaterThan:
currentValue = lhs > rhs ? 1 : 0;
break;
case AluGateOperators.greaterThanOrEqual:
currentValue = lhs >= rhs ? 1 : 0;
break;
case AluGateOperators.plusPlus:
currentValue = lhs + 1;
break;
case AluGateOperators.none:
default:
break;
Expand All @@ -519,7 +576,7 @@ private void RecalcValues()



private void ShowSymbolConditionally(
protected void ShowSymbolConditionally(
object nw,
Func<bool> active,
KAnimHashedString ifTrue,
Expand Down
2 changes: 1 addition & 1 deletion AutomationPlus/AluGateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override BuildingDef CreateBuildingDef()
buildingDef.AlwaysOperational = true;
buildingDef.LogicInputPorts = new List<LogicPorts.Port>() {
LogicPorts.Port.RibbonInputPort(AluGate.INPUT_PORT_ID1, new CellOffset(0, 1), (string) AluGateStrings.INPUT_PORT1, (string) AluGateStrings.INPUT_PORT_ACTIVE, (string) AluGateStrings.INPUT_PORT_INACTIVE , true, true),
LogicPorts.Port.RibbonInputPort(AluGate.INPUT_PORT_ID2, new CellOffset(0, 0), (string) AluGateStrings.INPUT_PORT2, (string) AluGateStrings.INPUT_PORT_ACTIVE, (string) AluGateStrings.INPUT_PORT_INACTIVE , true, true),
LogicPorts.Port.RibbonInputPort(AluGate.INPUT_PORT_ID2, new CellOffset(0, 0), (string) AluGateStrings.INPUT_PORT2, (string) AluGateStrings.INPUT_PORT_ACTIVE, (string) AluGateStrings.INPUT_PORT_INACTIVE , false, true),
new LogicPorts.Port(AluGate.OP_PORT_ID, new CellOffset(1, 1), AluGateStrings.OP_PORT_DESCRIPTION, AluGateStrings.OP_CODE_ACTIVE, AluGateStrings.OP_CODE_INACTIVE, false, LogicPortSpriteType.ControlInput, true),
};
buildingDef.LogicOutputPorts = new List<LogicPorts.Port>() {
Expand Down
7 changes: 7 additions & 0 deletions AutomationPlus/AluGateSideScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class AluGateSideScreen : SideScreenContent
{ AluGateOperators.exp , "Exponent" },
{ AluGateOperators.logicalBitLeft , "Bit Shift Left" },
{ AluGateOperators.logicalBitRight ,"Bit Shift Right"},
{ AluGateOperators.equal ,"Equal"},
{ AluGateOperators.notEqual ,"Not Equal"},
{ AluGateOperators.lessThan ,"Less than"},
{ AluGateOperators.lessThanOrEqual ,"Less than or equal"},
{ AluGateOperators.greaterThan ,"Greater than"},
{ AluGateOperators.greaterThanOrEqual ,"Greater than or equal"},
{ AluGateOperators.plusPlus ,"Increment by one"},
};
private AluGate targetAluGate;
public AluGateSideScreen()
Expand Down
21 changes: 14 additions & 7 deletions AutomationPlus/AluGateStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ class AluGateStrings
public static LocString DESC = (LocString)$@"The ALU can perform multiple operations on the inputs.
Operator Codes:
add = 0x1 (0001)
subtract = 0x2 (0010),
multiply = 0x4 (0100),
modulus = 0x5 (0101),
exp = 0x6 (0110),
divide = 0x8 (1000),
logicalBitRight = 0xD (1101),
logicalBitLeft = 0xE, (1110)
subtract = 0x2 (0010)
multiply = 0x3 (0011)
modulus = 0x4 (0100)
exp = 0x5 (0101)
divide = 0x6 (0110)
logicalBitRight = 0x7 (0111)
logicalBitLeft = 0x8 (1000)
equal = 0x9 (1001)
notEqual = 0xA (1010)
lessThan = 0xB (1011)
greaterThan = 0xC (1100)
lessThanOrEqual = 0xD (1101)
greaterThanOrEqual = 0xE (1110)
plusPlus = 0xF (1111)
Signed numbers when enabled sets the ALU into using a twos complement binary number system. When enabled, the first bit when active {UI.FormatAsAutomationState("active", UI.AutomationState.Active)} signifies a negative number.";

Expand Down
2 changes: 1 addition & 1 deletion AutomationPlus/DisplayAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static DisplayInfo GetDisplayInfo(bool IsHexMode, int value)
var displayMap = GetDisplayMap(IsHexMode);
if (!displayMap.ContainsKey(value))
{
value = 12;
value = IsHexMode? 15: 12;
}

return displayMap[value];
Expand Down
Loading

0 comments on commit 15e14d0

Please sign in to comment.