use of mcjty.rftoolscontrol.logic.running.RunningProgram in project RFToolsControl by McJty.
the class ProcessorTileEntity method processEventQueue.
private void processEventQueue() {
QueuedEvent queuedEvent = eventQueue.peek();
if (queuedEvent != null) {
CompiledEvent compiledEvent = queuedEvent.getCompiledEvent();
if (compiledEvent.isSingle() && runningEvents.contains(Pair.of(queuedEvent.getCardIndex(), compiledEvent.getIndex()))) {
return;
}
CpuCore core = findAvailableCore(queuedEvent.getCardIndex());
if (core != null) {
eventQueue.remove();
RunningProgram program = new RunningProgram(queuedEvent.getCardIndex());
program.startFromEvent(compiledEvent);
program.setCraftTicket(queuedEvent.getTicket());
program.setLastValue(queuedEvent.getParameter());
core.startProgram(program);
if (compiledEvent.isSingle()) {
runningEvents.add(Pair.of(queuedEvent.getCardIndex(), compiledEvent.getIndex()));
}
}
}
}
use of mcjty.rftoolscontrol.logic.running.RunningProgram in project RFToolsControl by McJty.
the class ProcessorTileEntity method handleCall.
public void handleCall(IProgram program, String signal) {
RunningProgram p = (RunningProgram) program;
CardInfo info = this.cardInfo[p.getCardIndex()];
CompiledCard compiledCard = info.getCompiledCard();
if (compiledCard != null) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_SIGNAL)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
String sig = evaluateStringParameter(compiledOpcode, null, 0);
if (signal.equals(sig)) {
p.pushCall(p.getCurrentOpcode(this).getPrimaryIndex());
p.setCurrent(event.getIndex());
return;
}
}
}
throw new ProgException(EXCEPT_MISSINGSIGNAL);
}
use of mcjty.rftoolscontrol.logic.running.RunningProgram in project RFToolsControl by McJty.
the class ProcessorTileEntity method getStatus.
private String getStatus(int c) {
CpuCore core = cpuCores.get(c);
String db = core.isDebug() ? "[DB] " : "";
if (core.hasProgram()) {
RunningProgram program = core.getProgram();
if (program.getDelay() > 0) {
return db + "<delayed: " + program.getDelay() + ">";
} else if (program.getLock() != null) {
return db + "<locked: " + program.getLock() + ">";
} else {
return db + "<busy>";
}
} else {
return db + "<idle>";
}
}
use of mcjty.rftoolscontrol.logic.running.RunningProgram in project RFToolsControl by McJty.
the class ProcessorTileEntity method runOrQueueEvent.
private void runOrQueueEvent(int cardIndex, CompiledEvent event, @Nullable String ticket, @Nullable Parameter parameter) {
if (event.isSingle() && runningEvents.contains(Pair.of(cardIndex, event.getIndex()))) {
// Already running and single
queueEvent(cardIndex, event, ticket, parameter);
return;
}
CpuCore core = findAvailableCore(cardIndex);
if (core == null) {
// No available core
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()));
}
}
}
use of mcjty.rftoolscontrol.logic.running.RunningProgram 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!");
}
}
Aggregations