Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] synced lobbyTime #61

Open
afrokick opened this issue Sep 25, 2023 · 0 comments
Open

[Feature Request] synced lobbyTime #61

afrokick opened this issue Sep 25, 2023 · 0 comments

Comments

@afrokick
Copy link
Contributor

Hey!

Motivation:

Almost every multiplayer online game has a synced clock aka remoteTime, remoteTicks, roomTime etc.

Its helps to understand when exactly actions be happened and how to handle it on the local side.

Suggestion:

When we create a lobby, we set on the server side:

_createdAt = Date.now();
lobbyTime(){
  return Date.now() - _createdAt;
}

Then, we send it to the every peer.

On the client side, we have:
network.ts

  private onLobbyTimeReceived(lobbyTime: number) {
    // TODO we need to compensate for the RTT/ping
    const compensation = 10;
    this._createdAt = Date.now() - lobbyTime + compensation;
    
  }
  get lobbyTime() {
    return Date.time() - this._createdAt;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant