geckosio / snapshot-interpolation

A Snapshot Interpolation library for Real-Time Multiplayer Games.
BSD 3-Clause "New" or "Revised" License
277 stars 25 forks source link

Way to clear out vault? #14

Closed finkton1 closed 2 years ago

finkton1 commented 3 years ago

Hello,

I have a use case where I have a turn based billiard style game and I am using this library. All works well - however, after my initial turn, and I try to hit the ball, it seems to want to move slightly, stop, then after the interpolation buffer I have set (150ms) it will move again and follow through.

My hacky way of fixing this is re-initalizing the SnapshotInterpolation object after each turn to remove all snapshots from the vault.

It seems to be after the first turn, the library retains all previous snapshots and causes a slight delay when the ball will move again because of the interpolation buffer I have set.

Could we include an option to clear the vault? Or perhaps there is a better way to fix this stopping issue?

Some of my source code below: Apologizes for the ugly code snippet could not get it to format correctly.

` const snap = this.SI.calcInterpolation('x y');

if (!snap) return;
console.log('snap count: ',this.SI.vault.size)
const { state } = snap;
if (!state) return;
state.forEach((ball) => {
 // console.log(state)
  //@ts-ignore
  const _ball = this.playerBallGroup.getBallById(ball.entityId);
  if (!_ball) return;
  //@ts-ignore
  _ball.setX(ball.x);
        //@ts-ignore
  _ball.setY(ball.y);
});

public resetSnap() { this.SI = new SnapshotInterpolation(30); this.SI.interpolationBuffer.set(150); }

`