mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Engine data saving
This commit is contained in:
parent
e79ba6117b
commit
8820b02406
@ -18,8 +18,10 @@
|
||||
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.engine.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.*;
|
||||
import com.volmit.iris.engine.hunk.Hunk;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
@ -30,6 +32,7 @@ import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
@ -42,6 +45,8 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class IrisEngine extends BlockPopulator implements Engine {
|
||||
@ -87,12 +92,12 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
@Getter
|
||||
private double maxBiomeDecoratorDensity;
|
||||
|
||||
private IrisEngineData engineData;
|
||||
private AtomicCache<IrisEngineData> engineData = new AtomicCache<>();
|
||||
|
||||
public IrisEngine(EngineTarget target, EngineCompound compound, int index) {
|
||||
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)");
|
||||
metrics = new EngineMetrics(32);
|
||||
engineData = new IrisEngineData();
|
||||
getEngineData();
|
||||
this.target = target;
|
||||
this.framework = new IrisEngineFramework(this);
|
||||
worldManager = new IrisWorldManager(this);
|
||||
@ -107,6 +112,35 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
J.a(this::computeBiomeMaxes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisEngineData getEngineData() {
|
||||
return engineData.aquire(() -> {
|
||||
File f = new File(getWorld().worldFolder(), "iris/engine-data/" + getDimension().getLoadKey() + "-" + getIndex() + ".json");
|
||||
|
||||
if(!f.exists())
|
||||
{
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
IO.writeAll(f, new Gson().toJson(new IrisEngineData()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new Gson().fromJson(IO.readAll(f), IrisEngineData.class);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new IrisEngineData();
|
||||
});
|
||||
}
|
||||
|
||||
private void computeBiomeMaxes() {
|
||||
for (IrisBiome i : getDimension().getAllBiomes(this)) {
|
||||
double density = 0;
|
||||
@ -140,6 +174,7 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
getWorldManager().close();
|
||||
getFramework().close();
|
||||
getTarget().close();
|
||||
saveEngineData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -167,6 +202,7 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
@ChunkCoordinates
|
||||
@Override
|
||||
public void generate(int x, int z, Hunk<BlockData> vblocks, Hunk<Biome> vbiomes, boolean multicore) {
|
||||
getEngineData().getStatistics().generatedChunk();
|
||||
try {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
Hunk<BlockData> blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t));
|
||||
@ -208,6 +244,17 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEngineData() {
|
||||
File f = new File(getWorld().worldFolder(), "iris/engine-data/" + getDimension().getLoadKey() + "-" + getIndex() + ".json");
|
||||
f.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(f, new Gson().toJson(getEngineData()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisBiome getFocus() {
|
||||
if (getDimension().getFocus() == null || getDimension().getFocus().trim().isEmpty()) {
|
||||
@ -219,19 +266,10 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
|
||||
@Override
|
||||
public void hotloading() {
|
||||
getEngineData().getStatistics().hotloaded();
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisEngineData getEngineData() {
|
||||
return engineData;
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk c) {
|
||||
|
@ -48,17 +48,16 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
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);
|
||||
private final ChronoLatch cl;
|
||||
private int actuallySpawned = 0;
|
||||
|
||||
public IrisWorldManager(Engine engine) {
|
||||
super(engine);
|
||||
cl = new ChronoLatch(5000);
|
||||
spawnCooldowns = new KMap<>();
|
||||
spawnable = true;
|
||||
art = J.ar(this::onAsyncTick, 7);
|
||||
}
|
||||
|
||||
|
@ -99,12 +99,16 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
||||
|
||||
default void save() {
|
||||
getParallax().saveAll();
|
||||
saveEngineData();
|
||||
}
|
||||
|
||||
default void saveNow() {
|
||||
getParallax().saveAllNOW();
|
||||
saveEngineData();
|
||||
}
|
||||
|
||||
void saveEngineData();
|
||||
|
||||
default String getName() {
|
||||
return getDimension().getName();
|
||||
}
|
||||
@ -404,7 +408,5 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
||||
|
||||
void hotloading();
|
||||
|
||||
void saveProperties();
|
||||
|
||||
IrisEngineData getEngineData();
|
||||
}
|
||||
|
@ -24,5 +24,6 @@ import lombok.Data;
|
||||
@Data
|
||||
public class IrisEngineData
|
||||
{
|
||||
private IrisEngineStatistics statistics = new IrisEngineStatistics();
|
||||
private KList<IrisEngineSpawnerCooldown> spawnerCooldowns = new KList<>();
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ public class IrisEngineSpawnerCooldown
|
||||
public void spawn(Engine engine)
|
||||
{
|
||||
lastSpawn = M.ms();
|
||||
engine.saveProperties();
|
||||
}
|
||||
|
||||
public boolean canSpawn(IrisRate s)
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.engine;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class IrisEngineStatistics {
|
||||
private int totalHotloads = 0;
|
||||
private int chunksGenerated = 0;
|
||||
|
||||
public void generatedChunk() {
|
||||
chunksGenerated++;
|
||||
}
|
||||
|
||||
public void hotloaded() {
|
||||
totalHotloads++;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user