Skip to main content
GameDev.net gamedev.net
🔒 Locked

Ticks in PHP Games

Started by Sayid Ahmed Mar 27, 2012 at 4:09 PM 0 replies 2k views
Original Post
Sayid Ahmed
Sayid Ahmed
With my current project the biggest challenge will be implementing the tick feature of my PHP + MySQL game. To briefly explain, my game is strategy based, is largely text-based (may have some javascript features later on). The following data will be stored in database tables and will need to be updated somehow:

  • one continuous 'world' with each player with their nation statistics
  • resources, units, research, production and such will all be updated on a tick basis (10 min periods, maybe?)
  • long term statistics; e.g. political party popularity for each player updates every 2 weeks
  • battles will be ticked and can last for days

    Which begs the question of how to implement this tick system. The long term stuff and low bandwidth stuff can be arranged by cron job - simple solution probably. It's the resources and battles and all that stuff that I'm curious about. Most online advice says use timestamps and only update on request by the user, but is it actually that much more efficient? Anybody have any experience with it so they can benchmark?

    What bothers me is that, one of the core features of the game will be trade, and with that you need a market place with lists of buy and sell orders. These will need to be kept up to date and every time the user visits the 'market.php' page it will have to do a search query and update it accordingly. I'm worried this could take very long and by the time the user chooses to buy or sell something, the data has changed and they'll get the wrong order when they submit.

    I'd guess some of this data can be cached and work quickly but I have no experience with this.

    Thanks
zoneweb
zoneweb

What bothers me is that, one of the core features of the game will be trade, and with that you need a market place with lists of buy and sell orders. These will need to be kept up to date and every time the user visits the 'market.php' page it will have to do a search query and update it accordingly. I'm worried this could take very long and by the time the user chooses to buy or sell something, the data has changed and they'll get the wrong order when they submit.


You need to queue the orders and process them one at a time. Read from the database only if the values have been changed. Otherwise, display it from the cache like what you've said.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.