For some odd reason, when I run the server locally, I get a stable 59fps. But when I upload to AWS, it gives me less than half the speed - to 24fps
I've also tried using setInterval(), but it does the same thing
Any ideas?
var previousTick = 0;
//Update LOBBIES
function gameLoop(){
var now = new Date().getTime();
if(previousTick + Math.floor(1000/settings.cps) < now){
previousTick = now;
checkCPS();
var pack = {
server: {
cps: cpsSave
}
};
for(var L in LOBBY_LIST){
var lobby = LOBBY_LIST[L].title;
pack.players = Player.update(lobby);
for(var S in SOCKET_LIST){
var user = SOCKET_LIST[S];
if(user.lobby == lobby){
user.emit('refresh', pack);
}
}
}
}
if(now - previousTick < Math.floor(1000/settings.cps) - 16){
setTimeout(gameLoop, 1);//sloppy timer
}
else {
setImmediate(gameLoop);//ultra accurate method
}
}
gameLoop();