Search in sources :

Example 6 with RunningProgram

use of mcjty.rftoolscontrol.logic.running.RunningProgram in project RFToolsControl by McJty.

the class ProcessorTileEntity method runOrDropEvent.

private void runOrDropEvent(int cardIndex, CompiledEvent event, @Nullable String ticket, @Nullable Parameter parameter) {
    if (event.isSingle() && runningEvents.contains(Pair.of(cardIndex, event.getIndex()))) {
        // Already running and single
        return;
    }
    CpuCore core = findAvailableCore(cardIndex);
    if (core == null) {
        // in the queue. If so we drop it. Otherwise we add it
        for (QueuedEvent q : eventQueue) {
            if (q.getCardIndex() == cardIndex) {
                if (q.getCompiledEvent().equals(event)) {
                    // This event is already in the queue. Just drop it
                    return;
                }
            }
        }
        // We could not find this event in the queue. Schedule it
        queueEvent(cardIndex, event, ticket, parameter);
    } else {
        RunningProgram program = new RunningProgram(cardIndex);
        program.startFromEvent(event);
        program.setCraftTicket(ticket);
        program.setLastValue(parameter);
        core.startProgram(program);
        if (event.isSingle()) {
            runningEvents.add(Pair.of(cardIndex, event.getIndex()));
        }
    }
}
Also used : CpuCore(mcjty.rftoolscontrol.logic.running.CpuCore) RunningProgram(mcjty.rftoolscontrol.logic.running.RunningProgram)

Aggregations

RunningProgram (mcjty.rftoolscontrol.logic.running.RunningProgram)6 CpuCore (mcjty.rftoolscontrol.logic.running.CpuCore)5 CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 ICompiledOpcode (mcjty.rftoolscontrol.api.code.ICompiledOpcode)1 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)1 ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)1 CompiledCard (mcjty.rftoolscontrol.logic.compiled.CompiledCard)1 CompiledOpcode (mcjty.rftoolscontrol.logic.compiled.CompiledOpcode)1 ProgException (mcjty.rftoolscontrol.logic.running.ProgException)1