Пример #1
0
        public void Generate(Block[,,] blocks, ChunkInfo info)
        {
            PerlinNoise coarse = new PerlinNoise(info.Seed + PerlinAllocations.TEMPERATURE_COARSE);
            PerlinNoise medium = new PerlinNoise(info.Seed + PerlinAllocations.TEMPERATURE_MEDIUM);
            PerlinNoise fine = new PerlinNoise(info.Seed + PerlinAllocations.TEMPERATURE_FINE);
            TemperatureInformation temperature = new TemperatureInformation();

            // Generate temperature.
            int ox = info.Bounds.Width / 2;
            int oy = info.Bounds.Height / 2;
            for (int x = -info.Bounds.Width / 2; x < info.Bounds.Width * 1.5; x++)
                for (int y = -info.Bounds.Height / 2; y < info.Bounds.Height * 1.5; y++)
                {
                    double noise = coarse.Noise((double)(info.Bounds.X + x) / PERLIN_COARSE_SCALE,
                        (double)(info.Bounds.Y + y) / PERLIN_COARSE_SCALE,
                        0);
                    noise += PerlinNoise.OFFSET;
                    if (x >= 0 && y >= 0 && x < info.Bounds.Width && y < info.Bounds.Height)
                        temperature.Temperature[x, y] = (float)noise;
                    temperature.NeighbouringTemperature[x + ox, y + oy] = (float)noise;
                }

            // Add to information list.
            info.Objects.Add(temperature);
        }
        public void Generate(Block[,,] blocks, ChunkInfo info)
        {
            while (RuntimeGame.DeviceForStateValidationOutput == null)
                continue;

            lock (RuntimeGame.LockForStateValidationOutput)
            {
                Console.Write("Locked graphics.  Rendering graph to file...");
                RainfallInformation rainfall = info.Objects.First(val => val is RainfallInformation) as RainfallInformation;
                TemperatureInformation temperature = info.Objects.First(val => val is TemperatureInformation) as TemperatureInformation;
                PresentationParameters pp = RuntimeGame.DeviceForStateValidationOutput.PresentationParameters;
                RenderTarget2D renderTarget = new RenderTarget2D(RuntimeGame.DeviceForStateValidationOutput, 200, 200, true, RuntimeGame.DeviceForStateValidationOutput.DisplayMode.Format, DepthFormat.Depth24);
                RuntimeGame.DeviceForStateValidationOutput.SetRenderTarget(renderTarget);
                RuntimeGame.ContextForStateValidationOutput.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);//, SaveStateMode.None, Matrix.Identity);
                //graphics.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
                //graphics.GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
                //graphics.GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;

                XnaGraphics graphics = new XnaGraphics(RuntimeGame.ContextForStateValidationOutput);
                if (File.Exists("state.png"))
                {
                    using (StreamReader reader = new StreamReader("state.png"))
                    {
                        Texture2D tex = Texture2D.FromStream(RuntimeGame.DeviceForStateValidationOutput, reader.BaseStream);
                        RuntimeGame.ContextForStateValidationOutput.SpriteBatch.Draw(tex, new Rectangle(0, 0, 200, 200), Color.White);
                    }
                }
                else
                {
                    graphics.FillRectangle(0, 0, 200, 200, Color.Red);
                    graphics.FillRectangle(0, 0, 100, 100, Color.White);
                }

                for (int x = 0; x < info.Bounds.Width; x++)
                    for (int y = 0; y < info.Bounds.Height; y++)
                    {
                        int r = 100 - (int)(rainfall.Rainfall[x, y] * 100);
                        int t = 100 - (int)(temperature.Temperature[x, y] * 100);

                        graphics.DrawLine(r, t, r + 1, t + 1, 1, new Color(0f, 0f, 0f, 0.1f).ToPremultiplied());
                    }

                RuntimeGame.ContextForStateValidationOutput.SpriteBatch.End();
                RuntimeGame.DeviceForStateValidationOutput.SetRenderTarget(null);
                using (StreamWriter writer = new StreamWriter("state.png"))
                {
                    renderTarget.SaveAsPng(writer.BaseStream, 200, 200);
                }
                Console.WriteLine(" done.");
            }
        }
        public GeneratedBlock Generate(ChunkInfo info, int x, int y)
        {
            // Create 20 continents.
            for (int i = 0; i < 5; i += 1)
            {
                int cx = info.Random.Next(-3000, 3000);
                int cy = info.Random.Next(-3000, 3000);
                int cw = (int)info.Random.NextGuassian(3000, 4000);
                int ch = (int)info.Random.NextGuassian(3000, 4000);
                info.Objects.Add(new Continent(cx, cy, cw, ch));
                info.Uniques.Add(new ContinentInformation(cx, cy));
            }

            // Don't set anything yet.
            return null;
        }
        public GeneratedBlock Generate(ChunkInfo info, int x, int y)
        {
            // Check continents to see where we're inside one.
            foreach (Continent c in info.Objects.Where(obj => obj is Continent))
            {
                // Skip, we're not inside this.
                if (!(x >= c.X - c.Width && y >= c.Y - c.Height &&
                      x <= c.X + c.Width && y <= c.Y + c.Height))
                    return null;

                // Temporary.
                if (x >= c.X - c.Width && y >= c.Y - c.Height &&
                      x <= c.X + c.Width && y <= c.Y + c.Height)
                    return new GeneratedBlock { Type = GeneratedBlock.BlockType.Grass };

                // Calculate shape.
                //int middleX = c.X;
                //int middleY = c.Y;

            }

            return null;
        }
Пример #5
0
        public static ProvideTask FillChunk(Chunk chunk, int[] rawdata, Block[, ,] blocks, ChunkInfo info, Action onSkip, Action onGeneration)
        {
            ProvideTask rt = new ProvideTask()
            {
                Chunk                = chunk,
                Blocks               = blocks,
                RawData              = rawdata,
                Info                 = info,
                OnSkipCallback       = onSkip,
                OnGenerationCallback = onGeneration
            };

            m_Tasks.Add(rt);
            return(rt);
        }
Пример #6
0
 private void Generate()
 {
     Thread t = new Thread(() =>
     {
         ChunkInfo i = new ChunkInfo(this.m_Uniques)
         {
             Seed = this.m_Seed,
             Random = new Random(this.m_Seed),
             Bounds = new Rectangle(this.GlobalX, this.GlobalY, Chunk.Width, Chunk.Height)
         };
         foreach (IGenerator g in this.m_Generators)
             g.Generate(this.m_Blocks, i);
         /*
         for (int x = 0; x < Chunk.Width; x++)
             for (int y = 0; y < Chunk.Height; y++)
             {
                     GeneratedBlock b = g.Generate(i, this.m_GlobalX + x, this.m_GlobalY + y);
                     if (b != null)
                         this.m_Blocks[x, y] = b;
                 }
                 int percent = (int)((double)(y + (x * Chunk.Height)) / (double)total * 100);
                 if (lastPercent < percent)
                 {
                     Log.WriteLine("... " + percent.ToString() + "% (" + (y + (x * Chunk.Height)).ToString() + "/" + total.ToString() + ") complete.");
                     lastPercent = percent;
                 }
             }*/
     });
     t.IsBackground = true;
     t.Start();
 }