make client prediction reverts more accurate

This commit is contained in:
HF 2021-01-27 22:56:14 +01:00
parent 41a9d7f334
commit 4e3f40c958

View File

@ -27,7 +27,7 @@ let pixelQueue = [];
/* /*
* requests that got predicted on client and yet have to be * requests that got predicted on client and yet have to be
* received from the server * received from the server
* [[i, j, offset, color], ...] * [[i, j, offset, colorold, colornew], ...]
*/ */
let clientPredictions = []; let clientPredictions = [];
/* /*
@ -84,7 +84,9 @@ export function receivePixelUpdate(
&& predPxl[1] === j && predPxl[1] === j
&& predPxl[2] === offset && predPxl[2] === offset
) { ) {
clientPredictions.splice(i, 1); if (predPxl[4] === color) {
clientPredictions.splice(i, 1);
}
return; return;
} }
} }
@ -136,7 +138,7 @@ export function tryPlacePixel(
curColor: ColorIndex, curColor: ColorIndex,
) { ) {
store.dispatch(updatePixel(i, j, offset, color)); store.dispatch(updatePixel(i, j, offset, color));
clientPredictions.push([i, j, offset, curColor]); clientPredictions.push([i, j, offset, curColor, color]);
if (pixelQueue.length) { if (pixelQueue.length) {
const lastReq = pixelQueue[pixelQueue.length - 1]; const lastReq = pixelQueue[pixelQueue.length - 1];