Author Topic: Building a countdown timer queue  (Read 325 times)

Offline Leviathan

  • Level 1
  • *
  • Posts: 2
  • Reputation: +0/-0
    • View Profile
Building a countdown timer queue
« on: February 01, 2012, 01:30:29 AM »
So I'm working a game feature similar to how OGame functions. You initiate an action and then it adds it to a queue, the queue is processed based on how long it takes for that action to complete.

For example: You initiate the process to build a building that takes 90 seconds to complete. It is the first added to your queue so it starts counting down immediately. Then you initiate the build of another building and it is also added to the queue. But before it starts processing it has to wait for the first action to be completed.

I'm doing this with PHP/MySQL and jQuery and I have the timer system down and you can add actions to a queue but the part I'm stuck on is having other actions wait their turn.

If someone could maybe guide me through the thought process of how to have an action wait it's turn in the queue that would be awesome. Also when would be the best time to handle the action once the timer has completed? Should I process it with an AJAX call to a custom API or should I handle the action when the user has refreshed the page?
« Last Edit: February 01, 2012, 01:32:53 AM by Leviathan »

Offline BlackScorp

  • Level 15
  • *
  • Posts: 123
  • Reputation: +6/-0
    • View Profile
    • Cruel Online
Re: Building a countdown timer queue
« Reply #1 on: February 01, 2012, 04:05:48 AM »
basicly you make your actions on click, but display the result later. for example your player clicks on upgraid a building. so you save in your database the new level of the building and the timestamp when the building upgraid process is done. so if player goes ingame he see the countdown if now is bigger than the timesamp so he see the new building level, else he see the building level -1.

to be clear, dont make an ajax request each second or stuff, just display content if the time is right for it.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Building a countdown timer queue
« Reply #2 on: February 01, 2012, 05:17:03 AM »
You don't wait or anything, there is no queue of any kind. Just an end time. When you enter a new building to the "queue" its end time is equal to the current building processing time + the remining process time of all previous buildings. After that you never check what was in what order.

Also read about "cronjobs" (but it is messy to use for your case, still AJAX/refresh is not good either...)

Offline Leviathan

  • Level 1
  • *
  • Posts: 2
  • Reputation: +0/-0
    • View Profile
Re: Building a countdown timer queue
« Reply #3 on: February 04, 2012, 09:17:55 PM »
Thanks Chris, making those changes lead me to getting it working.
« Last Edit: February 05, 2012, 11:26:12 PM by Leviathan »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal