scene.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. bool in_bounds(math::dim2::point c) const;
  31. bool in_bounds(collidable * c) const;
  32. void check_collisions();
  33. static void check_collisions(std::vector<collidable *> const & from,
  34. std::vector<collidable *> const & to);
  35. protected:
  36. std::vector<entity> entities;
  37. // Map from entity::collides_with -> [entity*]
  38. std::unordered_map<collision_t, std::vector<collidable *>> colliders;
  39. // Map from entity::collides_as -> [entity*]
  40. std::unordered_map<collision_t, std::vector<collidable *>> collidables;
  41. private:
  42. math::vec2 local_scene_dimension_;
  43. key_binding keys_;
  44. std::weak_ptr<game_dispatch> dispatch_;
  45. };
  46. }