public interface Architecture
Modifier and Type | Interface and Description |
---|---|
static interface |
Architecture.Name
Architectures can be annotated with this to provide a nice display name.
|
static interface |
Architecture.NoMemoryRequirements
Architectures flagged with this annotation can potentially run without
any additional memory installed in the computer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Called when a machine stopped.
|
boolean |
initialize()
Called when a machine starts up.
|
boolean |
isInitialized()
Used to check if the machine is fully initialized.
|
void |
load(net.minecraft.nbt.NBTTagCompound nbt)
Restores the state of this architecture as previously saved in
save(NBTTagCompound) . |
void |
onConnect()
Called when the owning machine was connected to the component network.
|
void |
onSignal()
Called when a new signal is queued in the hosting
Machine . |
boolean |
recomputeMemory(java.lang.Iterable<net.minecraft.item.ItemStack> components)
This is called when the amount of memory in the machine may have changed.
|
void |
runSynchronized()
Performs a synchronized call initialized in a previous call to
runThreaded(boolean) . |
ExecutionResult |
runThreaded(boolean isSynchronizedReturn)
Continues execution of the machine.
|
void |
save(net.minecraft.nbt.NBTTagCompound nbt)
Saves the architecture for later restoration, e.g.
|
boolean isInitialized()
boolean recomputeMemory(java.lang.Iterable<net.minecraft.item.ItemStack> components)
components
- the components to use for computing the total memory.boolean initialize()
onConnect()
for additional initialization that
depends on a node network (such as connecting a ROM file system).void close()
void runSynchronized()
runThreaded(boolean)
.
This method is invoked from the main server thread, meaning it is safe
to interact with the world without having to perform manual
synchronization.
This method is expected to leave the architecture in a state so it is
prepared to next be called with runThreaded(true). For example,
the Lua architecture will leave the results of the synchronized call on
the stack so they can be further processed in the next call to
runThreaded.ExecutionResult runThreaded(boolean isSynchronizedReturn)
isInitialized()
.
The resumed state is either a return from a synchronized call, when a
synchronized call has been completed (via runSynchronized), or
a normal yield in all other cases (sleep, interrupt, boot, ...).
This is expected to return within a very short time, usually. For example,
in Lua this returns as soon as the state yields, and returns at the latest
when the Settings.timeout is reached (in which case it forces the state
to crash).
This is expected to consume a single signal if one is present and return.
If returning from a synchronized call this should consume no signal.isSynchronizedReturn
- whether the architecture is resumed from an
earlier synchronized call. In the case of
Lua this means the results of the call are
now on the stack, for example.void onSignal()
Machine
.
Depending on how you structure your architecture, you may not need this
callback. For example, the Lua architectures simply pull the next signal
from the queue whenever runThreaded(boolean)
is called again. However,
if you'd like to react to signals in a more timely manner, you can
react to this while you are in a runThreaded(boolean)
call,
which is what it is intended to be used for.
Keep in mind that this may be called from any random thread, since
Context.signal(java.lang.String, java.lang.Object...)
does not require being called from a specific
thread.void onConnect()
initialize()
was called from the machine's load logic
(where it was not yet connected to the network).void load(net.minecraft.nbt.NBTTagCompound nbt)
save(NBTTagCompound)
. The architecture should be in the same
state it was when it was saved after this, so it can be resumed from
whatever state the owning machine was in when it was saved.nbt
- the tag compound to save to.void save(net.minecraft.nbt.NBTTagCompound nbt)
nbt
- the tag compound to save to.