| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 return window.webkitRequestAnimationFrame || | 35 return window.webkitRequestAnimationFrame || |
| 36 window.mozRequestAnimationFrame || | 36 window.mozRequestAnimationFrame || |
| 37 window.oRequestAnimationFrame || | 37 window.oRequestAnimationFrame || |
| 38 window.msRequestAnimationFrame || | 38 window.msRequestAnimationFrame || |
| 39 function(callback, element) { | 39 function(callback, element) { |
| 40 window.setTimeout( callback, 1000 / 60 ); | 40 window.setTimeout( callback, 1000 / 60 ); |
| 41 }; | 41 }; |
| 42 } )(); | 42 } )(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 | |
| 46 | |
| 47 | |
| 48 var kNPoints = 8000; | 45 var kNPoints = 8000; |
| 49 var kNModifications = 20; | 46 var kNModifications = 20; |
| 50 var kNVisiblePoints = 200; | 47 var kNVisiblePoints = 200; |
| 51 var kDecaySpeed = 20; | 48 var kDecaySpeed = 20; |
| 52 | 49 |
| 53 var kPointRadius = 4; | 50 var kPointRadius = 4; |
| 54 var kInitialLifeForce = 100; | 51 var kInitialLifeForce = 100; |
| 55 | 52 |
| 56 var livePoints = void 0; | 53 var livePoints = void 0; |
| 57 var dyingPoints = void 0; | 54 var dyingPoints = void 0; |
| 58 var scene = void 0; | 55 var scene = void 0; |
| 59 var renderingStartTime = void 0; | 56 var renderingStartTime = void 0; |
| 60 var omitFrameDueToVisibilityChange = false; | |
| 61 var scene = void 0; | 57 var scene = void 0; |
| 62 var pausePlot = void 0; | 58 var pausePlot = void 0; |
| 63 var splayTree = void 0; | 59 var splayTree = void 0; |
| 64 | 60 |
| 65 handleVisibilityChange(); | |
| 66 | |
| 67 function handleVisibilityChange() { | |
| 68 console.log("visibility change"); | |
| 69 omitFrameDueToVisibilityChange = true; | |
| 70 document.addEventListener("webkitvisibilitychange", handleVisibilityChange); | |
| 71 document.addEventListener("msvisibilitychange", handleVisibilityChange); | |
| 72 document.addEventListener("mozvisibilitychange", handleVisibilityChange); | |
| 73 document.addEventListener("visibilitychange", handleVisibilityChange); | |
| 74 } | |
| 75 | |
| 76 | 61 |
| 77 function Point(x, y, z, payload) { | 62 function Point(x, y, z, payload) { |
| 78 this.x = x; | 63 this.x = x; |
| 79 this.y = y; | 64 this.y = y; |
| 80 this.z = z; | 65 this.z = z; |
| 81 | 66 |
| 82 this.next = null; | 67 this.next = null; |
| 83 this.prev = null; | 68 this.prev = null; |
| 84 this.payload = payload; | 69 this.payload = payload; |
| 85 this.lifeForce = kInitialLifeForce; | 70 this.lifeForce = kInitialLifeForce; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 function render() { | 346 function render() { |
| 362 if (typeof renderingStartTime === 'undefined') { | 347 if (typeof renderingStartTime === 'undefined') { |
| 363 renderingStartTime = Date.now(); | 348 renderingStartTime = Date.now(); |
| 364 } | 349 } |
| 365 | 350 |
| 366 ModifyPointsSet(); | 351 ModifyPointsSet(); |
| 367 | 352 |
| 368 scene.draw(); | 353 scene.draw(); |
| 369 | 354 |
| 370 var renderingEndTime = Date.now(); | 355 var renderingEndTime = Date.now(); |
| 371 if (!omitFrameDueToVisibilityChange) { | 356 var pause = renderingEndTime - renderingStartTime; |
| 372 var pause = renderingEndTime - renderingStartTime; | 357 pausePlot.addPause(pause); |
| 373 pausePlot.addPause(pause); | |
| 374 } | |
| 375 renderingStartTime = renderingEndTime; | 358 renderingStartTime = renderingEndTime; |
| 376 omitFrameDueToVisibilityChange = false; | |
| 377 | 359 |
| 378 pausePlot.draw(); | 360 pausePlot.draw(); |
| 379 | 361 |
| 380 div.innerHTML = | 362 div.innerHTML = |
| 381 livePoints.count + "/" + dyingPoints.count + " " + | 363 livePoints.count + "/" + dyingPoints.count + " " + |
| 382 pause + "(max = " + pausePlot.maxPause + ") ms" ; | 364 pause + "(max = " + pausePlot.maxPause + ") ms" ; |
| 383 | 365 |
| 384 // Schedule next frame. | 366 // Schedule next frame. |
| 385 requestAnimationFrame(render); | 367 requestAnimationFrame(render); |
| 386 } | 368 } |
| 387 | 369 |
| 388 | 370 |
| 389 function init() { | 371 function init() { |
| 390 livePoints = new PointsList; | 372 livePoints = new PointsList; |
| 391 dyingPoints = new PointsList; | 373 dyingPoints = new PointsList; |
| 392 | 374 |
| 393 splayTree = new SplayTree(); | 375 splayTree = new SplayTree(); |
| 394 | 376 |
| 395 scene = new Scene(640, 480); | 377 scene = new Scene(640, 480); |
| 396 | 378 |
| 397 div = document.createElement("div"); | 379 div = document.createElement("div"); |
| 398 document.body.appendChild(div); | 380 document.body.appendChild(div); |
| 399 | 381 |
| 400 pausePlot = new PausePlot(480, 240, 160); | 382 pausePlot = new PausePlot(480, 240, 160); |
| 401 } | 383 } |
| 402 | 384 |
| 403 | 385 |
| 404 init(); | 386 init(); |
| 405 render(); | 387 render(); |
| OLD | NEW |