mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
make C client deflating 10-25% faster on average
This commit is contained in:
parent
7c765abf29
commit
3c420045d4
@ -189,12 +189,10 @@ namespace ClassicalSharp {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Returns whenever the given character is a valid colour code. </summary>
|
||||
public static bool ValidColCode(string text, int i) {
|
||||
return i < text.Length && ValidColCode(text[i]);
|
||||
}
|
||||
|
||||
/// <summary> Returns whenever the given character is a valid colour code. </summary>
|
||||
public static bool ValidColCode(char c) {
|
||||
if (c >= '~' && c <= '~') return Cols[c].A > 0;
|
||||
return Cols[Utils.UnicodeToCP437(c)].A > 0;
|
||||
@ -212,8 +210,6 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
#if !LAUNCHER
|
||||
/// <summary> Returns the last valid colour code in the given input,
|
||||
/// or \0 if no valid colour code was found. </summary>
|
||||
public static char LastCol(string text, int start) {
|
||||
if (start >= text.Length)
|
||||
start = text.Length - 1;
|
||||
|
@ -23,11 +23,7 @@ namespace ClassicalSharp {
|
||||
void IGameComponent.OnNewMap(Game game) { }
|
||||
void IGameComponent.OnNewMapLoaded(Game game) { }
|
||||
|
||||
/// <summary> List of chat messages received from the server and added by client commands. </summary>
|
||||
/// <remarks> index 0 is the oldest chat message, last index is newest. </remarks>
|
||||
public List<ChatLine> Log = new List<ChatLine>();
|
||||
|
||||
/// <summary> List of chat messages sent by the user to the server. </summary>
|
||||
public List<string> InputLog = new List<string>();
|
||||
|
||||
public void Send(string text) {
|
||||
|
@ -16,20 +16,14 @@ namespace ClassicalSharp.Map {
|
||||
public int Width, Height, Length, MaxX, MaxY, MaxZ, OneY;
|
||||
public bool HasBlocks;
|
||||
|
||||
/// <summary> Contains the environment metadata for this world. </summary>
|
||||
public WorldEnv Env;
|
||||
|
||||
/// <summary> Unique uuid/guid of this particular world. </summary>
|
||||
public Guid Uuid;
|
||||
|
||||
/// <summary> Current terrain.png or texture pack url of this map. </summary>
|
||||
public string TextureUrl = null;
|
||||
|
||||
public World(Game game) {
|
||||
Env = new WorldEnv(game);
|
||||
}
|
||||
|
||||
/// <summary> Resets all of the properties to their defaults and raises the 'OnNewMap' event. </summary>
|
||||
public void Reset() {
|
||||
Env.Reset();
|
||||
Width = 0; Height = 0; Length = 0;
|
||||
@ -42,7 +36,6 @@ namespace ClassicalSharp.Map {
|
||||
HasBlocks = false;
|
||||
}
|
||||
|
||||
/// <summary> Updates the underlying block array, and dimensions of this map. </summary>
|
||||
public void SetNewMap(BlockRaw[] blocksRaw, int width, int height, int length) {
|
||||
Width = width; MaxX = width - 1;
|
||||
Height = height; MaxY = height - 1;
|
||||
|
@ -10,76 +10,44 @@ namespace ClassicalSharp.Map {
|
||||
/// <summary> Contains the environment metadata for a world. </summary>
|
||||
public sealed class WorldEnv {
|
||||
|
||||
/// <summary> Colour of the sky located behind/above clouds. </summary>
|
||||
public FastColour SkyCol = DefaultSkyCol;
|
||||
public static readonly FastColour DefaultSkyCol = new FastColour(0x99, 0xCC, 0xFF);
|
||||
public const string DefaultSkyColHex = "99CCFF";
|
||||
|
||||
/// <summary> Colour applied to the fog/horizon looking out horizontally.
|
||||
/// Note the true horizon colour is a blend of this and sky colour. </summary>
|
||||
public FastColour FogCol = DefaultFogCol;
|
||||
public static readonly FastColour DefaultFogCol = new FastColour(0xFF, 0xFF, 0xFF);
|
||||
public const string DefaultFogColHex = "FFFFFF";
|
||||
|
||||
/// <summary> Colour applied to the clouds. </summary>
|
||||
public FastColour CloudsCol = DefaultCloudsCol;
|
||||
public static readonly FastColour DefaultCloudsCol = new FastColour(0xFF, 0xFF, 0xFF);
|
||||
public const string DefaultCloudsColHex = "FFFFFF";
|
||||
|
||||
/// <summary> Height of the clouds in world space. </summary>
|
||||
public int CloudHeight;
|
||||
|
||||
/// <summary> Modifier of how fast clouds travel across the world, defaults to 1. </summary>
|
||||
public float CloudsSpeed = 1;
|
||||
|
||||
/// <summary> Modifier of how fast rain/snow falls, defaults to 1. </summary>
|
||||
public float WeatherSpeed = 1;
|
||||
|
||||
/// <summary> Modifier of how fast rain/snow fades, defaults to 1. </summary>
|
||||
public float WeatherFade = 1;
|
||||
|
||||
/// <summary> Colour applied to blocks located in direct sunlight. </summary>
|
||||
public FastColour Sunlight;
|
||||
public int Sun, SunXSide, SunZSide, SunYBottom;
|
||||
public static readonly FastColour DefaultSunlight = new FastColour(0xFF, 0xFF, 0xFF);
|
||||
public const string DefaultSunlightHex = "FFFFFF";
|
||||
|
||||
/// <summary> Colour applied to blocks located in shadow / hidden from direct sunlight. </summary>
|
||||
public FastColour Shadowlight;
|
||||
public int Shadow, ShadowXSide, ShadowZSide, ShadowYBottom;
|
||||
public static readonly FastColour DefaultShadowlight = new FastColour(0x9B, 0x9B, 0x9B);
|
||||
public const string DefaultShadowlightHex = "9B9B9B";
|
||||
|
||||
/// <summary> Current weather for this particular map. </summary>
|
||||
public Weather Weather = Weather.Sunny;
|
||||
|
||||
/// <summary> Block that surrounds map the map horizontally (default water) </summary>
|
||||
public BlockID EdgeBlock = Block.StillWater;
|
||||
|
||||
/// <summary> Height of the map edge in world space. </summary>
|
||||
public int EdgeHeight;
|
||||
|
||||
/// <summary> Block that surrounds the map that fills the bottom of the map horizontally,
|
||||
/// fills part of the vertical sides of the map, and also surrounds map the map horizontally. (default bedrock) </summary>
|
||||
public BlockID SidesBlock = Block.Bedrock;
|
||||
|
||||
/// <summary> Maximum height of the various parts of the map sides, in world space. </summary>
|
||||
public int SidesHeight { get { return EdgeHeight + SidesOffset; } }
|
||||
|
||||
/// <summary> Offset of height of map sides from height of map edge. </summary>
|
||||
public int SidesOffset = -2;
|
||||
|
||||
/// <summary> Whether exponential fog mode is used by default. </summary>
|
||||
public bool ExpFog;
|
||||
|
||||
/// <summary> Horizontal skybox rotation speed. </summary>
|
||||
public float SkyboxHorSpeed;
|
||||
|
||||
/// <summary> Vertical skybox rotation speed. </summary>
|
||||
public float SkyboxVerSpeed;
|
||||
|
||||
/// <summary> Whether clouds still render, even with skybox. </summary>
|
||||
public bool SkyboxClouds;
|
||||
public float SkyboxHorSpeed, SkyboxVerSpeed;
|
||||
public bool ExpFog, SkyboxClouds;
|
||||
|
||||
Game game;
|
||||
public WorldEnv(Game game) {
|
||||
|
@ -61,8 +61,7 @@ namespace Launcher.Web {
|
||||
public string Token;
|
||||
|
||||
protected override void Handle(Request req) {
|
||||
JsonContext ctx = new JsonContext(); ctx.Val = (string)req.Data;
|
||||
JsonObject data = (JsonObject)Json.ParseStream(ctx);
|
||||
JsonObject data = ParseJson(req);
|
||||
Token = (string)data["token"];
|
||||
}
|
||||
}
|
||||
|
@ -437,10 +437,10 @@ namespace OpenTK.Platform.X11 {
|
||||
IntPtr prop_type, num_items, bytes_after, data = IntPtr.Zero;
|
||||
int prop_format;
|
||||
|
||||
API.XGetWindowProperty (window.Display, window.WinHandle, xa_data_sel, IntPtr.Zero, new IntPtr (1024), false, IntPtr.Zero,
|
||||
out prop_type, out prop_format, out num_items, out bytes_after, ref data);
|
||||
API.XGetWindowProperty(window.Display, window.WinHandle, xa_data_sel, IntPtr.Zero, new IntPtr (1024), false, IntPtr.Zero,
|
||||
out prop_type, out prop_format, out num_items, out bytes_after, ref data);
|
||||
|
||||
API.XDeleteProperty (window.Display, window.WinHandle, xa_data_sel);
|
||||
API.XDeleteProperty(window.Display, window.WinHandle, xa_data_sel);
|
||||
if (num_items == IntPtr.Zero) break;
|
||||
|
||||
if (prop_type == xa_utf8_string) {
|
||||
@ -468,7 +468,7 @@ namespace OpenTK.Platform.X11 {
|
||||
if (e.SelectionRequestEvent.selection == xa_clipboard && e.SelectionRequestEvent.target == xa_utf8_string && clipboard_copy_text != null) {
|
||||
reply.SelectionEvent.property = GetSelectionProperty(ref e);
|
||||
|
||||
byte[] utf8_data = Encoding.UTF8.GetBytes (clipboard_copy_text);
|
||||
byte[] utf8_data = Encoding.UTF8.GetBytes(clipboard_copy_text);
|
||||
fixed (byte* utf8_ptr = utf8_data) {
|
||||
API.XChangeProperty(window.Display, reply.SelectionEvent.requestor, reply.SelectionEvent.property, xa_utf8_string, 8,
|
||||
PropertyMode.Replace, (IntPtr)utf8_ptr, utf8_data.Length);
|
||||
|
@ -282,18 +282,24 @@ static Int32 Huffman_Decode(InflateState* state, HuffmanTable* table) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static Int32 Huffman_Unsafe_Decode(InflateState* state, HuffmanTable* table) {
|
||||
Inflate_UNSAFE_EnsureBits(state, INFLATE_MAX_BITS);
|
||||
UInt32 codeword = Inflate_PeekBits(state, INFLATE_FAST_BITS);
|
||||
Int32 packed = table->Fast[codeword];
|
||||
if (packed >= 0) {
|
||||
Int32 bits = packed >> INFLATE_FAST_BITS;
|
||||
Inflate_ConsumeBits(state, bits);
|
||||
return packed & 0x1FF;
|
||||
}
|
||||
#define Huffman_Unsafe_Decode(state, table, result) \
|
||||
{\
|
||||
Inflate_UNSAFE_EnsureBits(state, INFLATE_MAX_BITS);\
|
||||
Int32 packed = table.Fast[Inflate_PeekBits(state, INFLATE_FAST_BITS)];\
|
||||
if (packed >= 0) {\
|
||||
Int32 consumedBits = packed >> INFLATE_FAST_BITS;\
|
||||
Inflate_ConsumeBits(state, consumedBits);\
|
||||
result = packed & 0x1FF;\
|
||||
} else {\
|
||||
result = Huffman_Unsafe_Decode_Slow(state, &table);\
|
||||
}\
|
||||
}
|
||||
|
||||
static Int32 Huffman_Unsafe_Decode_Slow(InflateState* state, HuffmanTable* table) {
|
||||
UInt32 codeword = Inflate_PeekBits(state, INFLATE_FAST_BITS);
|
||||
/* Slow, bit by bit lookup. Need to reverse order for huffman. */
|
||||
codeword = Huffman_ReverseBits(codeword, INFLATE_FAST_BITS);
|
||||
|
||||
UInt32 i, j;
|
||||
for (i = INFLATE_FAST_BITS + 1, j = INFLATE_FAST_BITS; i < INFLATE_MAX_BITS; i++, j++) {
|
||||
codeword = (codeword << 1) | ((state->Bits >> j) & 1);
|
||||
@ -358,9 +364,8 @@ static void Inflate_InflateFast(InflateState* state) {
|
||||
|
||||
#define INFLATE_FAST_COPY_MAX (INFLATE_WINDOW_SIZE - INFLATE_FASTINF_OUT)
|
||||
while (state->AvailOut >= INFLATE_FASTINF_OUT && state->AvailIn >= INFLATE_FASTINF_IN && copyLen < INFLATE_FAST_COPY_MAX) {
|
||||
UInt32 lit = Huffman_Unsafe_Decode(state, &state->LitsTable);
|
||||
UInt32 lit; Huffman_Unsafe_Decode(state, state->LitsTable, lit);
|
||||
if (lit <= 256) {
|
||||
//Platform_Log1("lit %i", &lit);
|
||||
if (lit < 256) {
|
||||
window[curIdx] = (UInt8)lit;
|
||||
state->AvailOut--; copyLen++;
|
||||
@ -375,13 +380,11 @@ static void Inflate_InflateFast(InflateState* state) {
|
||||
Inflate_UNSAFE_EnsureBits(state, bits);
|
||||
UInt32 len = len_base[lenIdx] + Inflate_ReadBits(state, bits);
|
||||
|
||||
UInt32 distIdx = Huffman_Unsafe_Decode(state, &state->DistsTable);
|
||||
UInt32 distIdx; Huffman_Unsafe_Decode(state, state->DistsTable, distIdx);
|
||||
bits = dist_bits[distIdx];
|
||||
Inflate_UNSAFE_EnsureBits(state, bits);
|
||||
UInt32 dist = dist_base[distIdx] + Inflate_ReadBits(state, bits);
|
||||
|
||||
//Platform_Log2("len %i, dist %i", &len, &dist);
|
||||
|
||||
UInt32 startIdx = (curIdx - dist) & INFLATE_WINDOW_MASK;
|
||||
UInt32 i;
|
||||
if (curIdx >= startIdx && (curIdx + len) < INFLATE_WINDOW_SIZE) {
|
||||
@ -587,7 +590,6 @@ void Inflate_Process(InflateState* state) {
|
||||
Int32 lit = Huffman_Decode(state, &state->LitsTable);
|
||||
if (lit < 256) {
|
||||
if (lit == -1) return;
|
||||
//Platform_Log1("lit %i", &lit);
|
||||
*state->Output = (UInt8)lit;
|
||||
state->Window[state->WindowIndex] = (UInt8)lit;
|
||||
state->Output++; state->AvailOut--;
|
||||
@ -622,8 +624,6 @@ void Inflate_Process(InflateState* state) {
|
||||
Inflate_EnsureBits(state, bits);
|
||||
state->TmpDist = dist_base[distIdx] + Inflate_ReadBits(state, bits);
|
||||
state->State = INFLATE_STATE_COMPRESSED_DATA;
|
||||
|
||||
//Platform_Log2("len %i, dist %i", &state->TmpLit, &state->TmpDist);
|
||||
}
|
||||
|
||||
case INFLATE_STATE_COMPRESSED_DATA: {
|
||||
@ -732,8 +732,6 @@ static void Deflate_Lit(DeflateState* state, Int32 lit) {
|
||||
if (lit <= 143) { Deflate_PushHuff(state, lit + 48, 8); }
|
||||
else { Deflate_PushHuff(state, lit + 256, 9); }
|
||||
Deflate_FlushBits(state);
|
||||
|
||||
//Platform_Log1("lit %i", &lit);
|
||||
}
|
||||
|
||||
static void Deflate_LenDist(DeflateState* state, Int32 len, Int32 dist) {
|
||||
@ -755,8 +753,6 @@ static void Deflate_LenDist(DeflateState* state, Int32 len, Int32 dist) {
|
||||
if (dist_bits[j]) { Deflate_PushBits(state, dist - dist_base[j], dist_bits[j]); }
|
||||
Deflate_FlushBits(state);
|
||||
|
||||
//Platform_Log2("len %i, dist %i", &len, &dist);
|
||||
|
||||
len_base[29] = 0;
|
||||
dist_base[30] = 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user