public void Generate(World world) { WorldSizePixels = world.Width * world.Height; for (int i = 0; i < Seeds; i++) { int y = world.GetRandomHeight(); int x = world.GetRandomWidth(); if (Monitor.TryEnter(world[x, y])) { if (!world[x, y].Initialised) { world[x, y].Altitude = 70;// (short)world.random.Next(-100, 101); world[x, y].Initialised = true; RandomPointsWorldSeed worldSeed = new RandomPointsWorldSeed(world, this, new Point(x, y), world.GetPosition(x, y)); ThreadPool.QueueUserWorkItem(ProcessSeed, worldSeed); Interlocked.Increment(ref WorkingThreads); Interlocked.Increment(ref PixelsCompleted); } Monitor.Exit(world[x, y]); } else Seeds--; } while (WorkingThreads > 0) Thread.Sleep(5); return; }
public Position(World world, int x, int y) { World = world; Altitude = 0; X = x; Y = y; }
public void Generate(World world) { foreach (var p in world.Positions) { p.Altitude = Altitude; } }
public Flora(World world, int x, int y) { World = world; if (world[x, y].Flora == null) { world[x, y].Flora = this; } else { throw new Exception("Flora already exists at this location."); } }
private async void but_OK_Click(object sender, EventArgs e) { string buttonText = but_OK.Text; try { Enabled = false; but_OK.Text = "Loading..."; Cursor = Cursors.WaitCursor; // WaitCursor reverts during await Task.Run. A bug in winforms? var former = worldCtrl.WorldFormer; await Task.Run(() => { UpdateStatus("Building World"); var newWorld = new World(worldCtrl.WorldWidth, worldCtrl.WorldHeight, worldCtrl.WorldWrap); UpdateStatus("Terraforming World"); former.Generate(newWorld); foreach (var p in newWorld.Positions) { if (p.TotalAltitude < 0) { p.AdjustWaterLevel(-p.TotalAltitude); } } UpdateStatus("Building Flora"); newWorld.InitialiseFlora(floraCtrl.InitialCoverage); UpdateStatus("Building Creatures"); newWorld.InitialiseCreatures(creaturesCtrl.StartPopulation, creaturesCtrl.MaxPopulation); UpdateStatus("Complete"); CreatedWorld = newWorld; }); StartSim = true; Close(); } catch (Exception ex) { MessageBox.Show("Error", ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Enabled = true; but_OK.Text = buttonText; Cursor = Cursors.Default; } }
public RandomPointsWorldSeed(World world, RandomPointsWorldFormer worldFormer, Point point, Position parentPosition) { World = world; WorldFormer = worldFormer; Point = point; ParentPositon = parentPosition; }
public void BeginDraw(World world) { World = world; RefreshTimer.Start(); DrawMode = true; }