-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation #43
base: develop
Are you sure you want to change the base?
Documentation #43
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,19 @@ | |
import java.util.List; | ||
|
||
/** | ||
* @author synopia | ||
* @author synopia Representation of a region or floor {@link Floor} The BitMap consists of a number of bits, each of | ||
* which represent a block. A value of true or 1 means that the block is passable | ||
*/ | ||
public class BitMap { | ||
public static final int KERNEL_SIZE = 3; | ||
public static final float SQRT_2 = (float) Math.sqrt(2); | ||
BitSet map; | ||
|
||
/** | ||
* Creates a new Bitmap | ||
agent-q1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* A bitmap created this way always has a fixed number of nodes, decided by in-game Chunk | ||
* constants The default value for all the bits are false or 0. | ||
*/ | ||
public BitMap() { | ||
map = new BitSet(getNumberOfNodes()); | ||
} | ||
|
@@ -53,6 +59,12 @@ public boolean isPassable(int x, int y) { | |
return isPassable(offset(x, y)); | ||
} | ||
|
||
/** | ||
* Function that adds all the possible nodes that you could possibly go to from the current position | ||
* | ||
* @param offset the offset of the current position | ||
* @param successors the list into which the successor nodes will be added | ||
*/ | ||
public void getSuccessors(int offset, List<Integer> successors) { | ||
int x = getX(offset); | ||
int y = getY(offset); | ||
|
@@ -83,16 +95,32 @@ public void getSuccessors(int offset, List<Integer> successors) { | |
} | ||
} | ||
|
||
/** | ||
* Tells you whether there is any overlap between 'this' (the one that called the function) map and 'other' map | ||
* | ||
* @param other the map with which you want to check overlap | ||
* @return true if there is any overlap | ||
*/ | ||
public boolean overlap(BitMap other) { | ||
BitSet temp = (BitSet) map.clone(); | ||
temp.and(other.map); | ||
return temp.cardinality() > 0; | ||
} | ||
|
||
/** | ||
* Merges 'this' map and 'other' and sets its value to 'this' | ||
* | ||
* @param other bitmap with which you want to merge | ||
*/ | ||
public void merge(BitMap other) { | ||
map.or(other.map); | ||
} | ||
|
||
/** | ||
* Gives information about the map with 'X's representing Walkable Blocks and spaces representing blocked areas | ||
* | ||
* @return | ||
*/ | ||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
@@ -114,6 +142,11 @@ public String toString() { | |
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Function that return number of nodes in the bitmap | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no comment here, but it could use one (or at least get rid of the extra line) |
||
* @return number of cells in the map | ||
*/ | ||
public int getNumberOfNodes() { | ||
return getWidth() * getHeight(); | ||
} | ||
|
@@ -126,6 +159,11 @@ public int getHeight() { | |
return NavGraphChunk.SIZE_Z; | ||
} | ||
|
||
/** | ||
* @param from start position | ||
* @param to end postion | ||
* @return the Euclidean distance between two neighbouring cells in 2D | ||
*/ | ||
public float exactDistance(int from, int to) { | ||
int diff = to - from; | ||
if (diff == -getWidth() || diff == 1 || diff == getWidth() || diff == -1) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,10 @@ public void shutdown() { | |
taskMaster.shutdown(new ShutdownTask(), false); | ||
} | ||
|
||
/** | ||
* Checks if the terrain has been changed and sends a NavGraphChanged event which rebuilds the NavGraphChunk. | ||
* @param delta The time (in seconds) since the last engine update. | ||
*/ | ||
@Override | ||
public void update(float delta) { | ||
if (dirty) { | ||
|
@@ -79,6 +83,12 @@ public void update(float delta) { | |
} | ||
} | ||
|
||
/** | ||
* Called whenever a block is changed in the terrain | ||
* @param pos position of the changed block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalization is inconsistent between the "Block" in the first line and "block" in the later ones |
||
* @param newBlock the block it was changed to | ||
* @param originalBlock the block it initially was | ||
*/ | ||
@Override | ||
public void onBlockChanged(Vector3i pos, Block newBlock, Block originalBlock) { | ||
Vector3i chunkPos = ChunkMath.calcChunkPos(pos); | ||
|
@@ -90,6 +100,11 @@ public void chunkReady(OnChunkLoaded event, EntityRef worldEntity) { | |
taskMaster.offer(new UpdateChunkTask(event.getChunkPos())); | ||
} | ||
|
||
/** | ||
* | ||
* @param pos Position of the Walkable Block | ||
* @return WalkableBlock at that position | ||
*/ | ||
public WalkableBlock getBlock(Vector3i pos) { | ||
Vector3i chunkPos = ChunkMath.calcChunkPos(pos); | ||
NavGraphChunk navGraphChunk = heightMaps.get(chunkPos); | ||
|
@@ -100,11 +115,21 @@ public WalkableBlock getBlock(Vector3i pos) { | |
} | ||
} | ||
|
||
/** | ||
* Gives the WalkableBlock on which a minion is | ||
* @param minion The minion Walkable Block | ||
* @return a Walkable Block on which the minion is | ||
*/ | ||
public WalkableBlock getBlock(EntityRef minion) { | ||
Vector3f pos = minion.getComponent(LocationComponent.class).getWorldPosition(); | ||
return getBlock(pos); | ||
} | ||
|
||
/** | ||
* Approximates the WalkableBlock based on float coordinates | ||
* @param pos The position at which we want the WalkableBlock | ||
* @return WalkableBlock at pos | ||
*/ | ||
public WalkableBlock getBlock(Vector3f pos) { | ||
Vector3i blockPos = new Vector3i(pos.x + 0.25f, pos.y, pos.z + 0.25f); | ||
WalkableBlock block = getBlock(blockPos); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not strictly necessary I'd think that the string representation could simply be something like
"NavRegion(<id>, <size>)"
, avoiding line breaks.