@@ -32,18 +32,20 @@ class Timeline {
3232 // timeMark sorted by entropy
3333 // If you reset entropy, all the timeMarks behind the new entropy
3434 // should be dropped
35+ const ntime = options . ntime === undefined ? nowtime ( ) : options . ntime ;
36+
3537 this [ _timeMark ] = [ {
36- globalTime : this . globalTime ,
38+ globalTime : this . getGlobalTime ( ntime ) ,
3739 localTime : - options . originTime ,
3840 entropy : - options . originTime ,
3941 playbackRate : options . playbackRate ,
4042 globalEntropy : 0 ,
4143 } ] ;
4244
43- this [ _createTime ] = nowtime ( ) ;
45+ this [ _createTime ] = ntime ;
4446
4547 if ( this [ _parent ] ) {
46- this [ _timeMark ] [ 0 ] . globalEntropy = this [ _parent ] . entropy ;
48+ this [ _timeMark ] [ 0 ] . globalEntropy = this [ _parent ] . getEntropy ( ntime ) ;
4749 }
4850
4951 this [ _originTime ] = options . originTime ;
@@ -59,13 +61,15 @@ class Timeline {
5961 return this [ _timeMark ] [ this [ _timeMark ] . length - 1 ] ;
6062 }
6163
62- markTime ( { time = this . currentTime , entropy = this . entropy , playbackRate = this . playbackRate } = { } ) {
64+ markTime ( options = { } ) {
65+ const ntime = nowtime ( ) ;
66+ const { time = this . getCurrentTime ( ntime ) , entropy = this . getEntropy ( ntime ) , playbackRate = this . playbackRate } = options ;
6367 const timeMark = {
64- globalTime : this . globalTime ,
68+ globalTime : this . getGlobalTime ( ntime ) ,
6569 localTime : time ,
6670 entropy,
6771 playbackRate,
68- globalEntropy : this . globalEntropy ,
72+ globalEntropy : this . getGlobalEntropy ( ntime ) ,
6973 } ;
7074 this [ _timeMark ] . push ( timeMark ) ;
7175 }
@@ -75,6 +79,11 @@ class Timeline {
7579 return localTime + ( this . globalTime - globalTime ) * this . playbackRate ;
7680 }
7781
82+ getCurrentTime ( ntime ) {
83+ const { localTime, globalTime} = this . lastTimeMark ;
84+ return localTime + ( this . getGlobalTime ( ntime ) - globalTime ) * this . playbackRate ;
85+ }
86+
7887 set currentTime ( time ) {
7988 const from = this . currentTime ,
8089 to = time ,
@@ -111,10 +120,22 @@ class Timeline {
111120 return entropy + Math . abs ( ( this . globalEntropy - globalEntropy ) * this . playbackRate ) ;
112121 }
113122
123+ getEntropy ( ntime ) {
124+ const { entropy, globalEntropy} = this . lastTimeMark ;
125+ return entropy + Math . abs ( ( this . getGlobalEntropy ( ntime ) - globalEntropy ) * this . playbackRate ) ;
126+ }
127+
114128 get globalEntropy ( ) {
115129 return this [ _parent ] ? this [ _parent ] . entropy : nowtime ( ) - this [ _createTime ] ;
116130 }
117131
132+ getGlobalEntropy ( ntime ) {
133+ if ( this [ _parent ] ) {
134+ return this [ _parent ] . getEntropy ( ntime ) ;
135+ }
136+ return ( ntime === undefined ? nowtime ( ) : ntime ) - this [ _createTime ] ;
137+ }
138+
118139 get globalTime ( ) {
119140 if ( this [ _parent ] ) {
120141 return this [ _parent ] . currentTime ;
@@ -123,6 +144,13 @@ class Timeline {
123144 return nowtime ( ) ;
124145 }
125146
147+ getGlobalTime ( ntime ) {
148+ if ( this [ _parent ] ) {
149+ return this [ _parent ] . getCurrentTime ( ntime ) ;
150+ }
151+ return ntime === undefined ? nowtime ( ) : ntime ;
152+ }
153+
126154 // change entropy will NOT cause currentTime changing but may influence the pass
127155 // and the future of the timeline. (It may change the result of seek***Time)
128156 // While entropy is set, all the marks behind will be droped
@@ -291,7 +319,6 @@ class Timeline {
291319 globalTimeout = parent ? parent . setTimeout . bind ( parent ) : setTimeout ;
292320
293321 const heading = time . heading ;
294- // console.log(heading, parent, delay)
295322 if ( ! parent && heading === false && delay < 0 ) {
296323 delay = Infinity ;
297324 }
@@ -322,3 +349,4 @@ class Timeline {
322349}
323350
324351export default Timeline ;
352+ export { nowtime } ;
0 commit comments