Advertisement
JolyJDIA

Untitled

Jun 3rd, 2021
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. /*
  2.     *
  3.     *       Разбиваем чанк на параллельный шаринг
  4.     *                   ____________
  5.     *                  /|          /|
  6.     *                 / |         / |
  7.     *                /__|________/  |      - Core #1
  8.     *                |  | _ _ _ _|_ |
  9.     *                | /         |  /
  10.     *                |/          | /
  11.     *                |___________|/
  12.     *
  13.     *                   ____________
  14.     *                  /|          /|
  15.     *                 / |         / |
  16.     *                /__|________/  |      - Core #0
  17.     *                |  | _ _ _ _|_ |
  18.     *                | /         |  /
  19.     *                |/          | /
  20.     *                |___________|/
  21.     */
  22.  
  23.  
  24.     @SuppressWarnings("serial")
  25.     public static class SearchLocation0 extends CountedCompleter<Location> {
  26.         private final int lo, hi;
  27.         private final AtomicReference<Location> result;
  28.         private final Function<Block, Location> predicate;
  29.         private final Chunk chunk;
  30.         private final int thr;
  31.  
  32.         public SearchLocation0(SearchLocation0 c,
  33.                                int thr,
  34.                                Chunk chunk,
  35.                                int lo, int hi,
  36.                                Function<Block, Location> predicate,
  37.                                AtomicReference<Location> result) {
  38.             super(c);
  39.             this.thr = thr;
  40.             this.chunk = chunk;
  41.             this.lo = lo;
  42.             this.hi = hi;
  43.             this.predicate = predicate;
  44.             this.result = result;
  45.         }
  46.  
  47.         @Override
  48.         public Location getRawResult() {
  49.             return result.get();
  50.         }
  51.  
  52.         @Override
  53.         public void compute() {
  54.             int h = hi;
  55.             while (result.get() == null && h - lo > thr) {
  56.                 int mid = (lo + h) >>> 1;
  57.                 new SearchLocation0(this, thr, chunk, mid, h, predicate, result).fork();
  58.                 h = mid;
  59.             }
  60.             for (int y = h; y > lo; y--) {
  61.                 for (int x = 0; x < 16; x++) {
  62.                     for (int z = 0; z < 16; z++) {
  63.                         if (result.get() != null)
  64.                             return;
  65.                         Location loc = predicate.apply(chunk.getBlock(x, y, z));
  66.                         if (loc != null) {
  67.                             if (result.compareAndSet(null, loc)) {
  68.                                 quietlyCompleteRoot();
  69.                             }
  70.                             return;
  71.                         }
  72.                     }
  73.                 }
  74.             }
  75.             propagateCompletion();
  76.         }
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement