public Ch0nk(Dimension dimension, Vector3i position, IMaterial material) { _dimension = dimension; _position = position; _eightFoldTree = new EightFoldTree(Size, material); //_eightFoldTree[0, 0, 0] = new SandMaterial(); }
public Ch0nkWorld(Game game) { _realm = new Realm(); _dimension = _realm.Dimensions[0]; _dimension.GenerateAt(new Vector3i(0, 0, 0)); _game = game; _realm.Dimensions[0].ChangeMaterial(new BoundingSphere(new Vector3i(32, 32, 64), 20), new AirMaterial()); _realm.Dimensions[0].ChangeMaterial(new BoundingSphere(new Vector3i(0, 32, 64), 20), new SandMaterial()); _realm.Dimensions[0].ChangeMaterial(new BoundingSphere(new Vector3i(0, 64, 32), 20), new StoneMaterial()); //List<Block> blocks = new List<Block>(); //blocks.Add(new Block(c, new Vector3b(0, 0, 0), new GrassMaterial(), 1)); /*Stopwatch watch = new Stopwatch(); watch.Start(); blocks = _dimension.GetAllBlocks();*/ List<Block> blocks = _dimension.GetRandomTestingBlocks(new Vector3i()); Stopwatch watch = new Stopwatch(); Block[,,] cubeBlocks = new Block[64,64,64]; foreach (Block block in blocks) { cubeBlocks[block.RelativePosition.X, block.RelativePosition.Y, block.RelativePosition.Z] = block; } int size = 32; watch.Start(); for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) for (int k = 0; k < size; k++) { cubeBlocks[i, j, k].ViewFacesArray = new BitArray(6, false); cubeBlocks[i, j, k].ViewFaces = 0x00; //back and front cubeBlocks[i, j, k].ViewFacesArray.Set(0, CheckValue(i, j - 1, k, cubeBlocks, size)); cubeBlocks[i, j, k].ViewFacesArray.Set(1, CheckValue(i, j + 1, k, cubeBlocks, size)); //left and right cubeBlocks[i, j, k].ViewFacesArray.Set(2, CheckValue(i + 1, j, k, cubeBlocks, size)); cubeBlocks[i, j, k].ViewFacesArray.Set(3, CheckValue(i - 1, j, k, cubeBlocks, size)); //bottom and top cubeBlocks[i, j, k].ViewFacesArray.Set(4, CheckValue(i, j, k - 1, cubeBlocks, size)); cubeBlocks[i, j, k].ViewFacesArray.Set(5, CheckValue(i, j, k + 1, cubeBlocks, size)); /* //back and front cubeBlocks[i, j, k].ViewFaces |= CheckValue(i - 1, j, k, cubeBlocks); cubeBlocks[i, j, k].ViewFaces |= (byte)(CheckValue(i + 1, j, k, cubeBlocks) << 1); //left and right cubeBlocks[i, j, k].ViewFaces |= (byte)(CheckValue(i, j - 1, k, cubeBlocks) << 3); cubeBlocks[i, j, k].ViewFaces |= (byte)(CheckValue(i, j + 1, k, cubeBlocks) << 2); //bottom and top cubeBlocks[i, j, k].ViewFaces |= (byte)(CheckValue(i, j, k-1, cubeBlocks) << 4); cubeBlocks[i, j, k].ViewFaces |= (byte)(CheckValue(i, j, k+1, cubeBlocks) << 5); * */ } Console.WriteLine(watch.ElapsedMilliseconds); /*List<Block>[,] verticalBlocks = new List<Block>[64,64]; for (int i = 0; i < 64; i++ ) { for (int j = 0; j < 64; j++) { for (int k = 0; k < 64; k++) { if(verticalBlocks[i,j] == null) { verticalBlocks[i,j] = new List<Block>(); verticalBlocks[i,j].Add(cubeBlocks[i,j,k]); } else { Block lastBlock = verticalBlocks[i, j].Last(); if(lastBlock.Material.Equals(cubeBlocks[i,j,k].Material)) { lastBlock.Size += 1; } else { verticalBlocks[i, j].Add(cubeBlocks[i, j, k]); } } } } } blocks = new List<Block>(); foreach (List<Block> verticalBlock in verticalBlocks) { blocks.Add(verticalBlock.First()); }*/ //blocks = new List<Block>(); /*for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { for (int k = 0; k < 64; k++) { if((i == 0 || i == 63) || (j == 0 || j == 63) || (k == 0 || k == 63)) { blocks.Add(cubeBlocks[i, j, k]); } } } }*/ /*Face face = new Face(); for (int j = 0; j < 64; j++) { for (int k = 0; k < 64; k++) { if (cubeBlocks[0, j, k].Material is AirMaterial) { for(int i = 0; i < 64; i++) { if (!(cubeBlocks[i, j, k].Material is AirMaterial)) { face.data[j, k] = cubeBlocks[i, j, k]; break; } } } else face.data[j, k] = cubeBlocks[0, j, k]; } }*/ /*Face[] faces = new Face[6]; for (int i = 0; i < 6; i++) { faces[i] = new Face(); for (int j = 0; j < 64; j++) { for (int k = 0; k < 64; k++) { faces[i].data[i,j] } } faces[i].data[] }*/ //blocks.AddRange(face.GetBlocks()); //Console.WriteLine(watch.ElapsedMilliseconds); //_buffer = new DrawableBuffer(game, blocks); _buffer = new DrawableFaceBuffer(game, blocks); //Console.WriteLine(watch.ElapsedMilliseconds); }