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

Experimental client performance improvement #1035

Open
wants to merge 4 commits 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
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
28 changes: 13 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,14 @@ 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;
MapControl.ObjectsList.Add(this);
RestoreTargetStates();
}

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

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

if (ObjectID == Hero?.ObjectID)
Expand Down
59 changes: 24 additions & 35 deletions Client/MirObjects/MonsterObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,28 +434,25 @@ public override void Process()
for (int i = 0; i < Effects.Count; i++)
Effects[i].Process();

Color colour = DrawColour;
if (Poison == PoisonType.None)
DrawColour = Color.White;
if (Poison.HasFlag(PoisonType.Green))
DrawColour = Color.Green;
if (Poison.HasFlag(PoisonType.Red))
DrawColour = Color.Red;
if (Poison.HasFlag(PoisonType.Bleeding))
DrawColour = Color.DarkRed;
if (Poison.HasFlag(PoisonType.Slow))
DrawColour = Color.Purple;
if (Poison.HasFlag(PoisonType.Stun) || Poison.HasFlag(PoisonType.Dazed))
DrawColour = Color.Yellow;
if (Poison.HasFlag(PoisonType.Blindness))
DrawColour = Color.MediumVioletRed;
if (Poison.HasFlag(PoisonType.Frozen))
DrawColour = Color.Blue;
if (Poison.HasFlag(PoisonType.Paralysis) || Poison.HasFlag(PoisonType.LRParalysis))
DrawColour = Color.Gray;
if (Poison.HasFlag(PoisonType.DelayedExplosion))
DrawColour = Color.Orange;
if (colour != DrawColour) GameScene.Scene.MapControl.TextureValid = false;
Color newColour = Poison switch
{
_ when (Poison & PoisonType.DelayedExplosion) == PoisonType.DelayedExplosion => Color.Orange,
_ when (Poison & (PoisonType.Paralysis | PoisonType.LRParalysis)) != 0 => Color.Gray,
_ when (Poison & PoisonType.Frozen) == PoisonType.Frozen => Color.Blue,
_ when (Poison & PoisonType.Blindness) == PoisonType.Blindness => Color.MediumVioletRed,
_ when (Poison & (PoisonType.Stun | PoisonType.Dazed)) != 0 => Color.Yellow,
_ when (Poison & PoisonType.Slow) == PoisonType.Slow => Color.Purple,
_ when (Poison & PoisonType.Bleeding) == PoisonType.Bleeding => Color.DarkRed,
_ when (Poison & PoisonType.Red) == PoisonType.Red => Color.Red,
_ when (Poison & PoisonType.Green) == PoisonType.Green => Color.Green,
_ => Color.White
};

if (newColour != DrawColour)
{
DrawColour = newColour;
GameScene.Scene.MapControl.TextureValid = false;
}
}

public bool SetAction()
Expand Down Expand Up @@ -1037,31 +1034,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
84 changes: 29 additions & 55 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 @@ -862,33 +862,25 @@ public override void Process()
for (int i = 0; i < Effects.Count; i++)
Effects[i].Process();

Color colour = DrawColour;
DrawColour = Color.White;
if (Poison != PoisonType.None)
Color newColour = Poison switch
{

if (Poison.HasFlag(PoisonType.Green))
DrawColour = Color.Green;
if (Poison.HasFlag(PoisonType.Red))
DrawColour = Color.Red;
if (Poison.HasFlag(PoisonType.Bleeding))
DrawColour = Color.DarkRed;
if (Poison.HasFlag(PoisonType.Slow))
DrawColour = Color.Purple;
if (Poison.HasFlag(PoisonType.Stun) || Poison.HasFlag(PoisonType.Dazed))
DrawColour = Color.Yellow;
if (Poison.HasFlag(PoisonType.Blindness))
DrawColour = Color.MediumVioletRed;
if (Poison.HasFlag(PoisonType.Frozen))
DrawColour = Color.Blue;
if (Poison.HasFlag(PoisonType.Paralysis) || Poison.HasFlag(PoisonType.LRParalysis))
DrawColour = Color.Gray;
if (Poison.HasFlag(PoisonType.DelayedExplosion))
DrawColour = Color.Orange;
}

_ when (Poison & PoisonType.DelayedExplosion) == PoisonType.DelayedExplosion => Color.Orange,
_ when (Poison & (PoisonType.Paralysis | PoisonType.LRParalysis)) != 0 => Color.Gray,
_ when (Poison & PoisonType.Frozen) == PoisonType.Frozen => Color.Blue,
_ when (Poison & PoisonType.Blindness) == PoisonType.Blindness => Color.MediumVioletRed,
_ when (Poison & (PoisonType.Stun | PoisonType.Dazed)) != 0 => Color.Yellow,
_ when (Poison & PoisonType.Slow) == PoisonType.Slow => Color.Purple,
_ when (Poison & PoisonType.Bleeding) == PoisonType.Bleeding => Color.DarkRed,
_ when (Poison & PoisonType.Red) == PoisonType.Red => Color.Red,
_ when (Poison & PoisonType.Green) == PoisonType.Green => Color.Green,
_ => Color.White
};

if (colour != DrawColour) GameScene.Scene.MapControl.TextureValid = false;
if (newColour != DrawColour)
{
DrawColour = newColour;
GameScene.Scene.MapControl.TextureValid = false;
}
}
public virtual void SetAction()
{
Expand All @@ -910,19 +902,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 +967,6 @@ public virtual void SetAction()
QueuedAction action = ActionFeed[0];
ActionFeed.RemoveAt(0);


CurrentAction = action.Action;

if (RidingMount)
Expand Down Expand Up @@ -1036,8 +1023,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 +1049,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 +1602,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 +2308,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 +2326,6 @@ public virtual void ProcessFrames()
if (FrameIndex == 1 || FrameIndex == 4)
PlayStepSound();
}
//NextMotion += FrameInterval;
}

UpdateWingEffect();
Expand Down
4 changes: 1 addition & 3 deletions Client/MirScenes/Dialogs/BigMapDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,8 @@ private void OnBeforeDraw()
{
float x;
float y;
for (int i = MapControl.Objects.Count - 1; i >= 0; i--)
foreach (var ob in MapControl.Objects.Values)
{
MapObject ob = MapControl.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;
y = ((ob.CurrentLocation.Y - startPointY) * ScaleY) + DisplayLocation.Y;
Expand Down
4 changes: 1 addition & 3 deletions Client/MirScenes/Dialogs/MainDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,10 +1915,8 @@ 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--)
foreach (var ob in MapControl.Objects.Values)
{
MapObject ob = MapControl.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;
float y = ((ob.CurrentLocation.Y - startPointY) * scaleY) + drawLocation.Y;
Expand Down
Loading