ActionVisitor 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* -*-c++-*-
  2. * Copyright (C) 2009 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. #ifndef OSGANIMATION_ACTIONVISITOR_H
  15. #define OSGANIMATION_ACTIONVISITOR_H
  16. #include <vector>
  17. #include <osgAnimation/Export>
  18. #include <osg/Referenced>
  19. #include <osgAnimation/FrameAction>
  20. namespace osgAnimation
  21. {
  22. class Timeline;
  23. class Action;
  24. class ActionBlendIn;
  25. class ActionBlendOut;
  26. class ActionAnimation;
  27. class ActionStripAnimation;
  28. #define META_ActionVisitor(library,name) \
  29. virtual const char* libraryName() const { return #library; }\
  30. virtual const char* className() const { return #name; }
  31. class OSGANIMATION_EXPORT ActionVisitor : public osg::Referenced
  32. {
  33. public:
  34. META_ActionVisitor(osgAnimation, ActionVisitor);
  35. ActionVisitor();
  36. void traverse(Action& visitor);
  37. void pushFrameActionOnStack(const FrameAction& fa);
  38. void popFrameAction();
  39. void pushTimelineOnStack(Timeline* tm);
  40. void popTimeline();
  41. Timeline* getCurrentTimeline();
  42. void setCurrentLayer(int layer) { _currentLayer = layer;}
  43. int getCurrentLayer() const { return _currentLayer; }
  44. const std::vector<FrameAction>& getStackedFrameAction() const { return _stackFrameAction; }
  45. virtual void apply(Action& action);
  46. virtual void apply(Timeline& tm);
  47. virtual void apply(ActionBlendIn& action);
  48. virtual void apply(ActionBlendOut& action);
  49. virtual void apply(ActionAnimation& action);
  50. virtual void apply(ActionStripAnimation& action);
  51. protected:
  52. std::vector<FrameAction> _stackFrameAction;
  53. std::vector<Timeline*> _stackTimeline;
  54. int _currentLayer;
  55. };
  56. class OSGANIMATION_EXPORT UpdateActionVisitor : public osgAnimation::ActionVisitor
  57. {
  58. protected:
  59. unsigned int _frame;
  60. unsigned int _currentAnimationPriority;
  61. public:
  62. META_ActionVisitor(osgAnimation, UpdateActionVisitor);
  63. UpdateActionVisitor();
  64. void setFrame(unsigned int frame) { _frame = frame;}
  65. bool isActive(Action& action) const;
  66. unsigned int getLocalFrame() const;
  67. void apply(Timeline& action);
  68. void apply(Action& action);
  69. void apply(ActionBlendIn& action);
  70. void apply(ActionBlendOut& action);
  71. void apply(ActionAnimation& action);
  72. void apply(ActionStripAnimation& action);
  73. };
  74. class OSGANIMATION_EXPORT ClearActionVisitor : public osgAnimation::ActionVisitor
  75. {
  76. public:
  77. enum ClearType {
  78. BEFORE_FRAME,
  79. AFTER_FRAME
  80. };
  81. META_ActionVisitor(osgAnimation, ClearActionVisitor);
  82. ClearActionVisitor(ClearType type = BEFORE_FRAME);
  83. void setFrame(unsigned int frame) { _frame = frame;}
  84. void apply(Timeline& action);
  85. void apply(Action& action);
  86. protected:
  87. unsigned int _frame;
  88. std::vector<osg::ref_ptr<Action> > _remove;
  89. ClearType _clearType;
  90. };
  91. }
  92. #endif