Reduce array sizes in block info, make some things more consistent.

This commit is contained in:
UnknownShadow200 2015-04-01 06:27:13 +11:00
parent 168e685867
commit 1ceeeda4ba
3 changed files with 21 additions and 22 deletions

View File

@ -4,11 +4,11 @@ namespace ClassicalSharp {
public partial class BlockInfo { public partial class BlockInfo {
bool[] hidden = new bool[70 * 70 * 6]; bool[] hidden = new bool[blocksCount * blocksCount * 6];
void SetupCullingCache() { void SetupCullingCache() {
for( byte tile = 1; tile <= 65; tile++ ) { for( byte tile = 1; tile < blocksCount; tile++ ) {
for( byte neighbour = 1; neighbour <= 65; neighbour++ ) { for( byte neighbour = 1; neighbour < blocksCount; neighbour++ ) {
bool hidden = IsHidden( tile, neighbour ); bool hidden = IsHidden( tile, neighbour );
if( hidden ) { if( hidden ) {
SetHidden( tile, neighbour, TileSide.Left, true ); SetHidden( tile, neighbour, TileSide.Left, true );
@ -29,11 +29,11 @@ namespace ClassicalSharp {
} }
void SetHidden( byte tile, byte block, int tileSide, bool value ) { 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 ) { public bool IsFaceHidden( byte tile, byte block, int tileSide ) {
return hidden[( tile * 70 + block ) * 6 + tileSide]; return hidden[( tile * blocksCount + block ) * 6 + tileSide];
} }
} }
} }

View File

@ -142,7 +142,7 @@ namespace ClassicalSharp {
}; };
public static void MakeOptimisedTexture( FastBitmap atlas ) { public static void MakeOptimisedTexture( FastBitmap atlas ) {
int size = atlas.Width / 16; int tileSize = atlas.Width / 16;
int srcIndex = 0, destIndex = 0; int srcIndex = 0, destIndex = 0;
for( int y = 0; y < 6; y++ ) { for( int y = 0; y < 6; y++ ) {
@ -150,16 +150,15 @@ namespace ClassicalSharp {
for( int x = 0; x < 16; x++ ) { for( int x = 0; x < 16; x++ ) {
bool isUsed = ( flags & 1 << ( 15 - x ) ) != 0; bool isUsed = ( flags & 1 << ( 15 - x ) ) != 0;
if( isUsed && srcIndex != destIndex ) { if( isUsed && srcIndex != destIndex ) {
int srcX = x * size; int srcX = x * tileSize;
int srcY = y * size; int srcY = y * tileSize;
int destX = ( destIndex & 0x0F ) * size; int destX = ( destIndex & 0x0F ) * tileSize;
int destY = ( destIndex >> 4 ) * size; int destY = ( destIndex >> 4 ) * tileSize;
MovePortion( srcX, srcY, destX, destY, atlas, size ); MovePortion( srcX, srcY, destX, destY, atlas, tileSize );
} }
srcIndex++; srcIndex++;
destIndex++; if( isUsed ) destIndex++;
if( !isUsed ) destIndex--;
} }
} }
} }

View File

@ -10,14 +10,14 @@ namespace ClassicalSharp {
bool[] isSprite = new bool[blocksCount]; bool[] isSprite = new bool[blocksCount];
bool[] isLiquid = new bool[blocksCount]; bool[] isLiquid = new bool[blocksCount];
float[] heights = new float[blocksCount]; float[] heights = new float[blocksCount];
bool[] blocksLight = new bool[blocksCount]; bool[] blocksLight = new bool[blocksCount];
const int blocksCount = 256; const byte blocksCount = (byte)Block.StoneBrick + 1;
public void Init() { public void Init() {
for( int i = 1; i < blocksCount; i++ ) { for( int tile = 1; tile < blocksCount; tile++ ) {
heights[i] = 1; heights[tile] = 1f;
blocksLight[i] = true; blocksLight[tile] = true;
isOpaque[i] = true; isOpaque[tile] = true;
} }
SetupOptimTextures(); SetupOptimTextures();
@ -43,9 +43,9 @@ namespace ClassicalSharp {
} }
public void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete ) { public void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete ) {
for( int i = (int)Block.Stone; i <= (int)Block.Obsidian; i++ ) { for( int tile = (int)Block.Stone; tile <= (int)Block.Obsidian; tile++ ) {
canPlace[i] = true; canPlace[tile] = true;
canDelete[i] = true; canDelete[tile] = true;
} }
canPlace[(int)Block.Grass] = false; canPlace[(int)Block.Grass] = false;
canPlace[(int)Block.Lava] = false; canPlace[(int)Block.Lava] = false;