This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
forked from nerdsinspace/nocomment-master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackyTrackyManager.java
126 lines (109 loc) · 5.88 KB
/
TrackyTrackyManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package nocomment.master.tracking;
import nocomment.master.Server;
import nocomment.master.db.TrackResume;
import nocomment.master.scanners.ClusterRetryScanner;
import nocomment.master.scanners.HighwayScanner;
import nocomment.master.scanners.RingScanner;
import nocomment.master.scanners.SpiralScanner;
import nocomment.master.util.ChunkPos;
import java.util.OptionalInt;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class TrackyTrackyManager {
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(16); // at most 16 threads because stupid
private final Server server;
private final WorldTrackyTracky overworld;
private final WorldTrackyTracky nether;
private final WorldTrackyTracky end;
public TrackyTrackyManager(Server server) {
this.server = server;
this.overworld = new WorldTrackyTracky(server.getWorld((short) 0), this, this::lostTrackingInOverworld);
this.nether = new WorldTrackyTracky(server.getWorld((short) -1), this, this::lostTrackingInNether);
this.end = new WorldTrackyTracky(server.getWorld((short) 1), this, $ -> {});
highways();
clusters();
spiral();
}
private void highways() {
System.out.println("Nether:");
// scan the entire highway network every four hours
new HighwayScanner(nether.world, 10000, 30_000_000 / 8, 14_400_000, nether::ingestGenericNewHit).submitTasks();
// scan up to 250k (2m overworld) every 400 seconds (7 minutes ish)
new HighwayScanner(nether.world, 1000, 2_000_000 / 8, 400_000, nether::ingestGenericNewHit).submitTasks();
// scan up to 25k (200k overworld) every 40 seconds
new HighwayScanner(nether.world, 100, 25_000, 40_000, nether::ingestGenericNewHit).submitTasks();
// scan the 2k ring road every 4 seconds
new RingScanner(nether.world, 99, 1000, 6_000, nether::ingestGenericNewHit).submitTasks();
System.out.println("Overworld:");
// scan up to 25k overworld every 40 seconds
new HighwayScanner(overworld.world, 100, 25_000, 40_000, overworld::ingestGenericNewHit).submitTasks();
// scan the 2k ring road every 16 seconds
new RingScanner(overworld.world, 51, 2000, 16_000, overworld::ingestGenericNewHit).submitTasks();
System.out.println("End:");
new RingScanner(end.world, 99, 1250, 5_000, end::ingestGenericNewHit).submitTasks();
}
private void clusters() {
new ClusterRetryScanner(overworld.world, 50, 5, 1000, overworld::ingestGenericNewHit).submitTasks();
//new ClusterRetryScanner(nether.world, 50, 2, 1000, nether::ingestGenericNewHit).submitTasks();
new ClusterRetryScanner(end.world, 50, 1, 1000, end::ingestGenericNewHit).submitTasks();
}
private void spiral() {
new SpiralScanner(overworld.world, 1_000_000, 300_000, overworld::ingestGenericNewHit).submitTasks();
new SpiralScanner(nether.world, 1_000_000, 150_000, nether::ingestGenericNewHit).submitTasks();
new SpiralScanner(end.world, 1_000_000, 200_000, end::ingestGenericNewHit).submitTasks();
}
private void lostTrackingInOverworld(Track lost) {
nether.ingestApprox(new ChunkPos(lost.getMostRecentHit().x / 8, lost.getMostRecentHit().z / 8), OptionalInt.of(lost.getTrackID()), false, 11);
for (int i = 0; i <= 30; i += 10) {
scheduler.schedule(() -> nether.ingestApprox(new ChunkPos(lost.getMostRecentHit().x, lost.getMostRecentHit().z), OptionalInt.of(lost.getTrackID()), false, 17), i, TimeUnit.SECONDS);
}
}
private void lostTrackingInNether(Track lost) {
overworld.ingestApprox(new ChunkPos(lost.getMostRecentHit().x * 8, lost.getMostRecentHit().z * 8), OptionalInt.of(lost.getTrackID()), true, 11);
overworld.ingestApprox(new ChunkPos(lost.getMostRecentHit().x, lost.getMostRecentHit().z), OptionalInt.of(lost.getTrackID()), false, 19);
}
public boolean hasActiveFilter(int trackID) {
return overworld.hasActiveFilter(trackID) || nether.hasActiveFilter(trackID) || end.hasActiveFilter(trackID);
}
public void attemptResume(TrackResume resumeData) {
boolean interesting = trackInterestingEnoughToGridResume(resumeData, resumeData.dimension == 0);
System.out.println("Attempting to resume tracking at " + resumeData.pos + " in dimension " + resumeData.dimension + " in server " + server.hostname + " from track id " + resumeData.prevTrackID + " interesting " + interesting);
WorldTrackyTracky tracky;
switch (resumeData.dimension) {
case 0: {
tracky = overworld;
break;
}
case -1: {
tracky = nether;
break;
}
case 1: {
tracky = end;
interesting = true;
break;
}
default: {
System.out.println("We don't do that here " + resumeData.dimension);
return;
}
}
tracky.ingestApprox(resumeData.pos, OptionalInt.of(resumeData.prevTrackID), false, interesting ? 12 : 15);
}
private static boolean trackInterestingEnoughToGridResume(TrackResume resumeData, boolean ow) {
long spawnDistanceSq = resumeData.pos.distSq(ChunkPos.SPAWN);
// within 1600 blocks of spawn = within 100 chunks of spawn = we don't care
if (spawnDistanceSq <= 100 * 100) {
return false;
}
if (ow && spawnDistanceSq <= 1000 * 1000) {
return false;
}
int axisDistance = Math.min(Math.min(Math.abs(resumeData.pos.x), Math.abs(resumeData.pos.z)), Math.abs(Math.abs(resumeData.pos.x) - Math.abs(resumeData.pos.z)));
if (axisDistance <= 5 && spawnDistanceSq <= 1000 * 1000) {
return false;
}
return true;
}
}