Search in sources :

Example 1 with Info

use of logisticspipes.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.

the class ServerRouter method recheckAdjacent.

/**
 * Rechecks the piped connection to all adjacent routers as well as discover
 * new ones.
 */
private boolean recheckAdjacent() {
    connectionNeedsChecking = 0;
    if (LogisticsPipes.isDEBUG()) {
        causedBy.clear();
    }
    if (getPipe() != null) {
        /*
			if (getPipe().getDebug() != null && getPipe().getDebug().debugThisPipe) {
				Info info = StackTraceUtil.addTraceInformation("(" + getPipe().getX() + ", " + getPipe().getY() + ", " + getPipe().getZ() + ")");
				StackTraceUtil.printTrace();
				info.end();
			}
			*/
        getPipe().spawnParticle(Particles.LightRedParticle, 5);
    }
    LPTickHandler.adjChecksDone++;
    boolean adjacentChanged = false;
    CoreRoutedPipe thisPipe = getPipe();
    if (thisPipe == null) {
        return false;
    }
    HashMap<CoreRoutedPipe, ExitRoute> adjacent;
    List<Pair<ILogisticsPowerProvider, List<IFilter>>> power;
    List<Pair<ISubSystemPowerProvider, List<IFilter>>> subSystemPower;
    PathFinder finder = new PathFinder(thisPipe.container, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, localChangeListener);
    power = finder.powerNodes;
    subSystemPower = finder.subPowerProvider;
    adjacent = finder.result;
    Map<EnumFacing, List<CoreRoutedPipe>> pipeDirections = new HashMap<>();
    for (Entry<CoreRoutedPipe, ExitRoute> entry : adjacent.entrySet()) {
        List<CoreRoutedPipe> list = pipeDirections.computeIfAbsent(entry.getValue().exitOrientation, k -> new ArrayList<>());
        list.add(entry.getKey());
    }
    pipeDirections.entrySet().stream().filter(entry -> entry.getValue().size() > Configs.MAX_UNROUTED_CONNECTIONS).forEach(entry -> entry.getValue().forEach(adjacent::remove));
    listenedPipes.stream().filter(list -> !finder.listenedPipes.contains(list)).forEach(list -> list.remove(localChangeListener));
    listenedPipes = finder.listenedPipes;
    for (CoreRoutedPipe pipe : adjacent.keySet()) {
        if (pipe.stillNeedReplace()) {
            return false;
        }
    }
    boolean[] oldSideDisconnected = sideDisconnected;
    sideDisconnected = new boolean[6];
    checkSecurity(adjacent);
    boolean changed = false;
    for (int i = 0; i < 6; i++) {
        changed |= sideDisconnected[i] != oldSideDisconnected[i];
    }
    if (changed) {
        CoreRoutedPipe pipe = getPipe();
        if (pipe != null) {
            pipe.getWorld().markAndNotifyBlock(pipe.getPos(), pipe.getWorld().getChunkFromBlockCoords(pipe.getPos()), pipe.getWorld().getBlockState(pipe.getPos()), pipe.getWorld().getBlockState(pipe.getPos()), 3);
            pipe.refreshConnectionAndRender(false);
        }
        adjacentChanged = true;
    }
    if (_adjacent.size() != adjacent.size()) {
        adjacentChanged = true;
    }
    for (CoreRoutedPipe pipe : _adjacent.keySet()) {
        if (!adjacent.containsKey(pipe)) {
            adjacentChanged = true;
            break;
        }
    }
    if (_powerAdjacent != null) {
        if (power == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : _powerAdjacent) {
                if (!power.contains(provider)) {
                    adjacentChanged = true;
                    break;
                }
            }
        }
    }
    if (power != null) {
        if (_powerAdjacent == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : power) {
                if (!_powerAdjacent.contains(provider)) {
                    adjacentChanged = true;
                    break;
                }
            }
        }
    }
    if (_subSystemPowerAdjacent != null) {
        if (subSystemPower == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent) {
                if (!subSystemPower.contains(provider)) {
                    adjacentChanged = true;
                    break;
                }
            }
        }
    }
    if (subSystemPower != null) {
        if (_subSystemPowerAdjacent == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower) {
                if (!_subSystemPowerAdjacent.contains(provider)) {
                    adjacentChanged = true;
                    break;
                }
            }
        }
    }
    for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
        ExitRoute oldExit = _adjacent.get(pipe.getKey());
        if (oldExit == null) {
            adjacentChanged = true;
            break;
        }
        ExitRoute newExit = pipe.getValue();
        if (!newExit.equals(oldExit)) {
            adjacentChanged = true;
            break;
        }
    }
    if (!oldTouchedPipes.equals(finder.touchedPipes)) {
        CacheHolder.clearCache(oldTouchedPipes);
        CacheHolder.clearCache(finder.touchedPipes);
        oldTouchedPipes = finder.touchedPipes;
        BitSet visited = new BitSet(ServerRouter.getBiggestSimpleID());
        visited.set(getSimpleID());
        act(visited, new floodClearCache());
    }
    if (adjacentChanged) {
        HashMap<ServerRouter, ExitRoute> adjacentRouter = new HashMap<>();
        EnumSet<EnumFacing> routedexits = EnumSet.noneOf(EnumFacing.class);
        EnumMap<EnumFacing, Integer> subpowerexits = new EnumMap<>(EnumFacing.class);
        for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
            adjacentRouter.put((ServerRouter) pipe.getKey().getRouter(), pipe.getValue());
            if ((pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRouteTo) || pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && !routedexits.contains(pipe.getValue().exitOrientation))) {
                routedexits.add(pipe.getValue().exitOrientation);
            }
            if (!subpowerexits.containsKey(pipe.getValue().exitOrientation) && pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                subpowerexits.put(pipe.getValue().exitOrientation, PathFinder.messureDistanceToNextRoutedPipe(getLPPosition(), pipe.getValue().exitOrientation, pipe.getKey().getWorld()));
            }
        }
        _adjacent = Collections.unmodifiableMap(adjacent);
        _adjacentRouter_Old = _adjacentRouter;
        _adjacentRouter = Collections.unmodifiableMap(adjacentRouter);
        if (power != null) {
            _powerAdjacent = Collections.unmodifiableList(power);
        } else {
            _powerAdjacent = null;
        }
        if (subSystemPower != null) {
            _subSystemPowerAdjacent = Collections.unmodifiableList(subSystemPower);
        } else {
            _subSystemPowerAdjacent = null;
        }
        _routedExits = routedexits;
        _subPowerExits = subpowerexits;
        SendNewLSA();
    }
    return adjacentChanged;
}
Also used : PriorityQueue(java.util.PriorityQueue) LogisticsPipes(logisticspipes.LogisticsPipes) Quartet(logisticspipes.utils.tuples.Quartet) Particles(logisticspipes.pipefxhandlers.Particles) MainProxy(logisticspipes.proxy.MainProxy) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) Configs(logisticspipes.config.Configs) StackTraceUtil(logisticspipes.utils.StackTraceUtil) LogisticsModule(logisticspipes.modules.LogisticsModule) Map(java.util.Map) ObjectSets(it.unimi.dsi.fastutil.objects.ObjectSets) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) EnumSet(java.util.EnumSet) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) EnumMap(java.util.EnumMap) FluidResource(logisticspipes.request.resources.FluidResource) CacheHolder(logisticspipes.utils.CacheHolder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LPTickHandler(logisticspipes.ticks.LPTickHandler) UUID(java.util.UUID) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Info(logisticspipes.utils.StackTraceUtil.Info) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) IRoutingDebugAdapter(logisticspipes.interfaces.IRoutingDebugAdapter) BiConsumer(java.util.function.BiConsumer) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) PathFinder(logisticspipes.routing.pathfinder.PathFinder) OneList(logisticspipes.utils.OneList) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) DimensionManager(net.minecraftforge.common.DimensionManager) RoutingTableUpdateThread(logisticspipes.ticks.RoutingTableUpdateThread) ReentrantLock(java.util.concurrent.locks.ReentrantLock) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IResource(logisticspipes.request.resources.IResource) Lock(java.util.concurrent.locks.Lock) PipeItemsFirewall(logisticspipes.pipes.PipeItemsFirewall) TileEntity(net.minecraft.tileentity.TileEntity) BitSet(java.util.BitSet) Collections(java.util.Collections) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) List(java.util.List) ArrayList(java.util.ArrayList) OneList(logisticspipes.utils.OneList) LinkedList(java.util.LinkedList) EnumMap(java.util.EnumMap) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) Pair(logisticspipes.utils.tuples.Pair) BitSet(java.util.BitSet) PathFinder(logisticspipes.routing.pathfinder.PathFinder) IFilter(logisticspipes.interfaces.routing.IFilter)

Example 2 with Info

use of logisticspipes.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.

the class LogisticsTileGenericPipe method updateEntity.

@Override
public void updateEntity() {
    Info superDebug = StackTraceUtil.addSuperTraceInformation("Time: " + getWorld().getWorldTime());
    Info debug = StackTraceUtil.addTraceInformation("(" + getX() + ", " + getY() + ", " + getZ() + ")", superDebug);
    if (sendInitPacket && MainProxy.isServer(getWorldObj())) {
        sendInitPacket = false;
        getRenderController().sendInit();
    }
    if (!worldObj.isRemote) {
        if (deletePipe) {
            worldObj.setBlockToAir(xCoord, yCoord, zCoord);
        }
        if (pipe == null) {
            debug.end();
            return;
        }
        if (!initialized) {
            initialize(pipe);
        }
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        debug.end();
        return;
    }
    pipe.updateEntity();
    if (worldObj.isRemote) {
        debug.end();
        return;
    }
    if (blockNeighborChange) {
        computeConnections();
        pipe.onNeighborBlockChange(0);
        blockNeighborChange = false;
        refreshRenderState = true;
    }
    //Sideblocks need to be checked before this
    tilePart.updateEntity_LP();
    if (refreshRenderState) {
        // Pipe connections;
        for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
            renderState.pipeConnectionMatrix.setConnected(o, pipeConnectionsBuffer[o.ordinal()]);
            renderState.pipeConnectionMatrix.setBCConnected(o, pipeBCConnectionsBuffer[o.ordinal()]);
            renderState.pipeConnectionMatrix.setTDConnected(o, pipeTDConnectionsBuffer[o.ordinal()]);
        }
        // Pipe Textures
        for (int i = 0; i < 7; i++) {
            ForgeDirection o = ForgeDirection.getOrientation(i);
            renderState.textureMatrix.setIconIndex(o, pipe.getIconIndex(o));
        }
        //New Pipe Texture States
        renderState.textureMatrix.refreshStates(pipe);
        if (renderState.isDirty()) {
            renderState.clean();
            sendUpdateToClient();
        }
        refreshRenderState = false;
    }
    if (bcPlugableState.isDirty(true)) {
        sendUpdateToClient();
    }
    if (sendClientUpdate) {
        sendClientUpdate = false;
        MainProxy.sendPacketToAllWatchingChunk(xCoord, zCoord, MainProxy.getDimensionForWorld(worldObj), getLPDescriptionPacket());
    }
    getRenderController().onUpdate();
    if (!addedToNetwork) {
        addedToNetwork = true;
        SimpleServiceLocator.openComputersProxy.addToNetwork(this);
    }
    debug.end();
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Info(logisticspipes.utils.StackTraceUtil.Info) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo)

Example 3 with Info

use of logisticspipes.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.

the class ServerRouter method update.

@Override
public void update(boolean doFullRefresh, CoreRoutedPipe pipe) {
    if (connectionNeedsChecking == 2) {
        ensureChangeListenerAttachedToPipe(pipe);
        final Info info = StackTraceUtil.addTraceInformation(causedBy::toString);
        boolean blockNeedsUpdate = checkAdjacentUpdate();
        if (blockNeedsUpdate) {
            updateLsa();
        }
        info.end();
        ensureChangeListenerAttachedToPipe(pipe);
    }
    if (connectionNeedsChecking == 1) {
        connectionNeedsChecking = 2;
    }
    handleQueuedTasks(pipe);
    updateInterests();
    if (doFullRefresh) {
        ensureChangeListenerAttachedToPipe(pipe);
        boolean blockNeedsUpdate = checkAdjacentUpdate();
        if (blockNeedsUpdate) {
            // updateAdjacentAndLsa();
            updateLsa();
        }
        ensureChangeListenerAttachedToPipe(pipe);
        lazyUpdateRoutingTable();
    } else if (Configs.MULTI_THREAD_NUMBER > 0) {
        lazyUpdateRoutingTable();
    }
}
Also used : Info(logisticspipes.utils.StackTraceUtil.Info)

Example 4 with Info

use of logisticspipes.utils.StackTraceUtil.Info in project LogisticsPipes by RS485.

the class LogisticsTileGenericPipe method update.

@Override
public void update() {
    imcmpltgpCompanion.update();
    final Info superDebug = StackTraceUtil.addSuperTraceInformation(() -> "Time: " + getWorld().getWorldTime());
    final Info debug = StackTraceUtil.addTraceInformation(() -> "(" + getX() + ", " + getY() + ", " + getZ() + ")", superDebug);
    if (sendInitPacket && MainProxy.isServer(getWorld())) {
        sendInitPacket = false;
        getRenderController().sendInit();
    }
    if (!world.isRemote) {
        if (deletePipe) {
            world.setBlockToAir(getPos());
        }
        if (pipe == null) {
            debug.end();
            return;
        }
        if (!initialized) {
            initialize(pipe);
        }
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        debug.end();
        return;
    }
    pipe.updateEntity();
    if (world.isRemote) {
        debug.end();
        return;
    }
    if (blockNeighborChange) {
        computeConnections();
        pipe.onNeighborBlockChange();
        blockNeighborChange = false;
        refreshRenderState = true;
        if (MainProxy.isServer(world)) {
            MainProxy.sendPacketToAllWatchingChunk(this, PacketHandler.getPacket(PipeSolidSideCheck.class).setTilePos(this));
        }
    }
    if (refreshRenderState) {
        refreshRenderState();
        if (renderState.isDirty()) {
            renderState.clean();
            sendUpdateToClient();
        }
        refreshRenderState = false;
    }
    if (sendClientUpdate) {
        sendClientUpdate = false;
        MainProxy.sendPacketToAllWatchingChunk(this, getLPDescriptionPacket());
    }
    getRenderController().onUpdate();
    if (!addedToNetwork) {
        addedToNetwork = true;
        SimpleServiceLocator.openComputersProxy.addToNetwork(this);
    }
    debug.end();
}
Also used : Info(logisticspipes.utils.StackTraceUtil.Info)

Aggregations

Info (logisticspipes.utils.StackTraceUtil.Info)3 ObjectSets (it.unimi.dsi.fastutil.objects.ObjectSets)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Collections (java.util.Collections)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 NavigableSet (java.util.NavigableSet)1 PriorityQueue (java.util.PriorityQueue)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1