public void init(int chunkSize, int actualChunkX, int actualChunkZ, bool generateColumnsPerFrame = false) { tallestPoint = 0; solid = new BlockData(BlockData.BlockType.stone, new Vector3(), 20); this.chunkSize = chunkSize; actualChunkCoords = new ChunkPos(actualChunkX, actualChunkZ); filter = gameObject.GetComponent <MeshFilter>(); collider = gameObject.GetComponent <MeshCollider>(); WG = GetComponentInParent <WorldGenerator>(); bool loaded = WorldSaver.LoadChunk(this); if (!loaded) { Blocks = new BlockData[chunkSize, airLimit, chunkSize]; //fill the entire array of blocks with air for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < airLimit; y++) { for (int z = 0; z < chunkSize; z++) { Blocks[x, y, z] = new BlockData(BlockData.BlockType.air, new Vector3((actualChunkX + x), y, (actualChunkZ + z)), 20); } } } CalculateChunk(actualChunkX, actualChunkZ); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (!worldToolStripMenuItem.Enabled) { return; } if (saveWorldDialog.ShowDialog() == DialogResult.OK) { WorldSaver.Save(_world, saveWorldDialog.FileName); } }
private void openMenuItem_Click(object sender, EventArgs e) { if (!worldToolStripMenuItem.Enabled) { return; } if (openWorldDialog.ShowDialog() == DialogResult.OK) { var world = WorldSaver.Load(openWorldDialog.FileName); InitWithNewWorld(world); Map.Invalidate(); } }
void Update() { if (Input.GetKeyDown(KeyCode.G)) { WorldSaver.SaveWorld(); } if (Input.GetKeyDown(KeyCode.C)) { WorldSaver.ClearSave(); } if (Input.GetKeyDown(KeyCode.H)) { WorldSaver.LoadWorld(Application.dataPath + "/Saves/WORLDSAVE02.06.2021.bingus"); } }
public static void InitializeWorld(WorldLoader _worldLoader) { chunks = new Dictionary <int, int, Chunk>(); worldLoader = _worldLoader; // Load saved chunks if (!System.IO.File.Exists(Application.dataPath + "/Saves/WORLDSAVE02.06.2021.bingus")) { return; } ChunkData[] worldChunkData = WorldSaver.LoadWorld(Application.dataPath + "/Saves/WORLDSAVE02.06.2021.bingus"); foreach (ChunkData chunkData in worldChunkData) { int x = chunkData.x; int y = chunkData.y; chunks[x, y] = GenerateChunkFromData(chunkData); worldLoader.InstantiateChunk(x, y); } }
private void Awake() { Instance = this; createInputField.onValueChanged.AddListener(delegate { CreateInputFieldValueCheck(); }); }
/// <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); }
public World(IChunkProvider chunkGenerator, WorldSaver worldSaver) { this.chunkProvider = new ChunkProviderStorage(chunkGenerator, worldSaver); }
public ChunkProviderStorage(IChunkProvider chunkGenerator, WorldSaver worldSaver) { this.chunkGenerator = chunkGenerator; this.worldSaver = worldSaver; this.loadedChunks = new Dictionary <Vector2Int, Chunk>(); }