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

View File

@ -80,7 +80,7 @@ namespace ClassicalSharp {
TextureRectangle rec = game.TerrainAtlas.GetTexRec( texId );
int verSize = blockSize;
float height = game.BlockInfo.BlockHeight( (byte)block );
float height = game.BlockInfo.Height[(byte)block];
int blockY = y;
if( height != 1 ) {
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.Front, true );
SetHidden( tile, neighbour, TileSide.Back, true );
SetHidden( tile, neighbour, TileSide.Top, BlockHeight( tile ) == 1 );
SetHidden( tile, neighbour, TileSide.Bottom, BlockHeight( neighbour ) == 1 );
SetHidden( tile, neighbour, TileSide.Top, Height[tile] == 1 );
SetHidden( tile, neighbour, TileSide.Bottom, Height[neighbour] == 1 );
}
}
}
@ -25,8 +25,8 @@ namespace ClassicalSharp {
bool IsHidden( byte tile, byte block ) {
return
( ( tile == block || ( IsOpaque( block ) && !IsLiquid( block ) ) ) && !IsSprite( tile ) ) ||
( IsLiquid( tile ) && block == (byte)Block.Ice );
((tile == block || (IsOpaque[block] && !IsLiquid[block])) && !IsSprite[tile]) ||
(IsLiquid[tile] && block == (byte)Block.Ice);
}
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>
public partial class BlockInfo {
internal bool[] isTransparent = new bool[BlocksCount];
internal bool[] isTranslucent = new bool[BlocksCount];
internal bool[] isOpaque = new bool[BlocksCount];
internal bool[] isSprite = new bool[BlocksCount];
internal bool[] isLiquid = new bool[BlocksCount];
internal float[] heights = new float[BlocksCount];
internal bool[] blocksLight = new bool[BlocksCount];
internal bool[] emitsLight = new bool[BlocksCount];
internal string[] names = new string[BlocksCount];
internal FastColour[] fogColours = new FastColour[BlocksCount];
internal float[] fogDensities = new float[BlocksCount];
/// <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 = new bool[BlocksCount];
/// <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 = new bool[BlocksCount];
/// <summary> Gets whether the given block id is opaque/not partially see through. </summary>
public bool[] IsOpaque = new bool[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 int CpeBlocksCount = MaxDefinedCpeBlock + 1;
@ -24,26 +45,27 @@ namespace ClassicalSharp {
public void Init() {
for( int tile = 1; tile < BlocksCount; tile++ ) {
heights[tile] = 1f;
blocksLight[tile] = true;
isOpaque[tile] = true;
Height[tile] = 1f;
BlocksLight[tile] = true;
IsOpaque[tile] = true;
CollideType[tile] = BlockCollideType.Solid;
}
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++ ) {
names[i] = "Invalid";
Name[i] = "Invalid";
}
fogDensities[(byte)Block.StillWater] = 0.1f;
fogColours[(byte)Block.StillWater] = new FastColour( 5, 5, 51 );
fogDensities[(byte)Block.Water] = 0.1f;
fogColours[(byte)Block.Water] = new FastColour( 5, 5, 51 );
fogDensities[(byte)Block.StillLava] = 2f;
fogColours[(byte)Block.StillLava] = new FastColour( 153, 25, 0 );
fogDensities[(byte)Block.Lava] = 2f;
fogColours[(byte)Block.Lava] = new FastColour( 153, 25, 0 );
FogDensity[(byte)Block.StillWater] = 0.1f;
FogColour[(byte)Block.StillWater] = new FastColour( 5, 5, 51 );
FogDensity[(byte)Block.Water] = 0.1f;
FogColour[(byte)Block.Water] = new FastColour( 5, 5, 51 );
FogDensity[(byte)Block.StillLava] = 2f;
FogColour[(byte)Block.StillLava] = new FastColour( 153, 25, 0 );
FogDensity[(byte)Block.Lava] = 2f;
FogColour[(byte)Block.Lava] = new FastColour( 153, 25, 0 );
CollideType[(byte)Block.Snow] = BlockCollideType.WalkThrough;
SetupTextures();
SetBlockHeight( Block.Slab, 8/16f );
@ -85,111 +107,62 @@ namespace ClassicalSharp {
}
void MarkTransparent( Block id, bool blocks ) {
isTransparent[(int)id] = true;
blocksLight[(int)id] = blocks;
isOpaque[(int)id] = false;
IsTransparent[(int)id] = true;
BlocksLight[(int)id] = blocks;
IsOpaque[(int)id] = false;
}
void MarkSprite( Block id ) {
isSprite[(int)id] = true;
isTransparent[(int)id] = true;
blocksLight[(int)id] = false;
isOpaque[(int)id] = false;
IsSprite[(int)id] = true;
IsTransparent[(int)id] = true;
BlocksLight[(int)id] = false;
IsOpaque[(int)id] = false;
CollideType[(int)id] = BlockCollideType.WalkThrough;
}
void MarkTranslucent( Block id ) {
isTranslucent[(int)id] = true;
isOpaque[(int)id] = false;
IsTranslucent[(int)id] = true;
IsOpaque[(int)id] = false;
}
void SetIsLiquid( Block id ) {
isLiquid[(int)id] = true;
IsLiquid[(int)id] = true;
CollideType[(int)id] = BlockCollideType.SwimThrough;
}
void SetBlockHeight( Block id, float height ) {
heights[(int)id] = height;
Height[(int)id] = height;
}
void SetBlocksLight( Block id, bool blocks ) {
blocksLight[(int)id] = blocks;
BlocksLight[(int)id] = blocks;
}
void SetEmitsLight( Block id, bool 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];
EmitsLight[(int)id] = emits;
}
public void ResetBlockInfo( byte id ) {
isTransparent[id] = false;
isTranslucent[id] = false;
isOpaque[id] = true;
isSprite[id] = false;
isLiquid[id] = false;
heights[id] = 1;
blocksLight[id] = true;
emitsLight[id] = true;
names[id] = "Invalid";
fogColours[id] = default( FastColour );
fogDensities[id] = 0;
IsTransparent[id] = false;
IsTranslucent[id] = false;
IsOpaque[id] = true;
IsSprite[id] = false;
IsLiquid[id] = false;
Height[id] = 1;
BlocksLight[id] = true;
EmitsLight[id] = false;
Name[id] = "Invalid";
FogColour[id] = default( FastColour );
FogDensity[id] = 0;
CollideType[id] = BlockCollideType.Solid;
SetAll( 0, (Block)id );
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;
byte block = map.GetBlock( x, y, z );
if( condition( block ) ) {
float blockHeight = info.BlockHeight( block );
float blockHeight = info.Height[block];
Vector3 min = new Vector3( x, y, z );
Vector3 max = new Vector3( x + 1, y + blockHeight, z + 1 );
BoundingBox blockBB = new BoundingBox( min, max );

View File

@ -72,7 +72,7 @@ namespace ClassicalSharp.Particles {
for( int i = 0; i < 25; i++ ) {
double velX = ( 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 );
double xOffset = rnd.NextDouble() - 0.125;
double yOffset = rnd.NextDouble() - 0.125;

View File

@ -65,7 +65,7 @@ namespace ClassicalSharp.Particles {
float collideY = y;
if( topFace )
collideY += game.BlockInfo.BlockHeight( block );
collideY += game.BlockInfo.Height[block];
bool collide = topFace ? (Position.Y < collideY) : (Position.Y > collideY );
if( collide ) {
@ -78,7 +78,7 @@ namespace ClassicalSharp.Particles {
}
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() {

View File

@ -187,7 +187,7 @@ namespace ClassicalSharp {
}
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();

View File

@ -86,7 +86,7 @@ namespace ClassicalSharp {
if( block == 11 ) block = 10; // Still lava --> Lava
if( allAir && block != 0 ) allAir = false;
if( allSolid && !info.isOpaque[block] ) allSolid = false;
if( allSolid && !info.IsOpaque[block] ) allSolid = false;
chunkPtr[chunkIndex] = block;
}
}
@ -115,10 +115,10 @@ namespace ClassicalSharp {
X = x; Y = y; Z = z;
int index = ( ( yy << 8 ) + ( zz << 4 ) + xx ) * TileSide.Sides;
if( info.isSprite[tile] ) {
if( info.IsSprite[tile] ) {
int count = counts[index + TileSide.Top];
if( count != 0 ) {
blockHeight = info.heights[tile];
blockHeight = info.Height[tile];
DrawSprite( count );
}
return;
@ -130,9 +130,9 @@ namespace ClassicalSharp {
if( leftCount == 0 && rightCount == 0 && frontCount == 0 &&
backCount == 0 && bottomCount == 0 && topCount == 0 ) return;
emitsLight = info.emitsLight[tile];
blockHeight = info.heights[tile];
isTranslucent = info.isTranslucent[tile];
emitsLight = info.EmitsLight[tile];
blockHeight = info.Height[tile];
isTranslucent = info.IsTranslucent[tile];
if( leftCount != 0 )
DrawLeftFace( leftCount );
@ -168,7 +168,7 @@ namespace ClassicalSharp {
// 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.
if( info.IsSprite( tile ) ) {
if( info.IsSprite[tile] ) {
countIndex += TileSide.Top;
if( counts[countIndex] != 0 ) {
X = x; Y = y; Z = z;
@ -178,7 +178,7 @@ namespace ClassicalSharp {
}
} else {
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, maxX, TileSide.Right, 1 );
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 ) {
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;
DrawInfoFaceData counts = part.Count;

View File

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

View File

@ -16,7 +16,7 @@ namespace ClassicalSharp.Model {
public override float GetEyeY( Player player ) {
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;
@ -38,11 +38,11 @@ namespace ClassicalSharp.Model {
}
graphics.BindTexture( game.TerrainAtlas.TexId );
blockHeight = game.BlockInfo.BlockHeight( block );
blockHeight = game.BlockInfo.Height[block];
atlas = game.TerrainAtlas;
BlockInfo = game.BlockInfo;
if( BlockInfo.IsSprite( block ) ) {
if( BlockInfo.IsSprite[block] ) {
DrawXFace( 0f, TileSide.Right, false );
DrawZFace( 0f, TileSide.Back, false );
} else {

View File

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

View File

@ -19,9 +19,9 @@ namespace ClassicalSharp {
bool GetBoundingBox( byte block, int x, int y, int z, out BoundingBox box ) {
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 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 );
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.
static State[] stateCache = new State[0];
class StateComparer : IComparer<State> {
@ -171,7 +167,7 @@ namespace ClassicalSharp {
for( int x = min.X; x <= max.X; x++ ) {
for( int y = min.Y; y <= max.Y; y++ ) {
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;
}
}

View File

@ -73,7 +73,7 @@ namespace ClassicalSharp {
while( iterations < 10000 ) {
byte block = map.IsValidPos( x, y, z ) ? map.GetBlock( x, y, z ) : (byte)0;
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 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;
BlockInfo info = game.BlockInfo;
if( info.FogDensity( (byte)headBlock ) != 0 ) {
if( info.FogDensity[(byte)headBlock] != 0 ) {
graphics.SetFogMode( Fog.Exp );
graphics.SetFogDensity( info.FogDensity( (byte)headBlock ) );
adjFogCol = info.FogColour( (byte)headBlock );
graphics.SetFogDensity( info.FogDensity[(byte)headBlock] );
adjFogCol = info.FogColour[(byte)headBlock];
} else {
// Blend fog and sky together
FastColour fogCol = map.FogCol;

View File

@ -120,7 +120,7 @@ namespace ClassicalSharp {
}
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 ) {

View File

@ -28,7 +28,6 @@ namespace OpenTK {
static readonly List<DisplayDevice> available_displays = new List<DisplayDevice>();
static readonly IList<DisplayDevice> available_displays_readonly;
static readonly object display_lock = new object();
static DisplayDevice primary_display;
static Platform.IDisplayDeviceDriver implementation;
@ -38,10 +37,7 @@ namespace OpenTK {
}
internal DisplayDevice() {
lock (display_lock) {
available_displays.Add(this);
}
available_displays.Add(this);
available_resolutions_readonly = available_resolutions.AsReadOnly();
}
@ -92,11 +88,9 @@ namespace OpenTK {
if (value && primary_display != null && primary_display != this)
primary_display.IsPrimary = false;
lock (display_lock) {
primary = value;
if (value)
primary_display = this;
}
primary = value;
if (value)
primary_display = this;
}
}

View File

@ -19,12 +19,9 @@ namespace OpenTK.Graphics {
static GraphicsMode defaultMode;
static IGraphicsMode implementation;
static readonly object SyncRoot = new object();
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) {
@ -80,14 +77,11 @@ namespace OpenTK.Graphics {
/// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary>
public static GraphicsMode Default {
get {
lock (SyncRoot) {
if (defaultMode == null) {
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Default.BitsPerPixel,
16, 0, 2);
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 2);
}
return defaultMode;
}
if (defaultMode == null) {
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Default.BitsPerPixel, 16, 0, 2);
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 2);
}
return defaultMode;
}
}

View File

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

View File

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

View File

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

View File

@ -40,19 +40,6 @@ namespace OpenTK.Platform.X11 {
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]
internal enum MotifFlags {
API = 1,

View File

@ -103,10 +103,7 @@ namespace OpenTK.Platform.X11 {
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
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]
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
{
const string Library = "libGL.so.1";
static readonly object sync_root = new object();
// Disable BeforeFieldInit optimization.
static Glx() { }
@ -63,9 +62,7 @@ namespace OpenTK.Platform.X11
}
internal void LoadEntryPoints() {
lock( sync_root ) {
LoadDelegate( "glXSwapIntervalSGI", out glXSwapIntervalSGI );
}
LoadDelegate( "glXSwapIntervalSGI", out glXSwapIntervalSGI );
}
[SuppressUnmanagedCodeSecurity, DllImport( Library )]