Algorithm for Client-Server Games

Click Ok picture Click Ok · May 1, 2009 · Viewed 8.1k times · Source

For stand alone games, the basic game loop is (source: wikipedia)

while( user doesn't exit )
  check for user input
  run AI
  move enemies
  resolve collisions
  draw graphics
  play sounds
end while

But what if I develop client-server-like games, like Quake, Ragnarock, Trackmania, etc,

What the Loop/Algorithm for client and the server parts of the game?

Answer

Dave picture Dave · May 1, 2009

It would be something like

Client:

while( user does not exit )
    check for user input
    send commands to the server
    receive updates about the game from the server
    draw graphics
    play sounds
end

Server:

while( true )
    check for client commands
    run AI
    move all entities
    resolve collisions
    send updates about the game to the clients
end