mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
Fix DefineBlock/DefineBlockExt packets taking a disproportionate amount of time to process.
This commit is contained in:
parent
526fa9669c
commit
99bd040d2f
@ -12,24 +12,40 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public bool[] IsAir = new bool[BlocksCount];
|
public bool[] IsAir = new bool[BlocksCount];
|
||||||
|
|
||||||
internal void CheckOpaque() {
|
internal void SetupCullingCache() {
|
||||||
for( int tile = 1; tile < BlocksCount; tile++ ) {
|
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 ) {
|
if( MinBB[tile] != Vector3.Zero || MaxBB[tile] != Vector3.One ) {
|
||||||
IsOpaque[tile] = false;
|
IsOpaque[tile] = false;
|
||||||
IsTransparent[tile] = true;
|
IsTransparent[tile] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetupCullingCache() {
|
void UpdateCulling( byte tile, byte neighbour ) {
|
||||||
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;
|
|
||||||
bool hidden = IsHidden( tile, neighbour );
|
bool hidden = IsHidden( tile, neighbour );
|
||||||
if( tile == neighbour && !CullWithNeighbours[tile] )
|
if( tile == neighbour && !CullWithNeighbours[tile] )
|
||||||
hidden = false;
|
hidden = false;
|
||||||
@ -55,8 +71,6 @@ namespace ClassicalSharp {
|
|||||||
SetHidden( tile, neighbour, TileSide.Top, hidden && nMin.Y == 0 && tMax.Y == 1 );
|
SetHidden( tile, neighbour, TileSide.Top, hidden && nMin.Y == 0 && tMax.Y == 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsHidden( byte tile, byte block ) {
|
bool IsHidden( byte tile, byte block ) {
|
||||||
return
|
return
|
||||||
|
@ -163,7 +163,7 @@ namespace ClassicalSharp {
|
|||||||
FullBright[(int)id] = emits;
|
FullBright[(int)id] = emits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetBlockInfo( byte id ) {
|
public void ResetBlockInfo( byte id, bool updateCulling ) {
|
||||||
IsTransparent[id] = false;
|
IsTransparent[id] = false;
|
||||||
IsTranslucent[id] = false;
|
IsTranslucent[id] = false;
|
||||||
IsOpaque[id] = true;
|
IsOpaque[id] = true;
|
||||||
@ -180,7 +180,8 @@ namespace ClassicalSharp {
|
|||||||
CollideType[id] = BlockCollideType.Solid;
|
CollideType[id] = BlockCollideType.Solid;
|
||||||
SpeedMultiplier[id] = 1;
|
SpeedMultiplier[id] = 1;
|
||||||
SetAll( 0, (Block)id );
|
SetAll( 0, (Block)id );
|
||||||
SetupCullingCache();
|
if( updateCulling )
|
||||||
|
SetupCullingCache( id );
|
||||||
MinBB[id] = Vector3.Zero;
|
MinBB[id] = Vector3.Zero;
|
||||||
MaxBB[id] = Vector3.One;
|
MaxBB[id] = Vector3.One;
|
||||||
StepSounds[id] = SoundType.None;
|
StepSounds[id] = SoundType.None;
|
||||||
|
@ -410,7 +410,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandleCpeRemoveBlockDefinition() {
|
void HandleCpeRemoveBlockDefinition() {
|
||||||
game.BlockInfo.ResetBlockInfo( reader.ReadUInt8() );
|
game.BlockInfo.ResetBlockInfo( reader.ReadUInt8(), true );
|
||||||
game.BlockInfo.InitLightOffsets();
|
game.BlockInfo.InitLightOffsets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ namespace ClassicalSharp {
|
|||||||
byte HandleCpeDefineBlockCommonStart() {
|
byte HandleCpeDefineBlockCommonStart() {
|
||||||
byte block = reader.ReadUInt8();
|
byte block = reader.ReadUInt8();
|
||||||
BlockInfo info = game.BlockInfo;
|
BlockInfo info = game.BlockInfo;
|
||||||
info.ResetBlockInfo( block );
|
info.ResetBlockInfo( block, false );
|
||||||
|
|
||||||
info.Name[block] = reader.ReadAsciiString();
|
info.Name[block] = reader.ReadAsciiString();
|
||||||
info.CollideType[block] = (BlockCollideType)reader.ReadUInt8();
|
info.CollideType[block] = (BlockCollideType)reader.ReadUInt8();
|
||||||
@ -478,7 +478,7 @@ namespace ClassicalSharp {
|
|||||||
info.FogDensity[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
|
info.FogDensity[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
|
||||||
info.FogColour[block] = new FastColour(
|
info.FogColour[block] = new FastColour(
|
||||||
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8() );
|
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8() );
|
||||||
info.SetupCullingCache();
|
info.SetupCullingCache( block );
|
||||||
info.InitLightOffsets();
|
info.InitLightOffsets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user