From 69a8d761bf90706636a2cc434423536eb65a3f4d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 25 Feb 2015 06:40:27 +1100 Subject: [PATCH] Minor performance optimisations. --- Map.cs | 13 +++++-------- MeshBuilders/ChunkMeshBuilderTex2Col4.cs | 8 +++----- Rendering/MapRenderer.cs | 7 ++----- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Map.cs b/Map.cs index 465f9a858..50898622f 100644 --- a/Map.cs +++ b/Map.cs @@ -93,25 +93,22 @@ namespace ClassicalSharp { public int GetLightHeight( int x, int z ) { int index = ( x * Length ) + z; - int height = heightmap[index]; - - if( height == short.MaxValue ) { - height = CalcHeightAt( x, maxY, z, index ); - } - return height; + int height = heightmap[index]; + return height == short.MaxValue ? CalcHeightAt( x, maxY, z, index ) : height; } int CalcHeightAt( int x, int maxY, int z, int index ) { - heightmap[index] = -1; int mapIndex = ( maxY * Length + z ) * Width + x; for( int y = maxY; y >= 0; y-- ) { - byte block = GetBlock( mapIndex ); + byte block = mapData[mapIndex]; if( Window.BlockInfo.BlocksLight( block ) ) { heightmap[index] = (short)y; return y; } mapIndex -= oneY; } + + heightmap[index] = -1; return -1; } diff --git a/MeshBuilders/ChunkMeshBuilderTex2Col4.cs b/MeshBuilders/ChunkMeshBuilderTex2Col4.cs index ed395d177..3304f304c 100644 --- a/MeshBuilders/ChunkMeshBuilderTex2Col4.cs +++ b/MeshBuilders/ChunkMeshBuilderTex2Col4.cs @@ -102,15 +102,13 @@ namespace ClassicalSharp { } int GetLightHeight( int x, int z ) { - int y = map.GetLightHeight( x, z ); - if( y == -1 ) return -1; - return y; + return map.GetLightHeight( x, z ); } int GetLightHeightAdj( int x, int z ) { int y = map.GetLightHeight( x, z ); - if( y == -1 ) return -1; - return BlockInfo.BlockHeight( map.GetBlock( x, y, z ) ) == 1 ? y : y - 1; + return y == -1 ? -1 : + ( BlockInfo.BlockHeight( map.GetBlock( x, y, z ) ) == 1 ? y : y - 1 ); } protected override ChunkDrawInfo GetChunkInfo( int x, int y, int z ) { diff --git a/Rendering/MapRenderer.cs b/Rendering/MapRenderer.cs index 241873b8f..4c61ca5b4 100644 --- a/Rendering/MapRenderer.cs +++ b/Rendering/MapRenderer.cs @@ -3,13 +3,10 @@ using ClassicalSharp.GraphicsAPI; using OpenTK; namespace ClassicalSharp { - - + // TODO: optimise chunk rendering // --> reduce the two passes: liquid pass only needs 1 small texture - // |--> divide into 'solid', 'transparent', 'translucent passes' - // |--> don't render solid back facing polygons. may help with low performance computers. - // |--> use indices. + // --> use indices. public class MapRenderer : IDisposable { struct Point3S {