View Single Post
Old Sep 6th, 2007, 5:46 AM   #9
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 327
Rep Power: 3 kruptof is on a distinguished road
Quote:
Originally Posted by lectricpharaoh View Post
This won't work. This brings you full-circle to your original problem.

Picture this. You add an event that should fire after 10 seconds. You then add an event that should fire after 5 seconds, so it goes to the front of the queue. When it fires, you see the event that has a 10-second delay, and set the timer accordingly. The problem, however, is that 5 seconds have elapsed, so when the 10-second delay expires, it will have been 15 seconds.
Quote:
Originally Posted by kruptof
En-queue items as normal (using the delay time not the due time), set the timer interval to the one add the head of the queue, when that item is de-queue subtract that items time from the one at the head of the queue, if it's 0 de-queue
Items in the queue: 5(item1) 10(item2)

5 seconds pass:

dequeue item1, now subtract 5(item1's time) from the item at the head of the queue(item2), not zero so set the interval to 5. Now put all items that were dequeued back into the queue (with their original times).

Items in the queue: 5 (item2), 5 item(1)

5 seconds pass: (in total 10 seconds have passed)

Dequeue item2(because it's at the head of the queue), now subtract 5(item2's time) from the item at the head of the queue(item1), 5-5 = 0, now also dequeue item1.Now put all items that were dequeued back into the queue.(with their original times).

items in the queue5(item1) 10 (item2)


..and so on
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote