From 9e341c875e7d8fe527f1307c79cf20525facc80c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 21 May 2015 18:23:07 +1000 Subject: [PATCH] Don't recreate block textures unless necessary, combine MakeEdgeTexture and MakeSideTexture into MakeTexture. --- Network/NetworkProcessor.cs | 4 ---- Rendering/MapEnvRenderer.cs | 37 ++++++++++++++++++------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Network/NetworkProcessor.cs b/Network/NetworkProcessor.cs index ab3f10e3c..d58cd88eb 100644 --- a/Network/NetworkProcessor.cs +++ b/Network/NetworkProcessor.cs @@ -115,10 +115,6 @@ namespace ClassicalSharp { 8, 86, 2, 4, 66, 69, 2, 8, 138, }; - // TODO: Finish implementing CPE - // === CPE support list === - // TextHotKey : unlikely - // ExtPlayerList : yes (only version 1, not 2) static string[] clientExtensions = new string[] { "EmoteFix", "ClickDistance", "HeldBlock", "BlockPermissions", "SelectionCuboid", "MessageTypes", "CustomBlocks", "EnvColors", diff --git a/Rendering/MapEnvRenderer.cs b/Rendering/MapEnvRenderer.cs index 761f29e1a..e2e0eb135 100644 --- a/Rendering/MapEnvRenderer.cs +++ b/Rendering/MapEnvRenderer.cs @@ -35,8 +35,8 @@ namespace ClassicalSharp { Window.TerrainAtlasChanged += ResetTextures; Graphics = Window.Graphics; - MakeEdgeTexture(); - MakeSideTexture(); + MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, Map.EdgeBlock ); + MakeTexture( ref sideTexId, ref lastSideTexLoc, Map.SidesBlock ); ResetSidesAndEdges( null, null ); } @@ -78,8 +78,8 @@ namespace ClassicalSharp { Graphics.DeleteVb( sidesVboId ); Graphics.DeleteVb( edgesVboId ); sidesVboId = edgesVboId = -1; - MakeEdgeTexture(); - MakeSideTexture(); + MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, Map.EdgeBlock ); + MakeTexture( ref sideTexId, ref lastSideTexLoc, Map.SidesBlock ); } void OnNewMapLoaded( object sender, EventArgs e ) { @@ -89,17 +89,18 @@ namespace ClassicalSharp { void EnvVariableChanged( object sender, EnvVariableEventArgs e ) { if( e.Variable == EnvVariable.EdgeBlock ) { - MakeEdgeTexture(); + MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, Map.EdgeBlock ); } else if( e.Variable == EnvVariable.SidesBlock ) { - MakeSideTexture(); + MakeTexture( ref sideTexId, ref lastSideTexLoc, Map.SidesBlock ); } else if( e.Variable == EnvVariable.WaterLevel ) { ResetSidesAndEdges( null, null ); } } void ResetTextures( object sender, EventArgs e ) { - MakeEdgeTexture(); - MakeSideTexture(); + lastEdgeTexLoc = lastSideTexLoc = -1; + MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, Map.EdgeBlock ); + MakeTexture( ref sideTexId, ref lastSideTexLoc, Map.SidesBlock ); } void ResetSidesAndEdges( object sender, EventArgs e ) { @@ -256,17 +257,15 @@ namespace ClassicalSharp { #endregion - void MakeEdgeTexture() { - int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)Map.EdgeBlock, TileSide.Top ); - Window.Graphics.DeleteTexture( ref edgeTexId ); - edgeTexId = Window.TerrainAtlas.LoadTextureElement( texLoc ); - } - - void MakeSideTexture() { - int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)Map.SidesBlock, TileSide.Top ); - Window.Graphics.DeleteTexture( ref sideTexId ); - sideTexId = Window.TerrainAtlas.LoadTextureElement( texLoc ); - } + int lastEdgeTexLoc, lastSideTexLoc; + void MakeTexture( ref int texId, ref int lastTexLoc, Block block ) { + int texLoc = Window.BlockInfo.GetOptimTextureLoc( (byte)block, TileSide.Top ); + if( texLoc != lastTexLoc ) { + lastTexLoc = texLoc; + Window.Graphics.DeleteTexture( ref texId ); + texId = Window.TerrainAtlas.LoadTextureElement( texLoc ); + } + } void DrawXPlane( int x, int z1, int z2, int y1, int y2, FastColour col, VertexPos3fTex2fCol4b[] vertices ) { TextureRectangle rec = new TextureRectangle( 0, 0, z2 - z1, y2 - y1 );