claw
1.9.0
Toggle main menu visibility
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
*/
29
#include <
claw/tween/base_tweener.hpp
>
30
31
#include <
claw/assert.hpp
>
32
36
claw::tween::base_tweener::~base_tweener
()
37
{}
38
42
claw::tween::base_tweener
*
claw::tween::base_tweener::clone
()
const
43
{
44
return
do_clone();
45
}
46
50
bool
claw::tween::base_tweener::is_finished
()
const
51
{
52
return
do_is_finished();
53
}
54
60
double
claw::tween::base_tweener::update
(
double
dt)
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
78
void
claw::tween::base_tweener::on_finished
(
finish_callback
f)
79
{
80
m_on_finished.push_back(f);
81
}
82
86
void
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
}
assert.hpp
Some assert macros to strengthen you code.
CLAW_PRECOND
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
Definition
assert.hpp:94
CLAW_POSTCOND
#define CLAW_POSTCOND(b)
Abort the program if a postcondition is not true.
Definition
assert.hpp:96
base_tweener.hpp
Common interface for all tweeners.
claw::tween::base_tweener
Common interface for all tweeners.
Definition
base_tweener.hpp:45
claw::tween::base_tweener::finish_callback
std::function< void()> finish_callback
The type of the function called to notify the end of the tweener.
Definition
base_tweener.hpp:51
claw::tween::base_tweener::update
double update(double dt)
Update the base_tweener of a given amount of time.
Definition
base_tweener.cpp:60
claw::tween::base_tweener::clone
base_tweener * clone() const
Create a copy of this allocated with new.
Definition
base_tweener.cpp:42
claw::tween::base_tweener::~base_tweener
virtual ~base_tweener()
Destructor.
Definition
base_tweener.cpp:36
claw::tween::base_tweener::on_finished
void on_finished(finish_callback f)
Execute the callbacks notifying about the finish of the tweener.
Definition
base_tweener.cpp:78
claw::tween::base_tweener::is_finished
bool is_finished() const
Tell if the tweener has reached his total duration.
Definition
base_tweener.cpp:50
lib
tween
src
claw
tween
base_tweener.cpp
Generated by
1.17.0