Anonymous avatar Anonymous committed c2e8ae6

gardening (tearing it up more like)

Comments (0)

Files changed (5)

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

+package net.fishbulb.jcod.fov;
+
+import lombok.Getter;
+import net.fishbulb.jcod.util.PlotFunction;
+
+class BasicLOSFunction implements PlotFunction {
+    private float[][] resistanceMap;
+    private final int startx;
+    private final int starty;
+    float currentForce;
+    private final float decay;
+    private final RadiusStrategy radiusStrategy;
+
+    @Getter
+    boolean reachable = true;
+
+    BasicLOSFunction(float[][] resistanceMap, int startx, int starty, float currentForce, float decay, RadiusStrategy radiusStrategy) {
+        this.resistanceMap = resistanceMap;
+        this.startx = startx;
+        this.starty = starty;
+        this.currentForce = currentForce;
+        this.decay = decay;
+        this.radiusStrategy = radiusStrategy;
+    }
+
+    @Override
+    public boolean apply(int x, int y, float val) {
+        if (x != startx || y != starty) {
+            currentForce *= (1 - resistanceMap[x][y]);
+        }
+        double radius = radiusStrategy.radius(startx, starty, x, y);
+        reachable = currentForce - (radius * decay) > 0;
+        return reachable;
+    }
+}

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

 package net.fishbulb.jcod.fov;
 
-import lombok.Getter;
-import net.fishbulb.jcod.util.PlotFunction;
-
 import static net.fishbulb.jcod.util.PlotAlgorithms.Bresenham;
 
 /**
  * Adapted from SquidPony implementation by Eben Howard - http://squidpony.com - howard@squidpony.com
  */
 public class BresenhamLOS implements LOSSolver {
-    class LOSFunction implements PlotFunction {
-        private float[][] resistanceMap;
-        private final int startx;
-        private final int starty;
-        float currentForce;
-        private final float decay;
-        private final RadiusStrategy radiusStrategy;
-
-        @Getter
-        boolean reachable = true;
-
-        LOSFunction(float[][] resistanceMap, int startx, int starty, float currentForce, float decay, RadiusStrategy radiusStrategy) {
-            this.resistanceMap = resistanceMap;
-            this.startx = startx;
-            this.starty = starty;
-            this.currentForce = currentForce;
-            this.decay = decay;
-            this.radiusStrategy = radiusStrategy;
-        }
-
-        @Override public boolean apply(int x, int y, float val) {
-            if (x != startx || y != starty) {
-                currentForce *= (1 - resistanceMap[x][y]);
-            }
-            double radius = radiusStrategy.radius(startx, starty, x, y);
-            reachable = currentForce - (radius * decay) > 0;
-            return reachable;
-        }
-    }
-
     @Override
     public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety, float force, float decay, RadiusStrategy radiusStrategy) {
-        LOSFunction solver = new LOSFunction(resistanceMap, startx, starty, force, decay, radiusStrategy);
+        BasicLOSFunction solver = new BasicLOSFunction(resistanceMap, startx, starty, force, decay, radiusStrategy);
         Bresenham.apply(startx, starty, targetx, targety, solver);
         return solver.isReachable();
     }

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

 /**
  * Represents the eight grid directions and the deltaX, deltaY values associated
  * with those directions.
- *
+ * <p/>
  * The grid referenced has x positive to the right and y positive downwards.
  *
  * @author Eben Howard - http://squidpony.com - howard@squidpony.com
     /**
      * Returns the direction that most closely matches the input.
      *
-     * @param x
-     * @param y
-     * @return
+     * @param x X coordinate relative to starting position
+     * @param y Y coordinate relative to starting position (positive is down)
+     * @return Direction closest to the line from origin to point
      */
     static public Direction getDirection(int x, int y) {
         if (x < 0) {
         }
     }
 
-    /**
-     * Returns the Direction one step clockwise including diagonals.
-     *
-     */
+    /** Returns the Direction one step clockwise including diagonals. */
     public Direction clockwise() {
         switch (this) {
             case UP:
         }
     }
 
-    /**
-     * Returns the Direction one step counterclockwise including diagonals.
-     *
-     */
+    /** Returns the Direction one step counterclockwise including diagonals. */
     public Direction counterClockwise() {
         switch (this) {
             case UP:
         }
     }
 
-    /**
-     * Returns the direction directly opposite of this one.
-     *
-     * @return
-     */
+    /** Returns the direction directly opposite of this one. */
     public Direction opposite() {
         switch (this) {
             case UP:

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

  * For information on the sideview parameter, see the EliasLOS documentation.
  *
  * @author Eben Howard - http://squidpony.com - howard@squidpony.com
+ *
+ * @deprecated uses the broken EliasLOS
  */
 @Beta
+@Deprecated
 public class EliasFOV implements FOVSolver {
 
     private float[][] lightMap, resistanceMap;

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

 import java.util.List;
 
 /**
- * Uses Wu's Algorithm as modified by Elias to draw the line.
+ * A first stab at a "fuzzy" LOS using Hugo Elias's modification of Wu's algorithm.
  * <p/>
- * The side view parameter is how far along the antialiased path to consider
- * when determining if the far end can be seen, from 0.0 to 1.0 with 1.0
- * considering the entire line. The closer to 1.0 this value is, the more
- * complete and symmetrical end-to-end the line is, but the computation cost
- * also increases.
- * <p/>
- * If undesired artifacts are seen when running the lines (missing squares
- * perhaps), try increasing the sideview value.
+ * Portions of this code are from SquidLib
  *
- * @author Eben Howard - http://squidpony.com - howard@squidpony.com
+ * @deprecated JCOD port of EliasLOS is seriously busted at the moment
  */
 @Beta
+@Deprecated
 public class EliasLOS implements LOSSolver {
-
     private float sideview = 0.75f;
 
-    /** Creates this solver with the default side view parameter. */
+    private BresenhamLOS los = new BresenhamLOS();
+
     public EliasLOS() {
     }
 
-    /**
-     * Creates this solver with the provided value for how far along the
-     * antialiased line the antialiased portion will be considered.
-     *
-     * @param sideview
-     */
     public EliasLOS(float sideview) {
         this.sideview = sideview;
     }
 
-    public float getSideview() {
-        return sideview;
-    }
-
-    public void setSideview(float sideview) {
-        this.sideview = sideview;
-    }
-
     @Override
     public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety, float force, float decay, RadiusStrategy radiusStrategy) {
         List<Point> path = Elias.line(startx, starty, targetx, targety);
 
-        BresenhamLOS los1 = new BresenhamLOS();
-        BresenhamLOS los2 = new BresenhamLOS();
+        // XXX HMM this looks seriously wrong to me
+        float checkRadius = radiusStrategy.radius(startx, starty) * sideview;
 
-        float checkRadius = radiusStrategy.radius(startx, starty) * 0.75f;
         while (!path.isEmpty()) {
             Point p = path.remove(0);
 
             //if a non-solid midpoint on the path can see both the start and end, consider the two ends to be able to see each other
             if (resistanceMap[p.x][p.y] < 1
                     && radiusStrategy.radius(startx, starty, p.x, p.y) < checkRadius
-                    && los1.isReachable(resistanceMap, p.x, p.y, targetx, targety, force - (radiusStrategy.radius(startx, starty, p.x, p.y) * decay), decay, radiusStrategy)
-                    && los2.isReachable(resistanceMap, startx, starty, p.x, p.y, force, decay, radiusStrategy)) {
+                    && los.isReachable(resistanceMap, p.x, p.y, targetx, targety, force - (radiusStrategy.radius(startx, starty, p.x, p.y) * decay), decay, radiusStrategy)
+                    && los.isReachable(resistanceMap, startx, starty, p.x, p.y, force, decay, radiusStrategy)) {
 
                 return 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.