BsAnimationManager.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. struct AnimationProxy;
  9. /** @addtogroup Animation-Internal
  10. * @{
  11. */
  12. /**
  13. * Keeps track of all active animations, queues animation thread tasks and synchronizes data between simulation, core
  14. * and animation threads.
  15. */
  16. class AnimationManager : public Module<AnimationManager>
  17. {
  18. public:
  19. AnimationManager();
  20. /** Pauses or resumes the animation evaluation. */
  21. void setPaused(bool paused);
  22. /**
  23. * Determines how often to evaluate animations. If rendering is not running at adequate framerate the animation
  24. * could end up being evaluated less times than specified here.
  25. *
  26. * @param[in] fps Number of frames per second to evaluate the animation. Default is 60.
  27. */
  28. void setUpdateRate(UINT32 fps);
  29. /**
  30. * Synchronizes animation data from the animation thread with the scene objects. Should be called before component
  31. * updates are sent.
  32. */
  33. void preUpdate();
  34. /**
  35. * Synchronizes animation data to the animation thread, advances animation time and queues new animation evaluation
  36. * task.
  37. */
  38. void postUpdate();
  39. private:
  40. friend class Animation;
  41. /**
  42. * Registers a new animation and returns a unique ID for it. Must be called whenever an Animation is constructed.
  43. */
  44. UINT64 registerAnimation(Animation* anim);
  45. /** Unregisters an animation with the specified ID. Must be called before an Animation is destroyed. */
  46. void unregisterAnimation(UINT64 id);
  47. /** Worker method ran on the animation thread that evaluates all animation at the provided time. */
  48. void evaluateAnimation();
  49. UINT64 mNextId;
  50. UnorderedMap<UINT64, Animation*> mAnimations;
  51. float mUpdateRate;
  52. float mAnimationTime;
  53. float mLastAnimationUpdateTime;
  54. float mNextAnimationUpdateTime;
  55. bool mPaused;
  56. bool mWorkerRunning;
  57. SPtr<Task> mAnimationWorker;
  58. Vector<SPtr<AnimationProxy>> mProxies;
  59. };
  60. /** @} */
  61. }