public static void forBTCChunkGenerator() { ChunkLogger.LOGIT("Starting Chunk Generator"); ChunkGen.DownloadCSV(); Console.WriteLine("" + DateTime.Now.ToString()); ChunkGenerator.ChunkLogger.LOGITwriter.Close(); }
public void GenerateInitialChunks(OrbitCamera camera, Point3 origin, ref string message) { float origBuildRadius = GenerateDistance; GenerateDistance = origBuildRadius * 2.0f; int i = 0; int iters = WorldSize.X * WorldSize.Y * WorldSize.Z; for (int dx = origin.X - WorldSize.X / 2 + 1; dx < origin.X + WorldSize.X / 2; dx++) { for (int dy = origin.Y - WorldSize.Y / 2; dy <= origin.Y + WorldSize.Y / 2; dy++) { for (int dz = origin.Z - WorldSize.Z / 2 + 1; dz < origin.Z + WorldSize.Z / 2; dz++) { message = "Generating : " + (i + 1) + "/" + iters; i++; Point3 box = new Point3(dx, dy, dz); if (!ChunkData.ChunkMap.ContainsKey(box)) { Vector3 worldPos = new Vector3(box.X * ChunkData.ChunkSizeX, box.Y * ChunkData.ChunkSizeY, box.Z * ChunkData.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, (int)ChunkData.ChunkSizeX, (int)ChunkData.ChunkSizeY, (int)ChunkData.ChunkSizeZ, Components, Content, Graphics); chunk.ShouldRebuild = true; chunk.ShouldRecalculateLighting = true; chunk.IsVisible = true; chunk.ResetSunlight(0); GeneratedChunks.Enqueue(chunk); foreach (VoxelChunk chunk2 in GeneratedChunks) { if (!ChunkData.ChunkMap.ContainsKey(chunk2.ID)) { ChunkData.AddChunk(chunk2); RecalculateBounds(); } } } } } } UpdateRebuildList(); GenerateDistance = origBuildRadius; while (GeneratedChunks.Count > 0) { VoxelChunk gen = null; if (!GeneratedChunks.TryDequeue(out gen)) { break; } } ChunkData.ChunkManager.CreateGraphics(ref message, ChunkData); }
public void GenerateThread() { EventWaitHandle[] waitHandles = { NeedsGenerationEvent, Program.ShutdownEvent }; #if CREATE_CRASH_LOGS try #endif { while (!ExitThreads) { EventWaitHandle wh = Datastructures.WaitFor(waitHandles); //GeneratorLock.WaitOne(); if (!PauseThreads && ToGenerate != null && ToGenerate.Count > 0) { Point3 box = ToGenerate[0]; if (!ChunkData.ChunkMap.ContainsKey(box)) { Vector3 worldPos = new Vector3(box.X * ChunkData.ChunkSizeX, box.Y * ChunkData.ChunkSizeY, box.Z * ChunkData.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, (int)ChunkData.ChunkSizeX, (int)ChunkData.ChunkSizeY, (int)ChunkData.ChunkSizeZ, Components, Content, Graphics); Drawer3D.DrawBox(chunk.GetBoundingBox(), Color.Red, 0.1f); chunk.ShouldRebuild = true; chunk.ShouldRecalculateLighting = true; GeneratedChunks.Enqueue(chunk); } ToGenerate.Remove(box); } //GeneratorLock.ReleaseMutex(); if (wh == Program.ShutdownEvent) { break; } } } #if CREATE_CRASH_LOGS catch (Exception exception) { ProgramData.WriteExceptionLog(exception); } #endif }
public void GenerateInitialChunks(GlobalChunkCoordinate origin, Action <String> SetLoadingMessage) { // todo: Since the world isn't infinite we can get rid of this. float origBuildRadius = GenerateDistance; GenerateDistance = origBuildRadius * 2.0f; var initialChunkCoordinates = new List <GlobalChunkCoordinate>(); for (int dx = origin.X - WorldSize.X / 2 + 1; dx < origin.X + WorldSize.X / 2; dx++) { for (int dz = origin.Z - WorldSize.Z / 2 + 1; dz < origin.Z + WorldSize.Z / 2; dz++) { initialChunkCoordinates.Add(new GlobalChunkCoordinate(dx, 0, dz)); } } SetLoadingMessage("Generating Chunks..."); foreach (var box in initialChunkCoordinates) { Vector3 worldPos = new Vector3( box.X * VoxelConstants.ChunkSizeX, box.Y * VoxelConstants.ChunkSizeY, box.Z * VoxelConstants.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, World); chunk.IsVisible = true; ChunkData.AddChunk(chunk); } // This is critical at the beginning to allow trees to spawn on ramps correctly, // and also to ensure no inconsistencies in chunk geometry due to ramps. foreach (var chunk in ChunkData.ChunkMap) { ChunkGen.GenerateCaves(chunk, World); for (var i = 0; i < VoxelConstants.ChunkSizeY; ++i) { // Update corner ramps on all chunks so that they don't have seams when they // are initially built. //VoxelListPrimitive.UpdateCornerRamps(chunk, i); chunk.InvalidateSlice(i); } } RecalculateBounds(); SetLoadingMessage("Generating Ores..."); GenerateOres(); GenerateDistance = origBuildRadius; }
public void GenerateThread() { EventWaitHandle[] waitHandles = { NeedsGenerationEvent, Program.ShutdownEvent }; #if CREATE_CRASH_LOGS try #endif { while (!ExitThreads) { EventWaitHandle wh = Datastructures.WaitFor(waitHandles); //GeneratorLock.WaitOne(); if (!PauseThreads && ToGenerate != null && ToGenerate.Count > 0) { System.Threading.Tasks.Parallel.ForEach(ToGenerate, box => { //if (!ChunkData.CheckBounds(box)) //{ Vector3 worldPos = new Vector3( box.X * VoxelConstants.ChunkSizeX, box.Y * VoxelConstants.ChunkSizeY, box.Z * VoxelConstants.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, World); //Drawer3D.DrawBox(chunk.GetBoundingBox(), Color.Red, 0.1f, false); //} }); ToGenerate.Clear(); } //GeneratorLock.ReleaseMutex(); if (wh == Program.ShutdownEvent) { break; } } } #if CREATE_CRASH_LOGS catch (Exception exception) { ProgramData.WriteExceptionLog(exception); } #endif }
void GenerateWorld() { for (int z = 0; z < worldSizeZ; z++) { for (int x = 0; x < worldSizeX; x++) { ChunkGen tempChunk = Instantiate(chunk, transform.position, Quaternion.identity, transform).GetComponent <ChunkGen>(); tempChunk.offsetX = OffsetX; tempChunk.offsetY = OffsetY; tempChunk.CalculateStep(); tempChunk.transform.position = new Vector3(tempChunk.stepX * x, 0, tempChunk.stepY * z); tempChunk.GenerateChunk(); } } }
// Use this for initialization void Start() { chunkGen = GameObject.Find("Terrain").GetComponent <ChunkGen>(); blockWidth = chunkGen.blockWidth; mesh = GetComponent <MeshFilter>().mesh; col = GetComponent <MeshCollider>(); for (int i = 0; i < 8; i++) { tGrasses.Add(new Vector2(i, 7)); } GenTerrain(); AddExtras(); BuildMesh(); UpdateMesh(); }
public void GenerateOres() { foreach (VoxelType type in VoxelLibrary.GetTypes()) { if (type.SpawnClusters || type.SpawnVeins) { int numEvents = (int)MathFunctions.Rand(75*(1.0f - type.Rarity), 100*(1.0f - type.Rarity)); for (int i = 0; i < numEvents; i++) { BoundingBox clusterBounds = new BoundingBox { Max = new Vector3(Bounds.Max.X, type.MaxSpawnHeight, Bounds.Max.Z), Min = new Vector3(Bounds.Min.X, type.MinSpawnHeight, Bounds.Min.Z) }; if (type.SpawnClusters) { OreCluster cluster = new OreCluster() { Size = new Vector3(MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize), MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize), MathFunctions.Rand(type.ClusterSize*0.25f, type.ClusterSize)), Transform = MathFunctions.RandomTransform(clusterBounds), Type = type }; ChunkGen.GenerateCluster(cluster, ChunkData); } if (type.SpawnVeins) { OreVein vein = new OreVein() { Length = MathFunctions.Rand(type.VeinLength*0.75f, type.VeinLength*1.25f), Start = MathFunctions.RandVector3Box(clusterBounds), Type = type }; ChunkGen.GenerateVein(vein, ChunkData); } } } } }
// Todo: Move to ChunkGenerator public void GenerateInitialChunks(Rectangle spawnRect, GlobalChunkCoordinate origin, Action <String> SetLoadingMessage) { var initialChunkCoordinates = new List <GlobalChunkCoordinate>(); for (int dx = 0; dx < WorldSize.X; dx++) { for (int dz = 0; dz < WorldSize.Z; dz++) { initialChunkCoordinates.Add(new GlobalChunkCoordinate(dx, 0, dz)); } } SetLoadingMessage("Generating Chunks..."); float maxHeight = Math.Max(Overworld.GetMaxHeight(spawnRect), 0.17f); foreach (var box in initialChunkCoordinates) { Vector3 worldPos = new Vector3( box.X * VoxelConstants.ChunkSizeX, box.Y * VoxelConstants.ChunkSizeY, box.Z * VoxelConstants.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, World, maxHeight); ChunkData.AddChunk(chunk); } // This is critical at the beginning to allow trees to spawn on ramps correctly, // and also to ensure no inconsistencies in chunk geometry due to ramps. foreach (var chunk in ChunkData.ChunkMap) { ChunkGen.GenerateChunkData(chunk, World, maxHeight); for (var i = 0; i < VoxelConstants.ChunkSizeY; ++i) { chunk.InvalidateSlice(i); } } RecalculateBounds(); SetLoadingMessage("Generating Ores..."); GenerateOres(); NeedsMinimapUpdate = true; }
private void Update() { if (generateAnotherLayer) { generateAnotherLayer = false; for (int z = 0; z < worldSizeZ + 1; z++) { for (int x = 0; x < worldSizeX + 1; x++) { if (x == worldSizeX || z == worldSizeZ) { ChunkGen tempChunk = Instantiate(chunk, transform.position, Quaternion.identity, transform).GetComponent <ChunkGen>(); tempChunk.offsetX = OffsetX; tempChunk.offsetY = OffsetY; tempChunk.CalculateStep(); tempChunk.transform.position = new Vector3(tempChunk.stepX * x, 0, tempChunk.stepY * z); tempChunk.GenerateChunk(); } } } worldSizeX++; worldSizeZ++; } }
public void Update(DwarfTime gameTime, Camera camera, GraphicsDevice g) { UpdateRenderList(camera); if (waterUpdateTimer.Update(gameTime)) { WaterUpdateEvent.Set(); } UpdateRebuildList(); generateChunksTimer.Update(gameTime); if (generateChunksTimer.HasTriggered) { if (ToGenerate.Count > 0) { NeedsGenerationEvent.Set(); ChunkData.RecomputeNeighbors(); } foreach (VoxelChunk chunk in GeneratedChunks) { if (!ChunkData.ChunkMap.ContainsKey(chunk.ID)) { ChunkData.AddChunk(chunk); ChunkGen.GenerateVegetation(chunk, Components, Content, Graphics); ChunkGen.GenerateFauna(chunk, Components, Content, Graphics, PlayState.ComponentManager.Factions); List <VoxelChunk> adjacents = ChunkData.GetAdjacentChunks(chunk); foreach (VoxelChunk c in adjacents) { c.ShouldRecalculateLighting = true; c.ShouldRebuild = true; } RecalculateBounds(); } } while (GeneratedChunks.Count > 0) { VoxelChunk gen = null; if (!GeneratedChunks.TryDequeue(out gen)) { break; } } } visibilityChunksTimer.Update(gameTime); if (visibilityChunksTimer.HasTriggered) { visibleSet.Clear(); GetChunksIntersecting(camera.GetFrustrum(), visibleSet); //RemoveDistantBlocks(camera); } foreach (VoxelChunk chunk in ChunkData.ChunkMap.Values) { chunk.Update(gameTime); } Water.Splash(gameTime); Water.HandleTransfers(gameTime); HashSet <VoxelChunk> affectedChunks = new HashSet <VoxelChunk>(); foreach (Voxel voxel in KilledVoxels) { affectedChunks.Add(voxel.Chunk); voxel.Chunk.NotifyDestroyed(new Point3(voxel.GridPosition)); if (!voxel.IsInterior) { foreach (KeyValuePair <Point3, VoxelChunk> n in voxel.Chunk.Neighbors) { affectedChunks.Add(n.Value); } } } if (GameSettings.Default.FogofWar) { ChunkData.Reveal(KilledVoxels); } lock (RebuildList) { foreach (VoxelChunk affected in affectedChunks) { affected.NotifyTotalRebuild(false); } } KilledVoxels.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="SMP.World"/> class and generates 49 chunks. /// </summary> /// <param name='spawnx'> /// Spawnx. The x spawn pos. /// </param> /// <param name='spawny'> /// Spawny. The y spawn pos. /// </param> /// <param name='spawnz'> /// Spawnz. The z spawn pos. /// </param> public World(double spawnx, double spawny, double spawnz, string name, long seed) : this() { this.name = name; this.seed = seed; this.SpawnX = spawnx; this.SpawnY = spawny; this.SpawnZ = spawnz; chunkData = new Dictionary<Point, Chunk>(); physics = new Physics(this); generator = new GenStandard(this, true); chunkManager = new WorldChunkManager(this); Logger.Log("Generating " + this.name + "..."); int cursorH = 25 + this.name.Length; float count = 0, total = (Server.ViewDistance * 2 + 1) * (Server.ViewDistance * 2 + 1); Console.SetCursorPosition(cursorH, Console.CursorTop - 1); Console.Write("0%"); object derpLock = new object(); try // Mono 2.10.2 has Parallel.For(int) and Parallel.ForEach implemented, not sure about 2.8 though. Any version less does not support .NET 4.0 { Parallel.For(((int)SpawnX >> 4) - Server.ViewDistance, ((int)SpawnX >> 4) + Server.ViewDistance + 1, delegate(int x) { Parallel.For(((int)SpawnZ >> 4) - Server.ViewDistance, ((int)SpawnZ >> 4) + Server.ViewDistance + 1, delegate(int z) { LoadChunk(x, z, false, false); lock (derpLock) { Console.SetCursorPosition(cursorH, Console.CursorTop); count++; Console.Write((int)((count / total) * 100) + "%"); } }); //Logger.Log(x + " Row Generated."); }); } catch (NotImplementedException) { for (int x = ((int)SpawnX >> 4) - Server.ViewDistance; x < ((int)SpawnX >> 4) + Server.ViewDistance + 1; x++) { for (int z = ((int)SpawnZ >> 4) - Server.ViewDistance; z < ((int)SpawnZ >> 4) + Server.ViewDistance + 1; z++) { LoadChunk(x, z, false, false); Console.SetCursorPosition(cursorH, Console.CursorTop); count++; Console.Write((int)((count / total) * 100) + "%"); } //Logger.Log(x + " Row Generated."); } } Console.Write("\r"); Logger.Log("Look distance = " + Server.ViewDistance); Init(); physics.Start(); if (World.WorldLoad != null) World.WorldLoad(this); }
public void GenerateInitialChunks(Point3 origin, Action <String> SetLoadingMessage) { float origBuildRadius = GenerateDistance; GenerateDistance = origBuildRadius * 2.0f; int i = 0; int iters = WorldSize.X * WorldSize.Y * WorldSize.Z; for (int dx = origin.X - WorldSize.X / 2 + 1; dx < origin.X + WorldSize.X / 2; dx++) { for (int dy = origin.Y - WorldSize.Y / 2; dy <= origin.Y + WorldSize.Y / 2; dy++) { for (int dz = origin.Z - WorldSize.Z / 2 + 1; dz < origin.Z + WorldSize.Z / 2; dz++) { SetLoadingMessage("Generating : " + (i + 1) + "/" + iters); i++; Point3 box = new Point3(dx, dy, dz); if (!ChunkData.ChunkMap.ContainsKey(box)) { Vector3 worldPos = new Vector3(box.X * ChunkData.ChunkSizeX, box.Y * ChunkData.ChunkSizeY, box.Z * ChunkData.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, (int)ChunkData.ChunkSizeX, (int)ChunkData.ChunkSizeY, (int)ChunkData.ChunkSizeZ, Components, Content, Graphics); chunk.ShouldRebuild = true; chunk.ShouldRecalculateLighting = true; chunk.IsVisible = true; chunk.ResetSunlight(0); GeneratedChunks.Enqueue(chunk); foreach (VoxelChunk chunk2 in GeneratedChunks) { if (!ChunkData.ChunkMap.ContainsKey(chunk2.ID)) { ChunkData.AddChunk(chunk2); RecalculateBounds(); } } } } } } RecalculateBounds(); chunkData.RecomputeNeighbors(); SetLoadingMessage("Generating Ores..."); GenerateOres(); SetLoadingMessage("Fog of war..."); // We are going to force fog of war to be on for the first reveal then reset it back to it's previous setting after. // This is a pseudo hack to stop worlds created with Fog of War off then looking awful if it is turned back on. bool fogOfWar = GameSettings.Default.FogofWar; GameSettings.Default.FogofWar = true; ChunkData.Reveal(GeneratedChunks.First().MakeVoxel(0, (int)ChunkData.ChunkSizeY - 1, 0)); GameSettings.Default.FogofWar = fogOfWar; UpdateRebuildList(); GenerateDistance = origBuildRadius; while (GeneratedChunks.Count > 0) { VoxelChunk gen = null; if (!GeneratedChunks.TryDequeue(out gen)) { break; } } ChunkData.ChunkManager.CreateGraphics(SetLoadingMessage, ChunkData); }