using System.Collections.Generic;
namespace VRC.SDK3.ClientSim
{
///
/// This class is for holding a container of objects that can be deleted at any time.
///
///
public class ClientSimObjectCollection
{
private bool _shouldVerifyObjectList;
private readonly Queue _toBeAdded = new Queue();
private readonly Queue _toBeRemoved = new Queue();
private List _allObjects = new List();
public void AddObject(T obj)
{
if (obj == null)
{
return;
}
_toBeAdded.Enqueue(obj);
}
public void RemoveObject(T obj)
{
_shouldVerifyObjectList = true;
_toBeRemoved.Enqueue(obj);
}
public void ShouldVerifyObjects()
{
_shouldVerifyObjectList = true;
}
public void ProcessAddedAndRemovedObjects()
{
if (_toBeAdded.Count > 0)
{
foreach (var objs in _toBeAdded)
{
if (objs == null)
{
_shouldVerifyObjectList = true;
continue;
}
_allObjects.Add(objs);
}
_toBeAdded.Clear();
}
if (_toBeRemoved.Count > 0)
{
foreach (var objs in _toBeRemoved)
{
if (objs == null)
{
_shouldVerifyObjectList = true;
continue;
}
_allObjects.Remove(objs);
}
_toBeRemoved.Clear();
}
if (_shouldVerifyObjectList)
{
List allObjs = new List();
foreach (var objs in _allObjects)
{
if (objs == null)
{
continue;
}
allObjs.Add(objs);
}
_allObjects = allObjs;
}
}
public IEnumerable GetObjects()
{
foreach (var obj in _allObjects)
{
if (obj == null)
{
continue;
}
yield return obj;
}
}
}
}