fix: Cleans up Point checks and removes statics (#966)

- [X] Removes static freezing/unfreezing. Use other tools for this.
- [X] Cleans up IPoint3D allocations
- [X] Removes IPoint3D constructors since the compiler may not optimize the constructor path and allow allocations.


Note: Instead of `new Point3D(m)`, do something like `new Point3D(m.Location)`. Sorry for the inconvenience. In the long run this will prevent abuse of hot paths that will cause performance issues.
This commit is contained in:
Kamron Batman 2022-03-20 23:15:59 -07:00 committed by GitHub
parent 23532db603
commit 0925a2d435
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 184 additions and 958 deletions

View file

@ -12,41 +12,45 @@ namespace Server.Targets
protected override void OnTarget(Mobile from, object o)
{
if (o is IPoint3D p)
if (o is not IPoint3D ip)
{
if (!BaseCommand.IsAccessible(from, m_Object))
{
from.SendLocalizedMessage(500447); // That is not accessible.
return;
}
return;
}
if (p is Item pItem)
{
p = pItem.GetWorldTop();
}
if (!BaseCommand.IsAccessible(from, m_Object))
{
from.SendLocalizedMessage(500447); // That is not accessible.
return;
}
CommandLogging.WriteLine(
from,
"{0} {1} moving {2} to {3}",
from.AccessLevel,
CommandLogging.Format(from),
CommandLogging.Format(m_Object),
new Point3D(p)
);
Point3D p = ip switch
{
Item i => i.GetWorldTop(),
Mobile m => m.Location,
_ => new Point3D(ip)
};
if (m_Object is Item item)
CommandLogging.WriteLine(
from,
"{0} {1} moving {2} to {3}",
from.AccessLevel,
CommandLogging.Format(from),
CommandLogging.Format(m_Object),
p
);
if (m_Object is Item item)
{
if (!item.Deleted)
{
if (!item.Deleted)
{
item.MoveToWorld(new Point3D(p), from.Map);
}
item.MoveToWorld(p, from.Map);
}
else if (m_Object is Mobile m)
}
else if (m_Object is Mobile m)
{
if (!m.Deleted)
{
if (!m.Deleted)
{
m.MoveToWorld(new Point3D(p), from.Map);
}
m.MoveToWorld(p, from.Map);
}
}
}