Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Разбиваем чанк на параллельный шаринг
- * ____________
- * /| /|
- * / | / |
- * /__|________/ | - Core #1
- * | | _ _ _ _|_ |
- * | / | /
- * |/ | /
- * |___________|/
- *
- * ____________
- * /| /|
- * / | / |
- * /__|________/ | - Core #0
- * | | _ _ _ _|_ |
- * | / | /
- * |/ | /
- * |___________|/
- */
- @SuppressWarnings("serial")
- public static class SearchLocation0 extends CountedCompleter<Location> {
- private final int lo, hi;
- private final AtomicReference<Location> result;
- private final Function<Block, Location> predicate;
- private final Chunk chunk;
- private final int thr;
- public SearchLocation0(SearchLocation0 c,
- int thr,
- Chunk chunk,
- int lo, int hi,
- Function<Block, Location> predicate,
- AtomicReference<Location> result) {
- super(c);
- this.thr = thr;
- this.chunk = chunk;
- this.lo = lo;
- this.hi = hi;
- this.predicate = predicate;
- this.result = result;
- }
- @Override
- public Location getRawResult() {
- return result.get();
- }
- @Override
- public void compute() {
- int h = hi;
- while (result.get() == null && h - lo > thr) {
- int mid = (lo + h) >>> 1;
- new SearchLocation0(this, thr, chunk, mid, h, predicate, result).fork();
- h = mid;
- }
- for (int y = h; y > lo; y--) {
- for (int x = 0; x < 16; x++) {
- for (int z = 0; z < 16; z++) {
- if (result.get() != null)
- return;
- Location loc = predicate.apply(chunk.getBlock(x, y, z));
- if (loc != null) {
- if (result.compareAndSet(null, loc)) {
- quietlyCompleteRoot();
- }
- return;
- }
- }
- }
- }
- propagateCompletion();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement