Simple display test

This commit is contained in:
Stone_Red
2023-10-04 16:16:05 +02:00
parent f1992193e9
commit 1f78c8e36e
2 changed files with 37 additions and 13 deletions
@@ -11,19 +11,43 @@ namespace StoneRed.LogicSimulator.Simulation.LogicGates;
[LogicGateName("Test")] [LogicGateName("Test")]
internal class TestLogicGate : LogicGate, Interfaces.IDrawable internal class TestLogicGate : LogicGate, Interfaces.IDrawable
{ {
public override int OutputCount { get; set; } = 1; private readonly Color[] colors = new Color[9];
public override int InputCount { get; set; } = 1; private Texture2D texture = null!;
public override int OutputCount { get; set; } = 0;
public override int InputCount { get; set; } = 9;
public Texture2D Texture => CreateTexture(1, 1); public Texture2D Texture
{
get
{
Draw();
return texture;
}
}
protected internal override void Initialize()
{
texture = CreateTexture(3, 3);
texture.SetData(new Color[]
{
Color.Red, Color.Blue, Color.Red,
Color.Blue, Color.Red, Color.Blue,
Color.Red, Color.Blue, Color.Red
});
}
protected override void Execute() protected override void Execute()
{ {
Texture.SetData(new Color[] { Color.Red });
for (int i = 0; i < InputCount; i++) for (int i = 0; i < InputCount; i++)
{ {
SetOutputBit(GetInputBit(i), i); colors[i] = GetInputBit(i) == 1 ? Color.Red : Color.Gray;
} }
} }
private void Draw()
{
texture.SetData(colors);
}
} }
#endif #endif
@@ -98,7 +98,7 @@ internal class WorldScreen : SrlsScreen<Grid>
fps = 1f / gameTime.GetElapsedSeconds(); fps = 1f / gameTime.GetElapsedSeconds();
Matrix transformMatrix = camera.GetViewMatrix(); Matrix transformMatrix = camera.GetViewMatrix();
srls.SpriteBatch.Begin(SpriteSortMode.BackToFront, transformMatrix: transformMatrix); srls.SpriteBatch.Begin(SpriteSortMode.BackToFront, samplerState: SamplerState.PointClamp, transformMatrix: transformMatrix);
foreach (LogicGate logicGate in simulator.GetLogicGates()) foreach (LogicGate logicGate in simulator.GetLogicGates())
{ {
@@ -336,11 +336,11 @@ internal class WorldScreen : SrlsScreen<Grid>
if (connectionContext.IsInput) if (connectionContext.IsInput)
{ {
isConnected = logicGate.IsConnectedTo(connectionContext.LogicGate); isConnected = logicGate.IsConnectedTo(connectionContext.LogicGate, connectionContext.Index, i);
} }
else else
{ {
isConnected = connectionContext.LogicGate.IsConnectedTo(logicGate); isConnected = connectionContext.LogicGate.IsConnectedTo(logicGate, i, connectionContext.Index);
} }
connectionStatus = isConnected ? "[Disconnect]" : "[Connect]"; connectionStatus = isConnected ? "[Disconnect]" : "[Connect]";
@@ -382,9 +382,9 @@ internal class WorldScreen : SrlsScreen<Grid>
if (connectionContext.IsInput) if (connectionContext.IsInput)
{ {
if (logicGate.IsConnectedTo(connectionContext.LogicGate)) if (logicGate.IsConnectedTo(connectionContext.LogicGate, connectionContext.Index, index))
{ {
logicGate.Disconnect(connectionContext.LogicGate); logicGate.Disconnect(connectionContext.LogicGate, connectionContext.Index, index);
} }
else else
{ {
@@ -393,9 +393,9 @@ internal class WorldScreen : SrlsScreen<Grid>
} }
else else
{ {
if (connectionContext.LogicGate.IsConnectedTo(logicGate)) if (connectionContext.LogicGate.IsConnectedTo(logicGate, index, connectionContext.Index))
{ {
connectionContext.LogicGate.Disconnect(logicGate); connectionContext.LogicGate.Disconnect(logicGate, index, connectionContext.Index);
} }
else else
{ {