Browse Source

Push bounds check into scene.

Sam Jaffe 6 years ago
parent
commit
956fee0625
2 changed files with 14 additions and 0 deletions
  1. 2 0
      engine/include/game/engine/scene.hpp
  2. 12 0
      engine/src/scene.cpp

+ 2 - 0
engine/include/game/engine/scene.hpp

@@ -35,6 +35,8 @@ namespace engine {
   protected:
     graphics::manager const & graphics_manager() const;
     void change_scene(std::string const & scene_id);
+    bool in_bounds(math::dim2::point c) const;
+    bool in_bounds(collidable * c) const;
     void check_collisions();
     static void check_collisions(std::vector<collidable *> const & from,
                                  std::vector<collidable *> const & to);

+ 12 - 0
engine/src/scene.cpp

@@ -12,6 +12,7 @@
 #include "game/engine/game_dispatch.hpp"
 #include "game/graphics/renderer.hpp"
 #include "game/math/common.hpp"
+#include "game/math/compare.hpp"
 
 using namespace engine;
 
@@ -20,6 +21,17 @@ scene::scene(std::string const & str, std::shared_ptr<game_dispatch> dispatch)
 
 scene::~scene() {}
 
+bool scene::in_bounds(math::dim2::point p) const {
+  return math::between(p[0], 0.f, local_scene_dimension_[0]) &&
+         math::between(p[1], 0.f, local_scene_dimension_[1]);
+}
+
+bool scene::in_bounds(collidable * c) const {
+  auto & quad = c->render_info().points;
+  return in_bounds(quad.ll) || in_bounds(quad.lr) || in_bounds(quad.ur) ||
+         in_bounds(quad.ul);
+}
+
 void scene::check_collisions(std::vector<collidable *> const & from,
                              std::vector<collidable *> const & to) {
   for (auto & ent : from) {