0
\$\begingroup\$

i am trying to implement a networked multiplaye game. i understand the game loop described here :

previous = getCurrentTime()

def loop():
    double lag = 0.0
    while True:

      current = getCurrentTime()
      elapsed = current - previous
      previous = current
      lag += elapsed

      processInput()

      while (lag >= MS_PER_UPDATE):
        update()
        lag -= MS_PER_UPDATE
      render()

I understand this well for a single player game. but i have some doubts regading multiplayer aspect. in case of multiplayer my inputs are recieved over websockets and i have a procees running on a port to accept the websocket events.

how do i then implement a game loop as i can see in above ex input processing is insisde the game loop.

what i am confused is where to do input handling and where is state updation done when writing a server based multiplayer game.

i have two options : 1) whenever i get an input event i update the state of the player and broadcast it to all other players 2) have an independent game loop on server which simulates the game world and then the entire state of game world is broadcasted to the all the connected players.

I think the second option makes more sense? i know there are many things wrong with the first approach but i do not know what exactly(like frame rate issue for different players?).

I want to know how is such systems implemented in actual multiplayer games as i am tired of seeing half baked answers on some websites which even implement the game loop wrong. any reference would help a lot

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.