With a game like "Farmville", there is both processing during gameplay, and when the user is offline (plants are always growing, for example). Many of the game maps elements depend on time.

Is there a trick to make this scale? How can you possibly calculate 1 million users maps being modified every couple of seconds? Some of these games alert you, when things have changed, so it is not like they calculate everything when you login to the system.

How do you calculate game map changes, over time, when the user is not online?


Let's take plants growing as an example.



function update(seconds_since_last_draw) {
    tomato_plant.age += seconds_since_last_draw / tomato_grow_time;
    if (tomato_plant.age >= 1) {
       /* plant is finished growing */



 function tomato_plant_age(time) {
      age = (time - tomato_plant.start_time) / tomato_grow_time;


 age = (time - start_time) / grow_time
 solve for time when age = 1
 time = (age * grow_time) + start_time




  • \$\begingroup\$ This is a great point. For notifications, you could use similar functions to query the database and return only records that have changed ("grown") since the last update. \$\endgroup\$ – Richard Marskell - Drackir Feb 23 '12 at 19:58




Server Based Game


Local Machine Based Game




  • \$\begingroup\$ server based, not local. \$\endgroup\$ – codecompleting Feb 23 '12 at 17:44
  • \$\begingroup\$ Right. Server based? Then have a cron job run a program task at some time interval dictated by your game design. That program analyzes the current game state, applies "growth" models based on your design, and sends out alerts as appropriate to your design. \$\endgroup\$ – Tim Holt Feb 23 '12 at 18:00

Your Answer

