Move dispose method to parent interface.
This commit is contained in:
@@ -22,6 +22,14 @@ import net.minecraftforge.common.util.INBTSerializable;
|
||||
* devices can be detected.
|
||||
*/
|
||||
public interface Device extends INBTSerializable<CompoundTag> {
|
||||
/**
|
||||
* Called to dispose this device.
|
||||
* <p>
|
||||
* Called when the connected virtual machine stops or the device is removed from a {@link DeviceBus}.
|
||||
*/
|
||||
default void dispose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to serialize this device into its container's persistent storage.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package li.cil.oc2.api.bus.device.rpc;
|
||||
|
||||
import li.cil.oc2.api.bus.DeviceBus;
|
||||
import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.object.ObjectDevice;
|
||||
|
||||
@@ -74,35 +75,23 @@ public interface RPCDevice extends Device {
|
||||
/**
|
||||
* Called to start this device.
|
||||
* <p>
|
||||
* This is called when the connected virtual machine starts, or when the device is added to an already running
|
||||
* virtual machine.
|
||||
* This is called when the connected virtual machine starts, or when the device
|
||||
* is added to a {@link DeviceBus} with a currently running virtual machine.
|
||||
*/
|
||||
default void mount() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to stop this device.
|
||||
* Called to pause this device.
|
||||
* <p>
|
||||
* Called when the connected virtual machine stops, the device is removed from a currently running
|
||||
* virtual machine, or the connected virtual machine is suspended (chunk unload/server stopped/...).
|
||||
* Called when the connected virtual machine is suspended (chunk unload/server stopped/...).
|
||||
* <p>
|
||||
* Also called when the connected virtual machine stops or the device is removed from a
|
||||
* {@link DeviceBus} with a currently running virtual machine. In this case, {@link #dispose()}
|
||||
* will be called after this method returns.
|
||||
* <p>
|
||||
* If {@link #mount()} was called, this is guaranteed to be called.
|
||||
*/
|
||||
default void unmount() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to dispose this device.
|
||||
* <p>
|
||||
* Called when the connected virtual machine stops or the device is removed from a currently running
|
||||
* virtual machine.
|
||||
* <p>
|
||||
* Will only be called on unmounted devices (i.e. will always be called after {@link #unmount()} if
|
||||
* {@link #mount()} was called before). May be called without intermediary {@link #mount()} calls, e.g.
|
||||
* virtual machine stops, then device is disconnected from the virtual machine.
|
||||
* <p>
|
||||
* Intended for releasing persistent unmanaged resources.
|
||||
*/
|
||||
default void dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package li.cil.oc2.api.bus.device.vm;
|
||||
|
||||
import li.cil.oc2.api.bus.DeviceBus;
|
||||
import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCDevice;
|
||||
import li.cil.oc2.api.bus.device.vm.context.InterruptAllocator;
|
||||
@@ -51,7 +52,10 @@ import li.cil.sedna.api.device.MemoryMappedDevice;
|
||||
*/
|
||||
public interface VMDevice extends Device {
|
||||
/**
|
||||
* Called to initialize this device.
|
||||
* Called to start this device.
|
||||
* <p>
|
||||
* This is called when the connected virtual machine starts, or when the device
|
||||
* is added to a {@link DeviceBus} with a currently running virtual machine.
|
||||
* <p>
|
||||
* Register {@link MemoryMappedDevice}s and claim interrupts via the
|
||||
* {@link InterruptAllocator} made available through the {@code context}.
|
||||
@@ -59,7 +63,7 @@ public interface VMDevice extends Device {
|
||||
* If loading cannot complete, e.g. because resources cannot be allocated,
|
||||
* this should return {@code false}. The virtual machine will periodically
|
||||
* try again to load failed devices. The virtual machine will only start
|
||||
* running after all devices have successfully loaded.
|
||||
* or resume after all devices have successfully loaded.
|
||||
*
|
||||
* @param context the virtual machine context.
|
||||
* @return {@code true} if the device was loaded successfully; {@code false} otherwise.
|
||||
@@ -67,23 +71,13 @@ public interface VMDevice extends Device {
|
||||
VMDeviceLoadResult mount(VMContext context);
|
||||
|
||||
/**
|
||||
* Called when the device is removed from the context it was loaded with.
|
||||
* Called to pause this device.
|
||||
* <p>
|
||||
* This can happen because the VM was stopped or the device was removed from
|
||||
* the device bus that connected it to the VM, for example.
|
||||
* Called when the connected virtual machine is suspended (chunk unload/server stopped/...).
|
||||
* <p>
|
||||
* Intended for releasing resources acquired in {@link #mount(VMContext)}.
|
||||
* Also called when the connected virtual machine stops or the device is removed from a
|
||||
* {@link DeviceBus} with a currently running virtual machine. In this case, {@link #dispose()}
|
||||
* will be called after this method returns.
|
||||
*/
|
||||
void unmount();
|
||||
|
||||
/**
|
||||
* Called when the device is suspended.
|
||||
* <p>
|
||||
* This can happen when the level area containing the context the device was loaded in is unloaded,
|
||||
* e.g. due to player moving too far away from the area.
|
||||
* <p>
|
||||
* Intended for soft-releasing resources acquired in {@link #mount(VMContext)}, i.e. non-persisted
|
||||
* unmanaged resources.
|
||||
*/
|
||||
void dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user