Anonymous avatar Anonymous committed 1b9c608

condensed wall postProcess code

Comments (0)

Files changed (1)

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

 
     @Override
     public void computeFov(int x, int y, int maxRadius, boolean walls) {
-        int xo,yo;
-        int xmin=0;
-        int ymin=0;
-        int xmax=map.getWidth();
-        int ymax=map.getHeight();
-        int r2=maxRadius*maxRadius;
-        if ( maxRadius > 0 ) {
-            xmin=max(0, x- maxRadius);
-            ymin=max(0, y - maxRadius);
-            xmax=min(map.getWidth(), x+ maxRadius + 1);
-            ymax=min(map.getHeight(), y + maxRadius + 1);
+        int xo, yo;
+        int xmin = 0;
+        int ymin = 0;
+        int xmax = map.getWidth();
+        int ymax = map.getHeight();
+        int r2 = maxRadius * maxRadius;
+        if (maxRadius > 0) {
+            xmin = max(0, x - maxRadius);
+            ymin = max(0, y - maxRadius);
+            xmax = min(map.getWidth(), x + maxRadius + 1);
+            ymax = min(map.getHeight(), y + maxRadius + 1);
         }
         map.clearFov();
-        
-        xo=xmin; yo=ymin;
-        while ( xo < xmax ) {
-            castRay(x,y,xo++,yo,r2,walls);
+
+        xo = xmin; yo = ymin;
+        while (xo < xmax) {
+            castRay(x, y, xo++, yo, r2, walls);
         }
-        xo=xmax-1;yo=ymin+1;
-        while ( yo < ymax ) {
-            castRay(x,y,xo,yo++,r2,walls);
+        xo = xmax - 1; yo = ymin + 1;
+        while (yo < ymax) {
+            castRay(x, y, xo, yo++, r2, walls);
         }
-        xo=xmax-2;yo=ymax-1;
-        while ( xo >= 0 ) {
-            castRay(x,y,xo--,yo,r2,walls);
+        xo = xmax - 2; yo = ymax - 1;
+        while (xo >= 0) {
+            castRay(x, y, xo--, yo, r2, walls);
         }
-        xo=xmin;yo=ymax-2;
-        while ( yo > 0 ) {
-            castRay(x,y,xo,yo--,r2,walls);
+        xo = xmin; yo = ymax - 2;
+        while (yo > 0) {
+            castRay(x, y, xo, yo--, r2, walls);
         }
-        if ( walls ) {
+        if (walls) {
             // post-processing artefact fix
-            postProcess(xmin,ymin,x,y,-1,-1);
-            postProcess(x,ymin,xmax-1,y,1,-1);
-            postProcess(xmin,y,x,ymax-1,-1,1);
-            postProcess(x,y,xmax-1,ymax-1,1,1);
+            postProcess(xmin, ymin, x, y, -1, -1);
+            postProcess(x, ymin, xmax - 1, y, 1, -1);
+            postProcess(xmin, y, x, ymax - 1, -1, 1);
+            postProcess(x, y, xmax - 1, ymax - 1, 1, 1);
         }
     }
 
 
-    void postProcess(int x0,int y0, int x1, int y1, int dx, int dy) {
-        int cx,cy;
-        for (cx=x0; cx <= x1; cx++) {
-            for (cy=y0;cy <= y1; cy ++ ) {
-                int x2 = cx+dx;
-                int y2 = cy+dy;
-                if (map.contains(cx,cy) && map.isFov(cx,cy) && map.isTransparent(cx,cy)) {
-                    if ( x2 >= x0 && x2 <= x1 ) {
-                        if ( map.contains(x2, cy) && ! map.isTransparent(x2,cy) )
-                            map.setFov(x2, cy,true);
-                    }
-                    
-                    if ( y2 >= y0 && y2 <= y1 ) {
-                        if ( map.contains(cx, y2) && ! map.isTransparent(cx,y2) )
-                            map.setFov(cx, y2,true);
-                    }
-                    
-                    if ( x2 >= x0 && x2 <= x1 && y2 >= y0 && y2 <= y1 ) {
-                        if ( map.contains(x2, y2) && ! map.isTransparent(x2,y2) )
-                            map.setFov(x2, y2,true);
-                    }
-                }
+    void postProcess(int x0, int y0, int x1, int y1, int dx, int dy) {
+        int cx, cy;
+        for (cx = x0; cx <= x1; cx++) {
+            for (cy = y0; cy <= y1; cy++) {
+                int x2 = cx + dx;
+                int y2 = cy + dy;
+                if (!(map.contains(cx, cy) && map.isFov(cx, cy) && map.isTransparent(cx, cy)))
+                    continue;
+
+                if (x2 >= x0 && x2 <= x1 && map.contains(x2, cy) && !map.isTransparent(x2, cy))
+                    map.setFov(x2, cy, true);
+
+                if (y2 >= y0 && y2 <= y1 && map.contains(cx, y2) && !map.isTransparent(cx, y2))
+                    map.setFov(cx, y2, true);
+
+                if (x2 >= x0 && x2 <= x1 && y2 >= y0 && y2 <= y1 && map.contains(x2, y2) && !map.isTransparent(x2, y2))
+                    map.setFov(x2, y2, true);
             }
         }
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.