24 template<
typename KeyType >
30 std::vector< Key< KeyType > >
Keys;
49 typename std::vector< Key< KeyType > >::iterator
FindKey (
TimeType time );
69 template<
typename KeyType,
template<
typename KeyType >
class InterpolatorType >
77 template<
typename KeyType >
84 Keys.push_back( std::move( firstKey ) );
89 template<
typename KeyType >
92 auto iter = FindKey( time );
93 if( iter != Keys.end() )
101 template<
typename KeyType >
104 auto iter = FindPlace( time );
106 if( iter == Keys.end() )
109 AddDefaultInterpolator( Keys.size() - 1 );
115 if( abs( iter->Time - time ) <
epsilon )
123 AddDefaultInterpolator( std::distance( Keys.begin(), iter ) );
133 template<
typename KeyType >
141 template<
typename KeyType >
144 auto iter = FindKey( time );
145 if( iter == Keys.end() )
150 auto keyIdx = std::distance( Keys.begin(), iter );
151 UpdateInterpolator( keyIdx );
152 UpdateInterpolator( keyIdx - 1 );
161 template<
typename KeyType >
164 if( Keys.size() <= 1 )
167 auto iter = FindKey( time );
168 if( iter == Keys.end() )
171 iter = Keys.erase( iter );
174 auto keyIdx = std::distance( Keys.begin(), iter );
175 auto interIter = Interpolators.erase( Interpolators.begin() + keyIdx );
177 Size interpolatorIdx = std::distance( Interpolators.begin(), interIter );
178 UpdateInterpolator( interpolatorIdx );
179 UpdateInterpolator( interpolatorIdx - 1 );
186 template<
typename KeyType >
189 if( Keys.size() == 1 )
190 return Keys[ 0 ].Value;
194 auto iter = Keys.begin();
195 for( ; iter != Keys.end(); ++iter )
197 if( iter->Time > time )
201 Size keyIdx = std::distance( Keys.begin(), iter );
203 if( keyIdx >= Keys.size() )
204 return Keys.back().Value;
206 return Keys[ 0 ].Value;
208 return Interpolators[ keyIdx - 1 ]->Interpolate( time, Keys[ keyIdx - 1 ], Keys[ keyIdx ] );
213 template<
typename KeyType>
216 if( idx < Interpolators.size() )
218 Interpolators[ idx ] = std::move( interpolator );
219 UpdateInterpolator( idx );
234 template<
typename KeyType >
240 auto iterRange = std::equal_range( Keys.begin(), Keys.end(), fakeKey );
242 assert( std::distance( iterRange.first, iterRange.second ) <= 1 );
243 if( std::distance( iterRange.first, iterRange.second ) == 1 )
244 return iterRange.first;
251 template<
typename KeyType >
257 auto iter = std::lower_bound( Keys.begin(), Keys.end(), fakeKey );
263 template<
typename KeyType >
269 if( keyIndex == Keys.size() - 1 )
271 leftKeyIdx = keyIndex - 1;
272 rightKeyIdx = keyIndex;
276 leftKeyIdx = keyIndex;
277 rightKeyIdx = keyIndex + 1;
282 auto& leftKey = Keys[ leftKeyIdx ];
283 auto& rightKey = Keys[ rightKeyIdx ];
286 auto& leftInterpolator = keyIndex > 0 && keyIndex < Interpolators.size() ? Interpolators[ keyIndex - 1 ] : MakeUPtr< DummyInterpolator< KeyType > >();
287 auto& rightInterpolator = keyIndex < Interpolators.size() ? Interpolators[ keyIndex ] : MakeUPtr< DummyInterpolator< KeyType > >();
289 auto interpolator = DefaultInterpolators::Create< KeyType >( leftKey, rightKey,
CastConst( leftInterpolator ),
CastConst( rightInterpolator ) );
292 if( keyIndex == Keys.size() - 1 )
293 Interpolators.push_back( std::move( interpolator ) );
295 Interpolators.insert( Interpolators.begin() + keyIndex, std::move( interpolator ) );
299 UpdateInterpolator( keyIndex - 1 );
300 UpdateInterpolator( keyIndex + 1 );
305 template<
typename KeyType >
309 if( index >= Interpolators.size() )
313 assert( Keys.size() == Interpolators.size() + 1 );
318 auto& leftKey = Keys[ index ];
319 auto& rightKey = Keys[ index + 1 ];
321 auto& interpolator = Interpolators[ index ];
323 interpolator->Update( leftKey, rightKey, leftInterpolator, rightInterpolator );
TimeType Time
Definition: Key.h:16
std::vector< UPtr< Interpolator > > Interpolators
Definition: KeySet.h:31
Base class for interpolators.
Definition: IInterpolator.h:38
const TimeType epsilon
Definition: TimelinesTest.cpp:10
Key< KeyType > * GetKey(TimeType time)
Definition: KeySet.h:90
KeyType
Definition: all_0.js:13
bool AddKey(TimeType time, const KeyType &value)
Adds key. If key exists updates this key.
Definition: KeySet.h:102
void UpdateInterpolator(Size index)
Updates interpolator under index. If interpolator doesn't exists, nothing bad happens.
Definition: KeySet.h:306
bool UpdateKey(TimeType time, const KeyType &value)
Updates key.
Definition: KeySet.h:142
bool ChangeInterpolator(Size idx, UPtr< Interpolator > &&interpolator)
Definition: KeySet.h:214
KeyType Evaluate(TimeType time)
Definition: KeySet.h:187
InterpolatorType
Definition: IInterpolator.h:24
std::vector< Key< KeyType > >::iterator FindKey(TimeType time)
Definition: KeySet.h:235
Animation key.
Definition: IInterpolator.h:21
size_t Size
Definition: TypesDefinitions.h:35
Set of animation keys and interpolators.
Definition: KeySet.h:25
KeySet()
Constructor insert default KeyType in time 0.0;.
Definition: KeySet.h:78
UPtr< const IInterpolator< KeyType > > CastConst(UPtr< InterpolatorType< KeyType > > &interpolator)
Definition: KeySet.h:70
std::vector< Key< KeyType > > Keys
Definition: KeySet.h:30
void AddDefaultInterpolator(Size keyIndex)
Adds default interpolator for given type. Adds interpolator defined by function DefaultInterpolators:...
Definition: KeySet.h:264
bool RemoveKey(TimeType time)
Removes key. Last key can't be removed.
Definition: KeySet.h:162
std::vector< Key< KeyType > >::iterator FindPlace(TimeType time)
Definition: KeySet.h:252
double TimeType
Definition: TypesDefinitions.h:39
ValueType Value
Definition: Key.h:17
UPtr< PtrType > MakeUPtr(Args...args)
Definition: TypesDefinitions.h:70
IInterpolator< KeyType > Interpolator
Definition: KeySet.h:28
Temporary interpolator for internal use.
Definition: IInterpolator.h:67