Skip to content

Commit

Permalink
[Tests] Added tests for BoatPhysicsManager: (AAEmu#1115)
Browse files Browse the repository at this point in the history
- tests were not added for all methods.
  • Loading branch information
NL0bP authored Dec 15, 2024
1 parent 79c3849 commit b757905
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 16 deletions.
20 changes: 10 additions & 10 deletions AAEmu.Game/Core/Managers/World/BoatPhysicsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace AAEmu.Game.Core.Managers.World
public class BoatPhysicsManager
{
private float TargetPhysicsTps { get; set; } = 100f;
private Thread _thread;
internal Thread _thread;
private static Logger Logger { get; } = LogManager.GetCurrentClassLogger();

private CollisionSystem _collisionSystem;
private Jitter.World _physWorld;
private Buoyancy _buoyancy;
private bool ThreadRunning { get; set; }
internal CollisionSystem _collisionSystem;
internal Jitter.World _physWorld;
internal Buoyancy _buoyancy;
public bool ThreadRunning { get; set; }
public InstanceWorld SimulationWorld { get; set; }
private readonly object _slaveListLock = new();
private Random _random = new();
Expand Down Expand Up @@ -70,7 +70,7 @@ public void Initialize()
Logger.Info("BoatPhysicsManager initialized.");
}

private bool CustomWater(ref JVector area)
public bool CustomWater(ref JVector area)
{
return SimulationWorld?.IsWater(new Vector3(area.X, area.Z, area.Y)) ?? area.Y <= _waterLevel;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public void RemoveShip(Slave slave)
Logger.Debug($"RemoveShip {slave.Name} <- {SimulationWorld.Name}");
}

private void BoatPhysicsTick(Slave slave, RigidBody rigidBody)
public void BoatPhysicsTick(Slave slave, RigidBody rigidBody)
{
var shipModel = ModelManager.Instance.GetShipModel(slave.Template.ModelId);
if (shipModel == null) return;
Expand Down Expand Up @@ -260,7 +260,7 @@ private void BoatPhysicsTick(Slave slave, RigidBody rigidBody)
public static float GetRollAngle(JMatrix orientation)
{
var yawPitchRoll = GetYawPitchRollFromJMatrix(orientation);
return yawPitchRoll.Item3; // Roll angle in radians
return yawPitchRoll.Item2; // Roll angle in radians
}

public static (float, float, float) GetYawPitchRollFromJMatrix(JMatrix mat)
Expand Down Expand Up @@ -290,7 +290,7 @@ private void ApplyCollisions(Slave slave, RigidBody rigidBody, ShipModel shipMod
{
var floor = WorldManager.Instance.GetHeight(slave.Transform);
var boxSize = rigidBody.Shape.BoundingBox.Max - rigidBody.Shape.BoundingBox.Min;
var boatBottom = rigidBody.Position.Y/* - boxSize.Y / 2*/ - shipModel.MassBoxSizeZ/2 - shipModel.KeelHeight + shipModel.MassCenterZ;
var boatBottom = rigidBody.Position.Y/* - boxSize.Y / 2*/ - shipModel.MassBoxSizeZ / 2 - shipModel.KeelHeight + shipModel.MassCenterZ;

if (boatBottom < floor)
{
Expand Down Expand Up @@ -413,4 +413,4 @@ private void SendUpdatedMovementData(Slave slave, RigidBody rigidBody)
slave.Transform.FinalizeTransform();
}
}
}
}
3 changes: 2 additions & 1 deletion AAEmu.Game/Core/Managers/World/WorldManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using AAEmu.Commons.IO;
using AAEmu.Commons.Utils;
using AAEmu.Commons.Utils.XML;
using AAEmu.Game.Core.Managers.AAEmu.Game.Core.Managers;
using AAEmu.Game.Core.Managers.Id;
using AAEmu.Game.Core.Network.Game;
using AAEmu.Game.Core.Packets.G2C;
Expand Down Expand Up @@ -578,7 +579,7 @@ public void LoadWaterBodies()
}
}

public InstanceWorld GetWorld(uint worldId)
public virtual InstanceWorld GetWorld(uint worldId)
{
if (_worlds.TryGetValue(worldId, out var res))
return res;
Expand Down
2 changes: 1 addition & 1 deletion AAEmu.Game/Models/Game/Units/Slave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Slave : Unit
public float RotationDegrees { get; set; }
public sbyte AttachPointId { get; set; } = -1;
public uint OwnerObjId { get; set; }
public RigidBody RigidBody { get; set; }
public virtual RigidBody RigidBody { get; set; }
public SlaveSpawner Spawner { get; set; }
public Task LeaveTask { get; set; }
public CancellationTokenSource CancelTokenSource { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions AAEmu.Game/Models/Game/World/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class World
private static Logger Logger = LogManager.GetCurrentClassLogger();

public uint Id { get; set; } // iid - InstanceId
public string Name { get; set; }
public virtual string Name { get; set; }
public float MaxHeight { get; set; }
public double HeightMaxCoefficient { get; set; }
public virtual double HeightMaxCoefficient { get; set; }
public float OceanLevel { get; set; }
public int CellX { get; set; }
public int CellY { get; set; }
public uint TemplateId { get; set; } // worldId
public WorldSpawnPosition SpawnPosition { get; set; } = new();
public Region[,] Regions { get; set; } // TODO ... world - okay, instance - ....
public ushort[,] HeightMaps { get; set; }
public virtual ushort[,] HeightMaps { get; set; }
public List<uint> ZoneKeys { get; set; } = [];
public ConcurrentDictionary<uint, XmlWorldZone> XmlWorldZones;
public BoatPhysicsManager Physics { get; set; }
Expand All @@ -46,7 +46,7 @@ public World()
Logger.Info($"World {Id} removed");
}

public bool IsWater(Vector3 point)
public virtual bool IsWater(Vector3 point)
{
if (Water != null)
return Water.IsWater(point);
Expand Down
Loading

0 comments on commit b757905

Please sign in to comment.