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 ) {
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;
}

View File

@ -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 ) {

View File

@ -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 {