Search in sources :

Example 11 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class RenderGraph method reconnectRunOrder.

public void reconnectRunOrder(Node fromNode, int outputId, Node toNode, int inputId) {
    DependencyConnection connectionToReconnect = toNode.getInputRunOrderConnection(inputId);
    // for each output connected to toNode's input fbo connection(inputId) (should be just one)
    if (connectionToReconnect != null) {
        connectionToReconnect.getConnectedConnections().forEach((conUri, outputConnection) -> {
            ((DependencyConnection) outputConnection).getConnectedConnections().remove(connectionToReconnect.getName());
        });
        // connectionToReconnect gets removed and then created again
        toNode.removeRunOrderConnection(inputId, DependencyConnection.Type.INPUT);
    }
    connectRunOrder(fromNode, outputId, toNode, inputId);
}
Also used : DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)

Example 12 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class RenderGraph method reconnectAllConnectedInputsTo.

/**
 * Insert node's connection after a specific node's connection and reconnect the other previously connected nodes's connections
 * to the new one. Simple approach, maintain structure 1 to N. For M to N output do manually.
 */
public void reconnectAllConnectedInputsTo(DependencyConnection connectionToReplace, DependencyConnection newOutputConnection) {
    Node fromNode = findNode(connectionToReplace.getParentNode());
    ConnectionType connectionType;
    if (newOutputConnection instanceof FboConnection) {
        connectionType = ConnectionType.FBO;
    } else if (newOutputConnection instanceof BufferPairConnection) {
        connectionType = ConnectionType.BUFFER_PAIR;
    } else {
        logger.error("Unknown connection type: " + newOutputConnection + " .\n");
        throw new RuntimeException("Unknown connection type: " + newOutputConnection + " .\n");
    }
    if (!connectionToReplace.getConnectedConnections().isEmpty()) {
        // Hard to deal with concurency problems, iterate copy, edit original
        final Map<String, DependencyConnection> connectedConnections = connectionToReplace.getConnectedConnections();
        final Map<String, DependencyConnection> connectedConnectionsCopy = Maps.newHashMap(connectionToReplace.getConnectedConnections());
        for (DependencyConnection connectedConnectionCopy : connectedConnectionsCopy.values()) {
            DependencyConnection toConnection = connectedConnections.get(connectedConnectionCopy.getName());
            if (!toConnection.getParentNode().equals(fromNode.getUri())) {
                // TODO potteintionally harmful ID guesswork
                reconnectInputToOutput(findNode(toConnection.getParentNode()), DependencyConnection.getIdFromConnectionName(toConnection.getName()), newOutputConnection, connectionType, true);
            // Node toNode = findNode(toConnection.getParentNode());
            // if (!areConnected(fromNode, toNode)) {
            // connect(fromNode, toNode);
            // }
            }
        }
    }
}
Also used : FboConnection(org.terasology.engine.rendering.dag.dependencyConnections.FboConnection) DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection) BufferPairConnection(org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection)

Example 13 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class AbstractNode method addInputBufferPairConnection.

public boolean addInputBufferPairConnection(int id, BufferPairConnection from) {
    DependencyConnection bufferPairConenction = new BufferPairConnection(BufferPairConnection.getConnectionName(id, this.nodeUri), DependencyConnection.Type.INPUT, from.getData(), this.getUri());
    bufferPairConenction.setConnectedConnection(from);
    return addInputConnection(bufferPairConenction);
}
Also used : DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection) BufferPairConnection(org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection)

Example 14 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class AbstractNode method addOutputFboConnection.

/**
 * TODO do something if could not insert
 * @param id
 * @param fboData
 * @return true if inserted, false otherwise
 */
protected boolean addOutputFboConnection(int id, FBO fboData) {
    boolean success = false;
    String connectionUri = FboConnection.getConnectionName(id, this.nodeUri);
    if (outputConnections.containsKey(connectionUri)) {
        FboConnection fboConnection = (FboConnection) outputConnections.get(connectionUri);
        if (fboConnection.getData() != null) {
            logger.warn("Adding output fbo data to slot id " + id + " of " + this.nodeUri + "node overwrites data of existing connection: " + fboConnection.toString());
        }
        fboConnection.setData(fboData);
        // set data for all connected connections
        if (!fboConnection.getConnectedConnections().isEmpty()) {
            logger.info("Propagating fbo data to all connected connections of " + fboConnection + ": ");
            fboConnection.getConnectedConnections().forEach((k, v) -> {
                logger.info("setting data for: " + v.toString() + " ,");
                v.setData(fboData);
            });
            logger.info("data propagated.\n");
        }
        success = true;
    } else {
        DependencyConnection fboConnection = new FboConnection(FboConnection.getConnectionName(id, this.nodeUri), DependencyConnection.Type.OUTPUT, fboData, this.getUri());
        success = addOutputConnection(fboConnection);
    }
    return success;
}
Also used : FboConnection(org.terasology.engine.rendering.dag.dependencyConnections.FboConnection) DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)

Example 15 with DependencyConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection in project Terasology by MovingBlocks.

the class AbstractNode method addInputFboConnection.

/**
 * @param id
 * @param from
 * @return true if inserted, false otherwise
 */
protected boolean addInputFboConnection(int id, FboConnection from) {
    DependencyConnection fboConnection = new FboConnection(FboConnection.getConnectionName(id, this.nodeUri), DependencyConnection.Type.INPUT, from.getData(), this.getUri());
    // must remember where I'm connected from
    fboConnection.setConnectedConnection(from);
    return addInputConnection(fboConnection);
}
Also used : FboConnection(org.terasology.engine.rendering.dag.dependencyConnections.FboConnection) DependencyConnection(org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)

Aggregations

DependencyConnection (org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)18 BufferPairConnection (org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection)4 FboConnection (org.terasology.engine.rendering.dag.dependencyConnections.FboConnection)3 Nullable (javax.annotation.Nullable)2 SimpleUri (org.terasology.engine.core.SimpleUri)1 RunOrderConnection (org.terasology.engine.rendering.dag.dependencyConnections.RunOrderConnection)1