Skip to content
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

refactor: rework pathfinding logic from #76

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 9 additions & 23 deletions src/main/java/org/terasology/minion/move/FindPathToNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.minion.move;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import org.joml.Vector3f;
import org.terasology.engine.logic.behavior.BehaviorAction;
import org.terasology.engine.logic.behavior.core.Actor;
Expand All @@ -18,8 +14,9 @@
import org.terasology.pathfinding.componentSystem.PathfinderSystem;
import org.terasology.pathfinding.model.Path;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* Requests a path to a target defined using the <b>MinionMoveComponent.target</b>.<br/> <br/>
Expand Down Expand Up @@ -61,26 +58,15 @@ public void construct(final Actor actor) {
moveComponent.path = Path.INVALID;
return;
}
SettableFuture<List<Path>> pathFuture = pathfinderSystem.requestPath(
moveComponent.path = Path.INVALID;
pathfinderSystem.requestPath(
actor.getEntity(), currentBlock.getBlockPosition(),
Arrays.asList(workTarget.getBlockPosition()));

Futures.addCallback(pathFuture, new FutureCallback<List<Path>>() {
@Override
public void onSuccess(List<Path> paths) {
if (paths == null) {
moveComponent.path = Path.INVALID;
} else if (paths.size() > 0) {
moveComponent.path = paths.get(0);
}
actor.save(moveComponent);
}

@Override
public void onFailure(Throwable t) {
moveComponent.path = Path.INVALID;
Collections.singletonList(workTarget.getBlockPosition())).blockOptional().ifPresent(paths -> {
if (paths.size() > 0) {
moveComponent.path = paths.get(0);
}
}, MoreExecutors.directExecutor());
});
actor.save(moveComponent);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/terasology/minion/work/WorkBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.joml.Vector3ic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.core.GameThread;
import org.terasology.engine.entitySystem.entity.EntityManager;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeRemoveComponent;
Expand Down