Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
import defined from "../Core/defined.js";
|
|
|
|
|
import destroyObject from "../Core/destroyObject.js";
|
|
|
|
|
import DeveloperError from "../Core/DeveloperError.js";
|
|
|
|
|
import Event from "../Core/Event.js";
|
|
|
|
|
import getTimestamp from "../Core/getTimestamp.js";
|
|
|
|
|
import TimeConstants from "../Core/TimeConstants.js";
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
/**
|
|
|
|
|
* Monitors the frame rate (frames per second) in a {@link Scene} and raises an event if the frame rate is
|
|
|
|
|
* lower than a threshold. Later, if the frame rate returns to the required level, a separate event is raised.
|
|
|
|
|
* To avoid creating multiple FrameRateMonitors for a single {@link Scene}, use {@link FrameRateMonitor.fromScene}
|
|
|
|
|
* instead of constructing an instance explicitly.
|
|
|
|
|
*
|
|
|
|
|
* @alias FrameRateMonitor
|
|
|
|
|
* @constructor
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {object} [options] Object with the following properties:
|
2014-06-10 23:55:29 +08:00
|
|
|
* @param {Scene} options.scene The Scene instance for which to monitor performance.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [options.samplingWindow=5.0] The length of the sliding window over which to compute the average frame rate, in seconds.
|
|
|
|
|
* @param {number} [options.quietPeriod=2.0] The length of time to wait at startup and each time the page becomes visible (i.e. when the user
|
2014-06-11 00:50:49 +08:00
|
|
|
* switches back to the tab) before starting to measure performance, in seconds.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [options.warmupPeriod=5.0] The length of the warmup period, in seconds. During the warmup period, a separate
|
2014-05-09 09:44:49 +08:00
|
|
|
* (usually lower) frame rate is required.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [options.minimumFrameRateDuringWarmup=4] The minimum frames-per-second that are required for acceptable performance during
|
2014-05-09 09:44:49 +08:00
|
|
|
* the warmup period. If the frame rate averages less than this during any samplingWindow during the warmupPeriod, the
|
|
|
|
|
* lowFrameRate event will be raised and the page will redirect to the redirectOnLowFrameRateUrl, if any.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [options.minimumFrameRateAfterWarmup=8] The minimum frames-per-second that are required for acceptable performance after
|
2014-05-09 09:44:49 +08:00
|
|
|
* the end of the warmup period. If the frame rate averages less than this during any samplingWindow after the warmupPeriod, the
|
|
|
|
|
* lowFrameRate event will be raised and the page will redirect to the redirectOnLowFrameRateUrl, if any.
|
|
|
|
|
*/
|
2015-12-12 09:31:44 +08:00
|
|
|
function FrameRateMonitor(options) {
|
2014-05-09 09:44:49 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2014-06-10 23:55:29 +08:00
|
|
|
if (!defined(options) || !defined(options.scene)) {
|
|
|
|
|
throw new DeveloperError("options.scene is required.");
|
2014-05-09 09:44:49 +08:00
|
|
|
}
|
|
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-06-10 23:55:29 +08:00
|
|
|
this._scene = options.scene;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
/**
|
2014-06-11 00:50:49 +08:00
|
|
|
* Gets or sets the length of the sliding window over which to compute the average frame rate, in seconds.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2014-05-09 09:44:49 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.samplingWindow =
|
|
|
|
|
options.samplingWindow ?? FrameRateMonitor.defaultSettings.samplingWindow;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
/**
|
|
|
|
|
* Gets or sets the length of time to wait at startup and each time the page becomes visible (i.e. when the user
|
2014-06-11 00:50:49 +08:00
|
|
|
* switches back to the tab) before starting to measure performance, in seconds.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2014-05-09 09:44:49 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.quietPeriod =
|
|
|
|
|
options.quietPeriod ?? FrameRateMonitor.defaultSettings.quietPeriod;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
/**
|
|
|
|
|
* Gets or sets the length of the warmup period, in seconds. During the warmup period, a separate
|
|
|
|
|
* (usually lower) frame rate is required.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2014-05-09 09:44:49 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.warmupPeriod =
|
|
|
|
|
options.warmupPeriod ?? FrameRateMonitor.defaultSettings.warmupPeriod;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
/**
|
|
|
|
|
* Gets or sets the minimum frames-per-second that are required for acceptable performance during
|
|
|
|
|
* the warmup period. If the frame rate averages less than this during any <code>samplingWindow</code> during the <code>warmupPeriod</code>, the
|
|
|
|
|
* <code>lowFrameRate</code> event will be raised and the page will redirect to the <code>redirectOnLowFrameRateUrl</code>, if any.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2014-05-09 09:44:49 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.minimumFrameRateDuringWarmup =
|
|
|
|
|
options.minimumFrameRateDuringWarmup ??
|
|
|
|
|
FrameRateMonitor.defaultSettings.minimumFrameRateDuringWarmup;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
/**
|
2014-05-09 09:44:49 +08:00
|
|
|
* Gets or sets the minimum frames-per-second that are required for acceptable performance after
|
|
|
|
|
* the end of the warmup period. If the frame rate averages less than this during any <code>samplingWindow</code> after the <code>warmupPeriod</code>, the
|
2018-01-05 01:08:04 +08:00
|
|
|
* <code>lowFrameRate</code> event will be raised and the page will redirect to the <code>redirectOnLowFrameRateUrl</code>, if any.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2025-03-04 03:03:53 +08:00
|
|
|
this.minimumFrameRateAfterWarmup =
|
|
|
|
|
options.minimumFrameRateAfterWarmup ??
|
|
|
|
|
FrameRateMonitor.defaultSettings.minimumFrameRateAfterWarmup;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2018-01-05 01:08:04 +08:00
|
|
|
this._lowFrameRate = new Event();
|
2016-03-02 00:06:17 +08:00
|
|
|
this._nominalFrameRate = new Event();
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-03-02 00:06:17 +08:00
|
|
|
this._frameTimes = [];
|
|
|
|
|
this._needsQuietPeriod = true;
|
|
|
|
|
this._quietPeriodEndTime = 0.0;
|
|
|
|
|
this._warmupPeriodEndTime = 0.0;
|
|
|
|
|
this._frameRateIsLow = false;
|
2014-05-16 04:38:52 +08:00
|
|
|
this._lastFramesPerSecond = undefined;
|
|
|
|
|
this._pauseCount = 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
const that = this;
|
|
|
|
|
this._preUpdateRemoveListener = this._scene.preUpdate.addEventListener(
|
|
|
|
|
function (scene, time) {
|
|
|
|
|
update(that, time);
|
2015-12-12 09:31:44 +08:00
|
|
|
},
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
this._hiddenPropertyName =
|
|
|
|
|
document.hidden !== undefined
|
2020-04-17 08:31:36 +08:00
|
|
|
? "hidden"
|
2014-05-09 09:44:49 +08:00
|
|
|
: document.mozHidden !== undefined
|
|
|
|
|
? "mozHidden"
|
|
|
|
|
: document.msHidden !== undefined
|
|
|
|
|
? "msHidden"
|
|
|
|
|
: document.webkitHidden !== undefined
|
|
|
|
|
? "webkitHidden"
|
|
|
|
|
: undefined;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
const visibilityChangeEventName =
|
|
|
|
|
document.hidden !== undefined
|
2016-03-02 00:06:17 +08:00
|
|
|
? "visibilitychange"
|
2014-05-09 09:44:49 +08:00
|
|
|
: document.mozHidden !== undefined
|
|
|
|
|
? "mozvisibilitychange"
|
|
|
|
|
: document.msHidden !== undefined
|
2016-03-02 00:06:17 +08:00
|
|
|
? "msvisibilitychange"
|
2014-05-09 09:44:49 +08:00
|
|
|
: document.webkitHidden !== undefined
|
2016-03-02 00:06:17 +08:00
|
|
|
? "webkitvisibilitychange"
|
2014-05-09 09:44:49 +08:00
|
|
|
: undefined;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
function visibilityChangeListener() {
|
|
|
|
|
visibilityChanged(that);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
this._visibilityChangeRemoveListener = undefined;
|
|
|
|
|
if (defined(visibilityChangeEventName)) {
|
|
|
|
|
document.addEventListener(
|
|
|
|
|
visibilityChangeEventName,
|
|
|
|
|
visibilityChangeListener,
|
2020-04-17 08:31:36 +08:00
|
|
|
false,
|
|
|
|
|
);
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
this._visibilityChangeRemoveListener = function () {
|
|
|
|
|
document.removeEventListener(
|
|
|
|
|
visibilityChangeEventName,
|
2014-05-16 04:38:52 +08:00
|
|
|
visibilityChangeListener,
|
2020-04-17 08:31:36 +08:00
|
|
|
false,
|
2014-05-09 09:44:49 +08:00
|
|
|
);
|
|
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
/**
|
|
|
|
|
* The default frame rate monitoring settings. These settings are used when {@link FrameRateMonitor.fromScene}
|
|
|
|
|
* needs to create a new frame rate monitor, and for any settings that are not passed to the
|
|
|
|
|
* {@link FrameRateMonitor} constructor.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2014-05-09 09:44:49 +08:00
|
|
|
* @memberof FrameRateMonitor
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {object}
|
2014-05-09 09:44:49 +08:00
|
|
|
*/
|
|
|
|
|
FrameRateMonitor.defaultSettings = {
|
|
|
|
|
samplingWindow: 5.0,
|
|
|
|
|
quietPeriod: 2.0,
|
2014-06-11 00:50:49 +08:00
|
|
|
warmupPeriod: 5.0,
|
2014-05-09 09:44:49 +08:00
|
|
|
minimumFrameRateDuringWarmup: 4,
|
|
|
|
|
minimumFrameRateAfterWarmup: 8,
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-09 09:44:49 +08:00
|
|
|
* Gets the {@link FrameRateMonitor} for a given scene. If the scene does not yet have
|
|
|
|
|
* a {@link FrameRateMonitor}, one is created with the {@link FrameRateMonitor.defaultSettings}.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2014-05-09 09:44:49 +08:00
|
|
|
* @param {Scene} scene The scene for which to get the {@link FrameRateMonitor}.
|
|
|
|
|
* @returns {FrameRateMonitor} The scene's {@link FrameRateMonitor}.
|
|
|
|
|
*/
|
|
|
|
|
FrameRateMonitor.fromScene = function (scene) {
|
2014-05-16 04:38:52 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
if (!defined(scene)) {
|
|
|
|
|
throw new DeveloperError("scene is required.");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-05-16 04:38:52 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
if (
|
2014-05-16 04:38:52 +08:00
|
|
|
!defined(scene._frameRateMonitor) ||
|
|
|
|
|
scene._frameRateMonitor.isDestroyed()
|
2020-04-17 08:31:36 +08:00
|
|
|
) {
|
2014-05-16 04:38:52 +08:00
|
|
|
scene._frameRateMonitor = new FrameRateMonitor({
|
|
|
|
|
scene: scene,
|
2014-05-09 09:44:49 +08:00
|
|
|
});
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-16 05:10:45 +08:00
|
|
|
return scene._frameRateMonitor;
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
2014-05-16 05:10:45 +08:00
|
|
|
Object.defineProperties(FrameRateMonitor.prototype, {
|
2020-04-17 08:31:36 +08:00
|
|
|
/**
|
2014-05-16 05:10:45 +08:00
|
|
|
* Gets the {@link Scene} instance for which to monitor performance.
|
|
|
|
|
* @memberof FrameRateMonitor.prototype
|
|
|
|
|
* @type {Scene}
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
|
|
|
|
scene: {
|
2014-05-16 05:10:45 +08:00
|
|
|
get: function () {
|
|
|
|
|
return this._scene;
|
2020-04-17 08:31:36 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-16 05:10:45 +08:00
|
|
|
* Gets the event that is raised when a low frame rate is detected. The function will be passed
|
|
|
|
|
* the {@link Scene} instance as its first parameter and the average number of frames per second
|
2014-05-16 04:38:52 +08:00
|
|
|
* over the sampling window as its second parameter.
|
2014-05-16 05:10:45 +08:00
|
|
|
* @memberof FrameRateMonitor.prototype
|
2014-05-09 09:44:49 +08:00
|
|
|
* @type {Event}
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2014-05-16 04:38:52 +08:00
|
|
|
lowFrameRate: {
|
2014-05-09 09:44:49 +08:00
|
|
|
get: function () {
|
|
|
|
|
return this._lowFrameRate;
|
2020-04-17 08:31:36 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-16 05:10:45 +08:00
|
|
|
* Gets the event that is raised when the frame rate returns to a normal level after having been low.
|
|
|
|
|
* The function will be passed the {@link Scene} instance as its first parameter and the average
|
|
|
|
|
* number of frames per second over the sampling window as its second parameter.
|
|
|
|
|
* @memberof FrameRateMonitor.prototype
|
|
|
|
|
* @type {Event}
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2014-05-16 05:10:45 +08:00
|
|
|
nominalFrameRate: {
|
|
|
|
|
get: function () {
|
|
|
|
|
return this._nominalFrameRate;
|
|
|
|
|
},
|
2020-04-17 08:31:36 +08:00
|
|
|
},
|
|
|
|
|
|
2014-05-16 05:10:45 +08:00
|
|
|
/**
|
|
|
|
|
* Gets the most recently computed average frames-per-second over the last <code>samplingWindow</code>.
|
|
|
|
|
* This property may be undefined if the frame rate has not been computed.
|
|
|
|
|
* @memberof FrameRateMonitor.prototype
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2014-05-16 05:10:45 +08:00
|
|
|
lastFramesPerSecond: {
|
|
|
|
|
get: function () {
|
|
|
|
|
return this._lastFramesPerSecond;
|
2020-04-17 08:31:36 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-16 05:10:45 +08:00
|
|
|
* Pauses monitoring of the frame rate. To resume monitoring, {@link FrameRateMonitor#unpause}
|
|
|
|
|
* must be called once for each time this function is called.
|
|
|
|
|
* @memberof FrameRateMonitor
|
|
|
|
|
*/
|
|
|
|
|
FrameRateMonitor.prototype.pause = function () {
|
|
|
|
|
++this._pauseCount;
|
|
|
|
|
if (this._pauseCount === 1) {
|
|
|
|
|
this._frameTimes.length = 0;
|
|
|
|
|
this._lastFramesPerSecond = undefined;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-16 05:10:45 +08:00
|
|
|
* Resumes monitoring of the frame rate. If {@link FrameRateMonitor#pause} was called
|
|
|
|
|
* multiple times, this function must be called the same number of times in order to
|
|
|
|
|
* actually resume monitoring.
|
|
|
|
|
* @memberof FrameRateMonitor
|
|
|
|
|
*/
|
2014-05-09 09:44:49 +08:00
|
|
|
FrameRateMonitor.prototype.unpause = function () {
|
|
|
|
|
--this._pauseCount;
|
2014-05-16 05:10:45 +08:00
|
|
|
if (this._pauseCount <= 0) {
|
2014-05-09 09:44:49 +08:00
|
|
|
this._pauseCount = 0;
|
|
|
|
|
this._needsQuietPeriod = true;
|
|
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
2014-05-16 05:10:45 +08:00
|
|
|
/**
|
|
|
|
|
* Returns true if this object was destroyed; otherwise, false.
|
|
|
|
|
* <br /><br />
|
|
|
|
|
* If this object was destroyed, it should not be used; calling any function other than
|
|
|
|
|
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
|
|
|
|
|
*
|
|
|
|
|
* @memberof FrameRateMonitor
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {boolean} True if this object was destroyed; otherwise, false.
|
2014-05-16 05:10:45 +08:00
|
|
|
*
|
|
|
|
|
* @see FrameRateMonitor#destroy
|
|
|
|
|
*/
|
2014-05-09 09:44:49 +08:00
|
|
|
FrameRateMonitor.prototype.isDestroyed = function () {
|
2018-01-05 01:08:04 +08:00
|
|
|
return false;
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-16 04:38:52 +08:00
|
|
|
* Unsubscribes this instance from all events it is listening to.
|
|
|
|
|
* Once an object is destroyed, it should not be used; calling any function other than
|
|
|
|
|
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
|
|
|
|
|
* assign the return value (<code>undefined</code>) to the object as done in the example.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2014-05-16 04:38:52 +08:00
|
|
|
* @memberof FrameRateMonitor
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2014-05-09 09:44:49 +08:00
|
|
|
* @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2014-05-09 09:44:49 +08:00
|
|
|
* @see FrameRateMonitor#isDestroyed
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2014-05-16 04:38:52 +08:00
|
|
|
FrameRateMonitor.prototype.destroy = function () {
|
|
|
|
|
this._preUpdateRemoveListener();
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-16 05:10:45 +08:00
|
|
|
if (defined(this._visibilityChangeRemoveListener)) {
|
2014-05-09 09:44:49 +08:00
|
|
|
this._visibilityChangeRemoveListener();
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
return destroyObject(this);
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
function update(monitor, time) {
|
2014-05-16 05:10:45 +08:00
|
|
|
if (monitor._pauseCount > 0) {
|
2020-04-17 08:31:36 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
const timeStamp = getTimestamp();
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
if (monitor._needsQuietPeriod) {
|
|
|
|
|
monitor._needsQuietPeriod = false;
|
|
|
|
|
monitor._frameTimes.length = 0;
|
2014-06-11 00:50:49 +08:00
|
|
|
monitor._quietPeriodEndTime =
|
|
|
|
|
timeStamp + monitor.quietPeriod / TimeConstants.SECONDS_PER_MILLISECOND;
|
|
|
|
|
monitor._warmupPeriodEndTime =
|
|
|
|
|
monitor._quietPeriodEndTime +
|
|
|
|
|
(monitor.warmupPeriod + monitor.samplingWindow) /
|
|
|
|
|
TimeConstants.SECONDS_PER_MILLISECOND;
|
2014-05-16 04:38:52 +08:00
|
|
|
} else if (timeStamp >= monitor._quietPeriodEndTime) {
|
|
|
|
|
monitor._frameTimes.push(timeStamp);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
const beginningOfWindow =
|
|
|
|
|
timeStamp -
|
|
|
|
|
monitor.samplingWindow / TimeConstants.SECONDS_PER_MILLISECOND;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
if (
|
|
|
|
|
monitor._frameTimes.length >= 2 &&
|
|
|
|
|
monitor._frameTimes[0] <= beginningOfWindow
|
2020-04-17 08:31:36 +08:00
|
|
|
) {
|
|
|
|
|
while (
|
2014-05-16 04:38:52 +08:00
|
|
|
monitor._frameTimes.length >= 2 &&
|
|
|
|
|
monitor._frameTimes[1] < beginningOfWindow
|
2020-04-17 08:31:36 +08:00
|
|
|
) {
|
2014-05-16 04:38:52 +08:00
|
|
|
monitor._frameTimes.shift();
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
const averageTimeBetweenFrames =
|
|
|
|
|
(timeStamp - monitor._frameTimes[0]) / (monitor._frameTimes.length - 1);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
monitor._lastFramesPerSecond = 1000.0 / averageTimeBetweenFrames;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-09 09:44:49 +08:00
|
|
|
const maximumFrameTime =
|
2020-04-17 08:31:36 +08:00
|
|
|
1000.0 /
|
2014-05-16 04:38:52 +08:00
|
|
|
(timeStamp > monitor._warmupPeriodEndTime
|
2014-05-09 09:44:49 +08:00
|
|
|
? monitor.minimumFrameRateAfterWarmup
|
2014-05-16 04:38:52 +08:00
|
|
|
: monitor.minimumFrameRateDuringWarmup);
|
2014-05-09 09:44:49 +08:00
|
|
|
if (averageTimeBetweenFrames > maximumFrameTime) {
|
2014-05-16 04:38:52 +08:00
|
|
|
if (!monitor._frameRateIsLow) {
|
|
|
|
|
monitor._frameRateIsLow = true;
|
|
|
|
|
monitor._needsQuietPeriod = true;
|
|
|
|
|
monitor.lowFrameRate.raiseEvent(
|
|
|
|
|
monitor.scene,
|
|
|
|
|
monitor._lastFramesPerSecond,
|
2014-05-16 05:10:45 +08:00
|
|
|
);
|
2014-05-09 09:44:49 +08:00
|
|
|
}
|
2014-05-16 04:38:52 +08:00
|
|
|
} else if (monitor._frameRateIsLow) {
|
|
|
|
|
monitor._frameRateIsLow = false;
|
|
|
|
|
monitor._needsQuietPeriod = true;
|
2014-05-09 09:44:49 +08:00
|
|
|
monitor.nominalFrameRate.raiseEvent(
|
|
|
|
|
monitor.scene,
|
2014-05-16 05:10:45 +08:00
|
|
|
monitor._lastFramesPerSecond,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
|
|
|
|
}
|
2014-05-09 09:44:49 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 04:38:52 +08:00
|
|
|
function visibilityChanged(monitor) {
|
|
|
|
|
if (document[monitor._hiddenPropertyName]) {
|
2014-05-16 05:10:45 +08:00
|
|
|
monitor.pause();
|
2020-04-17 08:31:36 +08:00
|
|
|
} else {
|
2014-05-16 05:10:45 +08:00
|
|
|
monitor.unpause();
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
}
|
Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
export default FrameRateMonitor;
|