Lazily allocate weather heightmap, also fix double texture warning screne not restoring the cursor (Thanks Zingan).

This commit is contained in:
UnknownShadow200 2016-01-09 21:45:25 +11:00
parent 5e29f5cd23
commit 6dbce98a67
4 changed files with 15 additions and 9 deletions

View File

@ -17,7 +17,7 @@ namespace ClassicalSharp {
this.body = body;
}
internal Screen lastScreen;
internal bool lastCursorVisible;
internal bool wasCursorVisible;
string title;
string[] body;
@ -92,8 +92,10 @@ namespace ClassicalSharp {
game.activeScreen = game.WarningScreens[0];
} else {
game.activeScreen = lastScreen;
if( game.CursorVisible != lastCursorVisible )
game.CursorVisible = lastCursorVisible;
if( game.CursorVisible != wasCursorVisible )
game.CursorVisible = wasCursorVisible;
if( game.activeScreen == null && game.CursorVisible )
game.CursorVisible = false;
}
}

View File

@ -197,6 +197,7 @@ namespace ClassicalSharp {
Culling.CalcFrustumEquations( ref Projection, ref modelView );
bool visible = activeScreen == null || !activeScreen.BlocksWorld;
if( Map.IsNotLoaded ) visible = false;
if( visible ) {
AxisLinesRenderer.Render( e.Time );
Players.RenderModels( Graphics, e.Time, t );
@ -352,10 +353,10 @@ namespace ClassicalSharp {
screen.lastScreen = activeScreen;
activeScreen = screen;
screen.lastCursorVisible = CursorVisible;
if( !CursorVisible) CursorVisible = true;
screen.wasCursorVisible = CursorVisible;
if( !CursorVisible ) CursorVisible = true;
} else {
screen.lastCursorVisible = WarningScreens[0].lastCursorVisible;
screen.wasCursorVisible = WarningScreens[0].wasCursorVisible;
}
WarningScreens.Add( screen );
screen.Init();

View File

@ -147,7 +147,7 @@ namespace ClassicalSharp {
void HandleLevelFinalise() {
game.SetNewScreen( null );
game.activeScreen = prevScreen;
if( prevScreen != null )
if( prevScreen != null && prevCursorVisible != game.CursorVisible )
game.CursorVisible = prevCursorVisible;
prevScreen = null;

View File

@ -29,6 +29,7 @@ namespace ClassicalSharp {
public void Render( double deltaTime ) {
Weather weather = map.Weather;
if( weather == Weather.Sunny ) return;
if( heightmap == null ) InitHeightmap();
graphics.Texturing = true;
graphics.BindTexture( weather == Weather.Rainy ? game.RainTexId : game.SnowTexId );
@ -102,7 +103,9 @@ namespace ClassicalSharp {
width = map.Width;
maxY = map.Height - 1;
oneY = length * width;
}
void InitHeightmap() {
heightmap = new short[map.Width * map.Length];
for( int i = 0; i < heightmap.Length; i++ ) {
heightmap[i] = short.MaxValue;
@ -148,7 +151,7 @@ namespace ClassicalSharp {
}
internal void UpdateHeight( int x, int y, int z, byte oldBlock, byte newBlock ) {
if( game.Map.IsNotLoaded ) return;
if( game.Map.IsNotLoaded || heightmap == null ) return;
bool didBlock = BlocksRain( oldBlock );
bool nowBlocks = BlocksRain( newBlock );
if( didBlock == nowBlocks ) return;