Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualhplus0603

Posted 10 July 2012 - 02:24 PM

I guess I don't understand lockstep.


I highly recommend reading the Age of Empires ("1,500 archers") article, linked to by the FAQ of this forum.

In a peer to peer method, is there a such thing as a host vs client?


You can use a peer-to-peer physical network connection, and still use a client/server logical game topology.

I guess the host would be one in charge of gathering up the random numbers for the game and sending it to the client... is that correct?


No. In a lock-step simulation, you initialize all the (pseudo-)random number generators to the same value once. Then, because all nodes run exactly the same commands in exactly the same order, the random number generators will generate the same values on all the nodes.

A simple way to think about this is that the game client looks something like:

game_step = 1;
for (step = game_step; step <= game_step + latency; ++step) {
  send_empty_data_for_step(step);
}
forever() {
  receive_packets();
  if (i_have_all_packets_for_step(game_step)) {
    step_simulation_once();
    game_step += 1;
    send_user_input_for_step(game_step + latency);
  }
  collect_input_commands();
  animate();
  render();
}

It's important that local commands do not actually have any effect on the local game state -- the local game state is only affected within step_simulation_once().

The "hosting" player still runs this kind of client, just like anyone else. Additionally, on the host, there is another logical process, that does:

game_step = 1;
forever() {
  if (i_have_all_player_data_for_step(game_step)) {
    send_all_player_data_for_step_to_all_players(game_step);
    game_step += 1;
  }
}

This can be interwoven in the main loop, or it can be a separate thread, or it can even be a separate process. It doesn't matter much. Note that the server doesn't necessarily have to simulate anything at all -- if you do proper lock-step, then the clients will all simulate exactly the same thing for the same step number. De-synch will be the result of a code bug, or the result of deliberate cheating.

#1hplus0603

Posted 10 July 2012 - 02:23 PM

I guess I don't understand lockstep.


I highly recommend reading the Age of Empires ("1,500 archers") article, linked to by the FAQ of this forum.

In a peer to peer method, is there a such thing as a host vs client?


You can use a peer-to-peer physical network connection, and still use a client/server logical game topology.

I guess the host would be one in charge of gathering up the random numbers for the game and sending it to the client... is that correct?


No. In a lock-step simulation, you initialize all the (pseudo-)random number generators to the same value once. Then, because all nodes run exactly the same commands in exactly the same order, the random number generators will generate the same values on all the nodes.

A simple way to think about this is that the game client looks something like:

game_step = 1;
for (step = game_step; step <= game_step + latency; ++step) {
  send_empty_data_for_step(step);
}
forever() {
  receive_packets();
  if (i_have_all_packets_for_step(game_step)) {
    step_once();
    game_step += 1;
    send_user_input_for_step(game_step + latency);
  }
  animate();
  render();
}

The "hosting" player still runs this kind of client, just like anyone else. Additionally, on the host, there is another logical process, that does:

game_step = 1;
forever() {
  if (i_have_all_player_data_for_step(game_step)) {
    send_all_player_data_for_step_to_all_players(game_step);
    game_step += 1;
  }
}

This can be interwoven in the main loop, or it can be a separate thread, or it can even be a separate process. It doesn't matter much. Note that the server doesn't necessarily have to simulate anything at all -- if you do proper lock-step, then the clients will all simulate exactly the same thing for the same step number. De-synch will be the result of a code bug, or the result of deliberate cheating.

PARTNERS