Implement EnvMapAppearance v2 extension.

This commit is contained in:
UnknownShadow200 2015-12-31 16:02:49 +11:00
parent 06b0562695
commit 76452c75d1
7 changed files with 44 additions and 34 deletions

View File

@ -40,7 +40,7 @@ namespace ClassicalSharp {
Make( -140, 50, "View distance", OnWidgetClick,
g => g.ViewDistance.ToString(),
(g, v) => g.SetViewDistance( Int32.Parse( v ) ) ),
(g, v) => g.SetViewDistance( Int32.Parse( v ), true ) ),
// Column 2
!network.IsSinglePlayer ? null :

View File

@ -98,6 +98,7 @@ namespace ClassicalSharp {
/// <summary> Radius of the sphere the player can see around the position of the current camera. </summary>
public int ViewDistance = 512;
internal int MaxViewDistance = 32768, UserViewDistance = 512;
/// <summary> Field of view for the current camera in degrees. </summary>
public int FieldOfView = 70;

View File

@ -44,6 +44,7 @@ namespace ClassicalSharp {
Options.Load();
AcceptedUrls.Load();
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
UserViewDistance = ViewDistance;
CameraClipping = Options.GetBool( OptionsKey.CameraClipping, true );
InputHandler = new InputHandler( this );
Chat = new ChatLog( this );
@ -146,10 +147,16 @@ namespace ClassicalSharp {
}
}
public void SetViewDistance( int distance ) {
public void SetViewDistance( int distance, bool save ) {
ViewDistance = distance;
Utils.LogDebug( "setting view distance to: " + distance );
Options.Set( OptionsKey.ViewDist, distance );
if( ViewDistance > MaxViewDistance )
ViewDistance = MaxViewDistance;
Utils.LogDebug( "setting view distance to: {0} ({1})", distance, ViewDistance );
if( save ) {
UserViewDistance = distance;
Options.Set( OptionsKey.ViewDist, distance );
}
Events.RaiseViewDistanceChanged();
UpdateProjection();
}

View File

@ -362,20 +362,20 @@ namespace ClassicalSharp {
for( int i = 0; i < viewDistances.Length; i++ ) {
int dist = viewDistances[i];
if( dist > game.ViewDistance ) {
game.SetViewDistance( dist ); return;
game.SetViewDistance( dist, true ); return;
}
}
game.SetViewDistance( viewDistances[0] );
game.SetViewDistance( viewDistances[0], true );
}
void CycleDistanceBackwards() {
for( int i = viewDistances.Length - 1; i >= 0; i-- ) {
int dist = viewDistances[i];
if( dist < game.ViewDistance ) {
game.SetViewDistance( dist ); return;
game.SetViewDistance( dist, true ); return;
}
}
game.SetViewDistance( viewDistances[viewDistances.Length - 1] );
game.SetViewDistance( viewDistances[viewDistances.Length - 1], true );
}
float fovIndex = -1;

View File

@ -55,7 +55,7 @@ namespace ClassicalSharp {
#region Reading
int cpeServerExtensionsCount;
bool sendHeldBlock, useMessageTypes, usingTexturePack;
bool sendHeldBlock, useMessageTypes;
static string[] clientExtensions = {
"ClickDistance", "CustomBlocks", "HeldBlock",
"EmoteFix", "TextHotKey", "ExtPlayerList",
@ -91,7 +91,7 @@ namespace ClassicalSharp {
} else if( extName == "PlayerClick" ) {
UsingPlayerClick = true;
} else if( extName == "EnvMapAppearance" && extVersion == 2 ) {
usingTexturePack = true;
handlers[(int)PacketId.CpeEnvSetMapApperance] = HandleCpeEnvSetMapAppearance2;
packetSizes[(int)PacketId.CpeEnvSetMapApperance] += 4;
} else if( extName == "LongerMessages" ) {
ServerSupportsPatialMessages = true;
@ -108,7 +108,7 @@ namespace ClassicalSharp {
SendPacket();
for( int i = 0; i < clientExtensions.Length; i++ ) {
string name = clientExtensions[i];
int version = (name == "ExtPlayerList") ? 2 : 1;
int version = (name == "ExtPlayerList" || name == "EnvMapAppearance") ? 2 : 1;
MakeExtEntry( name, version );
SendPacket();
}
@ -297,11 +297,6 @@ namespace ClassicalSharp {
game.Map.SetSidesBlock( (Block)reader.ReadUInt8() );
game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() );
game.Map.SetEdgeLevel( reader.ReadInt16() );
if( usingTexturePack ) {
// TODO: proper envmapappearance version 2 support
game.Map.SetCloudsLevel( reader.ReadInt16() );
short maxViewDist = reader.ReadInt16(); // TODO: what to do with this?
}
if( url == String.Empty ) {
TexturePackExtractor extractor = new TexturePackExtractor();
@ -321,6 +316,14 @@ namespace ClassicalSharp {
Utils.LogDebug( "Image url: " + url );
}
void HandleCpeEnvSetMapAppearance2() {
HandleCpeEnvSetMapApperance();
game.Map.SetCloudsLevel( reader.ReadInt16() );
short maxViewDist = reader.ReadInt16();
game.MaxViewDistance = maxViewDist <= 0 ? 32768 : maxViewDist;
game.SetViewDistance( game.UserViewDistance, false );
}
void DownloadTexturePack( WarningScreen screen ) {
DownloadTexturePack( ((string)screen.Metadata).Substring( 3 ) );
}
@ -331,9 +334,7 @@ namespace ClassicalSharp {
if( !game.AcceptedUrls.HasAccepted( url ) )
game.AcceptedUrls.AddAccepted( url );
// NOTE: This is entirely against the original CPE specification, but we
// do it here as a convenience until EnvMapAppearance v2 is more widely adopted.
if( usingTexturePack || url.EndsWith( ".zip" ) )
if( url.EndsWith( ".zip" ) )
game.AsyncDownloader.DownloadData( url, true, "texturePack", lastModified );
else
game.AsyncDownloader.DownloadImage( url, true, "terrain", lastModified );

View File

@ -261,7 +261,8 @@ namespace ClassicalSharp {
const double targetTime = (1.0 / 30) + 0.01;
void UpdateChunks( double deltaTime ) {
int chunksUpdatedThisFrame = 0;
int adjViewDistSqr = ( game.ViewDistance + 14 ) * ( game.ViewDistance + 14 );
int viewDist = game.ViewDistance < 16 ? 16 : game.ViewDistance;
int adjViewDistSqr = (viewDist + 24) * (viewDist + 24);
chunksTarget += deltaTime < targetTime ? 1 : -1; // build more chunks if 30 FPS or over, otherwise slowdown.
Utils.Clamp( ref chunksTarget, 4, 12 );

View File

@ -219,10 +219,10 @@ namespace ClassicalSharp.Renderers {
z2 = z1 + axisSize;
if( z2 > endZ ) z2 = endZ;
vertices[i++] = new VertexPos3fTex2fCol4b( x1, y, z1, x1 / 2048f + offset, z1 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x1, y, z2, x1 / 2048f + offset, z2 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x2, y, z2, x2 / 2048f + offset, z2 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x2, y, z1, x2 / 2048f + offset, z1 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x1, y + 0.1f, z1, x1 / 2048f + offset, z1 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x1, y + 0.1f, z2, x1 / 2048f + offset, z2 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x2, y + 0.1f, z2, x2 / 2048f + offset, z2 / 2048f + offset, col );
vertices[i++] = new VertexPos3fTex2fCol4b( x2, y + 0.1f, z1, x2 / 2048f + offset, z1 / 2048f + offset, col );
}
}
}