mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-26 18:49:06 +00:00
Goes faster
This commit is contained in:
@@ -35,6 +35,8 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Snippet("style")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@@ -70,6 +72,10 @@ public class IrisGeneratorStyle {
|
||||
@MaxNumber(64)
|
||||
@Desc("The exponent")
|
||||
private double exponent = 1;
|
||||
@MinNumber(0)
|
||||
@MaxNumber(8192)
|
||||
@Desc("If the cache size is set above 0, this generator will be cached")
|
||||
private int cacheSize = 0;
|
||||
|
||||
public IrisGeneratorStyle(NoiseStyle s) {
|
||||
this.style = s;
|
||||
@@ -81,6 +87,18 @@ public class IrisGeneratorStyle {
|
||||
}
|
||||
|
||||
public CNG createNoCache(RNG rng, IrisData data) {
|
||||
return createNoCache(rng, data, false);
|
||||
}
|
||||
|
||||
|
||||
private int hash()
|
||||
{
|
||||
return Objects.hash(expression, imageMap, multiplier, axialFracturing, fracture != null ? fracture.hash() : 0, exponent, cacheSize, zoom, cellularZoom, cellularFrequency, style);
|
||||
}
|
||||
|
||||
public CNG createNoCache(RNG rng, IrisData data, boolean actuallyCached) {
|
||||
String cacheKey = hash() + "";
|
||||
|
||||
if(getExpression() != null) {
|
||||
IrisExpression e = data.getExpressionLoader().load(getExpression());
|
||||
|
||||
@@ -134,7 +152,7 @@ public class IrisGeneratorStyle {
|
||||
}
|
||||
|
||||
public CNG create(RNG rng, IrisData data) {
|
||||
return cng.aquire(() -> createNoCache(rng, data));
|
||||
return cng.aquire(() -> createNoCache(rng, data, true));
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
|
||||
@@ -31,11 +31,15 @@ import com.volmit.iris.engine.object.StudioMode;
|
||||
import com.volmit.iris.engine.platform.studio.StudioGenerator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.IrisBiomeStorage;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.view.BiomeGridHunkHolder;
|
||||
import com.volmit.iris.util.hunk.view.ChunkDataHunkHolder;
|
||||
import com.volmit.iris.util.io.ReactiveFolder;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Setter;
|
||||
@@ -278,9 +282,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
if(studioGenerator != null) {
|
||||
studioGenerator.generateChunk(getEngine(), tc, x, z);
|
||||
} else {
|
||||
Hunk<BlockData> blocks = Hunk.view(tc);
|
||||
Hunk<Biome> biomes = Hunk.view(tc, tc.getMinHeight(), tc.getMaxHeight());
|
||||
ChunkDataHunkHolder blocks = new ChunkDataHunkHolder(tc);
|
||||
BiomeGridHunkHolder biomes = new BiomeGridHunkHolder(tc, tc.getMinHeight(), tc.getMaxHeight());
|
||||
getEngine().generate(x << 4, z << 4, blocks, biomes, true);
|
||||
blocks.apply();
|
||||
biomes.apply();
|
||||
}
|
||||
|
||||
ChunkData c = tc.getRaw();
|
||||
|
||||
82
src/main/java/com/volmit/iris/util/cache/ArrayCache.java
vendored
Normal file
82
src/main/java/com/volmit/iris/util/cache/ArrayCache.java
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.util.hunk.bits.Writable;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ArrayCache<T> extends Writable<T> {
|
||||
T get(int i);
|
||||
|
||||
void set(int i, T t);
|
||||
|
||||
void iset(int i, int v);
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
void writeCache(DataOutputStream dos) throws IOException;
|
||||
|
||||
static int zigZag(int coord, int size)
|
||||
{
|
||||
if(coord < 0)
|
||||
{
|
||||
coord = Math.abs(coord);
|
||||
}
|
||||
|
||||
if(coord % (size * 2) >= size)
|
||||
{
|
||||
return (size) - (coord % size) - 1;
|
||||
}
|
||||
|
||||
else {
|
||||
return coord % size;
|
||||
}
|
||||
}
|
||||
|
||||
default void set(int x, int y, T v)
|
||||
{
|
||||
set((zigZag(y, getHeight()) * getWidth()) + zigZag(x, getWidth()), v);
|
||||
}
|
||||
|
||||
default T get(int x, int y)
|
||||
{
|
||||
try
|
||||
{
|
||||
return get((zigZag(y, getHeight()) * getWidth()) + zigZag(x, getWidth()));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
default void iset(int x, int y, int v)
|
||||
{
|
||||
iset((zigZag(y, getHeight()) * getWidth()) + zigZag(x, getWidth()), v);
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/cache/ByteBitCache.java
vendored
Normal file
44
src/main/java/com/volmit/iris/util/cache/ByteBitCache.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ByteBitCache extends DataBitCache<Integer> {
|
||||
public ByteBitCache(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer readNodeData(DataInputStream din) throws IOException {
|
||||
return (int) din.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Integer integer) throws IOException {
|
||||
dos.writeByte(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, v);
|
||||
}
|
||||
}
|
||||
76
src/main/java/com/volmit/iris/util/cache/ByteCache.java
vendored
Normal file
76
src/main/java/com/volmit/iris/util/cache/ByteCache.java
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ByteCache implements ArrayCache<Integer> {
|
||||
@Getter
|
||||
private final int width;
|
||||
@Getter
|
||||
private final int height;
|
||||
private final byte[] cache;
|
||||
|
||||
public ByteCache(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
cache = new byte[width * height];
|
||||
}
|
||||
|
||||
public void set(int i, Integer v)
|
||||
{
|
||||
cache[i] = v.byteValue();
|
||||
}
|
||||
|
||||
public Integer get(int i)
|
||||
{
|
||||
return (int)cache[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCache(DataOutputStream dos) throws IOException {
|
||||
dos.writeInt(width);
|
||||
dos.writeInt(height);
|
||||
|
||||
for(int i = 0; i < width * height; i++)
|
||||
{
|
||||
dos.writeByte(get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer readNodeData(DataInputStream din) throws IOException {
|
||||
return (int) din.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Integer integer) throws IOException {
|
||||
dos.writeByte(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, v);
|
||||
}
|
||||
}
|
||||
58
src/main/java/com/volmit/iris/util/cache/DataBitCache.java
vendored
Normal file
58
src/main/java/com/volmit/iris/util/cache/DataBitCache.java
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import com.volmit.iris.util.hunk.bits.DataContainer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class DataBitCache<T> implements ArrayCache<T> {
|
||||
@Getter
|
||||
private final int width;
|
||||
@Getter
|
||||
private final int height;
|
||||
private final DataContainer<T> cache;
|
||||
|
||||
public DataBitCache(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
cache = new DataContainer<>(this, width * height);
|
||||
}
|
||||
|
||||
public void set(int i, T v)
|
||||
{
|
||||
cache.set(i, v);
|
||||
}
|
||||
|
||||
public T get(int i)
|
||||
{
|
||||
return cache.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCache(DataOutputStream dos) throws IOException {
|
||||
dos.writeInt(width);
|
||||
dos.writeInt(height);
|
||||
cache.writeDos(dos);
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/cache/FloatBitCache.java
vendored
Normal file
44
src/main/java/com/volmit/iris/util/cache/FloatBitCache.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FloatBitCache extends DataBitCache<Float> {
|
||||
public FloatBitCache(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Float integer) throws IOException {
|
||||
dos.writeFloat(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, (float)v);
|
||||
}
|
||||
}
|
||||
93
src/main/java/com/volmit/iris/util/cache/FloatCache.java
vendored
Normal file
93
src/main/java/com/volmit/iris/util/cache/FloatCache.java
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FloatCache implements ArrayCache<Float> {
|
||||
@Getter
|
||||
private final int width;
|
||||
@Getter
|
||||
private final int height;
|
||||
private final float[] cache;
|
||||
|
||||
|
||||
public FloatCache(File file) throws IOException {
|
||||
this(new DataInputStream(new FileInputStream(file)));
|
||||
}
|
||||
|
||||
public FloatCache(DataInputStream din) throws IOException {
|
||||
this(din.readInt(), din.readInt());
|
||||
for(int i = 0; i < width * height; i++)
|
||||
{
|
||||
cache[i] = din.readFloat();
|
||||
}
|
||||
din.close();
|
||||
}
|
||||
|
||||
public FloatCache(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
cache = new float[width * height];
|
||||
}
|
||||
|
||||
public void set(int i, Float v)
|
||||
{
|
||||
cache[i] = v;
|
||||
}
|
||||
|
||||
public Float get(int i)
|
||||
{
|
||||
return cache[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCache(DataOutputStream dos) throws IOException {
|
||||
dos.writeInt(width);
|
||||
dos.writeInt(height);
|
||||
|
||||
for(int i = 0; i < width * height; i++)
|
||||
{
|
||||
dos.writeFloat(get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Float integer) throws IOException {
|
||||
dos.writeFloat(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, (float) v);
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/cache/IntBitCache.java
vendored
Normal file
44
src/main/java/com/volmit/iris/util/cache/IntBitCache.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class IntBitCache extends DataBitCache<Integer> {
|
||||
public IntBitCache(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Integer integer) throws IOException {
|
||||
dos.writeInt(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, v);
|
||||
}
|
||||
}
|
||||
78
src/main/java/com/volmit/iris/util/cache/IntCache.java
vendored
Normal file
78
src/main/java/com/volmit/iris/util/cache/IntCache.java
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import com.volmit.iris.util.hunk.bits.DataContainer;
|
||||
import com.volmit.iris.util.hunk.bits.Writable;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class IntCache implements ArrayCache<Integer> {
|
||||
@Getter
|
||||
private final int width;
|
||||
@Getter
|
||||
private final int height;
|
||||
private final int[] cache;
|
||||
|
||||
public IntCache(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
cache = new int[width * height];
|
||||
}
|
||||
|
||||
public void set(int i, Integer v)
|
||||
{
|
||||
cache[i] = v;
|
||||
}
|
||||
|
||||
public Integer get(int i)
|
||||
{
|
||||
return cache[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCache(DataOutputStream dos) throws IOException {
|
||||
dos.writeInt(width);
|
||||
dos.writeInt(height);
|
||||
|
||||
for(int i = 0; i < width * height; i++)
|
||||
{
|
||||
dos.writeInt(get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Integer integer) throws IOException {
|
||||
dos.writeInt(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, v);
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/cache/ShortBitCache.java
vendored
Normal file
44
src/main/java/com/volmit/iris/util/cache/ShortBitCache.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ShortBitCache extends DataBitCache<Short> {
|
||||
public ShortBitCache(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Short integer) throws IOException {
|
||||
dos.writeShort(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, (short) v);
|
||||
}
|
||||
}
|
||||
76
src/main/java/com/volmit/iris/util/cache/ShortCache.java
vendored
Normal file
76
src/main/java/com/volmit/iris/util/cache/ShortCache.java
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ShortCache implements ArrayCache<Short> {
|
||||
@Getter
|
||||
private final int width;
|
||||
@Getter
|
||||
private final int height;
|
||||
private final short[] cache;
|
||||
|
||||
public ShortCache(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
cache = new short[width * height];
|
||||
}
|
||||
|
||||
public void set(int i, Short v)
|
||||
{
|
||||
cache[i] = v;
|
||||
}
|
||||
|
||||
public Short get(int i)
|
||||
{
|
||||
return cache[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCache(DataOutputStream dos) throws IOException {
|
||||
dos.writeInt(width);
|
||||
dos.writeInt(height);
|
||||
|
||||
for(int i = 0; i < width * height; i++)
|
||||
{
|
||||
dos.writeShort(get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Short integer) throws IOException {
|
||||
dos.writeShort(integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, (short) v);
|
||||
}
|
||||
}
|
||||
40
src/main/java/com/volmit/iris/util/cache/UByteBitCache.java
vendored
Normal file
40
src/main/java/com/volmit/iris/util/cache/UByteBitCache.java
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
public class UByteBitCache extends ByteBitCache {
|
||||
public UByteBitCache(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int i, Integer v) {
|
||||
super.set(i, v + Byte.MIN_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(int i) {
|
||||
return super.get(i) - Byte.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, v);
|
||||
}
|
||||
}
|
||||
40
src/main/java/com/volmit/iris/util/cache/UByteCache.java
vendored
Normal file
40
src/main/java/com/volmit/iris/util/cache/UByteCache.java
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.cache;
|
||||
|
||||
public class UByteCache extends ByteCache {
|
||||
public UByteCache(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int i, Integer v) {
|
||||
super.set(i, v + Byte.MIN_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(int i) {
|
||||
return super.get(i) - Byte.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iset(int i, int v) {
|
||||
set(i, v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.data.chunk.LinkedTerrainChunk;
|
||||
import com.volmit.iris.util.hunk.storage.AtomicHunk;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class BiomeGridHunkHolder extends AtomicHunk<Biome> {
|
||||
@Getter
|
||||
private final BiomeGrid chunk;
|
||||
private final int minHeight;
|
||||
private final int maxHeight;
|
||||
|
||||
public BiomeGridHunkHolder(BiomeGrid chunk, int minHeight, int maxHeight) {
|
||||
super(16, maxHeight - minHeight, 16);
|
||||
this.chunk = chunk;
|
||||
this.minHeight = minHeight;
|
||||
this.maxHeight = maxHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return maxHeight - minHeight;
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
for(int i = 0; i < getHeight(); i++) {
|
||||
for(int j = 0; j < getWidth(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
Biome b = super.getRaw(j, i, k);
|
||||
|
||||
if(b != null)
|
||||
{
|
||||
chunk.setBiome(j, i + minHeight, k, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getRaw(int x, int y, int z) {
|
||||
Biome b = super.getRaw(x, y, z);
|
||||
|
||||
return b != null ? b : Biome.PLAINS;
|
||||
}
|
||||
|
||||
public void forceBiomeBaseInto(int x, int y, int z, Object somethingVeryDirty) {
|
||||
if(chunk instanceof LinkedTerrainChunk) {
|
||||
INMS.get().forceBiomeInto(x, y + minHeight, z, somethingVeryDirty, ((LinkedTerrainChunk) chunk).getRawBiome());
|
||||
return;
|
||||
}
|
||||
INMS.get().forceBiomeInto(x, y + minHeight, z, somethingVeryDirty, chunk);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.data.chunk.LinkedTerrainChunk;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
@@ -31,6 +32,7 @@ public class BiomeGridHunkView implements Hunk<Biome> {
|
||||
private final BiomeGrid chunk;
|
||||
private final int minHeight;
|
||||
private final int maxHeight;
|
||||
private int highest = -1000;
|
||||
|
||||
public BiomeGridHunkView(BiomeGrid chunk, int minHeight, int maxHeight) {
|
||||
this.chunk = chunk;
|
||||
@@ -56,6 +58,12 @@ public class BiomeGridHunkView implements Hunk<Biome> {
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Biome t) {
|
||||
chunk.setBiome(x, y + minHeight, z, t);
|
||||
|
||||
if(y > highest)
|
||||
{
|
||||
highest = y;
|
||||
Iris.info("Highest = " + highest);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.storage.AtomicHunk;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class ChunkDataHunkHolder extends AtomicHunk<BlockData> {
|
||||
private static final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final ChunkData chunk;
|
||||
|
||||
public ChunkDataHunkHolder(ChunkData chunk) {
|
||||
super(16, chunk.getMaxHeight() - chunk.getMinHeight(), 16);
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return chunk.getMaxHeight() - chunk.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getRaw(int x, int y, int z) {
|
||||
BlockData b = super.getRaw(x, y, z);
|
||||
|
||||
return b != null ? b : AIR;
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
for(int i = 0; i < getHeight(); i++) {
|
||||
for(int j = 0; j < getWidth(); j++) {
|
||||
for(int k = 0; k < getDepth(); k++) {
|
||||
BlockData b = super.getRaw(j, i, k);
|
||||
|
||||
if(b != null)
|
||||
{
|
||||
chunk.setBlock(j, i + chunk.getMinHeight(), k, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.IRare;
|
||||
import com.volmit.iris.engine.object.NoiseStyle;
|
||||
import com.volmit.iris.util.cache.FloatBitCache;
|
||||
import com.volmit.iris.util.cache.FloatCache;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.function.NoiseInjector;
|
||||
@@ -33,6 +35,11 @@ import com.volmit.iris.util.stream.arithmetic.FittedStream;
|
||||
import com.volmit.iris.util.stream.sources.CNGStream;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -56,6 +63,7 @@ public class CNG {
|
||||
private boolean trueFracturing = false;
|
||||
private KList<CNG> children;
|
||||
private CNG fracture;
|
||||
private FloatCache cache;
|
||||
private NoiseGenerator generator;
|
||||
private NoiseInjector injector;
|
||||
private RNG rng;
|
||||
@@ -133,14 +141,55 @@ public class CNG {
|
||||
}, 1D, 1);
|
||||
}
|
||||
|
||||
public CNG cached(int size)
|
||||
public CNG cached(int size, String key, File cacheFolder)
|
||||
{
|
||||
if(size <= 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
generator = new CachedNoise(generator, size);
|
||||
cache = null;
|
||||
|
||||
File f = new File(new File(cacheFolder, ".cache"), key + ".cnm");
|
||||
FloatCache fbc;
|
||||
boolean cached = false;
|
||||
if(f.exists())
|
||||
{
|
||||
try {
|
||||
fbc = new FloatCache(f);
|
||||
cached = true;
|
||||
} catch(IOException e) {
|
||||
fbc = new FloatCache(size, size);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
fbc = new FloatCache(size, size);
|
||||
}
|
||||
|
||||
if(!cached)
|
||||
{
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
for(int j = 0; j < size; j++)
|
||||
{
|
||||
fbc.set(i, j, (float) noise(i, j));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
DataOutputStream dos = new DataOutputStream(fos);
|
||||
fbc.writeCache(dos);
|
||||
dos.close();
|
||||
Iris.info("Saved Noise Cache " + f.getName());
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
cache = fbc;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -435,6 +484,11 @@ public class CNG {
|
||||
}
|
||||
|
||||
public double noise(double... dim) {
|
||||
if(cache != null && dim.length == 2)
|
||||
{
|
||||
return cache.get((int)dim[0], (int)dim[1]);
|
||||
}
|
||||
|
||||
double n = getNoise(dim);
|
||||
n = power != 1D ? (n < 0 ? -Math.pow(Math.abs(n), power) : Math.pow(n, power)) : n;
|
||||
double m = 1;
|
||||
|
||||
Reference in New Issue
Block a user