1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Send terminal text and colours separately

This gives us slightly better compression, as backgrounds will often be
a single run of colours while the foreground won't be.

In practice, this is rarely an issue, as most terminals are small, but
worth doing anyway.
This commit is contained in:
Jonathan Coates 2022-05-30 13:44:11 +01:00
parent 3f0704624e
commit 1fd57a874f
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -324,9 +324,9 @@ public synchronized void write( PacketBuffer buffer )
TextBuffer textColour = this.textColour[y];
TextBuffer backColour = backgroundColour[y];
for( int x = 0; x < width; x++ ) buffer.writeByte( text.charAt( x ) & 0xFF );
for( int x = 0; x < width; x++ )
{
buffer.writeByte( text.charAt( x ) & 0xFF );
buffer.writeByte( getColour(
backColour.charAt( x ), Colour.BLACK ) << 4 |
getColour( textColour.charAt( x ), Colour.WHITE )
@ -353,10 +353,9 @@ public synchronized void read( PacketBuffer buffer )
TextBuffer textColour = this.textColour[y];
TextBuffer backColour = backgroundColour[y];
for( int x = 0; x < width; x++ ) text.setChar( x, (char) (buffer.readByte() & 0xFF) );
for( int x = 0; x < width; x++ )
{
text.setChar( x, (char) (buffer.readByte() & 0xFF) );
byte colour = buffer.readByte();
backColour.setChar( x, base16.charAt( (colour >> 4) & 0xF ) );
textColour.setChar( x, base16.charAt( colour & 0xF ) );