Reorganise BlockInfo, more work on BlockDefinitions.

This commit is contained in:
UnknownShadow200 2015-09-22 16:48:04 +10:00
parent 7271e02f6f
commit dde58e8b1d
25 changed files with 149 additions and 218 deletions

View File

@ -102,7 +102,7 @@ namespace ClassicalSharp {
if( block == Block.TNT ) { if( block == Block.TNT ) {
buffer.Append( ref ptr2, "TNT" ); buffer.Append( ref ptr2, "TNT" );
} else { } else {
string value = game.BlockInfo.GetName( (byte)block ); string value = game.BlockInfo.Name[(byte)block];
if( (byte)block < BlockInfo.CpeBlocksCount ) { if( (byte)block < BlockInfo.CpeBlocksCount ) {
SplitUppercase( value, ref ptr2 ); SplitUppercase( value, ref ptr2 );
} else { } else {
@ -175,7 +175,7 @@ namespace ClassicalSharp {
int texId = game.BlockInfo.GetTextureLoc( (byte)block, TileSide.Left ); int texId = game.BlockInfo.GetTextureLoc( (byte)block, TileSide.Left );
TextureRectangle rec = game.TerrainAtlas.GetTexRec( texId ); TextureRectangle rec = game.TerrainAtlas.GetTexRec( texId );
int verSize = blockSize; int verSize = blockSize;
float height = game.BlockInfo.BlockHeight( (byte)block ); float height = game.BlockInfo.Height[(byte)block];
int blockY = y; int blockY = y;
if( height != 1 ) { if( height != 1 ) {
rec.V1 = rec.V1 + TerrainAtlas2D.invElementSize * height; rec.V1 = rec.V1 + TerrainAtlas2D.invElementSize * height;

View File

@ -80,7 +80,7 @@ namespace ClassicalSharp {
TextureRectangle rec = game.TerrainAtlas.GetTexRec( texId ); TextureRectangle rec = game.TerrainAtlas.GetTexRec( texId );
int verSize = blockSize; int verSize = blockSize;
float height = game.BlockInfo.BlockHeight( (byte)block ); float height = game.BlockInfo.Height[(byte)block];
int blockY = y; int blockY = y;
if( height != 1 ) { if( height != 1 ) {
rec.V1 = rec.V1 + TerrainAtlas2D.invElementSize * height; rec.V1 = rec.V1 + TerrainAtlas2D.invElementSize * height;

View File

@ -16,8 +16,8 @@ namespace ClassicalSharp {
SetHidden( tile, neighbour, TileSide.Right, true ); SetHidden( tile, neighbour, TileSide.Right, true );
SetHidden( tile, neighbour, TileSide.Front, true ); SetHidden( tile, neighbour, TileSide.Front, true );
SetHidden( tile, neighbour, TileSide.Back, true ); SetHidden( tile, neighbour, TileSide.Back, true );
SetHidden( tile, neighbour, TileSide.Top, BlockHeight( tile ) == 1 ); SetHidden( tile, neighbour, TileSide.Top, Height[tile] == 1 );
SetHidden( tile, neighbour, TileSide.Bottom, BlockHeight( neighbour ) == 1 ); SetHidden( tile, neighbour, TileSide.Bottom, Height[neighbour] == 1 );
} }
} }
} }
@ -25,8 +25,8 @@ namespace ClassicalSharp {
bool IsHidden( byte tile, byte block ) { bool IsHidden( byte tile, byte block ) {
return return
( ( tile == block || ( IsOpaque( block ) && !IsLiquid( block ) ) ) && !IsSprite( tile ) ) || ((tile == block || (IsOpaque[block] && !IsLiquid[block])) && !IsSprite[tile]) ||
( IsLiquid( tile ) && block == (byte)Block.Ice ); (IsLiquid[tile] && block == (byte)Block.Ice);
} }
void SetHidden( byte tile, byte block, int tileSide, bool value ) { void SetHidden( byte tile, byte block, int tileSide, bool value ) {

View File

@ -5,17 +5,38 @@ namespace ClassicalSharp {
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary> /// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
public partial class BlockInfo { public partial class BlockInfo {
internal bool[] isTransparent = new bool[BlocksCount]; /// <summary> Gets whether the given block id is transparent/fully see through. </summary>
internal bool[] isTranslucent = new bool[BlocksCount]; /// <remarks> Alpha values are treated as either 'fully see through' or 'fully solid'. </remarks>
internal bool[] isOpaque = new bool[BlocksCount]; public bool[] IsTransparent = new bool[BlocksCount];
internal bool[] isSprite = new bool[BlocksCount];
internal bool[] isLiquid = new bool[BlocksCount]; /// <summary> Gets whether the given block id is translucent/partially see through. </summary>
internal float[] heights = new float[BlocksCount]; /// <remarks>Colour values are blended into both the transparent and opaque blocks behind them. </remarks>
internal bool[] blocksLight = new bool[BlocksCount]; public bool[] IsTranslucent = new bool[BlocksCount];
internal bool[] emitsLight = new bool[BlocksCount];
internal string[] names = new string[BlocksCount]; /// <summary> Gets whether the given block id is opaque/not partially see through. </summary>
internal FastColour[] fogColours = new FastColour[BlocksCount]; public bool[] IsOpaque = new bool[BlocksCount];
internal float[] fogDensities = new float[BlocksCount];
/// <summary> Gets whether the given block id is a sprite. (e.g. flowers, saplings, fire) </summary>
public bool[] IsSprite = new bool[BlocksCount];
/// <summary> Gets whether the given block id is a liquid. (e.g. water and lava) </summary>
public bool[] IsLiquid = new bool[BlocksCount];
/// <summary> Gets the block height of the given block id. </summary>
public float[] Height = new float[BlocksCount];
/// <summary> Gets whether the given block blocks sunlight. </summary>
public bool[] BlocksLight = new bool[BlocksCount];
public bool[] EmitsLight = new bool[BlocksCount];
public string[] Name = new string[BlocksCount];
public FastColour[] FogColour = new FastColour[BlocksCount];
public float[] FogDensity = new float[BlocksCount];
public BlockCollideType[] CollideType = new BlockCollideType[BlocksCount];
public const byte MaxDefinedCpeBlock = (byte)Block.StoneBrick; public const byte MaxDefinedCpeBlock = (byte)Block.StoneBrick;
public const int CpeBlocksCount = MaxDefinedCpeBlock + 1; public const int CpeBlocksCount = MaxDefinedCpeBlock + 1;
@ -24,26 +45,27 @@ namespace ClassicalSharp {
public void Init() { public void Init() {
for( int tile = 1; tile < BlocksCount; tile++ ) { for( int tile = 1; tile < BlocksCount; tile++ ) {
heights[tile] = 1f; Height[tile] = 1f;
blocksLight[tile] = true; BlocksLight[tile] = true;
isOpaque[tile] = true; IsOpaque[tile] = true;
CollideType[tile] = BlockCollideType.Solid;
} }
for( int i = 0; i < CpeBlocksCount; i++ ) { for( int i = 0; i < CpeBlocksCount; i++ ) {
names[i] = Enum.GetName( typeof( Block ), (byte)i ); Name[i] = Enum.GetName( typeof( Block ), (byte)i );
} }
for( int i = CpeBlocksCount; i < BlocksCount; i++ ) { for( int i = CpeBlocksCount; i < BlocksCount; i++ ) {
names[i] = "Invalid"; Name[i] = "Invalid";
} }
fogDensities[(byte)Block.StillWater] = 0.1f; FogDensity[(byte)Block.StillWater] = 0.1f;
fogColours[(byte)Block.StillWater] = new FastColour( 5, 5, 51 ); FogColour[(byte)Block.StillWater] = new FastColour( 5, 5, 51 );
fogDensities[(byte)Block.Water] = 0.1f; FogDensity[(byte)Block.Water] = 0.1f;
fogColours[(byte)Block.Water] = new FastColour( 5, 5, 51 ); FogColour[(byte)Block.Water] = new FastColour( 5, 5, 51 );
fogDensities[(byte)Block.StillLava] = 2f; FogDensity[(byte)Block.StillLava] = 2f;
fogColours[(byte)Block.StillLava] = new FastColour( 153, 25, 0 ); FogColour[(byte)Block.StillLava] = new FastColour( 153, 25, 0 );
fogDensities[(byte)Block.Lava] = 2f; FogDensity[(byte)Block.Lava] = 2f;
fogColours[(byte)Block.Lava] = new FastColour( 153, 25, 0 ); FogColour[(byte)Block.Lava] = new FastColour( 153, 25, 0 );
CollideType[(byte)Block.Snow] = BlockCollideType.WalkThrough;
SetupTextures(); SetupTextures();
SetBlockHeight( Block.Slab, 8/16f ); SetBlockHeight( Block.Slab, 8/16f );
@ -85,111 +107,62 @@ namespace ClassicalSharp {
} }
void MarkTransparent( Block id, bool blocks ) { void MarkTransparent( Block id, bool blocks ) {
isTransparent[(int)id] = true; IsTransparent[(int)id] = true;
blocksLight[(int)id] = blocks; BlocksLight[(int)id] = blocks;
isOpaque[(int)id] = false; IsOpaque[(int)id] = false;
} }
void MarkSprite( Block id ) { void MarkSprite( Block id ) {
isSprite[(int)id] = true; IsSprite[(int)id] = true;
isTransparent[(int)id] = true; IsTransparent[(int)id] = true;
blocksLight[(int)id] = false; BlocksLight[(int)id] = false;
isOpaque[(int)id] = false; IsOpaque[(int)id] = false;
CollideType[(int)id] = BlockCollideType.WalkThrough;
} }
void MarkTranslucent( Block id ) { void MarkTranslucent( Block id ) {
isTranslucent[(int)id] = true; IsTranslucent[(int)id] = true;
isOpaque[(int)id] = false; IsOpaque[(int)id] = false;
} }
void SetIsLiquid( Block id ) { void SetIsLiquid( Block id ) {
isLiquid[(int)id] = true; IsLiquid[(int)id] = true;
CollideType[(int)id] = BlockCollideType.SwimThrough;
} }
void SetBlockHeight( Block id, float height ) { void SetBlockHeight( Block id, float height ) {
heights[(int)id] = height; Height[(int)id] = height;
} }
void SetBlocksLight( Block id, bool blocks ) { void SetBlocksLight( Block id, bool blocks ) {
blocksLight[(int)id] = blocks; BlocksLight[(int)id] = blocks;
} }
void SetEmitsLight( Block id, bool emits ) { void SetEmitsLight( Block id, bool emits ) {
emitsLight[(int)id] = emits; EmitsLight[(int)id] = emits;
}
/// <summary> Gets whether the given block id is opaque/not see through. </summary>
public bool IsOpaque( byte id ) {
return isOpaque[id];
}
/// <summary> Gets whether the given block id is opaque/not see through, and occupies a full block. </summary>
public bool IsFullAndOpaque( byte id ) {
return isOpaque[id] && heights[id] == 1;
}
/// <summary> Gets whether the given block id is transparent/fully see through. </summary>
/// <remarks> Alpha values are treated as either 'fully see through' or 'fully solid'. </remarks>
public bool IsTransparent( byte id ) {
return isTransparent[id];
}
/// <summary> Gets the tile height of the given block id. </summary>
public float BlockHeight( byte id ) {
return heights[id];
}
/// <summary> Gets whether the given block id is translucent/partially see through. </summary>
/// <remarks>Colour values are blended into both the transparent and opaque blocks behind them. </remarks>
public bool IsTranslucent( byte id ) {
return isTranslucent[id];
}
/// <summary> Gets whether the given block blocks sunlight. </summary>
public bool BlocksLight( byte id ) {
return blocksLight[id];
}
/// <summary> Gets whether the given block id is a sprite. (flowers, saplings, fire, etc) </summary>
public bool IsSprite( byte id ) {
return isSprite[id];
}
/// <summary> Gets whether the given block id is a liquid. (water or lava) </summary>
public bool IsLiquid( byte id ) {
return isLiquid[id];
}
public bool EmitsLight( byte id ) {
return emitsLight[id];
}
public float FogDensity( byte id ) {
return fogDensities[id];
}
public FastColour FogColour( byte id ) {
return fogColours[id];
}
public string GetName( byte id ) {
return names[id];
} }
public void ResetBlockInfo( byte id ) { public void ResetBlockInfo( byte id ) {
isTransparent[id] = false; IsTransparent[id] = false;
isTranslucent[id] = false; IsTranslucent[id] = false;
isOpaque[id] = true; IsOpaque[id] = true;
isSprite[id] = false; IsSprite[id] = false;
isLiquid[id] = false; IsLiquid[id] = false;
heights[id] = 1; Height[id] = 1;
blocksLight[id] = true; BlocksLight[id] = true;
emitsLight[id] = true; EmitsLight[id] = false;
names[id] = "Invalid"; Name[id] = "Invalid";
fogColours[id] = default( FastColour ); FogColour[id] = default( FastColour );
fogDensities[id] = 0; FogDensity[id] = 0;
CollideType[id] = BlockCollideType.Solid;
SetAll( 0, (Block)id ); SetAll( 0, (Block)id );
SetupCullingCache(); SetupCullingCache();
} }
} }
public enum BlockCollideType : byte {
WalkThrough, // i.e. gas or sprite
SwimThrough, // i.e. liquid
Solid, // i.e. solid
}
} }

View File

@ -78,7 +78,7 @@ namespace ClassicalSharp {
if( !map.IsValidPos( x, y, z ) ) continue; if( !map.IsValidPos( x, y, z ) ) continue;
byte block = map.GetBlock( x, y, z ); byte block = map.GetBlock( x, y, z );
if( condition( block ) ) { if( condition( block ) ) {
float blockHeight = info.BlockHeight( block ); float blockHeight = info.Height[block];
Vector3 min = new Vector3( x, y, z ); Vector3 min = new Vector3( x, y, z );
Vector3 max = new Vector3( x + 1, y + blockHeight, z + 1 ); Vector3 max = new Vector3( x + 1, y + blockHeight, z + 1 );
BoundingBox blockBB = new BoundingBox( min, max ); BoundingBox blockBB = new BoundingBox( min, max );

View File

@ -72,7 +72,7 @@ namespace ClassicalSharp.Particles {
for( int i = 0; i < 25; i++ ) { for( int i = 0; i < 25; i++ ) {
double velX = ( rnd.NextDouble() * 0.8/*5*/ ) - 0.4/*0.25*/; double velX = ( rnd.NextDouble() * 0.8/*5*/ ) - 0.4/*0.25*/;
double velZ = ( rnd.NextDouble() * 0.8/*5*/ ) - 0.4/*0.25*/; double velZ = ( rnd.NextDouble() * 0.8/*5*/ ) - 0.4/*0.25*/;
double velY = ( rnd.NextDouble() + 0.25 ) * game.BlockInfo.BlockHeight( block ); double velY = ( rnd.NextDouble() + 0.25 ) * game.BlockInfo.Height[block];
Vector3 velocity = new Vector3( (float)velX, (float)velY, (float)velZ ); Vector3 velocity = new Vector3( (float)velX, (float)velY, (float)velZ );
double xOffset = rnd.NextDouble() - 0.125; double xOffset = rnd.NextDouble() - 0.125;
double yOffset = rnd.NextDouble() - 0.125; double yOffset = rnd.NextDouble() - 0.125;

View File

@ -65,7 +65,7 @@ namespace ClassicalSharp.Particles {
float collideY = y; float collideY = y;
if( topFace ) if( topFace )
collideY += game.BlockInfo.BlockHeight( block ); collideY += game.BlockInfo.Height[block];
bool collide = topFace ? (Position.Y < collideY) : (Position.Y > collideY ); bool collide = topFace ? (Position.Y < collideY) : (Position.Y > collideY );
if( collide ) { if( collide ) {
@ -78,7 +78,7 @@ namespace ClassicalSharp.Particles {
} }
bool CanPassThrough( byte block ) { bool CanPassThrough( byte block ) {
return block == 0 || game.BlockInfo.IsSprite( block ) || game.BlockInfo.IsLiquid( block ); return block == 0 || game.BlockInfo.IsSprite[block] || game.BlockInfo.IsLiquid[block];
} }
public override void Dispose() { public override void Dispose() {

View File

@ -187,7 +187,7 @@ namespace ClassicalSharp {
} }
internal bool CanPick( byte block ) { internal bool CanPick( byte block ) {
return !(block == 0 || (BlockInfo.IsLiquid( block ) && !(CanPlace[block] && CanDelete[block]))); return !(block == 0 || (BlockInfo.IsLiquid[block] && !(CanPlace[block] && CanDelete[block])));
} }
public KeyMap Keys = new KeyMap(); public KeyMap Keys = new KeyMap();

View File

@ -86,7 +86,7 @@ namespace ClassicalSharp {
if( block == 11 ) block = 10; // Still lava --> Lava if( block == 11 ) block = 10; // Still lava --> Lava
if( allAir && block != 0 ) allAir = false; if( allAir && block != 0 ) allAir = false;
if( allSolid && !info.isOpaque[block] ) allSolid = false; if( allSolid && !info.IsOpaque[block] ) allSolid = false;
chunkPtr[chunkIndex] = block; chunkPtr[chunkIndex] = block;
} }
} }
@ -115,10 +115,10 @@ namespace ClassicalSharp {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;
int index = ( ( yy << 8 ) + ( zz << 4 ) + xx ) * TileSide.Sides; int index = ( ( yy << 8 ) + ( zz << 4 ) + xx ) * TileSide.Sides;
if( info.isSprite[tile] ) { if( info.IsSprite[tile] ) {
int count = counts[index + TileSide.Top]; int count = counts[index + TileSide.Top];
if( count != 0 ) { if( count != 0 ) {
blockHeight = info.heights[tile]; blockHeight = info.Height[tile];
DrawSprite( count ); DrawSprite( count );
} }
return; return;
@ -130,9 +130,9 @@ namespace ClassicalSharp {
if( leftCount == 0 && rightCount == 0 && frontCount == 0 && if( leftCount == 0 && rightCount == 0 && frontCount == 0 &&
backCount == 0 && bottomCount == 0 && topCount == 0 ) return; backCount == 0 && bottomCount == 0 && topCount == 0 ) return;
emitsLight = info.emitsLight[tile]; emitsLight = info.EmitsLight[tile];
blockHeight = info.heights[tile]; blockHeight = info.Height[tile];
isTranslucent = info.isTranslucent[tile]; isTranslucent = info.IsTranslucent[tile];
if( leftCount != 0 ) if( leftCount != 0 )
DrawLeftFace( leftCount ); DrawLeftFace( leftCount );
@ -168,7 +168,7 @@ namespace ClassicalSharp {
// Sprites only use one face to indicate stretching count, so we can take a shortcut here. // Sprites only use one face to indicate stretching count, so we can take a shortcut here.
// Note that sprites are not drawn with any of the DrawXFace, they are drawn using DrawSprite. // Note that sprites are not drawn with any of the DrawXFace, they are drawn using DrawSprite.
if( info.IsSprite( tile ) ) { if( info.IsSprite[tile] ) {
countIndex += TileSide.Top; countIndex += TileSide.Top;
if( counts[countIndex] != 0 ) { if( counts[countIndex] != 0 ) {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;
@ -178,7 +178,7 @@ namespace ClassicalSharp {
} }
} else { } else {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;
emitsLight = info.emitsLight[tile]; emitsLight = info.EmitsLight[tile];
TestAndStretchZ( zz, countIndex, tile, chunkIndex, x, 0, TileSide.Left, -1 ); TestAndStretchZ( zz, countIndex, tile, chunkIndex, x, 0, TileSide.Left, -1 );
TestAndStretchZ( zz, countIndex, tile, chunkIndex, x, maxX, TileSide.Right, 1 ); TestAndStretchZ( zz, countIndex, tile, chunkIndex, x, maxX, TileSide.Right, 1 );
TestAndStretchX( xx, countIndex, tile, chunkIndex, z, 0, TileSide.Front, -extChunkSize ); TestAndStretchX( xx, countIndex, tile, chunkIndex, z, 0, TileSide.Front, -extChunkSize );

View File

@ -155,7 +155,7 @@ namespace ClassicalSharp {
unsafe void AddVertices( byte tile, int count, int face ) { unsafe void AddVertices( byte tile, int count, int face ) {
int i = atlas.Get1DIndex( info.GetTextureLoc( tile, face ) ); int i = atlas.Get1DIndex( info.GetTextureLoc( tile, face ) );
DrawInfo part = info.IsTranslucent( tile ) ? drawInfoTranslucent[i] : drawInfoNormal[i]; DrawInfo part = info.IsTranslucent[tile] ? drawInfoTranslucent[i] : drawInfoNormal[i];
part.iCount += 6; part.iCount += 6;
DrawInfoFaceData counts = part.Count; DrawInfoFaceData counts = part.Count;

View File

@ -130,7 +130,7 @@ namespace ClassicalSharp {
int mapIndex = ( maxY * Length + z ) * Width + x; int mapIndex = ( maxY * Length + z ) * Width + x;
for( int y = maxY; y >= 0; y-- ) { for( int y = maxY; y >= 0; y-- ) {
byte block = mapData[mapIndex]; byte block = mapData[mapIndex];
if( info.BlocksLight( block ) ) { if( info.BlocksLight[block] ) {
heightmap[index] = (short)( y - 1 ); heightmap[index] = (short)( y - 1 );
return y; return y;
} }
@ -142,8 +142,8 @@ namespace ClassicalSharp {
} }
void UpdateHeight( int x, int y, int z, byte oldBlock, byte newBlock ) { void UpdateHeight( int x, int y, int z, byte oldBlock, byte newBlock ) {
bool didBlock = info.BlocksLight( oldBlock ); bool didBlock = info.BlocksLight[oldBlock];
bool nowBlocks = info.BlocksLight( newBlock ); bool nowBlocks = info.BlocksLight[newBlock];
if( didBlock == nowBlocks ) return; if( didBlock == nowBlocks ) return;
int index = ( z * Width ) + x; int index = ( z * Width ) + x;
@ -276,7 +276,7 @@ namespace ClassicalSharp {
int curRunCount = skip[index]; int curRunCount = skip[index];
x += curRunCount; mapIndex += curRunCount; index += curRunCount; x += curRunCount; mapIndex += curRunCount; index += curRunCount;
if( x < xCount && info.blocksLight[mapPtr[mapIndex]] ) { if( x < xCount && info.BlocksLight[mapPtr[mapIndex]] ) {
heightmap[heightmapIndex + x] = (short)( y - 1 ); heightmap[heightmapIndex + x] = (short)( y - 1 );
elemsLeft--; elemsLeft--;
skip[index] = 0; skip[index] = 0;

View File

@ -16,7 +16,7 @@ namespace ClassicalSharp.Model {
public override float GetEyeY( Player player ) { public override float GetEyeY( Player player ) {
byte block = Byte.Parse( player.ModelName ); byte block = Byte.Parse( player.ModelName );
return block == 0 ? 1 : game.BlockInfo.BlockHeight( block ); return block == 0 ? 1 : game.BlockInfo.Height[block];
} }
const float adjust = 0.1f; const float adjust = 0.1f;
@ -38,11 +38,11 @@ namespace ClassicalSharp.Model {
} }
graphics.BindTexture( game.TerrainAtlas.TexId ); graphics.BindTexture( game.TerrainAtlas.TexId );
blockHeight = game.BlockInfo.BlockHeight( block ); blockHeight = game.BlockInfo.Height[block];
atlas = game.TerrainAtlas; atlas = game.TerrainAtlas;
BlockInfo = game.BlockInfo; BlockInfo = game.BlockInfo;
if( BlockInfo.IsSprite( block ) ) { if( BlockInfo.IsSprite[block] ) {
DrawXFace( 0f, TileSide.Right, false ); DrawXFace( 0f, TileSide.Right, false );
DrawZFace( 0f, TileSide.Back, false ); DrawZFace( 0f, TileSide.Back, false );
} else { } else {

View File

@ -643,35 +643,36 @@ namespace ClassicalSharp {
BlockInfo info = game.BlockInfo; BlockInfo info = game.BlockInfo;
info.ResetBlockInfo( block ); info.ResetBlockInfo( block );
info.names[block] = reader.ReadAsciiString(); info.Name[block] = reader.ReadAsciiString();
byte solidity = reader.ReadUInt8(); info.CollideType[block] = (BlockCollideType)reader.ReadUInt8();
byte movementSpeed = reader.ReadUInt8(); byte movementSpeed = reader.ReadUInt8();
info.SetTop( reader.ReadUInt8(), (Block)block ); info.SetTop( reader.ReadUInt8(), (Block)block );
info.SetSide( reader.ReadUInt8(), (Block)block ); info.SetSide( reader.ReadUInt8(), (Block)block );
info.SetBottom( reader.ReadUInt8(), (Block)block ); info.SetBottom( reader.ReadUInt8(), (Block)block );
reader.ReadUInt8(); // opacity hint, but we ignore this. reader.ReadUInt8(); // opacity hint, but we ignore this.
info.blocksLight[block] = reader.ReadUInt8() == 0; info.BlocksLight[block] = reader.ReadUInt8() == 0;
reader.ReadUInt8(); // walk sound, but we ignore this. reader.ReadUInt8(); // walk sound, but we ignore this.
info.EmitsLight[block] = reader.ReadUInt8() != 0;
if( opcode == (byte)PacketId.CpeDefineBlock ) { if( opcode == (byte)PacketId.CpeDefineBlock ) {
byte shape = reader.ReadUInt8(); byte shape = reader.ReadUInt8();
if( shape == 1 ) info.heights[block] = 1; if( shape == 1 ) info.Height[block] = 1;
else if( shape == 2 ) info.heights[block] = 0.5f; else if( shape == 2 ) info.Height[block] = 0.5f;
// TODO: upside down slab not properly supported // TODO: upside down slab not properly supported
else if( shape == 3 ) info.heights[block] = 0.5f; else if( shape == 3 ) info.Height[block] = 0.5f;
else if( shape == 4 ) info.isSprite[block] = true; else if( shape == 4 ) info.IsSprite[block] = true;
byte blockDraw = reader.ReadUInt8(); byte blockDraw = reader.ReadUInt8();
if( blockDraw == 0 ) info.isOpaque[block] = true; if( blockDraw == 0 ) info.IsOpaque[block] = true;
else if( blockDraw == 1 ) info.isTransparent[block] = true; else if( blockDraw == 1 ) info.IsTransparent[block] = true;
else if( blockDraw == 2 ) info.isTranslucent[block] = true; else if( blockDraw == 2 ) info.IsTranslucent[block] = true;
else if( blockDraw == 3 ) info.isTranslucent[block] = true; else if( blockDraw == 3 ) info.IsTranslucent[block] = true;
Console.WriteLine( shape + "," + blockDraw ); Console.WriteLine( shape + "," + blockDraw );
} else { } else {
byte fogDensity = reader.ReadUInt8(); byte fogDensity = reader.ReadUInt8();
info.fogDensities[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f; info.FogDensity[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
info.fogColours[block] = new FastColour( info.FogColour[block] = new FastColour(
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8() ); reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8() );
} }
info.SetupCullingCache(); info.SetupCullingCache();

View File

@ -19,9 +19,9 @@ namespace ClassicalSharp {
bool GetBoundingBox( byte block, int x, int y, int z, out BoundingBox box ) { bool GetBoundingBox( byte block, int x, int y, int z, out BoundingBox box ) {
box = new BoundingBox( Vector3.Zero, Vector3.Zero ); box = new BoundingBox( Vector3.Zero, Vector3.Zero );
if( CanWalkThrough( block ) ) return false; if( info.CollideType[block] != BlockCollideType.Solid ) return false;
Vector3 min = new Vector3( x, y, z ); Vector3 min = new Vector3( x, y, z );
Vector3 max = new Vector3( x + 1, y + info.BlockHeight( block ), z + 1 ); Vector3 max = new Vector3( x + 1, y + info.Height[block], z + 1 );
box = new BoundingBox( min, max ); box = new BoundingBox( min, max );
return true; return true;
} }
@ -38,10 +38,6 @@ namespace ClassicalSharp {
} }
} }
bool CanWalkThrough( byte block ) {
return block == 0 || info.IsSprite( block ) || info.IsLiquid( block ) || block == (byte)Block.Snow;
}
// TODO: test for corner cases, and refactor this. // TODO: test for corner cases, and refactor this.
static State[] stateCache = new State[0]; static State[] stateCache = new State[0];
class StateComparer : IComparer<State> { class StateComparer : IComparer<State> {
@ -171,7 +167,7 @@ namespace ClassicalSharp {
for( int x = min.X; x <= max.X; x++ ) { for( int x = min.X; x <= max.X; x++ ) {
for( int y = min.Y; y <= max.Y; y++ ) { for( int y = min.Y; y <= max.Y; y++ ) {
for( int z = min.Z; z <= max.Z; z++ ) { for( int z = min.Z; z <= max.Z; z++ ) {
if( !CanWalkThrough( GetPhysicsBlockId( x, y, z ) ) ) if( info.CollideType[GetPhysicsBlockId( x, y, z )] == BlockCollideType.Solid )
return false; return false;
} }
} }

View File

@ -73,7 +73,7 @@ namespace ClassicalSharp {
while( iterations < 10000 ) { while( iterations < 10000 ) {
byte block = map.IsValidPos( x, y, z ) ? map.GetBlock( x, y, z ) : (byte)0; byte block = map.IsValidPos( x, y, z ) ? map.GetBlock( x, y, z ) : (byte)0;
Vector3 min = new Vector3( x, y, z ); Vector3 min = new Vector3( x, y, z );
Vector3 max = min + new Vector3( 1, block == 0 ? 1 : info.BlockHeight( block ), 1 ); Vector3 max = min + new Vector3( 1, block == 0 ? 1 : info.Height[block], 1 );
float dx = Math.Min( Math.Abs( origin.X - min.X ), Math.Abs( origin.X - max.X ) ); float dx = Math.Min( Math.Abs( origin.X - min.X ), Math.Abs( origin.X - max.X ) );
float dy = Math.Min( Math.Abs( origin.Y - min.Y ), Math.Abs( origin.Y - max.Y ) ); float dy = Math.Min( Math.Abs( origin.Y - min.Y ), Math.Abs( origin.Y - max.Y ) );

View File

@ -121,10 +121,10 @@ namespace ClassicalSharp.Renderers {
Block headBlock = game.LocalPlayer.BlockAtHead; Block headBlock = game.LocalPlayer.BlockAtHead;
BlockInfo info = game.BlockInfo; BlockInfo info = game.BlockInfo;
if( info.FogDensity( (byte)headBlock ) != 0 ) { if( info.FogDensity[(byte)headBlock] != 0 ) {
graphics.SetFogMode( Fog.Exp ); graphics.SetFogMode( Fog.Exp );
graphics.SetFogDensity( info.FogDensity( (byte)headBlock ) ); graphics.SetFogDensity( info.FogDensity[(byte)headBlock] );
adjFogCol = info.FogColour( (byte)headBlock ); adjFogCol = info.FogColour[(byte)headBlock];
} else { } else {
// Blend fog and sky together // Blend fog and sky together
FastColour fogCol = map.FogCol; FastColour fogCol = map.FogCol;

View File

@ -120,7 +120,7 @@ namespace ClassicalSharp {
} }
bool BlocksRain( byte block ) { bool BlocksRain( byte block ) {
return !( block == 0 || info.IsSprite( block ) || info.IsLiquid( block ) ); return !(block == 0 || info.IsSprite[block] || info.IsLiquid[block]);
} }
internal void UpdateHeight( int x, int y, int z, byte oldBlock, byte newBlock ) { internal void UpdateHeight( int x, int y, int z, byte oldBlock, byte newBlock ) {

View File

@ -28,7 +28,6 @@ namespace OpenTK {
static readonly List<DisplayDevice> available_displays = new List<DisplayDevice>(); static readonly List<DisplayDevice> available_displays = new List<DisplayDevice>();
static readonly IList<DisplayDevice> available_displays_readonly; static readonly IList<DisplayDevice> available_displays_readonly;
static readonly object display_lock = new object();
static DisplayDevice primary_display; static DisplayDevice primary_display;
static Platform.IDisplayDeviceDriver implementation; static Platform.IDisplayDeviceDriver implementation;
@ -38,10 +37,7 @@ namespace OpenTK {
} }
internal DisplayDevice() { internal DisplayDevice() {
lock (display_lock) {
available_displays.Add(this); available_displays.Add(this);
}
available_resolutions_readonly = available_resolutions.AsReadOnly(); available_resolutions_readonly = available_resolutions.AsReadOnly();
} }
@ -92,13 +88,11 @@ namespace OpenTK {
if (value && primary_display != null && primary_display != this) if (value && primary_display != null && primary_display != this)
primary_display.IsPrimary = false; primary_display.IsPrimary = false;
lock (display_lock) {
primary = value; primary = value;
if (value) if (value)
primary_display = this; primary_display = this;
} }
} }
}
/// <summary> Selects an available resolution that matches the specified parameters. </summary> /// <summary> Selects an available resolution that matches the specified parameters. </summary>
/// <param name="width">The width of the requested resolution in pixels.</param> /// <param name="width">The width of the requested resolution in pixels.</param>

View File

@ -19,13 +19,10 @@ namespace OpenTK.Graphics {
static GraphicsMode defaultMode; static GraphicsMode defaultMode;
static IGraphicsMode implementation; static IGraphicsMode implementation;
static readonly object SyncRoot = new object();
static GraphicsMode() { static GraphicsMode() {
lock (SyncRoot) {
implementation = Platform.Factory.Default.CreateGraphicsMode(); implementation = Platform.Factory.Default.CreateGraphicsMode();
} }
}
internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int buffers) { internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int buffers) {
if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero."); if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero.");
@ -80,16 +77,13 @@ namespace OpenTK.Graphics {
/// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary> /// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary>
public static GraphicsMode Default { public static GraphicsMode Default {
get { get {
lock (SyncRoot) {
if (defaultMode == null) { if (defaultMode == null) {
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Default.BitsPerPixel, Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Default.BitsPerPixel, 16, 0, 2);
16, 0, 2);
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 2); defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 2);
} }
return defaultMode; return defaultMode;
} }
} }
}
// Queries the implementation for the actual graphics mode if this hasn't been done already. // Queries the implementation for the actual graphics mode if this hasn't been done already.
// This method allows for lazy evaluation of the actual GraphicsMode and should be called // This method allows for lazy evaluation of the actual GraphicsMode and should be called

View File

@ -8,14 +8,11 @@
using System; using System;
namespace OpenTK.Graphics.OpenGL namespace OpenTK.Graphics.OpenGL {
{
/// <summary> /// <summary> OpenGL bindings for .NET, implementing the full OpenGL API, including extensions. </summary>
/// OpenGL bindings for .NET, implementing the full OpenGL API, including extensions. public sealed partial class GL : BindingsBase {
/// </summary>
public sealed partial class GL : BindingsBase
{
static readonly object sync_root = new object();
static GL() { } static GL() { }
GraphicsContextBase context; GraphicsContextBase context;

View File

@ -7,8 +7,6 @@ namespace OpenTK.Platform.MacOS
{ {
class QuartzDisplayDeviceDriver : IDisplayDeviceDriver class QuartzDisplayDeviceDriver : IDisplayDeviceDriver
{ {
static object display_lock = new object();
static Dictionary<DisplayDevice, IntPtr> displayMap = static Dictionary<DisplayDevice, IntPtr> displayMap =
new Dictionary<DisplayDevice, IntPtr>(); new Dictionary<DisplayDevice, IntPtr>();

View File

@ -7,18 +7,15 @@ namespace OpenTK.Platform.Windows {
internal partial class Wgl : BindingsBase { internal partial class Wgl : BindingsBase {
const string Library = "OPENGL32.DLL"; const string Library = "OPENGL32.DLL";
static readonly object sync_root = new object();
protected override IntPtr GetAddress( string funcname ) { protected override IntPtr GetAddress( string funcname ) {
return Wgl.wglGetProcAddress( funcname ); return Wgl.wglGetProcAddress( funcname );
} }
internal void LoadEntryPoints() { internal void LoadEntryPoints() {
lock( sync_root ) {
LoadDelegate( "wglGetSwapIntervalEXT", out wglGetSwapIntervalEXT ); LoadDelegate( "wglGetSwapIntervalEXT", out wglGetSwapIntervalEXT );
LoadDelegate( "wglSwapIntervalEXT", out wglSwapIntervalEXT ); LoadDelegate( "wglSwapIntervalEXT", out wglSwapIntervalEXT );
} }
}
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
internal delegate Boolean SwapIntervalEXT(int interval); internal delegate Boolean SwapIntervalEXT(int interval);

View File

@ -40,19 +40,6 @@ namespace OpenTK.Platform.X11 {
internal int MWidth, MHeight; internal int MWidth, MHeight;
} }
[StructLayout(LayoutKind.Sequential)]
internal struct MotifWmHints {
internal IntPtr flags;
internal IntPtr functions;
internal IntPtr decorations;
internal IntPtr input_mode;
internal IntPtr status;
public override string ToString () {
return string.Format("MotifWmHints <flags={0}, functions={1}, decorations={2}, input_mode={3}, status={4}", (MotifFlags) flags.ToInt32 (), (MotifFunctions) functions.ToInt32 (), (MotifDecorations) decorations.ToInt32 (), (MotifInputMode) input_mode.ToInt32 (), status.ToInt32 ());
}
}
[Flags] [Flags]
internal enum MotifFlags { internal enum MotifFlags {
API = 1, API = 1,

View File

@ -104,9 +104,6 @@ namespace OpenTK.Platform.X11 {
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XSetTransientForHint(IntPtr display, IntPtr window, IntPtr prop_window); public extern static int XSetTransientForHint(IntPtr display, IntPtr window, IntPtr prop_window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref MotifWmHints data, int nelements);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr[] data, int nelements); public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr[] data, int nelements);

View File

@ -53,7 +53,6 @@ namespace OpenTK.Platform.X11
partial class Glx : BindingsBase partial class Glx : BindingsBase
{ {
const string Library = "libGL.so.1"; const string Library = "libGL.so.1";
static readonly object sync_root = new object();
// Disable BeforeFieldInit optimization. // Disable BeforeFieldInit optimization.
static Glx() { } static Glx() { }
@ -63,10 +62,8 @@ namespace OpenTK.Platform.X11
} }
internal void LoadEntryPoints() { internal void LoadEntryPoints() {
lock( sync_root ) {
LoadDelegate( "glXSwapIntervalSGI", out glXSwapIntervalSGI ); LoadDelegate( "glXSwapIntervalSGI", out glXSwapIntervalSGI );
} }
}
[SuppressUnmanagedCodeSecurity, DllImport( Library )] [SuppressUnmanagedCodeSecurity, DllImport( Library )]
public static extern bool glXIsDirect(IntPtr dpy, IntPtr context); public static extern bool glXIsDirect(IntPtr dpy, IntPtr context);