コード例 #1
0
ファイル: TerrainChunk.cs プロジェクト: DeinFreund/Cyubey
    private void generate()
    {
        Debug.Log("Generating " + pos);
        DateTime start2 = DateTime.Now;

        float[,,] ground = getFloat();
        terrain.fillArray(pos * (size * Chunk.size), ground);

        for (int x = 0; x < size * Chunk.size; x++)
        {
            for (int y = 0; y < size * Chunk.size; y++)
            {
                for (int z = 0; z < size * Chunk.size; z++)
                {
                    blocks[x, y, z] = ground[x, y, z] > 0.42 ? Rock.ID : Air.ID;
                }
            }
        }
        for (int x = 0; x < size * Chunk.size; x++)
        {
            for (int y = 1; y < size * Chunk.size; y++)
            {
                for (int z = 0; z < size * Chunk.size; z++)
                {
                    //if (blocks[x, y, z] == Air.ID && blocks[x, y - 1, z] == Rock.ID && y < 3) blocks[x, y, z] = Water.ID;
                }
            }
        }
        generated = true;
        TerrainCompositor.TerrainGenerated(pos);
        disposeFloat(ground);
        Debug.Log("Genearting took " + DateTime.Now.Subtract(start2) + " to fill " + ground.GetLength(0) + " | " + ground.GetLength(1) + " | " + ground.GetLength(2));
    }
コード例 #2
0
ファイル: BlockFactory.cs プロジェクト: DeinFreund/Cyubey
    public static Block create(Coordinates position, bool serverBlock, List <Liquid> liquids)
    {
        Block block;

        switch (TerrainCompositor.GetBlock(position))
        {
        case Rock.ID:
            block = new Rock(position, serverBlock);
            break;

        case Air.ID:
            block = new Air(position, serverBlock);
            break;

        case Water.ID:
            block = new Water(position, serverBlock, 1);
            liquids.Add(block as Liquid);
            break;

        default:
            Debug.LogError("Unknown block ID: " + TerrainCompositor.GetBlock(position) + " at coordinates " + position);
            block = new Air(position, serverBlock);
            break;
        }
        return(block);
    }
コード例 #3
0
 private static void unloadChunk(Coordinates coords)
 {
     lock (chunks)
     {
         if (!chunks.ContainsKey(coords))
         {
             return;
         }
         Profiler.BeginSample("Unloading Chunks");
         //Debug.Log("Unloading Chunk at " + coords.ToString());
         TerrainCompositor.ChunkUnloaded(chunks[coords]);
         chunks[coords].unload();
         chunks.Remove(coords);
         Profiler.EndSample();
     }
 }
コード例 #4
0
 private static void loadChunk(Coordinates coords)
 {
     lock (chunks)
     {
         if (chunks.ContainsKey(coords))
         {
             return;
         }
         if (loadingChunks.Contains(coords))
         {
             return;
         }
         loadingChunks.Add(coords);
         chunks[coords] = new Chunk(coords);
         TerrainCompositor.ChunkLoaded(chunks[coords]);
     }
 }
コード例 #5
0
ファイル: Chunk.cs プロジェクト: DeinFreund/Cyubey
    public Chunk(Coordinates coords)
    {
        //Profiler.BeginSample("Constructing chunk");
        this.x         = coords.getX();
        this.y         = coords.getY();
        this.z         = coords.getZ();
        this.coords    = new Coordinates(x, y, z);
        this.centerpos = new Position(size / 2, size / 2, size / 2, this);
        terrainReady   = TerrainCompositor.GetBlockReady(centerpos);

        generate();
        faces.Add(new Face(this, new Coordinates(0, 1, 0)));
        faces.Add(new Face(this, new Coordinates(0, -1, 0)));
        faces.Add(new Face(this, new Coordinates(1, 0, 0)));
        faces.Add(new Face(this, new Coordinates(-1, 0, 0)));
        faces.Add(new Face(this, new Coordinates(0, 0, 1)));
        faces.Add(new Face(this, new Coordinates(0, 0, -1)));
        //Profiler.EndSample();
    }