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

Store colour support in the Terminal

Previously we stored it alongside the terminal. While this makes sense -
it's not a property of the terminal itself, it ends up duplicating code
in a bunch of places.

We now track the colour flag on the terminal itself. This allows us to
simplify a couple of things:

 - The palette now also knows whether it supports colours or not, and so
   performs greyscale conversion. This means we no longer need to thread
   a "greyscale" flag throughout terminal rendering.

 - Remove isColour() getters from a whole load of
   places (TerminalMethods, ServerTerminal, IComputerEnvironment).
This commit is contained in:
Jonathan Coates 2022-10-21 18:26:57 +01:00
parent c49547b962
commit cf05ab1db1
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
33 changed files with 190 additions and 262 deletions

View File

@ -9,7 +9,6 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
@ -32,10 +31,7 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
@Override
protected WidgetTerminal createTerminal()
{
return new WidgetTerminal(
getMenu().getFamily() != ComputerFamily.NORMAL, terminalData, input,
leftPos + ComputerSidebar.WIDTH + BORDER, topPos + BORDER
);
return new WidgetTerminal( terminalData, input, leftPos + ComputerSidebar.WIDTH + BORDER, topPos + BORDER );
}
@Override

View File

@ -43,10 +43,7 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
@Override
protected WidgetTerminal createTerminal()
{
return new WidgetTerminal(
getMenu().getFamily() != ComputerFamily.NORMAL, terminalData, input,
leftPos + BORDER + ComputerSidebar.WIDTH, topPos + BORDER
);
return new WidgetTerminal( terminalData, input, leftPos + BORDER + ComputerSidebar.WIDTH, topPos + BORDER );
}
@Override

View File

@ -8,7 +8,6 @@ package dan200.computercraft.client.gui;
import com.mojang.blaze3d.matrix.MatrixStack;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.IHasContainer;
@ -56,7 +55,7 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
super.init();
minecraft.keyboardHandler.setSendRepeatsToGui( true );
terminal = addWidget( new WidgetTerminal( getMenu().getFamily() != ComputerFamily.NORMAL, terminalData, new ClientInputHandler( menu ), 0, 0 ) );
terminal = addWidget( new WidgetTerminal( terminalData, new ClientInputHandler( menu ), 0, 0 ) );
terminal.visible = false;
terminal.active = false;
setFocused( terminal );

View File

@ -33,11 +33,9 @@ public class WidgetTerminal extends Widget
{
private static final float TERMINATE_TIME = 0.5f;
private final boolean isColour;
private final @Nonnull Terminal terminal;
private final @Nonnull InputHandler computer;
// The positions of the actual terminal
private final int innerX;
private final int innerY;
@ -54,11 +52,10 @@ public class WidgetTerminal extends Widget
private final BitSet keysDown = new BitSet( 256 );
public WidgetTerminal( boolean isColour, @Nonnull Terminal terminal, @Nonnull InputHandler computer, int x, int y )
public WidgetTerminal( @Nonnull Terminal terminal, @Nonnull InputHandler computer, int x, int y )
{
super( x, y, terminal.getWidth() * FONT_WIDTH + MARGIN * 2, terminal.getHeight() * FONT_HEIGHT + MARGIN * 2, StringTextComponent.EMPTY );
this.isColour = isColour;
this.terminal = terminal;
this.computer = computer;
@ -178,7 +175,7 @@ public class WidgetTerminal extends Widget
public boolean mouseClicked( double mouseX, double mouseY, int button )
{
if( !inTermRegion( mouseX, mouseY ) ) return false;
if( !isColour || button < 0 || button > 2 ) return false;
if( !hasMouseSupport() || button < 0 || button > 2 ) return false;
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
@ -198,7 +195,7 @@ public class WidgetTerminal extends Widget
public boolean mouseReleased( double mouseX, double mouseY, int button )
{
if( !inTermRegion( mouseX, mouseY ) ) return false;
if( !isColour || button < 0 || button > 2 ) return false;
if( !hasMouseSupport() || button < 0 || button > 2 ) return false;
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
@ -221,7 +218,7 @@ public class WidgetTerminal extends Widget
public boolean mouseDragged( double mouseX, double mouseY, int button, double v2, double v3 )
{
if( !inTermRegion( mouseX, mouseY ) ) return false;
if( !isColour || button < 0 || button > 2 ) return false;
if( !hasMouseSupport() || button < 0 || button > 2 ) return false;
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
@ -242,7 +239,7 @@ public class WidgetTerminal extends Widget
public boolean mouseScrolled( double mouseX, double mouseY, double delta )
{
if( !inTermRegion( mouseX, mouseY ) ) return false;
if( !isColour || delta == 0 ) return false;
if( !hasMouseSupport() || delta == 0 ) return false;
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
@ -262,6 +259,11 @@ public class WidgetTerminal extends Widget
return active && visible && mouseX >= innerX && mouseY >= innerY && mouseX < innerX + innerWidth && mouseY < innerY + innerHeight;
}
private boolean hasMouseSupport()
{
return terminal.isColour();
}
public void update()
{
if( terminateTimer >= 0 && terminateTimer < TERMINATE_TIME && (terminateTimer += 0.05f) > TERMINATE_TIME )
@ -315,14 +317,7 @@ public class WidgetTerminal extends Widget
IRenderTypeBuffer.Impl renderer = IRenderTypeBuffer.immediate( Tessellator.getInstance().getBuilder() );
IVertexBuilder buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH );
if( terminal != null )
{
FixedWidthFontRenderer.drawTerminal( matrix, buffer, innerX, innerY, terminal, !isColour, MARGIN, MARGIN, MARGIN, MARGIN );
}
else
{
FixedWidthFontRenderer.drawEmptyTerminal( matrix, buffer, x, y, width, height );
}
FixedWidthFontRenderer.drawTerminal( matrix, buffer, innerX, innerY, terminal, MARGIN, MARGIN, MARGIN, MARGIN );
renderer.endBatch();
}

View File

@ -25,15 +25,13 @@ import javax.annotation.Nonnull;
*/
public class PocketComputerData
{
private boolean isColour;
private Terminal terminal;
private ComputerState state = ComputerState.OFF;
private int lightColour = -1;
public PocketComputerData( boolean colour )
{
isColour = colour;
terminal = new Terminal( ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight );
terminal = new Terminal( ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight, colour );
}
public int getLightState()
@ -41,11 +39,6 @@ public class PocketComputerData
return state != ComputerState.OFF ? lightColour : -1;
}
public boolean isColour()
{
return isColour;
}
@Nonnull
public Terminal getTerminal()
{
@ -65,8 +58,7 @@ public class PocketComputerData
public void setTerminal( TerminalState state )
{
isColour = state.colour;
if( state.width != terminal.getWidth() || state.height != terminal.getHeight() )
if( state.width != terminal.getWidth() || state.height != terminal.getHeight() || state.colour != terminal.isColour() )
{
terminal = state.create();
}

View File

@ -92,7 +92,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
FixedWidthFontRenderer.drawTerminal(
matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH ),
MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN
MARGIN, MARGIN, terminal, MARGIN, MARGIN, MARGIN, MARGIN
);
FixedWidthFontRenderer.drawBlocker(
matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_BLOCKER ),

View File

@ -173,14 +173,14 @@ class MonitorTextureBufferShader
buffer.limit( pos );
}
public static void setUniformData( ByteBuffer buffer, Terminal terminal, boolean greyscale )
public static void setUniformData( ByteBuffer buffer, Terminal terminal )
{
int pos = 0;
Palette palette = terminal.getPalette();
for( int i = 0; i < 16; i++ )
{
double[] colour = palette.getColour( i );
if( greyscale )
if( !terminal.isColour() )
{
float f = FixedWidthFontRenderer.toGreyscale( colour );
buffer.putFloat( pos, f ).putFloat( pos + 4, f ).putFloat( pos + 8, f );

View File

@ -63,7 +63,7 @@ public final class PrintoutRenderer
{
FixedWidthFontRenderer.drawString( transform, buffer,
x, y + line * FONT_HEIGHT, text[start + line], colours[start + line],
Palette.DEFAULT, false, light
Palette.DEFAULT, light
);
}
}
@ -76,7 +76,7 @@ public final class PrintoutRenderer
FixedWidthFontRenderer.drawString( transform, buffer,
x, y + line * FONT_HEIGHT,
new TextBuffer( text[start + line] ), new TextBuffer( colours[start + line] ),
Palette.DEFAULT, false, light
Palette.DEFAULT, light
);
}
}

View File

@ -157,7 +157,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
DirectBuffers.setBufferData( GL31.GL_TEXTURE_BUFFER, monitor.tboBuffer, terminalBuffer, GL20.GL_STATIC_DRAW );
ByteBuffer uniformBuffer = getBuffer( MonitorTextureBufferShader.UNIFORM_SIZE );
MonitorTextureBufferShader.setUniformData( uniformBuffer, terminal, !monitor.isColour() );
MonitorTextureBufferShader.setUniformData( uniformBuffer, terminal );
DirectBuffers.setBufferData( GL31.GL_UNIFORM_BUFFER, monitor.tboUniform, uniformBuffer, GL20.GL_STATIC_DRAW );
}
@ -197,13 +197,13 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
// Draw the main terminal and store how many vertices it has.
DirectFixedWidthFontRenderer.drawTerminalWithoutCursor(
buffer, 0, 0, terminal, !monitor.isColour(), yMargin, yMargin, xMargin, xMargin
buffer, 0, 0, terminal, yMargin, yMargin, xMargin, xMargin
);
int termIndexes = buffer.position() / vertexSize;
// If the cursor is visible, we append it to the end of our buffer. When rendering, we can either
// render n or n+1 quads and so toggle the cursor on and off.
DirectFixedWidthFontRenderer.drawCursor( buffer, 0, 0, terminal, !monitor.isColour() );
DirectFixedWidthFontRenderer.drawCursor( buffer, 0, 0, terminal );
buffer.flip();

View File

@ -61,25 +61,25 @@ public final class DirectFixedWidthFontRenderer
);
}
private static void drawQuad( ByteBuffer emitter, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
private static void drawQuad( ByteBuffer emitter, float x, float y, float width, float height, Palette palette, char colourIndex )
{
byte[] colour = palette.getByteColour( getColour( colourIndex, Colour.BLACK ), greyscale );
byte[] colour = palette.getRenderColours( getColour( colourIndex, Colour.BLACK ) );
quad( emitter, x, y, x + width, y + height, colour, BACKGROUND_START, BACKGROUND_START, BACKGROUND_END, BACKGROUND_END );
}
private static void drawBackground(
@Nonnull ByteBuffer buffer, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
@Nonnull ByteBuffer buffer, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette,
float leftMarginSize, float rightMarginSize, float height
)
{
if( leftMarginSize > 0 )
{
drawQuad( buffer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ) );
drawQuad( buffer, x - leftMarginSize, y, leftMarginSize, height, palette, backgroundColour.charAt( 0 ) );
}
if( rightMarginSize > 0 )
{
drawQuad( buffer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ) );
drawQuad( buffer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, backgroundColour.charAt( backgroundColour.length() - 1 ) );
}
// Batch together runs of identical background cells.
@ -92,7 +92,7 @@ public final class DirectFixedWidthFontRenderer
if( blockColour != '\0' )
{
drawQuad( buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour );
drawQuad( buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, blockColour );
}
blockColour = colourIndex;
@ -101,15 +101,15 @@ public final class DirectFixedWidthFontRenderer
if( blockColour != '\0' )
{
drawQuad( buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour );
drawQuad( buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, blockColour );
}
}
private static void drawString( @Nonnull ByteBuffer buffer, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette, boolean greyscale )
private static void drawString( @Nonnull ByteBuffer buffer, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette )
{
for( int i = 0; i < text.length(); i++ )
{
byte[] colour = palette.getByteColour( getColour( textColour.charAt( i ), Colour.BLACK ), greyscale );
byte[] colour = palette.getRenderColours( getColour( textColour.charAt( i ), Colour.BLACK ) );
int index = text.charAt( i );
if( index > 255 ) index = '?';
@ -118,7 +118,7 @@ public final class DirectFixedWidthFontRenderer
}
public static void drawTerminalWithoutCursor(
@Nonnull ByteBuffer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale,
@Nonnull ByteBuffer buffer, float x, float y, @Nonnull Terminal terminal,
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
)
{
@ -127,12 +127,12 @@ public final class DirectFixedWidthFontRenderer
// Top and bottom margins
drawBackground(
buffer, x, y - topMarginSize, terminal.getBackgroundColourLine( 0 ), palette, greyscale,
buffer, x, y - topMarginSize, terminal.getBackgroundColourLine( 0 ), palette,
leftMarginSize, rightMarginSize, topMarginSize
);
drawBackground(
buffer, x, y + height * FONT_HEIGHT, terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
buffer, x, y + height * FONT_HEIGHT, terminal.getBackgroundColourLine( height - 1 ), palette,
leftMarginSize, rightMarginSize, bottomMarginSize
);
@ -141,21 +141,21 @@ public final class DirectFixedWidthFontRenderer
{
float rowY = y + FONT_HEIGHT * i;
drawBackground(
buffer, x, rowY, terminal.getBackgroundColourLine( i ), palette, greyscale,
buffer, x, rowY, terminal.getBackgroundColourLine( i ), palette,
leftMarginSize, rightMarginSize, FONT_HEIGHT
);
drawString(
buffer, x, rowY, terminal.getLine( i ), terminal.getTextColourLine( i ),
palette, greyscale
palette
);
}
}
public static void drawCursor( @Nonnull ByteBuffer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale )
public static void drawCursor( @Nonnull ByteBuffer buffer, float x, float y, @Nonnull Terminal terminal )
{
if( isCursorVisible( terminal ) )
{
byte[] colour = terminal.getPalette().getByteColour( 15 - terminal.getTextColour(), greyscale );
byte[] colour = terminal.getPalette().getRenderColours( 15 - terminal.getTextColour() );
drawChar( buffer, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour );
}
}

View File

@ -92,26 +92,26 @@ public final class FixedWidthFontRenderer
quad( transform, buffer, x, y, x + width, y + height, z, colour, BACKGROUND_START, BACKGROUND_START, BACKGROUND_END, BACKGROUND_END, light );
}
private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex, int light )
private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, Palette palette, char colourIndex, int light )
{
byte[] colour = palette.getByteColour( getColour( colourIndex, Colour.BLACK ), greyscale );
byte[] colour = palette.getRenderColours( getColour( colourIndex, Colour.BLACK ) );
drawQuad( transform, buffer, x, y, 0, width, height, colour, light );
}
private static void drawBackground(
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
@Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
@Nonnull TextBuffer backgroundColour, @Nonnull Palette palette,
float leftMarginSize, float rightMarginSize, float height, int light
)
{
if( leftMarginSize > 0 )
{
drawQuad( transform, buffer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ), light );
drawQuad( transform, buffer, x - leftMarginSize, y, leftMarginSize, height, palette, backgroundColour.charAt( 0 ), light );
}
if( rightMarginSize > 0 )
{
drawQuad( transform, buffer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ), light );
drawQuad( transform, buffer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, backgroundColour.charAt( backgroundColour.length() - 1 ), light );
}
// Batch together runs of identical background cells.
@ -124,7 +124,7 @@ public final class FixedWidthFontRenderer
if( blockColour != '\0' )
{
drawQuad( transform, buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour, light );
drawQuad( transform, buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, blockColour, light );
}
blockColour = colourIndex;
@ -133,18 +133,18 @@ public final class FixedWidthFontRenderer
if( blockColour != '\0' )
{
drawQuad( transform, buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour, light );
drawQuad( transform, buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, blockColour, light );
}
}
public static void drawString(
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder renderer, float x, float y,
@Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette, boolean greyscale, int light
@Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette, int light
)
{
for( int i = 0; i < text.length(); i++ )
{
byte[] colour = palette.getByteColour( getColour( textColour.charAt( i ), Colour.BLACK ), greyscale );
byte[] colour = palette.getRenderColours( getColour( textColour.charAt( i ), Colour.BLACK ) );
int index = text.charAt( i );
if( index > 255 ) index = '?';
@ -154,7 +154,7 @@ public final class FixedWidthFontRenderer
public static void drawTerminalWithoutCursor(
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
@Nonnull Terminal terminal, boolean greyscale,
@Nonnull Terminal terminal,
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
)
{
@ -164,13 +164,13 @@ public final class FixedWidthFontRenderer
// Top and bottom margins
drawBackground(
transform, buffer, x, y - topMarginSize,
terminal.getBackgroundColourLine( 0 ), palette, greyscale,
terminal.getBackgroundColourLine( 0 ), palette,
leftMarginSize, rightMarginSize, topMarginSize, FULL_BRIGHT_LIGHTMAP
);
drawBackground(
transform, buffer, x, y + height * FONT_HEIGHT,
terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
terminal.getBackgroundColourLine( height - 1 ), palette,
leftMarginSize, rightMarginSize, bottomMarginSize, FULL_BRIGHT_LIGHTMAP
);
@ -180,12 +180,12 @@ public final class FixedWidthFontRenderer
float rowY = y + FONT_HEIGHT * i;
drawBackground(
transform, buffer, x, rowY, terminal.getBackgroundColourLine( i ),
palette, greyscale, leftMarginSize, rightMarginSize, FONT_HEIGHT, FULL_BRIGHT_LIGHTMAP
palette, leftMarginSize, rightMarginSize, FONT_HEIGHT, FULL_BRIGHT_LIGHTMAP
);
drawString(
transform, buffer, x, rowY, terminal.getLine( i ), terminal.getTextColourLine( i ),
palette, greyscale, FULL_BRIGHT_LIGHTMAP
palette, FULL_BRIGHT_LIGHTMAP
);
}
}
@ -200,25 +200,23 @@ public final class FixedWidthFontRenderer
}
public static void drawCursor(
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
@Nonnull Terminal terminal, boolean greyscale
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y, @Nonnull Terminal terminal
)
{
if( isCursorVisible( terminal ) && FrameInfo.getGlobalCursorBlink() )
{
byte[] colour = terminal.getPalette().getByteColour( 15 - terminal.getTextColour(), greyscale );
byte[] colour = terminal.getPalette().getRenderColours( 15 - terminal.getTextColour() );
drawChar( transform, buffer, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour, FULL_BRIGHT_LIGHTMAP );
}
}
public static void drawTerminal(
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
@Nonnull Terminal terminal, boolean greyscale,
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y, @Nonnull Terminal terminal,
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
)
{
drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
drawCursor( transform, buffer, x, y, terminal, greyscale );
drawTerminalWithoutCursor( transform, buffer, x, y, terminal, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
drawCursor( transform, buffer, x, y, terminal );
}
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull IVertexBuilder renderer, float x, float y, float width, float height )

View File

@ -69,10 +69,4 @@ public class TermAPI extends TermMethods implements ILuaAPI
{
return terminal;
}
@Override
public boolean isColour()
{
return environment.isColour();
}
}

View File

@ -37,8 +37,6 @@ public abstract class TermMethods
@Nonnull
public abstract Terminal getTerminal() throws LuaException;
public abstract boolean isColour() throws LuaException;
/**
* Write {@code text} at the current cursor position, moving the cursor to the end of the text.
*
@ -258,7 +256,7 @@ public abstract class TermMethods
@LuaFunction( { "isColour", "isColor" } )
public final boolean getIsColour() throws LuaException
{
return isColour();
return getTerminal().isColour();
}
/**

View File

@ -637,11 +637,10 @@ final class ComputerExecutor
private void displayFailure( String message, String extra )
{
Terminal terminal = computer.getTerminal();
boolean colour = computer.getComputerEnvironment().isColour();
terminal.reset();
// Display our primary error message
if( colour ) terminal.setTextColour( 15 - Colour.RED.ordinal() );
if( terminal.isColour() ) terminal.setTextColour( 15 - Colour.RED.ordinal() );
terminal.write( message );
if( extra != null )
@ -654,7 +653,7 @@ final class ComputerExecutor
// And display our generic "CC may be installed incorrectly" message.
terminal.setCursorPos( 0, terminal.getCursorY() + 1 );
if( colour ) terminal.setTextColour( 15 - Colour.WHITE.ordinal() );
if( terminal.isColour() ) terminal.setTextColour( 15 - Colour.WHITE.ordinal() );
terminal.write( "ComputerCraft may be installed incorrectly" );
}

View File

@ -18,8 +18,6 @@ public interface IComputerEnvironment
double getTimeOfDay();
boolean isColour();
long getComputerSpaceLimit();
@Nonnull

View File

@ -11,11 +11,16 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
public class Terminal
{
private static final String base16 = "0123456789abcdef";
private static final String BASE_16 = "0123456789abcdef";
private int width;
private int height;
private final boolean colour;
private int cursorX = 0;
private int cursorY = 0;
@ -23,26 +28,25 @@ public class Terminal
private int cursorColour = 0;
private int cursorBackgroundColour = 15;
private int width;
private int height;
private TextBuffer[] text;
private TextBuffer[] textColour;
private TextBuffer[] backgroundColour;
private final Palette palette = new Palette();
private final Palette palette;
private final Runnable onChanged;
private final @Nullable Runnable onChanged;
public Terminal( int width, int height )
public Terminal( int width, int height, boolean colour )
{
this( width, height, null );
this( width, height, colour, null );
}
public Terminal( int width, int height, Runnable changedCallback )
public Terminal( int width, int height, boolean colour, Runnable changedCallback )
{
this.width = width;
this.height = height;
this.colour = colour;
palette = new Palette( colour );
onChanged = changedCallback;
text = new TextBuffer[height];
@ -51,8 +55,8 @@ public class Terminal
for( int i = 0; i < this.height; i++ )
{
text[i] = new TextBuffer( ' ', this.width );
textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
textColour[i] = new TextBuffer( BASE_16.charAt( cursorColour ), this.width );
backgroundColour[i] = new TextBuffer( BASE_16.charAt( cursorBackgroundColour ), this.width );
}
}
@ -78,6 +82,11 @@ public class Terminal
return height;
}
public boolean isColour()
{
return colour;
}
public synchronized void resize( int width, int height )
{
if( width == this.width && height == this.height )
@ -102,8 +111,8 @@ public class Terminal
if( i >= oldHeight )
{
text[i] = new TextBuffer( ' ', this.width );
textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
textColour[i] = new TextBuffer( BASE_16.charAt( cursorColour ), this.width );
backgroundColour[i] = new TextBuffer( BASE_16.charAt( cursorBackgroundColour ), this.width );
}
else if( this.width == oldWidth )
{
@ -114,8 +123,8 @@ public class Terminal
else
{
text[i] = new TextBuffer( ' ', this.width );
textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
textColour[i] = new TextBuffer( BASE_16.charAt( cursorColour ), this.width );
backgroundColour[i] = new TextBuffer( BASE_16.charAt( cursorBackgroundColour ), this.width );
text[i].write( oldText[i] );
textColour[i].write( oldTextColour[i] );
backgroundColour[i].write( oldBackgroundColour[i] );
@ -212,8 +221,8 @@ public class Terminal
if( y >= 0 && y < height )
{
this.text[y].write( text, x );
textColour[y].fill( base16.charAt( cursorColour ), x, x + text.length() );
backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ), x, x + text.length() );
textColour[y].fill( BASE_16.charAt( cursorColour ), x, x + text.length() );
backgroundColour[y].fill( BASE_16.charAt( cursorBackgroundColour ), x, x + text.length() );
setChanged();
}
}
@ -237,8 +246,8 @@ public class Terminal
else
{
newText[y] = new TextBuffer( ' ', width );
newTextColour[y] = new TextBuffer( base16.charAt( cursorColour ), width );
newBackgroundColour[y] = new TextBuffer( base16.charAt( cursorBackgroundColour ), width );
newTextColour[y] = new TextBuffer( BASE_16.charAt( cursorColour ), width );
newBackgroundColour[y] = new TextBuffer( BASE_16.charAt( cursorBackgroundColour ), width );
}
}
text = newText;
@ -253,8 +262,8 @@ public class Terminal
for( int y = 0; y < height; y++ )
{
text[y].fill( ' ' );
textColour[y].fill( base16.charAt( cursorColour ) );
backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ) );
textColour[y].fill( BASE_16.charAt( cursorColour ) );
backgroundColour[y].fill( BASE_16.charAt( cursorBackgroundColour ) );
}
setChanged();
}
@ -265,8 +274,8 @@ public class Terminal
if( y >= 0 && y < height )
{
text[y].fill( ' ' );
textColour[y].fill( base16.charAt( cursorColour ) );
backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ) );
textColour[y].fill( BASE_16.charAt( cursorColour ) );
backgroundColour[y].fill( BASE_16.charAt( cursorBackgroundColour ) );
setChanged();
}
}
@ -357,8 +366,8 @@ public class Terminal
for( int x = 0; x < width; x++ )
{
byte colour = buffer.readByte();
backColour.setChar( x, base16.charAt( (colour >> 4) & 0xF ) );
textColour.setChar( x, base16.charAt( colour & 0xF ) );
backColour.setChar( x, BASE_16.charAt( (colour >> 4) & 0xF ) );
textColour.setChar( x, BASE_16.charAt( colour & 0xF ) );
}
}
@ -399,12 +408,12 @@ public class Terminal
{
text[n].write( nbt.getString( "term_text_" + n ) );
}
textColour[n].fill( base16.charAt( cursorColour ) );
textColour[n].fill( BASE_16.charAt( cursorColour ) );
if( nbt.contains( "term_textColour_" + n ) )
{
textColour[n].write( nbt.getString( "term_textColour_" + n ) );
}
backgroundColour[n].fill( base16.charAt( cursorBackgroundColour ) );
backgroundColour[n].fill( BASE_16.charAt( cursorBackgroundColour ) );
if( nbt.contains( "term_textBgColour_" + n ) )
{
backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
public class ClientTerminal implements ITerminal
public class ClientTerminal
{
private boolean colour;
private Terminal terminal;
@ -28,20 +28,11 @@ public class ClientTerminal implements ITerminal
return changed;
}
// ITerminal implementation
@Override
public Terminal getTerminal()
{
return terminal;
}
@Override
public boolean isColour()
{
return colour;
}
public void read( TerminalState state )
{
colour = state.colour;
@ -60,7 +51,7 @@ public class ClientTerminal implements ITerminal
{
if( terminal == null )
{
terminal = new Terminal( width, height, () -> terminalChanged = true );
terminal = new Terminal( width, height, colour, () -> terminalChanged = true );
terminalChanged = true;
}
else

View File

@ -1,15 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
public interface ITerminal
{
Terminal getTerminal();
boolean isColour();
}

View File

@ -8,32 +8,26 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import javax.annotation.Nullable;
import java.util.concurrent.atomic.AtomicBoolean;
public class ServerTerminal implements ITerminal
public class ServerTerminal
{
private final boolean colour;
private Terminal terminal;
private @Nullable Terminal terminal;
private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
private boolean terminalChangedLastFrame = false;
public ServerTerminal( boolean colour )
{
this.colour = colour;
terminal = null;
}
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
{
this.colour = colour;
terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
}
protected void resize( int width, int height )
{
if( terminal == null )
{
terminal = new Terminal( width, height, this::markTerminalChanged );
terminal = new Terminal( width, height, colour, this::markTerminalChanged );
markTerminalChanged();
}
else
@ -66,20 +60,13 @@ public class ServerTerminal implements ITerminal
return terminalChangedLastFrame;
}
@Override
public Terminal getTerminal()
{
return terminal;
}
@Override
public boolean isColour()
{
return colour;
}
public TerminalState write()
{
return new TerminalState( colour, terminal );
return new TerminalState( terminal );
}
}

View File

@ -56,18 +56,12 @@ public class ServerComputer implements InputHandler, IComputerEnvironment
this.family = family;
instanceID = ServerComputerRegistry.INSTANCE.getUnusedInstanceID();
terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
terminal = new Terminal( terminalWidth, terminalHeight, family != ComputerFamily.NORMAL, this::markTerminalChanged );
computer = new Computer( this, terminal, computerID );
computer.setLabel( label );
}
@Override
public boolean isColour()
{
return family != ComputerFamily.NORMAL;
}
public ComputerFamily getFamily()
{
return family;
@ -126,7 +120,7 @@ public class ServerComputer implements InputHandler, IComputerEnvironment
public TerminalState getTerminalState()
{
return new TerminalState( isColour(), terminal );
return new TerminalState( terminal );
}
public void keepAlive()

View File

@ -7,6 +7,7 @@ package dan200.computercraft.shared.network.client;
import dan200.computercraft.client.pocket.ClientPocketComputers;
import dan200.computercraft.client.pocket.PocketComputerData;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.network.NetworkMessage;
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
@ -28,7 +29,7 @@ public class PocketComputerDataMessage implements NetworkMessage
instanceId = computer.getInstanceID();
state = computer.getState();
lightState = computer.getLight();
terminal = sendTerminal ? computer.getTerminalState() : new TerminalState( false, null );
terminal = sendTerminal ? computer.getTerminalState() : new TerminalState( (Terminal) null );
}
public PocketComputerDataMessage( PacketBuffer buf )

View File

@ -42,23 +42,24 @@ public class TerminalState
private ByteBuf compressed;
public TerminalState( boolean colour, @Nullable Terminal terminal )
public TerminalState( @Nullable Terminal terminal )
{
this( colour, terminal, true );
this( terminal, true );
}
public TerminalState( boolean colour, @Nullable Terminal terminal, boolean compress )
public TerminalState( @Nullable Terminal terminal, boolean compress )
{
this.colour = colour;
this.compress = compress;
if( terminal == null )
{
colour = false;
width = height = 0;
buffer = null;
}
else
{
colour = terminal.isColour();
width = terminal.getWidth();
height = terminal.getHeight();
@ -123,7 +124,7 @@ public class TerminalState
public Terminal create()
{
if( buffer == null ) throw new NullPointerException( "Terminal does not exist" );
Terminal terminal = new Terminal( width, height );
Terminal terminal = new Terminal( width, height, colour );
terminal.read( new PacketBuffer( buffer ) );
return terminal;
}

View File

@ -39,6 +39,7 @@ public class KeyEventServerMessage extends ComputerServerMessage
@Override
public void toBytes( @Nonnull PacketBuffer buf )
{
super.toBytes( buf );
buf.writeByte( type );
buf.writeVarInt( key );
}

View File

@ -120,12 +120,6 @@ public class MonitorPeripheral extends TermMethods implements IPeripheral
return terminal;
}
@Override
public boolean isColour() throws LuaException
{
return getMonitor().isColour();
}
@Nullable
@Override
public Object getTarget()

View File

@ -577,6 +577,8 @@ public class TileMonitor extends TileGeneric
private void monitorTouched( float xPos, float yPos, float zPos )
{
if( !advanced ) return;
XYPair pair = XYPair
.of( xPos, yPos, zPos, getDirection(), getOrientation() )
.add( xIndex, height - yIndex - 1 );
@ -587,7 +589,7 @@ public class TileMonitor extends TileGeneric
}
ServerTerminal serverTerminal = getServerMonitor();
if( serverTerminal == null || !serverTerminal.isColour() ) return;
if( serverTerminal == null ) return;
Terminal originTerminal = serverTerminal.getTerminal();
if( originTerminal == null ) return;

View File

@ -63,7 +63,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
SidedCaps.ofNullable( facing -> facing == null ? new InvWrapper( this ) : new SidedInvWrapper( this, facing ) );
private LazyOptional<IPeripheral> peripheralCap;
private final Terminal page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
private final Terminal page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE, true );
private String pageTitle = "";
private boolean printing = false;

View File

@ -5,7 +5,6 @@
*/
package dan200.computercraft.shared.util;
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
@ -14,18 +13,19 @@ import javax.annotation.Nonnull;
public class Palette
{
private static final int PALETTE_SIZE = 16;
private final boolean colour;
private final double[][] colours = new double[PALETTE_SIZE][3];
private final byte[][] byteColours = new byte[PALETTE_SIZE][4];
private final byte[][] greyByteColours = new byte[PALETTE_SIZE][4];
public static final Palette DEFAULT = new Palette();
public static final Palette DEFAULT = new Palette( true );
public Palette()
public Palette( boolean colour )
{
// Get the default palette
this.colour = colour;
resetColours();
for( int i = 0; i < PALETTE_SIZE; i++ ) byteColours[i][3] = greyByteColours[i][3] = (byte) 255;
for( int i = 0; i < PALETTE_SIZE; i++ ) byteColours[i][3] = (byte) 255;
}
public void setColour( int i, double r, double g, double b )
@ -35,12 +35,17 @@ public class Palette
colours[i][1] = g;
colours[i][2] = b;
byteColours[i][0] = (byte) (int) (r * 255);
byteColours[i][1] = (byte) (int) (g * 255);
byteColours[i][2] = (byte) (int) (b * 255);
byte grey = (byte) (int) ((r + g + b) / 3 * 255);
greyByteColours[i][0] = greyByteColours[i][1] = greyByteColours[i][2] = grey;
if( colour )
{
byteColours[i][0] = (byte) (int) (r * 255);
byteColours[i][1] = (byte) (int) (g * 255);
byteColours[i][2] = (byte) (int) (b * 255);
}
else
{
byte grey = (byte) (int) ((r + g + b) / 3 * 255);
byteColours[i][0] = byteColours[i][1] = byteColours[i][2] = grey;
}
}
public void setColour( int i, Colour colour )
@ -54,20 +59,18 @@ public class Palette
}
/**
* Get the colour as a set of bytes rather than floats. This is called frequently by {@link FixedWidthFontRenderer},
* as our vertex format uses bytes.
* Get the colour as a set of RGB values suitable for rendering. Colours are automatically converted to greyscale
* when using a black and white palette.
* <p>
* This returns a byte array, suitable for being used directly by our terminal vertex format.
*
* This allows us to do the conversion once (when setting the colour) rather than for every vertex, at the cost of
* some memory overhead.
*
* @param i The colour index.
* @param greyscale Whether this number should be converted to greyscale.
* @param i The colour index.
* @return The number as a tuple of bytes.
*/
@Nonnull
public byte[] getByteColour( int i, boolean greyscale )
public byte[] getRenderColours( int i )
{
return greyscale ? greyByteColours[i] : byteColours[i];
return byteColours[i];
}
public void resetColour( int i )

View File

@ -97,7 +97,7 @@ public class ComputerTestDelegate
if( REPORT_PATH.delete() ) ComputerCraft.log.info( "Deleted previous coverage report." );
Terminal term = new Terminal( 80, 100 );
Terminal term = new Terminal( 80, 100, true );
IWritableMount mount = new FileMount( new File( "test-files/mount" ), 10_000_000 );
// Remove any existing files

View File

@ -62,12 +62,6 @@ public class BasicEnvironment implements IComputerEnvironment
return 0;
}
@Override
public boolean isColour()
{
return true;
}
@Override
public long getComputerSpaceLimit()
{

View File

@ -37,7 +37,7 @@ public class ComputerBootstrap
public static void run( String program, int maxTimes )
{
run( program, x -> { }, maxTimes );
run( program, x -> {}, maxTimes );
}
public static void run( IWritableMount mount, Consumer<Computer> setup, int maxTicks )
@ -45,7 +45,7 @@ public class ComputerBootstrap
ComputerCraft.logComputerErrors = true;
ComputerCraft.maxMainComputerTime = ComputerCraft.maxMainGlobalTime = Integer.MAX_VALUE;
Terminal term = new Terminal( ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight );
Terminal term = new Terminal( ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight, true );
final Computer computer = new Computer( new BasicEnvironment( mount ), term, 0 );
AssertApi api = new AssertApi();

View File

@ -55,7 +55,7 @@ public class FakeComputerManager
@Nonnull
public static Computer create()
{
Computer computer = new Computer( new BasicEnvironment(), new Terminal( 51, 19 ), 0 );
Computer computer = new Computer( new BasicEnvironment(), new Terminal( 51, 19, true ), 0 );
machines.put( computer, new ConcurrentLinkedQueue<>() );
return computer;
}

View File

@ -27,7 +27,7 @@ class TerminalTest
@Test
void testCreation()
{
Terminal terminal = new Terminal( 16, 9 );
Terminal terminal = new Terminal( 16, 9, true );
assertEquals( 16, terminal.getWidth() );
assertEquals( 9, terminal.getHeight() );
}
@ -35,7 +35,7 @@ class TerminalTest
@Test
void testSetAndGetLine()
{
Terminal terminal = new Terminal( 16, 9 );
Terminal terminal = new Terminal( 16, 9, true );
terminal.setLine( 1, "ABCDEFGHIJKLMNOP", "0123456789abcdef", "fedcba9876543210" );
assertEquals( "ABCDEFGHIJKLMNOP", terminal.getLine( 1 ).toString() );
assertEquals( "0123456789abcdef", terminal.getTextColourLine( 1 ).toString() );
@ -45,7 +45,7 @@ class TerminalTest
@Test
void testGetLineOutOfBounds()
{
Terminal terminal = new Terminal( 16, 9 );
Terminal terminal = new Terminal( 16, 9, true );
assertNull( terminal.getLine( -5 ) );
assertNull( terminal.getLine( 12 ) );
@ -60,7 +60,7 @@ class TerminalTest
@Test
void testDefaults()
{
Terminal terminal = new Terminal( 16, 9 );
Terminal terminal = new Terminal( 16, 9, true );
assertEquals( 0, terminal.getCursorX() );
assertEquals( 0, terminal.getCursorY() );
assertFalse( terminal.getCursorBlink() );
@ -71,7 +71,7 @@ class TerminalTest
@Test
void testDefaultTextBuffer()
{
assertThat( new Terminal( 4, 3 ), textMatches( new String[] {
assertThat( new Terminal( 4, 3, true ), textMatches( new String[] {
" ",
" ",
" ",
@ -81,7 +81,7 @@ class TerminalTest
@Test
void testDefaultTextColourBuffer()
{
assertThat( new Terminal( 4, 3 ), textColourMatches( new String[] {
assertThat( new Terminal( 4, 3, true ), textColourMatches( new String[] {
"0000",
"0000",
"0000",
@ -91,7 +91,7 @@ class TerminalTest
@Test
void testDefaultBackgroundColourBuffer()
{
assertThat( new Terminal( 4, 3 ), TerminalMatchers.backgroundColourMatches( new String[] {
assertThat( new Terminal( 4, 3, true ), TerminalMatchers.backgroundColourMatches( new String[] {
"ffff",
"ffff",
"ffff",
@ -102,7 +102,7 @@ class TerminalTest
void testZeroSizeBuffers()
{
String[] x = new String[0];
assertThat( new Terminal( 0, 0 ), allOf(
assertThat( new Terminal( 0, 0, true ), allOf(
textMatches( new String[0] ),
textColourMatches( x ),
TerminalMatchers.backgroundColourMatches( x )
@ -113,7 +113,7 @@ class TerminalTest
void testResizeWidthAndHeight()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setLine( 0, "test", "aaaa", "eeee" );
callCounter.reset();
@ -146,7 +146,7 @@ class TerminalTest
void testResizeSmaller()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setLine( 0, "test", "aaaa", "eeee" );
terminal.setLine( 1, "smol", "aaaa", "eeee" );
terminal.setLine( 2, "term", "aaaa", "eeee" );
@ -176,7 +176,7 @@ class TerminalTest
void testResizeWithSameDimensions()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
TerminalBufferSnapshot old = new TerminalBufferSnapshot( terminal );
terminal.resize( 4, 3 );
@ -189,7 +189,7 @@ class TerminalTest
void testSetAndGetCursorPos()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setCursorPos( 2, 1 );
@ -202,7 +202,7 @@ class TerminalTest
void testSetCursorPosUnchanged()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setCursorPos( 2, 1 );
callCounter.reset();
@ -217,7 +217,7 @@ class TerminalTest
void testSetCursorBlink()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setCursorBlink( true );
@ -229,7 +229,7 @@ class TerminalTest
void testSetCursorBlinkUnchanged()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setCursorBlink( true );
callCounter.reset();
@ -243,7 +243,7 @@ class TerminalTest
void testSetTextColour()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setTextColour( 5 );
@ -255,7 +255,7 @@ class TerminalTest
void testSetTextColourUnchanged()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setTextColour( 5 );
callCounter.reset();
@ -269,7 +269,7 @@ class TerminalTest
void testSetBackgroundColour()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setBackgroundColour( 5 );
@ -281,7 +281,7 @@ class TerminalTest
void testSetBackgroundColourUnchanged()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setBackgroundColour( 5 );
callCounter.reset();
@ -295,7 +295,7 @@ class TerminalTest
void testBlitFromOrigin()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
blit( terminal, "test", "1234", "abcd" );
@ -322,7 +322,7 @@ class TerminalTest
void testBlitWithOffset()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setCursorPos( 2, 1 );
callCounter.reset();
@ -353,7 +353,7 @@ class TerminalTest
void testBlitOutOfBounds()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
TerminalBufferSnapshot old = new TerminalBufferSnapshot( terminal );
terminal.setCursorPos( 2, -5 );
@ -372,7 +372,7 @@ class TerminalTest
@Test
public void testBlitPartialBuffer()
{
Terminal terminal = new Terminal( 4, 3 );
Terminal terminal = new Terminal( 4, 3, true );
ByteBuffer text = LuaValues.encode( "123456" );
text.position( 1 );
@ -386,7 +386,7 @@ class TerminalTest
void testWriteFromOrigin()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.write( "test" );
@ -413,7 +413,7 @@ class TerminalTest
void testWriteWithOffset()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setCursorPos( 2, 1 );
callCounter.reset();
@ -444,7 +444,7 @@ class TerminalTest
void testWriteOutOfBounds()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
TerminalBufferSnapshot old = new TerminalBufferSnapshot( terminal );
terminal.setCursorPos( 2, -5 );
@ -465,7 +465,7 @@ class TerminalTest
void testScrollUp()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setLine( 1, "test", "1111", "eeee" );
callCounter.reset();
@ -496,7 +496,7 @@ class TerminalTest
void testScrollDown()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setLine( 1, "test", "1111", "eeee" );
callCounter.reset();
@ -527,7 +527,7 @@ class TerminalTest
void testScrollZeroLinesUnchanged()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
terminal.setLine( 1, "test", "1111", "eeee" );
TerminalBufferSnapshot old = new TerminalBufferSnapshot( terminal );
@ -543,7 +543,7 @@ class TerminalTest
void testClear()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
TerminalBufferSnapshot old = new TerminalBufferSnapshot( terminal );
terminal.setLine( 1, "test", "1111", "eeee" );
@ -559,7 +559,7 @@ class TerminalTest
void testClearLine()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
TerminalBufferSnapshot old = new TerminalBufferSnapshot( terminal );
terminal.setLine( 1, "test", "1111", "eeee" );
@ -576,7 +576,7 @@ class TerminalTest
void testClearLineOutOfBounds()
{
CallCounter callCounter = new CallCounter();
Terminal terminal = new Terminal( 4, 3, callCounter );
Terminal terminal = new Terminal( 4, 3, true, callCounter );
TerminalBufferSnapshot old;
terminal.setLine( 1, "test", "1111", "eeee" );
@ -599,7 +599,7 @@ class TerminalTest
@Test
void testPacketBufferRoundtrip()
{
Terminal writeTerminal = new Terminal( 2, 1 );
Terminal writeTerminal = new Terminal( 2, 1, true );
blit( writeTerminal, "hi", "11", "ee" );
writeTerminal.setCursorPos( 2, 5 );
@ -610,7 +610,7 @@ class TerminalTest
writeTerminal.write( packetBuffer );
CallCounter callCounter = new CallCounter();
Terminal readTerminal = new Terminal( 2, 1, callCounter );
Terminal readTerminal = new Terminal( 2, 1, true, callCounter );
packetBuffer.writeBytes( packetBuffer );
readTerminal.read( packetBuffer );
@ -630,7 +630,7 @@ class TerminalTest
@Test
void testNbtRoundtrip()
{
Terminal writeTerminal = new Terminal( 10, 5 );
Terminal writeTerminal = new Terminal( 10, 5, true );
blit( writeTerminal, "hi", "11", "ee" );
writeTerminal.setCursorPos( 2, 5 );
writeTerminal.setTextColour( 3 );
@ -640,7 +640,7 @@ class TerminalTest
writeTerminal.writeToNBT( nbt );
CallCounter callCounter = new CallCounter();
Terminal readTerminal = new Terminal( 2, 1, callCounter );
Terminal readTerminal = new Terminal( 2, 1, true, callCounter );
readTerminal.readFromNBT( nbt );
@ -660,13 +660,13 @@ class TerminalTest
@Test
void testReadWriteNBTEmpty()
{
Terminal terminal = new Terminal( 0, 0 );
Terminal terminal = new Terminal( 0, 0, true );
CompoundNBT nbt = new CompoundNBT();
terminal.writeToNBT( nbt );
CallCounter callCounter = new CallCounter();
terminal = new Terminal( 0, 1, callCounter );
terminal = new Terminal( 0, 1, true, callCounter );
terminal.readFromNBT( nbt );
assertThat( terminal, allOf(

View File

@ -26,7 +26,7 @@ public class TerminalStateTest
Terminal terminal = randomTerminal();
PacketBuffer buffer = new PacketBuffer( Unpooled.directBuffer() );
new TerminalState( true, terminal, true ).write( buffer );
new TerminalState( terminal, true ).write( buffer );
checkEqual( terminal, read( buffer ) );
assertEquals( 0, buffer.readableBytes() );
@ -38,7 +38,7 @@ public class TerminalStateTest
Terminal terminal = randomTerminal();
PacketBuffer buffer = new PacketBuffer( Unpooled.directBuffer() );
new TerminalState( true, terminal, false ).write( buffer );
new TerminalState( terminal, false ).write( buffer );
checkEqual( terminal, read( buffer ) );
assertEquals( 0, buffer.readableBytes() );
@ -47,7 +47,7 @@ public class TerminalStateTest
private static Terminal randomTerminal()
{
Random random = new Random();
Terminal terminal = new Terminal( 10, 5 );
Terminal terminal = new Terminal( 10, 5, true );
for( int y = 0; y < terminal.getHeight(); y++ )
{
TextBuffer buffer = terminal.getLine( y );
@ -77,7 +77,7 @@ public class TerminalStateTest
if( !state.hasTerminal() ) return null;
Terminal other = new Terminal( state.width, state.height );
Terminal other = new Terminal( state.width, state.height, true );
state.apply( other );
return other;
}