Ejemplo n.º 1
0
 public void Unlink(Thought from)
 {
     if (from != null)
     {
         from.next = next;
     }
     next = null;
 }
Ejemplo n.º 2
0
        public static void Test(Thought thought, params object[] Params)
        {
            //Client client = Params[0] as Client;
            //ServerConsole.WriteLine("Sent unk 4");
            //client.Send(new Packets.UnknownError2(Packets.UNKNOWN_ERROR2.NINE));

            //Thinker.Requeue(5, thought);
        }
Ejemplo n.º 3
0
        public static void Test(Thought thought, params object[] Params)
        {
            //Client client = Params[0] as Client;
            //ServerConsole.WriteLine("Sent unk 4");
            //client.Send(new Packets.UnknownError2(Packets.UNKNOWN_ERROR2.NINE));

            //Thinker.Requeue(5, thought);
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
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("Exception in timed callback: {0}", MessageLevel.Error, e.Message);
                        if (e.StackTrace != null)
                        {
                            ServerConsole.WriteLine(e.StackTrace, MessageLevel.Error);
                        }
                        ServerConsole.WriteLine("");
                    }
                    pos = next;
                }
                _time = Math.Min(_time, time + 5);
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
 public void Unlink(Thought from)
 {
     if (from != null)
     {
         from.next = next;
     }
     next = null;
 }
Ejemplo n.º 11
0
 public void Link(Thought to)
 {
     next = to.next;
     to.next = this;
 }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
 }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
0
 public void Link(Thought to)
 {
     next    = to.next;
     to.next = this;
 }