game_dispatch.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // game_dispatch.hpp
  3. // gameutils
  4. //
  5. // Created by Sam Jaffe on 9/2/16.
  6. //
  7. #pragma once
  8. #include <chrono>
  9. #include <memory>
  10. #include <unordered_map>
  11. #include "game/math/math_fwd.hpp"
  12. #include "vector/vector.hpp"
  13. #include "engine_fwd.hpp"
  14. #include "events.hpp"
  15. #include "game/graphics/graphics_fwd.h"
  16. #include "game/util/time.hpp"
  17. namespace engine {
  18. class game_dispatch {
  19. public:
  20. game_dispatch(std::shared_ptr<graphics::renderer> renderer);
  21. ~game_dispatch();
  22. void process_key_event(raw_key_t key, bool press);
  23. void process_mouse_event(math::vec2 click, bool press);
  24. bool is_running() const { return running; }
  25. void quit() { running = false; }
  26. public:
  27. void update();
  28. void render();
  29. private:
  30. env::clock::tick next_frame();
  31. private:
  32. std::shared_ptr<graphics::renderer> renderer;
  33. math::vec2 screen_size;
  34. env::clock::duration minimum_frame_duration;
  35. std::unique_ptr<fps_counter> counter;
  36. using scene_t = std::shared_ptr<scene>;
  37. std::unordered_map<scene_id_t, scene_t> scenes;
  38. bool running = true;
  39. env::clock::timestamp current_timestamp;
  40. struct current_scene_info {
  41. current_scene_info();
  42. current_scene_info(scene *);
  43. scene_t ptr;
  44. std::string current_scene_id; // metadata
  45. math::vec2 local_size; // metadata
  46. bool is_mouse_event;
  47. bool is_keyboard_event;
  48. } curr_scene;
  49. };
  50. }