Skip to content

Commit

Permalink
Use PhTree instead of ad-hoc implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 27, 2019
1 parent 015a8d2 commit 072ee19
Show file tree
Hide file tree
Showing 36 changed files with 25 additions and 2,571 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -14,7 +14,7 @@
<powermock.version>1.4.12</powermock.version>
<build.number>Unknown</build.number>
</properties>

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
Expand All @@ -34,6 +34,11 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.ethz.globis.phtree</groupId>
<artifactId>phtree</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>

<url>http://www.citizensnpcs.co</url>
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/net/citizensnpcs/api/ai/goals/WanderGoal.java
Expand Up @@ -11,6 +11,7 @@
import com.google.common.base.Function;
import com.google.common.base.Supplier;

import ch.ethz.globis.phtree.PhTreeSolid;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.ai.Goal;
import net.citizensnpcs.api.ai.event.NavigationCompleteEvent;
Expand All @@ -19,7 +20,6 @@
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.cuboid.QuadTree;

/**
* A sample {@link Goal}/{@link Behavior} that will wander within a certain radius or {@link QuadTree}.
Expand All @@ -32,11 +32,12 @@ public class WanderGoal extends BehaviorGoalAdapter implements Listener {
private final NPC npc;
private boolean paused;
private final Random random = new Random();
private final Supplier<QuadTree> tree;
private final Supplier<PhTreeSolid<Boolean>> tree;
private int xrange;
private int yrange;

private WanderGoal(NPC npc, int xrange, int yrange, Supplier<QuadTree> tree, Function<NPC, Location> fallback) {
private WanderGoal(NPC npc, int xrange, int yrange, Supplier<PhTreeSolid<Boolean>> tree,
Function<NPC, Location> fallback) {
this.npc = npc;
this.xrange = xrange;
this.yrange = yrange;
Expand All @@ -53,7 +54,8 @@ private Location findRandomPosition() {
int z = base.getBlockZ() + random.nextInt(2 * xrange) - xrange;
Block block = base.getWorld().getBlockAt(x, y, z);
if (MinecraftBlockExaminer.canStandOn(block)) {
if (tree != null && tree.get() != null && tree.get().search(x, y, z).isEmpty()) {
long[] pt = { x, y, z };
if (tree != null && tree.get() != null && !tree.get().contains(pt, pt)) {
continue;
}
found = block.getLocation().add(0, 1, 0);
Expand Down Expand Up @@ -126,7 +128,8 @@ public static WanderGoal createWithNPCAndRange(NPC npc, int xrange, int yrange)
return createWithNPCAndRangeAndTree(npc, xrange, yrange, null);
}

public static WanderGoal createWithNPCAndRangeAndTree(NPC npc, int xrange, int yrange, Supplier<QuadTree> tree) {
public static WanderGoal createWithNPCAndRangeAndTree(NPC npc, int xrange, int yrange,
Supplier<PhTreeSolid<Boolean>> tree) {
return createWithNPCAndRangeAndTreeAndFallback(npc, xrange, yrange, tree, null);
}

Expand All @@ -140,13 +143,13 @@ public static WanderGoal createWithNPCAndRangeAndTree(NPC npc, int xrange, int y
* @param yrange
* y range, in blocks
* @param tree
* an optional {@link QuadTree} supplier to allow only wandering within a certain {@link QuadTree}
* an optional {@link PhTreeSolid} supplier to allow only wandering within a certain {@link PhTreeSolid}
* @param fallback
* an optional fallback location
* @return the built goal
*/
public static WanderGoal createWithNPCAndRangeAndTreeAndFallback(NPC npc, int xrange, int yrange,
Supplier<QuadTree> tree, Function<NPC, Location> fallback) {
Supplier<PhTreeSolid<Boolean>> tree, Function<NPC, Location> fallback) {
return new WanderGoal(npc, xrange, yrange, tree, fallback);
}
}
11 changes: 9 additions & 2 deletions src/main/java/net/citizensnpcs/api/hpastar/HPAGraph.java
Expand Up @@ -13,23 +13,30 @@

import com.google.common.collect.Lists;

import ch.ethz.globis.phtree.PhTree;
import net.citizensnpcs.api.astar.Plan;
import net.citizensnpcs.api.astar.pathfinder.BlockSource;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.Path;

public class HPAGraph {
// TODO: y-clusters
private final BlockSource blockSource;
public List<List<HPACluster>> clusters = Lists.newArrayList();
// TODO: y-clusters
private final int cx, cy, cz;
private final List<PhTree<HPACluster>> phtrees = Lists.newArrayList();

public HPAGraph(BlockSource blockSource) {
public HPAGraph(BlockSource blockSource, int cx, int cy, int cz) {
this.blockSource = blockSource;
this.cx = cx;
this.cy = cy;
this.cz = cz;
}

public void addClustersAtDepth(int depth, List<HPACluster> other) {
while (clusters.size() <= depth) {
clusters.add(new ArrayList<HPACluster>());
// phtrees.add(new ArrayList<PhTree<HPACluster>>());
}
clusters.get(depth).addAll(other);
}
Expand Down

This file was deleted.

90 changes: 0 additions & 90 deletions src/main/java/net/citizensnpcs/api/util/cuboid/QuadCuboid.java

This file was deleted.

75 changes: 0 additions & 75 deletions src/main/java/net/citizensnpcs/api/util/cuboid/QuadNode.java

This file was deleted.

0 comments on commit 072ee19

Please sign in to comment.