Claw  1.7.0
tweener_group.cpp
Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2011 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022   contact: julien.jorge@gamned.org
00023 */
00029 #include "claw/tween/tweener_group.hpp"
00030 
00031 /*----------------------------------------------------------------------------*/
00036 void claw::tween::tweener_group::insert( const tweener& t )
00037 {
00038   m_tweeners.push_back(t);
00039 
00040   m_tweeners.back().update(0); // force the initial position
00041 
00042   if ( m_tweeners.back().is_finished() )
00043     m_tweeners.pop_back();
00044 } // tweener_group::insert()
00045 
00046 /*----------------------------------------------------------------------------*/
00050 void claw::tween::tweener_group::clear()
00051 {
00052   m_tweeners.clear();
00053 } // tweener_group::clear()
00054 
00055 /*----------------------------------------------------------------------------*/
00059 claw::tween::tweener_group* claw::tween::tweener_group::do_clone() const
00060 {
00061   return new tweener_group(*this);
00062 } // tweener_group::do_clone()
00063 
00064 /*----------------------------------------------------------------------------*/
00068 bool claw::tween::tweener_group::do_is_finished() const
00069 {
00070   return m_tweeners.empty();
00071 } // tweener_group::do_is_finished()
00072 
00073 /*----------------------------------------------------------------------------*/
00078 double claw::tween::tweener_group::do_update( double dt )
00079 {
00080   typedef std::list<tweener>::iterator iterator_type;
00081   double result(dt);
00082 
00083   iterator_type it = m_tweeners.begin();
00084 
00085   while ( it != m_tweeners.end() )
00086     {
00087       const double r = it->update(dt);
00088       result = std::min(result, r);
00089 
00090       if ( it->is_finished() )
00091         {
00092           const iterator_type tmp(it);
00093           ++it;
00094           m_tweeners.erase(tmp);
00095         }
00096       else
00097         ++it;
00098     }
00099 
00100   return result;
00101 } // tweener_group::do_update()