mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Ditched AsyncZoneGeneratedHandler for a Zone Consumer
This commit is contained in:
parent
34f45f1fad
commit
791476d6d5
4 changed files with 13 additions and 17 deletions
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -16,7 +17,6 @@ import org.apache.logging.log4j.Logger;
|
|||
import com.fasterxml.jackson.databind.InjectableValues;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import brainwine.gameserver.zone.gen.AsyncZoneGeneratedHandler;
|
||||
import brainwine.gameserver.zone.gen.AsyncZoneGenerator;
|
||||
import brainwine.gameserver.zone.gen.StaticZoneGenerator;
|
||||
|
||||
|
@ -106,13 +106,13 @@ public class ZoneManager {
|
|||
zonesByName.put(name.toLowerCase(), zone);
|
||||
}
|
||||
|
||||
public void generateZoneAsync(Biome biome, int width, int height, int seed, AsyncZoneGeneratedHandler callback) {
|
||||
public void generateZoneAsync(Biome biome, int width, int height, int seed, Consumer<Zone> callback) {
|
||||
asyncGenerator.generateZone(biome, width, height, seed, zone -> {
|
||||
if(zone != null) {
|
||||
putZone(zone);
|
||||
}
|
||||
|
||||
callback.handle(zone);
|
||||
callback.accept(zone);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package brainwine.gameserver.zone.gen;
|
||||
|
||||
import brainwine.gameserver.zone.Zone;
|
||||
|
||||
public interface AsyncZoneGeneratedHandler {
|
||||
|
||||
public void handle(Zone zone);
|
||||
}
|
|
@ -2,6 +2,7 @@ package brainwine.gameserver.zone.gen;
|
|||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -44,13 +45,13 @@ public class AsyncZoneGenerator extends Thread {
|
|||
|
||||
System.gc();
|
||||
Zone generated = zone;
|
||||
AsyncZoneGeneratedHandler callback = task.getCallback();
|
||||
Consumer<Zone> callback = task.getCallback();
|
||||
|
||||
if(callback != null) {
|
||||
GameServer.getInstance().queueSynchronousTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.handle(generated);
|
||||
callback.accept(generated);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ public class AsyncZoneGenerator extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
public void generateZone(Biome biome, int width, int height, int seed, AsyncZoneGeneratedHandler callback) {
|
||||
public void generateZone(Biome biome, int width, int height, int seed, Consumer<Zone> callback) {
|
||||
tasks.add(new AsyncZoneGeneratorTask(biome, width, height, seed, callback));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package brainwine.gameserver.zone.gen;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import brainwine.gameserver.zone.Biome;
|
||||
import brainwine.gameserver.zone.Zone;
|
||||
|
||||
public class AsyncZoneGeneratorTask {
|
||||
|
||||
|
@ -8,9 +11,9 @@ public class AsyncZoneGeneratorTask {
|
|||
private final int width;
|
||||
private final int height;
|
||||
private final int seed;
|
||||
private final AsyncZoneGeneratedHandler callback;
|
||||
private final Consumer<Zone> callback;
|
||||
|
||||
public AsyncZoneGeneratorTask(Biome biome, int width, int height, int seed, AsyncZoneGeneratedHandler callback) {
|
||||
public AsyncZoneGeneratorTask(Biome biome, int width, int height, int seed, Consumer<Zone> callback) {
|
||||
this.biome = biome;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
@ -34,7 +37,7 @@ public class AsyncZoneGeneratorTask {
|
|||
return seed;
|
||||
}
|
||||
|
||||
public AsyncZoneGeneratedHandler getCallback() {
|
||||
public Consumer<Zone> getCallback() {
|
||||
return callback;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue