Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed Feb 23, 2020
2 parents 1348d78 + 3b98afc commit 6bc11ab
Show file tree
Hide file tree
Showing 26 changed files with 440 additions and 170 deletions.
1 change: 1 addition & 0 deletions src/Configuration/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public Profile(string username, string servername, string charactername)

[JsonProperty] public bool ShowHouseContent { get; set; }
[JsonProperty] public bool SaveHealthbars { get; set; }
[JsonProperty] public bool TextFading { get; set; } = true;


internal static string ProfilePath { get; } = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Profiles");
Expand Down
112 changes: 65 additions & 47 deletions src/Game/GameObjects/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#endregion

using System;

using System.Collections.Generic;
using ClassicUO.Configuration;
using ClassicUO.Game.Data;
using ClassicUO.Game.Managers;
Expand All @@ -41,7 +41,13 @@ internal partial class Item : Entity
private bool _isMulti;


//private static readonly Queue<Item> _pool = new Queue<Item>();
private static readonly Queue<Item> _pool = new Queue<Item>();

static Item()
{
for (int i = 0; i < 5000; i++)
_pool.Enqueue(new Item(0));
}

public Item(uint serial) : base(serial)
{
Expand All @@ -50,50 +56,62 @@ public Item(uint serial) : base(serial)

public static Item Create(uint serial)
{
//if (_pool.Count != 0)
//{
// var i = _pool.Dequeue();
// i.IsDestroyed = false;
// i.Graphic = 0;
// i.uint = serial;
// i._amount = 0;
// i._animDataFrame = default;
// i._animSpeed = 0;
// i._container = 0;
// i._isMulti = false;
// i._layer = 0;
// i._price = 0;
// i._spellsBitFiled = 0;
// i.UsedLayer = false;
// i._originalGraphic = 0;
// i._displayedGraphic = null;

// i.LightID = 0;
// i.MultiDistanceBonus = 0;
// i.BookType = SpellBookType.Unknown;
// i.Flags = 0;
// i.WantUpdateMulti = true;
// i._force = false;
// i.MultiInfo = null;
// i.MultiGraphic = 0;
// i.CharacterIsBehindFoliage = false;

// i.AlphaHue = 0;
// i.Name = null;
// i.Direction = 0;
// i.Equipment = null;
// i.LastAnimationChangeTime = 0;
// i.Items = new EntityCollection<Item>();
// i.IsClicked = false;
// i.Properties.Clear();
// i._delta = 0;
// i.PropertiesHash = 0;

// i._itemData = null;


// return i;
//}
if (_pool.Count != 0)
{
var i = _pool.Dequeue();
i.IsDestroyed = false;
i.Graphic = 0;
i.Serial = serial;
i.Amount = 0;
i._animSpeed = 0;
i.Container = 0;
i._isMulti = false;
i.Layer = 0;
i.Price = 0;
i.UsedLayer = false;
i._originalGraphic = 0;
i._displayedGraphic = null;
i.X = 0;
i.Y = 0;
i.Z = 0;

i.LightID = 0;
i.MultiDistanceBonus = 0;
i.Flags = 0;
i.WantUpdateMulti = true;
i._force = false;
i.MultiInfo = null;
i.MultiGraphic = 0;

i.AlphaHue = 0;
i.Name = null;
i.Direction = 0;
i.Equipment = null;
i.AnimIndex = 0;
i.Hits = 0;
i.HitsMax = 0;
i.LastStepTime = 0;
i.LastAnimationChangeTime = 0;
if (i.Items == null || i.Items.Count != 0)
i.Items = new EntityCollection<Item>();
i.IsClicked = false;
i.IsDamageable = false;
i.Offset = Vector3.Zero;

i.TextContainer?.Clear();
i.IsFlipped = false;
i.Bounds = Rectangle.Empty;
i.FrameInfo = Rectangle.Empty;
i.UseObjectHandles = false;
i.ClosedObjectHandles = false;
i.ObjectHandlesOpened = false;
i.AlphaHue = 0;
i.DrawTransparent = false;
i.AllowedToDraw = true;
i.Texture = null;

return i;
}

return new Item(serial);
}
Expand All @@ -110,7 +128,7 @@ public override void Destroy()

base.Destroy();

//_pool.Enqueue(this);
_pool.Enqueue(this);
}

public uint Price;
Expand Down
2 changes: 1 addition & 1 deletion src/Game/GameObjects/Land.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal sealed partial class Land : GameObject
private static readonly Queue<Land> _pool = new Queue<Land>();
static Land()
{
for (int i = 0; i < 1000; i++)
for (int i = 0; i < 5000; i++)
_pool.Enqueue(new Land());
}

Expand Down
82 changes: 82 additions & 0 deletions src/Game/GameObjects/Mobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;

using ClassicUO.Configuration;
Expand All @@ -46,6 +47,84 @@ public Mobile(uint serial) : base(serial)
CalculateRandomIdleTime();
}


private static readonly Queue<Mobile> _pool = new Queue<Mobile>();

static Mobile()
{
for (int i = 0; i < 1000; i++)
_pool.Enqueue(new Mobile(0));
}

public static Mobile Create(uint serial)
{
if (_pool.Count != 0)
{
Mobile mobile = _pool.Dequeue();
mobile.IsDestroyed = false;
mobile.Graphic = 0;
mobile.Serial = serial;
mobile.Steps.Clear();
mobile.Offset = Vector3.Zero;
mobile.SpeedMode = CharacterSpeedType.Normal;
mobile.DeathScreenTimer = 0;
mobile._isMale = false;
mobile.Race = 0;
mobile.Hits = 0;
mobile.HitsMax = 0;
mobile.Mana = 0;
mobile.ManaMax = 0;
mobile.Stamina = 0;
mobile.StaminaMax = 0;
mobile.NotorietyFlag = 0;
mobile.IsRenamable = false;
mobile.Flags = 0;
mobile.InWarMode = false;
mobile.Equipment = null;
mobile.IsRunning = false;
mobile.AnimationInterval = 0;
mobile.AnimationFrameCount = 0;
mobile.AnimationRepeatMode = 1;
mobile.AnimationRepeat = false;
mobile.AnimationFromServer = false;
mobile.AnimationDirection = false;
mobile.LastStepSoundTime = 0;
mobile.StepSoundOffset = 0;
mobile.Title = string.Empty;
mobile.AnimationGroup = 0xFF;
mobile._isDead = false;
mobile._isSA_Poisoned = false;
mobile._lastAnimationIdleDelay = 0;
mobile.X = 0;
mobile.Y = 0;
mobile.Z = 0;
mobile.Direction = 0;
mobile.LastAnimationChangeTime = Time.Ticks;
mobile.TextContainer?.Clear();
mobile.HitsPercentage = 0;
mobile.HitsTexture?.Destroy();
mobile.HitsTexture = null;
mobile.IsFlipped = false;
mobile.Bounds = Rectangle.Empty;
mobile.FrameInfo = Rectangle.Empty;
mobile.UseObjectHandles = false;
mobile.ClosedObjectHandles = false;
mobile.ObjectHandlesOpened = false;
mobile.AlphaHue = 0;
mobile.DrawTransparent = false;
mobile.AllowedToDraw = true;
mobile.Texture = null;

if (mobile.Items == null || mobile.Items.Count != 0)
mobile.Items = new EntityCollection<Item>();

mobile.CalculateRandomIdleTime();
}

return new Mobile(serial);
}


public Deque<Step> Steps { get; } = new Deque<Step>(Constants.MAX_STEP_COUNT);

public CharacterSpeedType SpeedMode = CharacterSpeedType.Normal;
Expand Down Expand Up @@ -972,6 +1051,9 @@ public override void Destroy()
}

base.Destroy();

if (!(this is PlayerMobile))
_pool.Enqueue(this);
}

internal struct Step
Expand Down
4 changes: 3 additions & 1 deletion src/Game/GameObjects/Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using ClassicUO.IO.Resources;
using ClassicUO.Renderer;
using ClassicUO.Utility;
using Microsoft.Xna.Framework;

namespace ClassicUO.Game.GameObjects
{
Expand All @@ -41,7 +42,7 @@ internal sealed partial class Multi : GameObject

static Multi()
{
for (int i = 0; i < 1000; i++)
for (int i = 0; i < 5000; i++)
_pool.Enqueue(new Multi());
}

Expand Down Expand Up @@ -92,6 +93,7 @@ public static Multi Create(ushort graphic)
m.MultiOffsetX = m.MultiOffsetY = m.MultiOffsetZ = 0;
m.IsCustom = false;
m.State = 0;
m.Offset = Vector3.Zero;

return m;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Game/GameObjects/Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal sealed partial class Static : GameObject
private static readonly Queue<Static> _pool = new Queue<Static>();
static Static()
{
for (int i = 0; i < 1000; i++)
for (int i = 0; i < 5000; i++)
_pool.Enqueue(new Static());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Game/GameObjects/Views/LightningEffectView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override bool Draw(UltimaBatcher2D batcher, int posX, int posY)
return false;

Texture = GumpsLoader.Instance.GetTexture(_displayed);
ref Point offset = ref _offsets[_displayed - 20000];
ref Point offset = ref _offsets[ Utility.RandomHelper.GetValue(0, _offsets.Length - 1)];

Bounds.X = offset.X;
Bounds.Y = Texture.Height - 33 + offset.Y;
Expand Down
34 changes: 25 additions & 9 deletions src/Game/Managers/BoatMovingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ struct ItemInside
private static readonly List<uint> _toRemove = new List<uint>();
private static readonly Dictionary<uint, RawList<ItemInside>> _items = new Dictionary<uint, RawList<ItemInside>>();

private const int SLOW_INTERVAL = 1000;
private const int NORMAL_INTERVAL = 500;
private const int FAST_INTERVAL = 250;

public static void AddStep(uint serial, byte speed, Direction movingDir, Direction facingDir, ushort x, ushort y, sbyte z)
{
Expand Down Expand Up @@ -192,7 +195,27 @@ public static void Update()
break;
}

int maxDelay = step.Speed <= 2 ? 1000 : 250;
bool drift = step.MovingDir != step.FacingDir;

int maxDelay;

switch (step.Speed)
{
case 0x02:
maxDelay = SLOW_INTERVAL;
break;
default:
case 0x03:
maxDelay = NORMAL_INTERVAL;
break;
case 0x04:
maxDelay = FAST_INTERVAL;
break;
}

Console.WriteLine("Speed: {0}, delay: {1}", step.Speed, maxDelay);


int delay = (int) Time.Ticks - (int) item.LastStepTime;
bool removeStep = delay >= maxDelay;
bool directionChange = false;
Expand Down Expand Up @@ -302,14 +325,7 @@ private static void UpdateEntitiesInside(uint serial, bool removeStep, int x, in
{
entity.X = (ushort) (x - it.X);
entity.Y = (ushort) (y - it.Y);
entity.Z = (sbyte) (z - it.Z);

if (entity == World.Player)
{
World.RangeSize.X = entity.X;
World.RangeSize.Y = entity.Y;
}

entity.Z = (sbyte) (z - it.Z);
entity.UpdateScreenPosition();

entity.Offset.X = 0;
Expand Down
6 changes: 2 additions & 4 deletions src/Game/Managers/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ClassicUO.Game.Managers
internal static class UIManager
{
private static readonly TextFileParser _parser = new TextFileParser(string.Empty, new[] { ' ' }, new char[] { }, new[] { '{', '}' });
private static readonly TextFileParser _cmdparser = new TextFileParser(string.Empty, new[] { ' ' }, new char[] { }, new char[] { });
private static readonly TextFileParser _cmdparser = new TextFileParser(string.Empty, new[] { ' ' }, new char[] { }, new char[] { '@', '@' });
private static readonly Dictionary<uint, Point> _gumpPositionCache = new Dictionary<uint, Point>();
private static readonly Control[] _mouseDownControls = new Control[5];

Expand Down Expand Up @@ -621,11 +621,9 @@ public static Control Create(uint sender, uint gumpID, int x, int y, string layo
{
string text = ClilocLoader.Instance.GetString(int.Parse(gparams[1]));

if (gparams.Count > 2 && gparams[2].Length != 0 && gparams[2][0] == '@')
if (gparams.Count > 2 && gparams[2].Length != 0)
{
string args = gparams[2];
//Convert tooltip args format to standard cliloc format
args = args.Trim('@').Replace('@', '\t');

if (args.Length > 1)
text = ClilocLoader.Instance.Translate(text, args);
Expand Down
Loading

0 comments on commit 6bc11ab

Please sign in to comment.