Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.common.ClientTerminal;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
Expand All @@ -43,25 +44,24 @@ public void render( TileMonitor tileEntity, double posX, double posY, double pos
private void renderMonitorAt( TileMonitor monitor, double posX, double posY, double posZ, float f, int i )
{
// Render from the origin monitor
TileMonitor origin = monitor.getOrigin();
if( origin == null )
{
return;
}
ClientMonitor originTerminal = monitor.getClientMonitor();

if( originTerminal == null ) return;
TileMonitor origin = originTerminal.getOrigin();
BlockPos monitorPos = monitor.getPos();

// Ensure each monitor is rendered only once
// Ensure each monitor terminal is rendered only once. We allow rendering a specific tile
// multiple times in a single frame to ensure compatibility with shaders which may run a
// pass multiple times.
long renderFrame = ComputerCraft.getRenderFrame();
if( origin.m_lastRenderFrame == renderFrame )
if( originTerminal.lastRenderFrame == renderFrame && !monitorPos.equals( originTerminal.lastRenderPos ) )
{
return;
}
else
{
origin.m_lastRenderFrame = renderFrame;
}

boolean redraw = origin.pollChanged();
BlockPos monitorPos = monitor.getPos();
originTerminal.lastRenderFrame = renderFrame;
originTerminal.lastRenderPos = monitorPos;

BlockPos originPos = origin.getPos();
posX += originPos.getX() - monitorPos.getX();
posY += originPos.getY() - monitorPos.getY();
Expand All @@ -82,65 +82,65 @@ private void renderMonitorAt( TileMonitor monitor, double posX, double posY, dou
GlStateManager.rotate( pitch, 1.0f, 0.0f, 0.0f );
GlStateManager.translate(
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
((double)origin.getHeight() - 0.5) - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN),
(origin.getHeight() - 0.5) - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN),
0.5
);
double xSize = (double)origin.getWidth() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER );
double ySize = (double)origin.getHeight() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER );
double xSize = origin.getWidth() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER );
double ySize = origin.getHeight() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER );

// Get renderers
Minecraft mc = Minecraft.getMinecraft();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder renderer = tessellator.getBuffer();

// Get terminal
ClientTerminal clientTerminal = (ClientTerminal)origin.getTerminal();
Terminal terminal = (clientTerminal != null) ? clientTerminal.getTerminal() : null;
redraw = redraw || (clientTerminal != null && clientTerminal.hasTerminalChanged());
boolean redraw = originTerminal.pollTerminalChanged();

// Draw the contents
GlStateManager.depthMask( false );
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, 0xFF, 0xFF );
GlStateManager.disableLighting();
mc.entityRenderer.disableLightmap();
try
{
Terminal terminal = originTerminal.getTerminal();
if( terminal != null )
{
Palette palette = terminal.getPalette();

// Allocate display lists
if( origin.m_renderDisplayList < 0 )
if( originTerminal.renderDisplayList < 0 )
{
origin.m_renderDisplayList = GlStateManager.glGenLists( 3 );
originTerminal.renderDisplayList = GlStateManager.glGenLists( 3 );
redraw = true;
}

// Draw a terminal
boolean greyscale = !clientTerminal.isColour();
boolean greyscale = !originTerminal.isColour();
int width = terminal.getWidth();
int height = terminal.getHeight();
int cursorX = terminal.getCursorX();
int cursorY = terminal.getCursorY();
FixedWidthFontRenderer fontRenderer = (FixedWidthFontRenderer)ComputerCraft.getFixedWidthFontRenderer();
FixedWidthFontRenderer fontRenderer = (FixedWidthFontRenderer) ComputerCraft.getFixedWidthFontRenderer();

GlStateManager.pushMatrix();
try
{
double xScale = xSize / (double) ( width * FixedWidthFontRenderer.FONT_WIDTH );
double yScale = ySize / (double) ( height * FixedWidthFontRenderer.FONT_HEIGHT );
double xScale = xSize / ( width * FixedWidthFontRenderer.FONT_WIDTH );
double yScale = ySize / ( height * FixedWidthFontRenderer.FONT_HEIGHT );
GlStateManager.scale( xScale, -yScale, 1.0 );

// Draw background
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.background );
if( redraw )
{
// Build background display list
GlStateManager.glNewList( origin.m_renderDisplayList, GL11.GL_COMPILE );
GlStateManager.glNewList( originTerminal.renderDisplayList, GL11.GL_COMPILE );
try
{
double marginXSize = TileMonitor.RENDER_MARGIN / xScale;
double marginYSize = TileMonitor.RENDER_MARGIN / yScale;
double marginSquash = marginYSize / (double) FixedWidthFontRenderer.FONT_HEIGHT;
double marginSquash = marginYSize / FixedWidthFontRenderer.FONT_HEIGHT;

// Top and bottom margins
GlStateManager.pushMatrix();
Expand All @@ -149,7 +149,7 @@ private void renderMonitorAt( TileMonitor monitor, double posX, double posY, dou
GlStateManager.scale( 1.0, marginSquash, 1.0 );
GlStateManager.translate( 0.0, -marginYSize / marginSquash, 0.0 );
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale, palette );
GlStateManager.translate( 0.0, ( marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT ) / marginSquash, 0.0 );
GlStateManager.translate( 0.0, (marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT) / marginSquash, 0.0 );
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale, palette );
}
finally
Expand All @@ -174,15 +174,15 @@ private void renderMonitorAt( TileMonitor monitor, double posX, double posY, dou
GlStateManager.glEndList();
}
}
GlStateManager.callList( origin.m_renderDisplayList );
GlStateManager.callList( originTerminal.renderDisplayList );
GlStateManager.resetColor();

// Draw text
fontRenderer.bindFont();
if( redraw )
{
// Build text display list
GlStateManager.glNewList( origin.m_renderDisplayList + 1, GL11.GL_COMPILE );
GlStateManager.glNewList( originTerminal.renderDisplayList + 1, GL11.GL_COMPILE );
try
{
// Lines
Expand All @@ -202,15 +202,15 @@ private void renderMonitorAt( TileMonitor monitor, double posX, double posY, dou
GlStateManager.glEndList();
}
}
GlStateManager.callList( origin.m_renderDisplayList + 1 );
GlStateManager.callList( originTerminal.renderDisplayList + 1 );
GlStateManager.resetColor();

// Draw cursor
fontRenderer.bindFont();
if( redraw )
{
// Build cursor display list
GlStateManager.glNewList( origin.m_renderDisplayList + 2, GL11.GL_COMPILE );
GlStateManager.glNewList( originTerminal.renderDisplayList + 2, GL11.GL_COMPILE );
try
{
// Cursor
Expand All @@ -236,7 +236,7 @@ private void renderMonitorAt( TileMonitor monitor, double posX, double posY, dou
}
if( ComputerCraft.getGlobalCursorBlink() )
{
GlStateManager.callList( origin.m_renderDisplayList + 2 );
GlStateManager.callList( originTerminal.renderDisplayList + 2 );
GlStateManager.resetColor();
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/dan200/computercraft/core/terminal/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Terminal( int width, int height )
m_palette = new Palette();
}

public void reset()
public synchronized void reset()
{
m_cursorColour = 0;
m_cursorBackgroundColour = 15;
Expand All @@ -76,7 +76,7 @@ public int getHeight() {
return m_height;
}

public void resize( int width, int height )
public synchronized void resize( int width, int height )
{
if( width == m_width && height == m_height )
{
Expand Down Expand Up @@ -189,7 +189,7 @@ public Palette getPalette()
return m_palette;
}

public void blit( String text, String textColour, String backgroundColour )
public synchronized void blit( String text, String textColour, String backgroundColour )
{
int x = m_cursorX;
int y = m_cursorY;
Expand All @@ -202,7 +202,7 @@ public void blit( String text, String textColour, String backgroundColour )
}
}

public void write( String text )
public synchronized void write( String text )
{
int x = m_cursorX;
int y = m_cursorY;
Expand All @@ -215,7 +215,7 @@ public void write( String text )
}
}

public void scroll( int yDiff )
public synchronized void scroll( int yDiff )
{
if( yDiff != 0 )
{
Expand Down Expand Up @@ -245,7 +245,7 @@ public void scroll( int yDiff )
}
}

public void clear()
public synchronized void clear()
{
for( int y = 0; y < m_height; ++y )
{
Expand All @@ -256,7 +256,7 @@ public void clear()
m_changed = true;
}

public void clearLine()
public synchronized void clearLine()
{
int y = m_cursorY;
if( y >= 0 && y < m_height )
Expand All @@ -268,7 +268,7 @@ public void clearLine()
}
}

public TextBuffer getLine( int y )
public synchronized TextBuffer getLine( int y )
{
if( y >= 0 && y < m_height )
{
Expand All @@ -277,15 +277,15 @@ public TextBuffer getLine( int y )
return null;
}

public void setLine( int y, String text, String textColour, String backgroundColour )
public synchronized void setLine( int y, String text, String textColour, String backgroundColour )
{
m_text[y].write( text );
m_textColour[y].write( textColour );
m_backgroundColour[y].write( backgroundColour );
m_changed = true;
}

public TextBuffer getTextColourLine( int y )
public synchronized TextBuffer getTextColourLine( int y )
{
if( y>=0 && y<m_height )
{
Expand All @@ -294,7 +294,7 @@ public TextBuffer getTextColourLine( int y )
return null;
}

public TextBuffer getBackgroundColourLine( int y )
public synchronized TextBuffer getBackgroundColourLine( int y )
{
if( y>=0 && y<m_height )
{
Expand All @@ -318,7 +318,7 @@ public void clearChanged()
m_changed = false;
}

public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound )
public synchronized NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound )
{
nbttagcompound.setInteger( "term_cursorX", m_cursorX );
nbttagcompound.setInteger( "term_cursorY", m_cursorY );
Expand All @@ -338,7 +338,7 @@ public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound )
return nbttagcompound;
}

public void readFromNBT( NBTTagCompound nbttagcompound )
public synchronized void readFromNBT( NBTTagCompound nbttagcompound )
{
m_cursorX = nbttagcompound.getInteger( "term_cursorX" );
m_cursorY = nbttagcompound.getInteger( "term_cursorY" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@ public class ClientTerminal implements ITerminal
private boolean m_colour;
private Terminal m_terminal;
private boolean m_terminalChanged;
private boolean m_terminalChangedLastFrame;

public ClientTerminal( boolean colour )
{
m_colour = colour;
m_terminal = null;
m_terminalChanged = false;
m_terminalChangedLastFrame = false;
}

public void update()
{
m_terminalChangedLastFrame = m_terminalChanged || (m_terminal != null && m_terminal.getChanged());
if( m_terminal != null )
{
m_terminalChanged |= m_terminal.getChanged();
m_terminal.clearChanged();
}
m_terminalChanged = false;
}

public boolean hasTerminalChanged()
public boolean pollTerminalChanged()
{
return m_terminalChangedLastFrame;
boolean changed = m_terminalChanged;
m_terminalChanged = false;
return changed;
}

// ITerminal implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class TilePeripheralBase extends TileGeneric
{
// Statics

private EnumFacing m_dir;
protected EnumFacing m_dir;
private int m_anim;
private boolean m_changed;

Expand Down Expand Up @@ -98,6 +98,11 @@ public EnumFacing getDirection()
return m_dir;
}

public EnumFacing getCachedDirection()
{
return m_dir;
}

@Override
public void setDirection( EnumFacing dir )
{
Expand Down
Loading