Skip to content

Commit

Permalink
Merge pull request #4007 from AnalyticalGraphicsInc/clockRealtimeMode
Browse files Browse the repository at this point in the history
Move logic for real-time mode (SYSTEM_CLOCK) into Clock itself.
  • Loading branch information
mramato authored Jun 10, 2016
2 parents d238e98 + 8176ef2 commit e0dc8ef
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 408 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change Log
* Fix some large polygon triangulations. [#2788](https://github.com/AnalyticalGraphicsInc/cesium/issues/2788)
* Improved performance and accuracy of polygon triangulation by using the [earcut](https://github.com/mapbox/earcut) library. Loading a GeoJSON with polygons for each country was 2x faster.
* Added CZML support for Box, Corridor and Cylinder
* `Clock` now keeps its configuration settings self-consistent. Previously, this was done by `AnimationViewModel` and could become inconsistent in certain cases. [#4007](https://github.com/AnalyticalGraphicsInc/cesium/pull/4007)

### 1.22 - 2016-06-01

Expand Down
248 changes: 176 additions & 72 deletions Source/Core/Clock.js

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions Source/DataSources/DataSourceClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ define([
'use strict';

/**
* Represents CZML document-level clock settings.
* Represents desired clock settings for a particular {@link DataSource}. These settings may be applied
* to the {@link Clock} when the DataSource is loaded.
*
* @alias DataSourceClock
* @constructor
Expand Down Expand Up @@ -50,45 +51,48 @@ define([
},

/**
* Gets or sets the start time of the clock to use when looping or clamped.
* Gets or sets the desired start time of the clock.
* See {@link Clock#startTime}.
* @memberof DataSourceClock.prototype
* @type {JulianDate}
*/
startTime : createRawPropertyDescriptor('startTime'),

/**
* Gets or sets the stop time of the clock to use when looping or clamped.
* Gets or sets the desired stop time of the clock.
* See {@link Clock#stopTime}.
* @memberof DataSourceClock.prototype
* @type {JulianDate}
*/
stopTime : createRawPropertyDescriptor('stopTime'),

/**
* Gets or sets the initial time to use when switching to this clock.
* Gets or sets the desired current time when this data source is loaded.
* See {@link Clock#currentTime}.
* @memberof DataSourceClock.prototype
* @type {JulianDate}
*/
currentTime : createRawPropertyDescriptor('currentTime'),

/**
* Gets or sets how the clock should behave when <code>startTime</code> or <code>stopTime</code> is reached.
* Gets or sets the desired clock range setting.
* See {@link Clock#clockRange}.
* @memberof DataSourceClock.prototype
* @type {ClockRange}
*/
clockRange : createRawPropertyDescriptor('clockRange'),

/**
* Gets or sets if clock advancement is frame dependent or system clock dependent.
* Gets or sets the desired clock step setting.
* See {@link Clock#clockStep}.
* @memberof DataSourceClock.prototype
* @type {ClockStep}
*/
clockStep : createRawPropertyDescriptor('clockStep'),

/**
* Gets or sets how much time advances with each tick, negative values allow for advancing backwards.
* If <code>clockStep</code> is set to ClockStep.TICK_DEPENDENT this is the number of seconds to advance.
* If <code>clockStep</code> is set to ClockStep.SYSTEM_CLOCK_MULTIPLIER this value is multiplied by the
* elapsed system time since the last call to tick.
* Gets or sets the desired clock multiplier.
* See {@link Clock#multiplier}.
* @memberof DataSourceClock.prototype
* @type {Number}
*/
Expand Down Expand Up @@ -163,10 +167,10 @@ define([
}
result.startTime = this.startTime;
result.stopTime = this.stopTime;
result.currentTime = this.currentTime;
result.clockRange = this.clockRange;
result.clockStep = this.clockStep;
result.multiplier = this.multiplier;
result.currentTime = this.currentTime;
result.clockStep = this.clockStep;
return result;
};

Expand Down
26 changes: 3 additions & 23 deletions Source/Widgets/Animation/AnimationViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ define([
var realtimeShuttleRingAngle = 15;
var maxShuttleRingAngle = 105;

function cancelRealtime(clockViewModel) {
if (clockViewModel.clockStep === ClockStep.SYSTEM_CLOCK) {
clockViewModel.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
clockViewModel.multiplier = 1;
}
}

function unpause(clockViewModel) {
cancelRealtime(clockViewModel);
clockViewModel.shouldAnimate = true;
}

function numberComparator(left, right) {
return left - right;
}
Expand Down Expand Up @@ -284,10 +272,9 @@ define([
var pauseCommand = createCommand(function() {
var clockViewModel = that._clockViewModel;
if (clockViewModel.shouldAnimate) {
cancelRealtime(clockViewModel);
clockViewModel.shouldAnimate = false;
} else if (that._canAnimate) {
unpause(clockViewModel);
clockViewModel.shouldAnimate = true;
}
});

Expand All @@ -300,7 +287,6 @@ define([

var playReverseCommand = createCommand(function() {
var clockViewModel = that._clockViewModel;
cancelRealtime(clockViewModel);
var multiplier = clockViewModel.multiplier;
if (multiplier > 0) {
clockViewModel.multiplier = -multiplier;
Expand All @@ -317,7 +303,6 @@ define([

var playForwardCommand = createCommand(function() {
var clockViewModel = that._clockViewModel;
cancelRealtime(clockViewModel);
var multiplier = clockViewModel.multiplier;
if (multiplier < 0) {
clockViewModel.multiplier = -multiplier;
Expand All @@ -333,15 +318,12 @@ define([
});

var playRealtimeCommand = createCommand(function() {
var clockViewModel = that._clockViewModel;
clockViewModel.clockStep = ClockStep.SYSTEM_CLOCK;
clockViewModel.multiplier = 1.0;
clockViewModel.shouldAnimate = true;
that._clockViewModel.clockStep = ClockStep.SYSTEM_CLOCK;
}, knockout.getObservable(this, '_isSystemTimeAvailable'));

this._playRealtimeViewModel = new ToggleButtonViewModel(playRealtimeCommand, {
toggled : knockout.computed(function() {
return clockViewModel.shouldAnimate && clockViewModel.clockStep === ClockStep.SYSTEM_CLOCK;
return clockViewModel.clockStep === ClockStep.SYSTEM_CLOCK;
}),
tooltip : knockout.computed(function() {
return that._isSystemTimeAvailable ? 'Today (real-time)' : 'Current time not in range';
Expand All @@ -350,7 +332,6 @@ define([

this._slower = createCommand(function() {
var clockViewModel = that._clockViewModel;
cancelRealtime(clockViewModel);
var shuttleRingTicks = that._allShuttleRingTicks;
var multiplier = clockViewModel.multiplier;
var index = getTypicalMultiplierIndex(multiplier, shuttleRingTicks) - 1;
Expand All @@ -361,7 +342,6 @@ define([

this._faster = createCommand(function() {
var clockViewModel = that._clockViewModel;
cancelRealtime(clockViewModel);
var shuttleRingTicks = that._allShuttleRingTicks;
var multiplier = clockViewModel.multiplier;
var index = getTypicalMultiplierIndex(multiplier, shuttleRingTicks) + 1;
Expand Down
Loading

0 comments on commit e0dc8ef

Please sign in to comment.