1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-15 04:30:29 +00:00

Move our test thread scheduler into the main jar

While useless in-game, both CCEmuX and eval.tweaked.cc ended up
reimplementing it, so might as well expose it!
This commit is contained in:
Jonathan Coates 2022-11-03 20:29:48 +00:00
parent 45c5de73bb
commit 998efcc950
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
4 changed files with 9 additions and 7 deletions

View File

@ -3,9 +3,8 @@
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com * Send enquiries to dratcliffe@gmail.com
*/ */
package dan200.computercraft.test.core.computer; package dan200.computercraft.core.computer.mainthread;
import dan200.computercraft.core.computer.mainthread.MainThreadScheduler;
import dan200.computercraft.core.metrics.MetricsObserver; import dan200.computercraft.core.metrics.MetricsObserver;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -13,8 +12,10 @@ import java.util.concurrent.TimeUnit;
/** /**
* A {@link MainThreadScheduler} which fails when a computer tries to enqueue work. * A {@link MainThreadScheduler} which fails when a computer tries to enqueue work.
* <p>
* This is useful for emulators, where we'll never make any main thread calls.
*/ */
public class FakeMainThreadScheduler implements MainThreadScheduler public class NoWorkMainThreadScheduler implements MainThreadScheduler
{ {
@Override @Override
public Executor createExecutor( MetricsObserver observer ) public Executor createExecutor( MetricsObserver observer )

View File

@ -13,12 +13,12 @@ import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.core.computer.Computer; import dan200.computercraft.core.computer.Computer;
import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.core.computer.ComputerSide;
import dan200.computercraft.core.computer.mainthread.NoWorkMainThreadScheduler;
import dan200.computercraft.core.filesystem.FileMount; import dan200.computercraft.core.filesystem.FileMount;
import dan200.computercraft.core.filesystem.FileSystemException; import dan200.computercraft.core.filesystem.FileSystemException;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.support.TestFiles; import dan200.computercraft.support.TestFiles;
import dan200.computercraft.test.core.computer.BasicEnvironment; import dan200.computercraft.test.core.computer.BasicEnvironment;
import dan200.computercraft.test.core.computer.FakeMainThreadScheduler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
@ -111,7 +111,7 @@ public class ComputerTestDelegate
} }
BasicEnvironment environment = new BasicEnvironment( mount ); BasicEnvironment environment = new BasicEnvironment( mount );
context = new ComputerContext( environment, 1, new FakeMainThreadScheduler() ); context = new ComputerContext( environment, 1, new NoWorkMainThreadScheduler() );
computer = new Computer( context, environment, term, 0 ); computer = new Computer( context, environment, term, 0 );
computer.getEnvironment().setPeripheral( ComputerSide.TOP, new FakeModem() ); computer.getEnvironment().setPeripheral( ComputerSide.TOP, new FakeModem() );
computer.getEnvironment().setPeripheral( ComputerSide.BOTTOM, new FakePeripheralHub() ); computer.getEnvironment().setPeripheral( ComputerSide.BOTTOM, new FakePeripheralHub() );

View File

@ -7,9 +7,9 @@ package dan200.computercraft.shared.network.server;
import dan200.computercraft.shared.computer.upload.FileSlice; import dan200.computercraft.shared.computer.upload.FileSlice;
import dan200.computercraft.shared.computer.upload.FileUpload; import dan200.computercraft.shared.computer.upload.FileUpload;
import dan200.computercraft.test.core.ArbitraryByteBuffer;
import dan200.computercraft.support.FakeContainer; import dan200.computercraft.support.FakeContainer;
import dan200.computercraft.support.WithMinecraft; import dan200.computercraft.support.WithMinecraft;
import dan200.computercraft.test.core.ArbitraryByteBuffer;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.jqwik.api.*; import net.jqwik.api.*;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;

View File

@ -10,6 +10,7 @@ import dan200.computercraft.core.ComputerContext
import dan200.computercraft.core.computer.Computer import dan200.computercraft.core.computer.Computer
import dan200.computercraft.core.computer.ComputerThread import dan200.computercraft.core.computer.ComputerThread
import dan200.computercraft.core.computer.TimeoutState import dan200.computercraft.core.computer.TimeoutState
import dan200.computercraft.core.computer.mainthread.NoWorkMainThreadScheduler
import dan200.computercraft.core.lua.MachineEnvironment import dan200.computercraft.core.lua.MachineEnvironment
import dan200.computercraft.core.lua.MachineResult import dan200.computercraft.core.lua.MachineResult
import dan200.computercraft.core.terminal.Terminal import dan200.computercraft.core.terminal.Terminal
@ -27,7 +28,7 @@ typealias FakeComputerTask = (state: TimeoutState) -> MachineResult
class KotlinComputerManager : AutoCloseable { class KotlinComputerManager : AutoCloseable {
private val machines: MutableMap<Computer, Queue<FakeComputerTask>> = HashMap() private val machines: MutableMap<Computer, Queue<FakeComputerTask>> = HashMap()
private val context = ComputerContext(BasicEnvironment(), ComputerThread(1), FakeMainThreadScheduler()) { DummyLuaMachine(it) } private val context = ComputerContext(BasicEnvironment(), ComputerThread(1), NoWorkMainThreadScheduler()) { DummyLuaMachine(it) }
private val errorLock: Lock = ReentrantLock() private val errorLock: Lock = ReentrantLock()
private val hasError = errorLock.newCondition() private val hasError = errorLock.newCondition()