Finish support for 10 bit blocks

This commit is contained in:
UnknownShadow200 2018-03-08 10:43:31 +11:00
parent b37da6a576
commit b04ff7333c
6 changed files with 31 additions and 12 deletions

View File

@ -101,7 +101,7 @@ namespace ClassicalSharp {
public const int CpeCount = MaxCpeBlock + 1;
#if USE16_BIT
public const BlockID MaxDefinedBlock = 0xFFF;
public const BlockID MaxDefinedBlock = 0x3FF;
#else
public const BlockID MaxDefinedBlock = 0xFF;
#endif

View File

@ -100,7 +100,7 @@ namespace ClassicalSharp {
/// should be drawn with the neighbour 'other' present on the other side of the face. </summary>
public static bool IsFaceHidden(BlockID block, BlockID other, int tileSide) {
#if USE16_BIT
return (hidden[(block << 12) | other] & (1 << tileSide)) != 0;
return (hidden[(block << 10) | other] & (1 << tileSide)) != 0;
#else
return (hidden[(block << 8) | other] & (1 << tileSide)) != 0;
#endif

View File

@ -107,7 +107,7 @@ namespace ClassicalSharp {
BlockID DefaultMapping(int i) {
#if USE16_BIT
if ((i >= Block.CpeCount && i < 256) || i == Block.Air) return Block.Air;
if ((i >= Block.CpeCount) || i == Block.Air) return Block.Air;
#else
if (i >= Block.CpeCount || i == Block.Air) return Block.Air;
#endif

View File

@ -18,9 +18,13 @@ namespace ClassicalSharp.Physics {
public State(int x, int y, int z, BlockID block, float tSquared) {
X = x << 3; Y = y << 3; Z = z << 3;
X |= (block & 0x07);
Y |= (block & 0x38) >> 3;
Z |= (block & 0xC0) >> 6;
X |= (block & 0x007);
Y |= (block & 0x038) >> 3;
#if !USE16_BIT
Z |= (block & 0x0C0) >> 6;
#else
Z |= (block & 0x1C0) >> 6;
#endif
this.tSquared = tSquared;
}
}

View File

@ -203,7 +203,7 @@ namespace ClassicalSharp {
X = x; Y = y; Z = z;
fullBright = BlockInfo.FullBright[b];
#if USE16_BIT
int tileIdx = b << 12;
int tileIdx = b << 10;
#else
int tileIdx = b << 8;
#endif

View File

@ -120,6 +120,9 @@ namespace ClassicalSharp.Network.Protocols {
if (mapSizeIndex == 4) {
if (map == null) {
int size = mapSize[0] << 24 | mapSize[1] << 16 | mapSize[2] << 8 | mapSize[3];
#if USE16_BIT
if (reader.ExtendedBlocks) size *= 2;
#endif
map = new byte[size];
}
mapIndex += gzipStream.Read(map, mapIndex, map.Length - mapIndex);
@ -131,6 +134,14 @@ namespace ClassicalSharp.Network.Protocols {
game.WorldEvents.RaiseMapLoading(progress);
}
#if USE16_BIT
static ushort[] UInt8sToUInt16s(byte[] src) {
ushort[] dst = new ushort[src.Length / 2];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
return dst;
}
#endif
void HandleLevelFinalise() {
game.Gui.SetNewScreen(null);
game.Gui.activeScreen = prevScreen;
@ -147,7 +158,11 @@ namespace ClassicalSharp.Network.Protocols {
Utils.LogDebug("map loading took: " + loadingMs);
#if USE16_BIT
if (reader.ExtendedBlocks) {
game.World.SetNewMap(UInt8sToUInt16s(map), mapWidth, mapHeight, mapLength);
} else{
game.World.SetNewMap(Utils.UInt8sToUInt16s(map), mapWidth, mapHeight, mapLength);
}
#else
game.World.SetNewMap(map, mapWidth, mapHeight, mapLength);
#endif