thedupdup

Members
  • Content Count

    22
  • Joined

  • Last visited

  1. What would that do?
  2. I see what you mean now. But if I add to timeElapsed like in the stackexchange example timeElapsed seems to increase a bunch (the opposite of what was happening before).
  3. The delta average (when the tab is active) is around 16 milliseconds, the updateFrequency has a minimum of 40 milliseconds. I think we are missing the point of the question though: things only go wrong after the tab is inactive for some time. If you just load the page the values are fine, but when you switch tabs the timeElapsed variable is decreased a bunch. So if I loaded the page then switched to a new tab for 3 minutes, timeElapsed would be around -3000, this is not supposed to happen however.
  4. The frequency by itself is not the problem, its when i switch tabs the timeElapsed variable decreases a bunch (im not sure what this is caused by).
  5. No, if I do it like the stack exchange example, the timeElapsed will increase a bunch when the tab is not active. And delta will always be smaller then update frequency.
  6. Can you explain to me a bit better what a phase locked loop is in this context?
  7. The variable timeElapsed is for a lerp function. I haven't been able to get good results in any other way. I based the lerp function on this: https://gamedev.stackexchange.com/questions/102483/client-interpolation-for-100-serverside-game
  8. I have a counter that subtracts the delta each from and adds the update frequency from the server (at the same frequency) . Here is a simplified version of my code: (function loop(now) { var now = Date.now(); delta = now - Time; Time = now; timeElapsed -= delta; if(frameAvg == null){ frameAvg = delta; } frameAvg = (frameAvg + delta) / 2; counter += frameAvg; if(counter > updateFrequency){ timeElapsed += updateFrequency; counter -= updateFrequency; } console.log(timeElapsed); requestAnimationFrame(loop) })(0); When I load the page and take a look at console it is fine, timeElapsed is around 300. But if I switch tabs for a few minutes timeElapsed will then be far into the negative numbers (around -3000 if you leave it for a few minutes). I don't understand what the problem is, how can I fix it?
  9. thedupdup

    My javascript websockets seem to be buffering incoming messages

    Yes, it will go from a steady 60 to a 0 unpredictably. But the problem is all the time stamps on the messages are normal.
  10. thedupdup

    My javascript websockets seem to be buffering incoming messages

    The server sends updates around 20 times per second, is this too much? I also tried just printing Date.now(), some times two of the printed dates were the same.
  11. thedupdup

    My javascript websockets seem to be buffering incoming messages

    I still get 0 when I use a server running on localhost, I don't think its packet loss.
  12. thedupdup

    My javascript websockets seem to be buffering incoming messages

    Okay, I have ruled this out by attaching timestamps from the server to the packets, the timestamp difference is very consistent. This would not be so if there was a missing packet.
  13. thedupdup

    My javascript websockets seem to be buffering incoming messages

    So its caused by packet loss? Basically all I need to to do is process the messages as soon as they are received, is this possible?
  14. Im receiving websocket messages on my webpage, and i'm trying to calculate the frequency at which they are received. I do this like so: let startTime = new Date(); ws.onmessage = function (evt) { prevData = recivedData; var receivedMsg = evt.data; recivedData = JSON.parse(receivedMsg); const endTime = new Date(); const timeDif = endTime - startTime; startTime = endTime; console.log(timeDif) } But it seems timeDif sometimes is 0, and I find this unlikely. People in other questions of mine have sad that its due to the websocket buffering incoming messages. How do I prevent this?
  15. Okay so in that code they subtract net_offset from current_time? Is net_offset just the time it takes the packet from the server to reach the client?