コード例 #1
0
ファイル: MovementOrder.cs プロジェクト: JHaugland/WetAffairs
 public virtual Waypoint ActivateNextWaypoint()
 {
     if (_waypoints == null || _waypoints.Count == 0)
     {
         return(null);
     }
     if (!IsRecurring)
     {
         _waypoints.RemoveFirst();
         //GameManager.Instance.Log.LogDebug(
         //    string.Format("Waypoint Id={0},  removed from MovementOrder {1}. Remaining wp count={2}",
         //    Id, this.ToString(), _waypoints.Count));
     }
     else
     {
         var wp2 = _waypoints.Dequeue();
         if (_waypoints.Count > 0 && !wp2.IsNotRecurring) //do not enqueue same waypoint if no other remaining
         {
             if (wp2.TargetDetectedUnit == null)          //do not re-enqueue targetting waypoints
             {
                 _waypoints.Enqueue(wp2);
             }
         }
     }
     return(GetActiveWaypoint());
 }
コード例 #2
0
ファイル: FlexQueueBasicTest.cs プロジェクト: CodeHex/TCL
        public void GetNextItemFromFlexQueueWhenNoItemsAvailable()
        {
            // Arrange
            var queue = new FlexQueue<long>();

            // Act
            queue.Dequeue();
        }
コード例 #3
0
ファイル: FlexQueueBasicTest.cs プロジェクト: CodeHex/TCL
        public void GetNextItemFromFlexQueue()
        {
            // Arrange
            var queue = new FlexQueue<string>();

            // Act
            queue.Enqueue("DDD");
            queue.Enqueue("EEE");
            queue.Enqueue("FFF");
            queue.Enqueue("GGG");

            var firstItem = queue.Dequeue();
            var secondItem = queue.Dequeue();
            var thirdItem = queue.Dequeue();

            // Assert
            Assert.AreEqual("DDD", firstItem);
            Assert.AreEqual("EEE", secondItem);
            Assert.AreEqual("FFF", thirdItem);
        }
コード例 #4
0
ファイル: FlexQueueBasicTest.cs プロジェクト: CodeHex/TCL
        public void GetNumberOfItemsInFlexQueue()
        {
            // Arrange
            var queue = new FlexQueue<object>();
            queue.Enqueue("Hello");
            queue.Enqueue(65);
            queue.Enqueue(new List<string>());
            queue.Enqueue(new Action(() => Console.Write("Adding Action")));

            // Act and Assert
            Assert.AreEqual(4, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(3, queue.Count);
        }
コード例 #5
0
        public void Arrange(Document document)
        {
            var pageSize = document.Variables["page"]["size"].GetValue <Size>();
            var margin   = document.Variables["page"]["margin"].GetValue <Thickness>();
            var boxSize  = pageSize;

            boxSize.Height -= margin.Height;
            boxSize.Width  -= margin.Width;

            var startOffset = new Position(margin.Left, margin.Top);
            var contentArea = new Rectangle(startOffset, boxSize);

            var    curPage   = AddPage(document, pageSize, contentArea);
            double curHeight = boxSize.Height;

            var flexQueue   = new FlexQueue <Measurement>(); //new Queue<Measurement>();
            var enqueueNext = false;

            // Stage one:
            // Add measurements to pages
            foreach (var measurement in document.Measurements)
            {
                if (enqueueNext)
                {
                    flexQueue.Enqueue(measurement, measurement.Flexible);
                    enqueueNext = measurement.PagebreakPenalty > 0;
                }
                else if (measurement.PagebreakPenalty > 0)
                {
                    flexQueue.Enqueue(measurement.Flexible);
                    flexQueue.Enqueue(measurement, measurement.Flexible);
                    enqueueNext = true;
                }
                else
                {
                    while (flexQueue.Count > 0)
                    {
                        var peeked = flexQueue.Peek();
                        if (FitAll(peeked, curHeight))
                        {
                            foreach (var ms in peeked)
                            {
                                TryFitMeasurement(curPage, ms, flexQueue, true, ref curHeight);
                            }
                            flexQueue.Dequeue();
                        }
                        else if (!flexQueue.IsFlex)
                        {
                            curHeight      = boxSize.Height;
                            curPage.Filled = true;
                            curPage        = AddPage(document, pageSize, contentArea);
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (TryFitMeasurement(curPage, measurement, flexQueue, false, ref curHeight) == FitResult.AddPage)
                    {
                        curHeight      = boxSize.Height;
                        curPage.Filled = true;
                        curPage        = AddPage(document, pageSize, contentArea);
                    }
                }
            }

            // Add leftover flexible items
            while (flexQueue.Count > 0)
            {
                var ms = flexQueue.Dequeue();
                foreach (var m in ms)
                {
                    m.Flexible = false;

                    if (TryFitMeasurement(curPage, m, flexQueue, false, ref curHeight) == FitResult.AddPage)
                    {
                        curHeight      = boxSize.Height;
                        curPage.Filled = true;
                        curPage        = AddPage(document, pageSize, contentArea);
                    }
                }
            }

            // Stage two:
            // Layout measurements on each page
            foreach (var page in document.Pages)
            {
                var currentOffset = startOffset;

                foreach (var measurement in page.Measurements)
                {
                    var size = measurement.Size;

                    currentOffset.Y += measurement.Margin.Top;

                    var visualOffset = currentOffset;
                    visualOffset.X += measurement.Margin.Left;

                    measurement.Position = visualOffset;
                    Realign(measurement, boxSize, pageSize, measurement.Element.HorizontalAlignment);
                    measurement.Element.Arrange(measurement);

                    currentOffset.Y += size.Height;
                    currentOffset.Y += measurement.Margin.Bottom;
                }

                // Set number at the end of the page layouting
                // so that any number changing elements can take effect
                page.Number = document.PageNumbering.Next();
                page.AddPageItems();
            }
        }