Guest User

Untitled

a guest
Jul 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. var rendering = false;
  2. var waiting_for_data = true;
  3. var data_update = false;
  4.  
  5. socket.on('update', function(data){
  6.  
  7. if(rendering)console.log("rendering");
  8.  
  9. data_update = true;
  10. game_data = data;
  11. data_update = false;
  12.  
  13. if(waiting_for_data){
  14. waiting_for_data = false;
  15. render();
  16. }
  17.  
  18.  
  19. });
  20.  
  21. window.requestAnimFrame = (function(){
  22. return window.requestAnimationFrame ||
  23. window.webkitRequestAnimationFrame ||
  24. window.mozRequestAnimationFrame ||
  25. window.oRequestAnimationFrame ||
  26. window.msRequestAnimationFrame ||
  27. function(/* function */ callback, /* DOMElement */ element){
  28. window.setTimeout(callback, 1000 / 60);
  29. };
  30. })();
  31.  
  32.  
  33. function render(){
  34.  
  35.  
  36. while(data_update){
  37. console.log("waiting" + data_update);
  38. }
  39.  
  40. if(game_data == null )console.log(game_data);
  41.  
  42. rendering = true;
  43. //mapa.draw(context, game_data.player_position);
  44. renderer.draw(game_data);
  45. rendering = false;
  46.  
  47. window.requestAnimFrame(render);
  48. }
  49.  
  50. }
Add Comment
Please, Sign In to add comment