From 75411303523458344bf2bfdb66b72f60d4725d07 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Sat, 1 Apr 2017 00:02:56 -0700 Subject: [PATCH 01/16] Allow IModel Render to be overridden by plugins. --- ClassicalSharp/Entities/Entity.cs | 2 +- ClassicalSharp/Entities/Model/IModel.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ClassicalSharp/Entities/Entity.cs b/ClassicalSharp/Entities/Entity.cs index b597f4a79..16423fc70 100644 --- a/ClassicalSharp/Entities/Entity.cs +++ b/ClassicalSharp/Entities/Entity.cs @@ -109,7 +109,7 @@ namespace ClassicalSharp.Entities { return game.World.SafeGetBlock(Vector3I.Floor(coords)); } - internal Matrix4 TransformMatrix(float scale, Vector3 pos) { + public Matrix4 TransformMatrix(float scale, Vector3 pos) { return Matrix4.RotateZ(-RotZ * Utils.Deg2Rad) * Matrix4.RotateX(-RotX * Utils.Deg2Rad) * diff --git a/ClassicalSharp/Entities/Model/IModel.cs b/ClassicalSharp/Entities/Model/IModel.cs index 7a54ed41e..8c585e5a9 100644 --- a/ClassicalSharp/Entities/Model/IModel.cs +++ b/ClassicalSharp/Entities/Model/IModel.cs @@ -99,7 +99,7 @@ namespace ClassicalSharp.Model { /// Sets up the state for, then renders an entity model, /// based on the given entity's position and orientation. - public void Render(Entity p) { + public virtual void Render(Entity p) { index = 0; pos = p.Position; if (Bobbing) pos.Y += p.anim.bobbingModel; From e665d60f5aa0eb9db981621a15312fd9391e82ac Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Sat, 1 Apr 2017 14:41:40 -0700 Subject: [PATCH 02/16] Revert "Allow IModel Render to be overridden by plugins." This reverts commit 75411303523458344bf2bfdb66b72f60d4725d07. --- ClassicalSharp/Entities/Entity.cs | 2 +- ClassicalSharp/Entities/Model/IModel.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ClassicalSharp/Entities/Entity.cs b/ClassicalSharp/Entities/Entity.cs index 16423fc70..b597f4a79 100644 --- a/ClassicalSharp/Entities/Entity.cs +++ b/ClassicalSharp/Entities/Entity.cs @@ -109,7 +109,7 @@ namespace ClassicalSharp.Entities { return game.World.SafeGetBlock(Vector3I.Floor(coords)); } - public Matrix4 TransformMatrix(float scale, Vector3 pos) { + internal Matrix4 TransformMatrix(float scale, Vector3 pos) { return Matrix4.RotateZ(-RotZ * Utils.Deg2Rad) * Matrix4.RotateX(-RotX * Utils.Deg2Rad) * diff --git a/ClassicalSharp/Entities/Model/IModel.cs b/ClassicalSharp/Entities/Model/IModel.cs index 8c585e5a9..7a54ed41e 100644 --- a/ClassicalSharp/Entities/Model/IModel.cs +++ b/ClassicalSharp/Entities/Model/IModel.cs @@ -99,7 +99,7 @@ namespace ClassicalSharp.Model { /// Sets up the state for, then renders an entity model, /// based on the given entity's position and orientation. - public virtual void Render(Entity p) { + public void Render(Entity p) { index = 0; pos = p.Position; if (Bobbing) pos.Y += p.anim.bobbingModel; From 42017ad59618ff433aa50179630385283a301be0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 5 Apr 2017 18:55:01 -0700 Subject: [PATCH 03/16] Made inventory switching re-bindable and fixed CRTL selecting in inventory screen closing inventory screen. Inventory switching(I.E. Pressing ALT in-game showing a second inventory) is now re-bindable. Pressing the CRTL keys should've allowed the user to select a block without the inventory screen closing, but this was not the case. Instead, that functionality was binded to the ALT keys. It has now been re-binded to the CRTL keys. --- .../2D/Screens/Inventory/InventoryScreen.Input.cs | 2 +- .../2D/Screens/Menu/KeyBindingsScreens.cs | 8 ++++---- ClassicalSharp/2D/Widgets/HotbarWidget.cs | 2 +- ClassicalSharp/Game/KeyMap.cs | 13 ++++++------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs b/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs index eac3c668e..536c78824 100644 --- a/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs +++ b/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs @@ -48,7 +48,7 @@ namespace ClassicalSharp.Gui.Screens { return true; } - bool hotbar = game.IsKeyDown(Key.AltLeft) || game.IsKeyDown(Key.AltRight); + bool hotbar = game.Input.ControlDown; if (!hotbar) game.Gui.SetNewScreen(null); } diff --git a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs index 8ed24c679..c04acf175 100644 --- a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs +++ b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs @@ -120,12 +120,12 @@ namespace ClassicalSharp.Gui.Screens { public override void Init() { base.Init(); - left = new KeyBind[3]; - left[0] = KeyBind.ExtInput; left[1] = KeyBind.HideFps; left[2] = KeyBind.HideGui; + left = new KeyBind[4]; + left[0] = KeyBind.ExtInput; left[1] = KeyBind.HideFps; left[2] = KeyBind.HideGui; left[3] = KeyBind.HotbarSwitching; right = new KeyBind[4]; right[0] = KeyBind.Screenshot; right[1] = KeyBind.Fullscreen; right[2] = KeyBind.AxisLines; right[3] = KeyBind.Autorotate; - leftDesc = new string[] { "Show ext input", "Hide FPS", "Hide gui" }; - rightDesc = new string[] { "Screenshot", "Fullscreen", "Show axis lines", "Toggle auto-rotate" }; + leftDesc = new string[] { "Show ext input", "Hide FPS", "Hide gui", "Hotbar switching" }; + rightDesc = new string[] { "Screenshot", "Fullscreen", "Show axis lines", "Toggle auto-rotate", }; title = "Other controls"; leftPage = (g, w) => g.Gui.SetNewScreen(new HacksKeyBindingsScreen(g)); diff --git a/ClassicalSharp/2D/Widgets/HotbarWidget.cs b/ClassicalSharp/2D/Widgets/HotbarWidget.cs index 2156e476d..cac853993 100644 --- a/ClassicalSharp/2D/Widgets/HotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/HotbarWidget.cs @@ -120,7 +120,7 @@ namespace ClassicalSharp.Gui.Widgets { // a) user presses alt then number // b) user presses alt // thus we only do case b) if case a) did not happen - if (!(key == Key.AltLeft || key == Key.AltRight)) return false; + if (!(key == game.Input.Keys[KeyBind.HotbarSwitching])) return false; if (altHandled) { altHandled = false; return true; } // handled already // Alternate between first and second row diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs index 28cb4209f..80bc6d56f 100644 --- a/ClassicalSharp/Game/KeyMap.cs +++ b/ClassicalSharp/Game/KeyMap.cs @@ -10,8 +10,8 @@ namespace ClassicalSharp { Forward, Back, Left, Right, Jump, Respawn, SetSpawn, Chat, Inventory, ToggleFog, SendChat, PauseOrExit, PlayerList, Speed, NoClip, Fly, FlyUp, FlyDown, ExtInput, HideFps, - Screenshot, Fullscreen, ThirdPerson, HideGui, AxisLines, - ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight, Autorotate, + HotbarSwitching, Screenshot, Fullscreen, ThirdPerson, HideGui, AxisLines, + ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight, Autorotate #pragma warning restore 1591 } @@ -34,17 +34,16 @@ namespace ClassicalSharp { public KeyMap() { // We can't use enum array initaliser because this causes problems when building with mono // and running on default .NET (https://bugzilla.xamarin.com/show_bug.cgi?id=572) - keys = new Key[31]; + keys = new Key[32]; keys[0] = Key.W; keys[1] = Key.S; keys[2] = Key.A; keys[3] = Key.D; keys[4] = Key.Space; keys[5] = Key.R; keys[6] = Key.Enter; keys[7] = Key.T; keys[8] = Key.B; keys[9] = Key.F; keys[10] = Key.Enter; keys[11] = Key.Escape; keys[12] = Key.Tab; keys[13] = Key.ShiftLeft; keys[14] = Key.X; keys[15] = Key.Z; keys[16] = Key.Q; keys[17] = Key.E; keys[18] = Key.AltLeft; keys[19] = Key.F3; - keys[20] = Key.F12; keys[21] = Key.F11; keys[22] = Key.F5; - keys[23] = Key.F1; keys[24] = Key.F7; keys[25] = Key.C; - keys[26] = Key.ControlLeft; - keys[27] = Key.Unknown; keys[28] = Key.Unknown; keys[29] = Key.Unknown; keys[30] = Key.F6; + keys[20] = Key.AltLeft; keys[21] = Key.F12; keys[22] = Key.F11; keys[23] = Key.F5; + keys[24] = Key.F1; keys[25] = Key.F7; keys[26] = Key.C; keys[27] = Key.ControlLeft; + keys[28] = Key.Unknown; keys[29] = Key.Unknown; keys[30] = Key.Unknown; keys[31] = Key.F6; defaultKeys = new Key[keys.Length]; for (int i = 0; i < defaultKeys.Length; i++) From 115f1e305c858dd53a3198f94e5631db843ee534 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 6 Apr 2017 19:27:26 +1000 Subject: [PATCH 04/16] Fix some things in pull request keybind didn't apply to hotbar + num don't change keybind enum order because it breaks plugins --- ClassicalSharp/2D/Widgets/HotbarWidget.cs | 4 ++-- ClassicalSharp/Game/KeyMap.cs | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ClassicalSharp/2D/Widgets/HotbarWidget.cs b/ClassicalSharp/2D/Widgets/HotbarWidget.cs index cac853993..0623378a0 100644 --- a/ClassicalSharp/2D/Widgets/HotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/HotbarWidget.cs @@ -103,7 +103,7 @@ namespace ClassicalSharp.Gui.Widgets { if (key >= Key.Number1 && key <= Key.Number9) { int index = (int)key - (int)Key.Number1; - if (game.Input.AltDown) { + if (game.IsKeyDown(KeyBind.HotbarSwitching)) { // Pick from first to ninth row game.Inventory.Offset = index * Inventory.BlocksPerRow; altHandled = true; @@ -120,7 +120,7 @@ namespace ClassicalSharp.Gui.Widgets { // a) user presses alt then number // b) user presses alt // thus we only do case b) if case a) did not happen - if (!(key == game.Input.Keys[KeyBind.HotbarSwitching])) return false; + if (key != game.Input.Keys[KeyBind.HotbarSwitching]) return false; if (altHandled) { altHandled = false; return true; } // handled already // Alternate between first and second row diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs index 80bc6d56f..9ed1a4a9b 100644 --- a/ClassicalSharp/Game/KeyMap.cs +++ b/ClassicalSharp/Game/KeyMap.cs @@ -10,8 +10,9 @@ namespace ClassicalSharp { Forward, Back, Left, Right, Jump, Respawn, SetSpawn, Chat, Inventory, ToggleFog, SendChat, PauseOrExit, PlayerList, Speed, NoClip, Fly, FlyUp, FlyDown, ExtInput, HideFps, - HotbarSwitching, Screenshot, Fullscreen, ThirdPerson, HideGui, AxisLines, - ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight, Autorotate + Screenshot, Fullscreen, ThirdPerson, HideGui, AxisLines, + ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight, + Autorotate, HotbarSwitching #pragma warning restore 1591 } @@ -41,9 +42,11 @@ namespace ClassicalSharp { keys[11] = Key.Escape; keys[12] = Key.Tab; keys[13] = Key.ShiftLeft; keys[14] = Key.X; keys[15] = Key.Z; keys[16] = Key.Q; keys[17] = Key.E; keys[18] = Key.AltLeft; keys[19] = Key.F3; - keys[20] = Key.AltLeft; keys[21] = Key.F12; keys[22] = Key.F11; keys[23] = Key.F5; - keys[24] = Key.F1; keys[25] = Key.F7; keys[26] = Key.C; keys[27] = Key.ControlLeft; - keys[28] = Key.Unknown; keys[29] = Key.Unknown; keys[30] = Key.Unknown; keys[31] = Key.F6; + keys[20] = Key.F12; keys[21] = Key.F11; keys[22] = Key.F5; + keys[23] = Key.F1; keys[24] = Key.F7; keys[25] = Key.C; + keys[26] = Key.ControlLeft; + keys[27] = Key.Unknown; keys[28] = Key.Unknown; keys[29] = Key.Unknown; + keys[30] = Key.F6; keys[31] = Key.AltLeft; defaultKeys = new Key[keys.Length]; for (int i = 0; i < defaultKeys.Length; i++) From 373dfc7da34a534ecbb6f9bf13ec0f381cc4342a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 8 Apr 2017 20:06:52 +1000 Subject: [PATCH 05/16] Allow non-humanoid models to use humanoid animations --- ClassicalSharp/Entities/Components/AnimatedComponent.cs | 2 +- ClassicalSharp/Entities/Model/HumanoidModel.cs | 4 +++- ClassicalSharp/Entities/Model/IModel.cs | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ClassicalSharp/Entities/Components/AnimatedComponent.cs b/ClassicalSharp/Entities/Components/AnimatedComponent.cs index dbd8e9abf..b40a199a1 100644 --- a/ClassicalSharp/Entities/Components/AnimatedComponent.cs +++ b/ClassicalSharp/Entities/Components/AnimatedComponent.cs @@ -71,7 +71,7 @@ namespace ClassicalSharp.Entities { tiltY = (float)Math.Sin(walkTime) * swing * (0.15f * Utils.Deg2Rad); } - if (entity.Model is HumanoidModel) + if (entity.Model.CalcHumanAnims) CalcHumanAnim(idleXRot, idleZRot); } diff --git a/ClassicalSharp/Entities/Model/HumanoidModel.cs b/ClassicalSharp/Entities/Model/HumanoidModel.cs index 9e07aca96..3f2523e98 100644 --- a/ClassicalSharp/Entities/Model/HumanoidModel.cs +++ b/ClassicalSharp/Entities/Model/HumanoidModel.cs @@ -10,7 +10,9 @@ namespace ClassicalSharp.Model { public class HumanoidModel : IModel { public ModelSet Set, SetSlim, Set64; - public HumanoidModel(Game window) : base(window) { } + public HumanoidModel(Game window) : base(window) { + CalcHumanAnims = true; + } protected BoxDesc head, torso, lLeg, rLeg, lArm, rArm; protected float offset = 0.5f; diff --git a/ClassicalSharp/Entities/Model/IModel.cs b/ClassicalSharp/Entities/Model/IModel.cs index 7a54ed41e..27d11eb6a 100644 --- a/ClassicalSharp/Entities/Model/IModel.cs +++ b/ClassicalSharp/Entities/Model/IModel.cs @@ -30,6 +30,9 @@ namespace ClassicalSharp.Model { /// Whether this entity requires downloading of a skin texture. public bool UsesSkin = true; + /// Whether humanoid animations should be calculated, instead of normal animations. + public bool CalcHumanAnims; + /// Gravity applied to this entity. public virtual float Gravity { get { return 0.08f; } } From b6ef3934cb63ae4f3d99370391c62e1b7261ca17 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 8 Apr 2017 20:22:41 +1000 Subject: [PATCH 06/16] x --- ClassicalSharp/Entities/Components/AnimatedComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClassicalSharp/Entities/Components/AnimatedComponent.cs b/ClassicalSharp/Entities/Components/AnimatedComponent.cs index b40a199a1..021796f05 100644 --- a/ClassicalSharp/Entities/Components/AnimatedComponent.cs +++ b/ClassicalSharp/Entities/Components/AnimatedComponent.cs @@ -20,7 +20,7 @@ namespace ClassicalSharp.Entities { public float walkTime, swing, bobStrength = 1, velTiltStrength = 1; internal float walkTimeO, walkTimeN, swingO, swingN; - internal float leftXRot, leftZRot, rightXRot, rightZRot; + public float leftXRot, leftZRot, rightXRot, rightZRot; /// Calculates the next animation state based on old and new position. public void UpdateAnimState(Vector3 oldPos, Vector3 newPos, double delta) { From 6c5f9307b1d83f880aee5f6cb190a50415f1cf20 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 8 Apr 2017 22:33:56 +1000 Subject: [PATCH 07/16] Fix stackoverflow when legacy mode and very large map and view distance, fixes #403. (Thanks lemon) --- .../Rendering/Env/MapBordersRenderer.cs | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs b/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs index 4170c87d9..75d2a52a6 100644 --- a/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs +++ b/ClassicalSharp/Rendering/Env/MapBordersRenderer.cs @@ -170,8 +170,9 @@ namespace ClassicalSharp.Renderers { sidesVertices += Utils.CountVertices(map.Width, map.Length, axisSize); // YQuads beneath map sidesVertices += 2 * Utils.CountVertices(map.Width, Math.Abs(y), axisSize); // ZQuads sidesVertices += 2 * Utils.CountVertices(map.Length, Math.Abs(y), axisSize); // XQuads - VertexP3fT2fC4b* v = stackalloc VertexP3fT2fC4b[sidesVertices]; - IntPtr ptr = (IntPtr)v; + + VertexP3fT2fC4b[] v = new VertexP3fT2fC4b[sidesVertices]; + int index = 0; fullColSides = game.BlockInfo.FullBright[block]; int col = fullColSides ? FastColour.WhitePacked : map.Env.Shadow; @@ -181,18 +182,18 @@ namespace ClassicalSharp.Renderers { for (int i = 0; i < rects.Length; i++) { Rectangle r = rects[i]; - DrawY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, 0, YOffset(block), ref v); + DrawY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, 0, YOffset(block), v, ref index); } // Work properly for when ground level is below 0 int y1 = 0, y2 = y; if (y < 0) { y1 = y; y2 = 0; } - DrawY(0, 0, map.Width, map.Length, 0, axisSize, col, 0, 0, ref v); - DrawZ(0, 0, map.Width, y1, y2, axisSize, col, ref v); - DrawZ(map.Length, 0, map.Width, y1, y2, axisSize, col, ref v); - DrawX(0, 0, map.Length, y1, y2, axisSize, col, ref v); - DrawX(map.Width, 0, map.Length, y1, y2, axisSize, col, ref v); - sidesVb = gfx.CreateVb(ptr, VertexFormat.P3fT2fC4b, sidesVertices); + DrawY(0, 0, map.Width, map.Length, 0, axisSize, col, 0, 0, v, ref index); + DrawZ(0, 0, map.Width, y1, y2, axisSize, col, v, ref index); + DrawZ(map.Length, 0, map.Width, y1, y2, axisSize, col, v, ref index); + DrawX(0, 0, map.Length, y1, y2, axisSize, col, v, ref index); + DrawX(map.Width, 0, map.Length, y1, y2, axisSize, col, v, ref index); + sidesVb = gfx.CreateVb(v, VertexFormat.P3fT2fC4b, sidesVertices); } void RebuildEdges(int y, int axisSize) { @@ -202,8 +203,8 @@ namespace ClassicalSharp.Renderers { Rectangle r = rects[i]; edgesVertices += Utils.CountVertices(r.Width, r.Height, axisSize); // YPlanes outside } - VertexP3fT2fC4b* v = stackalloc VertexP3fT2fC4b[edgesVertices]; - IntPtr ptr = (IntPtr)v; + VertexP3fT2fC4b[] v = new VertexP3fT2fC4b[edgesVertices]; + int index = 0; fullColEdge = game.BlockInfo.FullBright[block]; int col = fullColEdge ? FastColour.WhitePacked : map.Env.Sun; @@ -214,9 +215,9 @@ namespace ClassicalSharp.Renderers { for (int i = 0; i < rects.Length; i++) { Rectangle r = rects[i]; DrawY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, - HorOffset(block), YOffset(block), ref v); + HorOffset(block), YOffset(block), v, ref index); } - edgesVb = gfx.CreateVb(ptr, VertexFormat.P3fT2fC4b, edgesVertices); + edgesVb = gfx.CreateVb(v, VertexFormat.P3fT2fC4b, edgesVertices); } float HorOffset(BlockID block) { @@ -230,7 +231,7 @@ namespace ClassicalSharp.Renderers { } void DrawX(int x, int z1, int z2, int y1, int y2, int axisSize, - int col, ref VertexP3fT2fC4b* v) { + int col, VertexP3fT2fC4b[] v, ref int i) { int endZ = z2, endY = y2, startY = y1; for (; z1 < endZ; z1 += axisSize) { z2 = z1 + axisSize; @@ -241,16 +242,16 @@ namespace ClassicalSharp.Renderers { if (y2 > endY) y2 = endY; TextureRec rec = new TextureRec(0, 0, z2 - z1, y2 - y1); - *v = new VertexP3fT2fC4b(x, y1, z1, rec.U1, rec.V2, col); v++; - *v = new VertexP3fT2fC4b(x, y2, z1, rec.U1, rec.V1, col); v++; - *v = new VertexP3fT2fC4b(x, y2, z2, rec.U2, rec.V1, col); v++; - *v = new VertexP3fT2fC4b(x, y1, z2, rec.U2, rec.V2, col); v++; + v[i++] = new VertexP3fT2fC4b(x, y1, z1, rec.U1, rec.V2, col); + v[i++] = new VertexP3fT2fC4b(x, y2, z1, rec.U1, rec.V1, col); + v[i++] = new VertexP3fT2fC4b(x, y2, z2, rec.U2, rec.V1, col); + v[i++] = new VertexP3fT2fC4b(x, y1, z2, rec.U2, rec.V2, col); } } } void DrawZ(int z, int x1, int x2, int y1, int y2, int axisSize, - int col, ref VertexP3fT2fC4b* v) { + int col, VertexP3fT2fC4b[] v, ref int i) { int endX = x2, endY = y2, startY = y1; for (; x1 < endX; x1 += axisSize) { x2 = x1 + axisSize; @@ -261,16 +262,16 @@ namespace ClassicalSharp.Renderers { if (y2 > endY) y2 = endY; TextureRec rec = new TextureRec(0, 0, x2 - x1, y2 - y1); - *v = new VertexP3fT2fC4b(x1, y1, z, rec.U1, rec.V2, col); v++; - *v = new VertexP3fT2fC4b(x1, y2, z, rec.U1, rec.V1, col); v++; - *v = new VertexP3fT2fC4b(x2, y2, z, rec.U2, rec.V1, col); v++; - *v = new VertexP3fT2fC4b(x2, y1, z, rec.U2, rec.V2, col); v++; + v[i++] = new VertexP3fT2fC4b(x1, y1, z, rec.U1, rec.V2, col); + v[i++] = new VertexP3fT2fC4b(x1, y2, z, rec.U1, rec.V1, col); + v[i++] = new VertexP3fT2fC4b(x2, y2, z, rec.U2, rec.V1, col); + v[i++] = new VertexP3fT2fC4b(x2, y1, z, rec.U2, rec.V2, col); } } } void DrawY(int x1, int z1, int x2, int z2, float y, int axisSize, - int col, float offset, float yOffset, ref VertexP3fT2fC4b* v) { + int col, float offset, float yOffset, VertexP3fT2fC4b[] v, ref int i) { int endX = x2, endZ = z2, startZ = z1; for (; x1 < endX; x1 += axisSize) { x2 = x1 + axisSize; @@ -281,10 +282,10 @@ namespace ClassicalSharp.Renderers { if (z2 > endZ) z2 = endZ; TextureRec rec = new TextureRec(0, 0, x2 - x1, z2 - z1); - *v = new VertexP3fT2fC4b(x1 + offset, y + yOffset, z1 + offset, rec.U1, rec.V1, col); v++; - *v = new VertexP3fT2fC4b(x1 + offset, y + yOffset, z2 + offset, rec.U1, rec.V2, col); v++; - *v = new VertexP3fT2fC4b(x2 + offset, y + yOffset, z2 + offset, rec.U2, rec.V2, col); v++; - *v = new VertexP3fT2fC4b(x2 + offset, y + yOffset, z1 + offset, rec.U2, rec.V1, col); v++; + v[i++] = new VertexP3fT2fC4b(x1 + offset, y + yOffset, z1 + offset, rec.U1, rec.V1, col); + v[i++] = new VertexP3fT2fC4b(x1 + offset, y + yOffset, z2 + offset, rec.U1, rec.V2, col); + v[i++] = new VertexP3fT2fC4b(x2 + offset, y + yOffset, z2 + offset, rec.U2, rec.V2, col); + v[i++] = new VertexP3fT2fC4b(x2 + offset, y + yOffset, z1 + offset, rec.U2, rec.V1, col); } } } From 0f472741ff4f5e09af59c279b4bb1a22d7a2f362 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 07:31:13 +1000 Subject: [PATCH 08/16] Increase map volume limit from 800^3 to int.MaxValue in singleplayer. (Thanks Pear) --- ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs index 832326f64..7fdb41ecf 100644 --- a/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs @@ -118,7 +118,7 @@ namespace ClassicalSharp.Gui.Screens { int length = GetInt(2), seed = GetSeedInt(3); long volume = (long)width * height * length; - if (volume > 800 * 800 * 800) { + if (volume > int.MaxValue) { game.Chat.Add("&cThe generated map's volume is too big."); } else if (width == 0 || height == 0 || length == 0) { game.Chat.Add("&cOne of the map dimensions is invalid."); From 20f638fb67f9e64811b4f8fa8ee2c565824fd8d1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 08:21:12 +1000 Subject: [PATCH 09/16] Make model system more flexible, less hardcoding in sitting model --- ClassicalSharp/Entities/Model/BlockModel.cs | 2 +- ClassicalSharp/Entities/Model/ChickenModel.cs | 2 +- ClassicalSharp/Entities/Model/CreeperModel.cs | 2 +- ClassicalSharp/Entities/Model/CustomModel.cs | 2 +- ClassicalSharp/Entities/Model/HumanModels.cs | 82 +++++-------------- .../Entities/Model/HumanoidModel.cs | 2 +- ClassicalSharp/Entities/Model/IModel.cs | 9 +- ClassicalSharp/Entities/Model/PigModel.cs | 2 +- ClassicalSharp/Entities/Model/SheepModel.cs | 2 +- .../Entities/Model/SkeletonModel.cs | 2 +- ClassicalSharp/Entities/Model/SpiderModel.cs | 2 +- ClassicalSharp/Entities/Model/ZombieModel.cs | 2 +- 12 files changed, 36 insertions(+), 75 deletions(-) diff --git a/ClassicalSharp/Entities/Model/BlockModel.cs b/ClassicalSharp/Entities/Model/BlockModel.cs index 25bdc1df9..8390f0d4b 100644 --- a/ClassicalSharp/Entities/Model/BlockModel.cs +++ b/ClassicalSharp/Entities/Model/BlockModel.cs @@ -76,7 +76,7 @@ namespace ClassicalSharp.Model { } int lastTexId = -1; - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { // TODO: using 'is' is ugly, but means we can avoid creating // a string every single time held block changes. if (p is FakePlayer) { diff --git a/ClassicalSharp/Entities/Model/ChickenModel.cs b/ClassicalSharp/Entities/Model/ChickenModel.cs index b94c38c06..502c634b5 100644 --- a/ClassicalSharp/Entities/Model/ChickenModel.cs +++ b/ClassicalSharp/Entities/Model/ChickenModel.cs @@ -55,7 +55,7 @@ namespace ClassicalSharp.Model { get { return new AABB(-4/16f, 0, -8/16f, 4/16f, 15/16f, 4/16f); } } - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); DrawRotate(-p.HeadXRadians, 0, 0, Head2, true); diff --git a/ClassicalSharp/Entities/Model/CreeperModel.cs b/ClassicalSharp/Entities/Model/CreeperModel.cs index 8b1646ccd..e523a6a2e 100644 --- a/ClassicalSharp/Entities/Model/CreeperModel.cs +++ b/ClassicalSharp/Entities/Model/CreeperModel.cs @@ -50,7 +50,7 @@ namespace ClassicalSharp.Model { } /// - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); diff --git a/ClassicalSharp/Entities/Model/CustomModel.cs b/ClassicalSharp/Entities/Model/CustomModel.cs index 43e3c4221..7d8bf173e 100644 --- a/ClassicalSharp/Entities/Model/CustomModel.cs +++ b/ClassicalSharp/Entities/Model/CustomModel.cs @@ -29,7 +29,7 @@ namespace ClassicalSharp.Model { internal AABB pickingBounds; public override AABB PickingBounds { get { return pickingBounds; } } - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { int texId = p.TextureId <= 0 ? cache.HumanoidTexId : p.TextureId; } diff --git a/ClassicalSharp/Entities/Model/HumanModels.cs b/ClassicalSharp/Entities/Model/HumanModels.cs index e896fa53e..692698b40 100644 --- a/ClassicalSharp/Entities/Model/HumanModels.cs +++ b/ClassicalSharp/Entities/Model/HumanModels.cs @@ -38,85 +38,41 @@ namespace ClassicalSharp.Model { } } - public class SittingModel : HumanoidModel { + public class SittingModel : IModel { - public SittingModel(Game window) : base(window) { } + public SittingModel(Game window) : base(window) { + CalcHumanAnims = true; + } const int sitOffset = 10; - protected override void MakeDescriptions() { - head = MakeBoxBounds(-4, 24-sitOffset, -4, 4, 32-sitOffset, 4).RotOrigin(0, (sbyte)(24-sitOffset), 0); - torso = MakeBoxBounds(-4, 12-sitOffset, -2, 4, 24-sitOffset, 2); - lLeg = MakeBoxBounds(-4, 0-sitOffset, -2, 0, 12-sitOffset, 2).RotOrigin(0, (sbyte)(12-sitOffset), 0); - rLeg = MakeBoxBounds(0, 0-sitOffset, -2, 4, 12-sitOffset, 2).RotOrigin(0, (sbyte)(12-sitOffset), 0); - lArm = MakeBoxBounds(-8, 12-sitOffset, -2, -4, 24-sitOffset, 2).RotOrigin(-5, (sbyte)(22-sitOffset), 0); - rArm = MakeBoxBounds(4, 12-sitOffset, -2, 8, 24-sitOffset, 2).RotOrigin(5, (sbyte)(22-sitOffset), 0); - } + public override void CreateParts() { } public override float MaxScale { get { return 2; } } public override float ShadowScale { get { return 0.5f; } } - public override float NameYOffset { get { return (32-sitOffset)/16f + 0.5f/16f; } } + public override float NameYOffset { get { return (32 - sitOffset)/16f + 0.5f/16f; } } - public override float GetEyeY(Entity entity) { return (26-sitOffset)/16f; } + public override float GetEyeY(Entity entity) { return (26 - sitOffset)/16f; } public override Vector3 CollisionSize { - get { return new Vector3(8/16f + 0.6f/16f, (28.1f-sitOffset)/16f, 8/16f + 0.6f/16f); } + get { return new Vector3(8/16f + 0.6f/16f, (28.1f - sitOffset)/16f, 8/16f + 0.6f/16f); } } public override AABB PickingBounds { - get { return new AABB(-8/16f, 0, -4/16f, 8/16f, (32-sitOffset)/16f, 4/16f); } - } - - protected override void DrawModel(Entity p) { - game.Graphics.BindTexture(GetTexture(p.TextureId)); - game.Graphics.AlphaTest = false; - - bool _64x64 = p.SkinType != SkinType.Type64x32; - uScale = p.uScale / 64f; - vScale = p.vScale / (_64x64 ? 64 : 32); - RenderParts(p); - } - - protected override void RenderParts(Entity p) { - SkinType skinType = p.SkinType; - ModelSet model = skinType == SkinType.Type64x64Slim ? SetSlim : - (skinType == SkinType.Type64x64 ? Set64 : Set); - - DrawRotate(-p.HeadXRadians, 0, 0, model.Head, true); - DrawPart(model.Torso); - - float legRotateX = 1.5f; - float legRotateZ = 0.1f; - - DrawRotate(legRotateX, 0, -legRotateZ, model.LeftLeg, false); - DrawRotate(legRotateX, 0, legRotateZ, model.RightLeg, false); - Rotate = RotateOrder.XZY; - //DrawRotate(0, 0, -legRotateZ, model.LeftArm, false); - //DrawRotate(0, 0, legRotateZ, model.RightArm, false); - DrawRotate(p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArm, false); - DrawRotate(p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArm, false); - Rotate = RotateOrder.ZYX; - UpdateVB(); - - game.Graphics.AlphaTest = true; - index = 0; - if (skinType != SkinType.Type64x32) { - DrawPart(model.TorsoLayer); - DrawRotate(legRotateX, 0, -legRotateZ, model.LeftLegLayer, false); - DrawRotate(legRotateX, 0, legRotateZ, model.RightLegLayer, false); - Rotate = RotateOrder.XZY; - - DrawRotate(p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArmLayer, false); - DrawRotate(p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArmLayer, false); - //DrawRotate(0, 0, -legRotateZ, model.LeftArmLayer, false); - //DrawRotate(0, 0, legRotateZ, model.RightArmLayer, false); - Rotate = RotateOrder.ZYX; - } - DrawRotate(-p.HeadXRadians, 0, 0, model.Hat, true); - UpdateVB(); + get { return new AABB(-8/16f, 0, -4/16f, 8/16f, (32 - sitOffset)/16f, 4/16f); } + } + + + protected override Matrix4 TransformMatrix(Entity p, Vector3 pos) { + pos.Y -= sitOffset / 16f; + return Matrix4.RotateY((float)game.accumulator) * p.TransformMatrix(p.ModelScale, pos); } + public override void DrawModel(Entity p) { + p.anim.legXRot = 1.5f; + game.ModelCache.Models[0].Instance.DrawModel(p); + } } public class HumanoidHeadModel : HumanoidModel { diff --git a/ClassicalSharp/Entities/Model/HumanoidModel.cs b/ClassicalSharp/Entities/Model/HumanoidModel.cs index 3f2523e98..faee14009 100644 --- a/ClassicalSharp/Entities/Model/HumanoidModel.cs +++ b/ClassicalSharp/Entities/Model/HumanoidModel.cs @@ -84,7 +84,7 @@ namespace ClassicalSharp.Model { get { return new AABB(-8/16f, 0, -4/16f, 8/16f, 32/16f, 4/16f); } } - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.TextureId)); game.Graphics.AlphaTest = false; diff --git a/ClassicalSharp/Entities/Model/IModel.cs b/ClassicalSharp/Entities/Model/IModel.cs index 27d11eb6a..9e9926bde 100644 --- a/ClassicalSharp/Entities/Model/IModel.cs +++ b/ClassicalSharp/Entities/Model/IModel.cs @@ -123,14 +123,14 @@ namespace ClassicalSharp.Model { game.Graphics.SetBatchFormat(VertexFormat.P3fT2fC4b); game.Graphics.PushMatrix(); - Matrix4 m = p.TransformMatrix(p.ModelScale, pos); + Matrix4 m = TransformMatrix(p, pos); game.Graphics.MultiplyMatrix(ref m); DrawModel(p); game.Graphics.PopMatrix(); } /// Performs the actual rendering of an entity model. - protected abstract void DrawModel(Entity p); + public abstract void DrawModel(Entity p); /// Sends the updated vertex data to the GPU. protected void UpdateVB() { @@ -143,6 +143,11 @@ namespace ClassicalSharp.Model { /// Disposes of any native resources tied to this entity model. public virtual void Dispose() { } + + protected virtual Matrix4 TransformMatrix(Entity p, Vector3 pos) { + return p.TransformMatrix(p.ModelScale, pos); + } + protected int col; protected int[] cols = new int[6]; protected internal ModelVertex[] vertices; diff --git a/ClassicalSharp/Entities/Model/PigModel.cs b/ClassicalSharp/Entities/Model/PigModel.cs index 5d2fc4ae5..62cbabe85 100644 --- a/ClassicalSharp/Entities/Model/PigModel.cs +++ b/ClassicalSharp/Entities/Model/PigModel.cs @@ -49,7 +49,7 @@ namespace ClassicalSharp.Model { } /// - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); diff --git a/ClassicalSharp/Entities/Model/SheepModel.cs b/ClassicalSharp/Entities/Model/SheepModel.cs index 595f389c4..5545ed5bb 100644 --- a/ClassicalSharp/Entities/Model/SheepModel.cs +++ b/ClassicalSharp/Entities/Model/SheepModel.cs @@ -82,7 +82,7 @@ namespace ClassicalSharp.Model { } /// - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { IGraphicsApi gfx = game.Graphics; gfx.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); diff --git a/ClassicalSharp/Entities/Model/SkeletonModel.cs b/ClassicalSharp/Entities/Model/SkeletonModel.cs index 1eba5be96..193d965b8 100644 --- a/ClassicalSharp/Entities/Model/SkeletonModel.cs +++ b/ClassicalSharp/Entities/Model/SkeletonModel.cs @@ -44,7 +44,7 @@ namespace ClassicalSharp.Model { get { return new AABB(-4/16f, 0, -4/16f, 4/16f, 32/16f, 4/16f); } } - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); diff --git a/ClassicalSharp/Entities/Model/SpiderModel.cs b/ClassicalSharp/Entities/Model/SpiderModel.cs index d5225ba4c..fa3bfa15d 100644 --- a/ClassicalSharp/Entities/Model/SpiderModel.cs +++ b/ClassicalSharp/Entities/Model/SpiderModel.cs @@ -48,7 +48,7 @@ namespace ClassicalSharp.Model { const float eighthPi = (float)(Math.PI / 8); /// - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); diff --git a/ClassicalSharp/Entities/Model/ZombieModel.cs b/ClassicalSharp/Entities/Model/ZombieModel.cs index 6d5d9cc78..9e13a7739 100644 --- a/ClassicalSharp/Entities/Model/ZombieModel.cs +++ b/ClassicalSharp/Entities/Model/ZombieModel.cs @@ -47,7 +47,7 @@ namespace ClassicalSharp.Model { get { return new AABB(-4/16f, 0, -4/16f, 4/16f, 32/16f, 4/16f); } } - protected override void DrawModel(Entity p) { + public override void DrawModel(Entity p) { game.Graphics.BindTexture(GetTexture(p.MobTextureId)); DrawRotate(-p.HeadXRadians, 0, 0, Head, true); From 04cef2f247e319f09f04e62103bc933d0c41406f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 08:40:06 +1000 Subject: [PATCH 10/16] Fix last commit --- ClassicalSharp/Entities/Model/BlockModel.cs | 2 +- ClassicalSharp/Entities/Model/ChickenModel.cs | 1 + ClassicalSharp/Entities/Model/HumanModels.cs | 4 ++- ClassicalSharp/Entities/Model/IModel.cs | 35 ++++++++++--------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ClassicalSharp/Entities/Model/BlockModel.cs b/ClassicalSharp/Entities/Model/BlockModel.cs index 8390f0d4b..a9ba534c6 100644 --- a/ClassicalSharp/Entities/Model/BlockModel.cs +++ b/ClassicalSharp/Entities/Model/BlockModel.cs @@ -75,7 +75,7 @@ namespace ClassicalSharp.Model { return base.RenderDistance(p); } - int lastTexId = -1; + int lastTexId = -1, col; public override void DrawModel(Entity p) { // TODO: using 'is' is ugly, but means we can avoid creating // a string every single time held block changes. diff --git a/ClassicalSharp/Entities/Model/ChickenModel.cs b/ClassicalSharp/Entities/Model/ChickenModel.cs index 502c634b5..4e2edb449 100644 --- a/ClassicalSharp/Entities/Model/ChickenModel.cs +++ b/ClassicalSharp/Entities/Model/ChickenModel.cs @@ -65,6 +65,7 @@ namespace ClassicalSharp.Model { DrawRotate(0, 0, -Math.Abs(p.anim.armXRot), LeftWing, false); DrawRotate(0, 0, Math.Abs(p.anim.armXRot), RightWing, false); + int col = cols[0]; for (int i = 0; i < cols.Length; i++) { cols[i] = FastColour.ScalePacked(col, 0.7f); } diff --git a/ClassicalSharp/Entities/Model/HumanModels.cs b/ClassicalSharp/Entities/Model/HumanModels.cs index 692698b40..85e21f865 100644 --- a/ClassicalSharp/Entities/Model/HumanModels.cs +++ b/ClassicalSharp/Entities/Model/HumanModels.cs @@ -71,7 +71,9 @@ namespace ClassicalSharp.Model { public override void DrawModel(Entity p) { p.anim.legXRot = 1.5f; - game.ModelCache.Models[0].Instance.DrawModel(p); + IModel model = game.ModelCache.Models[0].Instance; + model.SetupState(p); + model.DrawModel(p); } } diff --git a/ClassicalSharp/Entities/Model/IModel.cs b/ClassicalSharp/Entities/Model/IModel.cs index 9e9926bde..d144160d0 100644 --- a/ClassicalSharp/Entities/Model/IModel.cs +++ b/ClassicalSharp/Entities/Model/IModel.cs @@ -67,7 +67,6 @@ namespace ClassicalSharp.Model { /// assuming that the model is not rotated at all. public abstract AABB PickingBounds { get; } - protected Vector3 pos; protected float cosHead, sinHead; protected float uScale, vScale; @@ -103,22 +102,9 @@ namespace ClassicalSharp.Model { /// Sets up the state for, then renders an entity model, /// based on the given entity's position and orientation. public void Render(Entity p) { - index = 0; - pos = p.Position; + Vector3 pos = p.Position; if (Bobbing) pos.Y += p.anim.bobbingModel; - - Vector3I P = Vector3I.Floor(p.EyePosition); - col = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside; - uScale = 1 / 64f; vScale = 1 / 32f; - - cols[0] = col; - cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom); - cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ); cols[3] = cols[2]; - cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX); cols[5] = cols[4]; - - float yawDelta = p.HeadY - p.RotY; - cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad); - sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad); + SetupState(p); game.Graphics.SetBatchFormat(VertexFormat.P3fT2fC4b); game.Graphics.PushMatrix(); @@ -129,6 +115,22 @@ namespace ClassicalSharp.Model { game.Graphics.PopMatrix(); } + public void SetupState(Entity p) { + index = 0; + Vector3I P = Vector3I.Floor(p.EyePosition); + int col = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside; + uScale = 1 / 64f; vScale = 1 / 32f; + + cols[0] = col; + cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom); + cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ); cols[3] = cols[2]; + cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX); cols[5] = cols[4]; + + float yawDelta = p.HeadY - p.RotY; + cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad); + sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad); + } + /// Performs the actual rendering of an entity model. public abstract void DrawModel(Entity p); @@ -148,7 +150,6 @@ namespace ClassicalSharp.Model { return p.TransformMatrix(p.ModelScale, pos); } - protected int col; protected int[] cols = new int[6]; protected internal ModelVertex[] vertices; protected internal int index, texIndex; From 27c85121001942d31368bfea39ed9724c89208d0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 10:18:29 +1000 Subject: [PATCH 11/16] better model animation, fix sitting model --- .../Entities/Components/AnimatedComponent.cs | 33 +++++++++---------- ClassicalSharp/Entities/Model/ChickenModel.cs | 8 ++--- ClassicalSharp/Entities/Model/CreeperModel.cs | 8 ++--- ClassicalSharp/Entities/Model/HumanModels.cs | 7 ++-- .../Entities/Model/HumanoidModel.cs | 16 ++++----- ClassicalSharp/Entities/Model/PigModel.cs | 8 ++--- ClassicalSharp/Entities/Model/SheepModel.cs | 16 ++++----- .../Entities/Model/SkeletonModel.cs | 8 ++--- ClassicalSharp/Entities/Model/ZombieModel.cs | 8 ++--- 9 files changed, 56 insertions(+), 56 deletions(-) diff --git a/ClassicalSharp/Entities/Components/AnimatedComponent.cs b/ClassicalSharp/Entities/Components/AnimatedComponent.cs index 021796f05..0fe2312b1 100644 --- a/ClassicalSharp/Entities/Components/AnimatedComponent.cs +++ b/ClassicalSharp/Entities/Components/AnimatedComponent.cs @@ -14,13 +14,13 @@ namespace ClassicalSharp.Entities { this.game = game; this.entity = entity; } - - public float legXRot, armXRot, armZRot; + public float bobbingHor, bobbingVer, bobbingModel, tiltX, tiltY; - public float walkTime, swing, bobStrength = 1, velTiltStrength = 1; - + public float walkTime, swing, bobStrength = 1, velTiltStrength = 1; internal float walkTimeO, walkTimeN, swingO, swingN; - public float leftXRot, leftZRot, rightXRot, rightZRot; + + public float leftLegX, leftLegZ, rightLegX, rightLegZ; + public float leftArmX, leftArmZ, rightArmX, rightArmZ; /// Calculates the next animation state based on old and new position. public void UpdateAnimState(Vector3 oldPos, Vector3 newPos, double delta) { @@ -54,9 +54,13 @@ namespace ClassicalSharp.Entities { float idleXRot = (float)(Math.Sin(idleTime * idleXPeriod) * idleMax); float idleZRot = (float)(idleMax + Math.Cos(idleTime * idleZPeriod) * idleMax); - armXRot = (float)(Math.Cos(walkTime) * swing * armMax) - idleXRot; - legXRot = -(float)(Math.Cos(walkTime) * swing * legMax); - armZRot = -idleZRot; + leftArmX = (float)(Math.Cos(walkTime) * swing * armMax) - idleXRot; + leftArmZ = -idleZRot; + leftLegX = -(float)(Math.Cos(walkTime) * swing * legMax); + leftLegZ = 0; + + rightLegX = -leftLegX; rightLegZ = -leftLegZ; + rightArmX = -leftArmX; rightArmZ = -leftArmZ; bobbingHor = (float)(Math.Cos(walkTime) * swing * (2.5f/16f)); bobbingVer = (float)(Math.Abs(Math.Sin(walkTime)) * swing * (2.5f/16f)); @@ -71,7 +75,7 @@ namespace ClassicalSharp.Entities { tiltY = (float)Math.Sin(walkTime) * swing * (0.15f * Utils.Deg2Rad); } - if (entity.Model.CalcHumanAnims) + if (entity.Model.CalcHumanAnims && !game.SimpleArmsAnim) CalcHumanAnim(idleXRot, idleZRot); } @@ -82,14 +86,9 @@ namespace ClassicalSharp.Entities { } void CalcHumanAnim(float idleXRot, float idleZRot) { - if (game.SimpleArmsAnim) { - leftXRot = armXRot; leftZRot = armZRot; - rightXRot = -armXRot; rightZRot = -armZRot; - } else { - PerpendicularAnim(0.23f, idleXRot, idleZRot, out leftXRot, out leftZRot); - PerpendicularAnim(0.28f, idleXRot, idleZRot, out rightXRot, out rightZRot); - rightXRot = -rightXRot; rightZRot = -rightZRot; - } + PerpendicularAnim(0.23f, idleXRot, idleZRot, out leftArmX, out leftArmZ); + PerpendicularAnim(0.28f, idleXRot, idleZRot, out rightArmX, out rightArmZ); + rightArmX = -rightArmX; rightArmZ = -rightArmZ; } const float maxAngle = 110 * Utils.Deg2Rad; diff --git a/ClassicalSharp/Entities/Model/ChickenModel.cs b/ClassicalSharp/Entities/Model/ChickenModel.cs index 4e2edb449..5bb8bd7d6 100644 --- a/ClassicalSharp/Entities/Model/ChickenModel.cs +++ b/ClassicalSharp/Entities/Model/ChickenModel.cs @@ -62,15 +62,15 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, Head3, true); DrawPart(Torso); - DrawRotate(0, 0, -Math.Abs(p.anim.armXRot), LeftWing, false); - DrawRotate(0, 0, Math.Abs(p.anim.armXRot), RightWing, false); + DrawRotate(0, 0, -Math.Abs(p.anim.leftArmX), LeftWing, false); + DrawRotate(0, 0, Math.Abs(p.anim.leftArmX), RightWing, false); int col = cols[0]; for (int i = 0; i < cols.Length; i++) { cols[i] = FastColour.ScalePacked(col, 0.7f); } - DrawRotate(p.anim.legXRot, 0, 0, LeftLeg, false); - DrawRotate(-p.anim.legXRot, 0, 0, RightLeg, false); + DrawRotate(p.anim.leftLegX, 0, 0, LeftLeg, false); + DrawRotate(p.anim.rightLegX, 0, 0, RightLeg, false); UpdateVB(); } diff --git a/ClassicalSharp/Entities/Model/CreeperModel.cs b/ClassicalSharp/Entities/Model/CreeperModel.cs index e523a6a2e..f7d74358d 100644 --- a/ClassicalSharp/Entities/Model/CreeperModel.cs +++ b/ClassicalSharp/Entities/Model/CreeperModel.cs @@ -55,10 +55,10 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, Head, true); DrawPart(Torso); - DrawRotate(p.anim.legXRot, 0, 0, LeftLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, RightLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, LeftLegBack, false); - DrawRotate(p.anim.legXRot, 0, 0, RightLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, LeftLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, RightLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, LeftLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, RightLegBack, false); UpdateVB(); } diff --git a/ClassicalSharp/Entities/Model/HumanModels.cs b/ClassicalSharp/Entities/Model/HumanModels.cs index 85e21f865..0f29a9e01 100644 --- a/ClassicalSharp/Entities/Model/HumanModels.cs +++ b/ClassicalSharp/Entities/Model/HumanModels.cs @@ -62,15 +62,16 @@ namespace ClassicalSharp.Model { public override AABB PickingBounds { get { return new AABB(-8/16f, 0, -4/16f, 8/16f, (32 - sitOffset)/16f, 4/16f); } } - protected override Matrix4 TransformMatrix(Entity p, Vector3 pos) { pos.Y -= sitOffset / 16f; - return Matrix4.RotateY((float)game.accumulator) * p.TransformMatrix(p.ModelScale, pos); + return p.TransformMatrix(p.ModelScale, pos); } public override void DrawModel(Entity p) { - p.anim.legXRot = 1.5f; + p.anim.leftLegX = 1.5f; p.anim.rightLegX = 1.5f; + p.anim.leftLegZ = -0.1f; p.anim.rightLegZ = 0.1f; + IModel model = game.ModelCache.Models[0].Instance; model.SetupState(p); model.DrawModel(p); diff --git a/ClassicalSharp/Entities/Model/HumanoidModel.cs b/ClassicalSharp/Entities/Model/HumanoidModel.cs index faee14009..432bf5693 100644 --- a/ClassicalSharp/Entities/Model/HumanoidModel.cs +++ b/ClassicalSharp/Entities/Model/HumanoidModel.cs @@ -102,11 +102,11 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, model.Head, true); DrawPart(model.Torso); - DrawRotate(p.anim.legXRot, 0, 0, model.LeftLeg, false); - DrawRotate(-p.anim.legXRot, 0, 0, model.RightLeg, false); + DrawRotate(p.anim.leftLegX, 0, p.anim.leftLegZ, model.LeftLeg, false); + DrawRotate(p.anim.rightLegX, 0, p.anim.rightLegZ, model.RightLeg, false); Rotate = RotateOrder.XZY; - DrawRotate(p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArm, false); - DrawRotate(p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArm, false); + DrawRotate(p.anim.leftArmX, 0, p.anim.leftArmZ, model.LeftArm, false); + DrawRotate(p.anim.rightArmX, 0, p.anim.rightArmZ, model.RightArm, false); Rotate = RotateOrder.ZYX; UpdateVB(); @@ -114,11 +114,11 @@ namespace ClassicalSharp.Model { index = 0; if (skinType != SkinType.Type64x32) { DrawPart(model.TorsoLayer); - DrawRotate(p.anim.legXRot, 0, 0, model.LeftLegLayer, false); - DrawRotate(-p.anim.legXRot, 0, 0, model.RightLegLayer, false); + DrawRotate(p.anim.leftLegX, 0, 0, model.LeftLegLayer, false); + DrawRotate(p.anim.rightLegX, 0, 0, model.RightLegLayer, false); Rotate = RotateOrder.XZY; - DrawRotate(p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArmLayer, false); - DrawRotate(p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArmLayer, false); + DrawRotate(p.anim.leftArmX, 0, p.anim.leftArmZ, model.LeftArmLayer, false); + DrawRotate(p.anim.rightArmX, 0, p.anim.rightArmZ, model.RightArmLayer, false); Rotate = RotateOrder.ZYX; } DrawRotate(-p.HeadXRadians, 0, 0, model.Hat, true); diff --git a/ClassicalSharp/Entities/Model/PigModel.cs b/ClassicalSharp/Entities/Model/PigModel.cs index 62cbabe85..21964cd8c 100644 --- a/ClassicalSharp/Entities/Model/PigModel.cs +++ b/ClassicalSharp/Entities/Model/PigModel.cs @@ -54,10 +54,10 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, Head, true); DrawPart(Torso); - DrawRotate(p.anim.legXRot, 0, 0, LeftLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, RightLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, LeftLegBack, false); - DrawRotate(p.anim.legXRot, 0, 0, RightLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, LeftLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, RightLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, LeftLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, RightLegBack, false); UpdateVB(); } diff --git a/ClassicalSharp/Entities/Model/SheepModel.cs b/ClassicalSharp/Entities/Model/SheepModel.cs index 5545ed5bb..bb89ed0a9 100644 --- a/ClassicalSharp/Entities/Model/SheepModel.cs +++ b/ClassicalSharp/Entities/Model/SheepModel.cs @@ -88,10 +88,10 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, Head, true); DrawPart(Torso); - DrawRotate(p.anim.legXRot, 0, 0, LeftLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, RightLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, LeftLegBack, false); - DrawRotate(p.anim.legXRot, 0, 0, RightLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, LeftLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, RightLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, LeftLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, RightLegBack, false); UpdateVB(); if (Utils.CaselessEquals(p.ModelName, "sheep_nofur")) return; @@ -100,10 +100,10 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, FurHead, true); DrawPart(FurTorso); - DrawRotate(p.anim.legXRot, 0, 0, FurLeftLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, FurRightLegFront, false); - DrawRotate(-p.anim.legXRot, 0, 0, FurLeftLegBack, false); - DrawRotate(p.anim.legXRot, 0, 0, FurRightLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, FurLeftLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, FurRightLegFront, false); + DrawRotate(p.anim.rightLegX, 0, 0, FurLeftLegBack, false); + DrawRotate(p.anim.leftLegX, 0, 0, FurRightLegBack, false); UpdateVB(); } diff --git a/ClassicalSharp/Entities/Model/SkeletonModel.cs b/ClassicalSharp/Entities/Model/SkeletonModel.cs index 193d965b8..bf0e11ba7 100644 --- a/ClassicalSharp/Entities/Model/SkeletonModel.cs +++ b/ClassicalSharp/Entities/Model/SkeletonModel.cs @@ -49,10 +49,10 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, Head, true); DrawPart(Torso); - DrawRotate(p.anim.legXRot, 0, 0, LeftLeg, false); - DrawRotate(-p.anim.legXRot, 0, 0, RightLeg, false); - DrawRotate(90 * Utils.Deg2Rad, 0, p.anim.armZRot, LeftArm, false); - DrawRotate(90 * Utils.Deg2Rad, 0, -p.anim.armZRot, RightArm, false); + DrawRotate(p.anim.leftLegX, 0, 0, LeftLeg, false); + DrawRotate(p.anim.rightLegX, 0, 0, RightLeg, false); + DrawRotate(90 * Utils.Deg2Rad, 0, p.anim.leftArmZ, LeftArm, false); + DrawRotate(90 * Utils.Deg2Rad, 0, p.anim.rightArmZ, RightArm, false); UpdateVB(); } diff --git a/ClassicalSharp/Entities/Model/ZombieModel.cs b/ClassicalSharp/Entities/Model/ZombieModel.cs index 9e13a7739..3f2b36de9 100644 --- a/ClassicalSharp/Entities/Model/ZombieModel.cs +++ b/ClassicalSharp/Entities/Model/ZombieModel.cs @@ -52,10 +52,10 @@ namespace ClassicalSharp.Model { DrawRotate(-p.HeadXRadians, 0, 0, Head, true); DrawPart(Torso); - DrawRotate(p.anim.legXRot, 0, 0, LeftLeg, false); - DrawRotate(-p.anim.legXRot, 0, 0, RightLeg, false); - DrawRotate(90 * Utils.Deg2Rad, 0, p.anim.armZRot, LeftArm, false); - DrawRotate(90 * Utils.Deg2Rad, 0, -p.anim.armZRot, RightArm, false); + DrawRotate(p.anim.leftLegX, 0, 0, LeftLeg, false); + DrawRotate(p.anim.rightLegX, 0, 0, RightLeg, false); + DrawRotate(90 * Utils.Deg2Rad, 0, p.anim.leftArmZ, LeftArm, false); + DrawRotate(90 * Utils.Deg2Rad, 0, p.anim.rightArmZ, RightArm, false); DrawRotate(-p.HeadXRadians, 0, 0, Hat, true); UpdateVB(); } From 19e2ff846c5d713c4b3886ab730d7feb5669a6b7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 12:35:31 +1000 Subject: [PATCH 12/16] better var names --- ClassicalSharp/2D/IsometricBlockDrawer.cs | 1 - ClassicalSharp/TexturePack/Animations.cs | 6 +++--- ClassicalSharp/TexturePack/TerrainAtlas1D.cs | 16 ++++++++-------- ClassicalSharp/TexturePack/TerrainAtlas2D.cs | 12 ++++++------ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ClassicalSharp/2D/IsometricBlockDrawer.cs b/ClassicalSharp/2D/IsometricBlockDrawer.cs index 1abdfc724..5d566878f 100644 --- a/ClassicalSharp/2D/IsometricBlockDrawer.cs +++ b/ClassicalSharp/2D/IsometricBlockDrawer.cs @@ -19,7 +19,6 @@ namespace ClassicalSharp { TerrainAtlas1D atlas; int index; float scale; - const float invElemSize = TerrainAtlas2D.invElementSize; bool bright; VertexP3fT2fC4b[] vertices; int vb; diff --git a/ClassicalSharp/TexturePack/Animations.cs b/ClassicalSharp/TexturePack/Animations.cs index b14c9c123..e95f73bfc 100644 --- a/ClassicalSharp/TexturePack/Animations.cs +++ b/ClassicalSharp/TexturePack/Animations.cs @@ -57,11 +57,11 @@ namespace ClassicalSharp.Textures { /// Runs through all animations and if necessary updates the terrain atlas. public void Tick(ScheduledTask task) { if (useLavaAnim) { - int size = Math.Min(game.TerrainAtlas.elementSize, 64); + int size = Math.Min(game.TerrainAtlas.TileSize, 64); DrawAnimation(null, 30, size); } if (useWaterAnim) { - int size = Math.Min(game.TerrainAtlas.elementSize, 64); + int size = Math.Min(game.TerrainAtlas.TileSize, 64); DrawAnimation(null, 14, size); } @@ -160,7 +160,7 @@ namespace ClassicalSharp.Textures { FastBitmap.MovePortion(data.FrameX + data.State * size, data.FrameY, 0, 0, animsBuffer, animPart, size); } - gfx.UpdateTexturePart(atlas.TexIds[index], 0, rowNum * game.TerrainAtlas.elementSize, animPart); + gfx.UpdateTexturePart(atlas.TexIds[index], 0, rowNum * game.TerrainAtlas.TileSize, animPart); } bool IsDefaultZip() { diff --git a/ClassicalSharp/TexturePack/TerrainAtlas1D.cs b/ClassicalSharp/TexturePack/TerrainAtlas1D.cs index 5e762278a..9767d75ce 100644 --- a/ClassicalSharp/TexturePack/TerrainAtlas1D.cs +++ b/ClassicalSharp/TexturePack/TerrainAtlas1D.cs @@ -41,15 +41,15 @@ namespace ClassicalSharp.Textures { public void UpdateState(TerrainAtlas2D atlas2D) { int maxVerticalSize = Math.Min(4096, gfx.MaxTextureDimensions); - int elementsPerFullAtlas = maxVerticalSize / atlas2D.elementSize; - int totalElements = TerrainAtlas2D.RowsCount * TerrainAtlas2D.ElementsPerRow; + int elementsPerFullAtlas = maxVerticalSize / atlas2D.TileSize; + int totalElements = TerrainAtlas2D.RowsCount * TerrainAtlas2D.TilesPerRow; int atlasesCount = Utils.CeilDiv(totalElements, elementsPerFullAtlas); elementsPerAtlas1D = Math.Min(elementsPerFullAtlas, totalElements); - int atlas1DHeight = Utils.NextPowerOf2(elementsPerAtlas1D * atlas2D.elementSize); + int atlas1DHeight = Utils.NextPowerOf2(elementsPerAtlas1D * atlas2D.TileSize); Convert2DTo1D(atlas2D, atlasesCount, atlas1DHeight); - elementsPerBitmap = atlas1DHeight / atlas2D.elementSize; + elementsPerBitmap = atlas1DHeight / atlas2D.TileSize; invElementSize = 1f / elementsPerBitmap; } @@ -65,8 +65,8 @@ namespace ClassicalSharp.Textures { } void Make1DTexture(int i, FastBitmap atlas, TerrainAtlas2D atlas2D, int atlas1DHeight, ref int index) { - int elemSize = atlas2D.elementSize; - using (Bitmap atlas1d = Platform.CreateBmp(atlas2D.elementSize, atlas1DHeight)) + int elemSize = atlas2D.TileSize; + using (Bitmap atlas1d = Platform.CreateBmp(atlas2D.TileSize, atlas1DHeight)) using (FastBitmap dst = new FastBitmap(atlas1d, true, false)) { for (int index1D = 0; index1D < elementsPerAtlas1D; index1D++) { @@ -80,8 +80,8 @@ namespace ClassicalSharp.Textures { public int CalcMaxUsedRow(TerrainAtlas2D atlas2D, BlockInfo info) { int maxVerSize = Math.Min(4096, gfx.MaxTextureDimensions); - int verElements = maxVerSize / atlas2D.elementSize; - int totalElements = GetMaxUsedRow(info.textures) * TerrainAtlas2D.ElementsPerRow; + int verElements = maxVerSize / atlas2D.TileSize; + int totalElements = GetMaxUsedRow(info.textures) * TerrainAtlas2D.TilesPerRow; return Utils.CeilDiv(totalElements, verElements); } diff --git a/ClassicalSharp/TexturePack/TerrainAtlas2D.cs b/ClassicalSharp/TexturePack/TerrainAtlas2D.cs index 1f3178ab9..23c05ed67 100644 --- a/ClassicalSharp/TexturePack/TerrainAtlas2D.cs +++ b/ClassicalSharp/TexturePack/TerrainAtlas2D.cs @@ -11,10 +11,10 @@ namespace ClassicalSharp { /// Represents a 2D packed texture atlas, specifically for terrain.png. public class TerrainAtlas2D : IDisposable { - public const int ElementsPerRow = 16, RowsCount = 16; - public const float invElementSize = 1 / 16f; + public const int TilesPerRow = 16, RowsCount = 16; public Bitmap AtlasBitmap; - public int elementSize; + public int TileSize; + IGraphicsApi gfx; IDrawer2D drawer; @@ -26,19 +26,19 @@ namespace ClassicalSharp { /// Updates the underlying atlas bitmap, fields, and texture. public void UpdateState(BlockInfo info, Bitmap bmp) { AtlasBitmap = bmp; - elementSize = bmp.Width / ElementsPerRow; + TileSize = bmp.Width / TilesPerRow; using (FastBitmap fastBmp = new FastBitmap(bmp, true, true)) info.RecalculateSpriteBB(fastBmp); } /// Creates a new texture that contains the tile at the specified index. public int LoadTextureElement(int index) { - int size = elementSize; + int size = TileSize; using (FastBitmap atlas = new FastBitmap(AtlasBitmap, true, true)) using (Bitmap bmp = Platform.CreateBmp(size, size)) using (FastBitmap dst = new FastBitmap(bmp, true, false)) { - int x = index % ElementsPerRow, y = index / ElementsPerRow; + int x = index % TilesPerRow, y = index / TilesPerRow; FastBitmap.MovePortion(x * size, y * size, 0, 0, atlas, dst, size); return gfx.CreateTexture(dst, true); } From eaab271d08c2110ff3ba3b491923ecf22826fb71 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 17:19:27 +1000 Subject: [PATCH 13/16] we need to be more public about things --- ClassicalSharp/Entities/Entity.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClassicalSharp/Entities/Entity.cs b/ClassicalSharp/Entities/Entity.cs index b597f4a79..16423fc70 100644 --- a/ClassicalSharp/Entities/Entity.cs +++ b/ClassicalSharp/Entities/Entity.cs @@ -109,7 +109,7 @@ namespace ClassicalSharp.Entities { return game.World.SafeGetBlock(Vector3I.Floor(coords)); } - internal Matrix4 TransformMatrix(float scale, Vector3 pos) { + public Matrix4 TransformMatrix(float scale, Vector3 pos) { return Matrix4.RotateZ(-RotZ * Utils.Deg2Rad) * Matrix4.RotateX(-RotX * Utils.Deg2Rad) * From c0e90d2a57cf7aef82427afeb327bb68c8ae4af3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 21:56:43 +1000 Subject: [PATCH 14/16] tidy up PhysicsComponent --- .../Entities/Components/HacksComponent.cs | 1 + .../Entities/Components/PhysicsComponent.cs | 56 +++++++++---------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/ClassicalSharp/Entities/Components/HacksComponent.cs b/ClassicalSharp/Entities/Components/HacksComponent.cs index 49193c26c..6cf6a87ba 100644 --- a/ClassicalSharp/Entities/Components/HacksComponent.cs +++ b/ClassicalSharp/Entities/Components/HacksComponent.cs @@ -71,6 +71,7 @@ namespace ClassicalSharp.Entities { public bool HalfSpeeding; public bool CanJumpHigher { get { return Enabled && CanAnyHacks && CanSpeed; } } + public bool Floating { get { return Noclip || Flying; } } /// Parses hack flags specified in the motd and/or name of the server. /// Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz diff --git a/ClassicalSharp/Entities/Components/PhysicsComponent.cs b/ClassicalSharp/Entities/Components/PhysicsComponent.cs index 5878ca56d..4d1c6490d 100644 --- a/ClassicalSharp/Entities/Components/PhysicsComponent.cs +++ b/ClassicalSharp/Entities/Components/PhysicsComponent.cs @@ -33,7 +33,7 @@ namespace ClassicalSharp.Entities { } public void UpdateVelocityState() { - if (hacks.Flying || hacks.Noclip) { + if (hacks.Floating) { entity.Velocity.Y = 0; // eliminate the effect of gravity int dir = (hacks.FlyingUp || jumping) ? 1 : (hacks.FlyingDown ? -1 : 0); @@ -109,34 +109,32 @@ namespace ClassicalSharp.Entities { public void PhysicsTick(Vector3 vel) { if (hacks.Noclip) entity.onGround = false; - float multiply = GetBaseMultiply(true); - float yMultiply = GetBaseMultiply(hacks.CanSpeed); - float modifier = LowestSpeedModifier(); - - float yMul = Math.Max(1f, yMultiply / 5) * modifier; - float horMul = multiply * modifier; - if (!(hacks.Flying || hacks.Noclip)) { - if (secondJump) { horMul *= 93f; yMul *= 10f; } - else if (firstJump) { horMul *= 46.5f; yMul *= 7.5f; } + float baseSpeed = GetBaseSpeed(); + float horSpeed = baseSpeed * GetSpeed(true); + float verSpeed = baseSpeed * Math.Max(1, GetSpeed(hacks.CanSpeed) / 5); + + if (!hacks.Floating) { + if (secondJump) { horSpeed *= 93f; verSpeed *= 10f; } + else if (firstJump) { horSpeed *= 46.5f; verSpeed *= 7.5f; } } - if (entity.TouchesAnyWater() && !hacks.Flying && !hacks.Noclip) { - MoveNormal(vel, 0.02f * horMul, waterDrag, liquidGrav, yMul); - } else if (entity.TouchesAnyLava() && !hacks.Flying && !hacks.Noclip) { - MoveNormal(vel, 0.02f * horMul, lavaDrag, liquidGrav, yMul); - } else if (entity.TouchesAnyRope() && !hacks.Flying && !hacks.Noclip) { - MoveNormal(vel, 0.02f * 1.7f, ropeDrag, ropeGrav, yMul); + if (entity.TouchesAnyWater() && !hacks.Floating) { + MoveNormal(vel, 0.02f * horSpeed, waterDrag, liquidGrav, verSpeed); + } else if (entity.TouchesAnyLava() && !hacks.Floating) { + MoveNormal(vel, 0.02f * horSpeed, lavaDrag, liquidGrav, verSpeed); + } else if (entity.TouchesAnyRope() && !hacks.Floating) { + MoveNormal(vel, 0.02f * 1.7f, ropeDrag, ropeGrav, verSpeed); } else { - float factor = !(hacks.Flying || hacks.Noclip) && entity.onGround ? 0.1f : 0.02f; + float factor = !hacks.Floating && entity.onGround ? 0.1f : 0.02f; float gravity = useLiquidGravity ? liquidGrav : entity.Model.Gravity; - if (hacks.Flying || hacks.Noclip) { - MoveFlying(vel, factor * horMul, entity.Model.Drag, gravity, yMul); + if (hacks.Floating) { + MoveFlying(vel, factor * horSpeed, entity.Model.Drag, gravity, verSpeed); } else { - MoveNormal(vel, factor * horMul, entity.Model.Drag, gravity, yMul); + MoveNormal(vel, factor * horSpeed, entity.Model.Drag, gravity, verSpeed); } - if (entity.BlockUnderFeet == Block.Ice && !(hacks.Flying || hacks.Noclip)) { + if (entity.BlockUnderFeet == Block.Ice && !hacks.Floating) { // limit components to +-0.25f by rescaling vector to [-0.25, 0.25] if (Math.Abs(entity.Velocity.X) > 0.25f || Math.Abs(entity.Velocity.Z) > 0.25f) { float scale = Math.Min( @@ -189,19 +187,15 @@ namespace ClassicalSharp.Entities { entity.Velocity.Y -= gravity; } - float GetBaseMultiply(bool canSpeed) { - float multiply = 0; - float speed = (hacks.Flying || hacks.Noclip) ? 8 : 1; - - - if (hacks.Speeding && canSpeed) multiply += speed * hacks.SpeedMultiplier; - if (hacks.HalfSpeeding && canSpeed) multiply += speed * hacks.SpeedMultiplier / 2; - if (multiply == 0) multiply = speed; - return hacks.CanSpeed ? multiply : Math.Min(multiply, hacks.MaxSpeedMultiplier); + float GetSpeed(bool canSpeed) { + float factor = hacks.Floating ? 8 : 1, speed = factor; + if (hacks.Speeding && canSpeed) speed += factor * hacks.SpeedMultiplier; + if (hacks.HalfSpeeding && canSpeed) speed += factor * hacks.SpeedMultiplier / 2; + return hacks.CanSpeed ? speed : Math.Min(speed, hacks.MaxSpeedMultiplier); } const float inf = float.PositiveInfinity; - float LowestSpeedModifier() { + float GetBaseSpeed() { AABB bounds = entity.Bounds; useLiquidGravity = false; float baseModifier = LowestModifier(bounds, false); From feed58a2c7126564ccd4c0fb559fe1e1b5aef7d5 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 22:21:35 +1000 Subject: [PATCH 15/16] Fix BlockModel (Thanks goodlyay) --- ClassicalSharp/Entities/Model/BlockModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ClassicalSharp/Entities/Model/BlockModel.cs b/ClassicalSharp/Entities/Model/BlockModel.cs index a9ba534c6..7f75de4e3 100644 --- a/ClassicalSharp/Entities/Model/BlockModel.cs +++ b/ClassicalSharp/Entities/Model/BlockModel.cs @@ -94,6 +94,7 @@ namespace ClassicalSharp.Model { col = FastColour.ScalePacked(col, colScale); block = ((FakePlayer)p).Block; } else { + col = cols[0]; block = Utils.FastByte(p.ModelName); } From 9044b14bb52670068a03a2f9f500708359d59ec7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Apr 2017 22:30:01 +1000 Subject: [PATCH 16/16] fix -hax +fly being extremely slow flying (Thanks fam0r) --- .../Entities/Components/PhysicsComponent.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ClassicalSharp/Entities/Components/PhysicsComponent.cs b/ClassicalSharp/Entities/Components/PhysicsComponent.cs index 4d1c6490d..06e5cee1b 100644 --- a/ClassicalSharp/Entities/Components/PhysicsComponent.cs +++ b/ClassicalSharp/Entities/Components/PhysicsComponent.cs @@ -110,9 +110,11 @@ namespace ClassicalSharp.Entities { public void PhysicsTick(Vector3 vel) { if (hacks.Noclip) entity.onGround = false; float baseSpeed = GetBaseSpeed(); - float horSpeed = baseSpeed * GetSpeed(true); - float verSpeed = baseSpeed * Math.Max(1, GetSpeed(hacks.CanSpeed) / 5); - + float verSpeed = baseSpeed * Math.Max(1, GetSpeed(hacks.CanSpeed, 8f) / 5); + float horSpeed = baseSpeed * GetSpeed(true, 8f/5); + // previously horSpeed used to be multiplied by factor of 0.02 in last case + // it's now multiplied by 0.1, so need to divide by 5 so user speed modifier comes out same + if (!hacks.Floating) { if (secondJump) { horSpeed *= 93f; verSpeed *= 10f; } else if (firstJump) { horSpeed *= 46.5f; verSpeed *= 7.5f; } @@ -125,7 +127,7 @@ namespace ClassicalSharp.Entities { } else if (entity.TouchesAnyRope() && !hacks.Floating) { MoveNormal(vel, 0.02f * 1.7f, ropeDrag, ropeGrav, verSpeed); } else { - float factor = !hacks.Floating && entity.onGround ? 0.1f : 0.02f; + float factor = hacks.Floating || entity.onGround ? 0.1f : 0.02f; float gravity = useLiquidGravity ? liquidGrav : entity.Model.Gravity; if (hacks.Floating) { @@ -187,8 +189,8 @@ namespace ClassicalSharp.Entities { entity.Velocity.Y -= gravity; } - float GetSpeed(bool canSpeed) { - float factor = hacks.Floating ? 8 : 1, speed = factor; + float GetSpeed(bool canSpeed, float speedMul) { + float factor = hacks.Floating ? speedMul : 1, speed = factor; if (hacks.Speeding && canSpeed) speed += factor * hacks.SpeedMultiplier; if (hacks.HalfSpeeding && canSpeed) speed += factor * hacks.SpeedMultiplier / 2; return hacks.CanSpeed ? speed : Math.Min(speed, hacks.MaxSpeedMultiplier);