More efficiency improvements.

This commit is contained in:
UnknownShadow200 2015-04-04 11:10:26 +11:00
parent 0118370400
commit 8adfbc6cc6
4 changed files with 19 additions and 17 deletions

View File

@ -89,9 +89,9 @@ namespace ClassicalSharp.GraphicsAPI {
set { ToggleCap( EnableCap.Fog, value ); } set { ToggleCap( EnableCap.Fog, value ); }
} }
public override void SetFogColour( FastColour col ) { public unsafe override void SetFogColour( FastColour col ) {
float[] colRGBA = { col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f }; Vector4 colRGBA = new Vector4( col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f );
GL.Fog( FogParameter.FogColor, colRGBA ); GL.Fog( FogParameter.FogColor, &colRGBA.X );
} }
public override void SetFogDensity( float value ) { public override void SetFogDensity( float value ) {

View File

@ -62,18 +62,20 @@ namespace ClassicalSharp {
/// <summary> Reads a string, then converts control characters into the /// <summary> Reads a string, then converts control characters into the
/// unicode values of their equivalent code page 437 graphical representations. </summary> /// unicode values of their equivalent code page 437 graphical representations. </summary>
public string ReadTextString() { public string ReadTextString() {
byte[] data = ReadBytes( 64 ); string value = GetTextString( buffer ).TrimEnd( '\0', ' ' ); // servers can use either null or spaces for padding.
return GetTextString( data ).TrimEnd( '\0', ' ' ); // servers can use either null or spaces for padding. Remove( 64 );
return value;
} }
public string ReadString() { public string ReadString() {
byte[] data = ReadBytes( 64 ); string value = GetAsciiString( buffer ).TrimEnd( '\0', ' ' );
return GetAsciiString( data ).TrimEnd( '\0', ' ' ); Remove( 64 );
return value;
} }
static char[] characters = new char[64];
static string GetAsciiString( byte[] data ) { static string GetAsciiString( byte[] data ) {
char[] characters = new char[data.Length]; for( int i = 0; i < 64; i++ ) {
for( int i = 0; i < data.Length; i++ ) {
byte code = data[i]; byte code = data[i];
characters[i] = code >= 0x80 ? '?' : (char)code; characters[i] = code >= 0x80 ? '?' : (char)code;
} }
@ -82,8 +84,7 @@ namespace ClassicalSharp {
static string GetTextString( byte[] data ) { static string GetTextString( byte[] data ) {
// code page 437 indices --> actual unicode characters // code page 437 indices --> actual unicode characters
char[] characters = new char[data.Length]; for( int i = 0; i < 64; i++ ) {
for( int i = 0; i < data.Length; i++ ) {
byte code = data[i]; byte code = data[i];
if( code < 0x20 ) { // general control characters if( code < 0x20 ) { // general control characters
characters[i] = controlCharReplacements[code]; characters[i] = controlCharReplacements[code];

View File

@ -5,7 +5,7 @@ namespace ClassicalSharp {
internal class FixedBufferStream : Stream { internal class FixedBufferStream : Stream {
private byte[] _buffer; public byte[] _buffer;
private int _position; private int _position;
private int _length; private int _length;

View File

@ -329,14 +329,12 @@ namespace ClassicalSharp {
case PacketId.LevelDataChunk: case PacketId.LevelDataChunk:
{ {
int usedLength = reader.ReadInt16(); int usedLength = reader.ReadInt16();
byte[] data = reader.ReadBytes( 1024 );
byte progress = reader.ReadUInt8();
Window.RaiseMapLoading( progress );
gzippedMap.Position = 0; gzippedMap.Position = 0;
gzippedMap.SetLength( usedLength ); gzippedMap.SetLength( usedLength );
gzippedMap.Write( data, 0, usedLength ); Buffer.BlockCopy( reader.buffer, 0, gzippedMap._buffer, 0, usedLength );
reader.Remove( 1024 );
gzippedMap.Position = 0; gzippedMap.Position = 0;
if( mapSizeIndex < 4 ) { if( mapSizeIndex < 4 ) {
mapSizeIndex += gzipStream.Read( mapSize, 0, 4 - mapSizeIndex ); mapSizeIndex += gzipStream.Read( mapSize, 0, 4 - mapSizeIndex );
} }
@ -348,6 +346,9 @@ namespace ClassicalSharp {
} }
mapIndex += gzipStream.Read( map, mapIndex, map.Length - mapIndex ); mapIndex += gzipStream.Read( map, mapIndex, map.Length - mapIndex );
} }
byte progress = reader.ReadUInt8();
Window.RaiseMapLoading( progress );
} break; } break;
case PacketId.LevelFinalise: case PacketId.LevelFinalise: