game_dispatch.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "time.hpp"
  12. #include "engine_fwd.hpp"
  13. #include "events.hpp"
  14. #include "math/math_fwd.hpp"
  15. #include "math/vector.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. [[noreturn]] void gameloop( );
  23. void quit( );
  24. private:
  25. void single_frame( tick t ) { }
  26. tick get_tick( );
  27. tick next_frame( );
  28. void cleanup_resources( ) { } // TODO ???
  29. private:
  30. math::vec2 screen_size;
  31. duration minimum_frame_duration;
  32. using scene_t = std::unique_ptr<scene>;
  33. std::unordered_map<scene_id_t, scene_t> scenes;
  34. bool running = true;
  35. timestamp current_timestamp;
  36. struct current_scene_info {
  37. current_scene_info( );
  38. current_scene_info( scene * );
  39. scene * ptr; // weak
  40. std::string current_scene_id; // metadata
  41. math::vec2 local_size; // metadata
  42. bool is_mouse_event;
  43. bool is_keyboard_event;
  44. } curr_scene;
  45. };
  46. }