remove implicit usings
parent
1123ef5662
commit
37d10db955
|
@ -2,7 +2,6 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class ComponentDepot
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal class ComponentDepot
|
||||
{
|
||||
private Dictionary<Type, ComponentStorage> storages = new Dictionary<Type, ComponentStorage>();
|
||||
|
||||
private Dictionary<FilterSignature, IndexableSet<int>> filterSignatureToEntityIDs = new Dictionary<FilterSignature, IndexableSet<int>>();
|
||||
|
@ -10,18 +13,18 @@ internal class ComponentDepot
|
|||
|
||||
private Dictionary<int, HashSet<Type>> entityComponentMap = new Dictionary<int, HashSet<Type>>();
|
||||
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
private Dictionary<Type, Filter> singleComponentFilters = new Dictionary<Type, Filter>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
internal void Register<TComponent>() where TComponent : struct
|
||||
{
|
||||
if (!storages.ContainsKey(typeof(TComponent)))
|
||||
{
|
||||
storages.Add(typeof(TComponent), new ComponentStorage<TComponent>());
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
singleComponentFilters.Add(typeof(TComponent), CreateFilter(new HashSet<Type>() { typeof(TComponent) }, new HashSet<Type>()));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,7 +231,7 @@ internal class ComponentDepot
|
|||
filterSignatureToEntityIDs[filterSignature].Add(entityID);
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
public IEnumerable<object> Debug_GetAllComponents(int entityID)
|
||||
{
|
||||
foreach (var (type, storage) in storages)
|
||||
|
@ -255,5 +258,6 @@ internal class ComponentDepot
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal abstract class ComponentStorage
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal abstract class ComponentStorage
|
||||
{
|
||||
public abstract bool Has(int entityID);
|
||||
public abstract void Remove(int entityID);
|
||||
public abstract object Debug_Get(int entityID);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: we can probably get rid of this weird entity storage system by using filters
|
||||
internal class ComponentStorage<TComponent> : ComponentStorage where TComponent : struct
|
||||
{
|
||||
// FIXME: we can probably get rid of this weird entity storage system by using filters
|
||||
internal class ComponentStorage<TComponent> : ComponentStorage where TComponent : struct
|
||||
{
|
||||
private int nextID;
|
||||
private readonly Dictionary<int, int> entityIDToStorageIndex = new Dictionary<int, int>(16);
|
||||
private int[] entityIDs = new int[16];
|
||||
|
@ -37,12 +40,12 @@ internal class ComponentStorage<TComponent> : ComponentStorage where TComponent
|
|||
|
||||
public ref readonly TComponent Get()
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (nextID == 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Component storage is empty!");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return ref components[0];
|
||||
}
|
||||
|
||||
|
@ -103,4 +106,5 @@ internal class ComponentStorage<TComponent> : ComponentStorage where TComponent
|
|||
{
|
||||
return new Entity(entityIDs[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
// NOTE: these methods are very inefficient
|
||||
// NOTE: these methods are very inefficient
|
||||
// this class should only be used in debugging contexts!!
|
||||
|
||||
#if DEBUG
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public abstract class DebugSystem : System
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
|
||||
public struct Entity : IEquatable<Entity>
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public struct Entity : IEquatable<Entity>
|
||||
{
|
||||
public int ID { get; }
|
||||
|
||||
internal Entity(int id)
|
||||
|
@ -23,4 +25,5 @@ public struct Entity : IEquatable<Entity>
|
|||
{
|
||||
return ID == other.ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public abstract class EntityComponentReader
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public abstract class EntityComponentReader
|
||||
{
|
||||
internal EntityStorage EntityStorage;
|
||||
internal ComponentDepot ComponentDepot;
|
||||
internal RelationDepot RelationDepot;
|
||||
|
@ -76,4 +79,5 @@ public abstract class EntityComponentReader
|
|||
{
|
||||
return RelationDepot.RelatedToB<TRelationKind>(entity.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
namespace MoonTools.ECS;
|
||||
|
||||
internal class EntityStorage
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal class EntityStorage
|
||||
{
|
||||
public IDStorage idStorage = new IDStorage();
|
||||
|
||||
public Entity Create()
|
||||
|
@ -18,4 +18,5 @@ internal class EntityStorage
|
|||
{
|
||||
idStorage.Release(entity.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Filter
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public class Filter
|
||||
{
|
||||
internal FilterSignature Signature;
|
||||
private ComponentDepot ComponentDepot;
|
||||
|
||||
|
@ -17,4 +20,5 @@ public class Filter
|
|||
|
||||
public int Count => ComponentDepot.FilterCount(this);
|
||||
public bool Empty => Count == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public struct FilterBuilder
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public struct FilterBuilder
|
||||
{
|
||||
private ComponentDepot ComponentDepot;
|
||||
private HashSet<Type> Included;
|
||||
private HashSet<Type> Excluded;
|
||||
|
@ -38,4 +41,5 @@ public struct FilterBuilder
|
|||
{
|
||||
return ComponentDepot.CreateFilter(Included, Excluded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public struct FilterSignature
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public struct FilterSignature
|
||||
{
|
||||
private const int HASH_FACTOR = 97;
|
||||
|
||||
public HashSet<Type> Included;
|
||||
|
@ -44,4 +47,5 @@ public struct FilterSignature
|
|||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class IDStorage
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal class IDStorage
|
||||
{
|
||||
private int nextID = 0;
|
||||
|
||||
private readonly Stack<int> availableIDs = new Stack<int>();
|
||||
|
@ -33,4 +35,5 @@ internal class IDStorage
|
|||
availableIDs.Push(id);
|
||||
availableIDHash.Add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
namespace MoonTools.ECS;
|
||||
|
||||
public interface IHasEntity
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public interface IHasEntity
|
||||
{
|
||||
Entity Entity { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class MessageDepot
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal class MessageDepot
|
||||
{
|
||||
private Dictionary<Type, MessageStorage> storages = new Dictionary<Type, MessageStorage>();
|
||||
|
||||
private MessageStorage<TMessage> Lookup<TMessage>() where TMessage : struct
|
||||
|
@ -56,4 +59,5 @@ internal class MessageDepot
|
|||
storage.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal abstract class MessageStorage
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal abstract class MessageStorage
|
||||
{
|
||||
public abstract void Clear();
|
||||
}
|
||||
}
|
||||
|
||||
internal class MessageStorage<TMessage> : MessageStorage where TMessage : struct
|
||||
{
|
||||
internal class MessageStorage<TMessage> : MessageStorage where TMessage : struct
|
||||
{
|
||||
private int count = 0;
|
||||
private int capacity = 128;
|
||||
private TMessage[] messages;
|
||||
|
@ -84,4 +87,5 @@ internal class MessageStorage<TMessage> : MessageStorage where TMessage : struct
|
|||
set.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal static class RandomGenerator
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System;
|
||||
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public struct Relation : IEquatable<Relation>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal class RelationDepot
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
internal class RelationStorage
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
|
||||
public abstract class Renderer : EntityComponentReader
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public abstract class Renderer : EntityComponentReader
|
||||
{
|
||||
public Renderer(World world)
|
||||
{
|
||||
world.AddRenderer(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
namespace MoonTools.ECS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public abstract class System : EntityComponentReader
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public abstract class System : EntityComponentReader
|
||||
{
|
||||
internal MessageDepot MessageDepot;
|
||||
|
||||
internal void RegisterMessageDepot(MessageDepot messageDepot)
|
||||
|
@ -23,13 +26,13 @@ public abstract class System : EntityComponentReader
|
|||
|
||||
protected void Set<TComponent>(in Entity entity, in TComponent component) where TComponent : struct
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
// check for use after destroy
|
||||
if (!Exists(entity))
|
||||
{
|
||||
throw new ArgumentException("This entity is not valid!");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
ComponentDepot.Set<TComponent>(entity.ID, component);
|
||||
}
|
||||
|
||||
|
@ -89,4 +92,5 @@ public abstract class System : EntityComponentReader
|
|||
RelationDepot.OnEntityDestroy(entity.ID);
|
||||
EntityStorage.Destroy(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
namespace MoonTools.ECS;
|
||||
|
||||
public class World
|
||||
namespace MoonTools.ECS
|
||||
{
|
||||
public class World
|
||||
{
|
||||
private readonly EntityStorage EntityStorage = new EntityStorage();
|
||||
private readonly ComponentDepot ComponentDepot = new ComponentDepot();
|
||||
private readonly MessageDepot MessageDepot = new MessageDepot();
|
||||
|
@ -46,4 +46,5 @@ public class World
|
|||
{
|
||||
MessageDepot.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue