Claw  1.7.3
code/tween/base_tweener.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/base_tweener.hpp>
00030 
00031 #include <claw/assert.hpp>
00032 
00033 /*----------------------------------------------------------------------------*/
00037 claw::tween::base_tweener::~base_tweener()
00038 {
00039 
00040 } // base_tweener::~base_tweener()
00041 
00042 /*----------------------------------------------------------------------------*/
00046 claw::tween::base_tweener* claw::tween::base_tweener::clone() const
00047 {
00048   return do_clone();
00049 } // base_tweener::clone()
00050 
00051 /*----------------------------------------------------------------------------*/
00055 bool claw::tween::base_tweener::is_finished() const
00056 {
00057   return do_is_finished();
00058 } // base_tweener::is_finished()
00059 
00060 /*----------------------------------------------------------------------------*/
00066 double claw::tween::base_tweener::update( double dt )
00067 {
00068   CLAW_PRECOND( dt >= 0 );
00069 
00070   const double result = do_update(dt);
00071 
00072   if ( is_finished() )
00073     notify_finished();
00074 
00075   CLAW_POSTCOND( result <= dt );
00076   CLAW_POSTCOND( result >= 0 );
00077 
00078   return result;
00079 } // base_tweener::update()
00080 
00081 /*----------------------------------------------------------------------------*/
00085 void claw::tween::base_tweener::on_finished( finish_callback f )
00086 {
00087   m_on_finished.push_back(f);
00088 } // base_tweener::on_finished()
00089 
00090 /*----------------------------------------------------------------------------*/
00094 void claw::tween::base_tweener::notify_finished() const
00095 {
00096   // If one of the callbacks deletes the tweener, then m_on_finished will not be
00097   // available. Since we still want to execute all the callbacks, we iterate on
00098   // a copy of it.
00099   const std::list<finish_callback> callbacks(m_on_finished);
00100 
00101   for ( std::list<finish_callback>::const_iterator it=callbacks.begin();
00102         it!=callbacks.end(); ++it )
00103     (*it)();
00104 } // base_tweener::notify_finished()