Ejemplo n.º 1
0
    public void CreateChunk(int x, int y, int z)
    {
        //TODO: Create a way to limit the world to some value, like +-500 000

        WorldPos worldPos = new WorldPos(x, y, z);

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

        newChunkObject.transform.SetParent(this.gameObject.transform);
        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

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

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        Serialization.Load(newChunk);
    }
Ejemplo n.º 2
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x,y,z);

        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(worldPos.x,worldPos.y,worldPos.z),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        //bool loaded = Serialization.Load(newChunk);
        //if(loaded)
            //return;
        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();
        bool loaded = Serialization.Load(newChunk);
    }
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

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

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

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

        //Add these lines:
        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        bool loaded = Serialization.Load(newChunk);
    }
    public void CreateChunk(int x, int y, int z)
    {
        //the coordinates of this chunk in the world
        WorldPos worldPos = new WorldPos(x, y, z);

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

        //Get the object's chunk component
        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        //Assign its values
        newChunk.pos = worldPos;
        newChunk.world = this;

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

        //now spawn me some test chunks!
        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

           // newChunk.SetBlocksUnmodified();

        //bool loaded = Serialization.Load(newChunk);
    }
Ejemplo n.º 5
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

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

        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

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

        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        Serialization.Load(newChunk);
    }
Ejemplo n.º 6
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

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

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

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

        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);
        if (newChunk.airCount == 6144)
        {
            newChunk.gameObject.SetActive(false);
        }
        newChunk.SetBlocksUnmodified();

        for (int i = 0; i < newChunk.treeList.Count; i++)
        {
            GameObject newTree = Instantiate(treePrefab);
            newTree.transform.position = newChunk.treeList[i];
        }
        for (int i = 0; i < newChunk.bushList.Count; i++)
        {
            GameObject newBush = Instantiate(huckPrefab);
            newBush.transform.position = newChunk.bushList[i];
        }
        if (newChunk.boneSpawn)
        {
            print("boneSpawn");
            GameObject newBone = Instantiate(bonePrefab);
            newBone.transform.position = newChunk.boneList[0];
        }
        if (newChunk.horseSpawn)
        {
            print("boneSpawn");
            GameObject newHorse = Instantiate(horsePrefab);
            newHorse.transform.position = newChunk.horseList[0];
        }
        Serialization.Load(newChunk);
        if (newChunk.hasWater)
        {
            GameObject newWater = Instantiate(waterPrefab);
            newWater.transform.position = newChunk.transform.position;
            newChunk.water      = newWater;
            newChunk.chunkWater = newWater.GetComponent <ChunkWater>();
        }
    }
Ejemplo n.º 7
0
    public void CreateChunk(int x, int y, int z)
    {
        //the coordinates of this chunk in the world
        WorldPos worldPos = new WorldPos(x, y, z);

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

        newChunkObject.name             = "Chunk " + x / Chunk.chunkSize + "," + y / Chunk.chunkSize + "," + z / Chunk.chunkSize;
        newChunkObject.transform.parent = transform;

        //Get the object's chunk component
        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        //Assign its values
        newChunk.pos   = worldPos;
        newChunk.world = this;

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

        /*  for (int xi = 0; xi < 16; xi++)
         * {
         *    for (int yi = 0; yi < 16; yi++)
         *    {
         *        for (int zi = 0; zi < 16; zi++)
         *        {
         *            if (yi <= 7)
         *            {
         *                SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
         *            }
         *            else
         *            {
         *                SetBlock(x + xi, y + yi, z + zi, new BlockAir());
         *            }
         *        }
         *    }
         * }*/
        //load modifyed blocks

        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        bool loaded = Serialization.Load(newChunk);
        //PostProcessChunk(x,y,z);
    }
Ejemplo n.º 8
0
    public void CreateChunk(int x, int y, int z)
    {
        var worldPos       = new Vector3Int(x, y, z);
        var newChunkObject = Instantiate(chunkPrefab, worldPos, Quaternion.identity, transform);
        var newChunk       = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;
        chunks.Add(worldPos, newChunk);

        var terrain = new TerrainGen();

        newChunk = terrain.ChunkGen(newChunk);
        newChunk.SetBlocksUnmodified();
        bool loaded = Serialization.Load(newChunk);
    }
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

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

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

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

        /*
         * for (int xi = 0; xi < 16; xi++)
         * {
         * for (int yi = 0; yi < 16; yi++)
         * {
         * for (int zi = 0; zi < 16; zi++)
         * {
         *
         *  if (yi <= 16)
         *  {
         *      SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
         *  }
         *  else
         *  {
         *      SetBlock(x + xi, y + yi, z + zi, new BlockAir());
         *  }
         *
         * }
         * }
         * }
         */
        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);

        //newChunk.SetBlocksUnmodified();

        //bool loaded = Serialization.Load(newChunk);
    }
Ejemplo n.º 10
0
    public void CreateChunk(int x, int y)
    {
        WorldPos   worldPos       = new WorldPos(x, y);
        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk      newChunk       = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);
        newChunk.SetBlocksUnmodified();
        bool loaded = Serialization.Load(newChunk);
    }
Ejemplo n.º 11
0
    void GenAndLoadChunk(Chunk chunk)
    {
        var terrainGen = new TerrainGen();

        terrainGen.ChunkGen(chunk);

        Serialization.Load(chunk);

        if (Config.Toggle.LightSceneOnStart)
        {
            if (chunk.pos.y == Config.Env.WorldMaxY)
            {
                BlockLight.ResetLightChunkColumn(this, chunk);
            }
        }

        chunk.terrainGenerated = true;
    }
//    public int newChunkX;
//    public int newChunkY;
//    public int newChunkZ;
//
//    public bool genChunk;

//    void Start()
//    {
//        for (int x = -4; x < 4; x++)
//        {
//            for (int y = -1; y < 3; y++)
//            {
//                for (int z = -4; z < 4; z++)
//                {
//                    CreateChunk(x * 16, y * 16, z * 16);
//                }
//            }
//        }
//    }
//
//    void Update()
//    {
//        if (genChunk)
//        {
//            genChunk = false;
//            WorldPos chunkPos = new WorldPos(newChunkX, newChunkY, newChunkZ);
//            Chunk chunk = null;
//
//            if (chunks.TryGetValue(chunkPos, out chunk))
//            {
//                DestroyChunk(chunkPos.x, chunkPos.y, chunkPos.z);
//            }
//            else
//            {
//                CreateChunk(chunkPos.x, chunkPos.y, chunkPos.z);
//            }
//        }
//    }

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

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk      newChunk       = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

//        bool loaded = Serialization.Load(newChunk);
//        if (loaded)
//        {
//            return;
//        }

//        for (int xi = 0; xi < 16; xi++)
//        {
//            for (int yi = 0; yi < 16; yi++)
//            {
//                for (int zi = 0; zi < 16; zi++)
//                {
//                    if (yi <= 7)
//                    {
//                        SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
//                    }
//                    else
//                    {
//                        SetBlock(x + xi, y + yi, z + zi, new BlockAir());
//                    }
//                }
//            }
//        }

        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlockUnmodified();

        Serialization.Load(newChunk);
    }
        /**
         * Creates a new chunk at the given world position.
         */
        public void CreateChunk(WorldPos pos)
        {
            Chunk chunk = new Chunk();

            chunk.pos   = pos;
            chunk.world = this;

            chunks.Add(pos, chunk);

            if (!FileManager.LoadChunk(chunk))
            {
                chunk = terrainGen.ChunkGen(chunk);
                MakePhysical(chunk);
                return;
            }

            chunk.empty = IsChunkEmpty(chunk);
            MakePhysical(chunk);
        }
Ejemplo n.º 14
0
    public void createChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos (x, y, z);

        //Instantiate a new Chunk at the coordinates
        GameObject newChunkObject = Instantiate (chunkPrefab, new Vector3 (x, y, z),
                                                 Quaternion.Euler (Vector3.zero)) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk> ();

        newChunk.pos = worldPos;
        newChunk.world = this;

        //Add the new Chunk to the dictionary at this world position
        chunks.Add (worldPos, newChunk);

        TerrainGen terrainGen = new TerrainGen ();
        newChunk = terrainGen.ChunkGen (newChunk);
        newChunk.setBlocksUnmodified ();
        Serialization.loadChunk (newChunk);
    }
Ejemplo n.º 15
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos (x, 0, z);

        GameObject newChunkObject = Instantiate (chunkPrefab, new Vector3 (x, 0, z), Quaternion.identity) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk> ();
        newChunk.name = "Chunk@" + new Vector3(x, y, z);
        newChunk.pos = worldPos;
        newChunk.world = this;

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

        var terrainGen = new TerrainGen ();
        newChunk = terrainGen.ChunkGen (newChunk);

        newChunk.SetBlocksUnmodified ();

        Serialization.Load (newChunk);
    }
    public Chunk LoadChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        Chunk newChunk = new Chunk();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        //generate the chunk
        TerrainGen terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);
        newChunk.InitBlocks();

        //load changed blocks
        Serialization.LoadChunk(newChunk);

        return(newChunk);
    }
    public void createChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate a new Chunk at the coordinates
        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z),
                                                Quaternion.Euler(Vector3.zero)) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk> ();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        //Add the new Chunk to the dictionary at this world position
        chunks.Add(worldPos, newChunk);

        TerrainGen terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);
        newChunk.setBlocksUnmodified();
        Serialization.loadChunk(newChunk);
    }
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, 0, z);

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, 0, z), Quaternion.identity) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk> ();

        newChunk.name  = "Chunk@" + new Vector3(x, y, z);
        newChunk.pos   = worldPos;
        newChunk.world = this;

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

        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        Serialization.Load(newChunk);
    }
Ejemplo n.º 19
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk> ();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        /*bool loaded = Serialization.Load (newChunk);
         * if (loaded)
         *      return;*/

/*		for (int xi = 0; xi < chunkWidth; xi++) {
 *                      for (int yi = 0; yi < chunkHeight; yi++) {
 *                              for (int zi = 0; zi < chunkWidth; zi++) {
 *                                      if (yi <= 7) {
 *                                              SetBlockChunk (newChunk, xi, yi, zi, new BlockGrass ());
 *                                      } else {
 *                                              SetBlockChunk (newChunk, xi, yi, zi, new BlockAir ());
 *                                      }
 *                              }
 *                      }
 *              }
 */
        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk, newChunk.pos.x, newChunk.pos.y, newChunk.pos.z);

        newChunk.SetBlockUnModified();
        Serialization.Load(newChunk);
    }
Ejemplo n.º 20
0
    void GenAndLoadChunk(Chunk chunk)
    {
        var terrainGen = new TerrainGen();
        terrainGen.ChunkGen(chunk);

        Serialization.Load(chunk);

        if (Config.Toggle.LightSceneOnStart)
        {
            if (chunk.pos.y == Config.Env.WorldMaxY)
            {
                BlockLight.ResetLightChunkColumn(this, chunk);
            }
        }

        chunk.terrainGenerated = true;
    }
Ejemplo n.º 21
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

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

        Chunk newChunk = newChunkObject.GetComponent<Chunk>(); //gets the script component

        newChunk.pos = worldPos; //rounds position to an int
        newChunk.world = this; //tells the chunk how to get back to mommy
        newChunk.tag = "breakable";

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

        TerrainGen terrainGen = new TerrainGen(); //this has some preset values for generating
        newChunk = terrainGen.ChunkGen(newChunk); //this runs the generation code

        newChunk.SetBlocksUnmodified(); //this tells Serialization not to save as there was no changes

        Serialization.Load(newChunk);
    }
Ejemplo n.º 22
0
 /// <summary>
 /// This is the code that generates the chunk. 
 /// If using a different TerrainGen, override this class and call it here. 
 /// </summary>
 /// <param name="chunk"></param>
 protected virtual void GenerateChunk(Chunk chunk)
 {
     if (isFlat == "false") {
         var terrainGen = new TerrainGen(noiseGen);
         terrainGen.ChunkGen(chunk);
     }else{
         var terrainGenFlat = new TerrainGenFlat(noiseGen);
         terrainGenFlat.ChunkGen(chunk);
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 /// This is the code that generates the chunk. 
 /// If using a different TerrainGen, override this class and call it here. 
 /// </summary>
 /// <param name="chunk"></param>
 protected virtual void GenerateChunk(Chunk chunk)
 {
     var terrainGen = new TerrainGen();
     terrainGen.ChunkGen(chunk);
 }
Ejemplo n.º 24
0
    //    public int newChunkX;
    //    public int newChunkY;
    //    public int newChunkZ;
    //
    //    public bool genChunk;
    //    void Start()
    //    {
    //        for (int x = -4; x < 4; x++)
    //        {
    //            for (int y = -1; y < 3; y++)
    //            {
    //                for (int z = -4; z < 4; z++)
    //                {
    //                    CreateChunk(x * 16, y * 16, z * 16);
    //                }
    //            }
    //        }
    //    }
    //
    //    void Update()
    //    {
    //        if (genChunk)
    //        {
    //            genChunk = false;
    //            WorldPos chunkPos = new WorldPos(newChunkX, newChunkY, newChunkZ);
    //            Chunk chunk = null;
    //
    //            if (chunks.TryGetValue(chunkPos, out chunk))
    //            {
    //                DestroyChunk(chunkPos.x, chunkPos.y, chunkPos.z);
    //            }
    //            else
    //            {
    //                CreateChunk(chunkPos.x, chunkPos.y, chunkPos.z);
    //            }
    //        }
    //    }
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        //        bool loaded = Serialization.Load(newChunk);
        //        if (loaded)
        //        {
        //            return;
        //        }

        //        for (int xi = 0; xi < 16; xi++)
        //        {
        //            for (int yi = 0; yi < 16; yi++)
        //            {
        //                for (int zi = 0; zi < 16; zi++)
        //                {
        //                    if (yi <= 7)
        //                    {
        //                        SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
        //                    }
        //                    else
        //                    {
        //                        SetBlock(x + xi, y + yi, z + zi, new BlockAir());
        //                    }
        //                }
        //            }
        //        }

        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlockUnmodified();

        Serialization.Load(newChunk);
    }
Ejemplo n.º 25
0
    /// <summary>
    /// This is the code that generates the chunk.
    /// If using a different TerrainGen, override this class and call it here.
    /// </summary>
    /// <param name="chunk"></param>
    protected virtual void GenerateChunk(Chunk chunk)
    {
        var terrainGen = new TerrainGen();

        terrainGen.ChunkGen(chunk);
    }