Ejemplo n.º 1
0
        public void To_ManagedArray_Implicit()
        {
            var managedArray = Enumerable.Range(0, 25).Select(x => (float)x).ToArray();
            var array        = new BlitableArray <float>();

            array.Allocate(managedArray, Allocator.Temp);
            managedArray = array;

            AreEqual(array.Length, managedArray.Length);

            for (int i = 0; i < array.Length; i++)
            {
                AreEqual(array[i], managedArray[i]);
            }

            array.Dispose();
        }
Ejemplo n.º 2
0
        public void To_NativeArray_Call()
        {
            var managedArray = Enumerable.Range(0, 25).Select(x => (float)x).ToArray();
            var array        = new BlitableArray <float>();

            array.Allocate(managedArray, Allocator.Temp);
            NativeArray <float> nativeArray = array.ToNativeArray(Allocator.Temp);

            AreEqual(array.Length, nativeArray.Length);

            for (int i = 0; i < array.Length; i++)
            {
                AreEqual(array[i], nativeArray[i]);
            }

            nativeArray.Dispose();
            array.Dispose();
        }
Ejemplo n.º 3
0
            public void Alocation_From_Other()
            {
                var managedArray = Enumerable.Range(0, 25).Select(x => (float)x).ToArray();
                var otherArray   = new NativeArray <float>(managedArray, Allocator.Temp);
                var array        = new BlitableArray <float>();

                array.Allocate(otherArray, Allocator.Temp);

                AreEqual(otherArray.Length, array.Length);

                for (int i = 0; i < array.Length; i++)
                {
                    AreEqual(otherArray[i], array[i]);
                }

                otherArray.Dispose();
                array.Dispose();
            }
Ejemplo n.º 4
0
        protected override void OnUpdate()
        {
            Entities
            .WithStructuralChanges()
            .ForEach((Entity e, in MapRequest mapRequest) =>
            {
                int mapEdgeSize = mapRequest.MapEdgeSize;
                NativeArray <Entity> tileEntities = new NativeArray <Entity>(mapEdgeSize * mapEdgeSize, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
                EntityManager.CreateEntity(_tileArchetype, tileEntities);

                int index1D = 0;
                for (int y = 0; y < mapEdgeSize; y++)
                {
                    for (int x = 0; x < mapEdgeSize; x++)
                    {
                        var tileEntity  = tileEntities[y * mapEdgeSize + x];
                        var tileType    = FindTileType(new float2(x, y), mapRequest);
                        var resourceOre = CalcResourceOre(new float2(x, y), mapRequest, tileType);
                        EntityManager.SetComponentData(tileEntity, tileType);
                        EntityManager.SetComponentData(tileEntity, new MapIndex(index1D, new int2(x, y)));
                        EntityManager.SetComponentData(tileEntity, resourceOre);

                        ++index1D;
                    }
                }

                EntityManager.DestroyEntity(e);

                var tiles = new BlitableArray <Entity>();
                tiles.Allocate(tileEntities, Allocator.Persistent);
                var mapSettingsEntity = EntityManager.CreateEntity(_mapSettingsArchetype);
                SetSingleton(new MapSettings {
                    MapEdgeSize = mapEdgeSize, Tiles = tiles
                });

                tileEntities.Dispose();

                Enabled = false;
            }).Run();
        }