public void CreateSimpleChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newSimpleChunkObject = Instantiate(
            simpleChunkPrefab, new Vector3(x, y, z),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

        SimpleChunk newSimpleChunk = newSimpleChunkObject.GetComponent <SimpleChunk>();

        newSimpleChunk.pos         = worldPos;
        newSimpleChunk.simpleWorld = this;

        //Add it to the chunks dictionary with the position as the key
        simpleChunks.Add(worldPos, newSimpleChunk);

        var terrainGen = new TerrainGen();

        newSimpleChunk = terrainGen.SimpleChunkGen(newSimpleChunk);
        if (newSimpleChunk.simpleChunkType == SimpleChunkType.Air)
        {
            newSimpleChunk.gameObject.SetActive(false); return;
        }
        newSimpleChunkObject.GetComponent <Renderer>().material.mainTexture = textureDict.textDict[newSimpleChunk.simpleChunkType];
    }
Exemplo n.º 2
0
    // Randomly searches world for a chunk that the player can spawn at (Chances of this being slow in some situations)
    public static Vector2Int getRandomSpawnTile(World world, Biome[] allowedBiomes, Tile[] allowedTiles)
    {
        bool[,] checkedChunks = new bool[world.width, world.height];
        System.Random rnd = new System.Random();

        while (true)
        {
            int rndX = rnd.Next(world.width);
            int rndY = rnd.Next(world.height);

            if (checkedChunks[rndX, rndY])             // Skip checking this chunk if it has already been checked
            {
                continue;
            }

            SimpleChunk simpleChunk = world.GetSimpleChunkAt(new Vector2Int(rndX, rndY));

            if (doesBiomesContain(allowedBiomes, simpleChunk.biome))             // Is this a spawnable biome?
            {
                Chunk chunk = world.GetChunkAt(new Vector2Int(rndX, rndY));

                for (int y = 0; y < world.chunkSize; y++)
                {
                    for (int x = 0; x < world.chunkSize; x++)
                    {
                        if (doesTilesContain(allowedTiles, chunk.tiles[x, y]))
                        {
                            return(new Vector2Int((rndX * world.chunkSize) + x, (rndY * world.chunkSize) + y));
                        }
                    }
                }
            }
        }
    }
    public void DestroySimpleChunk(int x, int y, int z)
    {
        SimpleChunk simpleChunk = null;

        if (simpleChunks.TryGetValue(new WorldPos(x, y, z), out simpleChunk))
        {
            Object.Destroy(simpleChunk.gameObject);
            simpleChunks.Remove(new WorldPos(x, y, z));
        }
    }
 void UpdateIfEqual(int value1, int value2, WorldPos pos)
 {
     if (value1 == value2)
     {
         SimpleChunk chunk = GetSimpleChunk(pos.x, pos.y, pos.z);
         if (chunk != null)
         {
             chunk.update = true;
         }
     }
 }
Exemplo n.º 5
0
        public void TestSimpleIJobChunk([Values(0, 1, 2, 3)] int mode, [Values(1, 100)] int n)
        {
            NativeArray <Entity> eArr = new NativeArray <Entity>(n, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < n; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            NativeList <int> listOfInt = new NativeList <int>(1, Allocator.TempJob);

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk <int>
            {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false),
                listOfT  = listOfInt
            };

            switch (mode)
            {
            case 0:
                job.Schedule(query).Complete();
                break;

            case 1:
                job.ScheduleParallel(query).Complete();
                break;

            case 2:
                job.ScheduleSingle(query).Complete();
                break;

            case 3:
                job.Run(query);
                break;
            }

            for (int i = 0; i < n; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(10 + i + 100, data.value);
            }

            listOfInt.Dispose();
            eArr.Dispose();
        }
    public SimpleChunk GetSimpleChunk(int x, int y, int z)
    {
        WorldPos pos      = new WorldPos();
        float    multiple = SimpleChunk.chunkSize;

        pos.x = Mathf.FloorToInt(x / multiple) * SimpleChunk.chunkSize;
        pos.y = Mathf.FloorToInt(y / multiple) * SimpleChunk.chunkSize;
        pos.z = Mathf.FloorToInt(z / multiple) * SimpleChunk.chunkSize;

        SimpleChunk containerSimpleChunk = null;

        simpleChunks.TryGetValue(pos, out containerSimpleChunk);

        return(containerSimpleChunk);
    }
Exemplo n.º 7
0
        public void RunSimpleIJobChunk()
        {
            didDispose = 0;
            const int            N    = 10000 * NMULT;
            NativeArray <Entity> eArr = new NativeArray <Entity>(N, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < N; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false)
            };

            job.Schedule(query).Complete();

#if !UNITY_DOTSPLAYER
            // TODO: Understand / fix why the editor tests don't run quite the same code path.
            job.mDisposable.Dispose();
#endif

            for (int i = 0; i < N; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(data.value, 10 + i + 100);
            }

            Assert.AreEqual(1, didDispose);
            eArr.Dispose();
        }
Exemplo n.º 8
0
        public void RunSimpleIJobChunk()
        {
            const int            N    = 10000 * NMULT;
            NativeArray <Entity> eArr = new NativeArray <Entity>(N, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < N; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            NativeList <int> listOfInt = new NativeList <int>(1, Allocator.TempJob);

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk <int>
            {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false),
                listOfT  = listOfInt
            };

            job.Run(query);

            for (int i = 0; i < N; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(10 + i + 100, data.value);
            }

            listOfInt.Dispose();
            eArr.Dispose();
        }
Exemplo n.º 9
0
        public void RunSimpleIJobChunk()
        {
            didDispose = 0;
            const int            N    = 10 * 1000;
            NativeArray <Entity> eArr = new NativeArray <Entity>(N, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < N; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false)
            };

            job.Schedule(query).Complete();

            for (int i = 0; i < N; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(data.value, 10 + i + 100);
            }

#if NET_DOTS
            Assert.AreEqual(1, didDispose);
#endif

            eArr.Dispose();
        }
    //public Block GetBlock(int x, int y, int z)
    //{
    //    Chunk containerChunk = GetSimpleChunk(x, y, z);

    //    if (containerChunk != null)
    //    {
    //        Block block = containerChunk.GetBlock(
    //            x - containerChunk.pos.x,
    //            y - containerChunk.pos.y,
    //            z - containerChunk.pos.z);

    //        return block;
    //    }
    //    else
    //    {
    //        return new BlockAir();
    //    }

    //}

    //public void SetBlock(int x, int y, int z, Block block)
    //{
    //    Chunk chunk = GetChunk(x, y, z);

    //    if (chunk != null)
    //    {
    //        chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, block);
    //        chunk.update = true;

    //        UpdateIfEqual(x - chunk.pos.x, 0, new WorldPos(x - 1, y, z));
    //        UpdateIfEqual(x - chunk.pos.x, Chunk.chunkSize - 1, new WorldPos(x + 1, y, z));
    //        UpdateIfEqual(y - chunk.pos.y, 0, new WorldPos(x, y - 1, z));
    //        UpdateIfEqual(y - chunk.pos.y, Chunk.chunkSize - 1, new WorldPos(x, y + 1, z));
    //        UpdateIfEqual(z - chunk.pos.z, 0, new WorldPos(x, y, z - 1));
    //        UpdateIfEqual(z - chunk.pos.z, Chunk.chunkSize - 1, new WorldPos(x, y, z + 1));

    //    }
    //}

    public void SetSimpleChunk(int x, int y, int z, SimpleChunk simpleChunkTemplate)
    {
        print("2");
        simpleChunks.Add(new WorldPos(x, y, z), simpleChunkTemplate);
    }