Don't repaint unnecessary frames (when we lag)

This commit is contained in:
theKidOfArcrania 2017-02-27 00:23:02 +00:00
parent bdfc2984ee
commit 87054842de
2 changed files with 58 additions and 38 deletions

View File

@ -115,6 +115,7 @@ $(function() {
frame = data.frame;
});
var paintFrames = 0;
socket.on('notifyFrame', function(data, fn) {
if (timeout != undefined)
clearTimeout(timeout);
@ -127,7 +128,6 @@ $(function() {
}
frame++;
requestAnimationFrame(function() {
if (data.newPlayers)
{
data.newPlayers.forEach(function(p) {
@ -146,6 +146,8 @@ $(function() {
player.heading = val.heading;
});
paintFrames++;
requestAnimationFrame(function() {
paintLoop();
});
timeout = setTimeout(function() {
@ -165,8 +167,15 @@ $(function() {
var deadFrames = 0;
function paintLoop()
{
renderer.paint();
if (paintFrames === 0)
return;
while (paintFrames > 0)
{
renderer.update();
paintFrames--;
}
renderer.paint();
if (user.dead)
{
if (timeout)
@ -184,6 +193,7 @@ $(function() {
socket.disconnect();
deadFrames++;
paintFrames++;
requestAnimationFrame(paintLoop);
}
}

View File

@ -401,6 +401,7 @@ $(function() {
frame = data.frame;
});
var paintFrames = 0;
socket.on('notifyFrame', function(data, fn) {
if (timeout != undefined)
clearTimeout(timeout);
@ -413,7 +414,6 @@ $(function() {
}
frame++;
requestAnimationFrame(function() {
if (data.newPlayers)
{
data.newPlayers.forEach(function(p) {
@ -432,6 +432,8 @@ $(function() {
player.heading = val.heading;
});
paintFrames++;
requestAnimationFrame(function() {
paintLoop();
});
timeout = setTimeout(function() {
@ -451,8 +453,15 @@ $(function() {
var deadFrames = 0;
function paintLoop()
{
renderer.paint();
if (paintFrames === 0)
return;
while (paintFrames > 0)
{
renderer.update();
paintFrames--;
}
renderer.paint();
if (user.dead)
{
if (timeout)
@ -470,6 +479,7 @@ $(function() {
socket.disconnect();
deadFrames++;
paintFrames++;
requestAnimationFrame(paintLoop);
}
}