scene.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // scene.cpp
  3. // engine
  4. //
  5. // Created by Sam Jaffe on 9/2/16.
  6. //
  7. #include "game/engine/scene.hpp"
  8. #include "game/engine/entity.hpp"
  9. #include "game/engine/events.hpp"
  10. #include "game/engine/game_dispatch.hpp"
  11. #include "game/graphics/renderer.hpp"
  12. #include "game/math/common.hpp"
  13. using namespace engine;
  14. scene::~scene() {}
  15. void scene::update(float delta) {
  16. for (auto & ent : entities) {
  17. ent.update(delta);
  18. }
  19. for (auto & pair : colliders) {
  20. auto & collidable = collidables[pair.first];
  21. for (auto & ent : pair.second) {
  22. for (auto & hit : collidable) {
  23. if (math::intersects(ent->render_info().points,
  24. hit->render_info().points)) {
  25. ent->collide(*hit);
  26. }
  27. }
  28. }
  29. }
  30. }
  31. void scene::render() {
  32. for (auto & ent : entities) {
  33. renderer->draw(ent.render_info());
  34. }
  35. }
  36. void scene::handle_key_event(event::key_event evt) {
  37. if (evt.type & event::PRESSED_MASK && evt.key == keys::QUIT) {
  38. dispatch_.lock()->quit();
  39. }
  40. }
  41. void scene::handle_mouse_event(event::mouse_event evt) {}
  42. math::vec2 scene::size() const { return local_scene_dimension_; }
  43. key_binding const & scene::keys() const { return keys_; }