diff --git a/Model/BlockModel.cs b/Model/BlockModel.cs index 5a481acd7..5dae1880a 100644 --- a/Model/BlockModel.cs +++ b/Model/BlockModel.cs @@ -9,7 +9,6 @@ namespace ClassicalSharp.Model { public class BlockModel : IModel { byte block = (byte)Block.Air; - int vb; public BlockModel( Game window ) : base( window ) { vertices = new VertexPos3fTex2fCol4b[6 * 6]; vb = window.Graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 6 * 6 ); diff --git a/Model/ChickenModel.cs b/Model/ChickenModel.cs index d65ccc846..a91c28a29 100644 --- a/Model/ChickenModel.cs +++ b/Model/ChickenModel.cs @@ -50,7 +50,8 @@ namespace ClassicalSharp.Model { const float y1 = 0f, y2 = 0.3125f, z2 = 0.0625f, z1 = -0.125f; YPlane( 32, 0, 3, 3, x2, x1, z1, z2, y1, false ); // bottom feet ZPlane( 36, 3, 1, 5, legX1, legX2, y1, y2, z2, false ); // vertical part of leg - return new ModelPart( vertices, 2 * 6, graphics ); + int vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, 2 * 6 ); + return new ModelPart( vb, 0, 2 * 6, graphics ); } public override float NameYOffset { diff --git a/Model/IModel.cs b/Model/IModel.cs index 7d73d1329..00650c050 100644 --- a/Model/IModel.cs +++ b/Model/IModel.cs @@ -49,22 +49,33 @@ namespace ClassicalSharp.Model { protected FastColour col = new FastColour( 178, 178, 178 ); protected VertexPos3fTex2fCol4b[] vertices; protected int index = 0; + protected int vb = 0; protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH, float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) { - index = 0; + // TODO: temp hack until we change other classes. + if( !( this is PlayerModel ) ) { + index = 0; + } YPlane( x + sidesW, y, endsW, endsH, x2, x1, z2, z1, y2, _64x64 ); // top YPlane( x + sidesW + bodyW, y, endsW, endsH, x2, x1, z1, z2, y1, _64x64 ); // bottom ZPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, y1, y2, z1, _64x64 ); // front ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // left XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // right - return new ModelPart( vertices, 6 * 6, graphics ); + if( !( this is PlayerModel ) ) { + int vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, 6 * 6 ); + return new ModelPart( vb, 0, 6 * 6, graphics ); + } else { + return new ModelPart( this.vb, index - 36, 6 * 6, graphics ); + } } protected ModelPart MakeRotatedPart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH, float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) { - index = 0; + if( !( this is PlayerModel ) ) { + index = 0; + } YPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, z1, z2, y2, _64x64 ); // top YPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, z1, z2, y1, _64x64 ); // bottom ZPlane( x + sidesW, y, endsW, endsH, x2, x1, y1, y2, z1, _64x64 ); // front @@ -79,7 +90,12 @@ namespace ClassicalSharp.Model { vertex.Y = z; vertices[i] = vertex; } - return new ModelPart( vertices, 6 * 6, graphics ); + if( !( this is PlayerModel ) ) { + int vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, 6 * 6 ); + return new ModelPart( vb, 0, 6 * 6, graphics ); + } else { + return new ModelPart( this.vb, index - 36, 6 * 6, graphics ); + } } protected static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) { diff --git a/Model/ModelPart.cs b/Model/ModelPart.cs index 9ac03108f..99265e510 100644 --- a/Model/ModelPart.cs +++ b/Model/ModelPart.cs @@ -6,17 +6,19 @@ namespace ClassicalSharp { public class ModelPart { public int VbId; + public int Offset = 0; public int Count; public IGraphicsApi Graphics; - public ModelPart( VertexPos3fTex2fCol4b[] vertices, int count, IGraphicsApi graphics ) { + public ModelPart( int vb, int offset, int count, IGraphicsApi graphics ) { + Offset = offset; Count = count; Graphics = graphics; - VbId = Graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, count ); + VbId = vb; } public void Render() { - Graphics.DrawVb( DrawMode.Triangles, VertexFormat.Pos3fTex2fCol4b, VbId, 0, Count ); + Graphics.DrawVb( DrawMode.Triangles, VertexFormat.Pos3fTex2fCol4b, VbId, Offset, Count ); } public void Dispose() { diff --git a/Model/PlayerModel.cs b/Model/PlayerModel.cs index c24608dc6..7ddc18aed 100644 --- a/Model/PlayerModel.cs +++ b/Model/PlayerModel.cs @@ -10,7 +10,7 @@ namespace ClassicalSharp.Model { ModelSet Set64x32, Set64x64, Set64x64Slim; public PlayerModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[6 * 6]; + vertices = new VertexPos3fTex2fCol4b[( 6 * 6 ) * 7 * 3]; Set64x32 = new ModelSet(); Set64x32.Head = MakeHead( false ); Set64x32.Torso = MakeTorso( false ); @@ -37,6 +37,11 @@ namespace ClassicalSharp.Model { Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.4375f, 3, true ); Set64x64Slim.RightArm = MakeRightArm( 40, 16, 0.25f, 0.4375f, 3, true ); Set64x64Slim.Hat = MakeHat( true ); + + vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b ); + Set64x32.SetVb( vb ); + Set64x64.SetVb( vb ); + Set64x64Slim.SetVb( vb ); vertices = null; using( Bitmap bmp = new Bitmap( "char.png" ) ) { @@ -98,9 +103,7 @@ namespace ClassicalSharp.Model { } public override void Dispose() { - Set64x32.Dispose(); - Set64x64.Dispose(); - Set64x64Slim.Dispose(); + graphics.DeleteVb( vb ); graphics.DeleteTexture( ref DefaultTexId ); } @@ -108,14 +111,9 @@ namespace ClassicalSharp.Model { public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat; - public void Dispose() { - Hat.Dispose(); - RightArm.Dispose(); - LeftArm.Dispose(); - RightLeg.Dispose(); - LeftLeg.Dispose(); - Torso.Dispose(); - Head.Dispose(); + public void SetVb( int vb ) { + Head.VbId = Torso.VbId = LeftLeg.VbId = RightLeg.VbId = + LeftArm.VbId = RightArm.VbId = Hat.VbId = vb; } } }