This commit is contained in:
Daniel Mills 2021-07-31 19:41:12 -04:00
parent 16de60f82d
commit ee18217520
9 changed files with 257 additions and 58 deletions

View File

@ -438,6 +438,7 @@ public class IrisProject {
settings.put("json.maxItemsComputed", 30000);
JSONArray schemas = new JSONArray();
IrisDataManager dm = new IrisDataManager(getPath());
// TODO Cleanup
schemas.put(getSchemaEntry(IrisDimension.class, dm, "/dimensions/*.json", "/dimensions/*/*.json", "/dimensions/*/*/*.json"));
schemas.put(getSchemaEntry(IrisEntity.class, dm, "/entities/*.json", "/entities/*/*.json", "/entities/*/*/*.json"));
schemas.put(getSchemaEntry(IrisBiome.class, dm, "/biomes/*.json", "/biomes/*/*.json", "/biomes/*/*/*.json"));
@ -449,6 +450,7 @@ public class IrisProject {
schemas.put(getSchemaEntry(IrisJigsawStructure.class, dm, "/jigsaw-structures/*.json", "/jigsaw-structures/*/*/*.json", "/jigsaw-structures/*/*.json"));
schemas.put(getSchemaEntry(IrisBlockData.class, dm, "/blocks/*.json", "/blocks/*/*.json", "/blocks/*/*/*.json"));
schemas.put(getSchemaEntry(IrisLootTable.class, dm, "/loot/*.json", "/loot/*/*.json", "/loot/*/*/*.json"));
schemas.put(getSchemaEntry(IrisSpawner.class, dm, "/spawners/*.json", "/spawners/*/*.json", "/spawners/*/*/*.json"));
settings.put("json.schemas", schemas);
ws.put("settings", settings);

View File

@ -162,6 +162,7 @@ public class SchemaBuilder {
prop.put("maxLength", max);
description.add(SYMBOL_LIMIT__N + " Maximum Length allowed is " + max);
}
// TODO Automate registry lists
if (k.isAnnotationPresent(RegistryListBiome.class)) {
String key = "enum-reg-biome";

View File

@ -27,6 +27,7 @@ import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import org.bukkit.Chunk;
import org.bukkit.event.block.BlockBreakEvent;
@ -36,36 +37,55 @@ import org.bukkit.inventory.ItemStack;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class IrisWorldManager extends EngineAssignedWorldManager {
private boolean spawnable;
private final int art;
private final KMap<UUID, Long> spawnCooldowns;
private int entityCount = 0;
private ChronoLatch cl = new ChronoLatch(5000);
public IrisWorldManager(Engine engine) {
super(engine);
spawnCooldowns = new KMap<>();
spawnable = true;
art = J.ar(this::onAsyncTick, 200);
art = J.ar(this::onAsyncTick, 7);
}
private void onAsyncTick() {
int biomeBaseCooldownMinutes = 2;
int biomeSpawnedCooldownMinutes = 3;
int biomeNotSpawnedCooldownMinutes = 5;
if (!getEngine().getWorld().hasRealWorld()) {
return;
}
if ((double) entityCount / (getEngine().getWorld().realWorld().getLoadedChunks().length+1) > 1)
{
return;
}
if(cl.flip())
{
J.s(() -> entityCount = getEngine().getWorld().realWorld().getEntities().size());
}
int biomeBaseCooldownSeconds = 1;
int biomeSpawnedCooldownSeconds = 0;
int biomeNotSpawnedCooldownSeconds = 1;
int actuallySpawned = 0;
for(UUID i : spawnCooldowns.k())
{
if(M.ms() - spawnCooldowns.get(i) > TimeUnit.MINUTES.toMillis(biomeBaseCooldownMinutes))
if(M.ms() - spawnCooldowns.get(i) > TimeUnit.SECONDS.toMillis(biomeBaseCooldownSeconds))
{
spawnCooldowns.remove(i);
Iris.debug("Biome " + i.toString() + " is off cooldown");
}
}
KMap<UUID, KList<Chunk>> data = new KMap<>();
int spawnBuffer = 8;
KMap<UUID, KList<Chunk>> data = mapChunkBiomes();
int spawnBuffer = 32;
Iris.debug("Checking " + data.size() + " Loaded Biomes for new spawns...");
for(UUID i : data.k().shuffleCopy(RNG.r))
{
@ -79,15 +99,32 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
break;
}
spawnCooldowns.put(i, spawnIn(data.get(i).getRandom(), i) ?
(M.ms() + TimeUnit.MINUTES.toMillis(biomeSpawnedCooldownMinutes)) :
(M.ms() + TimeUnit.MINUTES.toMillis(biomeNotSpawnedCooldownMinutes)));
Iris.debug(" Spawning for " + i.toString());
for(int ig = 0; ig < data.get(i).size() / 8; ig++)
{
boolean g = spawnIn(data.get(i).getRandom(), i);
spawnCooldowns.put(i, g ?
(M.ms() + TimeUnit.SECONDS.toMillis(biomeSpawnedCooldownSeconds)) :
(M.ms() + TimeUnit.SECONDS.toMillis(biomeNotSpawnedCooldownSeconds)));
if(g)
{
actuallySpawned++;
}
}
}
if(actuallySpawned <= 0)
{
J.sleep(5000);
}
}
private boolean spawnIn(Chunk c, UUID id) {
if(c.getEntities().length > 16)
if(c.getEntities().length > 2)
{
Iris.debug(" Not spawning in " + id.toString() + " (" + c.getX() + ", " + c.getZ() + "). More than 2 entities in this chunk.");
return false;
}
@ -98,7 +135,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
{
if(i.spawnInChunk(getEngine(), c))
{
Iris.debug("Spawning Biome Entities in Chunk " + c.getX() + "," + c.getZ() + " Biome ID: " + id);
Iris.debug(" Spawning Biome Entities in Chunk " + c.getX() + "," + c.getZ() + " Biome ID: " + id);
return true;
}
}
@ -111,7 +148,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
{
if(i.spawnInChunk(getEngine(), c))
{
Iris.debug("Spawning Region Entities in Chunk " + c.getX() + "," + c.getZ() + " Biome ID: " + id);
Iris.debug(" Spawning Region Entities in Chunk " + c.getX() + "," + c.getZ() + " Biome ID: " + id);
return true;
}
}
@ -122,7 +159,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
{
if(i.spawnInChunk(getEngine(), c))
{
Iris.debug("Spawning Dimension Entities in Chunk " + c.getX() + "," + c.getZ() + " Biome ID: " + id);
Iris.debug(" Spawning Dimension Entities in Chunk " + c.getX() + "," + c.getZ() + " Biome ID: " + id);
return true;
}
}

View File

@ -99,7 +99,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
this.production = production;
this.dimensionQuery = query;
initialized = new AtomicBoolean(false);
art = J.ar(this::tick, 20);
art = J.ar(this::tick, 40);
populators = new KList<BlockPopulator>().qadd(new BlockPopulator() {
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
@ -143,9 +143,18 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
return;
}
int pri = Thread.currentThread().getPriority();
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
if (M.ms() - mst > 1000) {
generatedPerSecond = (double) (generated - lgenerated) / ((double) (M.ms() - mst) / 1000D);
mst = M.ms();
lgenerated = generated;
}
try {
if (hotloader != null) {
J.a(() -> hotloader.check());
hotloader.check();
getComposite().clean();
}
} catch (Throwable e) {
@ -153,11 +162,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
}
if (M.ms() - mst > 1000) {
generatedPerSecond = (double) (generated - lgenerated) / ((double) (M.ms() - mst) / 1000D);
mst = M.ms();
lgenerated = generated;
}
Thread.currentThread().setPriority(pri);
}
private synchronized IrisDimension getDimension(IrisWorld world) {

View File

@ -19,13 +19,16 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.engine.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.RegistryListEntity;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.common.IRare;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.J;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -39,7 +42,7 @@ import org.bukkit.entity.Entity;
@AllArgsConstructor
@Desc("Represents an entity spawn during initial chunk generation")
@Data
public class IrisEntitySpawn {
public class IrisEntitySpawn implements IRare {
@RegistryListEntity
@Required
@Desc("The entity")
@ -61,13 +64,13 @@ public class IrisEntitySpawn {
private final transient AtomicCache<IrisEntity> ent = new AtomicCache<>();
public boolean spawn(Engine gen, Chunk c, RNG rng) {
int spawns = rng.i(1, rarity) == 1 ? rng.i(minSpawns, maxSpawns) : 0;
int spawns = minSpawns == maxSpawns ? minSpawns : rng.i(Math.min(minSpawns, maxSpawns), Math.max(minSpawns, maxSpawns));
if (spawns > 0) {
for (int i = 0; i < spawns; i++) {
int x = (c.getX() * 16) + rng.i(15);
int z = (c.getZ() * 16) + rng.i(15);
int h = gen.getHeight(x, z) + gen.getMinHeight();
int h = c.getWorld().getHighestBlockYAt(x, z);
spawn100(gen, new Location(c.getWorld(), x, h, z));
}
@ -96,11 +99,11 @@ public class IrisEntitySpawn {
private Entity spawn100(Engine g, Location at) {
try {
Location l = at.clone().add(0.5, 1, 0.5);
Iris.debug(" Spawned " + "Entity<" + getEntity() + "> at " + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ());
Iris.debug(" Spawned " + "Entity<" + getEntity() + "> at " + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ());
return getRealEntity(g).spawn(g, l, rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)));
} catch (Throwable e) {
Iris.reportError(e);
Iris.error("Failed to retrieve real entity @ " + at);
Iris.error(" Failed to retrieve real entity @ " + at);
return null;
}
}

View File

@ -18,10 +18,16 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.engine.object.common.IRare;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.engine.stream.convert.SelectionStream;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.reflect.V;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -40,12 +46,23 @@ public class IrisSpawner extends IrisRegistrant {
@Desc("The entity spawns to add")
private KList<IrisEntitySpawn> spawns = new KList<>();
private AtomicCache<KList<IrisEntitySpawn>> selection = new AtomicCache<>();
public boolean spawnInChunk(Engine engine, Chunk c) {
if(spawns.isEmpty())
{
Iris.warn(" Spawner " + getLoadKey() + " has an empty spawn list! (" + getLoadFile().getPath() + ")");
return false;
}
return spawns.getRandom().spawn(engine, c, RNG.r);
return selection.aquire(() -> {
KList<IrisEntitySpawn> rarityTypes = new KList<>();
for (IrisEntitySpawn i : spawns) {
rarityTypes.addMultiple(i, IRare.get(i));
}
return rarityTypes;
}).getRandom(RNG.r).spawn(engine, c, RNG.r);
}
}

View File

@ -0,0 +1,37 @@
/*
* 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.object;
import com.volmit.iris.engine.object.annotations.Desc;
import lombok.Data;
@Data
@Desc("Represents a time of day (24h time, not 12h am/pm)")
public class IrisTime {
@Desc("The beginning hour")
private double startHour = 0;
@Desc("The ending hour")
private double endHour = 24;
public boolean isWithin(double hour)
{
}
}

View File

@ -0,0 +1,31 @@
/*
* 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.object;
import com.volmit.iris.engine.object.annotations.Desc;
import lombok.Data;
@Desc("Represents a weather type")
public enum IrisWeather {
@Desc("Represents when weather is not causing downfall")
NONE,
@Desc("Represents rain or snow")
DOWNFALL
}

View File

@ -21,34 +21,71 @@ package com.volmit.iris.engine.parallel;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Looper;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
public class MultiBurst {
public static final MultiBurst burst = new MultiBurst("Iris", IrisSettings.get().getConcurrency().getMiscThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getMiscThreadCount()));
private final ExecutorService service;
private ExecutorService syncService;
private ExecutorService service;
private final Looper heartbeat;
private final AtomicLong last;
private int tid;
private final String name;
private final int tc;
private final int priority;
public MultiBurst(int tc) {
this("Iris", 6, tc);
}
public MultiBurst(String name, int priority, int tc) {
service = Executors.newFixedThreadPool(Math.max(tc, 1), r -> {
tid++;
Thread t = new Thread(r);
t.setName(name + " " + tid);
t.setPriority(priority);
t.setUncaughtExceptionHandler((et, e) ->
{
Iris.info("Exception encountered in " + et.getName());
e.printStackTrace();
});
this.name = name;
this.priority = priority;
this.tc = tc;
last = new AtomicLong(M.ms());
heartbeat = new Looper() {
@Override
protected long loop() {
if(M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null)
{
service.shutdown();
service = null;
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resource.");
}
return t;
});
return 60000;
}
};
heartbeat.setName(name);
heartbeat.start();
}
private synchronized ExecutorService getService()
{
last.set(M.ms());
if(service == null || service.isShutdown())
{
service = Executors.newFixedThreadPool(Math.max(tc, 1), r -> {
tid++;
Thread t = new Thread(r);
t.setName(name + " " + tid);
t.setPriority(priority);
t.setUncaughtExceptionHandler((et, e) ->
{
Iris.info("Exception encountered in " + et.getName());
e.printStackTrace();
});
return t;
});
Iris.debug("Started MultiBurst Pool " + name + " with " + tc + " threads at " + priority + " priority.");
}
return service;
}
public void burst(Runnable... r) {
@ -66,7 +103,7 @@ public class MultiBurst {
}
public BurstExecutor burst(int estimate) {
return new BurstExecutor(service, estimate);
return new BurstExecutor(getService(), estimate);
}
public BurstExecutor burst() {
@ -74,43 +111,72 @@ public class MultiBurst {
}
public <T> Future<T> lazySubmit(Callable<T> o) {
return service.submit(o);
return getService().submit(o);
}
public void lazy(Runnable o) {
service.execute(o);
getService().execute(o);
}
public Future<?> future(Runnable o) {
return service.submit(o);
return getService().submit(o);
}
public CompletableFuture<?> complete(Runnable o) {
return CompletableFuture.runAsync(o, service);
return CompletableFuture.runAsync(o, getService());
}
public void shutdownNow() {
service.shutdownNow().forEach(Runnable::run);
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
heartbeat.interrupt();
if(service != null)
{
service.shutdownNow().forEach(Runnable::run);
}
}
public void shutdown() {
service.shutdown();
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
heartbeat.interrupt();
if(service != null)
{
service.shutdown();
}
}
public void shutdownLater() {
J.a(service::shutdown, 100);
if(service != null)
{
service.submit(() -> {
J.sleep(3000);
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
if(service != null)
{
service.shutdown();
}
});
heartbeat.interrupt();
}
}
public void shutdownAndAwait() {
service.shutdown();
try {
while (!service.awaitTermination(10, TimeUnit.SECONDS)) {
Iris.info("Still waiting to shutdown burster...");
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
heartbeat.interrupt();
if(service != null)
{
service.shutdown();
try {
while (!service.awaitTermination(10, TimeUnit.SECONDS)) {
Iris.info("Still waiting to shutdown burster...");
}
} catch (Throwable e) {
e.printStackTrace();
Iris.reportError(e);
}
} catch (Throwable e) {
e.printStackTrace();
Iris.reportError(e);
}
}
}