game_dispatch.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/util/time.hpp"
  16. namespace engine {
  17. class game_dispatch {
  18. public:
  19. game_dispatch();
  20. void process_key_event(raw_key_t key, bool press);
  21. void process_mouse_event(math::vec2 click, bool press);
  22. bool is_running() const { return running; }
  23. void quit() { running = false; }
  24. public:
  25. void update();
  26. void render();
  27. private:
  28. float next_frame();
  29. tick get_tick();
  30. private:
  31. math::vec2 screen_size;
  32. duration minimum_frame_duration;
  33. using scene_t = std::shared_ptr<scene>;
  34. std::unordered_map<scene_id_t, scene_t> scenes;
  35. bool running = true;
  36. timestamp current_timestamp;
  37. struct current_scene_info {
  38. current_scene_info();
  39. current_scene_info(scene *);
  40. scene_t ptr;
  41. std::string current_scene_id; // metadata
  42. math::vec2 local_size; // metadata
  43. bool is_mouse_event;
  44. bool is_keyboard_event;
  45. } curr_scene;
  46. };
  47. }