Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.LongHashMap;
import net.minecraft.util.Vec3;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.locks.LockSupport;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -92,9 +93,17 @@ public void solve() {

if (nativeLoaded) {
try {
TimeCache.ensureStarted();
final long deadline = TimeCache.now + 10000;
long handle = startCoroutine();
try {
while (true) {
if (TimeCache.now > deadline) {
ChatTransmitter.addToQueue("§fSolver took too long (10s) YIKES!!!");
ChatTransmitter.addToQueue("Room: " + dungeonRoom.getDungeonRoomInfo().getName());
ChatTransmitter.addToQueue("Roomsate is :" + roomState);
break;
}
roomState.setPlayerPos(new Vec3(getX(handle), getY(handle), getZ(handle)));
roomState.setOpenMechanicsBitset(getMech(handle));
double cost = everyNode[getNode(handle)].getAction().evalulateCost(roomState, dungeonRoom, cache, pathPlanner);
Expand Down Expand Up @@ -127,17 +136,20 @@ private void setup() {
List<ActionDAGNode> dagNodeList = new ArrayList<>();
int[] nodeStatus = dag.getNodeStatusAll();

List<ActionDAGNode> allNodes = dag.getAllNodes();

requireIdBitMapping = new int[dag.getAllNodes().size()];
orIdIdxMapping = new int[dag.getAllNodes().size()];
nodeType = new int[dag.getAllNodes().size()];
require = new long[dag.getAllNodes().size()];
or = new int[dag.getAllNodes().size()][];
sanity = new boolean[dag.getAllNodes().size()];
int nodeCount = allNodes.size();
requireIdBitMapping = new int[nodeCount];
orIdIdxMapping = new int[nodeCount];
nodeType = new int[nodeCount];
require = new long[nodeCount];
or = new int[nodeCount][];
sanity = new boolean[nodeCount];



label: for (int i = 0; i < dag.getAllNodes().size(); i++) {
ActionDAGNode node = dag.getAllNodes().get(i);
label: for (int i = 0; i < allNodes.size(); i++) {
ActionDAGNode node = allNodes.get(i);
for (ActionDAGNode actionDAGNode : node.getRequiredBy()) {
if (actionDAGNode.getOr().isEmpty()) continue;
continue label;
Expand All @@ -147,12 +159,13 @@ private void setup() {
requireIdBitMapping[node.getId()] = dagNodeList.size();
dagNodeList.add(node);
}

bitNodes = dagNodeList.toArray(new ActionDAGNode[0]);
requireBitSize = bitNodes.length;

long mult = 1;
List<ActionDAGNode[]> orNodes = new ArrayList<>();
for (ActionDAGNode allNode : dag.getAllNodes()) {
for (ActionDAGNode allNode : allNodes) {
if (allNode.getOr().isEmpty()) continue;
ActionDAGNode[] ornode = new ActionDAGNode[allNode.getOr().size()+1];
for (int i = 0; i < allNode.getOr().size(); i++) {
Expand All @@ -170,21 +183,20 @@ private void setup() {
mechanicNames = dungeonRoom.getMechanics().entrySet().stream().filter(a -> a.getValue() instanceof DungeonDoorState || a.getValue() instanceof DungeonOnewayDoorState)
.map(a -> a.getKey()).collect(Collectors.toList());

int bitset = 0;
stBitset = 0;
for (int i = 0; i < mechanicNames.size(); i++) {
String mechanicName = mechanicNames.get(i);
if (!((WorldMutatingMechanicState)dungeonRoom.getMechanics().get(mechanicName)).isBlocking(dungeonRoom)) {
bitset |= 1 << i;
stBitset |= 1 << i;
}
}
stBitset = bitset;

for (int i = 0; i < nodeStatus.length; i++) {
if (nodeStatus[i] == 1 || nodeStatus[i] == 2)
nodeType[i] = 0;
}

everyNode = dag.getAllNodes().toArray(new ActionDAGNode[0]);
everyNode = allNodes.toArray(new ActionDAGNode[0]);
for (int i = 0; i < everyNode.length; i++) {
require[i] = 0;
for (int j = 0; j < everyNode[i].getRequire().size(); j++) {
Expand Down Expand Up @@ -229,3 +241,33 @@ public List<ActionDAGNode> reconstructPath() {


}

class TimeCache {
static volatile long now;
private static volatile boolean started = false;

static {
start();
}

static void ensureStarted() {
// no-op, forces class initialization
}

private static synchronized void start() {
if (started) return;
started = true;

now = System.currentTimeMillis();
Thread t = new Thread(() -> {
while (true) {
now = System.currentTimeMillis();
LockSupport.parkNanos(50_000_000);
}
}, "TimeCache");
t.setDaemon(true);
t.start();
}

private TimeCache() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import net.minecraft.util.Vec3;

import java.util.*;

@Getter @Setter
@Getter @Setter @ToString
public class RoomState {
private DungeonRoom dungeonRoom;
private Vec3 playerPos;
Expand All @@ -42,4 +43,4 @@ public void setPlayerPos(Vec3 playerPos) {
public RoomState(List<String> openMechanicsIndex) {
this.openMechanicsIndex = openMechanicsIndex;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@
import kr.syeyoung.dungeonsguide.mod.stomp.StompManager;
import kr.syeyoung.dungeonsguide.mod.stomp.StompPayload;
import kr.syeyoung.dungeonsguide.mod.utils.MapUtils;
import kr.syeyoung.dungeonsguide.mod.wsresource.StaticResource;
import kr.syeyoung.dungeonsguide.mod.wsresource.StaticResourceCache;
import net.minecraft.util.ChatComponentText;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;

import java.util.concurrent.TimeoutException;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class FeatureCollectScore extends SimpleFeature {
Logger logger = LogManager.getLogger("FeatureCollectScore");
Expand Down Expand Up @@ -61,13 +66,19 @@ public void collectDungeonRunData(byte[] mapData, DungeonContext context) {
return;
}

StaticResource targetResource = null;
String target = null;
try {
target = StaticResourceCache.INSTANCE.getResource(StaticResourceCache.DATA_COLLECTION).get().getValue();
targetResource = StaticResourceCache.INSTANCE.getResource(StaticResourceCache.DATA_COLLECTION).get(1, TimeUnit.SECONDS);
} catch (TimeoutException e) {
ChatTransmitter.sendDebugChat("Idk but this fixed the new bug.");
e.printStackTrace();
return;
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
target = targetResource.getValue();

if (FeatureRegistry.ETC_COLLECT_SCORE.isEnabled() && !target.contains("falsefalsefalsefalse")) {
StompManager.getInstance().send(new StompPayload().payload(payload.toString()).destination(target.replace("false", "").trim()));
Expand Down