Beispiel #1
0
 public void Unlink(Thought from)
 {
     if (from != null)
     {
         from.next = next;
     }
     next = null;
 }
Beispiel #2
0
        /// <summary>
        /// Clear the head from thoughts
        /// </summary>
        public void Clear()
        {
            Thought pos = _head;

            _head = null;
            while (pos != null && pos.Next != null)
            {
                pos.Next.Unlink(pos);
                pos = pos.Next;
            }
        }
Beispiel #3
0
        public static Thought UnlinkJob(Thought head, int time)
        {
            if (head == null || head.triggerTime > time)
            {
                return(head);
            }

            Thought pos = head;

            while (pos.next != null && pos.next.triggerTime <= time)
            {
                pos = pos.next;
            }

            Thought next = pos.next;

            pos.next = null;
            return(next);
        }
Beispiel #4
0
        /// <summary>
        /// Remove a thought from the head
        /// </summary>
        /// <param name="thought"></param>
        public void Remove(Thought thought)
        {
            if (_head == thought)
            {
                _head = _head.Next;
            }
            else
            {
                Thought pos = _head;
                while (pos != null && pos.Next != thought)
                {
                    pos = pos.Next;
                }

                if (pos != null && pos.Next == thought)
                {
                    thought.Unlink(pos);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Executes the thoughts work
        /// </summary>
        public void Work()
        {
            while (true)
            {
                int time = _time;

                Thought head;
                Thought pos;
                pos  = head = _head;
                head = _head = Thought.UnlinkJob(_head, time);
                if (pos == head)
                {
                    Thread.Sleep(10);
                    continue;
                }

                while (pos != null)
                {
                    Thought next = pos.Next;
                    pos.Unlink(null);

                    try {
                        pos.Trigger();
                    } catch (Exception e) {
                        ServerConsole.WriteLine(System.Drawing.Color.Red, "Exception in timed callback: {0}", e.Message);
                        if (e.StackTrace != null)
                        {
                            ServerConsole.WriteLine(System.Drawing.Color.Red, e.StackTrace);
                        }
                        ServerConsole.WriteLine("");
                    }
                    pos = next;
                }
                _time = Math.Min(_time, time + 5);
                Thread.Sleep(10);
            }
        }
Beispiel #6
0
        public void AutoLink(ref Thought head)
        {
            if (head == null)
            {
                head = this;
                return;
            }

            if (TriggerTime <= head.TriggerTime)
            {
                this.next = head;
                head      = this;
                return;
            }

            Thought pos = head;

            while (pos.next != null && TriggerTime > pos.next.TriggerTime)
            {
                pos = pos.next;
            }

            Link(pos);
        }
Beispiel #7
0
 public void Link(Thought to)
 {
     next    = to.next;
     to.next = this;
 }
Beispiel #8
0
 /// <summary>
 /// Requeues the thought with a delta timer
 /// </summary>
 /// <param name="delta"></param>
 /// <param name="thought"></param>
 public void RequeueDelta(double delta, Thought thought)
 {
     thought.TriggerTime += (int)(delta * 10);
     thought.AutoLink(ref _head);
 }
Beispiel #9
0
 /// <summary>
 /// Requeues the thought
 /// </summary>
 /// <param name="time"></param>
 /// <param name="thought"></param>
 public void Requeue(double time, Thought thought)
 {
     thought.TriggerTime = (int)(_time + time * 10);
     thought.AutoLink(ref _head);
 }