From 1ceeeda4ba72bb112d7a5e08a8ab0fc2b0985ba7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 1 Apr 2015 06:27:13 +1100 Subject: [PATCH] Reduce array sizes in block info, make some things more consistent. --- Blocks/BlockInfo.Culling.cs | 10 +++++----- Blocks/BlockInfo.Optimised.cs | 15 +++++++-------- Blocks/BlockInfo.cs | 18 +++++++++--------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Blocks/BlockInfo.Culling.cs b/Blocks/BlockInfo.Culling.cs index bdce8e7fb..cbd921abc 100644 --- a/Blocks/BlockInfo.Culling.cs +++ b/Blocks/BlockInfo.Culling.cs @@ -4,11 +4,11 @@ namespace ClassicalSharp { public partial class BlockInfo { - bool[] hidden = new bool[70 * 70 * 6]; + bool[] hidden = new bool[blocksCount * blocksCount * 6]; void SetupCullingCache() { - for( byte tile = 1; tile <= 65; tile++ ) { - for( byte neighbour = 1; neighbour <= 65; neighbour++ ) { + for( byte tile = 1; tile < blocksCount; tile++ ) { + for( byte neighbour = 1; neighbour < blocksCount; neighbour++ ) { bool hidden = IsHidden( tile, neighbour ); if( hidden ) { SetHidden( tile, neighbour, TileSide.Left, true ); @@ -29,11 +29,11 @@ namespace ClassicalSharp { } void SetHidden( byte tile, byte block, int tileSide, bool value ) { - hidden[( tile * 70 + block ) * 6 + tileSide] = value; + hidden[( tile * blocksCount + block ) * 6 + tileSide] = value; } public bool IsFaceHidden( byte tile, byte block, int tileSide ) { - return hidden[( tile * 70 + block ) * 6 + tileSide]; + return hidden[( tile * blocksCount + block ) * 6 + tileSide]; } } } \ No newline at end of file diff --git a/Blocks/BlockInfo.Optimised.cs b/Blocks/BlockInfo.Optimised.cs index b75217f8a..8e20192c5 100644 --- a/Blocks/BlockInfo.Optimised.cs +++ b/Blocks/BlockInfo.Optimised.cs @@ -142,7 +142,7 @@ namespace ClassicalSharp { }; public static void MakeOptimisedTexture( FastBitmap atlas ) { - int size = atlas.Width / 16; + int tileSize = atlas.Width / 16; int srcIndex = 0, destIndex = 0; for( int y = 0; y < 6; y++ ) { @@ -150,16 +150,15 @@ namespace ClassicalSharp { for( int x = 0; x < 16; x++ ) { bool isUsed = ( flags & 1 << ( 15 - x ) ) != 0; if( isUsed && srcIndex != destIndex ) { - int srcX = x * size; - int srcY = y * size; - int destX = ( destIndex & 0x0F ) * size; - int destY = ( destIndex >> 4 ) * size; - MovePortion( srcX, srcY, destX, destY, atlas, size ); + int srcX = x * tileSize; + int srcY = y * tileSize; + int destX = ( destIndex & 0x0F ) * tileSize; + int destY = ( destIndex >> 4 ) * tileSize; + MovePortion( srcX, srcY, destX, destY, atlas, tileSize ); } srcIndex++; - destIndex++; - if( !isUsed ) destIndex--; + if( isUsed ) destIndex++; } } } diff --git a/Blocks/BlockInfo.cs b/Blocks/BlockInfo.cs index 1d1191c41..b002e9d24 100644 --- a/Blocks/BlockInfo.cs +++ b/Blocks/BlockInfo.cs @@ -10,14 +10,14 @@ namespace ClassicalSharp { bool[] isSprite = new bool[blocksCount]; bool[] isLiquid = new bool[blocksCount]; float[] heights = new float[blocksCount]; - bool[] blocksLight = new bool[blocksCount]; - const int blocksCount = 256; + bool[] blocksLight = new bool[blocksCount]; + const byte blocksCount = (byte)Block.StoneBrick + 1; public void Init() { - for( int i = 1; i < blocksCount; i++ ) { - heights[i] = 1; - blocksLight[i] = true; - isOpaque[i] = true; + for( int tile = 1; tile < blocksCount; tile++ ) { + heights[tile] = 1f; + blocksLight[tile] = true; + isOpaque[tile] = true; } SetupOptimTextures(); @@ -43,9 +43,9 @@ namespace ClassicalSharp { } public void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete ) { - for( int i = (int)Block.Stone; i <= (int)Block.Obsidian; i++ ) { - canPlace[i] = true; - canDelete[i] = true; + for( int tile = (int)Block.Stone; tile <= (int)Block.Obsidian; tile++ ) { + canPlace[tile] = true; + canDelete[tile] = true; } canPlace[(int)Block.Grass] = false; canPlace[(int)Block.Lava] = false;