mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
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:
parent
66e0bc887c
commit
b0c7f5f55a
@ -80,13 +80,18 @@ namespace ClassicalSharp.Particles {
|
|||||||
public void BreakBlockEffect( Vector3I position, byte block ) {
|
public void BreakBlockEffect( Vector3I position, byte block ) {
|
||||||
Vector3 startPos = new Vector3( position.X, position.Y, position.Z );
|
Vector3 startPos = new Vector3( position.X, position.Y, position.Z );
|
||||||
int texLoc = game.BlockInfo.GetTextureLoc( block, TileSide.Left );
|
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 minBB = game.BlockInfo.MinBB[block];
|
||||||
Vector3 maxBB = game.BlockInfo.MaxBB[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++ ) {
|
for( int i = 0; i < 25; i++ ) {
|
||||||
double velX = rnd.NextDouble() * 0.8 - 0.4; // [-0.4, 0.4]
|
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,
|
Vector3 pos = startPos + new Vector3( 0.5f + (float)xOffset,
|
||||||
(float)yOffset, 0.5f + (float)zOffset );
|
(float)yOffset, 0.5f + (float)zOffset );
|
||||||
|
|
||||||
TextureRec particleRec = rec;
|
TextureRec rec = baseRec;
|
||||||
particleRec.U1 = rec.U1 + rnd.Next( 0, cellsCount ) * elemSize;
|
rec.U1 = baseRec.U1 + rnd.Next( minU, maxU ) * uvScale;
|
||||||
particleRec.V1 = rec.V1 + rnd.Next( 0, cellsCount ) * elemSize;
|
rec.V1 = baseRec.V1 + rnd.Next( minV, maxV ) * uvScale;
|
||||||
particleRec.U2 = particleRec.U1 + elemSize;
|
rec.U2 = Math.Min( baseRec.U1 + maxU * uvScale, rec.U1 + elemSize );
|
||||||
particleRec.V2 = particleRec.V1 + elemSize;
|
rec.V2 = Math.Min( baseRec.V1 + maxV * uvScale, rec.V1 + elemSize );
|
||||||
double life = 1.5 - rnd.NextDouble();
|
double life = 1.5 - rnd.NextDouble();
|
||||||
|
|
||||||
TerrainParticle p = AddParticle( terrainParticles, ref terrainCount, false );
|
TerrainParticle p = AddParticle( terrainParticles, ref terrainCount, false );
|
||||||
p.ResetState( pos, velocity, life );
|
p.ResetState( pos, velocity, life );
|
||||||
p.rec = particleRec;
|
p.rec = rec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,9 @@ namespace OpenTK.Platform.Windows {
|
|||||||
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
||||||
static extern UIntPtr GetWindowLongPtr(IntPtr hWnd, GetWindowLongOffsets nIndex);
|
static extern UIntPtr GetWindowLongPtr(IntPtr hWnd, GetWindowLongOffsets nIndex);
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
|
||||||
|
internal static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
[DllImport("User32.dll"), SuppressUnmanagedCodeSecurity]
|
[DllImport("User32.dll"), SuppressUnmanagedCodeSecurity]
|
||||||
internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);
|
internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);
|
||||||
|
|
||||||
|
@ -699,6 +699,9 @@ namespace OpenTK.Platform.Windows
|
|||||||
API.TranslateMessage(ref msg);
|
API.TranslateMessage(ref msg);
|
||||||
API.DispatchMessage(ref msg);
|
API.DispatchMessage(ref msg);
|
||||||
}
|
}
|
||||||
|
IntPtr foreground = API.GetForegroundWindow();
|
||||||
|
if( foreground != IntPtr.Zero )
|
||||||
|
focused = foreground == window.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWindowInfo WindowInfo {
|
public IWindowInfo WindowInfo {
|
||||||
|
@ -33,7 +33,7 @@ namespace OpenTK.Platform.Windows {
|
|||||||
/// \internal
|
/// \internal
|
||||||
/// <summary>Describes a win32 window.</summary>
|
/// <summary>Describes a win32 window.</summary>
|
||||||
public sealed class WinWindowInfo : IWindowInfo {
|
public sealed class WinWindowInfo : IWindowInfo {
|
||||||
IntPtr handle, dc;
|
internal IntPtr handle, dc;
|
||||||
WinWindowInfo parent;
|
WinWindowInfo parent;
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user