Don't update particles every frame, bump to 0.4.

This commit is contained in:
UnknownShadow200 2014-12-29 09:48:40 +11:00
parent 481029572b
commit e1ba6f7b11
5 changed files with 61 additions and 51 deletions

View File

@ -11,14 +11,15 @@ namespace ClassicalSharp.Particles {
public double Lifetime = 0;
public Game Window;
public int Id;
protected Vector3 lastPos, nextPos;
public abstract void Render( double delta, VertexPos3fTex2f[] vertices, ref int index );
public abstract void Render( double delta, float t, VertexPos3fTex2f[] vertices, ref int index );
public abstract void Dispose();
public Particle( Game window, Vector3 pos, Vector3 velocity, int id, double lifetime ) {
Window = window;
Position = pos;
Position = lastPos = nextPos = pos;
Velocity = velocity;
Id = id;
Lifetime = lifetime;
@ -42,7 +43,8 @@ namespace ClassicalSharp.Particles {
maxY = Position.Y;
}
public override void Render( double delta, VertexPos3fTex2f[] vertices, ref int index ) {
public override void Render( double delta, float t, VertexPos3fTex2f[] vertices, ref int index ) {
Position = Vector3.Lerp( lastPos, nextPos, t );
float x1 = Position.X, y1 = Position.Y, z1 = Position.Z,
x2 = Position.X + Size.X, y2 = Position.Y + Size.Y;
vertices[index++] = new VertexPos3fTex2f( x1, y1, z1, Rectangle.U1, Rectangle.V2 );
@ -55,6 +57,7 @@ namespace ClassicalSharp.Particles {
}
public override bool Tick( double delta ) {
lastPos = Position = nextPos;
Velocity.Y -= gravity * (float)delta;
int startY = (int)Math.Floor( Position.Y );
Position += Velocity * (float)delta;
@ -74,19 +77,19 @@ namespace ClassicalSharp.Particles {
for( int y = startY; y >= endY; y-- ) {
if( y < 0 ) {
return CollideWithGround( 0 ) ? true : base.Tick( delta );
//break;
}
byte block = GetBlock( (int)Position.X, y, (int)Position.Z );
if( block == 0 || Window.BlockInfo.IsSprite( block ) || Window.BlockInfo.IsLiquid( block ) )
continue;
float groundHeight = y + Window.BlockInfo.BlockHeight( block );
float groundHeight = y + Window.BlockInfo.BlockHeight( block );
if( Position.Y < groundHeight ) {
return CollideWithGround( groundHeight ) ? true : base.Tick( delta );
//break;
}
}
}
nextPos = Position;
Position = lastPos;
return base.Tick( delta );
}
@ -106,6 +109,8 @@ namespace ClassicalSharp.Particles {
Position.Y = y;
maxY = y;
Velocity = Vector3.Zero;
nextPos = Position;
Position = lastPos;
return false;
}

View File

@ -7,7 +7,7 @@ namespace ClassicalSharp.Particles {
public class ParticleManager {
List<TerrainParticle> particles = new List<TerrainParticle>();
List<Particle> particles = new List<Particle>();
public Game Window;
public IGraphicsApi Graphics;
@ -16,19 +16,13 @@ namespace ClassicalSharp.Particles {
Graphics = window.Graphics;
}
public void Render( double delta ) {
public void Render( double delta, float t ) {
if( particles.Count == 0 ) return;
VertexPos3fTex2f[] vertices = new VertexPos3fTex2f[particles.Count * 6];
int index = 0;
for( int i = 0; i < particles.Count; i++ ) {
Particle particle = particles[i];
particle.Render( delta, vertices, ref index );
if( particle.Tick( delta ) ) {
particles.RemoveAt( i );
i--;
particle.Dispose();
}
particles[i].Render( delta, t, vertices, ref index );
}
Graphics.Texturing = true;
@ -39,6 +33,17 @@ namespace ClassicalSharp.Particles {
Graphics.Texturing = false;
}
public void Tick( double delta ) {
for( int i = 0; i < particles.Count; i++ ) {
Particle particle = particles[i];
if( particle.Tick( delta ) ) {
particles.RemoveAt( i );
i--;
particle.Dispose();
}
}
}
int particleId = 0;
public void BreakBlockEffect( Vector3I position, byte block ) {
Vector3 startPos = new Vector3( position.X, position.Y, position.Z );

View File

@ -226,6 +226,7 @@ namespace ClassicalSharp {
Network.Tick( ticksPeriod );
LocalPlayer.Tick( ticksPeriod );
Camera.Tick( ticksPeriod );
ParticleManager.Tick( ticksPeriod );
for( int i = 0; i < NetPlayers.Length; i++ ) {
if( NetPlayers[i] != null ) {
NetPlayers[i].Tick( ticksPeriod );
@ -249,8 +250,9 @@ namespace ClassicalSharp {
bool visible = activeScreen == null || !activeScreen.BlocksWorld;
if( visible ) {
//EnvRenderer.EnableAmbientLighting();
RenderPlayers( e.Time );
ParticleManager.Render( e.Time );
float t = (float)( ticksAccumulator / ticksPeriod );
RenderPlayers( e.Time, t );
ParticleManager.Render( e.Time, t );
SelectedPos = Camera.GetPickedPos(); // TODO: only pick when necessary
Picking.Render( e.Time );
EnvRenderer.Render( e.Time );
@ -282,9 +284,8 @@ namespace ClassicalSharp {
SwapBuffers();
}
void RenderPlayers( double deltaTime ) {
//Graphics.AlphaTest = true;
float t = (float)( ticksAccumulator / ticksPeriod );
void RenderPlayers( double deltaTime, float t ) {
//Graphics.AlphaTest = true;
for( int i = 0; i < NetPlayers.Length; i++ ) {
if( NetPlayers[i] != null ) {
NetPlayers[i].Render( deltaTime, t );

View File

@ -19,7 +19,7 @@ namespace ClassicalSharp {
public static class Utils {
public static string AppName = "ClassicalSharp 0.3";
public static string AppName = "ClassicalSharp 0.4";
public static int NextPowerOf2( int value ) {
int next = 1;

View File

@ -1,30 +1,29 @@
ClassicalSharp is a custom Minecraft Classic client written in C#.
It is not affiliated with (or supported by) Mojang AB, Minecraft, or Microsoft in any way.
=== What ClassicalSharp is ===
* Works with both Minecraft.net and ClassiCube.net
* Lightweight, minimal memory usage compared to standard client.
* Should work with effectively all graphics cards that support OpenGL.
=== What ClassicalSharp is not ===
* It does not work with 'modern/premium' minecraft servers.
* It does not provide singleplayer support.
=== Requirements ===
* ClassicalSharp requires .NET Framework 2.0. (Vista and above already include later versions of the .NET Framework)
* Mono should also work in theory, but I have not tested that.
* You will need to put "terrain.png","clouds.png", and "char.png" into the same directory as the client.
=== Todo list ===
* Texture animations.
* Proper SelectionBox sorting.
* DirectX API support.
* Some of the remaining CPE extensions.
* Test that Mojang Accounts work properly.
* Fix issues with framerate limiting not working properly on same cards.
(will require 'sleeping'of main thread)
ClassicalSharp is a custom Minecraft Classic client written in C#.
It is not affiliated with (or supported by) Mojang AB, Minecraft, or Microsoft in any way.
=== What ClassicalSharp is ===
* Works with both Minecraft.net and ClassiCube.net
* Lightweight, minimal memory usage compared to standard client.
* Should work with effectively all graphics cards that support OpenGL.
=== What ClassicalSharp is not ===
* It does not work with 'modern/premium' minecraft servers.
* It does not provide singleplayer support.
=== Requirements ===
* ClassicalSharp requires .NET Framework 2.0. (Vista and above already include later versions of the .NET Framework)
* Mono should also work in theory, but I have not tested that.
=== Todo list ===
* Texture animations.
* Proper SelectionBox sorting.
* DirectX API support.
* Some of the remaining CPE extensions.
* Test that Mojang Accounts work properly.
* Fix issues with framerate limiting not working properly on same cards.
(will require 'sleeping'of main thread)