/// <summary> /// generates a chunk over time, with build in delays to ensure a playabole performance when generating the chunk /// </summary> /// <param name="actualChunkX">actual x coords of the chunk</param> /// <param name="actualChunkZ">actual z coords of the chunk</param> /// <param name="chunkObject">the gameObject to add all the blocks to</param> private void CalculateChunk(int actualChunkX, int actualChunkZ) { for (int x = 0; x < chunkSize; x++) { for (int z = 0; z < chunkSize; z++) { #region comments //these are probably a bit better for plains-ish biomes //explanations of values in these lines //argument 1: x+actualChunkX to get the actual x value in world position of the chunk //argument 2: simplex noise method calls this Y, im using this to control how high i want the layers, // 0 to get the highest value, at the very button, 300 to get fairly low values resulting in layers at the bottom of the actual world // 100 to get an average of a 1 layer thick dirt layer, might change this to 20, looks nice, resulting in multiple layers of dirt, or 0 // 0 it is, at least for smooth-ish plains // argument 3: z + actual z to get the actual z value in the world position of the chunk //argument 4: smoothness of the terrain, larger = less noisy //argument 5:max height of hills //argument 6: exponent, usefull for creating larger cliffs without changing too much on arg 4 & 5 (has the exact same effect though #endregion int stoneHeightBorder = 0; int XModifier = 1; //converted to negative if the chunk's X is a negative value int ZModifier = 1; //converted to negative if the chunk's Z is a negative value /*if (actualChunkX < 0) * XModifier = -XModifier; * if (actualChunkZ < 0) * ZModifier = -ZModifier; */ int _Z = actualChunkZ + (z * ZModifier); int _X = actualChunkX + (x * XModifier); //make a new thread to calculate StoneHeightBorder... //Thread t = new Thread(() => //{ stoneHeightBorder = SimplexNoise(_X, 0, _Z, 0.05f, 4, 0) - 24; //base layer of stone stoneHeightBorder += SimplexNoise(_X, 0, _Z, 0.008f, 48, 0) + 48; // stone mountains //}); //t.Start(); //while waiting for this line to be calculated (which is probably faster) int dirtHeightBorder = SimplexNoise(_X, 100, _Z, 0.04f, 3, 0) + 1; //int dirtHeightBorder = SimplexNoise((x + actualChunkX), 40, (z + actualChunkZ), 80, 10, 0) + 3; //and then joining them together //t.Join(); //this is all done to because both calculations are some fairly heavy calculations, doing them this way seperates them //out onto different CPU cores... probably not any noticeable performance increase... i get the feeling it would actually //use more cpu power to generate the new thread than it would to run both calculations on the same core, but this is a //attempt to make the simplex noise generation slightly more efficient #region fancy values /* * quite nice values, look for better alternatives though: * int stoneHeightBorder = SimplexNoise((x+actualChunkX), 0, (z+actualChunkZ), 10, 3, 1.2f); * stoneHeightBorder += SimplexNoise((x+actualChunkX), 300, (z+actualChunkZ), 20, 4, 0) + 10; // controls "hills" * int dirtHeightBorder = SimplexNoise((x+actualChunkX), 100, (z+actualChunkZ), 50, 2, 0) + 1; * */ #endregion if (dirtHeightBorder < 1) { dirtHeightBorder = 1; } if (stoneHeightBorder + dirtHeightBorder + 1 > tallestPoint) { tallestPoint = stoneHeightBorder + dirtHeightBorder + 1; } int temp = 60 - (dirtHeightBorder + stoneHeightBorder); //temp -= 15; //Debug.LogError(temp); CalculateChunkColumn(stoneHeightBorder, dirtHeightBorder, (x + actualChunkX), (z + actualChunkZ), temp); } } if (chunkColumnThreads.Count != 0) { //didn't really change ther performance alot... oh well, i suppose its better than running it all on the UI thread? foreach (Thread cCThread in chunkColumnThreads) { cCThread.Join(); //gather all the columns back to the main thread } chunkColumnThreads.Clear(); } WorldSaver.SaveChunk(this); }
public void setBlock(int x, int y, int z) { Blocks[x % chunkSize, y, z % chunkSize].type = BlockData.BlockType.air; Render(); WorldSaver.SaveChunk(this); }