Skip to content

Commit

Permalink
sync to latest version of ace physics (#44)
Browse files Browse the repository at this point in the history
* sync to latest version of ace physics

* fix unicode char
  • Loading branch information
gmriggs committed Jan 25, 2022
1 parent a828c0c commit 45eaaab
Show file tree
Hide file tree
Showing 78 changed files with 4,375 additions and 1,064 deletions.
2 changes: 1 addition & 1 deletion ACE
Submodule ACE updated 708 files
8 changes: 8 additions & 0 deletions ACViewer/ACViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<Compile Include="Enum\ModelType.cs" />
<Compile Include="Enum\ProfilerSection.cs" />
<Compile Include="Enum\ViewMode.cs" />
<Compile Include="Extensions\MathExtensions.cs" />
<Compile Include="Extensions\PositionExtensions.cs" />
<Compile Include="Extensions\TextureExtensions.cs" />
<Compile Include="Extensions\Vector2Extensions.cs" />
Expand Down Expand Up @@ -245,6 +246,12 @@
<Compile Include="Model\VertexInstanceEnv.cs" />
<Compile Include="Model\VertexPositionNormalTextures.cs" />
<Compile Include="ParticleViewer.cs" />
<Compile Include="Physics\Command\ACCmdInterp.cs" />
<Compile Include="Physics\Command\CmdStruct.cs" />
<Compile Include="Physics\Command\CommandInterpreter.cs" />
<Compile Include="Physics\Command\CommandList.cs" />
<Compile Include="Physics\Command\CommandListElement.cs" />
<Compile Include="Physics\Command\InputEvent.cs" />
<Compile Include="Physics\Common\ImgTex.cs" />
<Compile Include="Physics\Common\LandSurf.cs" />
<Compile Include="Physics\Common\Palette.cs" />
Expand All @@ -263,6 +270,7 @@
<Compile Include="Physics\Common\TexMerge.cs" />
<Compile Include="Physics\Common\TextureMergeInfo.cs" />
<Compile Include="Physics\Common\TMTerrainDesc.cs" />
<Compile Include="Physics\Managers\ServerObjectManager.cs" />
<Compile Include="Render\Buffer.cs" />
<Compile Include="Render\ParticleBatch.cs" />
<Compile Include="Render\ParticleBatchDraw.cs" />
Expand Down
15 changes: 15 additions & 0 deletions ACViewer/Extensions/MathExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ACViewer.Extensions
{
public static class MathExtensions
{
public static float Clamp(float val, float min, float max)
{
if (val < min)
val = min;
else if (val > max)
val = max;

return val;
}
}
}
10 changes: 5 additions & 5 deletions ACViewer/Physics/Animation/AFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public AFrame(Vector3 origin, Quaternion orientation)

public AFrame(AFrame frame)
{
Origin = new Vector3(frame.Origin.X, frame.Origin.Y, frame.Origin.Z);
Origin = frame.Origin;
Orientation = new Quaternion(frame.Orientation.X, frame.Orientation.Y, frame.Orientation.Z, frame.Orientation.W);
}

public AFrame(DatLoader.Entity.Frame frame)
{
Origin = new Vector3(frame.Origin.X, frame.Origin.Y, frame.Origin.Z);
Origin = frame.Origin;
Orientation = new Quaternion(frame.Orientation.X, frame.Orientation.Y, frame.Orientation.Z, frame.Orientation.W);
}

public AFrame(ACE.Entity.Frame frame)
{
Origin = new Vector3(frame.Origin.X, frame.Origin.Y, frame.Origin.Z);
Origin = frame.Origin;
Orientation = new Quaternion(frame.Orientation.X, frame.Orientation.Y, frame.Orientation.Z, frame.Orientation.W);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ public void set_rotate(Quaternion orientation)

public void set_vector_heading(Vector3 heading)
{
var normal = new Vector3(heading.X, heading.Y, heading.Z);
var normal = heading;
if (Vec.NormalizeCheckSmall(ref normal)) return;

var zDeg = 450.0f - ((float)Math.Atan2(normal.Y, normal.X)).ToDegrees();
Expand All @@ -217,7 +217,7 @@ public void set_vector_heading(Vector3 heading)

public override string ToString()
{
return Origin + " " + Orientation;
return $"[{Origin.X} {Origin.Y} {Origin.Z}] {Orientation.W} {Orientation.X} {Orientation.Y} {Orientation.Z}";
}

public bool Equals(AFrame frame)
Expand Down
2 changes: 1 addition & 1 deletion ACViewer/Physics/Animation/AnimData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ACE.Server.Physics.Animation
namespace ACE.Server.Physics.Animation
{
public class AnimData
{
Expand Down
2 changes: 1 addition & 1 deletion ACViewer/Physics/Animation/AnimSequenceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AnimSequenceNode(AnimData animData)

public float get_ending_frame()
{
if (Framerate > 0.0f)
if (Framerate >= 0.0f)
return HighFrame + 1 - PhysicsGlobals.EPSILON;
else
return LowFrame;
Expand Down
6 changes: 6 additions & 0 deletions ACViewer/Physics/Animation/InterpretedMotionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,11 @@ public void RemoveMotion(uint motion)
break;
}
}

public bool HasCommands()
{
//return ForwardCommand != 0 && ForwardCommand != (uint)MotionCommand.Ready || SideStepCommand != 0 || TurnCommand != 0;
return SideStepCommand != 0 || TurnCommand != 0;
}
}
}
17 changes: 12 additions & 5 deletions ACViewer/Physics/Animation/MotionInterp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Numerics;
using ACE.Entity.Enum;
using ACE.Server.Physics.Common;
using ACE.Server.Physics.Extensions;

namespace ACE.Server.Physics.Animation
{
Expand Down Expand Up @@ -170,6 +169,7 @@ public void HandleExitWorld()
}
}
PendingMotions.Clear();
if (PhysicsObj != null) PhysicsObj.IsAnimating = false;
}

public void HitGround()
Expand Down Expand Up @@ -226,7 +226,10 @@ public void MotionDone(bool success)

motionData = PendingMotions.First;
if (motionData != null)
{
PendingMotions.Remove(motionData);
PhysicsObj.IsAnimating = PendingMotions.Count > 0;
}
}
}

Expand Down Expand Up @@ -385,6 +388,7 @@ public WeenieError StopMotion(uint motion, MovementParameters movementParams)
public void add_to_queue(int contextID, uint motion, WeenieError jumpErrorCode)
{
PendingMotions.AddLast(new MotionNode(contextID, motion, jumpErrorCode));
PhysicsObj.IsAnimating = true;
}

public void adjust_motion(ref uint motion, ref float speed, HoldKey holdKey)
Expand Down Expand Up @@ -641,7 +645,7 @@ public float get_jump_v_z()
return 10.0f;

float vz = extent;
if (WeenieObj.InqJumpVelocity(extent, ref vz))
if (WeenieObj.InqJumpVelocity(extent, out vz))
return vz;

return 0.0f;
Expand All @@ -652,8 +656,8 @@ public Vector3 get_leave_ground_velocity()
var velocity = get_state_velocity();
velocity.Z = get_jump_v_z();

if (!velocity.Equals(Vector3.Zero))
velocity = PhysicsObj.Position.GlobalToLocalVec(velocity);
if (Vec.IsZero(velocity))
velocity = PhysicsObj.Position.GlobalToLocalVec(PhysicsObj.Velocity);

return velocity;
}
Expand Down Expand Up @@ -689,7 +693,7 @@ public Vector3 get_state_velocity()
var maxSpeed = RunAnimSpeed * rate;
if (velocity.Length() > maxSpeed)
{
velocity = velocity.Normalize();
velocity = Vector3.Normalize(velocity);
velocity *= maxSpeed;
}
return velocity;
Expand Down Expand Up @@ -774,6 +778,9 @@ public WeenieError motion_allows_jump(uint substate)
return WeenieError.None;
}

/// <summary>
/// Alternatively, you can use PhysicsObj.IsAnimating for better performance.
/// </summary>
public bool motions_pending()
{
return PendingMotions.Count > 0;
Expand Down
39 changes: 31 additions & 8 deletions ACViewer/Physics/Animation/MotionTable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Numerics;

using ACE.DatLoader;
using ACE.DatLoader.Entity;
using ACE.DatLoader.Entity.AnimationHooks;
using ACE.Entity.Enum;
using ACE.Server.Physics.Animation.Internal;

Expand All @@ -17,15 +20,15 @@ public class MotionTable
public Dictionary<uint, Dictionary<uint, MotionData>> Links;
public uint DefaultStyle;

public static Dictionary<uint, float> WalkSpeed;
public static Dictionary<uint, float> RunSpeed;
public static Dictionary<uint, float> TurnSpeed;
public static ConcurrentDictionary<uint, float> WalkSpeed { get; set; }
public static ConcurrentDictionary<uint, float> RunSpeed { get; set; }
public static ConcurrentDictionary<uint, float> TurnSpeed { get; set; }

static MotionTable()
{
WalkSpeed = new Dictionary<uint, float>();
RunSpeed = new Dictionary<uint, float>();
TurnSpeed = new Dictionary<uint, float>();
WalkSpeed = new ConcurrentDictionary<uint, float>();
RunSpeed = new ConcurrentDictionary<uint, float>();
TurnSpeed = new ConcurrentDictionary<uint, float>();
}

public MotionTable()
Expand Down Expand Up @@ -454,14 +457,28 @@ public void re_modify(Sequence sequence, MotionState pstate)
}
}

private static readonly List<(float, AttackHook)> emptyList = new List<(float, AttackHook)>();

public static List<(float time, AttackHook attackHook)> GetAttackFrames(uint motionTableId, MotionStance stance, MotionCommand motion)
{
if (motionTableId == 0) return emptyList;

var motionTable = DatManager.PortalDat.ReadFromDat<DatLoader.FileTypes.MotionTable>(motionTableId);
return motionTable.GetAttackFrames(motionTableId, stance, motion);
}

public static float GetAnimationLength(uint motionTableId, MotionStance stance, MotionCommand motion, float speed = 1.0f)
{
if (motionTableId == 0) return 0;

var motionTable = DatManager.PortalDat.ReadFromDat<DatLoader.FileTypes.MotionTable>(motionTableId);
return motionTable.GetAnimationLength(stance, motion, null) / speed;
}

public static float GetAnimationLength(uint motionTableId, MotionStance stance, MotionCommand currentMotion, MotionCommand motion, float speed = 1.0f)
{
if (motionTableId == 0) return 0;

var motionTable = DatManager.PortalDat.ReadFromDat<DatLoader.FileTypes.MotionTable>(motionTableId);

var animLength = 0.0f;
Expand All @@ -477,6 +494,8 @@ public static float GetAnimationLength(uint motionTableId, MotionStance stance,

public static float GetCycleLength(uint motionTableId, MotionStance stance, MotionCommand motion, float speed = 1.0f)
{
if (motionTableId == 0) return 0;

var motionTable = DatManager.PortalDat.ReadFromDat<DatLoader.FileTypes.MotionTable>(motionTableId);
return motionTable.GetCycleLength(stance, motion) / speed;
}
Expand All @@ -495,7 +514,7 @@ public static float GetRunSpeed(uint motionTableID)
return 0.0f;

var speed = GetAnimDist(motionData);
RunSpeed.Add(motionTableID, speed);
RunSpeed[motionTableID] = speed;
return speed;
}

Expand All @@ -513,7 +532,7 @@ public static float GetTurnSpeed(uint motionTableID)
return 0.0f;

var speed = Math.Abs(motionData.Omega.Z);
TurnSpeed.Add(motionTableID, speed);
TurnSpeed[motionTableID] = speed;
return speed;
}

Expand All @@ -522,6 +541,8 @@ public static float GetTurnSpeed(uint motionTableID)
/// </summary>
public static MotionData GetMotionData(uint motionTableID, uint motion, uint? currentStyle = null)
{
if (motionTableID == 0) return null;

var motionTable = DatManager.PortalDat.ReadFromDat<DatLoader.FileTypes.MotionTable>(motionTableID);
if (currentStyle == null)
currentStyle = motionTable.DefaultStyle;
Expand All @@ -533,6 +554,8 @@ public static MotionData GetMotionData(uint motionTableID, uint motion, uint? cu

public static MotionData GetLinkData(uint motionTableID, uint motion, uint? currentStyle = null)
{
if (motionTableID == 0) return null;

var motionTable = DatManager.PortalDat.ReadFromDat<DatLoader.FileTypes.MotionTable>(motionTableID);
if (currentStyle == null)
currentStyle = motionTable.DefaultStyle;
Expand Down
16 changes: 12 additions & 4 deletions ACViewer/Physics/Animation/MovementSystem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using ACE.Server.Physics.Common;
using ACViewer.Extensions;

namespace ACE.Server.Physics.Animation
{
public class MovementSystem
{
public static float GetJumpHeight(float burden, int jumpSkill, float power, float scaling)
public static float GetJumpHeight(float burden, uint jumpSkill, float power, float scaling)
{
if (power < 0.0f) power = 0.0f;
if (power > 1.0f) power = 1.0f;
power = MathExtensions.Clamp(power, 0.0f, 1.0f);

var result = EncumbranceSystem.GetBurdenMod(burden) * (jumpSkill / (jumpSkill + 1300) * 22.200001f + 0.050000001f) * power / scaling;
var result = EncumbranceSystem.GetBurdenMod(burden) * (jumpSkill / (jumpSkill + 1300.0f) * 22.2f + 0.05f) * power / scaling;

if (result < 0.35f)
result = 0.35f;
Expand All @@ -35,5 +35,13 @@ public static int JumpStaminaCost(float power, float burden, bool pk)
else
return (int)Math.Ceiling((burden + 0.5f) * power * 8.0f + 2.0f);
}

public static float GetJumpPower(uint stamina, float burden, bool pk)
{
if (pk)
return stamina / 100.0f - 1.0f;
else
return (stamina - 2.0f) / (burden * 8.0f + 4.0f);
}
}
}
29 changes: 29 additions & 0 deletions ACViewer/Physics/Animation/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ public class Sequence
public int PlacementFrameID;
public bool IsTrivial;

public static HashSet<uint> PlayerIdleAnims;

static Sequence()
{
PlayerIdleAnims = new HashSet<uint>();
PlayerIdleAnims.Add(0x03000001); // NonCombat
PlayerIdleAnims.Add(0x0300049E); // AtlatlCombat
PlayerIdleAnims.Add(0x0300045A); // BowCombat
PlayerIdleAnims.Add(0x03000474); // CrossbowCombat
PlayerIdleAnims.Add(0x03000CA8); // DualWieldCombat
PlayerIdleAnims.Add(0x03000448); // HandCombat
PlayerIdleAnims.Add(0x0300076C); // Magic
PlayerIdleAnims.Add(0x0300043D); // SwordCombat
PlayerIdleAnims.Add(0x03000426); // SwordShieldCombat
PlayerIdleAnims.Add(0x030008DF); // ThrownShieldCombat
PlayerIdleAnims.Add(0x0300049E); // ThrownWeaponCombat
PlayerIdleAnims.Add(0x03000B05); // TwoHandedSwordCombat
}

public bool is_idle_anim()
{
return CurrAnim == null || PlayerIdleAnims.Contains(CurrAnim.Value.Anim.ID);
}

public bool is_first_cyclic()
{
return CurrAnim == null || CurrAnim.Equals(FirstCyclic);
}

public Sequence()
{
Init();
Expand Down
2 changes: 1 addition & 1 deletion ACViewer/Physics/BSP/BSPNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public BSPNode(DatLoader.Entity.BSPNode node, Dictionary<ushort, DatLoader.Entit
{
NumPolys = node.InPolys.Count;
PolyIDs = node.InPolys;
Polygons = new List<Polygon>();
Polygons = new List<Polygon>(node.InPolys.Count);
foreach (var poly in node.InPolys)
Polygons.Add(PolygonCache.Get(polys[poly], vertexArray));
}
Expand Down
Loading

0 comments on commit 45eaaab

Please sign in to comment.