Beispiel #1
0
            static int Check <T>()
            {
                var genericTypeId = Typeof <T> .Id;

                Assert.Equal(Typeof.GetTypeId(typeof(T)), genericTypeId);
                return(genericTypeId);
            }
Beispiel #2
0
        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>()));
        }
Beispiel #3
0
        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)));
            }
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
 private static int GetTypeId(IComponent component)
 {
     return(Typeof.GetTypeId(component.GetType()));
 }
Beispiel #6
0
        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>()));
        }