Commits

Anonymous committed 8eb77aa

optimized raycast for rays that escape map

  • Participants
  • Parent commits 22a7583

Comments (0)

Files changed (1)

src/main/java/net/fishbulb/jcod/fov/FovAlgorithm.java

         private final int r2;
         private final boolean includeWalls;
 
+        private boolean inside = false;
+
         RayCast(int xo, int yo, int xd, int yd, int r, boolean includeWalls) {
             this.xo = xo;
             this.yo = yo;
         }
 
         @Override public boolean apply(int x, int y) {
-            if (r2 > 0 && ((x - xo) *(x - xo) + (y - yo) * (y - yo)) > r2) return true;
-            if (!map.contains(x,y)) return true;
+            if (r2 > 0 && ((x - xo) *(x - xo) + (y - yo) * (y - yo)) > r2) return false;
+            if (!map.contains(x,y)) return !inside;
+            inside = true;
             if (map.isTransparent(x,y)) {
                 map.setFov(x, y, true);
             } else {