Files
Ragon/Ragon.Core/Game/EntityList.cs
T

35 lines
962 B
C#
Raw Normal View History

2022-12-16 00:05:46 +04:00
namespace Ragon.Core.Game;
public class EntityList
{
2022-12-17 14:05:53 +04:00
private readonly List<Entity> _dynamicEntitiesList = new List<Entity>();
private readonly List<Entity> _staticEntitiesList = new List<Entity>();
private readonly Dictionary<ushort, Entity> _entitiesMap = new Dictionary<ushort, Entity>();
2022-12-16 00:05:46 +04:00
2022-12-17 14:05:53 +04:00
public IReadOnlyList<Entity> StaticList => _staticEntitiesList;
2022-12-16 00:05:46 +04:00
public IReadOnlyList<Entity> DynamicList => _dynamicEntitiesList;
public IReadOnlyDictionary<ushort, Entity> Map => _entitiesMap;
public void Add(Entity entity)
{
if (entity.StaticId != 0)
2022-12-17 14:05:53 +04:00
_staticEntitiesList.Add(entity);
2022-12-16 00:05:46 +04:00
else
_dynamicEntitiesList.Add(entity);
_entitiesMap.Add(entity.Id, entity);
}
public Entity Remove(Entity entity)
{
if (_entitiesMap.Remove(entity.Id, out var existEntity))
{
2022-12-17 14:05:53 +04:00
_staticEntitiesList.Remove(entity);
2022-12-16 00:05:46 +04:00
_dynamicEntitiesList.Remove(entity);
return existEntity;
}
return null;
}
}