Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-t committed Nov 6, 2017
2 parents c680922 + 91fa594 commit 5c2fcfb
Show file tree
Hide file tree
Showing 19 changed files with 494 additions and 95 deletions.
385 changes: 378 additions & 7 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.fabioticconi</groupId>
<artifactId>rlforj-alt</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>
<packaging>jar</packaging>

<name>Roguelike Library For Java (Alternative version)</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rlforj.los;
package rlforj;

import rlforj.los.IFovAlgorithm;
import rlforj.los.ILosAlgorithm;
import rlforj.pathfinding.AStar;

/**
Expand All @@ -10,7 +12,7 @@
*
* @author sdatta
*/
public interface ILosBoard
public interface IBoard
{
/**
* Is the location (x, y) inside the board ?
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rlforj/examples/ExampleBoard.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package rlforj.examples;

import rlforj.los.ILosBoard;
import rlforj.IBoard;
import rlforj.math.Point;

import java.util.HashMap;
import java.util.Map;

public class ExampleBoard implements ILosBoard
public class ExampleBoard implements IBoard
{

public char visibleFloor = '.', invisibleFloor = ' ', invisibleWall = ' ';
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/rlforj/los/BresLos.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rlforj.los;

import rlforj.IBoard;
import rlforj.math.Point;
import rlforj.util.BresenhamLine;

Expand Down Expand Up @@ -27,10 +28,10 @@ public BresLos(final boolean symmetric)
symmetricEnabled = symmetric;
}

public boolean existsLineOfSight(final ILosBoard b, final int startX, final int startY, final int x1, final int y1, final boolean calculateProject)
public boolean existsLineOfSight(final IBoard b, final int startX, final int startY, final int endX, final int endY, final boolean calculateProject)
{
final int dx = startX - x1;
final int dy = startY - y1;
final int dx = startX - endX;
final int dy = startY - endY;
final int adx = dx > 0 ? dx : -dx;
final int ady = dy > 0 ? dy : -dy;
final int len = (adx > ady ? adx : ady) + 1;//Max number of points on the path.
Expand All @@ -43,7 +44,7 @@ public boolean existsLineOfSight(final ILosBoard b, final int startX, final int
final int[] py = new int[len];

//Start to finish path
BresenhamLine.plot(startX, startY, x1, y1, px, py);
BresenhamLine.plot(startX, startY, endX, endY, px, py);

boolean los = false;
for (int i = 0; i < len; i++)
Expand All @@ -52,7 +53,7 @@ public boolean existsLineOfSight(final ILosBoard b, final int startX, final int
{
path.add(new Point(px[i], py[i]));
}
if (px[i] == x1 && py[i] == y1)
if (px[i] == endX && py[i] == endY)
{
los = true;
break;
Expand All @@ -69,7 +70,7 @@ public boolean existsLineOfSight(final ILosBoard b, final int startX, final int
px1 = new int[len];
py1 = new int[len];
// finish to start path.
BresenhamLine.plot(x1, y1, startX, startY, px1, py1);
BresenhamLine.plot(endX, endY, startX, startY, px1, py1);

final Vector<Point> oldpath = path;
path = new Vector<>(len);
Expand All @@ -79,7 +80,7 @@ public boolean existsLineOfSight(final ILosBoard b, final int startX, final int
{
path.add(new Point(px1[i], py1[i]));
}
if (px1[i] == x1 && py1[i] == y1)
if (px1[i] == endX && py1[i] == endY)
{
los = true;
break;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/rlforj/los/BresOpportunisticLos.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rlforj.los;

import rlforj.IBoard;
import rlforj.math.Point;
import rlforj.util.BresenhamLine;

Expand All @@ -20,10 +21,10 @@ public class BresOpportunisticLos implements ILosAlgorithm

private Vector<Point> path;

public boolean existsLineOfSight(final ILosBoard b, final int startX, final int startY, final int x1, final int y1, final boolean calculateProject)
public boolean existsLineOfSight(final IBoard b, final int startX, final int startY, final int endX, final int endY, final boolean calculateProject)
{
final int dx = startX - x1;
final int dy = startY - y1;
final int dx = startX - endX;
final int dy = startY - endY;
final int adx = dx > 0 ? dx : -dx;
final int ady = dy > 0 ? dy : -dy;
final int len = (adx > ady ? adx : ady) + 1;
Expand All @@ -38,15 +39,15 @@ public boolean existsLineOfSight(final ILosBoard b, final int startX, final int
py1 = new int[len];

//Compute both paths
BresenhamLine.plot(startX, startY, x1, y1, px, py);
BresenhamLine.plot(x1, y1, startX, startY, px1, py1);
BresenhamLine.plot(startX, startY, endX, endY, px, py);
BresenhamLine.plot(endX, endY, startX, startY, px1, py1);

boolean los = false;
boolean alternatePath = false;
for (int i = 0; i < len; i++)
{
// Have we reached the end ? In that case quit
if (px[i] == x1 && py[i] == y1)
if (px[i] == endX && py[i] == endY)
{
if (calculateProject)
{
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/rlforj/los/ConePrecisePremisive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rlforj.los;

import rlforj.IBoard;
import rlforj.math.Point;

import java.util.LinkedList;
Expand All @@ -13,8 +14,8 @@
public class ConePrecisePremisive extends PrecisePermissive implements IConeFovAlgorithm
{

public void visitConeFieldOfView(final ILosBoard b, final int x, final int y, final int distance, int startAngle,
int finishAngle)
public void visitConeFieldOfView(final IBoard b, final int x, final int y, final int distance, int startAngle,
int endAngle)
{
if (startAngle % 90 == 0 && startAngle % 360 != 0)
startAngle--;//we dont like to start at 90, 180, 270
Expand All @@ -26,24 +27,24 @@ public void visitConeFieldOfView(final ILosBoard b, final int x, final int y, fi
startAngle %= 360;
startAngle += 360;
}
if (finishAngle < 0)
if (endAngle < 0)
{
finishAngle %= 360;
finishAngle += 360;
endAngle %= 360;
endAngle += 360;
}

if (startAngle > 360)
startAngle %= 360;
if (finishAngle > 360)
finishAngle %= 360;
if (endAngle > 360)
endAngle %= 360;

final permissiveMaskT mask = new permissiveMaskT();
mask.east = mask.north = mask.south = mask.west = distance;
mask.mask = null;
mask.fovType = FovType.CIRCLE;
mask.distPlusOneSq = (distance + 1) * (distance + 1);
mask.board = b;
permissiveConeFov(x, y, mask, startAngle, finishAngle);
permissiveConeFov(x, y, mask, startAngle, endAngle);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/rlforj/los/IConeFovAlgorithm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rlforj.los;

import rlforj.IBoard;

/**
* FOV along a cone. Give starting and finish angle.
* Note: Positive Y axis is down.
Expand All @@ -18,7 +20,7 @@ public interface IConeFovAlgorithm extends IFovAlgorithm
* @param y y position
* @param distance maximum distance of cone of view
* @param startAngle start angle
* @param finishAngle end angle
* @param endAngle end angle
*/
void visitConeFieldOfView(ILosBoard b, int x, int y, int distance, int startAngle, int finishAngle);
void visitConeFieldOfView(IBoard b, int x, int y, int distance, int startAngle, int endAngle);
}
4 changes: 3 additions & 1 deletion src/main/java/rlforj/los/IFovAlgorithm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rlforj.los;

import rlforj.IBoard;

/**
* An interface for FOV algorithms.
*
Expand All @@ -25,6 +27,6 @@ public interface IFovAlgorithm
* @param y Starting location:y
* @param distance How far can this Field of View go
*/
void visitFieldOfView(ILosBoard b, int x, int y, int distance);
void visitFieldOfView(IBoard b, int x, int y, int distance);

}
9 changes: 5 additions & 4 deletions src/main/java/rlforj/los/ILosAlgorithm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rlforj.los;

import rlforj.IBoard;
import rlforj.math.Point;

import java.util.List;
Expand All @@ -14,18 +15,18 @@ public interface ILosAlgorithm

/**
* Calculates if line of sight exists between point startX, startY and
* x1, y1. Optionally calculate the path of projection.
* endX, y1. Optionally calculate the path of projection.
*
* @param b The board to be visited.
* @param startX Starting position:x
* @param startY Starting position:y
* @param x1 Target location:x
* @param y1 Target location:y
* @param endX Target location:x
* @param endY Target location:y
* @param calculateProject Whether to also calculate the path from the
* source to the target.
* @return true if a line of sight could be established
*/
boolean existsLineOfSight(ILosBoard b, int startX, int startY, int x1, int y1, boolean calculateProject);
boolean existsLineOfSight(IBoard b, int startX, int startY, int endX, int endY, boolean calculateProject);

/**
* Obtain the path of the projection calculated during the last call
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/rlforj/los/PrecisePermissive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rlforj.los;

import rlforj.IBoard;
import rlforj.math.Line2I;
import rlforj.math.Point;

Expand Down Expand Up @@ -320,7 +321,7 @@ else if (mask.fovType == FovType.CIRCLE)
return 1;
}

public void visitFieldOfView(final ILosBoard b, final int x, final int y, final int distance)
public void visitFieldOfView(final IBoard b, final int x, final int y, final int distance)
{
final permissiveMaskT mask = new permissiveMaskT();
mask.east = mask.north = mask.south = mask.west = distance;
Expand All @@ -335,17 +336,18 @@ public void visitFieldOfView(final ILosBoard b, final int x, final int y, final
* Algorithm inspired by
* http://groups.google.com/group/rec.games.roguelike.development/browse_thread/thread/f3506215be9d9f9a/2e543127f705a278#2e543127f705a278
*
* @see rlforj.los.ILosAlgorithm#existsLineOfSight(rlforj.los.ILosBoard, int, int, int, int, boolean)
* @see rlforj.los.ILosAlgorithm#existsLineOfSight(IBoard, int, int, int, int, boolean)
*/
public boolean existsLineOfSight(final ILosBoard b, final int startX, final int startY, final int x1, final int y1,
public boolean existsLineOfSight(final IBoard b, final int startX, final int startY, final int endX, final int endY,
final boolean calculateProject)
{
final permissiveMaskT mask = new permissiveMaskT();
final int dx = x1 - startX;
final int dx = endX - startX;
final int adx = dx > 0 ? dx : -dx;
final int dy = y1 - startY;
final int dy = endY - startY;
final int ady = dy > 0 ? dy : -dy;
final RecordQuadrantVisitBoard fb = new RecordQuadrantVisitBoard(b, startX, startY, x1, y1, calculateProject);
final RecordQuadrantVisitBoard fb = new RecordQuadrantVisitBoard(b, startX, startY, endX,
endY, calculateProject);
mask.east = mask.west = adx;
mask.north = mask.south = ady;
mask.mask = null;
Expand Down Expand Up @@ -435,10 +437,10 @@ public boolean existsLineOfSight(final ILosBoard b, final int startX, final int
if (calculateProject)
{
if (fb.endVisited)
path = GenericCalculateProjection.calculateProjecton(startX, startY, x1, y1, fb);
path = GenericCalculateProjection.calculateProjecton(startX, startY, endX, endY, fb);
else
{
fallBackLos.existsLineOfSight(b, startX, startY, x1, y1, true);
fallBackLos.existsLineOfSight(b, startX, startY, endX, endY, true);
path = (Vector<Point>) fallBackLos.getProjectPath();
}
// calculateProjecton(startX, startY, adx, ady, fb, state);
Expand All @@ -464,13 +466,13 @@ class permissiveMaskT
* Do not interact with the members directly. Use the provided
* functions.
*/ int north;
int south;
int east;
int west;
int south;
int east;
int west;
// int width;
// int height;
int[] mask;
ILosBoard board;
int[] mask;
IBoard board;
}

class fovStateT
Expand All @@ -482,7 +484,7 @@ class fovStateT
Object context;
Point quadrant;
Point extent;
ILosBoard board;
IBoard board;
}

class bumpT
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/rlforj/los/RecordQuadrantVisitBoard.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rlforj.los;

import rlforj.IBoard;
import rlforj.math.Point;

import java.util.HashSet;
Expand All @@ -11,9 +12,9 @@
*
* @author sdatta
*/
public class RecordQuadrantVisitBoard implements ILosBoard, GenericCalculateProjection.VisitedBoard
public class RecordQuadrantVisitBoard implements IBoard, GenericCalculateProjection.VisitedBoard
{
ILosBoard b;
IBoard b;

int sx, sy, sxy;

Expand All @@ -27,7 +28,7 @@ public class RecordQuadrantVisitBoard implements ILosBoard, GenericCalculateProj
boolean calculateProject;
private final Point visitedCheck = new Point(0, 0);

public RecordQuadrantVisitBoard(final ILosBoard b, final int sx, final int sy, final int dx, final int dy, final boolean calculateProject)
public RecordQuadrantVisitBoard(final IBoard b, final int sx, final int sy, final int dx, final int dy, final boolean calculateProject)
{
super();
this.b = b;
Expand Down
Loading

0 comments on commit 5c2fcfb

Please sign in to comment.