Esempio n. 1
0
        public void Build(object sender, EventArgs e)
        {
            List <Thread> threads = new List <Thread>();
            DequeueObject dequeueObject;

            for (int t = 0; t < MaxThreads; t++)
            {
                MapChanges.Add(new List <MapChange>());
                ChangedTiles.Add(new List <int>());

                if (Threading)
                {
                    threads.Add(new Thread(new ParameterizedThreadStart(EnqueueDrops)));
                    threads[t].Start(t);
                }
                else
                {
                    EnqueueDrops(MapChanges[t]);
                }
            }
            if (Threading)
            {
                foreach (var thread in threads)
                {
                    thread.Join();
                }

                threads.Clear();
            }

            Console.WriteLine("Drops Enqueued: " + MapChanges[0].Count);

            Timer.TimerEvent timerEventThreaded    = new Timer.TimerEvent("Threaded Dequeue", MaxThreads * 10000);
            Timer.TimerEvent timerEventNonThreaded = new Timer.TimerEvent("Not Threaded Dequeue", MaxThreads * 10000);
            Timer.TimingManager.Start();
            if (Threading)
            {
                timerEventThreaded.StartEvent();
            }
            else
            {
                timerEventNonThreaded.StartEvent();
            }


            for (int i = 0; i < MaxThreads; i++)
            {
                if (Threading)
                {
                    dequeueObject = new DequeueObject(MapChanges[i], ChangedTiles[i]);
                    threads.Add(new Thread(new ThreadStart(() => DequeueDrops(dequeueObject))));
                    threads[i].Start();
                }
                else
                {
                    dequeueObject = new DequeueObject(MapChanges[i], ChangedTiles[i]);
                    DequeueDrops(dequeueObject);
                }
            }
            if (Threading)
            {
                foreach (var thread in threads)
                {
                    thread.Join();
                }
                threads.Clear();
            }


            if (Threading)
            {
                //timerEventThreaded.FinishEvent(true);
            }
            else
            {
                timerEventNonThreaded.FinishEvent(true);
            }
            Timer.TimingManager.Stop();

            foreach (var t in timerEvents)
            {
                //t.WriteToFile();
            }

            PostProcessing(map.Tiles);
            MapChanges.Clear();
            ChangedTiles.Clear();
            GenerateImage();

            /*
             * for (int i = 0; i <  MaxThreads; i++)
             * {
             *  threads.Add(new Thread(new ThreadStart(() => PostProcessing(ChangedTiles[i]))));
             *  threads[i].Start();
             * }
             *
             *
             * form.Label.Invoke((MethodInvoker)delegate {
             *
             * form.Label.Text = newText;
             *
             * });
             *
             *
             * foreach (var thread in threads)
             * {
             *  thread.Join();
             * }
             * threads.Clear();
             */
            _pb.Image = _bm;
            _pb.Refresh();

            DropButton.Invoke((MethodInvoker) delegate
            {
                DropButton.PerformClick();
            });
            //WriteToConsole();
        }
Esempio n. 2
0
        private void DequeueDrops(Object Dequeue)
        {
            int              start, dist;
            bool             sign;
            DequeueObject    dequeueObject = (DequeueObject)Dequeue;
            List <int>       Tiles         = dequeueObject.Tiles;
            List <MapChange> mapChanges    = dequeueObject.MapChanges;

            int          modelCount = Enum.GetNames(typeof(Fibb.ModelChanges)).Length;
            ITile        tile, tempTile;
            List <int>   model;
            List <ITile> borderTiles;

            //Console.WriteLine("Thread ID: "+ Thread.CurrentThread.ManagedThreadId);
            Timer.TimerEvent timerEvent = new Timer.TimerEvent("Before Propogation id: " + Thread.CurrentThread.ManagedThreadId, 10000);



            timerEvents.Add(timerEvent);
            timerEvent.StartEvent();


            //Console.WriteLine(MapChanges.Count);
            foreach (var mp in mapChanges)
            {
                tile = mp.Tile;

                model = _fibb.Models[mp.Enum];

                start = model[mp.Index];

                map.BiomeIds++;
                sign = map.DetermineSign() > 50 ? false : true;

                tile.BiomeId = map.BiomeIds;
                tile.ChangeHeight(start, sign);

                borderTiles = new List <ITile>();

                tile.AddToBorderList(borderTiles, tile);

                while (borderTiles.Count > 0)
                {
                    int index = r.Next(borderTiles.Count);

                    tempTile = borderTiles[index];

                    dist = tile.GetDist(tempTile);

                    if (dist < mp.Index)
                    {
                        tempTile.ChangeHeight(model[mp.Index - dist], sign);

                        tempTile.BiomeId = map.BiomeIds;

                        tempTile.AddToBorderList(borderTiles, tempTile);
                    }
                    else
                    {
                        borderTiles.Remove(tempTile);
                    }
                }
            }


            timerEvent.FinishEvent(false);
        }