Add Thread-Safe Lists, and make all list access thread-safe

This commit is contained in:
Li 2022-08-31 20:31:07 +12:00
parent 900fe0d48a
commit 40c34ac030
24 changed files with 111 additions and 44 deletions

View file

@ -8,7 +8,7 @@ namespace HISP.Game.Inventory
public class HorseInventory
{
private User baseUser;
private List<HorseInstance> horsesList = new List<HorseInstance>();
private ThreadSafeList<HorseInstance> horsesList = new ThreadSafeList<HorseInstance>();
public HorseInstance[] HorseList
{
get

View file

@ -1,21 +1,20 @@
using System;
using System.Collections.Generic;
using HISP.Game.Items;
using HISP.Game.Items;
using HISP.Server;
namespace HISP.Game.Inventory
{
public class InventoryItem
{
public InventoryItem()
{
itemInstances = new List<ItemInstance>();
itemInstances = new ThreadSafeList<ItemInstance>();
Infinite = false;
ItemId = 0;
}
public int ItemId;
public bool Infinite;
private List<ItemInstance> itemInstances;
private ThreadSafeList<ItemInstance> itemInstances;
public void RemoveItem(ItemInstance itm)
{
itemInstances.Remove(itm);

View file

@ -13,10 +13,10 @@ namespace HISP.Game.Inventory
public User BaseUser;
private List<InventoryItem> inventoryItems;
private ThreadSafeList<InventoryItem> inventoryItems;
public PlayerInventory(User forUser)
{
inventoryItems = new List<InventoryItem>();
inventoryItems = new ThreadSafeList<InventoryItem>();
BaseUser = forUser;
ItemInstance[] instances = Database.GetPlayerInventory(BaseUser.Id).ToArray();

View file

@ -10,7 +10,7 @@ namespace HISP.Game.Inventory
public class ShopInventory : IInventory
{
private Shop baseShop;
private List<InventoryItem> inventoryItems;
private ThreadSafeList<InventoryItem> inventoryItems;
public int Count
{
get
@ -21,7 +21,7 @@ namespace HISP.Game.Inventory
public ShopInventory(Shop shopkeeper)
{
baseShop = shopkeeper;
inventoryItems = new List<InventoryItem>();
inventoryItems = new ThreadSafeList<InventoryItem>();
}
private void addItem(ItemInstance item, bool addToDatabase)