Search code examples
c++multiplayer

When to send packets in multiplayer game loop?


I'm programming my first multiplayer game loop and right now my loop consists of:

  1. logic
  2. process keyboard input
  3. process mouse input
  4. draw

At what point in the loop is it best to send packets to the server?

My current game loop:

    while (!key[KEY_ESC]) {
        while (speed_counter > 0) {
            update();
            keyboard();
            mouse();
            speed_counter--;
        }
        if(game_time - old_time >= 10) {
            fps = frames_done;
            frames_done = 0;
            old_time = game_time;
        }
        draw();
        frames_done++;
    }

Solution

  • You would want to send packets after input is received (in this case both keyboard and mouse) so that all moves can be updated at the same time. You would want a step 3.5 that was something like update other players if I understand your question correctly