Skip to content

Experimental client performance improvement #1035

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

Merged
merged 4 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion Client/MirControls/MirControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ public virtual void OnKeyUp(KeyEventArgs e)
public virtual void Redraw()
{
if (Parent != null) Parent.Redraw();

}

#region Font
Expand Down
26 changes: 11 additions & 15 deletions Client/MirObjects/MapObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ public abstract class MapObject
private static uint mouseObjectID;
public static uint MouseObjectID
{
get { return mouseObjectID; }
get => mouseObjectID;
set
{
if (mouseObjectID == value) return;
mouseObjectID = value;
MouseObject = MapControl.Objects.Find(x => x.ObjectID == value);
MouseObject = MapControl.Objects.TryGetValue(value, out var obj) ? obj : null;
}
}

private static uint lastTargetObjectId;
private static uint targetObjectID;
public static uint TargetObjectID
{
get { return targetObjectID; }
get => targetObjectID;
set
{
if (targetObjectID == value) return;
lastTargetObjectId = value;
targetObjectID = value;
TargetObject = value == 0 ? null : MapControl.Objects.Find(x => x.ObjectID == value);
TargetObject = MapControl.Objects.TryGetValue(value, out var obj) ? obj : null;
}
}

private static uint magicObjectID;
public static uint MagicObjectID
{
get { return magicObjectID; }
get => magicObjectID;
set
{
if (magicObjectID == value) return;
magicObjectID = value;
MagicObject = MapControl.Objects.Find(x => x.ObjectID == value);
MagicObject = MapControl.Objects.TryGetValue(value, out var obj) ? obj : null;
}
}

Expand Down Expand Up @@ -143,17 +143,13 @@ protected MapObject(uint objectID)
{
ObjectID = objectID;

for (int i = MapControl.Objects.Count - 1; i >= 0; i--)
{
MapObject ob = MapControl.Objects[i];
if (ob.ObjectID != ObjectID) continue;
ob.Remove();
}

MapControl.Objects.Add(this);
if (MapControl.Objects.TryGetValue(ObjectID, out var existingObject))
existingObject.Remove();

MapControl.Objects[ObjectID] = this;
RestoreTargetStates();
}

public void Remove()
{
if (MouseObject == this) MouseObjectID = 0;
Expand All @@ -167,7 +163,7 @@ public void Remove()
if (this == User.NextMagicObject)
User.ClearMagic();

MapControl.Objects.Remove(this);
MapControl.Objects.Remove(ObjectID);
GameScene.Scene.MapControl.RemoveObject(this);

if (ObjectID == Hero?.ObjectID)
Expand Down
18 changes: 5 additions & 13 deletions Client/MirObjects/MonsterObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,31 +1037,23 @@ public bool SetAction()
case MirAction.Struck:
uint attackerID = (uint)action.Params[0];
StruckWeapon = -2;
for (int i = 0; i < MapControl.Objects.Count; i++)
MapObject ob = MapControl.Objects[attackerID];
if (ob.Race == ObjectType.Player)
{
MapObject ob = MapControl.Objects[i];
if (ob.ObjectID != attackerID) continue;
if (ob.Race != ObjectType.Player) break;
PlayerObject player = ((PlayerObject)ob);
PlayerObject player = (PlayerObject)ob;
StruckWeapon = player.Weapon;
if (player.Class != MirClass.Assassin || StruckWeapon == -1) break; //Archer?
StruckWeapon = 1;
break;
if (player.Class == MirClass.Assassin && StruckWeapon > -1)
StruckWeapon = 1;
}
PlayFlinchSound();
PlayStruckSound();


// Sanjian
switch (BaseImage)
{
case Monster.GlacierBeast:
Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.GlacierBeast], 304, 6, 400, this));
break;
}



break;
case MirAction.Die:
switch (BaseImage)
Expand Down
42 changes: 12 additions & 30 deletions Client/MirObjects/PlayerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public override void Process()
GameScene.CanRun = false;
}

SkipFrames = this != User && ActionFeed.Count > 1;
SkipFrames = this != User && ActionFeed.Count > 0;

ProcessFrames();

Expand Down Expand Up @@ -910,19 +910,15 @@ public virtual void SetAction()
}
}

if (User == this && CMain.Time < MapControl.NextAction)// && CanSetAction)
{
//NextMagic = null;
if (User == this && CMain.Time < MapControl.NextAction)
return;
}


if (ActionFeed.Count == 0)
{
CurrentAction = MirAction.Standing;

CurrentAction = CMain.Time > BlizzardStopTime ? CurrentAction : MirAction.Stance2;
//CurrentAction = CMain.Time > SlashingBurstTime ? CurrentAction : MirAction.Lunge;

if (RidingMount)
{
Expand Down Expand Up @@ -979,7 +975,6 @@ public virtual void SetAction()
QueuedAction action = ActionFeed[0];
ActionFeed.RemoveAt(0);


CurrentAction = action.Action;

if (RidingMount)
Expand Down Expand Up @@ -1036,8 +1031,6 @@ public virtual void SetAction()
break;
}

temp = new Point(action.Location.X, temp.Y > CurrentLocation.Y ? temp.Y : CurrentLocation.Y);

if (MapLocation != temp)
{
GameScene.Scene.MapControl.RemoveObject(this);
Expand All @@ -1064,8 +1057,6 @@ public virtual void SetAction()
break;
case MirAction.DashFail:
Frames.TryGetValue(RidingMount ? MirAction.MountStanding : MirAction.Standing, out Frame);
//Frames.TryGetValue(MirAction.Standing, out Frame);
//CanSetAction = false;
break;
case MirAction.Jump:
Frames.TryGetValue(MirAction.Jump, out Frame);
Expand Down Expand Up @@ -1619,17 +1610,15 @@ public virtual void SetAction()
case MirAction.MountStruck:
uint attackerID = (uint)action.Params[0];
StruckWeapon = -2;
for (int i = 0; i < MapControl.Objects.Count; i++)
{
MapObject ob = MapControl.Objects[i];
if (ob.ObjectID != attackerID) continue;
if (ob.Race != ObjectType.Player) break;
PlayerObject player = ((PlayerObject)ob);
StruckWeapon = player.Weapon;
if (player.Class != MirClass.Assassin || StruckWeapon == -1) break;
StruckWeapon = 1;
break;
}

if (MapControl.Objects.TryGetValue(attackerID, out MapObject ob))
if (ob.Race == ObjectType.Player)
{
PlayerObject player = (PlayerObject)ob;
StruckWeapon = player.Weapon;
if (player.Class == MirClass.Assassin && StruckWeapon != -1)
StruckWeapon = 1;
}

PlayStruckSound();
PlayFlinchSound();
Expand Down Expand Up @@ -2327,20 +2316,14 @@ public virtual void ProcessFrames()
case MirAction.Sneek:
case MirAction.DashAttack:
if (!GameScene.CanMove) return;


GameScene.Scene.MapControl.TextureValid = false;

if (this == User) GameScene.Scene.MapControl.FloorValid = false;
//if (CMain.Time < NextMotion) return;
if (SkipFrames) UpdateFrame();


if (SkipFrames) FrameIndex = Frame.Count;

if (UpdateFrame(false) >= Frame.Count)
{


FrameIndex = Frame.Count - 1;
SetAction();
}
Expand All @@ -2351,7 +2334,6 @@ public virtual void ProcessFrames()
if (FrameIndex == 1 || FrameIndex == 4)
PlayStepSound();
}
//NextMotion += FrameInterval;
}

UpdateWingEffect();
Expand Down
5 changes: 3 additions & 2 deletions Client/MirScenes/Dialogs/BigMapDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,10 @@ private void OnBeforeDraw()
{
float x;
float y;
for (int i = MapControl.Objects.Count - 1; i >= 0; i--)
var objects = MapControl.Objects.Values.ToList();
for (int i = objects.Count - 1; i >= 0; i--)
{
MapObject ob = MapControl.Objects[i];
MapObject ob = objects[i];

if (ob.Race == ObjectType.Item || ob.Dead || ob.Race == ObjectType.Spell || ob.ObjectID == MapObject.User.ObjectID) continue;
x = ((ob.CurrentLocation.X - startPointX) * ScaleX) + DisplayLocation.X;
Expand Down
5 changes: 3 additions & 2 deletions Client/MirScenes/Dialogs/MainDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,9 +1915,10 @@ private void MiniMap_BeforeDraw(object sender, EventArgs e)
int startPointX = (int)(viewRect.X / scaleX);
int startPointY = (int)(viewRect.Y / scaleY);

for (int i = MapControl.Objects.Count - 1; i >= 0; i--)
var objects = MapControl.Objects.Values.ToList();
for (int i = objects.Count - 1; i >= 0; i--)
{
MapObject ob = MapControl.Objects[i];
MapObject ob = objects[i];

if (ob.Race == ObjectType.Item || ob.Dead || ob.Race == ObjectType.Spell || ob.Sneaking) continue;
float x = ((ob.CurrentLocation.X - startPointX) * scaleX) + drawLocation.X;
Expand Down
Loading