Optimise singleplayer water physics. (Thanks Fudgie)

This commit is contained in:
UnknownShadow200 2016-01-09 22:26:51 +11:00
parent 6dbce98a67
commit fcee4079ad
2 changed files with 30 additions and 31 deletions

View File

@ -366,7 +366,6 @@ namespace ClassicalSharp {
PerspectiveCamera oldCam = (PerspectiveCamera)Camera; PerspectiveCamera oldCam = (PerspectiveCamera)Camera;
if( Camera == firstPersonCam ) Camera = thirdPersonCam; if( Camera == firstPersonCam ) Camera = thirdPersonCam;
else if( Camera == thirdPersonCam ) Camera = forwardThirdPersonCam; else if( Camera == thirdPersonCam ) Camera = forwardThirdPersonCam;
//else if( Camera == forwardThirdPersonCam ) Camera = firstPersonZoomCam;
else Camera = firstPersonCam; else Camera = firstPersonCam;
if( !LocalPlayer.CanUseThirdPersonCamera || !LocalPlayer.HacksEnabled ) if( !LocalPlayer.CanUseThirdPersonCamera || !LocalPlayer.HacksEnabled )

View File

@ -11,6 +11,7 @@ namespace ClassicalSharp.Singleplayer {
Random rnd = new Random(); Random rnd = new Random();
BlockInfo info; BlockInfo info;
int width, length, height, oneY, volume; int width, length, height, oneY, volume;
int maxX, maxY, maxZ, maxWaterX, maxWaterY, maxWaterZ;
const uint tickMask = 0xF8000000; const uint tickMask = 0xF8000000;
const uint posMask = 0x07FFFFFF; const uint posMask = 0x07FFFFFF;
@ -93,9 +94,10 @@ namespace ClassicalSharp.Singleplayer {
void ResetMap( object sender, EventArgs e ) { void ResetMap( object sender, EventArgs e ) {
ClearQueuedEvents(); ClearQueuedEvents();
width = map.Width; width = map.Width; maxX = width - 1; maxWaterX = maxX - 2;
length = map.Length; height = map.Height; maxY = height - 1; maxWaterY = maxY - 2;
height = map.Height; length = map.Length; maxZ = length - 1; maxWaterZ = maxZ - 2;
oneY = width * length; oneY = width * length;
volume = height * width * length; volume = height * width * length;
} }
@ -114,18 +116,17 @@ namespace ClassicalSharp.Singleplayer {
void TickRandomBlocks() { void TickRandomBlocks() {
int xMax = width - 1, yMax = height - 1, zMax = length - 1; int xMax = width - 1, yMax = height - 1, zMax = length - 1;
for( int y = 0; y < height; y += 16 ) { for( int y = 0; y < height; y += 16 )
for( int z = 0; z < length; z += 16 ) { for( int z = 0; z < length; z += 16 )
for( int x = 0; x < width; x += 16 ) { for( int x = 0; x < width; x += 16 )
int lo = (y * length + z) * width + x; {
int hi = (Math.Min( yMax, y + 15 ) * length + Math.Min( zMax, z + 15 )) int lo = (y * length + z) * width + x;
* width + Math.Min( xMax, x + 15 ); int hi = (Math.Min( yMax, y + 15 ) * length + Math.Min( zMax, z + 15 ))
* width + Math.Min( xMax, x + 15 );
HandleBlock( rnd.Next( lo, hi ) );
HandleBlock( rnd.Next( lo, hi ) ); HandleBlock( rnd.Next( lo, hi ) );
HandleBlock( rnd.Next( lo, hi ) ); HandleBlock( rnd.Next( lo, hi ) );
} HandleBlock( rnd.Next( lo, hi ) );
}
} }
} }
@ -443,26 +444,25 @@ namespace ClassicalSharp.Singleplayer {
#region Sponge #region Sponge
void PlaceSponge( int x, int y, int z ) { void PlaceSponge( int x, int y, int z ) {
for( int yy = y - 2; yy <= y + 2; yy++ ) { for( int yy = y - 2; yy <= y + 2; yy++ )
for( int zz = z - 2; zz <= z + 2; zz++ ) { for( int zz = z - 2; zz <= z + 2; zz++ )
for( int xx = x - 2; xx <= x + 2; xx++ ) { for( int xx = x - 2; xx <= x + 2; xx++ )
byte block = map.SafeGetBlock( xx, yy, zz ); {
if( block == (byte)Block.Water || block == (byte)Block.StillWater ) byte block = map.SafeGetBlock( xx, yy, zz );
map.SetBlock( xx, yy, zz, (byte)Block.Air ); if( block == (byte)Block.Water || block == (byte)Block.StillWater )
} map.SetBlock( xx, yy, zz, (byte)Block.Air );
}
} }
} }
bool CheckIfSponge( int x, int y, int z ) { bool CheckIfSponge( int x, int y, int z ) {
for( int yy = y - 2; yy <= y + 2; yy++ ) { for( int yy = (y < 2 ? 0 : y - 2); yy <= (y > maxWaterY ? maxY : y + 2); yy++ )
for( int zz = z - 2; zz <= z + 2; zz++ ) { for( int zz = (z < 2 ? 0 : z - 2); zz <= (z > maxWaterZ ? maxZ : z + 2); zz++ )
for( int xx = x - 2; xx <= x + 2; xx++ ) { for( int xx = (x < 2 ? 0 : x - 2); xx <= (x > maxWaterX ? maxX : x + 2); xx++ )
byte block = map.SafeGetBlock( xx, yy, zz ); {
if( block == (byte)Block.Sponge ) return true; byte block = map.mapData[(yy * length + zz) * width + xx];
} if( block == (byte)Block.Sponge ) return true;
}
} }
return false; return false;
} }
#endregion #endregion