NL3D::CAnimation Class Reference

#include <animation.h>

Inheritance diagram for NL3D::CAnimation:

NL3D::UAnimation

Detailed Description

This class describes animations for several tracks. Each track works with a IAnimatedValue for the IAnimatable objects.

Author:
Cyril 'Hulud' Corvazier

Nevrax France

Date:
2001

Definition at line 60 of file animation.h.

Public interface.

enum  { NotFound = 0xffffffff }
void addTrack (const std::string &name, ITrack *pChannel)
uint getIdTrackByName (const std::string &name) const
ITrackgetTrack (uint trackId)
const ITrackgetTrack (uint trackId) const
void getTrackNames (std::set< std::string > &setString) const
void serial (NLMISC::IStream &f)
 Serial the template.

void setMinEndTime (TAnimationTime minEndTime)
 Set animation min end time.


Members

typedef std::map< std::string,
uint32
TMapStringUInt
typedef std::vector< ITrack * > TVectAPtrTrack
TMapStringUInt _IdByName
TAnimationTime _MinEndTime
std::string _Name
TVectAPtrTrack _TrackVector

Public Types


Public Member Functions

 CAnimation ()
 ctor

virtual ~CAnimation ()
 Destructor.

From UAnimation
virtual bool allTrackLoop () const
virtual TAnimationTime getBeginTime () const
virtual TAnimationTime getEndTime () const
virtual UTrackgetTrackByName (const char *name)
virtual void releaseTrack (UTrack *track)

Static Public Member Functions

Create / delete animations
UAnimationcreateAnimation (const char *sPath)
void releaseAnimation (UAnimation *animation)
Create / delete animations
UAnimationcreateAnimation (const char *sPath)
void releaseAnimation (UAnimation *animation)

Private Attributes

Anim time caching
bool _AnimLoop
bool _AnimLoopTouched
TAnimationTime _BeginTime
bool _BeginTimeTouched
TAnimationTime _EndTime
bool _EndTimeTouched


Member Typedef Documentation

typedef std::map<std::string, uint32> NL3D::CAnimation::TMapStringUInt [private]
 

Definition at line 149 of file animation.h.

typedef std::vector<ITrack* > NL3D::CAnimation::TVectAPtrTrack [private]
 

Definition at line 150 of file animation.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
NotFound 

Definition at line 70 of file animation.h.

00070 { NotFound=0xffffffff };


Constructor & Destructor Documentation

NL3D::CAnimation::CAnimation  ) 
 

ctor

NL3D::CAnimation::~CAnimation  )  [virtual]
 

Destructor.

Definition at line 53 of file animation.cpp.

References _TrackVector, NL3D_MEM_ANIMATION, and uint.

00054 {
00055         NL3D_MEM_ANIMATION
00056         // Delete all the pointers in the array
00057         for (uint i=0; i<_TrackVector.size(); i++)
00058                 // Delete
00059                 delete _TrackVector[i];
00060 }


Member Function Documentation

void NL3D::CAnimation::addTrack const std::string &  name,
ITrack pChannel
 

Add a track at the end of the track list.

This method is used to insert tracks in the animation. Tracks must be allocated with new. The pointer is then handeled by the CAnimation.

Definition at line 64 of file animation.cpp.

References _AnimLoopTouched, _BeginTimeTouched, _EndTimeTouched, _IdByName, _TrackVector, NL3D_MEM_ANIMATION, and uint32.

Referenced by NL3D::CAnimationOptimizer::optimize().

00065 {
00066         NL3D_MEM_ANIMATION
00067         // Add an entry in the map
00068         _IdByName.insert (TMapStringUInt::value_type (name, (uint32)_TrackVector.size()));
00069 
00070         // Add an entry in the array
00071         _TrackVector.push_back (pChannel);
00072 
00073         // 
00074         _BeginTimeTouched = _EndTimeTouched = _AnimLoopTouched= true;
00075 
00076 }

bool NL3D::CAnimation::allTrackLoop  )  const [virtual]
 

Say if all track of this animation loop. NB: If no tracks in the animation, return true

Implements NL3D::UAnimation.

Definition at line 192 of file animation.cpp.

References _AnimLoop, _AnimLoopTouched, _TrackVector, NL3D_HAUTO_UI_ANIMATION, NL3D_MEM_ANIMATION, t, and uint.

00193 {
00194         NL3D_MEM_ANIMATION
00195         NL3D_HAUTO_UI_ANIMATION;
00196 
00197         if(_AnimLoopTouched)
00198         {
00199                 // Track count
00200                 uint trackCount=_TrackVector.size();
00201 
00202                 // Default is true
00203                 _AnimLoop= true;
00204 
00205                 // Scan tracks keys
00206                 for (uint t=0; t<trackCount; t++)
00207                 {
00208                         if (!_TrackVector[t]->getLoopMode())
00209                         {
00210                                 _AnimLoop= false;
00211                                 break;
00212                         }
00213                 }
00214                 _AnimLoopTouched = false;
00215         }
00216 
00217         return _AnimLoop;
00218 }

UAnimation * NL3D::UAnimation::createAnimation const char *  sPath  )  [static, inherited]
 

Load an animation. This method will use CPath to find the good animation file. (*.anim). You should call releaseAnimation to delete the animation.

Parameters:
sPath is the animation file path.
Returns:
NULL if the file is not found. Else return the pointer on the animation interface.

Definition at line 259 of file animation.cpp.

References file, NL3D_HAUTO_UI_ANIMATION, and NL3D_MEM_ANIMATION.

00260 {
00261         NL3D_MEM_ANIMATION
00262         NL3D_HAUTO_UI_ANIMATION;
00263 
00264         // Allocate an animation
00265         std::auto_ptr<CAnimation> anim (new CAnimation);
00266 
00267         // Read it
00268         NLMISC::CIFile file;
00269         if (file.open ( NLMISC::CPath::lookup( sPath ) ) )
00270         {
00271                 // Serial the animation
00272                 file.serial (*anim);
00273 
00274                 // Return pointer
00275                 CAnimation *ret=anim.release ();
00276 
00277                 // Return the animation interface
00278                 return ret;
00279         }
00280         else 
00281                 return NULL;
00282 }

TAnimationTime NL3D::CAnimation::getBeginTime  )  const [virtual]
 

Get begin time of the animation.

Returns:
the begin time.

Implements NL3D::UAnimation.

Definition at line 125 of file animation.cpp.

References _BeginTime, _BeginTimeTouched, _TrackVector, NL3D_HAUTO_UI_ANIMATION, NL3D_MEM_ANIMATION, t, NL3D::TAnimationTime, and uint.

Referenced by NL3D::CAnimationPlaylist::getLocalTime(), NL3D::CAnimationPlaylist::setupMixer(), and NL3D::CMeshBaseInstance::traverseHrc().

00126 {
00127         NL3D_MEM_ANIMATION
00128         NL3D_HAUTO_UI_ANIMATION;
00129 
00130         if (_BeginTimeTouched)
00131         {
00132                 // Track count
00133                 uint trackCount=_TrackVector.size();
00134 
00135                 // Track count empty ?
00136                 if (trackCount==0)
00137                         return 0.f;
00138 
00139                 // Look for the lowest
00140                 _BeginTime=_TrackVector[0]->getBeginTime ();
00141 
00142                 // Scan all keys
00143                 for (uint t=1; t<trackCount; t++)
00144                 {
00145                         if (_TrackVector[t]->getBeginTime ()<_BeginTime)
00146                                 _BeginTime=_TrackVector[t]->getBeginTime ();
00147                 }
00148 
00149                 _BeginTimeTouched = false;
00150         }
00151 
00152         return _BeginTime;
00153 }

TAnimationTime NL3D::CAnimation::getEndTime  )  const [virtual]
 

Get end time of the animation.

Returns:
the end time.

Implements NL3D::UAnimation.

Definition at line 157 of file animation.cpp.

References _EndTime, _EndTimeTouched, _MinEndTime, _TrackVector, NL3D_HAUTO_UI_ANIMATION, NL3D_MEM_ANIMATION, t, NL3D::TAnimationTime, and uint.

Referenced by NL3D::CLodCharacterBuilder::addAnim(), NL3D::CAnimationPlaylist::getLocalTime(), NL3D::CAnimationOptimizer::optimize(), NL3D::CAnimationPlaylist::setupMixer(), and NL3D::CMeshBaseInstance::traverseHrc().

00158 {
00159         NL3D_MEM_ANIMATION
00160         NL3D_HAUTO_UI_ANIMATION;
00161 
00162         if (_EndTimeTouched)
00163         {
00164                 // Track count
00165                 uint trackCount=_TrackVector.size();
00166 
00167                 // Track count empty ?
00168                 if (trackCount==0)
00169                         return 0.f;
00170 
00171                 // Look for the highest
00172                 _EndTime=_TrackVector[0]->getEndTime ();
00173 
00174                 // Scan tracks keys
00175                 for (uint t=1; t<trackCount; t++)
00176                 {
00177                         if (_TrackVector[t]->getEndTime ()>_EndTime)
00178                                 _EndTime=_TrackVector[t]->getEndTime ();
00179                 }
00180                 
00181                 // Check min end time
00182                 if (_EndTime < _MinEndTime)
00183                         _EndTime = _MinEndTime;
00184 
00185                 _EndTimeTouched = false;
00186         }
00187 
00188         return _EndTime;
00189 }

uint NL3D::CAnimation::getIdTrackByName const std::string &  name  )  const [inline]
 

Get track with its name.

Parameters:
name is the name of the desired track.
Returns:
CAnimation::NotFound if the track doesn't exist else the the id of the track.

Definition at line 77 of file animation.h.

References _IdByName, NL3D_MEM_ANIMATION, NotFound, and uint.

Referenced by getTrackByName(), NL3D::CAnimationOptimizer::optimize(), and NL3D::CChannelMixer::refreshList().

00078         {
00079                 NL3D_MEM_ANIMATION
00080                 // Find an entry in the name/id map
00081                 TMapStringUInt::const_iterator ite=_IdByName.find (name);
00082 
00083                 // Not found ?
00084                 if (ite==_IdByName.end ())
00085                         // yes, error
00086                         return NotFound;
00087                 else
00088                         // no, return track ID
00089                         return (uint)ite->second;
00090         }

ITrack* NL3D::CAnimation::getTrack uint  trackId  )  [inline]
 

Get a track pointer

Parameters:
channelId is the id of the desired channel.

Definition at line 114 of file animation.h.

References _TrackVector, NL3D_MEM_ANIMATION, and uint.

00115         {
00116                 NL3D_MEM_ANIMATION
00117                 // Get the trackId-th track pointer
00118                 return _TrackVector[trackId];
00119         }

const ITrack* NL3D::CAnimation::getTrack uint  trackId  )  const [inline]
 

Get a const track pointer

Parameters:
channelId is the id of the desired channel.

Definition at line 103 of file animation.h.

References _TrackVector, NL3D_MEM_ANIMATION, and uint.

Referenced by getTrackByName(), and NL3D::CAnimationOptimizer::optimize().

00104         {
00105                 NL3D_MEM_ANIMATION
00106                 // Get the trackId-th track pointer
00107                 return _TrackVector[trackId];
00108         }

UTrack * NL3D::CAnimation::getTrackByName const char *  name  )  [virtual]
 

Get an animation track with its name. The track interface should be released with releaseTrack.

Parameters:
name is the name of the track to get.
Returns:
NULL if the track is not found, else a pointer on the track interface.

Implements NL3D::UAnimation.

Definition at line 222 of file animation.cpp.

References getIdTrackByName(), getTrack(), NL3D_HAUTO_UI_ANIMATION, NL3D_MEM_ANIMATION, and uint.

00223 {
00224         NL3D_MEM_ANIMATION
00225         NL3D_HAUTO_UI_ANIMATION;
00226 
00227         // Get track id
00228         uint id=getIdTrackByName (name);
00229 
00230         // Not found ?
00231         if (id==CAnimation::NotFound)
00232                 // Error, return NULL
00233                 return NULL;
00234         else
00235                 // No error, return the track
00236                 return getTrack (id);
00237 }

void NL3D::CAnimation::getTrackNames std::set< std::string > &  setString  )  const
 

Fill the set of string with the name of the channels.

Returns:
the count of track in this animation

Definition at line 108 of file animation.cpp.

References _IdByName, and NL3D_MEM_ANIMATION.

Referenced by NL3D::CAnimationSet::build(), NL3D::CAnimationOptimizer::optimize(), and NL3D::CScene::setAutomaticAnimationSet().

00109 {
00110         NL3D_MEM_ANIMATION
00111         // For each track name
00112         TMapStringUInt::const_iterator ite=_IdByName.begin();
00113         while (ite!=_IdByName.end())
00114         {
00115                 // Add the name in the map
00116                 setString.insert (ite->first);
00117 
00118                 // Next track
00119                 ite++;
00120         }
00121 }

void NL3D::UAnimation::releaseAnimation UAnimation animation  )  [static, inherited]
 

Release an animation. This animation must have been created will createAnimation().

Parameters:
animation is the animation to release.

Definition at line 286 of file animation.cpp.

References NL3D_HAUTO_UI_ANIMATION, and NL3D_MEM_ANIMATION.

00287 {
00288         NL3D_MEM_ANIMATION
00289         NL3D_HAUTO_UI_ANIMATION;
00290 
00291         // Cast the pointer
00292         CAnimation* release=(CAnimation*)animation;
00293 
00294         // Delete it
00295         delete release;
00296 }

void NL3D::CAnimation::releaseTrack UTrack track  )  [virtual]
 

Relase a track interface.

Parameters:
track is a pointer on the track interface to release.

Implements NL3D::UAnimation.

Definition at line 241 of file animation.cpp.

References NL3D_HAUTO_UI_ANIMATION, and NL3D_MEM_ANIMATION.

00242 {
00243         NL3D_MEM_ANIMATION
00244         NL3D_HAUTO_UI_ANIMATION;
00245 
00246         // Nothing to do
00247 }

void NL3D::CAnimation::serial NLMISC::IStream f  ) 
 

Serial the template.

Definition at line 80 of file animation.cpp.

References _IdByName, _MinEndTime, _TrackVector, NL3D_MEM_ANIMATION, NLMISC::IStream::serial(), NLMISC::IStream::serialCheck(), NLMISC::IStream::serialCont(), NLMISC::IStream::serialContPolyPtr(), NLMISC::IStream::serialVersion(), sint, and uint32.

00081 {
00082         NL3D_MEM_ANIMATION
00083         // Serial a header
00084         f.serialCheck ((uint32)'_LEN');
00085         f.serialCheck ((uint32)'MINA');
00086 
00087         // Serial a version
00088         sint version=f.serialVersion (1);
00089 
00090         // Serial the name
00091         f.serial (_Name);
00092 
00093         // Serial the name/id map
00094         f.serialCont(_IdByName);
00095 
00096         // Serial the vector
00097         f.serialContPolyPtr (_TrackVector);
00098 
00099         // Serial the min end time
00100         if (version>=1)
00101         {
00102                 f.serial (_MinEndTime);
00103         }
00104 }

void NL3D::CAnimation::setMinEndTime TAnimationTime  minEndTime  ) 
 

Set animation min end time.

Definition at line 251 of file animation.cpp.

References _MinEndTime, NL3D_MEM_ANIMATION, and NL3D::TAnimationTime.

Referenced by NL3D::CAnimationOptimizer::optimize().

00252 {
00253         NL3D_MEM_ANIMATION
00254         _MinEndTime = minEndTime;
00255 }


Field Documentation

bool NL3D::CAnimation::_AnimLoop [mutable, private]
 

Definition at line 168 of file animation.h.

Referenced by allTrackLoop().

bool NL3D::CAnimation::_AnimLoopTouched [mutable, private]
 

Definition at line 171 of file animation.h.

Referenced by addTrack(), and allTrackLoop().

TAnimationTime NL3D::CAnimation::_BeginTime [mutable, private]
 

Definition at line 166 of file animation.h.

Referenced by getBeginTime().

bool NL3D::CAnimation::_BeginTimeTouched [mutable, private]
 

Definition at line 169 of file animation.h.

Referenced by addTrack(), and getBeginTime().

TAnimationTime NL3D::CAnimation::_EndTime [mutable, private]
 

Definition at line 167 of file animation.h.

Referenced by getEndTime().

bool NL3D::CAnimation::_EndTimeTouched [mutable, private]
 

Definition at line 170 of file animation.h.

Referenced by addTrack(), and getEndTime().

TMapStringUInt NL3D::CAnimation::_IdByName [private]
 

Definition at line 156 of file animation.h.

Referenced by addTrack(), getIdTrackByName(), getTrackNames(), and serial().

TAnimationTime NL3D::CAnimation::_MinEndTime [private]
 

Definition at line 162 of file animation.h.

Referenced by getEndTime(), serial(), and setMinEndTime().

std::string NL3D::CAnimation::_Name [private]
 

Definition at line 153 of file animation.h.

TVectAPtrTrack NL3D::CAnimation::_TrackVector [private]
 

Definition at line 159 of file animation.h.

Referenced by addTrack(), allTrackLoop(), getBeginTime(), getEndTime(), getTrack(), serial(), and ~CAnimation().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:44:25 2004 for NeL by doxygen 1.3.6