Claw  1.7.0
tweener_group.cpp
Go to the documentation of this file.
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@gamned.org
23 */
30 
31 /*----------------------------------------------------------------------------*/
37 {
38  m_tweeners.push_back(t);
39 
40  m_tweeners.back().update(0); // force the initial position
41 
42  if ( m_tweeners.back().is_finished() )
43  m_tweeners.pop_back();
44 } // tweener_group::insert()
45 
46 /*----------------------------------------------------------------------------*/
51 {
52  m_tweeners.clear();
53 } // tweener_group::clear()
54 
55 /*----------------------------------------------------------------------------*/
59 claw::tween::tweener_group* claw::tween::tweener_group::do_clone() const
60 {
61  return new tweener_group(*this);
62 } // tweener_group::do_clone()
63 
64 /*----------------------------------------------------------------------------*/
68 bool claw::tween::tweener_group::do_is_finished() const
69 {
70  return m_tweeners.empty();
71 } // tweener_group::do_is_finished()
72 
73 /*----------------------------------------------------------------------------*/
78 double claw::tween::tweener_group::do_update( double dt )
79 {
80  typedef std::list<tweener>::iterator iterator_type;
81  double result(dt);
82 
83  iterator_type it = m_tweeners.begin();
84 
85  while ( it != m_tweeners.end() )
86  {
87  const double r = it->update(dt);
88  result = std::min(result, r);
89 
90  if ( it->is_finished() )
91  {
92  const iterator_type tmp(it);
93  ++it;
94  m_tweeners.erase(tmp);
95  }
96  else
97  ++it;
98  }
99 
100  return result;
101 } // tweener_group::do_update()