Skip to content

Commit

Permalink
Fix frame skip on lap change
Browse files Browse the repository at this point in the history
  • Loading branch information
tmalahie committed Aug 10, 2024
1 parent c39ec8b commit a5e912a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions scripts/mk.js
Original file line number Diff line number Diff line change
Expand Up @@ -10108,7 +10108,7 @@ function getApparentRotation(oPlayer) {
return res;
}

var lastState, lastStateTime;
var lastState, lastStateTime, lastStateChange;
function getLastObj(lastObjs,i,currentObj) {
if (lastObjs[i] && lastObjs[i].ref === currentObj.ref)
return lastObjs[i];
Expand Down Expand Up @@ -10168,7 +10168,8 @@ function handleLapChange(prevLepId,lapId, getId) {
resetAiPoints(oKart);
var sID = getScreenPlayerIndex(getId);
if (sID >= oPlayers.length) return;
resetRenderState();
lastStateChange = true;
clearPendingFrames();
hideLapSprites(lMap, sID);
var pMap = pMaps[lapId];
updateBgLayers(pMap, function(strImages, fixedScale) {
Expand All @@ -10189,6 +10190,9 @@ function handleCpChange(prevLap,prevCP, getId) {
}
function resetRenderState() {
lastState = undefined;
clearPendingFrames();
}
function clearPendingFrames() {
for (var i=0;i<frameHandlers.length;i++)
clearTimeout(frameHandlers[i]);
}
Expand Down Expand Up @@ -10380,6 +10384,13 @@ function render() {
});
}
}
if (lastStateChange) {
lastStateChange = false;
if (lastState) {
lastState.decor = currentState.decor;
lastState.items = currentState.items;
}
}
if (!lastState) lastState = currentState;

function renderFrame(frame) {
Expand Down

0 comments on commit a5e912a

Please sign in to comment.