mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Move CloudsLevel to map class, simplify various map set methods, reset texture pack to default if we can't download the .png or .zip., fixes #90.
This commit is contained in:
parent
28583dd90d
commit
dc5a29e9f1
@ -33,11 +33,8 @@ namespace ClassicalSharp {
|
||||
env.CloudsSpeed = Single.Parse( v ); } ),
|
||||
|
||||
Make( -140, 50, "Clouds offset", Docking.Centre, OnWidgetClick,
|
||||
g => { StandardEnvRenderer env = game.EnvRenderer as StandardEnvRenderer;
|
||||
return env == null ? "(not active)" : env.CloudsOffset.ToString(); },
|
||||
(g, v) => { StandardEnvRenderer env = game.EnvRenderer as StandardEnvRenderer;
|
||||
if( env != null )
|
||||
env.SetCloudsOffset( Int32.Parse( v ) ); } ),
|
||||
g => (g.Map.CloudHeight - g.Map.Height).ToString(),
|
||||
(g, v) => g.Map.SetCloudsLevel( g.Map.Height + Int32.Parse( v ) ) ),
|
||||
|
||||
Make( 140, -150, "Sunlight colour", Docking.Centre, OnWidgetClick,
|
||||
g => g.Map.Sunlight.ToRGBHexString(),
|
||||
|
@ -43,8 +43,8 @@ namespace ClassicalSharp {
|
||||
internal void RaiseTerrainAtlasChanged() { Raise( TerrainAtlasChanged ); }
|
||||
|
||||
/// <summary> Raised when an environment variable is changed by the user, CPE, or WoM config. </summary>
|
||||
public event EventHandler<EnvVariableEventArgs> EnvVariableChanged;
|
||||
internal void RaiseEnvVariableChanged( EnvVariable envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); }
|
||||
public event EventHandler<EnvVarEventArgs> EnvVariableChanged;
|
||||
internal void RaiseEnvVariableChanged( EnvVar envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); }
|
||||
|
||||
/// <summary> Raised when the user changed their view/fog distance. </summary>
|
||||
public event EventHandler ViewDistanceChanged;
|
||||
@ -71,7 +71,7 @@ namespace ClassicalSharp {
|
||||
// Cache event instances so we don't create needless new objects.
|
||||
IdEventArgs idArgs = new IdEventArgs();
|
||||
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs();
|
||||
EnvVariableEventArgs envArgs = new EnvVariableEventArgs();
|
||||
EnvVarEventArgs envArgs = new EnvVarEventArgs();
|
||||
ChatEventArgs chatArgs = new ChatEventArgs();
|
||||
|
||||
void Raise( EventHandler handler ) {
|
||||
@ -104,15 +104,16 @@ namespace ClassicalSharp {
|
||||
public int Progress;
|
||||
}
|
||||
|
||||
public sealed class EnvVariableEventArgs : EventArgs {
|
||||
public sealed class EnvVarEventArgs : EventArgs {
|
||||
|
||||
public EnvVariable Var;
|
||||
public EnvVar Var;
|
||||
}
|
||||
|
||||
public enum EnvVariable {
|
||||
public enum EnvVar {
|
||||
SidesBlock,
|
||||
EdgeBlock,
|
||||
WaterLevel,
|
||||
CloudsLevel,
|
||||
Weather,
|
||||
|
||||
SkyColour,
|
||||
|
@ -25,6 +25,7 @@ namespace ClassicalSharp {
|
||||
public FastColour Shadowlight, ShadowlightXSide, ShadowlightZSide, ShadowlightYBottom;
|
||||
public Weather Weather = Weather.Sunny;
|
||||
public Guid Uuid;
|
||||
public int CloudHeight;
|
||||
|
||||
public int GroundHeight {
|
||||
get { return WaterHeight - 2; }
|
||||
@ -43,17 +44,18 @@ namespace ClassicalSharp {
|
||||
|
||||
public void Reset() {
|
||||
WaterHeight = -1;
|
||||
SetShadowlight( DefaultShadowlight );
|
||||
SetSunlight( DefaultSunlight );
|
||||
CloudHeight = -1;
|
||||
Width = Height = Length = 0;
|
||||
Uuid = Guid.NewGuid();
|
||||
EdgeBlock = Block.StillWater;
|
||||
SidesBlock = Block.Bedrock;
|
||||
|
||||
SetShadowlight( DefaultShadowlight );
|
||||
SetSunlight( DefaultSunlight );
|
||||
SkyCol = DefaultSkyColour;
|
||||
FogCol = DefaultFogColour;
|
||||
CloudsCol = DefaultCloudsColour;
|
||||
Weather = Weather.Sunny;
|
||||
Uuid = Guid.NewGuid();
|
||||
|
||||
game.Events.RaiseOnNewMap();
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ namespace ClassicalSharp {
|
||||
block = Block.Bedrock;
|
||||
}
|
||||
SidesBlock = block;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.SidesBlock );
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.SidesBlock );
|
||||
}
|
||||
|
||||
public void SetEdgeBlock( Block block ) {
|
||||
@ -74,51 +76,39 @@ namespace ClassicalSharp {
|
||||
block = Block.StillWater;
|
||||
}
|
||||
EdgeBlock = block;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.EdgeBlock );
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.EdgeBlock );
|
||||
}
|
||||
|
||||
public void SetWaterLevel( int level ) {
|
||||
if( level == WaterHeight ) return;
|
||||
WaterHeight = level;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.WaterLevel );
|
||||
}
|
||||
public void SetCloudsLevel( int level ) { Set( level, ref CloudHeight, EnvVar.CloudsLevel ); }
|
||||
|
||||
public void SetWeather( Weather weather ) {
|
||||
if( weather == Weather ) return;
|
||||
Weather = weather;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.Weather );
|
||||
}
|
||||
public void SetWaterLevel( int level ) { Set( level, ref WaterHeight, EnvVar.WaterLevel ); }
|
||||
|
||||
public void SetSkyColour( FastColour col ) {
|
||||
if( col == SkyCol ) return;
|
||||
SkyCol = col;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.SkyColour );
|
||||
}
|
||||
public void SetSkyColour( FastColour col ) { Set( col, ref SkyCol, EnvVar.SkyColour ); }
|
||||
|
||||
public void SetFogColour( FastColour col ) {
|
||||
if( col == FogCol ) return;
|
||||
FogCol = col;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.FogColour );
|
||||
}
|
||||
public void SetFogColour( FastColour col ) { Set( col, ref FogCol, EnvVar.FogColour ); }
|
||||
|
||||
public void SetCloudsColour( FastColour col ) {
|
||||
if( col == CloudsCol ) return;
|
||||
CloudsCol = col;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.CloudsColour );
|
||||
}
|
||||
public void SetCloudsColour( FastColour col ) { Set( col, ref CloudsCol, EnvVar.CloudsColour ); }
|
||||
|
||||
public void SetSunlight( FastColour col ) {
|
||||
if( col == Sunlight ) return;
|
||||
Sunlight = col;
|
||||
public void SetSunlight( FastColour col ) {
|
||||
Set( col, ref Sunlight, EnvVar.SunlightColour );
|
||||
AdjustLight( Sunlight, ref SunlightXSide, ref SunlightZSide, ref SunlightYBottom );
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.SunlightColour );
|
||||
}
|
||||
|
||||
public void SetShadowlight( FastColour col ) {
|
||||
if( col == Shadowlight ) return;
|
||||
Shadowlight = col;
|
||||
Set( col, ref Shadowlight, EnvVar.ShadowlightColour );
|
||||
AdjustLight( Shadowlight, ref ShadowlightXSide, ref ShadowlightZSide, ref ShadowlightYBottom );
|
||||
game.Events.RaiseEnvVariableChanged( EnvVariable.ShadowlightColour );
|
||||
}
|
||||
|
||||
public void SetWeather( Weather weather ) {
|
||||
if( weather == Weather ) return;
|
||||
Weather = weather;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.Weather );
|
||||
}
|
||||
|
||||
void Set<T>( T value, ref T target, EnvVar var ) where T : IEquatable<T> {
|
||||
if( value.Equals( target ) ) return;
|
||||
target = value;
|
||||
game.Events.RaiseEnvVariableChanged( var );
|
||||
}
|
||||
|
||||
public int GetLightHeight( int x, int z ) {
|
||||
@ -178,6 +168,7 @@ namespace ClassicalSharp {
|
||||
if( WaterHeight == -1 ) WaterHeight = height / 2;
|
||||
maxY = height - 1;
|
||||
oneY = length * width;
|
||||
if( CloudHeight == -1 ) CloudHeight = height + 2;
|
||||
|
||||
heightmap = new short[width * length];
|
||||
for( int i = 0; i < heightmap.Length; i++ ) {
|
||||
|
@ -80,6 +80,7 @@ namespace ClassicalSharp {
|
||||
UsingPlayerClick = true;
|
||||
} else if( extName == "EnvMapAppearance" && extVersion == 2 ) {
|
||||
usingTexturePack = true;
|
||||
packetSizes[(int)PacketId.CpeEnvSetMapApperance] += 4;
|
||||
}
|
||||
cpeServerExtensionsCount--;
|
||||
|
||||
@ -235,12 +236,13 @@ namespace ClassicalSharp {
|
||||
|
||||
void HandleCpeEnvSetMapApperance() {
|
||||
string url = reader.ReadAsciiString();
|
||||
byte sideBlock = reader.ReadUInt8();
|
||||
byte edgeBlock = reader.ReadUInt8();
|
||||
short waterLevel = reader.ReadInt16();
|
||||
game.Map.SetWaterLevel( waterLevel );
|
||||
game.Map.SetEdgeBlock( (Block)edgeBlock );
|
||||
game.Map.SetSidesBlock( (Block)sideBlock );
|
||||
game.Map.SetSidesBlock( (Block)reader.ReadUInt8() );
|
||||
game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() );
|
||||
game.Map.SetWaterLevel( reader.ReadInt16() );
|
||||
if( usingTexturePack ) {
|
||||
game.Map.SetCloudsLevel( reader.ReadInt16() );
|
||||
short maxViewDist = reader.ReadInt16(); // TODO: what to do with this?
|
||||
}
|
||||
|
||||
if( url == String.Empty ) {
|
||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
||||
|
@ -73,14 +73,22 @@ namespace ClassicalSharp {
|
||||
|
||||
void CheckForNewTerrainAtlas() {
|
||||
DownloadedItem item;
|
||||
game.AsyncDownloader.TryGetItem( "terrain", out item );
|
||||
if( item != null && item.Data != null ) {
|
||||
game.ChangeTerrainAtlas( (Bitmap)item.Data );
|
||||
if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) {
|
||||
if( item.Data != null ) {
|
||||
game.ChangeTerrainAtlas( (Bitmap)item.Data );
|
||||
} else {
|
||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
||||
extractor.Extract( game.defaultTexPack, game );
|
||||
}
|
||||
}
|
||||
game.AsyncDownloader.TryGetItem( "texturePack", out item );
|
||||
if( item != null && item.Data != null ) {
|
||||
|
||||
if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) {
|
||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
||||
extractor.Extract( (byte[])item.Data, game );
|
||||
if( item.Data != null ) {
|
||||
extractor.Extract( (byte[])item.Data, game );
|
||||
} else {
|
||||
extractor.Extract( game.defaultTexPack, game );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,14 +452,14 @@ namespace ClassicalSharp {
|
||||
HandleLevelDataChunk, HandleLevelFinalise, null, HandleSetBlock,
|
||||
HandleAddEntity, HandleEntityTeleport, HandleRelPosAndOrientationUpdate,
|
||||
HandleRelPositionUpdate, HandleOrientationUpdate, HandleRemoveEntity,
|
||||
HandleMessage, HandleKick, HandleSetPermission,
|
||||
HandleMessage, HandleKick, HandleSetPermission,
|
||||
|
||||
HandleCpeExtInfo, HandleCpeExtEntry, HandleCpeSetClickDistance,
|
||||
HandleCpeCustomBlockSupportLevel, HandleCpeHoldThis, null,
|
||||
HandleCpeExtAddPlayerName, HandleCpeExtAddEntity, HandleCpeExtRemovePlayerName,
|
||||
HandleCpeEnvColours, HandleCpeMakeSelection, HandleCpeRemoveSelection,
|
||||
HandleCpeSetBlockPermission, HandleCpeChangeModel, HandleCpeEnvSetMapApperance,
|
||||
HandleCpeEnvWeatherType, HandleCpeHackControl, HandleCpeExtAddEntity2,
|
||||
HandleCpeEnvWeatherType, HandleCpeHackControl, HandleCpeExtAddEntity2,
|
||||
null, HandleCpeDefineBlock, HandleCpeRemoveBlockDefinition,
|
||||
};
|
||||
maxHandledPacket = handlers.Length;
|
||||
|
@ -30,20 +30,6 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
public abstract void Render( double deltaTime );
|
||||
|
||||
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
|
||||
if( e.Var == EnvVariable.SkyColour ) {
|
||||
SkyColourChanged();
|
||||
} else if( e.Var == EnvVariable.FogColour ) {
|
||||
FogColourChanged();
|
||||
} else if( e.Var == EnvVariable.CloudsColour ) {
|
||||
CloudsColourChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void SkyColourChanged();
|
||||
|
||||
protected abstract void FogColourChanged();
|
||||
|
||||
protected abstract void CloudsColourChanged();
|
||||
protected abstract void EnvVariableChanged( object sender, EnvVarEventArgs e );
|
||||
}
|
||||
}
|
||||
|
@ -87,14 +87,14 @@ namespace ClassicalSharp {
|
||||
RebuildEdges( map.WaterHeight, legacy ? 128 : 65536 );
|
||||
}
|
||||
|
||||
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
|
||||
if( e.Var == EnvVariable.EdgeBlock ) {
|
||||
void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
||||
if( e.Var == EnvVar.EdgeBlock ) {
|
||||
MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, map.EdgeBlock );
|
||||
} else if( e.Var == EnvVariable.SidesBlock ) {
|
||||
} else if( e.Var == EnvVar.SidesBlock ) {
|
||||
MakeTexture( ref sideTexId, ref lastSideTexLoc, map.SidesBlock );
|
||||
} else if( e.Var == EnvVariable.WaterLevel ) {
|
||||
} else if( e.Var == EnvVar.WaterLevel ) {
|
||||
ResetSidesAndEdges( null, null );
|
||||
} else if( e.Var == EnvVariable.SunlightColour ) {
|
||||
} else if( e.Var == EnvVar.SunlightColour ) {
|
||||
ResetSidesAndEdges( null, null );
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,10 @@ namespace ClassicalSharp {
|
||||
chunkPos = new Vector3I( int.MaxValue, int.MaxValue, int.MaxValue );
|
||||
}
|
||||
|
||||
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
|
||||
if( e.Var == EnvVariable.SunlightColour || e.Var == EnvVariable.ShadowlightColour ) {
|
||||
void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
||||
if( e.Var == EnvVar.SunlightColour || e.Var == EnvVar.ShadowlightColour ) {
|
||||
Refresh();
|
||||
} else if( e.Var == EnvVariable.WaterLevel ) {
|
||||
} else if( e.Var == EnvVar.WaterLevel ) {
|
||||
builder.clipLevel = Math.Max( 0, game.Map.GroundHeight );
|
||||
Refresh();
|
||||
}
|
||||
|
@ -28,13 +28,10 @@ namespace ClassicalSharp.Renderers {
|
||||
graphics.ClearColour( map.SkyCol );
|
||||
}
|
||||
|
||||
protected override void CloudsColourChanged() {
|
||||
}
|
||||
|
||||
protected override void FogColourChanged() {
|
||||
}
|
||||
|
||||
protected override void SkyColourChanged() {
|
||||
protected override void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
||||
if( e.Var == EnvVar.SkyColour ) {
|
||||
graphics.ClearColour( map.SkyCol );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,8 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
int cloudsVb = -1, cloudsIndices, skyVb = -1, skyIndices;
|
||||
public float CloudsSpeed = 1;
|
||||
public int CloudsOffset = 2;
|
||||
bool legacy;
|
||||
|
||||
public void SetCloudsOffset( int offset ) {
|
||||
CloudsOffset = offset;
|
||||
ResetClouds();
|
||||
ResetSky();
|
||||
}
|
||||
|
||||
public void SetUseLegacyMode( bool legacy ) {
|
||||
this.legacy = legacy;
|
||||
ResetSky();
|
||||
@ -33,7 +26,7 @@ namespace ClassicalSharp.Renderers {
|
||||
if( skyVb == -1 || cloudsVb == -1 ) return;
|
||||
|
||||
Vector3 pos = game.LocalPlayer.EyePosition;
|
||||
if( pos.Y < map.Height + CloudsOffset + 8 ) {
|
||||
if( pos.Y < map.CloudHeight + 8 ) {
|
||||
graphics.BeginVbBatch( VertexFormat.Pos3fCol4b );
|
||||
graphics.BindVb( skyVb );
|
||||
graphics.DrawIndexedVb( DrawMode.Triangles, skyIndices, 0 );
|
||||
@ -42,16 +35,17 @@ namespace ClassicalSharp.Renderers {
|
||||
ResetFog();
|
||||
}
|
||||
|
||||
protected override void CloudsColourChanged() {
|
||||
ResetClouds();
|
||||
}
|
||||
|
||||
protected override void FogColourChanged() {
|
||||
ResetFog();
|
||||
}
|
||||
|
||||
protected override void SkyColourChanged() {
|
||||
ResetSky();
|
||||
protected override void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
||||
if( e.Var == EnvVar.SkyColour ) {
|
||||
ResetSky();
|
||||
} else if( e.Var == EnvVar.FogColour ) {
|
||||
ResetFog();
|
||||
} else if( e.Var == EnvVar.CloudsColour ) {
|
||||
ResetClouds();
|
||||
} else if( e.Var == EnvVar.CloudsLevel ) {
|
||||
ResetSky();
|
||||
ResetClouds();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnNewMap( object sender, EventArgs e ) {
|
||||
@ -160,7 +154,7 @@ namespace ClassicalSharp.Renderers {
|
||||
cloudsIndices = Utils.CountIndices( x2 - x1, z2 - z1, axisSize );
|
||||
|
||||
VertexPos3fTex2fCol4b* vertices = stackalloc VertexPos3fTex2fCol4b[cloudsIndices / 6 * 4];
|
||||
DrawCloudsY( x1, z1, x2, z2, map.Height + CloudsOffset, axisSize, map.CloudsCol, vertices );
|
||||
DrawCloudsY( x1, z1, x2, z2, map.CloudHeight, axisSize, map.CloudsCol, vertices );
|
||||
cloudsVb = graphics.CreateVb( (IntPtr)vertices, VertexFormat.Pos3fTex2fCol4b, cloudsIndices / 6 * 4 );
|
||||
}
|
||||
|
||||
@ -170,7 +164,7 @@ namespace ClassicalSharp.Renderers {
|
||||
skyIndices = Utils.CountIndices( x2 - x1, z2 - z1, axisSize );
|
||||
|
||||
VertexPos3fCol4b* vertices = stackalloc VertexPos3fCol4b[skyIndices / 6 * 4];
|
||||
DrawSkyY( x1, z1, x2, z2, map.Height + CloudsOffset + 8, axisSize, map.SkyCol, vertices );
|
||||
DrawSkyY( x1, z1, x2, z2, map.CloudHeight + 8, axisSize, map.SkyCol, vertices );
|
||||
skyVb = graphics.CreateVb( (IntPtr)vertices, VertexFormat.Pos3fCol4b, skyIndices / 6 * 4 );
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Structure that can be used for quick manipulations of A/R/G/B colours. </summary>
|
||||
/// <remarks> This structure is **not** suitable for interop with OpenGL or Direct3D. </remarks>
|
||||
public struct FastColour {
|
||||
public struct FastColour : IEquatable<FastColour> {
|
||||
|
||||
public byte A, R, G, B;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user