Restructure Packages (read commit description)

There are now three root packages
- Engine: Generator & JSON Scaffolding
- Core: Managers, Commands, NMS
- Util: Random utility packages
This commit is contained in:
Daniel Mills
2021-07-16 01:46:22 -04:00
parent eef548f6a1
commit c984eb9b8c
423 changed files with 1001 additions and 1977 deletions

View File

@@ -0,0 +1,84 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.parallel;
import com.volmit.iris.Iris;
import com.volmit.iris.util.KList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@SuppressWarnings("ALL")
public class BurstExecutor {
private final ExecutorService executor;
private final KList<CompletableFuture<Void>> futures;
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
this.executor = executor;
futures = new KList<CompletableFuture<Void>>(burstSizeEstimate);
}
@SuppressWarnings("UnusedReturnValue")
public CompletableFuture<Void> queue(Runnable r) {
synchronized (futures) {
CompletableFuture<Void> c = CompletableFuture.runAsync(r, executor);
futures.add(c);
return c;
}
}
public BurstExecutor queue(KList<Runnable> r) {
synchronized (futures) {
for (Runnable i : r) {
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
futures.add(c);
}
}
return this;
}
public BurstExecutor queue(Runnable[] r) {
synchronized (futures) {
for (Runnable i : r) {
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
futures.add(c);
}
}
return this;
}
public void complete() {
synchronized (futures) {
if (futures.isEmpty()) {
return;
}
try {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
futures.clear();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
Iris.reportError(e);
}
}
}
}

View File

@@ -0,0 +1,29 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.parallel;
import com.volmit.iris.engine.hunk.Hunk;
public interface BurstedHunk<T> extends Hunk<T> {
int getOffsetX();
int getOffsetY();
int getOffsetZ();
}

View File

@@ -0,0 +1,99 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.parallel;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.IORunnable;
import com.volmit.iris.util.NastyRunnable;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
public class GridLock {
private final Hunk<ReentrantLock> locks;
public GridLock(int x, int z) {
this.locks = Hunk.newAtomicHunk(x, 1, z);
locks.iterateSync((a, b, c) -> locks.set(a, b, c, new ReentrantLock()));
}
public void with(int x, int z, Runnable r) {
lock(x, z);
r.run();
unlock(x, z);
}
public void withNasty(int x, int z, NastyRunnable r) throws Throwable {
lock(x, z);
r.run();
unlock(x, z);
}
public void withIO(int x, int z, IORunnable r) throws IOException {
lock(x, z);
r.run();
unlock(x, z);
}
public <T> T withResult(int x, int z, Supplier<T> r) {
lock(x, z);
T t = r.get();
unlock(x, z);
return t;
}
public void withAll(Runnable r) {
locks.iterateSync((a, b, c, d) -> d.lock());
r.run();
locks.iterateSync((a, b, c, d) -> d.unlock());
}
public <T> T withAllResult(Supplier<T> r) {
locks.iterateSync((a, b, c, d) -> d.lock());
T t = r.get();
locks.iterateSync((a, b, c, d) -> d.unlock());
return t;
}
public boolean tryLock(int x, int z) {
return locks.get(x, 0, z).tryLock();
}
public boolean tryLock(int x, int z, long timeout) {
try {
return locks.get(x, 0, z).tryLock(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Iris.reportError(e);
}
return false;
}
public void lock(int x, int z) {
locks.get(x, 0, z).lock();
}
public void unlock(int x, int z) {
locks.get(x, 0, z).unlock();
}
}

View File

@@ -0,0 +1,86 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.parallel;
import com.volmit.iris.Iris;
import com.volmit.iris.util.KList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MultiBurst {
public static final MultiBurst burst = new MultiBurst("Iris Burster", 10, Runtime.getRuntime().availableProcessors());
private final ExecutorService service;
private ExecutorService syncService;
private int tid;
public MultiBurst(int tc) {
this("Iris Generator", 6, tc);
}
public MultiBurst(String name, int priority, int tc) {
service = Executors.newFixedThreadPool(tc, r -> {
tid++;
Thread t = new Thread(r);
t.setName(name + " " + tid);
t.setPriority(6);
t.setUncaughtExceptionHandler((et, e) ->
{
Iris.info("Exception encountered in " + et.getName());
e.printStackTrace();
});
return t;
});
}
public void burst(Runnable... r) {
burst(r.length).queue(r).complete();
}
public void burst(KList<Runnable> r) {
burst(r.size()).queue(r).complete();
}
public void sync(Runnable... r) {
for (Runnable i : r) {
i.run();
}
}
public BurstExecutor burst(int estimate) {
return new BurstExecutor(service, estimate);
}
public BurstExecutor burst() {
return burst(16);
}
public void lazy(Runnable o) {
service.execute(o);
}
public void shutdownNow() {
service.shutdownNow().forEach(Runnable::run);
}
public void shutdown() {
service.shutdown();
}
}