示例#1
0
        public Aspect(SparseComponentArray sparseComponents, TypeIndexer typeIndexer, int maxEntities, int maxComponentTypes, Type[] types)
        {
            Debug.Assert(maxEntities > 0);
            Debug.Assert(maxComponentTypes > 0);

            this.maxEntities      = maxEntities;
            this.typeIndexer      = typeIndexer;
            this.sparseComponents = sparseComponents;

            typeMap = new IntMap(maxComponentTypes);

            entities   = new PackedArray <Entity>(maxEntities);
            components = new IArrayWrapper[types.Length];

            addedEntities   = new Entity[maxEntities];
            removedEntities = new Entity[maxEntities];

            foreach (Type type in types)
            {
                int typeIndex   = typeIndexer.GetIndex(type);
                int packedIndex = typeMap.Add(typeIndex);

                Type          genericArrayWrapper = typeof(ArrayWrapper <>).MakeGenericType(type);
                IArrayWrapper array = (IArrayWrapper)Activator.CreateInstance(genericArrayWrapper, maxEntities);
                components[packedIndex] = array;

                Bitmask = Bitmask.Set(typeIndex);
            }
        }
    public static TestStruct[] InitSomeStructs(int count)
    {
        var result = PackedArray.New <TestStruct>(count);

        for (var i = 0; i < count; i++)
        {
            result[i] = new TestStruct(i);
        }

        return(result);
    }
示例#3
0
        public EntityWorld(int maxEntities, int maxEvents, int maxComponentTypes)
        {
            this.maxEntities       = maxEntities;
            this.maxComponentTypes = maxComponentTypes;

            entities    = new PackedArray <Entity>(maxEntities);
            entityMasks = new B[maxEntities];

            typeIndexer      = new TypeIndexer(maxComponentTypes);
            entityManager    = new EntityManager(maxEntities);
            sparseComponents = new SparseComponentArray(maxComponentTypes, maxEntities);

            changeQueue = new ThreadLocal <ChangeQueue>(() =>
            {
                var cq = new ChangeQueue(maxComponentTypes, maxEvents);
                changeQueues.Add(cq);
                return(cq);
            });

            dirtyEntities     = new PackedArray <Entity>(maxEntities);
            entitiesToDestroy = new PackedArray <Entity>(maxEntities);
        }
示例#4
0
 public static IntFloatPair[] MakeArray()
 {
     return(PackedArray.New <IntFloatPair>(16));
 }