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;
}
}
}
}
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!");
}
}
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()));
}
}
}
Aggregations