claw 1.9.0
 
Loading...
Searching...
No Matches
base_tweener.cpp
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 contact: julien.jorge@stuff-o-matic.com
23*/
30
31#include <claw/assert.hpp>
32
38
43{
44 return do_clone();
45}
46
51{
52 return do_is_finished();
53}
54
61{
62 CLAW_PRECOND(dt >= 0);
63
64 const double result = do_update(dt);
65
66 if(is_finished())
67 notify_finished();
68
69 CLAW_POSTCOND(result <= dt);
70 CLAW_POSTCOND(result >= 0);
71
72 return result;
73}
74
79{
80 m_on_finished.push_back(f);
81}
82
86void claw::tween::base_tweener::notify_finished() const
87{
88 // If one of the callbacks deletes the tweener, then m_on_finished will not
89 // be available. Since we still want to execute all the callbacks, we iterate
90 // on a copy of it.
91 const std::list<finish_callback> callbacks(m_on_finished);
92
93 for(std::list<finish_callback>::const_iterator it = callbacks.begin();
94 it != callbacks.end(); ++it)
95 (*it)();
96}
Some assert macros to strengthen you code.
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
Definition assert.hpp:94
#define CLAW_POSTCOND(b)
Abort the program if a postcondition is not true.
Definition assert.hpp:96
Common interface for all tweeners.
Common interface for all tweeners.
std::function< void()> finish_callback
The type of the function called to notify the end of the tweener.
double update(double dt)
Update the base_tweener of a given amount of time.
base_tweener * clone() const
Create a copy of this allocated with new.
virtual ~base_tweener()
Destructor.
void on_finished(finish_callback f)
Execute the callbacks notifying about the finish of the tweener.
bool is_finished() const
Tell if the tweener has reached his total duration.