Пример #1
0
        static void ProcessSeed(object WorldSeed)
        {
            RandomPointsWorldSeed worldSeed = (RandomPointsWorldSeed)WorldSeed;
            if (RandNum.Double() > 0.1)
            {
                ThreadPool.QueueUserWorkItem(ProcessSeed, WorldSeed);
                return;
            }

            Point p = worldSeed.Point;

            Position Pos = worldSeed.ParentPositon; //worldSeed.world.GetPosition(p);
            for (int i = 0; i < 8; i++)
            {
                Point p2 = new Point(p.X, p.Y);
                switch (i)
                {
                    case 0: //top right
                        p2.X++;
                        p2.Y--;
                        break;

                    case 1: //right
                        p2.X++;
                        break;

                    case 2: //bottom right
                        p2.X++;
                        p2.Y++;
                        break;

                    case 3: //bottom
                        p2.Y++;
                        break;

                    case 4: //bottom left
                        p2.X--;
                        p2.Y++;
                        break;

                    case 5: //left
                        p2.X--;
                        break;

                    case 6: //top left
                        p2.X--;
                        p2.Y--;
                        break;

                    case 7: //top
                        p2.Y--;
                        break;
                }

                p2 = new Point(worldSeed.World.CheckXCoord(p2.X), worldSeed.World.CheckYCoord(p2.Y));
                Position Pos2 = worldSeed.World.GetPosition(p2);

                if (Monitor.TryEnter(Pos2))
                {
                    if (!Pos2.Initialised)
                    {
                        Pos2.Initialised = true;

                        short Step = (short)RandNum.Integer(2); //(MinStep, MaxStep);
                        if (Step == 0)
                        {
                            Pos2.Altitude = (short)Pos.Altitude;
                        }
                        else
                        {
                            if (RandNum.Double() < worldSeed.WorldFormer.HighAltitudeProbability)
                                Pos2.Altitude = (short)(Pos.Altitude + Step);
                            else
                                Pos2.Altitude = (short)(Pos.Altitude - Step);
                        }

                        Interlocked.Increment(ref worldSeed.WorldFormer.PixelsCompleted);

                        RandomPointsWorldSeed NewWorldSeed = new RandomPointsWorldFormer.RandomPointsWorldSeed(worldSeed.World, worldSeed.WorldFormer, p2, Pos2);

                        Interlocked.Increment(ref worldSeed.WorldFormer.WorkingThreads);
                        ThreadPool.QueueUserWorkItem(ProcessSeed, NewWorldSeed);
                    }
                    Monitor.Exit(Pos2);
                }
            }
            Interlocked.Decrement(ref worldSeed.WorldFormer.WorkingThreads);
        }
Пример #2
0
        static void ProcessSeed(object WorldSeed)
        {
            RandomPointsWorldSeed worldSeed = (RandomPointsWorldSeed)WorldSeed;

            if (RandNum.Double() > 0.1)
            {
                ThreadPool.QueueUserWorkItem(ProcessSeed, WorldSeed);
                return;
            }

            Point p = worldSeed.Point;

            Position Pos = worldSeed.ParentPositon; //worldSeed.world.GetPosition(p);

            for (int i = 0; i < 8; i++)
            {
                Point p2 = new Point(p.X, p.Y);
                switch (i)
                {
                case 0:     //top right
                    p2.X++;
                    p2.Y--;
                    break;

                case 1:     //right
                    p2.X++;
                    break;

                case 2:     //bottom right
                    p2.X++;
                    p2.Y++;
                    break;

                case 3:     //bottom
                    p2.Y++;
                    break;

                case 4:     //bottom left
                    p2.X--;
                    p2.Y++;
                    break;

                case 5:     //left
                    p2.X--;
                    break;

                case 6:     //top left
                    p2.X--;
                    p2.Y--;
                    break;

                case 7:     //top
                    p2.Y--;
                    break;
                }

                p2 = new Point(worldSeed.World.CheckXCoord(p2.X), worldSeed.World.CheckYCoord(p2.Y));
                Position Pos2 = worldSeed.World.GetPosition(p2);

                if (Monitor.TryEnter(Pos2))
                {
                    if (!Pos2.Initialised)
                    {
                        Pos2.Initialised = true;

                        short Step = (short)RandNum.Integer(2); //(MinStep, MaxStep);
                        if (Step == 0)
                        {
                            Pos2.Altitude = (short)Pos.Altitude;
                        }
                        else
                        {
                            if (RandNum.Double() < worldSeed.WorldFormer.HighAltitudeProbability)
                            {
                                Pos2.Altitude = (short)(Pos.Altitude + Step);
                            }
                            else
                            {
                                Pos2.Altitude = (short)(Pos.Altitude - Step);
                            }
                        }

                        Interlocked.Increment(ref worldSeed.WorldFormer.PixelsCompleted);

                        RandomPointsWorldSeed NewWorldSeed = new RandomPointsWorldFormer.RandomPointsWorldSeed(worldSeed.World, worldSeed.WorldFormer, p2, Pos2);

                        Interlocked.Increment(ref worldSeed.WorldFormer.WorkingThreads);
                        ThreadPool.QueueUserWorkItem(ProcessSeed, NewWorldSeed);
                    }
                    Monitor.Exit(Pos2);
                }
            }
            Interlocked.Decrement(ref worldSeed.WorldFormer.WorkingThreads);
        }