ScummVM API documentation
te_curve_anim2.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TETRAEDGE_TE_TE_CURVE_ANIM2_H
23 #define TETRAEDGE_TE_TE_CURVE_ANIM2_H
24 
25 #include "tetraedge/te/te_animation.h"
26 #include "tetraedge/te/te_interpolation.h"
27 
28 namespace Tetraedge {
29 
30 template<class T> static T linearInterpolation(T &obj1, T &obj2, double amount) {
31  amount = CLIP<double>(amount, 0.0, 1.0);
32  return (obj1 * (1.0 - amount)) + (obj2 * amount);
33 }
34 
35 template<class T, class S>
36 class TeCurveAnim2 : public TeAnimation {
37 public:
38  typedef void(T::*TMethod)(const S &);
39 
40  TeCurveAnim2() : _callbackObj(nullptr), _callbackMethod(nullptr), _duration(0), _lastUpdateTime(0) {}
41  virtual ~TeCurveAnim2() {}
42 
43  void setCurve(const Common::Array<float> &curve) {
44  // The original writes the curve to a stream to load it back in in
45  // the interpolation.. we just skip that with a direct array copy.
46  _interp.load(curve);
47  }
48 
49  void update(double millis) {
50  _lastUpdateTime = millis;
51 
52  double amount = _interp.interpole(millis, _duration);
53 
54  const S interpVal = linearInterpolation<S>(_startVal, _endVal, amount);
55  //debug("CurveAnim %.02f/%.02f (%.02f) -> %s", time, _maxTime, amount, interpVal.toString().c_str());
56  (_callbackObj->*_callbackMethod)(interpVal);
57  if (_lastUpdateTime >= _duration) {
58  if (_repeatCount == -1) {
59  seekToStart();
60  } else {
61  stop();
62  onFinished().call();
63  }
64  }
65  }
66 
67  S _startVal;
68  S _endVal;
69  T *_callbackObj;
70  TMethod _callbackMethod;
71  double _duration;
72 
73 private:
74  TeInterpolation _interp;
75  double _lastUpdateTime;
76 };
77 
78 } // end namespace Tetraedge
79 
80 #endif // TETRAEDGE_TE_TE_CURVE_ANIM2_H
Definition: detection.h:27
Definition: te_curve_anim2.h:36
Definition: te_animation.h:31
Definition: te_interpolation.h:31