예제 #1
0
파일: Frame.cs 프로젝트: youZhuang/emagezam
        private void GetChunkReferences()
        {
            if (ParentVolume.RuntimOnlyMesh && !Application.isPlaying)
            {
                return;
            }
            //Debug.Log("Frame GetChunkReferences");
            chunks =
                new Chunk[(int)Mathf.Ceil((float)XSize / ParentVolume.XChunkSize),
                          (int)Mathf.Ceil((float)YSize / ParentVolume.YChunkSize), (int)Mathf.Ceil((float)ZSize / ParentVolume.ZChunkSize)];

            for (int x = 0; x < (int)Mathf.Ceil((float)XSize / ParentVolume.XChunkSize); x++)
            {
                for (int y = 0; y < (int)Mathf.Ceil((float)YSize / ParentVolume.YChunkSize); y++)
                {
                    for (int z = 0; z < (int)Mathf.Ceil((float)ZSize / ParentVolume.ZChunkSize); z++)
                    {
                        Transform c = transform.Find("Chunks/Chunk (" + x + "," + y + "," + z + ")");
                        if (c == null)
                        {
                            //Debug.LogWarning("Couldn't get chunk refs - should probably work out why!");
                            CreateChunks();
                            return;
                        }
                        chunks[x, y, z] = c.GetComponent <Chunk>();
                    }
                }
            }
        }
예제 #2
0
    public void ShiftWorldChunks(Vector3i increment)
    {
        m_ChunkProcessor.ChunksAreBeingAdded = true;
        // We copy the original, because if we moved each chunk it's a
        // "destructive" move, possibly overwriting another chunk that also needs
        // to move.
        Chunk[, ,] copyOfOriginalChunks = CreateCopyOfOriginalChunkArray();
        List <Chunk> newCunksAddedToMap = new List <Chunk>();
        List <Chunk> chunksToDecorate   = new List <Chunk>();

        m_WorldData.MapChunkOffset = m_WorldData.MapChunkOffset - increment;
        //m_WorldData.MapChunkOffset.X -= increment.X;
        //m_WorldData.MapChunkOffset.Y -= increment.Y;
        for (int x = 0; x < m_WorldData.ChunksWide; x++)
        {
            for (int y = 0; y < m_WorldData.ChunksHigh; y++)
            {
                for (int z = 0; z < m_WorldData.ChunksDeep; z++)
                {
                    MoveChunk(copyOfOriginalChunks[x, y, z], increment, newCunksAddedToMap, chunksToDecorate);
                }
            }
        }
        m_ChunkProcessor.AddBatchOfChunks(newCunksAddedToMap, BatchType.TerrainGeneration);
        m_ChunkProcessor.AddBatchOfChunks(chunksToDecorate, BatchType.Decoration);
        m_ChunkProcessor.ChunksAreBeingAdded = false;
    }
예제 #3
0
    void Start()
    {
        data = new byte[worldX, worldY, worldZ];

        for (int x = 0; x < worldX; x++)
        {
            //int stone = Sin(x, 10, 5) + 5;
            //int stone = (x % 3);

            for (int z = 0; z < worldZ; z++)
            {
                int stone = PerlinNoise(x, 0, z, 10, 3, 1.2f);
                stone += PerlinNoise(x, 300, z, 20, 4, 0) + 10;
                int dirt = PerlinNoise(x, 100, z, 50, 2, 0); //Added +1 to make sure minimum grass height is 1

                /*int stone = PerlinNoise(x, 0, z, 10, 3, 1.2f);
                 * stone += PerlinNoise(x, 300, z, 20, 4, 0) + 10;*/

                for (int y = 0; y < worldY; y++)
                {
                    if (y <= stone)
                    {
                        data[x, y, z] = 1;
                    }
                    else if (y <= dirt + stone)
                    { //Changed this line thanks to a comment
                        data[x, y, z] = 2;
                    }
                }
            }
        }

        chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize),
                           Mathf.FloorToInt(worldY / chunkSize), Mathf.FloorToInt(worldZ / chunkSize)];
    }
예제 #4
0
        public DynamicRangeChunkVolume(GraphicsDevice device, GameDataProvider provider)
        {
            chunkWishList = new HashSet<WorldPosition>();
            this.provider = provider;
            volume = new Chunk[16, 16, 16];
            vertexBuffers = new CDictionary<Chunk, VBuffer7>();
            this.device = device;
            this.effect = Static.Effect;
            MiniMap = new Texture2D(Static.Device, 64, 64);
            MiniMapBuffer = new Color[64 * 64];
            MiniMapLayer = new Layer(MiniMap, 1, 0.7f, LayerDock.Far, LayerDock.Far,
                () =>
                {
                    return true;
                }
                );
            MiniMapLayer.Push(new LayerCell
            {
                SourceTexture = new Rectangle(0, 0, 64, 64),
                DestinationScreen = new Rectangle(-270, -270, 256, 256)
            });

            redrawWorker = new Timer(doRedraw);
            redrawWorker.Change(50, 50);

            hoverBoxMesh = HelpfulStuff.getCube(0.51f, GraphicsHelper.TextureCoord(36));
        }
예제 #5
0
        /// <summary>
        /// Awake is called before any start method is called.
        /// </summary>
        void Awake()
        {
            AntDirective = new NeuralNetwork(ConfigurationManager.Instance.Seed);
            //AntDirective.randomizeBiases();
            //AntDirective.randomizeWeights();
            AntDirective.load("Assets/Components/model10.txt");

            // Generate new random number generator
            RNG = new System.Random(ConfigurationManager.Instance.Seed);

            // Generate new simplex noise generator
            SimplexNoise = new SimplexNoise(ConfigurationManager.Instance.Seed);

            // Initialize a new 3D array of blocks with size of the number of chunks times the size of each chunk
            Blocks = new AbstractBlock[
                ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter,
                ConfigurationManager.Instance.World_Height *ConfigurationManager.Instance.Chunk_Diameter,
                ConfigurationManager.Instance.World_Diameter *ConfigurationManager.Instance.Chunk_Diameter];

            // Initialize a new 3D array of chunks with size of the number of chunks
            Chunks = new Chunk[
                ConfigurationManager.Instance.World_Diameter,
                ConfigurationManager.Instance.World_Height,
                ConfigurationManager.Instance.World_Diameter];
        }
예제 #6
0
    private void SetUp()
    {
        //Create Chunks
        UnityEngine.Debug.Log("Creating chunks");
        chunks = new Chunk[width, height, width];
        GameObject chunkObj;

        for (int i = 0; i < Width; i++)
        {
            for (int j = 0; j < Height; j++)
            {
                for (int k = 0; k < Width; k++)
                {
                    chunkObj                    = Instantiate(chunkToSpawn, transform) as GameObject;
                    chunks[i, j, k]             = chunkObj.GetComponent <Chunk>();
                    chunkObj.transform.position = new Vector3(i * Chunk.Width, j * Chunk.Height, k * Chunk.Width);
                }
            }
        }
        // Set Names
        SetChunkNames();
        //Set Chunk Locality
        SetChunkLocality(0, width - 1, 0, width - 1);
        //Generate Block Data
        DataGenerator.GenWorld(this);
        //Generate Mesh Data
        StartCoroutine(ChunkMeshGenerator.Initialize());
        ChunkMeshGenerator.DrawWorld(this);
    }
예제 #7
0
파일: World.cs 프로젝트: BluBambu/SkyArena
    public void InitWorld()
    {
        data   = new byte[worldX, worldY, worldZ];
        chunks = new Chunk[worldX / ChunkSize, worldY / ChunkSize, worldZ / ChunkSize];

        for (int x = 0; x < worldX; x++)
        {
            for (int z = 0; z < worldZ; z++)
            {
                int topY = worldY / 2 - 15 + (int)(15 * Mathf.PerlinNoise((float)x * .05f, (float)z * 0.05f));

                for (int y = 0; y < topY; y++)
                {
                    data[x, y, z] = Stone.ID;
                }

                for (int y = topY; y < worldY; y++)
                {
                    data[x, y, z] = Air.ID;
                }

                data[x, topY - 1, z] = Grass.ID;

                data[x, 0, z] = BedRock.ID;
            }
        }
    }
예제 #8
0
파일: World.cs 프로젝트: BluBambu/SkyArena
    public void InitWorld()
    {
        data = new byte[worldX, worldY, worldZ];
        chunks = new Chunk[worldX / ChunkSize, worldY / ChunkSize, worldZ / ChunkSize];

        for (int x = 0; x < worldX; x++)
        {
            for (int z = 0; z < worldZ; z++)
            {
                int topY = worldY / 2 - 15 + (int)(15 * Mathf.PerlinNoise((float)x * .05f, (float)z * 0.05f));

                for (int y = 0; y < topY; y++)
                {
                    data[x, y, z] = Stone.ID;
                }

                for (int y = topY; y < worldY; y++)
                {
                    data[x, y, z] = Air.ID;
                }

                data[x, topY - 1, z] = Grass.ID;

                data[x, 0, z] = BedRock.ID;
            }
        }
    }
예제 #9
0
    void Start()
    {
        chunkTickCount = chunksX * chunksY * chunksZ;

        meshFilter = GetComponent <MeshFilter>();
        Vector3[] cubeVertices = { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(0, 1, 1), new Vector3(1, 1, 1) };
        meshFilter.mesh.vertices = cubeVertices;
        int[] cubeIndices = { 0, 1, 1, 3, 3, 2, 2, 0, 4, 5, 5, 7, 7, 6, 6, 4, 0, 4, 1, 5, 2, 6, 3, 7 };
        meshFilter.mesh.SetIndices(cubeIndices, MeshTopology.Lines, 0);
        Color[] cubeColors = { Color.clear, Color.clear, Color.clear, Color.clear, Color.clear, Color.clear, Color.clear, Color.clear };
        meshFilter.mesh.colors = cubeColors;

        sizeX       = chunksX * Chunk.chunkSize;
        sizeY       = chunksY * Chunk.chunkSize;
        sizeZ       = chunksZ * Chunk.chunkSize;
        renderGrids = new GameObject[chunksX, chunksY, chunksZ];
        chunks      = new Chunk[chunksX, chunksY, chunksZ];
        for (int x = 0; x < chunksX; x++)
        {
            for (int y = 0; y < chunksY; y++)
            {
                for (int z = 0; z < chunksZ; z++)
                {
                    renderGrids[x, y, z] = new GameObject("Chunk " + (x + y * chunksX + z * chunksX * chunksY), typeof(Chunk));
                    renderGrids[x, y, z].GetComponent <MeshRenderer>().materials = materials;
                    renderGrids[x, y, z].transform.position = new Vector3(x * Chunk.chunkSize, y * Chunk.chunkSize, z * Chunk.chunkSize);
                    Chunk chunk = renderGrids[x, y, z].GetComponent <Chunk>();
                    chunk.position  = new Vector3i(x, y, z);
                    chunk.world     = this;
                    chunks[x, y, z] = chunk;
                }
            }
        }
        Generate();
    }
예제 #10
0
        //CANT GET RESET TO WORK
        public void reset()
        {
            network1.SetFitness(ConfigurationManager.Instance.nestBlocksPlaced);
            foreach (GameObject o in UnityEngine.Object.FindObjectsOfType <GameObject>())
            {
                if (!o.tag.Equals("MainCamera") && !o.tag.Equals("dontDelete"))
                {
                    Destroy(o);
                }
            }
            //Blocks = (AbstractBlock[,,])BlocksCopy.Clone();
            //Chunks = (Chunk[,,])ChunksCopy.Clone();
            // Initialize a new 3D array of blocks with size of the number of chunks times the size of each chunk
            Blocks = new AbstractBlock[
                ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter,
                ConfigurationManager.Instance.World_Height *ConfigurationManager.Instance.Chunk_Diameter,
                ConfigurationManager.Instance.World_Diameter *ConfigurationManager.Instance.Chunk_Diameter];

            // Initialize a new 3D array of chunks with size of the number of chunks
            Chunks = new Chunk[
                ConfigurationManager.Instance.World_Diameter,
                ConfigurationManager.Instance.World_Height,
                ConfigurationManager.Instance.World_Diameter];
            ConfigurationManager.Instance.nestBlocksPlaced = 0;
            GenerateData();
            GenerateChunks();
            GenerateAnts();
            generation();
        }
예제 #11
0
    // Use this for initialization
    void Start()
    {
        startPos    = Vector3.zero;
        updatedTime = Time.realtimeSinceStartup;

        data = new byte[worldX, worldY, worldZ];

        for (int x = 0; x < worldX; x++)
        {
            for (int z = 0; z < worldZ; z++)
            {
                for (int y = 0; y < worldY; y++)
                {
                    if (y <= 8)
                    {
                        data[x, y, z] = 1;
                    }
                }
            }
        }

        chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize),
                           Mathf.FloorToInt(worldY / chunkSize), Mathf.FloorToInt(worldZ / chunkSize)];

        spawnPlayerInCenter();
    }
예제 #12
0
    void Start()
    {
        _manager = this;
        database = _database;
#if !UNITY_EDITOR
        toucControl = true;
#endif
        if (!toucControl)
        {
            CrossPlatformInputManager.useHardwareInput();
        }
        else
        {
            CrossPlatformInputManager.useTouchInput();
        }

        UIHandler = _UIHandler;
        path      = Application.persistentDataPath;
        Debug.Log("Game started at " + path);
        mainThread = Thread.CurrentThread;
        Timer.start("Loading Materials");
        for (int i = 0; i <= Enum.GetValues(typeof(MyMaterial)).Length - 1; i++)
        {
            ((MyMaterial)i).loadMaterial();
        }
        Timer.endAndPrint("Loading Materials");
        halfMaxChunkCount       = (maxChunkCount / 2);
        chunkPrefab             = _chunkPrefab;
        chunks                  = new Chunk[maxChunkCount, 50, maxChunkCount];
        currentTerrainGenerator = new TerrainGenerator();


        //INITIATIONS
        ItemMeshCreator.init();
        IconRenderer.init();
        if (startGame)
        {
            //LOAD SAVE FILE
            save = SaveLoader.load(saveFileName);
            currentTerrainGenerator.initiateMap();
            //INITIALIZE PLAYER
            if (save.player == null)
            {
                save.player = new Player(spawnPoint);
            }
            save.player.init(playerPrefab);
            //INITIALIZE UI
            _UIHandler.init();
        }


        //START BACKGOUND THREAD
        if (startGame)
        {
            Thread thread = new Thread(Timer.doAsycTick);
            thread.IsBackground = true;
            thread.Start();
        }
    }
예제 #13
0
    void Start()
    {
        data = GameObject.Find("Relay").GetComponent<DataRelay>().data;

        chunks = new Chunk[Mathf.FloorToInt(worldX / chunksize),
            Mathf.FloorToInt(worldY / chunksize),
            Mathf.FloorToInt(worldZ / chunksize)];
    }
예제 #14
0
 public void Reset(int sizex, int sizey, int sizez)
 {
     MapSizeX = sizex;
     MapSizeY = sizey;
     MapSizeZ = sizez;
     chunks   = new Chunk[sizex / chunksize, sizey / chunksize, sizez / chunksize];
     d_Heightmap.Restart();
 }
예제 #15
0
    void Start()
    {
        data = GameObject.Find("Relay").GetComponent <DataRelay>().data;

        chunks = new Chunk[Mathf.FloorToInt(worldX / chunksize),
                           Mathf.FloorToInt(worldY / chunksize),
                           Mathf.FloorToInt(worldZ / chunksize)];
    }
예제 #16
0
 public void DeleteChunks()
 {
     foreach (Chunk chunk in transform.GetComponentsInChildren <Chunk>())
     {
         DestroyImmediate(chunk.gameObject);
     }
     chunkList = null;
 }
예제 #17
0
        void Init()
        {
            Chunks = new Chunk[X_CHUNKS, Y_CHUNKS, Z_CHUNKS];


            X_SIZE = X_CHUNKS * Chunk.X_SIZE;
            Y_SIZE = Y_CHUNKS * Chunk.Y_SIZE;
            Z_SIZE = Z_CHUNKS * Chunk.Z_SIZE;
        }
예제 #18
0
    // Use this for initialization
    void Start()
    {
        data = new byte[worldX, worldY, worldZ];

        for (int x = 0; x < worldX; x++)
        {
            for (int z = 0; z < worldZ; z++)
            {
                int stone = PerlinNoise(x, 0, z, 10, 3, 1.2f);
                stone += PerlinNoise(x, 300, z, 20, 4, 0) + 10;
                int dirt = PerlinNoise(x, 100, z, 50, 2, 0) + 1;         //Added +1 to make sure minimum grass height is 1

                for (int y = 0; y < worldY; y++)
                {
                    if (y <= stone)
                    {
                        data[x, y, z] = 1;
                    }
                    else if (y <= dirt + stone)                   //Changed this line thanks to a comment
                    {
                        data[x, y, z] = 2;
                    }
                    else
                    {
                        data[x, y, z] = 0;
                    }
                }
            }
        }
        chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize),
                           Mathf.FloorToInt(worldY / chunkSize),
                           Mathf.FloorToInt(worldZ / chunkSize)];
        int chunkCount = 1;

        for (int x = 0; x < chunks.GetLength(0); x++)
        {
            for (int y = 0; y < chunks.GetLength(1); y++)
            {
                for (int z = 0; z < chunks.GetLength(2); z++)
                {
                    GameObject newChunk = Instantiate(chunk, new Vector3(x * chunkSize - 0.5f,
                                                                         y * chunkSize + 0.5f,
                                                                         z * chunkSize - 0.5f),
                                                      new Quaternion(0, 0, 0, 0)) as GameObject;
                    newChunk.transform.parent = transform;
                    chunks[x, y, z]           = newChunk.GetComponent("Chunk") as Chunk;
                    chunks[x, y, z].chunkId   = chunkCount;
                    chunks[x, y, z].worldGO   = gameObject;
                    chunks[x, y, z].chunkSize = chunkSize;
                    chunks[x, y, z].chunkX    = x * chunkSize;
                    chunks[x, y, z].chunkY    = y * chunkSize;
                    chunks[x, y, z].chunkZ    = z * chunkSize;
                    chunkCount++;
                }
            }
        }
    }
예제 #19
0
 public DynamicRangeChunkVolume(GraphicsDevice device, GameDataProvider provider)
 {
     chunkWishList = new HashSet<WorldPosition>();
     this.provider = provider;
     volume = new Chunk[16, 16, 16];
     vertexBuffers = new CDictionary<Chunk, VertexBuffer[]>();
     this.device = device;
     this.effect = Static.Effect;
 }
예제 #20
0
        public LocalWorld(ChunkManager manager, IntVector3 size)
        {
            if (manager == null) throw new ArgumentNullException("manager");
            if (size.X < 1 || size.Y < 1 || size.Z < 1) throw new ArgumentOutOfRangeException("size");

            this.manager = manager;
            Size = size;

            chunks = new Chunk[size.X, size.Y, size.Z];
        }
예제 #21
0
    void Start()
    {
        data = new byte[worldX, worldY, worldZ];

        for (int x = 0; x < worldX; x++)
        {
            for (int z = 0; z < worldZ; z++)
            {
                int stone = PerlinNoise(x, 0, z, 10, 3, 1.2f);

                //when this line had a +10 on the end, the tops of the top-most
                //blocks didn't render. with +1 now they do
                stone += PerlinNoise(x, 300, z, 20, 4, 0) + 1;

                int dirt = PerlinNoise(x, 100, z, 50, 2, 0) + 1;                  //Added +1 to make sure minimum grass height is 1

                for (int y = 0; y < worldY; y++)
                {
                    if (y <= stone)
                    {
                        data [x, y, z] = 1;
                    }
                    else if (y <= dirt + stone)                         //Changed this line thanks to a comment
                    {
                        data [x, y, z] = 2;
                    }
                }
            }
        }

        chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize),
                           Mathf.FloorToInt(worldY / chunkSize), Mathf.FloorToInt(worldZ / chunkSize)];

        for (int x = 0; x < chunks.GetLength(0); x++)
        {
            for (int y = 0; y < chunks.GetLength(1); y++)
            {
                for (int z = 0; z < chunks.GetLength(2); z++)
                {
                    //Create a temporary Gameobject for the new chunk instead of using chunks[x,y,z]
                    GameObject newChunk = Instantiate(chunk, new Vector3(x * chunkSize - 0.5f,
                                                                         y * chunkSize + 0.5f, z * chunkSize - 0.5f), new Quaternion(0, 0, 0, 0)) as GameObject;

                    //Now instead of using a temporary variable for the script assign it
                    //to chunks[x,y,z] and use it instead of the old \"newChunkScript\"
                    chunks [x, y, z]           = newChunk.GetComponent("Chunk") as Chunk;
                    chunks [x, y, z].worldGO   = gameObject;
                    chunks [x, y, z].chunkSize = chunkSize;
                    chunks [x, y, z].chunkX    = x * chunkSize;
                    chunks [x, y, z].chunkY    = y * chunkSize;
                    chunks [x, y, z].chunkZ    = z * chunkSize;
                }
            }
        }
    }
예제 #22
0
        public ChunkRegion(World world, Vector3i position)
        {
            _world       = world;
            _position    = position;
            _chunks      = new Chunk[RegionChunkLength, RegionChunkLength, RegionChunkLength];
            _savedChunks = new Chunk[RegionChunkLength, RegionChunkLength, RegionChunkLength];
            _render      = new ChunkRegionRender(this);
            _deleted     = true;

            _world2dRegion = world.GetOrCreate2dRegion(new Vector2i(position.X, position.Z));
        }
예제 #23
0
    /// <summary>
    /// CREATE THE MESHES HERE THIS TIME AND GIVE IT TO CHUNK
    /// </summary>
    /// <param name="position"> IN WORDLD SPACE </param>
    public Sector(Vector3Int position, Node parent) : base(parent)
    {
        //base._uSize = _suSize;
        _position = position;
        _chunks   = new Chunk[_sSize, _sSize, _sSize];
        Vector3Int pos = Vector3Int.zero;

        _blockData = new BlockData[_suSize, _suSize, _suSize];

        CreateSectorAction csa = new CreateSectorAction(this);

        Parameters.ChunkActionData sad = new Parameters.ChunkActionData(position, _sSize);

        CreateChunksAction       cChunk = new CreateChunksAction(csa, sad);
        CreateBlockDataAction    cbda   = new CreateBlockDataAction(csa);
        TerraformBlockDataAction tfbda  = new TerraformBlockDataAction(csa);

        for (int i = 0; i < _suSize; i++)
        {
            for (int j = 0; j < _suSize; j++)
            {
                for (int k = 0; k < _suSize; k++)
                {
                    cbda.Add2Que(new Pair <Vector3Int, Vector3Int>(_position, new Vector3Int(i, j, k)));
                }
            }
        }

        csa.AddAction(0, cChunk);
        csa.AddAction(1, cbda);
        csa.AddAction(2, tfbda);
        csa.AddAction(3, new CreateMeshAction(csa));
        ActionQue.Add2Que(csa);

        /*
         * GameObject chunkParent = new GameObject(position.x + " " + position.y + " " + position.z);
         * for (int i = 0; i < _sSize; i++) {
         *      for (int j = 0; j < _sSize; j++) {
         *              for (int k = 0; k < _sSize; k++) {
         *                      pos.x = i * Chunk._uSize;
         *                      pos.y = j * Chunk._uSize;
         *                      pos.z = k * Chunk._uSize;
         *                      _chunks[i, j, k] = new Chunk(pos + position, this, chunkParent.transform);
         *              }
         *      }
         * }
         * _depth = 666;
         *
         *
         * //CreateBlockData();
         *
         */
    }
예제 #24
0
    public void create()
    {
        //Debug.Log ("Creating new region.");
        data   = new byte[regionXZ, regionY, regionXZ];
        chunks = new Chunk[Mathf.FloorToInt(regionXZ / Chunk.chunkSize),
                           Mathf.FloorToInt(regionY / Chunk.chunkSize),
                           Mathf.FloorToInt(regionXZ / Chunk.chunkSize)];
//				itemChunks = new ItemChunk[Mathf.FloorToInt (regionXZ / Chunk.chunkSize),
//		                           Mathf.FloorToInt (regionY / Chunk.chunkSize),
//		                           Mathf.FloorToInt (regionXZ / Chunk.chunkSize)];


        try {
            string fileNamePath = "C:/Data/" + this.hashString() + ".dat";

            if (File.Exists(fileNamePath) && world.useDisk)
            {
                //Load in data from file if found
                FileStream   fs     = File.OpenRead(fileNamePath);
                BinaryReader reader = new BinaryReader(fs);
                for (int x = 0; x < regionXZ; x++)
                {
                    for (int z = 0; z < regionXZ; z++)
                    {
                        for (int y = 0; y < regionY; y++)
                        {
                            data [x, y, z] = reader.ReadByte();
                        }
                    }
                }
                reader.Close();
            }
            else
            {
                //create this region's terrain data.
                WorldGeneration.Instance.generateRegion(this);

                isDirty = true;


                //Create a dungeon and put it in the scene.
//								GameObject dungeonGO = Instantiate (Resources.Load ("Voxel Generators/Dungeon Generator")) as GameObject;
//								VoxelStream dungeon = dungeonGO.GetComponent (typeof(VoxelStream)) as VoxelStream;
//								dungeon.create ();
//								merge (dungeon, this);
            }
        } catch (Exception ex) {
            Debug.Log(ex.ToString());
        }

        //create Trees
        //createTrees ();
    }
예제 #25
0
    void Start()
    {
        int chunkAmountX = Mathf.FloorToInt(World.WIDTH / World.CHUNK_SIZE);
        int chunkAmountY = Mathf.FloorToInt(World.HEIGHT / World.CHUNK_SIZE);
        int chunkAmountZ = Mathf.FloorToInt(World.DEPTH / World.CHUNK_SIZE);

        this.chunks = new Chunk[chunkAmountX, chunkAmountY, chunkAmountZ];

        this.generateWorldData();

        this.InvokeRepeating("loadUnloadTerrain", 0.0f, 2.0f);
    }
예제 #26
0
파일: World.cs 프로젝트: Summonera/Unity
    void Start()
    {
        worldY = chunkHeight;
        data   = new byte[worldX, worldY, worldZ];
        chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize), Mathf.FloorToInt(worldY / chunkHeight), Mathf.FloorToInt(worldZ / chunkSize)];
        CheckData();

        int xPos = (int)(player.transform.position.x / chunkSize);
        int zPos = (int)(player.transform.position.z / chunkSize);
        int dis  = renderDistance / chunkSize;

        CheckChunk(xPos, zPos, dis);
    }
예제 #27
0
	public World()
	{
		_chunks = new Chunk[_visibleX, _visibleY, _visibleZ];

		for(int x = 0; x < _visibleX; x++)
			for(int y = 0; y < _visibleY; y++)
				for(int z = 0; z < _visibleZ; z++)
					_chunks[x,y,z] = new Chunk(this,x,y,z);
		
		_worldVisibleSizeX = _visibleX * Chunk.SizeX;
		_worldVisibleSizeY = _visibleY * Chunk.SizeY;
		_worldVisibleSizeZ = _visibleZ * Chunk.SizeZ;
	}
예제 #28
0
    void Start()
    {
        data = new byte[worldX, worldY, worldZ];
        for (int x = 0; x < worldX; x++)
        {
            for (int z = 0; z < worldZ; z++)
            {
                int stone = PerlinNoise(x, 0, z, 10, 2, 1.2f);
                stone += PerlinNoise(x, 300, z, 20, 3, 0) + 8;
                int dirt = PerlinNoise(x, 200, z, 50, 2, 0) + 1;
                for (int y = 0; y < worldY; y++)
                {
                    if (y <= stone)
                    {
                        data[x, y, z] = 1;
                    }
                    else if (y <= dirt + stone)
                    {
                        data[x, y, z] = 2;
                    }
                    else
                    {
                        data[x, y, z] = 0;
                    }
                }
            }
        }

        chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize), Mathf.FloorToInt(worldY / chunkSize), Mathf.FloorToInt(worldZ / chunkSize)];
        for (int x = 0; x < chunks.GetLength(0); x++)
        {
            for (int y = 0; y < chunks.GetLength(1); y++)
            {
                for (int z = 0; z < chunks.GetLength(2); z++)
                {
                    GameObject newChunk = Instantiate(chunk, new Vector3(x * chunkSize - 0.5f, y * chunkSize + 0.5f, z * chunkSize - 0.5f), new Quaternion(0, 0, 0, 0)) as GameObject;

                    chunks[x, y, z]           = newChunk.GetComponent("Chunk") as Chunk;
                    chunks[x, y, z].worldGO   = gameObject;
                    chunks[x, y, z].chunkSize = chunkSize;
                    chunks[x, y, z].chunkX    = x * chunkSize;
                    chunks[x, y, z].chunkY    = y * chunkSize;
                    chunks[x, y, z].chunkZ    = z * chunkSize;
                }
            }
        }

        chunk.SetActive(false);
    }
예제 #29
0
        public ChunkRepositoryImplementation()
        {
            chunks = new List <Chunk>();
            int loopPadding = 8;

            chunkMapSize = new int[3] {
                Configuration.CHUNK_VIEW_DISTANCE * 2 + 1 + loopPadding,
                                                            Configuration.HEIGHT / Chunk.SIZE,
                                                            Configuration.CHUNK_VIEW_DISTANCE * 2 + 1 + loopPadding
            };
            chunkMap = new Chunk[chunkMapSize[0], chunkMapSize[1], chunkMapSize[2]];

            addToProcessingChunkList = new List <Chunk>(1000);
            processingChunkList      = new SortedList <int, Chunk>(2000, new PriorityComparer());
        }
예제 #30
0
        public World()
        {
            Chunks = new Chunk[10, 10, 10];

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        Chunks[i, j, k] = new Chunk(this, new Vector3(i * Chunk.SIZE, j * Chunk.SIZE, k * Chunk.SIZE));
                    }
                }
            }
        }
예제 #31
0
        public ChunkView(int radius)
        {
            var diameter = radius * 2;

            _radius = radius;
            _chunks = new Chunk[diameter, diameter, diameter];
            _center = new Vector3();

            _minVisible = new Vector3(
                (Chunk.Width * _radius) / 2.0f,
                (Chunk.Height * _radius) / 2.0f,
                (Chunk.Depth * _radius) / 2.0f);

            _maxVisible = _minVisible + new Vector3(Chunk.Width, Chunk.Height, Chunk.Depth);
        }
예제 #32
0
        void Init(bool createGround)
        {
            Chunks = new Chunk[X_CHUNKS, Y_CHUNKS, Z_CHUNKS];

            for (int x = 0; x < X_CHUNKS; x++)
            {
                for (int y = 0; y < Y_CHUNKS; y++)
                {
                    for (int z = 0; z < Z_CHUNKS; z++)
                    {
                        Chunks[x, y, z] = new Chunk(this, x, y, z, createGround);
                    }
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        if (chunks == null)
        {
            objectGO = GameObject.Instantiate(objectToView) as GameObject;
            voxels   = objectGO.GetComponent(typeof(VoxelStream)) as VoxelStream;
            voxels.create(null);
            objectBounds = voxels.getBounds();
            chunks       = new Chunk[Mathf.FloorToInt(objectBounds.x / Chunk.chunkSize),
                                     Mathf.FloorToInt(objectBounds.y / Chunk.chunkSize),
                                     Mathf.FloorToInt(objectBounds.z / Chunk.chunkSize)];


            GenerateChunks();
        }
    }
예제 #34
0
        public LocalWorld(ChunkManager manager, IntVector3 size)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (size.X < 1 || size.Y < 1 || size.Z < 1)
            {
                throw new ArgumentOutOfRangeException("size");
            }

            this.manager = manager;
            Size         = size;

            chunks = new Chunk[size.X, size.Y, size.Z];
        }
예제 #35
0
 void Start()
 {
     world = new Chunk[width, height, width];
     if (noise == null)
     {
         if (seed == long.MaxValue)
         {
             noise = new OpenSimplexNoise();
         }
         else
         {
             noise = new OpenSimplexNoise(seed);
         }
     }
     StartCoroutine(GenerateWorld());
 }
예제 #36
0
    // Start is called before the first frame update

    /*void Start()
     * {
     *  season = 2;
     *  second = 300;
     *
     *  data = new byte[worldX, worldY, worldZ];
     *
     *  for (int x = 0; x < worldX; x++)
     *  {
     *      for (int z = 0; z < worldZ; z++)
     *      {
     *          int stone = PerlinNoise(x, 0, z, 10, 3, 1.2f);
     *          stone += PerlinNoise(x, 300, z, 20, 4, 0) + 10;
     *          int dirt = PerlinNoise(x, 100, z, 50, 7, 0) + 1; // Added +1 to make sure minimum grass height is 1
     *
     *          for (int y = 1; y < worldY; y++)
     *          {
     *              if (worldType == WorldType.Normal)
     *              {
     *                  if (y == 1)
     *                  {
     *                      data[x, y, z] = 5; // Bedrock
     *                  }
     *                  else if (y <= stone)
     *                  {
     *                      data[x, y, z] = 3; // Stone
     *                  }
     *                  else if (y <= dirt)
     *                  {
     *                      data[x, y, z] = 1; // Dirt
     *                  }
     *                  else if (y <= dirt + stone)
     *                  { //Changed this line thanks to a comment
     *                      data[x, y, z] = 2;
     *                  }
     *              }
     *              else
     *              {
     *                  if (y == 1)
     *                  {
     *                      data[x, y, z] = 5;
     *                  }
     *                  if (y > 1 && y <= 4) //y <= 4, then stone
     *                  {
     *                      data[x, y, z] = 3;
     *                  }
     *                  if (y <= 7 && y > 4)
     *                  {
     *                      data[x, y, z] = 1;
     *                  }
     *                  if (y == 8)
     *                  {
     *                      data[x, y, z] = 2;
     *                  }
     *              }
     *          }
     *      }
     *
     *      chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize),
     *      Mathf.FloorToInt(worldY / chunkSize),
     *      Mathf.FloorToInt(worldZ / chunkSize)];
     *  }
     *
     *  CreateBorders();
     * }*/

    public void OnWorldLoad()
    {
        season = 2;
        second = 300;

        for (int x = 0; x < worldX; x++)
        {
            chunks = new Chunk[Mathf.FloorToInt(worldX / chunkSize),
                               Mathf.FloorToInt(worldY / chunkSize),
                               Mathf.FloorToInt(worldZ / chunkSize)];
        }

        CreateBorders();

        worldLoaded = true;
    }
예제 #37
0
    void Start()
    {
        //Make 2 perlin noise objects, one is used for the surface and the other for the caves
        PerlinNoise m_surfacePerlin = new PerlinNoise(m_surfaceSeed);
        PerlinNoise  m_cavePerlin = new PerlinNoise(m_caveSeed);

        //Set some varibles for the marching cubes plugin
        MarchingCubes.SetTarget(0.0f);
        MarchingCubes.SetWindingOrder(2, 1, 0);
        MarchingCubes.SetModeToCubes();

        //create a array to hold the voxel chunks
        m_Chunk  = new Chunk[m_chunksX,m_chunksY,m_chunksZ];

        //The offset is used to centre the terrain on the x and z axis. For the Y axis
        //we can have a certain amount of chunks above the y=0 and the rest will be below
        Vector3 offset = new Vector3(m_chunksX*m_voxelWidth*-0.5f, -(m_chunksY-m_chunksAbove0)*m_voxelHeight, m_chunksZ*m_voxelLength*-0.5f);

        for(int x = 0; x < m_chunksX; x++)
        {
            for(int y = 0; y < m_chunksY; y++)
            {
                for(int z = 0; z < m_chunksZ; z++)
                {
                    //The position of the voxel chunk
                    Vector3 pos = new Vector3(x*m_voxelWidth, y*m_voxelHeight, z*m_voxelLength);
                    //Create the voxel object
                    m_Chunk[x,y,z] = new Chunk(pos+offset, m_voxelWidth, m_voxelHeight, m_voxelLength, m_surfaceLevel);
                    //Create the voxel data
                    m_Chunk[x,y,z].CreateVoxels(m_surfacePerlin);

                    //Smooth the voxels, is optional but I think it looks nicer
                    m_Chunk[x,y,z].SmoothVoxels();
                    //Create the normals. This will create smoothed normal.
                    //This is optional and if not called the unsmoothed mesh normals will be used
                    m_Chunk[x,y,z].CalculateNormals();
                    //Creates the mesh form voxel data using the marching cubes plugin and creates the mesh collider
                    m_Chunk[x,y,z].CreateMesh(m_material);

                }
            }
        }
    }
예제 #38
0
파일: World.cs 프로젝트: Med506/mainGame
    // Use this for initialization
    void Awake()
    {
        data = new byte[worldX, worldY, worldZ];

        for(int x=0;x<worldX;x++) {
            for(int z=0;z<worldZ;z++) {
                int stone = PerlinNoise(x,0,z,10,3,1.2f);
                stone+= PerlinNoise(x,300,z,20,4,0)+10;
                int dirt = PerlinNoise(x,100,z,20,2,2f)+1;

                for(int y=0; y<worldY; y++) {
                    if(y<=stone){
                        data[x,y,z]=1;
                    } else if(y<=dirt+stone){
                        data[x,y,z]=2;
                    }
                }
            }
        }

        chunks = new Chunk[Mathf.FloorToInt (worldX / chunkSize), Mathf.FloorToInt (worldY / chunkSize), Mathf.FloorToInt (worldZ / chunkSize)];

        for(int x = 0; x<chunks.GetLength(0); x++) {
            for(int y = 0; y<chunks.GetLength(1); y++) {
                for(int z = 0; z<chunks.GetLength(2); z++) {

                    GameObject newChunks = Instantiate(chunk, new Vector3(x*chunkSize-0.5f, y*chunkSize+0.5f, z*chunkSize-0.5f), new Quaternion(0,0,0,0)) as GameObject;

                    chunks[x,y,z] = newChunks.GetComponent("Chunk") as Chunk;

                    chunks[x,y,z].worldGO = gameObject;
                    chunks[x,y,z].chunkSize = chunkSize;
                    chunks[x,y,z].chunkX=x*chunkSize;
                    chunks[x,y,z].chunkY=y*chunkSize;
                    chunks[x,y,z].chunkZ=z*chunkSize;
                }
            }
        }
    }
예제 #39
0
        void Init(bool createGround)
        {
            Chunks = new Chunk[X_CHUNKS, Y_CHUNKS, Z_CHUNKS];

            for (int x = 0; x < X_CHUNKS; x++)
            {
                for (int y = 0; y < Y_CHUNKS; y++)
                {
                    for (int z = 0; z < Z_CHUNKS; z++)
                    {
                        Chunks[x, y, z] = new Chunk(this, x, y, z, createGround);
                    }
                }
            }
        }
예제 #40
0
 void recenterMap()
 {
     IntVector3 prevCenter = mapOffset + new IntVector3(mapCenter);
     IntVector3 difference = prevCenter - player.chunk;
     Chunk[, ,] newMap = new Chunk[mapSize, mapSize, mapSize];
     for (int x = 0; x < mapSize; x++)
     {
         for (int y = 0; y < mapSize; y++)
         {
             for (int z = 0; z < mapSize; z++)
             {
                 IntVector3 oldCoordinates = new IntVector3(x, y, z);
                 IntVector3 newCoordinates = oldCoordinates + difference;
                 if (newCoordinates >= new IntVector3(0) && newCoordinates < new IntVector3(mapSize))
                 {
                     newMap.set(newCoordinates, map.get(oldCoordinates));
                 }
                 else
                 {
                     Chunk unload = map.get(oldCoordinates);
                     if (unload != null)
                     {
                         unload.Dispose();
                     }
                 }
             }
         }
     }
     mapOffset -= difference;
     map = newMap;
     fillMapThreaded();
 }
예제 #41
0
파일: Map.cs 프로젝트: kernelbitch/Lemma
        public Chunk GetChunk(int x, int y, int z, bool createIfNonExistent = true)
        {
            while (x < this.minX || x >= this.maxX || y < this.minY || y >= this.maxY || z < this.minZ || z >= this.maxZ)
            {
                if (createIfNonExistent)
                {
                    int originalChunkArraySize = this.maxChunks;
                    int oldMin = this.maxChunks / -2, oldMax = this.maxChunks / 2;
                    this.maxChunks *= 2;
                    int newMin = this.maxChunks / -2;

                    Queue<Chunk[, ,]> chunkQueue;
                    Map.freeChunkArrays.TryGetValue(this.maxChunks, out chunkQueue);

                    Chunk[, ,] newChunks;
                    if (chunkQueue != null && chunkQueue.Count > 0)
                        newChunks = chunkQueue.Dequeue();
                    else
                        newChunks = new Chunk[this.maxChunks, this.maxChunks, this.maxChunks];

                    for (int i = oldMin; i < oldMax; i++)
                    {
                        for (int j = oldMin; j < oldMax; j++)
                        {
                            for (int k = oldMin; k < oldMax; k++)
                            {
                                int i2 = i - oldMin, j2 = j - oldMin, k2 = k - oldMin;
                                newChunks[i - newMin, j - newMin, k - newMin] = this.chunks[i2, j2, k2];
                                this.chunks[i2, j2, k2] = null;
                            }
                        }
                    }

                    if (!Map.freeChunkArrays.TryGetValue(originalChunkArraySize, out chunkQueue))
                    {
                        chunkQueue = new Queue<Chunk[, ,]>();
                        Map.freeChunkArrays[originalChunkArraySize] = chunkQueue;
                    }
                    chunkQueue.Enqueue(this.chunks);

                    this.chunks = newChunks;
                    this.updateBounds();
                }
                else
                    return null;
            }

            int ix = (x - this.minX) / this.chunkSize, iy = (y - this.minY) / this.chunkSize, iz = (z - this.minZ) / this.chunkSize;
            Chunk chunk = this.chunks[ix, iy, iz];
            if (createIfNonExistent && chunk == null)
            {
                chunk = this.newChunk();
                chunk.Map = this;
                chunk.X = this.minX + (ix * this.chunkSize);
                chunk.Y = this.minY + (iy * this.chunkSize);
                chunk.Z = this.minZ + (iz * this.chunkSize);
                Queue<Box[, ,]> queue;
                if (Map.freeDataChunks.TryGetValue(this.chunkSize, out queue) && queue.Count > 0)
                    chunk.Data = queue.Dequeue();
                else
                    chunk.Data = new Box[this.chunkSize, this.chunkSize, this.chunkSize];
                chunk.IndexX = ix;
                chunk.IndexY = iy;
                chunk.IndexZ = iz;
                chunk.RelativeBoundingBox = new BoundingBox(new Vector3(chunk.X, chunk.Y, chunk.Z), new Vector3(chunk.X + this.chunkSize, chunk.Y + this.chunkSize, chunk.Z + this.chunkSize));
                this.chunks[ix, iy, iz] = chunk;
                this.Chunks.Add(chunk);
            }
            return chunk;
        }
예제 #42
0
파일: VoxelWorld.cs 프로젝트: GarethIW/LD27
        void Init(bool createGround)
        {
            Chunks = new Chunk[X_CHUNKS, Y_CHUNKS, Z_CHUNKS];

            for (int x = 0; x < X_CHUNKS; x++)
            {
                for (int y = 0; y < Y_CHUNKS; y++)
                {
                    for (int z = 0; z < Z_CHUNKS; z++)
                    {
                        Chunks[x, y, z] = new Chunk(this, x, y, z, createGround);
                    }
                }
            }

            X_SIZE = X_CHUNKS * Chunk.X_SIZE;
            Y_SIZE = Y_CHUNKS * Chunk.Y_SIZE;
            Z_SIZE = Z_CHUNKS * Chunk.Z_SIZE;
        }
예제 #43
0
        public static void Initialize()
        {
            InitializeThreads();

            Chunks = new Chunk[Constants.World.WorldSize, Constants.World.WorldSize, Constants.World.WorldSize];
            CenterIndex = new ChunkIndex(Constants.Engines.Physics.Player.Position);

            RenderHelp.CreateBlockData3DArray(out DataID);

            for (int x = -Constants.World.WorldSize / 2; x <= Constants.World.WorldSize / 2; x++)
            {
                for (int y = -Constants.World.WorldSize / 2; y <= Constants.World.WorldSize / 2; y++)
                {
                    for (int z = -Constants.World.WorldSize / 2; z <= Constants.World.WorldSize / 2; z++)
                    {
                        Chunk chunk = ObtainChunk(CenterIndex + new ChunkIndex(x, y, z), true);
                        ChunkIndex? index = GetArrayIndex(CenterIndex + new ChunkIndex(x, y, z));
                        Chunks[index.Value.X, index.Value.Y, index.Value.Z] = chunk;
                        TerrainGenerator.SetChunkTerrain(chunk);
                        ChangeChunk(chunk);
                    }
                }
            }
            //SetupThread.Start();
        }
예제 #44
0
파일: Map.cs 프로젝트: kernelbitch/Lemma
 protected Map(int maxChunks, int chunkHalfSize)
 {
     this.chunkHalfSize = chunkHalfSize;
     this.chunkSize = chunkHalfSize * 2;
     this.maxChunks = maxChunks;
     this.chunks = new Chunk[maxChunks, maxChunks, maxChunks];
 }
예제 #45
0
        /// <summary>
        /// Re-create all chunks
        /// </summary>
        public void CreateChunks()
        {
            //Debug.Log("CreateChunks " + ParentVolume.transform.name);
            if (ParentVolume.RuntimOnlyMesh && !Application.isPlaying) return;
            if (Voxels == null) return;

            DestroyMeshColliders();

            Transform chunkContainer = transform.FindChild("Chunks");

            for (int i = chunkContainer.childCount - 1; i >= 0; i--)
                if (chunkContainer.GetChild(i).GetComponent<Chunk>() != null)
                    DestroyImmediate(chunkContainer.GetChild(i).gameObject);

            chunks =
                new Chunk[(int) Mathf.Ceil((float) XSize / ParentVolume.XChunkSize),
                    (int) Mathf.Ceil((float) YSize / ParentVolume.YChunkSize), (int) Mathf.Ceil((float) ZSize / ParentVolume.YChunkSize)];

            int x = 0;
            int y = 0;
            int z = 0;
            int chunkX = 0;
            int chunkY = 0;
            int chunkZ = 0;
            while (x < XSize)
            {
                while (y < YSize)
                {
                    while (z < ZSize)
                    {
                        var newChunk =
                            Instantiate(ChunkPrefab, new Vector3(x, y, z)*ParentVolume.VoxelSize, Quaternion.identity)
                                as GameObject;
                        newChunk.name = "Chunk (" + chunkX + "," + chunkY + "," + chunkZ + ")";
                        newChunk.layer = ParentVolume.ChunkLayer;
                        newChunk.transform.parent = chunkContainer;
                        newChunk.transform.localPosition = new Vector3(x, y, z)*ParentVolume.VoxelSize;
                        newChunk.transform.rotation = transform.rotation;
                        newChunk.transform.localScale = transform.localScale;
                        newChunk.GetComponent<MeshRenderer>().shadowCastingMode = ParentVolume.CastShadows;
                        newChunk.GetComponent<MeshRenderer>().receiveShadows = ParentVolume.ReceiveShadows;
                        chunks[chunkX, chunkY, chunkZ] = newChunk.GetComponent<Chunk>();

                        z += ParentVolume.ZChunkSize;
                        chunkZ++;
                    }

                    z = 0;
                    chunkZ = 0;
                    y += ParentVolume.YChunkSize;
                    chunkY++;
                }

                y = 0;
                chunkY = 0;
                x += ParentVolume.XChunkSize;
                chunkX++;

#if UNITY_EDITOR
                if (!Application.isPlaying)
                    UnityEditor.EditorUtility.DisplayProgressBar("PicaVoxel", "Creating Chunks",(1f/(float) (XSize*YSize*ZSize))*(float) (x*y*z));
#endif
            }

#if UNITY_EDITOR
            if (!Application.isPlaying)
                UnityEditor.EditorUtility.ClearProgressBar();
#endif

            GenerateMeshColliders();
            UpdateAllChunks();
            SaveChunkMeshes(false);
        }
예제 #46
0
        void Init()
        {
            Chunks = new Chunk[X_CHUNKS, Y_CHUNKS, Z_CHUNKS];

            X_SIZE = X_CHUNKS * Chunk.X_SIZE;
            Y_SIZE = Y_CHUNKS * Chunk.Y_SIZE;
            Z_SIZE = Z_CHUNKS * Chunk.Z_SIZE;
        }
예제 #47
0
    // Use this for initialization
    void Start()
    {
        Application.targetFrameRate = 60;

        data = new Block[worldX, worldY, worldZ];

        for (int x = 0; x < worldX; x++) {
            for (int z = 0; z < worldZ; z++) {
                int stone = PerlinNoise (x, 0, z, 10, 3, 1.2f);
                stone += PerlinNoise (x, 300, z, 20, 4, 0) + 10;
                int dirt = PerlinNoise (x, 100, z, 50, 6, 0) + 2;

                for (int y = 0; y < worldY; y++) {
                    if (y <= stone) data[x,y,z] = new Rock();
                    else if (y < dirt+stone) data[x,y,z] = new Dirt();
                    else if (y == dirt+stone) data[x,y,z] = new Grass();
                    else data[x, y, z] = new Air();
                }
            }
        }

        if (isClient) {
            Cursor.lockState = CursorLockMode.Locked;
            chunks = new Chunk[Mathf.FloorToInt(worldX/chunkSize), Mathf.FloorToInt(worldY/chunkSize), Mathf.FloorToInt(worldZ/chunkSize)];
            GenerateChunks();
        }
    }
예제 #48
0
파일: Terrain.cs 프로젝트: fuboss/aiProject
        void Generate()
        {
            CleanUp();
            _chunks = new Chunk[Mathf.FloorToInt(size / chunkSize),
                Mathf.FloorToInt(worldHeight / chunkSize),
                Mathf.FloorToInt(size / chunkSize)];

            //первый запуск, строим землю
            if (!_needToLoad)
            {
                _mpd = new MidpointDisplacement(size, roughFactor, 0, worldHeight, worldHeight*0.8f);
                _mpd.SetBaseValue();
                _mpd.SetRandomValue();
                _mpd.Generate(roughValues);
                _worldData = new float[size, worldHeight, size];

                //generate all world data
                for (int i = 0; i < size*size; i++)
                {
                    float height = Mathf.Min(_mpd.data[(int) i/size, i%size], worldHeight - 1);

                    for (int h = 0; h < (int) (height); h++)
                        _worldData[(int) i/size, h, i%size] = 1;

                    if (smooth)
                    {
                        if (height >= 0)
                            _worldData[(int) i/size, (int) (height), i%size] = height - (int) height;
                    }
                }

                //разбивает worldData на чанки
                for (var i = 0; i < _chunks.GetLength(0); i++)
                {
                    for (var j = 0; j < _chunks.GetLength(1); j++)
                    {
                        for (var k = 0; k < _chunks.GetLength(2); k++)
                        {
                            float chunkX = (i * chunkSize);
                            float chunkY = (j * chunkSize);
                            float chunkZ = (k * chunkSize);

                            _chunks[i, j, k] = CreateChunk(chunkX, chunkY, chunkZ);
                            Block[, ,] chunkData = WorldToBlocks((int)chunkX, (int)chunkY, (int)chunkZ);

                            _chunks[i, j, k].Initialize(chunkData, chunkSize, chunkMaterial, this);
                        }
                    }
                }
            }
            else
            {
                var terrain = GameSaver.Instance.LoadTerrain();
                var chunksSaveData = Helper.SingleToMulti(terrain.Chunk_0, terrain.Chunk_1, terrain.Chunk_2,
                    terrain.Chunks);

                for (var i = 0; i < _chunks.GetLength(0); i++)
                {
                    for (var j = 0; j < _chunks.GetLength(1); j++)
                    {
                        for (var k = 0; k < _chunks.GetLength(2); k++)
                        {
                            var saveData = chunksSaveData[i, j, k];
                            _chunks[i, j, k] = CreateChunk(saveData.Position.x, saveData.Position.y, saveData.Position.z);
                            _chunks[i, j, k].Initialize(saveData, chunkSize, chunkMaterial, this);
                        }
                    }
                }

                terrain = null;
                chunksSaveData = null;

                _needToLoad = false;
            }

            RegenerateAllChunks();
        }
예제 #49
0
 private void InitChunkGroup()
 {
     _chunkGroup = new Chunk[Mathf.FloorToInt(worldX / chunkSize), Mathf.FloorToInt(worldY / chunkSize), Mathf.FloorToInt(worldZ / chunkSize)];
 }
예제 #50
0
파일: World.cs 프로젝트: bpgeck/Voxelnauts
	public void PopulateChunks() {
		GameObject[] chunkArr = GameObject.FindGameObjectsWithTag ("Chunk");
		chunks = new Chunk[Mathf.FloorToInt (worldX / chunkSize),
		                   Mathf.FloorToInt (worldY / chunkSize),
		                   Mathf.FloorToInt (worldZ / chunkSize)];

		print ("Found " + chunkArr.GetLength(0) + " chunks.");
		print ("Placing " + chunks.GetLength(0) + "x" + chunks.GetLength(1) + "x" + chunks.GetLength(2) + " grid of chunks");

		foreach (GameObject chunkGO in chunkArr) {
			Chunk chunk = chunkGO.GetComponent<Chunk>();
			int x = chunk.chunkX/chunkSize;
			int y = chunk.chunkY/chunkSize;
			int z = chunk.chunkZ/chunkSize;
			chunkGO.transform.position = new Vector3 (x*chunkSize-0.5f, y*chunkSize+0.5f, z*chunkSize-0.5f );
			chunks[x,y,z] = chunk;
			chunk.GetComponent<Chunk>().enabled = true;
			print ("Placed \"" + chunkGO.name + "\" in chunks[" + x + "," + y + "," + z + "].");
		}
	}
예제 #51
0
 public ChunkGroup(Chunk[,,] chunks)
 {
     Chunks = chunks;
 }
예제 #52
0
 public void InitializeGridChunks()
 {
     Chunks = new Chunk[m_ChunksWide,m_ChunksHigh,m_ChunksDeep];
     m_ChunkProcessor.ChunksAreBeingAdded = true;
     List<Chunk> newChunksToProcess = new List<Chunk>();
     // Add all world chunks to the batch for processing
     for (int x = LeftChunkBorderColumn; x <= RightChunkBorderColumn; x++)
     {
         for (int y = BottomChunkBorderRow; y <= TopChunkBorderRow; y++)
         {
             for (int z = 0; z < m_ChunksDeep; z++)
             {
                 Chunks[x, y, z] = new Chunk(x, y, z, this);
                 Chunks[x, y, z].InitializeBlocks();
                 newChunksToProcess.Add(Chunks[x, y, z]);
                 m_ChunkProcessor.AddChunkToTerrainQueue(Chunks[x, y, z]);
             }
         }
     }
     m_ChunkProcessor.AddBatchOfChunks(newChunksToProcess, BatchType.TerrainGeneration);
     m_ChunkProcessor.AddBatchOfChunks(newChunksToProcess, BatchType.Decoration);
     m_ChunkProcessor.ChunksAreBeingAdded = false;
 }
예제 #53
0
        private void GetChunkReferences()
        {
            if (ParentVolume == null) return;
            if (ParentVolume.RuntimOnlyMesh && !Application.isPlaying) return;
            //Debug.Log("Frame GetChunkReferences");
            chunks =
                new Chunk[(int) Mathf.Ceil((float) XSize / ParentVolume.XChunkSize),
                    (int) Mathf.Ceil((float) YSize / ParentVolume.YChunkSize), (int) Mathf.Ceil((float) ZSize / ParentVolume.ZChunkSize)];

            for (int x = 0; x < (int) Mathf.Ceil((float) XSize / ParentVolume.XChunkSize); x++)
                for (int y = 0; y < (int) Mathf.Ceil((float) YSize / ParentVolume.YChunkSize); y++)
                    for (int z = 0; z < (int) Mathf.Ceil((float) ZSize / ParentVolume.ZChunkSize); z++)
                    {
                        Transform c = transform.FindChild("Chunks/Chunk (" + x + "," + y + "," + z + ")");
                        if (c == null)
                        {
                            //Debug.LogWarning("Couldn't get chunk refs - should probably work out why!");
                            CreateChunks();
                            return;
                        }
                        chunks[x, y, z] = c.GetComponent<Chunk>();
                    }
        }
예제 #54
0
        public void newMap()
        {
            LoadingScreen.Display("Creating Map");
            map = new Chunk[mapSize, mapSize, mapSize];

            IntVector3 playerChunk = new IntVector3(0);
            mapOffset = new IntVector3(-mapCenter) + playerChunk;

            map.set(playerChunk - mapOffset, loadChunk(playerChunk));
            map.get(playerChunk - mapOffset).endFill();

            screenCenter = new IntVector2(graphics.Viewport.Width / 2, graphics.Viewport.Height / 2);
            player = new Player(this, screenCenter, new IntVector3(0), new Vector3(2, 15, 2));

            fillMap();
        }
예제 #55
0
 public void Reset(int sizex, int sizey, int sizez)
 {
     MapSizeX = sizex;
     MapSizeY = sizey;
     MapSizeZ = sizez;
     chunks = new Chunk[sizex / chunksize, sizey / chunksize, sizez / chunksize];
     chunksreceived = new bool[sizex / chunksize, sizey / chunksize, sizez / chunksize];
 }
예제 #56
0
파일: Frame.cs 프로젝트: AlanNess/flouUnity
        /// <summary>
        /// Re-create all chunks
        /// </summary>
        public void CreateChunks()
        {
            //Debug.Log("CreateChunks " + ParentVolume.transform.name);
            if (ParentVolume.RuntimOnlyMesh && !Application.isPlaying) return;
            if (Voxels == null) return;

            DestroyMeshColliders();

            Transform chunkContainer = transform.FindChild("Chunks");

            for (int i = chunkContainer.childCount - 1; i >= 0; i--)
                if (chunkContainer.GetChild(i).GetComponent<Chunk>() != null)
                    DestroyImmediate(chunkContainer.GetChild(i).gameObject);

            chunks =
                new Chunk[(int) Mathf.Ceil((float) XSize/Chunk.CHUNK_SIZE),
                    (int) Mathf.Ceil((float) YSize/Chunk.CHUNK_SIZE), (int) Mathf.Ceil((float) ZSize/Chunk.CHUNK_SIZE)];

            int x = 0;
            int y = 0;
            int z = 0;
            int chunkX = 0;
            int chunkY = 0;
            int chunkZ = 0;
            while (x < XSize)
            {
                while (y < YSize)
                {
                    while (z < ZSize)
                    {
                        var newChunk =
                            Instantiate(ChunkPrefab, new Vector3(x, y, z)*ParentVolume.VoxelSize, Quaternion.identity)
                                as GameObject;
                        newChunk.name = "Chunk (" + chunkX + "," + chunkY + "," + chunkZ + ")";
                        newChunk.layer = ParentVolume.gameObject.layer;
                        newChunk.transform.parent = chunkContainer;
                        newChunk.transform.localPosition = new Vector3(x, y, z)*ParentVolume.VoxelSize;
                        newChunk.transform.rotation = transform.rotation;
                        newChunk.transform.localScale = transform.localScale;
                        chunks[chunkX, chunkY, chunkZ] = newChunk.GetComponent<Chunk>();

                        z += Chunk.CHUNK_SIZE;
                        chunkZ++;
                    }

                    z = 0;
                    chunkZ = 0;
                    y += Chunk.CHUNK_SIZE;
                    chunkY++;
                }

                y = 0;
                chunkY = 0;
                x += Chunk.CHUNK_SIZE;
                chunkX++;
            }

            GenerateMeshColliders();
            UpdateAllChunks();
            SaveChunkMeshes();
        }
예제 #57
0
 public void Reset(int sizex, int sizey, int sizez)
 {
     MapSizeX = sizex;
     MapSizeY = sizey;
     MapSizeZ = sizez;
     chunks = new Chunk[sizex / chunksize, sizey / chunksize, sizez / chunksize];
     d_Heightmap.Restart();
 }