MercuryObjectCommands.h

Go to the documentation of this file.
00001 #ifndef MERCURYOBJECTCOMMANDS_H
00002 #define MERCURYOBJECTCOMMANDS_H
00003 
00004 #include "global.h"
00005 #include "MercuryCommands.h"
00006 #include <map>
00007 #include <vector>
00008 
00009 //Class definition, to allow use of class (but not including)
00010 class MercuryObject;
00011 class MercuryTweenOperation;
00012 
00013 typedef void (*MercuryTweenFunction)( const float fPercent, const float fLastPercent, MercuryObject * pObject, MercuryTweenOperation * pOperation );
00014 typedef float (*MercuryTweenType)( const float fPercent, PStack & pArgs  );
00015 
00017 class AutoCommandRegisterer
00018 {
00019 public:
00020     MercuryTweenFunction GetFunction( const MString &name );
00021     int RegisterFunction( MercuryTweenFunction fnct, const MString & name );
00022 
00023     MercuryTweenType GetTweenType( const MString &name );
00024     int RegisterTweenType( MercuryTweenType fnct, const MString & name );
00025     
00026     std::map< MString, MercuryTweenFunction > * sMapFunctions;
00027     std::map< MString, MercuryTweenType > * sMapTweens;
00028 
00029     int sNumFunctions;
00030 };
00031 extern AutoCommandRegisterer CommandRegisterer;
00032 
00034 class MercuryTweenOperation
00035 {
00036 public:
00037     MercuryTweenFunction    Function;
00038     MString                 Command;    //Object-specific command
00039     PStack                  Parameters;
00040 };
00041 
00043 class MercuryTween
00044 {
00045 public:
00046     MercuryTween();
00047     MercuryTween( const MercuryTween & rhs );
00048     MercuryTween & operator = ( const MercuryTween & rhs );
00049     ~MercuryTween();
00050     MVector< MercuryTweenOperation *> Operations;
00051     void Operate(  const float fPercent, const float fLastPercent, MercuryObject * pObject );
00052     float   fStart;
00053     float   fEnd;
00054     MercuryTweenType pTT;
00055     PStack  pTArgs;
00056     PStack  pKArgs;
00057     bool bAutoDelete;
00058     bool bDeleteChildren;
00059     int     iEndBase;
00060 };
00061 
00063 class MercuryTweenState
00064 {
00065 public:
00066     enum SPACE
00067     {
00068         CURRENT = 0,
00069         LOCAL,
00070         GLOBAL
00071     };
00072     MercuryTweenState();
00073     MercuryTweenState( const MercuryTweenState & rhs );
00074     MercuryTweenState & operator = ( const MercuryTweenState & rhs );
00075     ~MercuryTweenState();
00076 
00077     void AttachToObject( MercuryObject * object );
00078     void Update( float fDeltaTime );
00079 
00080     //Timestamps here relative to now=0
00082     void AddCommand( MercuryTween * ToPush, float fFuture = 0, SPACE iWhichPlace = CURRENT, MString sTweenName = "" );
00084     void AddCommand( const MString &command, SPACE iWhichPlace = CURRENT, MString sTweenName = "" );
00085 
00087     void ExecuteCommand( const MString & sName, const PStack & pKArgs );
00088 
00090     void FinishTweening();
00092     void StopTweening();
00094     void PauseTweening() { m_bPauseTweening = true; }
00096     void ResumeTweening() { m_bPauseTweening = false; }
00098     bool IsTweeningPaused() { return m_bPauseTweening; }
00099 
00100     //Temporary work around.  We need to have this public
00101     //so that tweens can access KArgs for the current tween
00102     MercuryTween * m_pCurrentTween;
00103 
00104     bool IsTweening() const { return !m_qTweens.empty(); } 
00105 private:
00106 
00107     float CalculateRemainingPercent( float fDeltaTime );
00108     float CalculateCurrentPercent( float fDeltaTime );
00109 
00110     float   m_fCurTime;
00111     bool    m_bPauseTweening;
00112     float   m_fRunningEnd;
00113 
00114     MercuryObject * m_pObject;
00115     MDeque< MercuryTween * > m_qTweens;
00116 
00117     void InternalUpdate( float fDeltaTime, bool bFinish = false );
00118 
00119     std::map< MString, std::vector< MercuryTween * > > m_LocalTweens;
00120     static std::map< MString, std::vector< MercuryTween * > > m_GlobalTweens;
00121     bool    m_bCloned;
00122 };
00123 
00124 #endif
00125 
00126 /* 
00127  * Copyright (c) 2005-2006, Charles Lohr
00128  * All rights reserved.
00129  *
00130  * Redistribution and use in source and binary forms, with or
00131  * without modification, are permitted provided that the following
00132  * conditions are met:
00133  *  -   Redistributions of source code must retain the above
00134  *      copyright notice, this list of conditions and the following disclaimer.
00135  *  -   Redistributions in binary form must reproduce the above copyright
00136  *      notice, this list of conditions and the following disclaimer in
00137  *      the documentation and/or other materials provided with the distribution.
00138  *  -   Neither the name of the <ORGANIZATION> nor the names of its
00139  *      contributors may be used to endorse or promote products derived from
00140  *      this software without specific prior written permission.
00141  *
00142  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00143  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00144  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00145  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00146  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00147  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00148  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00149  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00150  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00151  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00152  */

Hosted by SourceForge.net Logo