static int Check <T>() { var genericTypeId = Typeof <T> .Id; Assert.Equal(Typeof.GetTypeId(typeof(T)), genericTypeId); return(genericTypeId); }
public Actor Create(Type actorType, IComponent[]?components = null, int?actorId = null) { var typeId = Typeof.GetTypeId(actorType); var builder = GetOrAdd(typeId, _findOrCreate, actorType); var id = CreateOrCheckId(actorId); return(builder.BuildActor(id, components ?? Array.Empty <IComponent>())); }
public void GetId() { Parallel.ForEach(_types, t => Typeof.GetTypeId(t)); var unique = new HashSet <int>(); foreach (var type in _types) { Assert.True(unique.Add(Typeof.GetTypeId(type))); } }
public IComponent Create(Type componentType) { var typeId = Typeof.GetTypeId(componentType); // ReSharper disable once InvertIf if (!_resolvedBuilders.TryGetValue(typeId, out var componentBuilder)) { var builderType = typeof(IComponentBuilder <>).MakeGenericType(componentType); foreach (var builder in _builders) { if (!builderType.IsAssignableFrom(builderType)) { continue; } componentBuilder = builder; break; } AddBuilder(typeId, componentBuilder ??= CreateBuilder(componentType)); } return(componentBuilder.BuildComponent()); }
private static int GetTypeId(IComponent component) { return(Typeof.GetTypeId(component.GetType())); }
public Asset Create(Type entityType, int id, IComponent[]?components = null) { var builder = GetOrAdd(Typeof.GetTypeId(entityType), _findOrCreate, entityType); return(builder.BuildAsset(id, components ?? Array.Empty <IComponent>())); }