Skip to content

Commit

Permalink
Merge pull request #7066 from dwastberg/clock_stop_event
Browse files Browse the repository at this point in the history
Clock stop event
  • Loading branch information
Hannah authored Oct 23, 2018
2 parents 83c1ea4 + 30e359c commit a0a8ad4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 @@ -196,3 +196,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

0 comments on commit a0a8ad4

Please sign in to comment.