use of mcjty.rftoolscontrol.logic.compiled.CompiledEvent 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.compiled.CompiledEvent in project RFToolsControl by McJty.
the class ProcessorTileEntity method exception.
public void exception(ExceptionType exception, @Nullable RunningProgram program) {
// For too many events exception we don't want to queue another event for obvious reasons
if (exception != EXCEPT_TOOMANYEVENTS) {
for (int i = 0; i < cardInfo.length; i++) {
CardInfo info = cardInfo[i];
CompiledCard compiledCard = info.getCompiledCard();
if (compiledCard != null) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_EXCEPTION)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
String code = evaluateStringParameter(compiledOpcode, null, 0);
if (exception.getCode().equals(code)) {
runOrQueueEvent(i, event, program == null ? null : program.getCraftTicket(), null);
return;
}
}
}
}
}
String message;
if (program != null) {
CompiledCard card = getCompiledCard(program.getCardIndex());
if (card == null) {
message = TextFormatting.RED + "INTERNAL: " + exception.getDescription();
} else {
CompiledOpcode opcode = program.getCurrentOpcode(this);
int gridX = opcode.getGridX();
int gridY = opcode.getGridY();
message = TextFormatting.RED + "[" + gridX + "," + gridY + "] " + exception.getDescription();
}
} else {
message = TextFormatting.RED + exception.getDescription();
}
lastException = message;
lastExceptionTime = System.currentTimeMillis();
log(message);
}
use of mcjty.rftoolscontrol.logic.compiled.CompiledEvent in project RFToolsControl by McJty.
the class ProcessorTileEntity method signal.
@Override
public int signal(String signal) {
int cnt = 0;
for (int i = 0; i < cardInfo.length; i++) {
CardInfo info = cardInfo[i];
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)) {
runOrQueueEvent(i, event, null, null);
cnt++;
}
}
}
}
return cnt;
}
use of mcjty.rftoolscontrol.logic.compiled.CompiledEvent 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.compiled.CompiledEvent in project RFToolsControl by McJty.
the class ProcessorTileEntity method receiveMessage.
public void receiveMessage(String name, @Nullable Parameter value) {
for (int i = 0; i < cardInfo.length; i++) {
CardInfo info = cardInfo[i];
CompiledCard compiledCard = info.getCompiledCard();
if (compiledCard != null) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_MESSAGE)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
String messageName = evaluateStringParameter(compiledOpcode, null, 0);
if (name.equals(messageName)) {
runOrQueueEvent(i, event, null, value);
}
}
}
}
}
Aggregations