scene.hpp 1.2 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/math/math_fwd.hpp"
  12. #include "game/util/identity.hpp"
  13. #include "vector/vector.hpp"
  14. #include "engine_fwd.hpp"
  15. namespace graphics {
  16. class renderer;
  17. }
  18. namespace engine {
  19. class entity;
  20. class scene : public identity<scene, std::string> {
  21. public:
  22. using identity<scene, std::string>::identity;
  23. virtual ~scene();
  24. virtual void update(float delta);
  25. virtual void render();
  26. virtual void handle_key_event(event::key_event evt);
  27. virtual void handle_mouse_event(event::mouse_event evt);
  28. math::vec2 size() const;
  29. key_binding const & keys() const;
  30. protected:
  31. void change_scene(std::string const & scene_id);
  32. protected:
  33. graphics::renderer * renderer;
  34. std::vector<entity> entities;
  35. // Map from entity::collides_with -> [entity*]
  36. std::unordered_map<collision_t, std::vector<entity *>> colliders;
  37. // Map from entity::collides_as -> [entity*]
  38. std::unordered_map<collision_t, std::vector<entity *>> collidables;
  39. private:
  40. math::vec2 local_scene_dimension_;
  41. key_binding keys_;
  42. std::weak_ptr<game_dispatch> dispatch_;
  43. };
  44. }