mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
Minor performance optimisations.
This commit is contained in:
parent
b673944a61
commit
69a8d761bf
13
Map.cs
13
Map.cs
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 ) {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user