From 5fb2f4518984abfc1b242954bedccb31871ea850 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 7 Sep 2015 06:29:11 +1000 Subject: [PATCH] Fix chunks not being refreshed properly when sunlight/shadowlight changes. Fix client raising EnvVariableChanged events even if new is equal to old, fixes #54. --- ClassicalSharp/Map/Map.cs | 17 +++++++++++++---- ClassicalSharp/Rendering/MapRenderer.cs | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ClassicalSharp/Map/Map.cs b/ClassicalSharp/Map/Map.cs index e0d341691..66b99a6c6 100644 --- a/ClassicalSharp/Map/Map.cs +++ b/ClassicalSharp/Map/Map.cs @@ -57,6 +57,7 @@ namespace ClassicalSharp { } public void SetSidesBlock( Block block ) { + if( block == SidesBlock ) return; if( block > (Block)BlockInfo.MaxDefinedBlock ) { Utils.LogWarning( "Tried to set sides block to an invalid block: " + block ); block = Block.Bedrock; @@ -66,6 +67,7 @@ namespace ClassicalSharp { } public void SetEdgeBlock( Block block ) { + if( block == EdgeBlock ) return; if( block > (Block)BlockInfo.MaxDefinedBlock ) { Utils.LogWarning( "Tried to set edge block to an invalid block: " + block ); block = Block.StillWater; @@ -75,38 +77,45 @@ namespace ClassicalSharp { } public void SetWaterLevel( int level ) { + if( level == WaterHeight ) return; WaterHeight = level; game.RaiseEnvVariableChanged( EnvVariable.WaterLevel ); } public void SetWeather( Weather weather ) { + if( weather == Weather ) return; Weather = weather; game.RaiseEnvVariableChanged( EnvVariable.Weather ); } public void SetSkyColour( FastColour col ) { + if( col == SkyCol ) return; SkyCol = col; game.RaiseEnvVariableChanged( EnvVariable.SkyColour ); } public void SetFogColour( FastColour col ) { + if( col == FogCol ) return; FogCol = col; game.RaiseEnvVariableChanged( EnvVariable.FogColour ); } public void SetCloudsColour( FastColour col ) { + if( col == CloudsCol ) return; CloudsCol = col; game.RaiseEnvVariableChanged( EnvVariable.CloudsColour ); } - public void SetSunlight( FastColour value ) { - Sunlight = value; + public void SetSunlight( FastColour col ) { + if( col == Sunlight ) return; + Sunlight = col; AdjustLight( Sunlight, ref SunlightXSide, ref SunlightZSide, ref SunlightYBottom ); game.RaiseEnvVariableChanged( EnvVariable.SunlightColour ); } - public void SetShadowlight( FastColour value ) { - Shadowlight = value; + public void SetShadowlight( FastColour col ) { + if( col == Shadowlight ) return; + Shadowlight = col; AdjustLight( Shadowlight, ref ShadowlightXSide, ref ShadowlightZSide, ref ShadowlightYBottom ); game.RaiseEnvVariableChanged( EnvVariable.ShadowlightColour ); } diff --git a/ClassicalSharp/Rendering/MapRenderer.cs b/ClassicalSharp/Rendering/MapRenderer.cs index 8ddaacf05..64038cc8c 100644 --- a/ClassicalSharp/Rendering/MapRenderer.cs +++ b/ClassicalSharp/Rendering/MapRenderer.cs @@ -63,6 +63,7 @@ namespace ClassicalSharp { ClearChunkCache(); CreateChunkCache(); } + chunkPos = new Vector3I( int.MaxValue, int.MaxValue, int.MaxValue ); } void EnvVariableChanged( object sender, EnvVariableEventArgs e ) { @@ -75,8 +76,7 @@ namespace ClassicalSharp { _1Dcount = game.TerrainAtlas1D.TexIds.Length; bool fullResetRequired = elementsPerBitmap != game.TerrainAtlas1D.elementsPerBitmap; if( fullResetRequired ) { - Refresh(); - chunkPos = new Vector3I( int.MaxValue, int.MaxValue, int.MaxValue ); + Refresh(); } elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap; }