Exemplo n.º 1
0
        public bool Contains(T node)
        {
            Insist.IsNotNull(node, "node cannot be null");
            Insist.IsFalse(node.QueueIndex < 0 || node.QueueIndex >= _nodes.Length, "node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?");

            return(_nodes[node.QueueIndex] == node);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the selected text
        /// </summary>
        /// <param name="selectionStart">Selection start.</param>
        /// <param name="selectionEnd">Selection end.</param>
        public TextField SetSelection(int selectionStart, int selectionEnd)
        {
            Insist.IsFalse(selectionStart < 0, "selectionStart must be >= 0");
            Insist.IsFalse(selectionEnd < 0, "selectionEnd must be >= 0");

            selectionStart = Math.Min(text.Length, selectionStart);
            selectionEnd   = Math.Min(text.Length, selectionEnd);
            if (selectionEnd == selectionStart)
            {
                ClearSelection();
                return(this);
            }

            if (selectionEnd < selectionStart)
            {
                int temp = selectionEnd;
                selectionEnd   = selectionStart;
                selectionStart = temp;
            }

            hasSelection        = true;
            this.selectionStart = selectionStart;
            cursor = selectionEnd;

            return(this);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sets the cursor position and clears any selection
 /// </summary>
 /// <param name="cursorPosition">Cursor position.</param>
 public TextField SetCursorPosition(int cursorPosition)
 {
     Insist.IsFalse(cursorPosition < 0, "cursorPosition must be >= 0");
     ClearSelection();
     cursor = Math.Min(cursorPosition, text.Length);
     return(this);
 }
Exemplo n.º 4
0
        public void UpdatePriority(T node, int priority)
        {
            Insist.IsNotNull(node, "node cannot be null");
            Insist.IsFalse(Contains(node), "Cannot call UpdatePriority() on a node which is not enqueued: " + node);

            node.Priority = priority;
            OnNodeUpdated(node);
        }
Exemplo n.º 5
0
        public FSCollisionEllipse(float xRadius, float yRadius, int edgeCount)
        {
            Insist.IsFalse(edgeCount > Settings.MaxPolygonVertices, "edgeCount must be less than Settings.maxPolygonVertices");

            _xRadius   = xRadius;
            _yRadius   = yRadius;
            _edgeCount = edgeCount;
            _verts     = PolygonTools.CreateEllipse(_xRadius * FSConvert.DisplayToSim, _yRadius * FSConvert.DisplayToSim, _edgeCount);
        }
Exemplo n.º 6
0
        public FSCollisionEllipse SetEdgeCount(int edgeCount)
        {
            Insist.IsFalse(edgeCount > Settings.MaxPolygonVertices, "edgeCount must be less than Settings.maxPolygonVertices");

            _edgeCount = edgeCount;
            _verts     = PolygonTools.CreateEllipse(_xRadius * FSConvert.DisplayToSim, _yRadius * FSConvert.DisplayToSim, _edgeCount);
            RecreateFixture();
            return(this);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it.
        /// If queue is empty, result is undefined
        /// O(log n)
        /// </summary>
        public T Dequeue()
        {
            Insist.IsFalse(_numNodes <= 0, "Cannot call Dequeue() on an empty queue");
            Insist.IsTrue(IsValidQueue(), "Queue has been corrupted (Did you update a node priority manually instead of calling UpdatePriority()?" +
                          "Or add the same node to two different queues?)");

            T returnMe = _nodes[1];

            Remove(returnMe);
            return(returnMe);
        }
Exemplo n.º 8
0
        public void IsFalse_2_Null_Or_Empty_User_Message_Uses_Default_Message(string userMessage)
        {
            string message = null;

            try {
                Insist.IsFalse(true, ARGUMENT_NAME, userMessage);
            } catch (ArgumentException e) {
                message = e.Message;
            }

            Assert.IsNotNullOrEmpty(message);
        }
Exemplo n.º 9
0
        public Subtexture CreateRegion(string name, int x, int y, int width, int height, float pivotX = 0.5f, float pivotY = 0.5f)
        {
            Insist.IsFalse(_subtextureMap.ContainsKey(name), "Region {0} already exists in the texture atlas", name);

            var region = new Subtexture(Texture, new Rectangle(x, y, width, height), new Vector2(pivotX * width, pivotY * height));
            var index  = Subtextures.Count;

            Subtextures.Add(region);
            _subtextureMap.Add(name, index);

            return(region);
        }
Exemplo n.º 10
0
        public void Enqueue(T node, double priority)
        {
            Insist.IsNotNull(node, "node cannot be null");
            Insist.IsFalse(_numNodes >= _nodes.Length - 1, "Queue is full - node cannot be added: " + node);
            Insist.IsFalse(Contains(node), "Node is already enqueued: " + node);

            node.Priority = priority;
            _numNodes++;
            _nodes[_numNodes]   = node;
            node.QueueIndex     = _numNodes;
            node.InsertionIndex = _numNodesEverEnqueued++;
            CascadeUp(_nodes[_numNodes]);
        }
Exemplo n.º 11
0
        public void AddObserver(T eventType, Action handler)
        {
            List <Action> list = null;

            if (!_messageTable.TryGetValue(eventType, out list))
            {
                list = new List <Action>();
                _messageTable.Add(eventType, list);
            }

            Insist.IsFalse(list.Contains(handler), "You are trying to add the same observer twice");
            list.Add(handler);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Resize the queue so it can accept more nodes.  All currently enqueued nodes are remain.
        /// Attempting to decrease the queue size to a size too small to hold the existing nodes results in undefined behavior
        /// O(n)
        /// </summary>
        public void Resize(int maxNodes)
        {
            Insist.IsFalse(maxNodes <= 0, "Queue size cannot be smaller than 1");
            Insist.IsFalse(maxNodes < _numNodes, "Called Resize(" + maxNodes + "), but current queue contains " + _numNodes + " nodes");

            T[] newArray           = new T[maxNodes + 1];
            int highestIndexToCopy = Math.Min(maxNodes, _numNodes);

            for (int i = 1; i <= highestIndexToCopy; i++)
            {
                newArray[i] = _nodes[i];
            }
            _nodes = newArray;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sets the selection to only the selected index
        /// </summary>
        /// <param name="index">Index.</param>
        public ListBox <T> SetSelectedIndex(int index)
        {
            Insist.IsFalse(index < -1 || index >= _items.Count, "index must be >= -1 and < " + _items.Count + ": " + index);

            if (index == -1)
            {
                _selection.Clear();
            }
            else
            {
                _selection.Set(_items[index]);
            }

            return(this);
        }
Exemplo n.º 14
0
 public Subtexture GetSubtexture(int index)
 {
     Insist.IsFalse(index < 0 || index >= Subtextures.Count, "index out of range");
     return(Subtextures[index]);
 }
Exemplo n.º 15
0
 public BehaviorTreeBuilder <T> LogAction(string text)
 {
     Insist.IsFalse(_parentNodeStack.Count == 0,
                    "Can't create an unnested Action node. It must be a leaf node.");
     return(SetChildOnParent(new LogAction <T>(text)));
 }
Exemplo n.º 16
0
 public BehaviorTreeBuilder <T> WaitAction(float waitTime)
 {
     Insist.IsFalse(_parentNodeStack.Count == 0,
                    "Can't create an unnested Action node. It must be a leaf node.");
     return(SetChildOnParent(new WaitAction <T>(waitTime)));
 }
Exemplo n.º 17
0
 public void IsFalse_2_False_Throws_Exception()
 {
     Insist.IsFalse(true, ARGUMENT_NAME, MESSAGE);
 }
Exemplo n.º 18
0
 public void IsFalse_2_True_Does_Not_Throw_Exception()
 {
     Assert.DoesNotThrow(() => { Insist.IsFalse(false, ARGUMENT_NAME, MESSAGE); });
 }
Exemplo n.º 19
0
 public void IsFalse_2_Null_Or_Empty_Argument_Name_Throws_Exception(string argName)
 {
     Insist.IsFalse(false, argName, MESSAGE);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Splice a sub tree into the parent tree.
 /// </summary>
 public BehaviorTreeBuilder <T> SubTree(BehaviorTree <T> subTree)
 {
     Insist.IsFalse(_parentNodeStack.Count == 0,
                    "Can't splice an unnested sub tree, there must be a parent tree.");
     return(SetChildOnParent(new BehaviorTreeReference <T>(subTree)));
 }
Exemplo n.º 21
0
 public BehaviorTreeBuilder <T> Conditional(Func <T, TaskStatus> func)
 {
     Insist.IsFalse(_parentNodeStack.Count == 0,
                    "Can't create an unnested Conditional node. It must be a leaf node.");
     return(SetChildOnParent(new ExecuteActionConditional <T>(func)));
 }