2008-11-22 20:14:19 +08:00
|
|
|
/* -*-c++-*-
|
2009-06-15 22:48:37 +08:00
|
|
|
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
|
2008-11-22 20:14:19 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGANIMATION_TIMELINE_H
|
|
|
|
#define OSGANIMATION_TIMELINE_H
|
|
|
|
|
2008-11-28 22:34:38 +08:00
|
|
|
#include <osgAnimation/Export>
|
2008-11-22 20:14:19 +08:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <osg/Notify>
|
2009-06-15 22:48:37 +08:00
|
|
|
#include <osg/Stats>
|
|
|
|
#include <osgAnimation/Action>
|
|
|
|
#include <osgAnimation/FrameAction>
|
2008-11-22 20:14:19 +08:00
|
|
|
#include <osgAnimation/AnimationManagerBase>
|
2009-06-18 00:54:39 +08:00
|
|
|
#include <osgAnimation/StatsVisitor>
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
namespace osgAnimation
|
|
|
|
{
|
2009-06-15 22:48:37 +08:00
|
|
|
class OSGANIMATION_EXPORT Timeline : public Action //osg::Object
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2009-03-10 07:11:23 +08:00
|
|
|
Timeline();
|
|
|
|
Timeline(const Timeline& nc,const osg::CopyOp& op = osg::CopyOp::SHALLOW_COPY);
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
META_Action(osgAnimation, Timeline);
|
|
|
|
|
2009-05-25 20:04:29 +08:00
|
|
|
enum TimelineStatus
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
2009-03-10 07:11:23 +08:00
|
|
|
Play,
|
|
|
|
Stop
|
2008-11-22 20:14:19 +08:00
|
|
|
};
|
|
|
|
|
2009-05-25 20:04:29 +08:00
|
|
|
TimelineStatus getStatus() const { return _state; }
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-03-10 07:11:23 +08:00
|
|
|
typedef std::vector<FrameAction> ActionList;
|
|
|
|
typedef std::map<int, ActionList> ActionLayers;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
const ActionList& getActionLayer(int i) { return _actions[i];}
|
2008-11-22 20:14:19 +08:00
|
|
|
unsigned int getCurrentFrame() const { return _currentFrame;}
|
|
|
|
double getCurrentTime() const { return _currentFrame * 1.0 / _fps;}
|
|
|
|
|
|
|
|
void play() { _state = Play; }
|
|
|
|
void gotoFrame(unsigned int frame) { _currentFrame = frame; }
|
|
|
|
void stop() { _state = Stop; }
|
|
|
|
bool getEvaluating() const { return _evaluating;}
|
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
bool isActive(Action* activeAction);
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
void removeAction(Action* action);
|
|
|
|
virtual void addActionAt(unsigned int frame, Action* action, int priority = 0);
|
|
|
|
virtual void addActionAt(double t, Action* action, int priority = 0);
|
|
|
|
void addActionNow(Action* action, int priority = 0);
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
void clearActions();
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
virtual void update(double simulationTime);
|
|
|
|
void setLastFrameEvaluated(unsigned int frame) { _previousFrameEvaluated = frame; }
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
void setEvaluating(bool state) { _evaluating = state;}
|
|
|
|
void traverse(ActionVisitor& visitor);
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
void setStats(osg::Stats* stats);
|
|
|
|
osg::Stats* getStats();
|
|
|
|
void collectStats(bool state);
|
|
|
|
osgAnimation::StatsActionVisitor* getStatsVisitor();
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
const ActionLayers& getActionLayers() const { return _actions; }
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
void processPendingOperation();
|
2009-03-10 07:11:23 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
ActionLayers _actions;
|
|
|
|
double _lastUpdate;
|
|
|
|
double _speed;
|
|
|
|
unsigned int _currentFrame;
|
|
|
|
unsigned int _previousFrameEvaluated;
|
|
|
|
bool _initFirstFrame;
|
2009-05-25 20:04:29 +08:00
|
|
|
TimelineStatus _state;
|
2009-03-10 07:11:23 +08:00
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
bool _collectStats;
|
|
|
|
osg::ref_ptr<osg::Stats> _stats;
|
|
|
|
osg::ref_ptr<osgAnimation::StatsActionVisitor> _statsVisitor;
|
|
|
|
|
2009-03-10 07:11:23 +08:00
|
|
|
// to manage pending operation
|
|
|
|
bool _evaluating;
|
|
|
|
|
|
|
|
struct Command
|
|
|
|
{
|
|
|
|
Command():_priority(0) {}
|
|
|
|
Command(int priority, const FrameAction& action) : _priority(priority), _action(action) {}
|
|
|
|
int _priority;
|
|
|
|
FrameAction _action;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Command> CommandList;
|
|
|
|
CommandList _addActionOperations;
|
|
|
|
ActionList _removeActionOperations;
|
|
|
|
|
2009-06-15 22:48:37 +08:00
|
|
|
void internalRemoveAction(Action* action);
|
|
|
|
void internalAddAction(int priority, const FrameAction& ftl);
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|