MovieState.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. /**
  17. * The clock of a movie: which frame is shown at each moment, and when it ends.
  18. *
  19. * It has no knowledge of the video or the screen. It's separated from {@see MoviePlayer} so its
  20. * rules can be tested.
  21. */
  22. class MovieState{
  23. public:
  24. /**
  25. * Frame reported when there is no movie to play. It's high so the scripts that wait for a
  26. * frame of the movie to continue don't wait for ever.
  27. */
  28. static const int NO_MOVIE_FRAME = 32767;
  29. /**
  30. * Starts the movie from its first frame.
  31. *
  32. * @param[in] frame_count Number of frames of the movie.
  33. * @param[in] frames_per_second Frames shown per second.
  34. */
  35. void Start(const int frame_count, const float frames_per_second);
  36. /**
  37. * Chooses a movie without playing it. Until it starts the frame is 0, which is what the
  38. * scripts that wait for a frame of the movie expect before it starts.
  39. */
  40. void Prepare();
  41. /**
  42. * Stops the movie. The frame it reaches is kept.
  43. */
  44. void Stop();
  45. /**
  46. * Moves the clock forward.
  47. *
  48. * @param[in] seconds Seconds since the last update.
  49. * @return True if the movie ended in this update.
  50. */
  51. bool Advance(const float seconds);
  52. /**
  53. * @return True while the movie is being played.
  54. */
  55. bool IsPlaying() const;
  56. /**
  57. * Retrieves the frame that must be shown.
  58. *
  59. * @return The frame, starting at 0. When the movie ended, the number of frames. If there
  60. * was no movie, {@see NO_MOVIE_FRAME}.
  61. */
  62. int GetFrame() const;
  63. private:
  64. /**
  65. * Whether the movie is being played.
  66. */
  67. bool playing_ = false;
  68. /**
  69. * Whether a movie has been started.
  70. */
  71. bool started_ = false;
  72. /**
  73. * Number of frames of the movie.
  74. */
  75. int frame_count_ = 0;
  76. /**
  77. * Frames per second.
  78. */
  79. float frames_per_second_ = 15.0f;
  80. /**
  81. * Seconds played.
  82. */
  83. float elapsed_ = 0;
  84. };