mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -04:00
MayHaveCustomBlocks property -> MightHaveCustomBlocks function
since really only trivial code should be in a getter, and MightHaveCustomBlocks can potentially be quite expensive
This commit is contained in:
parent
485be4a3af
commit
67d2ecba74
@ -341,7 +341,7 @@ namespace MCGalaxy {
|
|||||||
if (pl.hasBlockDefs) continue;
|
if (pl.hasBlockDefs) continue;
|
||||||
|
|
||||||
// if custom block is replacing core block, need to always reload for fallback
|
// if custom block is replacing core block, need to always reload for fallback
|
||||||
if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue;
|
if (block >= Block.CpeCount && !pl.level.MightHaveCustomBlocks()) continue;
|
||||||
PlayerActions.ReloadMap(pl);
|
PlayerActions.ReloadMap(pl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,16 +33,15 @@ namespace MCGalaxy {
|
|||||||
public byte[][] CustomBlocks;
|
public byte[][] CustomBlocks;
|
||||||
public int ChunksX, ChunksY, ChunksZ;
|
public int ChunksX, ChunksY, ChunksZ;
|
||||||
|
|
||||||
public bool MayHaveCustomBlocks {
|
/// <summary> Relatively quick guess at whether this map might use custom blocks. </summary>
|
||||||
get {
|
public bool MightHaveCustomBlocks() {
|
||||||
byte[][] customBlocks = CustomBlocks;
|
byte[][] customBlocks = CustomBlocks;
|
||||||
if (customBlocks == null) return false;
|
if (customBlocks == null) return false;
|
||||||
|
|
||||||
for (int i = 0; i < customBlocks.Length; i++) {
|
for (int i = 0; i < customBlocks.Length; i++) {
|
||||||
if (customBlocks[i] != null) return true;
|
if (customBlocks[i] != null) return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -390,7 +389,7 @@ namespace MCGalaxy {
|
|||||||
AddCheck(b, false, data);
|
AddCheck(b, false, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save bandwidth sending identical looking blocks, like air/op_air changes.
|
// Save bandwidth not sending identical looking blocks, like air/op_air changes.
|
||||||
return !Block.VisuallyEquals(old, block);
|
return !Block.VisuallyEquals(old, block);
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
@ -251,10 +251,10 @@ namespace MCGalaxy {
|
|||||||
using (LevelChunkStream dst = new LevelChunkStream(this))
|
using (LevelChunkStream dst = new LevelChunkStream(this))
|
||||||
using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst))
|
using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst))
|
||||||
{
|
{
|
||||||
if (!level.MayHaveCustomBlocks) {
|
if (level.MightHaveCustomBlocks()) {
|
||||||
LevelChunkStream.CompressMapSimple(this, stream, dst);
|
|
||||||
} else {
|
|
||||||
LevelChunkStream.CompressMap(this, stream, dst);
|
LevelChunkStream.CompressMap(this, stream, dst);
|
||||||
|
} else {
|
||||||
|
LevelChunkStream.CompressMapSimple(this, stream, dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,14 +84,16 @@ namespace MCGalaxy.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static Stream CompressMapHeader(Player player, int volume, LevelChunkStream dst) {
|
public static Stream CompressMapHeader(Player p, int volume, LevelChunkStream dst) {
|
||||||
Stream stream = null;
|
Stream stream = null;
|
||||||
if (player.Supports(CpeExt.FastMap)) {
|
if (p.Supports(CpeExt.FastMap)) {
|
||||||
stream = new DeflateStream(dst, CompressionMode.Compress, true);
|
stream = new DeflateStream(dst, CompressionMode.Compress, true);
|
||||||
} else {
|
} else {
|
||||||
stream = new GZipStream(dst, CompressionMode.Compress, true);
|
stream = new GZipStream(dst, CompressionMode.Compress, true);
|
||||||
byte[] buffer = new byte[4]; NetUtils.WriteI32(volume, buffer, 0);
|
byte[] buffer = new byte[4];
|
||||||
stream.Write(buffer, 0, sizeof(int));
|
|
||||||
|
NetUtils.WriteI32(volume, buffer, 0);
|
||||||
|
stream.Write(buffer, 0, 4);
|
||||||
}
|
}
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
@ -117,7 +119,7 @@ namespace MCGalaxy.Network {
|
|||||||
bIndex++;
|
bIndex++;
|
||||||
|
|
||||||
if (bIndex == bufferSize) {
|
if (bIndex == bufferSize) {
|
||||||
// '0' to indicate classic blocks
|
// '0' to indicate this chunk has lower 8 bits of block ids
|
||||||
dst.chunkValue = p.hasExtBlocks ? (byte)0 : (byte)(i * progScale);
|
dst.chunkValue = p.hasExtBlocks ? (byte)0 : (byte)(i * progScale);
|
||||||
stream.Write(buffer, 0, bufferSize); bIndex = 0;
|
stream.Write(buffer, 0, bufferSize); bIndex = 0;
|
||||||
}
|
}
|
||||||
@ -132,7 +134,7 @@ namespace MCGalaxy.Network {
|
|||||||
|
|
||||||
// Store on stack instead of performing function call for every block in map
|
// Store on stack instead of performing function call for every block in map
|
||||||
byte* conv = stackalloc byte[Block.ExtendedCount];
|
byte* conv = stackalloc byte[Block.ExtendedCount];
|
||||||
byte* convExt = conv + Block.Count;
|
byte* convExt = conv + Block.Count;
|
||||||
#if TEN_BIT_BLOCKS
|
#if TEN_BIT_BLOCKS
|
||||||
byte* convExt2 = conv + Block.Count * 2;
|
byte* convExt2 = conv + Block.Count * 2;
|
||||||
byte* convExt3 = conv + Block.Count * 3;
|
byte* convExt3 = conv + Block.Count * 3;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user