scene.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // scene.hpp
  3. // engine
  4. //
  5. // Created by Sam Jaffe on 9/2/16.
  6. //
  7. #pragma once
  8. #include <memory>
  9. #include <unordered_map>
  10. #include <vector>
  11. #include "game/graphics/graphics_fwd.h"
  12. #include "game/math/math_fwd.hpp"
  13. #include "game/util/identity.hpp"
  14. #include "vector/vector.hpp"
  15. #include "engine_fwd.hpp"
  16. namespace engine {
  17. class scene : public identity<scene, std::string> {
  18. public:
  19. scene(std::string const &, std::shared_ptr<game_dispatch>);
  20. virtual ~scene();
  21. virtual void update(float delta) = 0;
  22. virtual void render(graphics::renderer & renderer) = 0;
  23. virtual void handle_key_event(event::key_event evt);
  24. virtual void handle_mouse_event(event::mouse_event evt);
  25. math::vec2 size() const;
  26. key_binding const & keys() const;
  27. protected:
  28. graphics::manager const & graphics_manager() const;
  29. void change_scene(std::string const & scene_id);
  30. void check_collisions();
  31. static void check_collisions(std::vector<collidable *> const & from,
  32. std::vector<collidable *> const & to);
  33. protected:
  34. std::vector<entity> entities;
  35. // Map from entity::collides_with -> [entity*]
  36. std::unordered_map<collision_t, std::vector<collidable *>> colliders;
  37. // Map from entity::collides_as -> [entity*]
  38. std::unordered_map<collision_t, std::vector<collidable *>> collidables;
  39. private:
  40. math::vec2 local_scene_dimension_;
  41. key_binding keys_;
  42. std::weak_ptr<game_dispatch> dispatch_;
  43. };
  44. }