Anonymous avatar Anonymous committed 37bac51

applied wall lighting fixups

Comments (0)

Files changed (2)

src/main/java/net/fishbulb/jcod/demo/Fov.java

         console.clear();
         console.setDefaultForeground(Color.BLACK);
         console.putChar(px, py, '@', BlendMode.None);
-        algo.computeFov(px, py, 10, false);
+        algo.computeFov(px, py, 0, true);
 
         for (int y = 0; y < height; y++) {
             for (int x = 0; x < width; x++) {
                 switch (c) {
                     case '=':
                         console.putChar(x, y, CharCodes.OEM.DHLINE, BlendMode.None);
+                    case ' ':
                         console.setCharBackground(x, y, lit ? lightGround : darkGround);
                         break;
                     case '#':
                         console.setCharBackground(x, y, lit ? lightWall : darkWall);
                         break;
-                    case ' ':
-                        console.setCharBackground(x, y, lit ? lightGround : darkGround);
-                        break;
                 }
             }
         }

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

         while ( yo > 0 ) {
             castRay(x,y,xo,yo--,r2,walls);
         }
-//        if ( walls ) {
-//		/* post-processing artefact fix */
-//            TCOD_map_postproc(m,xmin,ymin,x,y,-1,-1);
-//            TCOD_map_postproc(m,x,ymin,xmax-1,y,1,-1);
-//            TCOD_map_postproc(m,xmin,y,x,ymax-1,-1,1);
-//            TCOD_map_postproc(m,x,y,xmax-1,ymax-1,1,1);
-//        }
+        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);
+        }
     }
 
 
+    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);
+                    }
+                }
+            }
+        }
+    }
+
+
 }
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.