Tweaking ProtoSignalling

Michael

Moderator
Contributor
Architecture
I've been working on a slight rework of signaling. The Protosignal model is quite a bit more inefficient when compared to the original module but I think this module is easier to add additional blocks to the network. The backend implementation of the graph will need to be reworked, but this is just a proof of concept. The example code below shows how a signal is handled at a leaf for XOR ,AND and ,OR. The module is more event oriented so it should be easier to add more blocks to the module.

I also don't maintain a clunky graph of the network that is separate from the world. This should reduce the amount of memory for each node in the network. The performance problem will need to be addressed at some point.

Java:
    @In
    private SignalSystem signalSystem;

    @ReceiveEvent(components = {BlockComponent.class, XorGateComponent.class, SignalLeafComponent.class})
    public void signalXorChange(LeafNodeSignalChange event, EntityRef entity, BlockComponent blockComponent, XorGateComponent xorGateComponent) {
        if (event.getInputs().size() == 1 && event.getInputs().size() != 0) {
            for (Side side : SideBitFlag.getSides(signalSystem.getConnectedOutputs(entity))) {
                signalSystem.setLeafOutput(entity, side, xorGateComponent.strength,xorGateComponent.delay);
            }
        } else {
            for (Side side : SideBitFlag.getSides(signalSystem.getConnectedOutputs(entity))) {
                signalSystem.setLeafOutput(entity, side, (byte) 0,xorGateComponent.delay);
            }
        }
    }

    @ReceiveEvent(components = {BlockComponent.class, AndGateComponent.class, SignalLeafComponent.class})
    public void signalAndChange(LeafNodeSignalChange event, EntityRef entity, BlockComponent blockComponent, AndGateComponent andGateComponent) {

        if (event.getInputs().size() == SideBitFlag.getSides(signalSystem.getConnectedInputs(entity)).size() && event.getInputs().size() != 0) {
            for (Side side : SideBitFlag.getSides(signalSystem.getConnectedOutputs(entity))) {
                signalSystem.setLeafOutput(entity, side, andGateComponent.strength,andGateComponent.delay);
            }
        } else {
            for (Side side : SideBitFlag.getSides(signalSystem.getConnectedOutputs(entity))) {
                signalSystem.setLeafOutput(entity, side, (byte) 0,andGateComponent.delay);
            }
        }
    }

    @ReceiveEvent(components = {BlockComponent.class, OrGateComponent.class, SignalLeafComponent.class})
    public void signalOrChange(LeafNodeSignalChange event, EntityRef entity, BlockComponent blockComponent,OrGateComponent orGateComponent) {
        if (event.getInputs().size() > 0 && event.getInputs().size() != 0) {
            for (Side side : SideBitFlag.getSides(signalSystem.getConnectedOutputs(entity))) {
                signalSystem.setLeafOutput(entity, side, orGateComponent.strength,orGateComponent.delay);
            }
        } else {
            for (Side side : SideBitFlag.getSides(signalSystem.getConnectedOutputs(entity))) {
                signalSystem.setLeafOutput(entity, side, (byte) 0,orGateComponent.delay);
            }
        }
}
 
Last edited:
Top