From 05dcc77d6432b1995c4574b34c2cccadaa2949fc Mon Sep 17 00:00:00 2001 From: samreid Date: Mon, 6 Nov 2017 20:45:47 -0700 Subject: [PATCH] Moved makeEverythingSlow and makeRandomSlowness to initialize-globals, see https://github.com/phetsims/joist/issues/208 --- js/initialize-globals.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/js/initialize-globals.js b/js/initialize-globals.js index 0b0fa3260..39f95a8b0 100644 --- a/js/initialize-globals.js +++ b/js/initialize-globals.js @@ -416,6 +416,30 @@ // @public (writeable by phet-io) can be overwritten for replicable playback in phet-io. window.phet.chipper.randomSeed = phet.chipper.queryParameters.randomSeed; + /** + * Utility function to pause synchronously for the given number of milliseconds. + * @param {number} millis - amount of time to pause synchronously + */ + function sleep( millis ) { + var date = new Date(); + var curDate; + do { + curDate = new Date(); + } while ( curDate - date < millis ); + } + + /* + * These are used to make sure our sims still behave properly with an artificially higher load (so we can test what happens + * at 30fps, 5fps, etc). There tend to be bugs that only happen on less-powerful devices, and these functions facilitate + * testing a sim for robustness, and allowing others to reproduce slow-behavior bugs. + */ + window.phet.chipper.makeEverythingSlow = function() { + window.setInterval( function() { sleep( 64 ); }, 16 ); + }; + window.phet.chipper.makeRandomSlowness = function() { + window.setInterval( function() { sleep( Math.ceil( 100 + Math.random() * 200 ) ); }, Math.ceil( 100 + Math.random() * 200 ) ); + }; + /** * Enables or disables assertions in common libraries using query parameters. * There are two types of assertions: basic and slow. Enabling slow assertions will adversely impact performance.