screen_manager.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // 2014 Ingo Ruhnke <grumbel@gmail.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program 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. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef HEADER_SUPERTUX_SUPERTUX_SCREEN_MANAGER_HPP
  18. #define HEADER_SUPERTUX_SUPERTUX_SCREEN_MANAGER_HPP
  19. #include <memory>
  20. #include <SDL.h>
  21. #include "config.h"
  22. #include "control/mobile_controller.hpp"
  23. #include "squirrel/squirrel_thread_queue.hpp"
  24. #include "supertux/screen.hpp"
  25. #include "util/currenton.hpp"
  26. class Compositor;
  27. class ControllerHUD;
  28. class DrawingContext;
  29. class InputManager;
  30. class MenuManager;
  31. class MenuStorage;
  32. class ScreenFade;
  33. class VideoSystem;
  34. /**
  35. * Manages, updates and draws all Screens, Controllers, Menus and the Console.
  36. */
  37. class ScreenManager final : public Currenton<ScreenManager>
  38. {
  39. public:
  40. ScreenManager(VideoSystem& video_system, InputManager& input_manager);
  41. ~ScreenManager() override;
  42. void run();
  43. void quit(std::unique_ptr<ScreenFade> fade = {});
  44. void set_speed(float speed);
  45. float get_speed() const;
  46. bool has_pending_fadeout() const;
  47. // push new screen on screen_stack
  48. void push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> fade = {});
  49. void pop_screen(std::unique_ptr<ScreenFade> fade = {});
  50. void set_screen_fade(std::unique_ptr<ScreenFade> fade);
  51. void loop_iter();
  52. const std::vector<std::unique_ptr<Screen>>& get_screen_stack() { return m_screen_stack; }
  53. private:
  54. struct FPS_Stats;
  55. void draw_fps(DrawingContext& context, FPS_Stats& fps_statistics);
  56. void draw_player_pos(DrawingContext& context);
  57. void draw(Compositor& compositor, FPS_Stats& fps_statistics);
  58. void update_gamelogic(float dt_sec);
  59. void process_events();
  60. void handle_screen_switch();
  61. private:
  62. VideoSystem& m_video_system;
  63. InputManager& m_input_manager;
  64. std::unique_ptr<MenuStorage> m_menu_storage;
  65. std::unique_ptr<MenuManager> m_menu_manager;
  66. std::unique_ptr<ControllerHUD> m_controller_hud;
  67. MobileController m_mobile_controller;
  68. Uint32 last_ticks;
  69. Uint32 elapsed_ticks;
  70. const Uint32 ms_per_step;
  71. const float seconds_per_step;
  72. std::unique_ptr<FPS_Stats> m_fps_statistics;
  73. float m_speed;
  74. struct Action
  75. {
  76. enum Type { PUSH_ACTION, POP_ACTION, QUIT_ACTION };
  77. Type type;
  78. std::unique_ptr<Screen> screen;
  79. Action(Type type_,
  80. std::unique_ptr<Screen> screen_ = {}) :
  81. type(type_),
  82. screen(std::move(screen_))
  83. {}
  84. };
  85. std::vector<Action> m_actions;
  86. std::unique_ptr<ScreenFade> m_screen_fade;
  87. std::vector<std::unique_ptr<Screen> > m_screen_stack;
  88. };
  89. #endif
  90. /* EOF */