Search in sources :

Example 1 with BufferPairConnection

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

the class AbstractNode method addOutputBufferPairConnection.

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

Example 2 with BufferPairConnection

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

the class AbstractNode method addOutputBufferPairConnection.

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

Example 3 with BufferPairConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection 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 4 with BufferPairConnection

use of org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection 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)

Aggregations

BufferPairConnection (org.terasology.engine.rendering.dag.dependencyConnections.BufferPairConnection)4 DependencyConnection (org.terasology.engine.rendering.dag.dependencyConnections.DependencyConnection)4 FboConnection (org.terasology.engine.rendering.dag.dependencyConnections.FboConnection)1