OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Timeline.h
Go to the documentation of this file.
1 /* -*-c++-*-
2  * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3  *
4  * This library is open source and may be redistributed and/or modified under
5  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6  * (at your option) any later version. The full license is in LICENSE file
7  * included with this distribution, and on the openscenegraph.org website.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * OpenSceneGraph Public License for more details.
13 */
14 
15 #ifndef OSGANIMATION_TIMELINE
16 #define OSGANIMATION_TIMELINE 1
17 
18 #include <osgAnimation/Export>
19 #include <map>
20 #include <vector>
21 #include <osg/observer_ptr>
22 #include <osg/Notify>
23 #include <osg/Stats>
24 #include <osgAnimation/Action>
25 #include <osgAnimation/FrameAction>
26 #include <osgAnimation/AnimationManagerBase>
27 #include <osgAnimation/StatsVisitor>
28 
29 namespace osgAnimation
30 {
32  {
33  public:
34 
35  Timeline();
37 
39 
41  {
43  Stop
44  };
45 
46  TimelineStatus getStatus() const { return _state; }
47 
48  typedef std::vector<FrameAction> ActionList;
49  typedef std::map<int, ActionList> ActionLayers;
50 
51  const ActionList& getActionLayer(int i) { return _actions[i];}
52  unsigned int getCurrentFrame() const { return _currentFrame;}
53  double getCurrentTime() const { return _currentFrame * 1.0 / _fps;}
54 
55  void play() { _state = Play; }
56  void gotoFrame(unsigned int frame) { _currentFrame = frame; }
57  void stop() { _state = Stop; }
58  bool getEvaluating() const { return _evaluating;}
59 
60  bool isActive(Action* activeAction);
61 
62  void removeAction(Action* action);
63  virtual void addActionAt(unsigned int frame, Action* action, int priority = 0);
64  virtual void addActionAt(double t, Action* action, int priority = 0);
65  void addActionNow(Action* action, int priority = 0);
66 
67  void clearActions();
68 
69  virtual void update(double simulationTime);
70  void setLastFrameEvaluated(unsigned int frame) { _previousFrameEvaluated = frame; }
71 
72  void setEvaluating(bool state) { _evaluating = state;}
73  void traverse(ActionVisitor& visitor);
74 
75  void setStats(osg::Stats* stats);
76  osg::Stats* getStats();
77  void collectStats(bool state);
78  osgAnimation::StatsActionVisitor* getStatsVisitor();
79 
80  const ActionLayers& getActionLayers() const { return _actions; }
81 
82  void processPendingOperation();
83  void setAnimationManager(AnimationManagerBase*);
84  protected:
86  ActionLayers _actions;
87  double _lastUpdate;
88  double _speed;
89  unsigned int _currentFrame;
93 
97 
98  // to manage pending operation
100 
101  struct Command
102  {
103  Command():_priority(0) {}
104  Command(int priority, const FrameAction& action) : _priority(priority), _action(action) {}
107  };
108 
109  typedef std::vector<Command> CommandList;
110  CommandList _addActionOperations;
112 
113  void internalRemoveAction(Action* action);
114  void internalAddAction(int priority, const FrameAction& ftl);
115 
116  };
117 
118 
119 
120 }
121 
122 #endif
#define OSGANIMATION_EXPORT
Definition: Export.h:40
double getCurrentTime() const
Definition: Timeline.h:53
std::vector< FrameAction > ActionList
Definition: Timeline.h:48
ActionLayers _actions
Definition: Timeline.h:86
const ActionLayers & getActionLayers() const
Definition: Timeline.h:80
osg::ref_ptr< osg::Stats > _stats
Definition: Timeline.h:95
const ActionList & getActionLayer(int i)
Definition: Timeline.h:51
unsigned int _currentFrame
Definition: Timeline.h:89
TimelineStatus getStatus() const
Definition: Timeline.h:46
bool getEvaluating() const
Definition: Timeline.h:58
osg::observer_ptr< AnimationManagerBase > _animationManager
Definition: Timeline.h:85
std::pair< unsigned int, osg::ref_ptr< Action > > FrameAction
Definition: FrameAction.h:23
Command(int priority, const FrameAction &action)
Definition: Timeline.h:104
TimelineStatus _state
Definition: Timeline.h:92
unsigned int _previousFrameEvaluated
Definition: Timeline.h:90
void setEvaluating(bool state)
Definition: Timeline.h:72
CommandList _addActionOperations
Definition: Timeline.h:110
void gotoFrame(unsigned int frame)
Definition: Timeline.h:56
osg::ref_ptr< osgAnimation::StatsActionVisitor > _statsVisitor
Definition: Timeline.h:96
ActionList _removeActionOperations
Definition: Timeline.h:111
std::vector< Command > CommandList
Definition: Timeline.h:109
void setLastFrameEvaluated(unsigned int frame)
Definition: Timeline.h:70
std::map< int, ActionList > ActionLayers
Definition: Timeline.h:49
unsigned int getCurrentFrame() const
Definition: Timeline.h:52
#define META_Action(library, name)
Definition: Action.h:24