Skip to content

Commit

Permalink
Improved performance for DirectEve's Entities, Items and Modules by d…
Browse files Browse the repository at this point in the history
…elay-loading their properties

Made a lot of properties not-nullable, they will return -1 if not present in eve (due to this I had to clean up Questor's code a bit)
Removed Name property from items, it was a synonym for TypeName
  • Loading branch information
Da-Teach committed Mar 12, 2011
1 parent 476f7cb commit 1e98dd2
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
Binary file modified DirectEve/DirectEve.dll
Binary file not shown.
12 changes: 6 additions & 6 deletions Questor.Modules/Arm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void ProcessState()
break;
}

var neededDrones = Math.Floor((droneBay.Capacity - droneBay.UsedCapacity)/(drone.Volume ?? 5d));
var neededDrones = Math.Floor((droneBay.Capacity - droneBay.UsedCapacity)/drone.Volume);
if (neededDrones == 0)
{
Logging.Log("Arm: Moving items");
Expand All @@ -240,13 +240,13 @@ public void ProcessState()

if (!_missionItemMoved)
{
var missionItem = (corpHangar ?? itemHangar).Items.FirstOrDefault(i => (i.Name ?? string.Empty).ToLower() == bringItem);
var missionItem = (corpHangar ?? itemHangar).Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);
if (missionItem == null)
missionItem = itemHangar.Items.FirstOrDefault(i => (i.Name ?? string.Empty).ToLower() == bringItem);
missionItem = itemHangar.Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);

if (missionItem != null)
{
Logging.Log("Arm: Moving [" + missionItem.Name + "]");
Logging.Log("Arm: Moving [" + missionItem.TypeName + "]");

cargo.Add(missionItem, 1);
_missionItemMoved = true;
Expand All @@ -264,9 +264,9 @@ public void ProcessState()
if (ammo == null)
continue;

Logging.Log("Arm: Moving [" + item.Name + "]");
Logging.Log("Arm: Moving [" + item.TypeName + "]");

var moveQuantity = Math.Min(item.Quantity ?? -1, ammo.Quantity);
var moveQuantity = Math.Min(item.Quantity, ammo.Quantity);
moveQuantity = Math.Max(moveQuantity, 1);
cargo.Add(item, moveQuantity);

Expand Down
8 changes: 4 additions & 4 deletions Questor.Modules/Combat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity)
// Reload or change ammo
if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId)
{
Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.Name + "][" + charge.TypeId + "]");
Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
weapon.ReloadAmmo(charge);
}
else
{
Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.Name + "][" + charge.TypeId + "]");
Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
weapon.ChangeAmmo(charge);
}

Expand Down Expand Up @@ -132,12 +132,12 @@ public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity)
// Reload or change ammo
if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId)
{
Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.Name + "][" + charge.TypeId + "]");
Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
weapon.ReloadAmmo(charge);
}
else
{
Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.Name + "][" + charge.TypeId + "]");
Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
weapon.ChangeAmmo(charge);
}

Expand Down
10 changes: 5 additions & 5 deletions Questor.Modules/ItemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public long Id

public int TypeId
{
get { return _directItem.TypeId ?? 0; }
get { return _directItem.TypeId; }
}

public int GroupID
{
get { return _directItem.GroupId ?? 0; }
get { return _directItem.GroupId; }
}

public int Quantity
{
get { return _directItem.Quantity ?? 0; }
get { return _directItem.Quantity; }
}

public bool IsContraband
Expand All @@ -59,12 +59,12 @@ public bool IsContraband

public string Name
{
get { return _directItem.Name; }
get { return _directItem.TypeName; }
}

public double Volume
{
get { return _directItem.Volume ?? 0; }
get { return _directItem.Volume; }
}

public double TotalVolume
Expand Down
4 changes: 2 additions & 2 deletions Questor.Modules/MissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void LootItemAction(Action action)
var cargo = Cache.Instance.DirectEve.GetShipsCargo();
// We assume that the ship's cargo will be opened somewhere else
if (cargo.IsReady)
done |= cargo.Items.Any(i => items.Contains(i.Name));
done |= cargo.Items.Any(i => items.Contains(i.TypeName));
}
if (done)
{
Expand Down Expand Up @@ -408,7 +408,7 @@ private void LootAction(Action action)
var cargo = Cache.Instance.DirectEve.GetShipsCargo();
// We assume that the ship's cargo will be opened somewhere else
if (cargo.IsReady)
done |= cargo.Items.Any(i => items.Contains(i.Name));
done |= cargo.Items.Any(i => items.Contains(i.TypeName));
}
if (done)
{
Expand Down
4 changes: 2 additions & 2 deletions Questor.Modules/ModuleCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ModuleCache(DirectModule module)

public int GroupId
{
get { return _module.GroupId ?? -1; }
get { return _module.GroupId; }
}

public bool IsActivatable
Expand Down Expand Up @@ -103,7 +103,7 @@ public int CurrentCharges
get
{
if (_module.Charge != null)
return _module.Charge.Quantity ?? 0;
return _module.Charge.Quantity;

return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion Questor.Modules/Salvage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void ProcessState()
if (cargo.IsReady && cargo.Items.Any() && _nextAction < DateTime.Now)
{
// Check if there are actually duplicates
var duplicates = cargo.Items.Where(i => i.Quantity > 0 && i.TypeId.HasValue).GroupBy(i => i.TypeId).Any(t => t.Count() > 1);
var duplicates = cargo.Items.Where(i => i.Quantity > 0).GroupBy(i => i.TypeId).Any(t => t.Count() > 1);
if (duplicates)
State = SalvageState.StackItems;
else
Expand Down
10 changes: 5 additions & 5 deletions Questor.Modules/UnloadLoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ public void ProcessState()
case UnloadLootState.MoveLoot:
var lootHangar = corpLootHangar ?? hangar;

var lootToMove = cargo.Items.Where(i => (i.Name ?? string.Empty).ToLower() != Cache.Instance.BringMissionItem && !Settings.Instance.Ammo.Any(a => a.TypeId == i.TypeId));
var lootToMove = cargo.Items.Where(i => (i.TypeName ?? string.Empty).ToLower() != Cache.Instance.BringMissionItem && !Settings.Instance.Ammo.Any(a => a.TypeId == i.TypeId));
LootValue = 0;
foreach (var item in lootToMove)
{
if (!Cache.Instance.InvTypesById.ContainsKey(item.TypeId ?? -1))
if (!Cache.Instance.InvTypesById.ContainsKey(item.TypeId))
continue;

var invType = Cache.Instance.InvTypesById[item.TypeId ?? -1];
LootValue += (invType.MedianBuy ?? 0)*Math.Max(item.Quantity ?? -1, 1);
var invType = Cache.Instance.InvTypesById[item.TypeId];
LootValue += (invType.MedianBuy ?? 0)*Math.Max(item.Quantity, 1);
}

// Move loot to the loot hangar
Expand All @@ -138,7 +138,7 @@ public void ProcessState()
var ammoHangar = corpAmmoHangar ?? hangar;

// Move the mission item & ammo to the ammo hangar
ammoHangar.Add(cargo.Items.Where(i => ((i.Name ?? string.Empty).ToLower() == Cache.Instance.BringMissionItem || Settings.Instance.Ammo.Any(a => a.TypeId == i.TypeId))));
ammoHangar.Add(cargo.Items.Where(i => ((i.TypeName ?? string.Empty).ToLower() == Cache.Instance.BringMissionItem || Settings.Instance.Ammo.Any(a => a.TypeId == i.TypeId))));
_lastAction = DateTime.Now;

Logging.Log("UnloadLoot: Waiting for items to move");
Expand Down
2 changes: 1 addition & 1 deletion Questor/Storylines/MaterialsForWarPreparation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public StorylineState PreAcceptMission(Storyline storyline)
}

// How much kernite do we still need?
var neededQuantity = 8000 - (hangar.Items.Where(i => i.TypeId == 20).Sum(i => i.Quantity) ?? 0);
var neededQuantity = 8000 - hangar.Items.Where(i => i.TypeId == 20).Sum(i => i.Quantity);
if (neededQuantity > 0)
{
// Get the first order
Expand Down
4 changes: 2 additions & 2 deletions Questor/Storylines/Storyline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ private void BringSpoilsOfWar()
return;
}

Logging.Log("MaterialsForWarPreparation: Moving [" + item.Name + "][" + item.ItemId + "] to cargo");
cargo.Add(item, item.Quantity ?? 1);
Logging.Log("Storyline: Moving [" + item.TypeName + "][" + item.ItemId + "] to cargo");
cargo.Add(item, item.Quantity);
}

_nextAction = DateTime.Now.AddSeconds(10);
Expand Down
4 changes: 2 additions & 2 deletions Questor/Storylines/TransactionDataDelivery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ private bool MoveItem(bool pickup)
// Move items
foreach (var item in from.Items.Where(i => i.GroupId == groupId))
{
Logging.Log("TransactionDataDelivery: Moving [" + item.Name + "][" + item.ItemId + "] to " + (pickup ? "cargo" : "hangar"));
to.Add(item, item.Quantity ?? 1);
Logging.Log("TransactionDataDelivery: Moving [" + item.TypeName + "][" + item.ItemId + "] to " + (pickup ? "cargo" : "hangar"));
to.Add(item, item.Quantity);
}

_nextAction = DateTime.Now.AddSeconds(10);
Expand Down
10 changes: 5 additions & 5 deletions ValueDump/ItemCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class ItemCache
public ItemCache(DirectItem item)
{
Id = item.ItemId;
Name = item.Name;
Name = item.TypeName;

TypeId = item.TypeId ?? -1;
GroupId = item.GroupId ?? -1;
MarketGroupId = item.MarketGroupId ?? -1;
TypeId = item.TypeId;
GroupId = item.GroupId;
MarketGroupId = item.MarketGroupId;

Quantity = item.Quantity ?? -1;
Quantity = item.Quantity;
QuantitySold = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions ValueDump/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void OnFrame(object sender, EventArgs e)
Items.Clear();
var hangarItems = hangar.Items;
if (hangarItems != null)
Items.AddRange(hangarItems.Where(i => i.ItemId > 0 && i.MarketGroupId.HasValue && i.Quantity > 0).Select(i => new ItemCache(i)));
Items.AddRange(hangarItems.Where(i => i.ItemId > 0 && i.MarketGroupId > 0 && i.Quantity > 0).Select(i => new ItemCache(i)));

State = ValueDumpState.UpdatePrices;
break;
Expand Down Expand Up @@ -159,7 +159,7 @@ private void OnFrame(object sender, EventArgs e)
}

// Update Quantity
_currentItem.QuantitySold = _currentItem.Quantity - (directItem.Quantity ?? _currentItem.Quantity);
_currentItem.QuantitySold = _currentItem.Quantity - directItem.Quantity;

Log("Starting QuickSell for " + _currentItem.Name);
if (!directItem.QuickSell())
Expand Down

0 comments on commit 1e98dd2

Please sign in to comment.