Fix chunks not being refreshed properly when sunlight/shadowlight changes. Fix client raising EnvVariableChanged events even if new is equal to old, fixes #54.

This commit is contained in:
UnknownShadow200 2015-09-07 06:29:11 +10:00
parent 896408a751
commit 5fb2f45189
2 changed files with 15 additions and 6 deletions

View File

@ -57,6 +57,7 @@ namespace ClassicalSharp {
} }
public void SetSidesBlock( Block block ) { public void SetSidesBlock( Block block ) {
if( block == SidesBlock ) return;
if( block > (Block)BlockInfo.MaxDefinedBlock ) { if( block > (Block)BlockInfo.MaxDefinedBlock ) {
Utils.LogWarning( "Tried to set sides block to an invalid block: " + block ); Utils.LogWarning( "Tried to set sides block to an invalid block: " + block );
block = Block.Bedrock; block = Block.Bedrock;
@ -66,6 +67,7 @@ namespace ClassicalSharp {
} }
public void SetEdgeBlock( Block block ) { public void SetEdgeBlock( Block block ) {
if( block == EdgeBlock ) return;
if( block > (Block)BlockInfo.MaxDefinedBlock ) { if( block > (Block)BlockInfo.MaxDefinedBlock ) {
Utils.LogWarning( "Tried to set edge block to an invalid block: " + block ); Utils.LogWarning( "Tried to set edge block to an invalid block: " + block );
block = Block.StillWater; block = Block.StillWater;
@ -75,38 +77,45 @@ namespace ClassicalSharp {
} }
public void SetWaterLevel( int level ) { public void SetWaterLevel( int level ) {
if( level == WaterHeight ) return;
WaterHeight = level; WaterHeight = level;
game.RaiseEnvVariableChanged( EnvVariable.WaterLevel ); game.RaiseEnvVariableChanged( EnvVariable.WaterLevel );
} }
public void SetWeather( Weather weather ) { public void SetWeather( Weather weather ) {
if( weather == Weather ) return;
Weather = weather; Weather = weather;
game.RaiseEnvVariableChanged( EnvVariable.Weather ); game.RaiseEnvVariableChanged( EnvVariable.Weather );
} }
public void SetSkyColour( FastColour col ) { public void SetSkyColour( FastColour col ) {
if( col == SkyCol ) return;
SkyCol = col; SkyCol = col;
game.RaiseEnvVariableChanged( EnvVariable.SkyColour ); game.RaiseEnvVariableChanged( EnvVariable.SkyColour );
} }
public void SetFogColour( FastColour col ) { public void SetFogColour( FastColour col ) {
if( col == FogCol ) return;
FogCol = col; FogCol = col;
game.RaiseEnvVariableChanged( EnvVariable.FogColour ); game.RaiseEnvVariableChanged( EnvVariable.FogColour );
} }
public void SetCloudsColour( FastColour col ) { public void SetCloudsColour( FastColour col ) {
if( col == CloudsCol ) return;
CloudsCol = col; CloudsCol = col;
game.RaiseEnvVariableChanged( EnvVariable.CloudsColour ); game.RaiseEnvVariableChanged( EnvVariable.CloudsColour );
} }
public void SetSunlight( FastColour value ) { public void SetSunlight( FastColour col ) {
Sunlight = value; if( col == Sunlight ) return;
Sunlight = col;
AdjustLight( Sunlight, ref SunlightXSide, ref SunlightZSide, ref SunlightYBottom ); AdjustLight( Sunlight, ref SunlightXSide, ref SunlightZSide, ref SunlightYBottom );
game.RaiseEnvVariableChanged( EnvVariable.SunlightColour ); game.RaiseEnvVariableChanged( EnvVariable.SunlightColour );
} }
public void SetShadowlight( FastColour value ) { public void SetShadowlight( FastColour col ) {
Shadowlight = value; if( col == Shadowlight ) return;
Shadowlight = col;
AdjustLight( Shadowlight, ref ShadowlightXSide, ref ShadowlightZSide, ref ShadowlightYBottom ); AdjustLight( Shadowlight, ref ShadowlightXSide, ref ShadowlightZSide, ref ShadowlightYBottom );
game.RaiseEnvVariableChanged( EnvVariable.ShadowlightColour ); game.RaiseEnvVariableChanged( EnvVariable.ShadowlightColour );
} }

View File

@ -63,6 +63,7 @@ namespace ClassicalSharp {
ClearChunkCache(); ClearChunkCache();
CreateChunkCache(); CreateChunkCache();
} }
chunkPos = new Vector3I( int.MaxValue, int.MaxValue, int.MaxValue );
} }
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) { void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
@ -75,8 +76,7 @@ namespace ClassicalSharp {
_1Dcount = game.TerrainAtlas1D.TexIds.Length; _1Dcount = game.TerrainAtlas1D.TexIds.Length;
bool fullResetRequired = elementsPerBitmap != game.TerrainAtlas1D.elementsPerBitmap; bool fullResetRequired = elementsPerBitmap != game.TerrainAtlas1D.elementsPerBitmap;
if( fullResetRequired ) { if( fullResetRequired ) {
Refresh(); Refresh();
chunkPos = new Vector3I( int.MaxValue, int.MaxValue, int.MaxValue );
} }
elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap; elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap;
} }