Event.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef ANKI_EVENT_EVENT_H
  2. #define ANKI_EVENT_EVENT_H
  3. namespace anki {
  4. /// Abstract class for all events. All Event derived classes should be copy-able
  5. /// In order to recycle the events and save the mallocs
  6. class Event
  7. {
  8. public:
  9. /// The event type enum
  10. enum EventType
  11. {
  12. ET_SCENE_COLOR,
  13. ET_MAIN_RENDERER_PPS_HDR,
  14. ET_COUNT
  15. };
  16. /// Constructor
  17. Event(EventType type, float startTime, float duration);
  18. /// Copy constructor
  19. Event(const Event& b)
  20. {
  21. *this = b;
  22. }
  23. virtual ~Event();
  24. /// @name Accessors
  25. /// @{
  26. float getStartTime() const
  27. {
  28. return startTime;
  29. }
  30. float getDuration() const
  31. {
  32. return duration;
  33. }
  34. EventType getEventType() const
  35. {
  36. return type;
  37. }
  38. bool isDead(float crntTime) const
  39. {
  40. return crntTime >= startTime + duration;
  41. }
  42. /// @}
  43. /// Copy
  44. Event& operator=(const Event& b);
  45. /// @param[in] prevUpdateTime The time of the previous update (sec)
  46. /// @param[in] crntTime The current time (sec)
  47. void update(float prevUpdateTime, float crntTime);
  48. protected:
  49. /// This method should be implemented by the derived classes
  50. virtual void updateSp(float prevUpdateTime, float crntTime) = 0;
  51. /// Linear interpolation between values
  52. /// @param[in] from Starting value
  53. /// @param[in] to Ending value
  54. /// @param[in] delta The percentage from the from "from" value. Values
  55. /// from [0.0, 1.0]
  56. template<typename Type>
  57. static Type interpolate(const Type& from, const Type& to, float delta)
  58. {
  59. return from * (1.0 - delta) + to * delta;
  60. }
  61. private:
  62. EventType type; ///< Self explanatory
  63. float startTime; ///< The time the event will start. Eg 23:00
  64. float duration; ///< The duration of the event
  65. };
  66. } // end namespace
  67. #endif