Now particle block break spawning works properly with non 0 minX/Y/Z and non 1 maxX/Z, also fix client taking focus even when not the foreground window (Thanks Joseph)

This commit is contained in:
UnknownShadow200 2015-12-23 23:05:09 +11:00
parent 66e0bc887c
commit b0c7f5f55a
4 changed files with 22 additions and 11 deletions

View File

@ -80,13 +80,18 @@ namespace ClassicalSharp.Particles {
public void BreakBlockEffect( Vector3I position, byte block ) {
Vector3 startPos = new Vector3( position.X, position.Y, position.Z );
int texLoc = game.BlockInfo.GetTextureLoc( block, TileSide.Left );
TextureRec rec = game.TerrainAtlas.GetTexRec( texLoc );
TextureRec baseRec = game.TerrainAtlas.GetTexRec( texLoc );
const float uvScale = (1/16f) * TerrainAtlas2D.invElementSize;
const float elemSize = 4 * uvScale;
const float invSize = TerrainAtlas2D.invElementSize;
const int cellsCount = (int)((1/4f) / invSize);
const float elemSize = invSize / 4f;
Vector3 minBB = game.BlockInfo.MinBB[block];
Vector3 maxBB = game.BlockInfo.MaxBB[block];
int minU = Math.Min( (int)(minBB.X * 16), (int)(minBB.Z * 16) );
int maxU = Math.Min( (int)(maxBB.X * 16), (int)(maxBB.Z * 16) );
int minV = (int)(minBB.Y * 16), maxV = (int)(maxBB.Y * 16);
// This way we can avoid creating particles which outside the bounds and need to be clamped
if( minU < 13 && maxU > 13 ) maxU = 13;
if( minV < 13 && maxV > 13 ) maxV = 13;
for( int i = 0; i < 25; i++ ) {
double velX = rnd.NextDouble() * 0.8 - 0.4; // [-0.4, 0.4]
@ -100,16 +105,16 @@ namespace ClassicalSharp.Particles {
Vector3 pos = startPos + new Vector3( 0.5f + (float)xOffset,
(float)yOffset, 0.5f + (float)zOffset );
TextureRec particleRec = rec;
particleRec.U1 = rec.U1 + rnd.Next( 0, cellsCount ) * elemSize;
particleRec.V1 = rec.V1 + rnd.Next( 0, cellsCount ) * elemSize;
particleRec.U2 = particleRec.U1 + elemSize;
particleRec.V2 = particleRec.V1 + elemSize;
TextureRec rec = baseRec;
rec.U1 = baseRec.U1 + rnd.Next( minU, maxU ) * uvScale;
rec.V1 = baseRec.V1 + rnd.Next( minV, maxV ) * uvScale;
rec.U2 = Math.Min( baseRec.U1 + maxU * uvScale, rec.U1 + elemSize );
rec.V2 = Math.Min( baseRec.V1 + maxV * uvScale, rec.V1 + elemSize );
double life = 1.5 - rnd.NextDouble();
TerrainParticle p = AddParticle( terrainParticles, ref terrainCount, false );
p.ResetState( pos, velocity, life );
p.rec = particleRec;
p.rec = rec;
}
}

View File

@ -58,6 +58,9 @@ namespace OpenTK.Platform.Windows {
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
static extern UIntPtr GetWindowLongPtr(IntPtr hWnd, GetWindowLongOffsets nIndex);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll"), SuppressUnmanagedCodeSecurity]
internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);

View File

@ -699,6 +699,9 @@ namespace OpenTK.Platform.Windows
API.TranslateMessage(ref msg);
API.DispatchMessage(ref msg);
}
IntPtr foreground = API.GetForegroundWindow();
if( foreground != IntPtr.Zero )
focused = foreground == window.handle;
}
public IWindowInfo WindowInfo {

View File

@ -33,7 +33,7 @@ namespace OpenTK.Platform.Windows {
/// \internal
/// <summary>Describes a win32 window.</summary>
public sealed class WinWindowInfo : IWindowInfo {
IntPtr handle, dc;
internal IntPtr handle, dc;
WinWindowInfo parent;
bool disposed;