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

Interpolation + event updates causes visual glitch when mining #214

Open
sourencho opened this issue May 23, 2020 · 0 comments
Open

Interpolation + event updates causes visual glitch when mining #214

sourencho opened this issue May 23, 2020 · 0 comments
Labels
bug Something isn't working graphics networking

Comments

@sourencho
Copy link
Owner

PR #213 introduces a bug where a collision event causes mine to appear to be mined twice in a quick visual glitch.

This happens because now that the client is just interpolating, it no longer computes collisions locally. In order for the appropriate visual side effects of a collision event occur (such as the collision animaton), the server now sends events along with the game state. The callbacks for this event are then triggered on the client. This was done to trigger the collision animation but the "mine" callback also triggers. This causes the mine to lose a resource. Since the server already sent the mine with the updated number of resources we are now showing the state where the mine was mined twice. In the next frame this is likely to get corrected when we interpolate again but this causes a quick visual glitch.

A solution could be to have distinct callback subscriptions on the server and the client. That way the client can just subscribe the animation callback and not the "mine" one.

@sourencho sourencho added bug Something isn't working graphics networking labels May 23, 2020
sourencho added a commit that referenced this issue May 23, 2020
- Replace rewind and replay with the client playing in the past and
interpolating to game states recieved from the server stored in a fixed
size buffer. The size of the buffer is configurable through the var
CLIENT_GAME_STATE_BUFFER_SIZE in game_settings.json.
- The logic for updating the local game state is as follows:
  - If the clients tick is too far behind (more than
  MAX_BEHIND_TICK_DELTA ticks) the smallest server state in the buffer
  then the local state is overwritten with the smallest server state.
  - If the client tick is not too far behind the smallest server state
  then then a game state is interpolated for the next tick using the
  smallest server state.
  - If the client is ahead of the smallest server state then the next
  game state in the buffer is used to recalculate the current tick's
  state but the tick is not incremented. This is in order to stall and
  fall back behind the smallest server state. If there aren't any states
  in the buffer ahead of the current tick, then the game state doesn't
  change.
- Add debug metrics around interpolation, ahead, behind, etc and update
the layout to be more readable
- Implement hermite interpolation to be able interpolate curves rather
than straight lines given start and end velocity of the rigid bodies.
- Send collision events in game state updates. This was necessary
because we no longer extrapolate, we only interpolate, which means we no
longer run the physics simulation locally and can't trigger visuals
caused by collisions. The events recieved from the server are now
applied and trigger collision animations. This introduced a visual bug
(issue #214).
- Reduce server input window sleep to 16ms to make the client and server
ticks/sec in sync. This is a messy dependency, it just so happens that
the server sleeps for that window causing it to control it's steps per
second. Not really a good way to control tick speed and the client and
server tick speeds goes out of sync as more clients connect. We might
need to implement some clock sync in the future.
- Seems like this change also broke the winner being displayed on the
client (issue #215).
- Minor code cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graphics networking
Projects
None yet
Development

No branches or pull requests

1 participant