Fix DefineBlock/DefineBlockExt packets taking a disproportionate amount of time to process.

This commit is contained in:
UnknownShadow200 2016-01-07 09:54:40 +11:00
parent 526fa9669c
commit 99bd040d2f
3 changed files with 56 additions and 41 deletions

View File

@ -12,24 +12,40 @@ namespace ClassicalSharp {
public bool[] IsAir = new bool[BlocksCount];
internal void CheckOpaque() {
for( int tile = 1; tile < BlocksCount; tile++ ) {
internal void SetupCullingCache() {
IsAir[0] = true;
for( int tile = 1; tile < BlocksCount; tile++ )
CheckOpaque( tile );
for( int tile = 0; tile < CanStretch.Length; tile++ )
CanStretch[tile] = true;
for( int tileI = 1; tileI < BlocksCount; tileI++ ) {
for( int neighbourI = 1; neighbourI < BlocksCount; neighbourI++ ) {
byte tile = (byte)tileI, neighbour = (byte)neighbourI;
UpdateCulling( tile, neighbour );
}
}
}
internal void SetupCullingCache( byte tile ) {
IsAir[0] = true;
CheckOpaque( tile );
CanStretch[tile] = true;
for( int other = 1; other < BlocksCount; other++ ) {
UpdateCulling( tile, (byte)other );
UpdateCulling( (byte)other, tile );
}
}
void CheckOpaque( int tile ) {
if( MinBB[tile] != Vector3.Zero || MaxBB[tile] != Vector3.One ) {
IsOpaque[tile] = false;
IsTransparent[tile] = true;
}
}
}
internal void SetupCullingCache() {
IsAir[0] = true;
CheckOpaque();
for( int i = 0; i < CanStretch.Length; i++ )
CanStretch[i] = true;
for( int tileI = 1; tileI < BlocksCount; tileI++ ) {
for( int neighbourI = 1; neighbourI < BlocksCount; neighbourI++ ) {
byte tile = (byte)tileI, neighbour = (byte)neighbourI;
void UpdateCulling( byte tile, byte neighbour ) {
bool hidden = IsHidden( tile, neighbour );
if( tile == neighbour && !CullWithNeighbours[tile] )
hidden = false;
@ -55,8 +71,6 @@ namespace ClassicalSharp {
SetHidden( tile, neighbour, TileSide.Top, hidden && nMin.Y == 0 && tMax.Y == 1 );
}
}
}
}
bool IsHidden( byte tile, byte block ) {
return

View File

@ -163,7 +163,7 @@ namespace ClassicalSharp {
FullBright[(int)id] = emits;
}
public void ResetBlockInfo( byte id ) {
public void ResetBlockInfo( byte id, bool updateCulling ) {
IsTransparent[id] = false;
IsTranslucent[id] = false;
IsOpaque[id] = true;
@ -180,7 +180,8 @@ namespace ClassicalSharp {
CollideType[id] = BlockCollideType.Solid;
SpeedMultiplier[id] = 1;
SetAll( 0, (Block)id );
SetupCullingCache();
if( updateCulling )
SetupCullingCache( id );
MinBB[id] = Vector3.Zero;
MaxBB[id] = Vector3.One;
StepSounds[id] = SoundType.None;

View File

@ -410,7 +410,7 @@ namespace ClassicalSharp {
}
void HandleCpeRemoveBlockDefinition() {
game.BlockInfo.ResetBlockInfo( reader.ReadUInt8() );
game.BlockInfo.ResetBlockInfo( reader.ReadUInt8(), true );
game.BlockInfo.InitLightOffsets();
}
@ -434,7 +434,7 @@ namespace ClassicalSharp {
byte HandleCpeDefineBlockCommonStart() {
byte block = reader.ReadUInt8();
BlockInfo info = game.BlockInfo;
info.ResetBlockInfo( block );
info.ResetBlockInfo( block, false );
info.Name[block] = reader.ReadAsciiString();
info.CollideType[block] = (BlockCollideType)reader.ReadUInt8();
@ -478,7 +478,7 @@ namespace ClassicalSharp {
info.FogDensity[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
info.FogColour[block] = new FastColour(
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8() );
info.SetupCullingCache();
info.SetupCullingCache( block );
info.InitLightOffsets();
}