From 4401823fab3c41193d959925bf75b1d77286b9fe Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 12 May 2016 09:34:00 +1000 Subject: [PATCH] Rain speed / Snow speed / Weather falloff are not hardcoded. --- ClassicalSharp/Events/WorldEvents.cs | 5 +- ClassicalSharp/Map/WorldEnv.cs | 68 +++++++++++++-------- ClassicalSharp/Rendering/WeatherRenderer.cs | 12 +++- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/ClassicalSharp/Events/WorldEvents.cs b/ClassicalSharp/Events/WorldEvents.cs index b01a59396..46b40bf96 100644 --- a/ClassicalSharp/Events/WorldEvents.cs +++ b/ClassicalSharp/Events/WorldEvents.cs @@ -49,6 +49,9 @@ namespace ClassicalSharp.Events { CloudsColour, FogColour, SunlightColour, - ShadowlightColour, + ShadowlightColour, + + RainSpeed, + SnowSpeed, } } diff --git a/ClassicalSharp/Map/WorldEnv.cs b/ClassicalSharp/Map/WorldEnv.cs index 45c477320..703e7cb07 100644 --- a/ClassicalSharp/Map/WorldEnv.cs +++ b/ClassicalSharp/Map/WorldEnv.cs @@ -25,9 +25,18 @@ namespace ClassicalSharp.Map { /// Height of the clouds in world space. public int CloudHeight; - /// How fast clouds should travel across the map, defaults to 1. + /// Modifier of how fast clouds travel across the world, defaults to 1. public float CloudsSpeed = 1; + /// Modifier of how fast rain falls, defaults to 1. + public float RainSpeed = 1; + + /// Modifier of how fast snow falls, defaults to 1. + public float SnowSpeed = 1; + + /// Modifier of how fast rain/snow fades, defaults to 1. + public float WeatherFade = 1; + /// Colour applied to blocks located in direct sunlight. public FastColour Sunlight; public FastColour SunlightXSide, SunlightZSide, SunlightYBottom; @@ -47,7 +56,7 @@ namespace ClassicalSharp.Map { /// Height of the map edge in world space. public int EdgeHeight; - /// Block that surrounds the map that fills the bottom of the map horizontally, + /// Block that surrounds the map that fills the bottom of the map horizontally, /// fills part of the vertical sides of the map, and also surrounds map the map horizontally. (default bedrock) public Block SidesBlock = Block.Bedrock; @@ -67,6 +76,9 @@ namespace ClassicalSharp.Map { EdgeBlock = Block.StillWater; SidesBlock = Block.Bedrock; CloudsSpeed = 1; + RainSpeed = 1; + SnowSpeed = 1; + WeatherFade = 1; ResetLight(); SkyCol = DefaultSkyColour; @@ -84,8 +96,8 @@ namespace ClassicalSharp.Map { ref SunlightZSide, ref SunlightYBottom ); } - /// Sets the sides block to the given block, and raises the - /// EnvVariableChanged event with the variable 'SidesBlock'. + /// Sets sides block to the given block, and raises + /// EnvVariableChanged event with variable 'SidesBlock'. public void SetSidesBlock( Block block ) { if( block == SidesBlock ) return; if( block == (Block)BlockInfo.MaxDefinedBlock ) { @@ -96,8 +108,8 @@ namespace ClassicalSharp.Map { game.WorldEvents.RaiseEnvVariableChanged( EnvVar.SidesBlock ); } - /// Sets the edge block to the given block, and raises the - /// EnvVariableChanged event with the variable 'EdgeBlock'. + /// Sets edge block to the given block, and raises + /// EnvVariableChanged event with variable 'EdgeBlock'. public void SetEdgeBlock( Block block ) { if( block == EdgeBlock ) return; if( block == (Block)BlockInfo.MaxDefinedBlock ) { @@ -108,32 +120,40 @@ namespace ClassicalSharp.Map { game.WorldEvents.RaiseEnvVariableChanged( EnvVar.EdgeBlock ); } - /// Sets the height of the clouds in world space, and raises the - /// EnvVariableChanged event with the variable 'CloudsLevel'. + /// Sets clouds height in world space, and raises + /// EnvVariableChanged event with variable 'CloudsLevel'. public void SetCloudsLevel( int level ) { Set( level, ref CloudHeight, EnvVar.CloudsLevel ); } - /// Sets the current clouds speed, and raises the - /// EnvVariableChanged event with the variable 'CloudsSpeed'. + /// Sets clouds speed, and raises EnvVariableChanged + /// event with variable 'CloudsSpeed'. public void SetCloudsSpeed( float speed ) { Set( speed, ref CloudsSpeed, EnvVar.CloudsSpeed ); } - /// Sets the height of the map edges in world space, and raises the - /// EnvVariableChanged event with the variable 'EdgeLevel'. + /// Sets rain speed and raises EnvVariableChanged + /// event with variable 'RainSpeed'. + public void SetRainSpeed( float speed ) { Set( speed, ref RainSpeed, EnvVar.RainSpeed ); } + + /// Sets snow speed, and raises EnvVariableChanged + /// event with variable 'SnowSpeed'. + public void SetSnowSpeed( float speed ) { Set( speed, ref SnowSpeed, EnvVar.SnowSpeed ); } + + /// Sets height of the map edges in world space, and raises + /// EnvVariableChanged event with variable 'EdgeLevel'. public void SetEdgeLevel( int level ) { Set( level, ref EdgeHeight, EnvVar.EdgeLevel ); } - /// Sets the current sky colour, and raises the - /// EnvVariableChanged event with the variable 'SkyColour'. + /// Sets tsky colour, and raises + /// EnvVariableChanged event with variable 'SkyColour'. public void SetSkyColour( FastColour col ) { Set( col, ref SkyCol, EnvVar.SkyColour ); } - /// Sets the current fog colour, and raises the - /// EnvVariableChanged event with the variable 'FogColour'. + /// Sets fog colour, and raises + /// EnvVariableChanged event with variable 'FogColour'. public void SetFogColour( FastColour col ) { Set( col, ref FogCol, EnvVar.FogColour ); } - /// Sets the current clouds colour, and raises the - /// EnvVariableChanged event with the variable 'CloudsColour'. + /// Sets clouds colour, and raises + /// EnvVariableChanged event with variable 'CloudsColour'. public void SetCloudsColour( FastColour col ) { Set( col, ref CloudsCol, EnvVar.CloudsColour ); } - /// Sets the current sunlight colour, and raises the - /// EnvVariableChanged event with the variable 'SunlightColour'. + /// Sets sunlight colour, and raises + /// EnvVariableChanged event with variable 'SunlightColour'. public void SetSunlight( FastColour col ) { if( col == Sunlight ) return; Sunlight = col; @@ -143,8 +163,8 @@ namespace ClassicalSharp.Map { game.WorldEvents.RaiseEnvVariableChanged( EnvVar.SunlightColour ); } - /// Sets the current shadowlight colour, and raises the - /// EnvVariableChanged event with the variable 'ShadowlightColour'. + /// Sets current shadowlight colour, and raises + /// EnvVariableChanged event with variable 'ShadowlightColour'. public void SetShadowlight( FastColour col ) { if( col == Shadowlight ) return; Shadowlight = col; @@ -154,8 +174,8 @@ namespace ClassicalSharp.Map { game.WorldEvents.RaiseEnvVariableChanged( EnvVar.ShadowlightColour ); } - /// Sets the current weather, and raises the - /// EnvVariableChanged event with the variable 'Weather'. + /// Sets weather, and raises + /// EnvVariableChanged event with variable 'Weather'. public void SetWeather( Weather weather ) { if( weather == Weather ) return; Weather = weather; diff --git a/ClassicalSharp/Rendering/WeatherRenderer.cs b/ClassicalSharp/Rendering/WeatherRenderer.cs index 87cc4c12b..d728bf47c 100644 --- a/ClassicalSharp/Rendering/WeatherRenderer.cs +++ b/ClassicalSharp/Rendering/WeatherRenderer.cs @@ -43,8 +43,10 @@ namespace ClassicalSharp.Renderers { Vector3I pos = Vector3I.Floor( camPos ); bool moved = pos != lastPos; lastPos = pos; + WorldEnv env = game.World.Env; - float speed = weather == Weather.Rainy ? 1f : 0.20f; + float speed = weather == Weather.Rainy ? + 1.0f * env.RainSpeed : 0.2f * env.SnowSpeed; vOffset = -(float)game.accumulator * speed; rainAcc += deltaTime; bool particles = weather == Weather.Rainy; @@ -61,7 +63,10 @@ namespace ClassicalSharp.Renderers { if( particles && (rainAcc >= 0.25 || moved) ) game.ParticleManager.AddRainParticle( new Vector3( pos.X + dx, rainY, pos.Z + dz ) ); - col.A = (byte)Math.Max( 0, AlphaAt( dx * dx + dz * dz ) ); + + float alpha = AlphaAt( dx * dx + dz * dz ); + Utils.Clamp( ref alpha, 0, 0xFF ); + col.A = (byte)alpha; MakeRainForSquare( pos.X + dx, rainY, height, pos.Z + dz, col, ref index ); } } @@ -78,7 +83,8 @@ namespace ClassicalSharp.Renderers { float AlphaAt( float x ) { // Wolfram Alpha: fit {0,178},{1,169},{4,147},{9,114},{16,59},{25,9} - return 0.05f * x * x - 7 * x + 178; + float falloff = 0.05f * x * x - 7 * x; + return 178 + falloff * game.World.Env.WeatherFade; } void MakeRainForSquare( int x, float y, float height, int z, FastColour col, ref int index ) {