Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements to Physics.Common.WeenieObject #4212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Source/ACE.Server/Physics/Animation/MotionInterp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void HitGround()
{
if (PhysicsObj == null) return;

if (WeenieObj != null && !WeenieObj.IsCreature()) return;
if (WeenieObj != null && !WeenieObj.IsCreature) return;

if (!PhysicsObj.State.HasFlag(PhysicsState.Gravity)) return;

Expand All @@ -193,7 +193,7 @@ public void LeaveGround()
{
if (PhysicsObj == null) return;

if (WeenieObj != null && !WeenieObj.IsCreature()) return;
if (WeenieObj != null && !WeenieObj.IsCreature) return;

if (!PhysicsObj.State.HasFlag(PhysicsState.Gravity)) return;

Expand Down Expand Up @@ -265,7 +265,7 @@ public void ReportExhaustion()
{
if (PhysicsObj == null || !Initted) return;

if (WeenieObj == null || WeenieObj.IsCreature() && PhysicsObj.movement_is_autonomous())
if (WeenieObj == null || WeenieObj.IsCreature && PhysicsObj.movement_is_autonomous())
apply_raw_movement(false, false);
else
apply_interpreted_movement(false, false);
Expand Down Expand Up @@ -393,7 +393,7 @@ public void add_to_queue(int contextID, uint motion, WeenieError jumpErrorCode)

public void adjust_motion(ref uint motion, ref float speed, HoldKey holdKey)
{
if (WeenieObj != null && !WeenieObj.IsCreature())
if (WeenieObj != null && !WeenieObj.IsCreature)
return;

switch (motion)
Expand Down Expand Up @@ -431,7 +431,7 @@ public void apply_current_movement(bool cancelMoveTo, bool allowJump)
{
if (PhysicsObj == null || !Initted) return;

if (WeenieObj != null && !WeenieObj.IsCreature() || !PhysicsObj.movement_is_autonomous())
if (WeenieObj != null && !WeenieObj.IsCreature || !PhysicsObj.movement_is_autonomous())
apply_interpreted_movement(cancelMoveTo, allowJump);
else
apply_raw_movement(cancelMoveTo, allowJump);
Expand Down Expand Up @@ -588,7 +588,7 @@ public bool contact_allows_move(uint motion)
if (motion == (uint)MotionCommand.Dead || motion == (uint)MotionCommand.Falling || motion >= (uint)MotionCommand.TurnRight && motion <= (uint)MotionCommand.TurnLeft)
return true;

if (WeenieObj != null && !WeenieObj.IsCreature())
if (WeenieObj != null && !WeenieObj.IsCreature)
return true;

if (!PhysicsObj.State.HasFlag(PhysicsState.Gravity))
Expand Down Expand Up @@ -744,7 +744,7 @@ public WeenieError jump_is_allowed(float extent, int staminaCost)
if (PhysicsObj == null)
return WeenieError.NoPhysicsObject;

if (WeenieObj == null && !WeenieObj.IsCreature() || !PhysicsObj.State.HasFlag(PhysicsState.Gravity) ||
if (WeenieObj == null && !WeenieObj.IsCreature || !PhysicsObj.State.HasFlag(PhysicsState.Gravity) ||
PhysicsObj.TransientState.HasFlag(TransientStateFlags.Contact | TransientStateFlags.OnWalkable))
{
if (PhysicsObj.IsFullyConstrained())
Expand Down Expand Up @@ -811,7 +811,7 @@ public bool move_to_interpreted_state(InterpretedMotionState state)

if (diff)
{
if (WeenieObj != null && WeenieObj.IsCreature() || action.Autonomous)
if (WeenieObj != null && WeenieObj.IsCreature || action.Autonomous)
{
ServerActionStamp = action.Stamp;
movementParams.Speed = action.Speed;
Expand Down
96 changes: 51 additions & 45 deletions Source/ACE.Server/Physics/Common/WeenieObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,58 @@

namespace ACE.Server.Physics.Common
{
public class WeenieObject
public sealed class WeenieObject
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public uint ID;
public double UpdateTime;
// public readonly uint ID;
// public readonly double UpdateTime;
public readonly WorldObjectInfo WorldObjectInfo;
public WorldObject WorldObject => WorldObjectInfo?.TryGetWorldObject();

public bool IsMonster { get; set; }

public bool IsCombatPet { get; set; }
public readonly bool IsPlayer;
public readonly bool IsCreature;
public readonly bool IsStorage;
public readonly bool IsCorpse;

public bool IsFactionMob { get; set; }
public readonly bool IsMonster;

public FactionBits Faction1Bits { get; set; }
public readonly bool IsCombatPet;

public CreatureType? FoeType { get; set; }
public readonly bool IsFactionMob;

public PlayerKillerStatus PlayerKillerStatus { get; set; }
public readonly FactionBits Faction1Bits;

public WeenieObject() { }
public readonly CreatureType? FoeType;

public readonly PlayerKillerStatus PlayerKillerStatus;

private WeenieObject() { }

public static readonly WeenieObject DummyObject = new();

public WeenieObject(WorldObject worldObject)
{
WorldObjectInfo = new WorldObjectInfo(worldObject);

if (!(worldObject is Creature creature))
if (worldObject is not Creature creature)
{
if (worldObject is Corpse)
IsCorpse = true;
else if (worldObject is Storage)
IsStorage = true;
return;
}

IsCreature = true;

IsCombatPet = worldObject is CombatPet;
if (creature is Player)
IsPlayer = true;
else if (creature is CombatPet)
IsCombatPet = true;
else if (creature.IsMonster)
IsMonster = true;

IsMonster = creature.IsMonster && !IsCombatPet;

Faction1Bits = creature.Faction1Bits ?? FactionBits.None;

Expand Down Expand Up @@ -74,6 +93,9 @@ public bool InqJumpVelocity(float extent, out float velocity_z)
{
velocity_z = 0.0f;

if (!IsPlayer)
return false;

var player = WorldObject as Player;

if (player == null)
Expand Down Expand Up @@ -103,6 +125,9 @@ public bool InqJumpVelocity(float extent, out float velocity_z)
/// </summary>
public float? InqBurden()
{
if (!IsPlayer)
return null;

var player = WorldObject as Player;

if (player == null)
Expand Down Expand Up @@ -134,39 +159,19 @@ public bool InqRunRate(ref float rate)
return true;
}

public bool IsCorpse()
{
return WorldObject is Corpse;
}

public bool IsImpenetrable()
{
return WorldObject is Player player && player.PlayerKillerStatus == PlayerKillerStatus.Free;
return IsPlayer && WorldObject is Player player && player.PlayerKillerStatus == PlayerKillerStatus.Free;
}

public bool IsPK()
{
return WorldObject is Player player && player.IsPK;
return IsPlayer && WorldObject is Player player && player.IsPK;
}

public bool IsPKLite()
{
return WorldObject is Player player && player.IsPKL;
}

public bool IsPlayer()
{
return WorldObject is Player;
}

public bool IsCreature()
{
return WorldObject is Creature;
}

public bool IsStorage()
{
return WorldObject is Storage;
return IsPlayer && WorldObject is Player player && player.IsPKL;
}

public float JumpStaminaCost(float extent, int staminaCost)
Expand All @@ -179,20 +184,21 @@ public void InqCollisionProfile(ObjCollisionProfile prof)
if (WorldObject == null)
return;

prof.WCID = ID;
// prof.WCID = ID;
prof.ItemType = WorldObject.ItemType;

if (WorldObject is Creature)
if (IsCreature)
{
prof.Flags |= ObjCollisionProfileFlags.Creature;

if (WorldObject is Player)
prof.Flags |= ObjCollisionProfileFlags.Player;
if (IsPlayer)
prof.Flags |= ObjCollisionProfileFlags.Player;
}
else if (WorldObject is Door)
prof.Flags |= ObjCollisionProfileFlags.Door;

if (WorldObject.Attackable)
prof.Flags |= ObjCollisionProfileFlags.Attackable;

if (WorldObject is Door)
prof.Flags |= ObjCollisionProfileFlags.Door;
}

public int DoCollision(ObjCollisionProfile prof, ObjectGuid guid, PhysicsObj target)
Expand Down Expand Up @@ -232,7 +238,7 @@ public int DoCollision(EnvCollisionProfile prof, ObjectGuid guid, PhysicsObj tar
if (wo == null)
return 0;

if (wo is Player player)
if (IsPlayer && wo is Player player)
player.HandleFallingDamage(prof);
else
wo.OnCollideEnvironment();
Expand Down
4 changes: 2 additions & 2 deletions Source/ACE.Server/Physics/ObjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Init(PhysicsObj obj, ObjectInfoState state)
{
if (wobj.IsImpenetrable())
State |= ObjectInfoState.IsImpenetrable;
if (wobj.IsPlayer())
if (wobj.IsPlayer)
State |= ObjectInfoState.IsPlayer;
if (wobj.IsPK())
State |= ObjectInfoState.IsPK;
Expand Down Expand Up @@ -86,7 +86,7 @@ public bool MissileIgnore(PhysicsObj collideObj)
{
if (collideObj.WeenieObj != null && collideObj.ID != TargetID)
{
if (collideObj.State.HasFlag(PhysicsState.Ethereal) || TargetID != 0 && collideObj.WeenieObj.IsCreature())
if (collideObj.State.HasFlag(PhysicsState.Ethereal) || TargetID != 0 && collideObj.WeenieObj.IsCreature)
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.Server/Physics/PhysicsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static bool SetObjectMovement(PhysicsObj obj, object buffer, int size, in
else
return false;

var isPlayer = obj.WeenieObj != null && !obj.WeenieObj.IsPlayer();
var isPlayer = obj.WeenieObj != null && !obj.WeenieObj.IsPlayer;
if (!isPlayer || !autonomous)
{
obj.LastMoveWasAutonomous = autonomous;
Expand Down
10 changes: 5 additions & 5 deletions Source/ACE.Server/Physics/PhysicsObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public PhysicsObj()

// todo: only allocate these for server objects
// get rid of 'DatObject', use the existing WeenieObj == null
WeenieObj = new WeenieObject();
WeenieObj = WeenieObject.DummyObject;
ObjMaint = new ObjectMaint(this);

if (PhysicsEngine.Instance != null && PhysicsEngine.Instance.Server)
Expand Down Expand Up @@ -385,7 +385,7 @@ public TransitionState FindObjCollisions(Transition transition)
if (State.HasFlag(PhysicsState.Ethereal) && State.HasFlag(PhysicsState.IgnoreCollisions))
return TransitionState.OK;

if (WeenieObj != null && transition.ObjectInfo.State.HasFlag(ObjectInfoState.IsViewer) && WeenieObj.IsCreature())
if (WeenieObj != null && transition.ObjectInfo.State.HasFlag(ObjectInfoState.IsViewer) && WeenieObj.IsCreature)
return TransitionState.OK;

if (State.HasFlag(PhysicsState.Ethereal) || !State.HasFlag(PhysicsState.Static) && transition.ObjectInfo.Ethereal)
Expand All @@ -400,13 +400,13 @@ public TransitionState FindObjCollisions(Transition transition)

// TODO: reverse this check to make it more readable
// TODO: investigate not initting WeenieObj for DatObjects
var exemption = !( /*WeenieObj == null*/ DatObject || !WeenieObj.IsPlayer() || !state.HasFlag(ObjectInfoState.IsPlayer) ||
var exemption = !( /*WeenieObj == null*/ DatObject || !WeenieObj.IsPlayer || !state.HasFlag(ObjectInfoState.IsPlayer) ||
state.HasFlag(ObjectInfoState.IsImpenetrable) || WeenieObj.IsImpenetrable() ||
state.HasFlag(ObjectInfoState.IsPK) && WeenieObj.IsPK() || state.HasFlag(ObjectInfoState.IsPKLite) && WeenieObj.IsPKLite());

var missileIgnore = transition.ObjectInfo.MissileIgnore(this);

var isCreature = State.HasFlag(PhysicsState.Missile) || WeenieObj != null && WeenieObj.IsCreature();
var isCreature = State.HasFlag(PhysicsState.Missile) || WeenieObj != null && WeenieObj.IsCreature;
//isCreature = false; // hack?

if (!State.HasFlag(PhysicsState.HasPhysicsBSP) || missileIgnore || exemption)
Expand Down Expand Up @@ -1289,7 +1289,7 @@ public SetPositionError SetPositionInternal(Position pos, SetPosition setPos, Tr
return SetPositionError.OK;
}

if (WeenieObj != null && (WeenieObj.IsStorage() || WeenieObj.IsCorpse()))
if (WeenieObj != null && (WeenieObj.IsStorage || WeenieObj.IsCorpse))
return ForceIntoCell(newCell, pos);

//if (setPos.Flags.HasFlag(SetPositionFlags.DontCreateCells))
Expand Down