Search in sources :

Example 11 with CpuCore

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

the class ProcessorTileEntity method run.

private void run() {
    int rf = getEnergyStored();
    for (CpuCore core : cpuCores) {
        if (core.hasProgram()) {
            int rft = GeneralConfiguration.coreRFPerTick[core.getTier()];
            if (rft < rf) {
                core.run(this);
                consumeEnergy(rft);
                rf -= rft;
            }
        }
    }
}
Also used : CpuCore(mcjty.rftoolscontrol.logic.running.CpuCore)

Example 12 with CpuCore

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

the class Commands method handleDebugCommand.

private static void handleDebugCommand(ProcessorTileEntity processor, String[] splitted) {
    List<CpuCore> cores = processor.getCpuCores();
    String sub = splitted[1].toLowerCase();
    if ("debug".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int core = Integer.parseInt(splitted[2]);
                cores.get(core).setDebug(true);
                processor.log(TextFormatting.YELLOW + "Debug mode for core: " + core);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            for (CpuCore core : cores) {
                core.setDebug(true);
            }
            processor.log(TextFormatting.YELLOW + "Debug mode for all cores");
        }
    } else if ("resume".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int core = Integer.parseInt(splitted[2]);
                cores.get(core).setDebug(false);
                processor.log(TextFormatting.YELLOW + "Resume core: " + core);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            for (CpuCore core : cores) {
                core.setDebug(false);
            }
            processor.log(TextFormatting.YELLOW + "Resume all cores");
        }
    } else if ("info".equals(sub)) {
        for (int i = 0; i < cores.size(); i++) {
            CpuCore core = cores.get(i);
            if (core.isDebug()) {
                RunningProgram program = core.getProgram();
                if (program == null) {
                    processor.log("Core " + i + ": " + "not running");
                } else {
                    showCurrent(processor, i, program);
                }
            }
        }
    } else if ("last".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int i = Integer.parseInt(splitted[2]);
                CpuCore core = cores.get(i);
                if (core.hasProgram()) {
                    Parameter value = core.getProgram().getLastValue();
                    if (value == null || value.getParameterValue() == null) {
                        processor.log(TextFormatting.YELLOW + "Last value not set");
                    } else {
                        ParameterType type = value.getParameterType();
                        processor.log(TextFormatting.YELLOW + "Last " + type.getName() + ": " + TypeConverters.convertToString(value));
                    }
                } else {
                    processor.log(TextFormatting.YELLOW + "No program!");
                }
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            int i = 0;
            for (CpuCore core : cores) {
                if (core.hasProgram()) {
                    Parameter value = core.getProgram().getLastValue();
                    if (value == null || value.getParameterValue() == null) {
                        processor.log(TextFormatting.YELLOW + "" + i + ": Last value not set");
                    } else {
                        ParameterType type = value.getParameterType();
                        processor.log(TextFormatting.YELLOW + "" + i + ": Last " + type.getName() + ": " + TypeConverters.convertToString(value));
                    }
                }
                i++;
            }
        }
    } else if ("step".equals(sub) || "s".equals(sub)) {
        int cnt = 0;
        for (CpuCore core : cores) {
            if (core.isDebug()) {
                cnt++;
            }
        }
        int c = 0;
        if (cnt == 0) {
            processor.log(TextFormatting.RED + "Not debugging");
            return;
        } else if (cnt > 1) {
            if (splitted.length <= 2) {
                processor.log(TextFormatting.RED + "Missing core number");
                return;
            }
            try {
                c = Integer.parseInt(splitted[2]);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        }
        CpuCore core = cores.get(c);
        RunningProgram program = core.getProgram();
        if (program == null) {
            processor.log(TextFormatting.RED + "Core " + c + ": " + "not running");
            return;
        }
        core.step(processor);
        showCurrent(processor, c, program);
    } else {
        processor.log("Unknown 'db' command!");
    }
}
Also used : ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) CpuCore(mcjty.rftoolscontrol.logic.running.CpuCore) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) RunningProgram(mcjty.rftoolscontrol.logic.running.RunningProgram)

Example 13 with CpuCore

use of mcjty.rftoolscontrol.logic.running.CpuCore 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

CpuCore (mcjty.rftoolscontrol.logic.running.CpuCore)13 RunningProgram (mcjty.rftoolscontrol.logic.running.RunningProgram)5 NBTTagList (net.minecraft.nbt.NBTTagList)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)1 ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)1 CraftingStationTileEntity (mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity)1 MultiTankTileEntity (mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity)1 NodeTileEntity (mcjty.rftoolscontrol.blocks.node.NodeTileEntity)1 WorkbenchTileEntity (mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)1 CompiledEvent (mcjty.rftoolscontrol.logic.compiled.CompiledEvent)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 Pair (org.apache.commons.lang3.tuple.Pair)1