Minor performance optimisations.

This commit is contained in:
UnknownShadow200 2015-02-25 06:40:27 +11:00
parent b673944a61
commit 69a8d761bf
3 changed files with 10 additions and 18 deletions

13
Map.cs
View File

@ -93,25 +93,22 @@ namespace ClassicalSharp {
public int GetLightHeight( int x, int z ) { public int GetLightHeight( int x, int z ) {
int index = ( x * Length ) + z; int index = ( x * Length ) + z;
int height = heightmap[index]; int height = heightmap[index];
return height == short.MaxValue ? CalcHeightAt( x, maxY, z, index ) : height;
if( height == short.MaxValue ) {
height = CalcHeightAt( x, maxY, z, index );
}
return height;
} }
int CalcHeightAt( int x, int maxY, int z, int index ) { int CalcHeightAt( int x, int maxY, int z, int index ) {
heightmap[index] = -1;
int mapIndex = ( maxY * Length + z ) * Width + x; int mapIndex = ( maxY * Length + z ) * Width + x;
for( int y = maxY; y >= 0; y-- ) { for( int y = maxY; y >= 0; y-- ) {
byte block = GetBlock( mapIndex ); byte block = mapData[mapIndex];
if( Window.BlockInfo.BlocksLight( block ) ) { if( Window.BlockInfo.BlocksLight( block ) ) {
heightmap[index] = (short)y; heightmap[index] = (short)y;
return y; return y;
} }
mapIndex -= oneY; mapIndex -= oneY;
} }
heightmap[index] = -1;
return -1; return -1;
} }

View File

@ -102,15 +102,13 @@ namespace ClassicalSharp {
} }
int GetLightHeight( int x, int z ) { int GetLightHeight( int x, int z ) {
int y = map.GetLightHeight( x, z ); return map.GetLightHeight( x, z );
if( y == -1 ) return -1;
return y;
} }
int GetLightHeightAdj( int x, int z ) { int GetLightHeightAdj( int x, int z ) {
int y = map.GetLightHeight( x, z ); int y = map.GetLightHeight( x, z );
if( y == -1 ) return -1; return y == -1 ? -1 :
return BlockInfo.BlockHeight( map.GetBlock( x, y, z ) ) == 1 ? y : y - 1; ( BlockInfo.BlockHeight( map.GetBlock( x, y, z ) ) == 1 ? y : y - 1 );
} }
protected override ChunkDrawInfo GetChunkInfo( int x, int y, int z ) { protected override ChunkDrawInfo GetChunkInfo( int x, int y, int z ) {

View File

@ -3,13 +3,10 @@ using ClassicalSharp.GraphicsAPI;
using OpenTK; using OpenTK;
namespace ClassicalSharp { namespace ClassicalSharp {
// TODO: optimise chunk rendering // TODO: optimise chunk rendering
// --> reduce the two passes: liquid pass only needs 1 small texture // --> reduce the two passes: liquid pass only needs 1 small texture
// |--> divide into 'solid', 'transparent', 'translucent passes' // --> use indices.
// |--> don't render solid back facing polygons. may help with low performance computers.
// |--> use indices.
public class MapRenderer : IDisposable { public class MapRenderer : IDisposable {
struct Point3S { struct Point3S {