Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clock stop event #7066

Merged
merged 6 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Change Log
* Added `OpenCageGeocoderService`, which provides geocoding via [OpenCage](https://opencagedata.com/). [#7015](https://github.com/AnalyticalGraphicsInc/cesium/pull/7015)
* Added ground atmosphere lighting in 3D. This can be toggled with `Globe.showGroundAtmosphere`. [6877](https://github.com/AnalyticalGraphicsInc/cesium/pull/6877)
* Added `Globe.nightFadeOutDistance` and `Globe.nightFadeInDistance` to configure when ground atmosphere night lighting fades in and out. [6877](https://github.com/AnalyticalGraphicsInc/cesium/pull/6877)
* Added `onStop` event to `Clock` that fires each time stopTime is reached. [#7066](https://github.com/AnalyticalGraphicsInc/cesium/pull/7066)

##### Fixes :wrench:
* Fixed picking for overlapping translucent primitives. [#7039](https://github.com/AnalyticalGraphicsInc/cesium/pull/7039)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Hannah Bollar](https://github.com/hanbollar)
* [Felix Palmer](https://github.com/felixpalmer)
* [Cedric Le Roux](https://github.com/cleroux)
* [Dag Wästberg](https://github.com/dwastberg)
7 changes: 7 additions & 0 deletions Source/Core/Clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ define([
* @type {Event}
*/
this.onTick = new Event();
/**
* An {@link Event} that is fired whenever {@link Clock#stopTime} is reached.
* @type {Event}
*/
this.onStop = new Event();

this._currentTime = undefined;
this._multiplier = undefined;
Expand Down Expand Up @@ -290,13 +295,15 @@ define([
currentTime = JulianDate.clone(startTime, currentTime);
} else if (JulianDate.greaterThan(currentTime, stopTime)) {
currentTime = JulianDate.clone(stopTime, currentTime);
this.onStop.raiseEvent(this);
}
} else if (clockRange === ClockRange.LOOP_STOP) {
if (JulianDate.lessThan(currentTime, startTime)) {
currentTime = JulianDate.clone(startTime, currentTime);
}
while (JulianDate.greaterThan(currentTime, stopTime)) {
currentTime = JulianDate.addSeconds(startTime, JulianDate.secondsDifference(currentTime, stopTime), currentTime);
this.onStop.raiseEvent(this);
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions Specs/Core/ClockSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,46 @@ defineSuite([
expect(start).toEqual(clock.currentTime);
});

it('fires onEnd event when endTime is reached and clock range is CLAMPED', function() {
var start = new JulianDate(0);
var stop = new JulianDate(1);
var currentTime = stop;
var multiplier = 100.0;
var clock = new Clock({
startTime : start,
stopTime : stop,
currentTime : currentTime,
clockStep : ClockStep.TICK_DEPENDENT,
multiplier : multiplier,
clockRange : ClockRange.CLAMPED,
shouldAnimate : true
});
var onStopSpy = jasmine.createSpy('event');
clock.onStop.addEventListener(onStopSpy);
clock.tick();
expect(onStopSpy).toHaveBeenCalled();
});

it('fires onEnd event when endTime is reached and clock range is LOOP_STOP', function() {
var start = new JulianDate(0);
var stop = new JulianDate(1);
var currentTime = stop;
var multiplier = 100.0;
var clock = new Clock({
startTime : start,
stopTime : stop,
currentTime : currentTime,
clockStep : ClockStep.TICK_DEPENDENT,
multiplier : multiplier,
clockRange : ClockRange.LOOP_STOP,
shouldAnimate : true
});
var onStopSpy = jasmine.createSpy('event');
clock.onStop.addEventListener(onStopSpy);
clock.tick();
expect(onStopSpy).toHaveBeenCalled();
});

describe('SYSTEM_CLOCK modes', function() {
var baseDate = new Date(2016, 6, 7);

Expand Down