mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-27 07:32:56 +00:00
Track turtle commands as server tasks
They're basically an alternative version of issueMainThreadTask anyway.
This commit is contained in:
parent
f3cace1d03
commit
8abcfcb4ac
@ -13,6 +13,7 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.turtle.*;
|
import dan200.computercraft.api.turtle.*;
|
||||||
|
import dan200.computercraft.core.tracking.Tracking;
|
||||||
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
||||||
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
@ -972,17 +973,21 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
TurtleCommandQueueEntry nextCommand = m_commandQueue.poll();
|
TurtleCommandQueueEntry nextCommand = m_commandQueue.poll();
|
||||||
if( nextCommand != null )
|
if( nextCommand != null )
|
||||||
{
|
{
|
||||||
|
ServerComputer computer = m_owner.getServerComputer();
|
||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
|
long start = System.nanoTime();
|
||||||
TurtleCommandResult result = nextCommand.command.execute( this );
|
TurtleCommandResult result = nextCommand.command.execute( this );
|
||||||
|
long end = System.nanoTime();
|
||||||
|
|
||||||
// Dispatch the callback
|
// Dispatch the callback
|
||||||
int callbackID = nextCommand.callbackID;
|
if( computer != null )
|
||||||
if( callbackID >= 0 )
|
|
||||||
{
|
{
|
||||||
if( result != null && result.isSuccess() )
|
Tracking.addServerTiming( computer.getComputer(), end - start );
|
||||||
|
int callbackID = nextCommand.callbackID;
|
||||||
|
if( callbackID >= 0 )
|
||||||
{
|
{
|
||||||
ServerComputer computer = m_owner.getServerComputer();
|
if( result != null && result.isSuccess() )
|
||||||
if( computer != null )
|
|
||||||
{
|
{
|
||||||
Object[] results = result.getResults();
|
Object[] results = result.getResults();
|
||||||
if( results != null )
|
if( results != null )
|
||||||
@ -1000,11 +1005,7 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
|
||||||
{
|
|
||||||
ServerComputer computer = m_owner.getServerComputer();
|
|
||||||
if( computer != null )
|
|
||||||
{
|
{
|
||||||
computer.queueEvent( "turtle_response", new Object[] {
|
computer.queueEvent( "turtle_response", new Object[] {
|
||||||
callbackID, false, result != null ? result.getErrorMessage() : null
|
callbackID, false, result != null ? result.getErrorMessage() : null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user